summaryrefslogtreecommitdiff
path: root/Source/Core/Common/MemoryUtil.cpp
diff options
context:
space:
mode:
authorshuffle2 <godisgovernment@gmail.com>2017-06-02 21:53:02 -0700
committerGitHub <noreply@github.com>2017-06-02 21:53:02 -0700
commit3443454ba279811a6e10a840d8c21af3e24dd614 (patch)
tree96b3ee4dd51d96b761ff124abaca1cbd3079bf4a /Source/Core/Common/MemoryUtil.cpp
parent0b63fcc78f235c739cd2bcb93fde6a9d2c286af7 (diff)
parente019872d623f044efc49bf5b50c47330d367cc61 (diff)
Merge pull request #5271 from JosJuice/allow-aslr
Allow (but don't force) ASLR
Diffstat (limited to 'Source/Core/Common/MemoryUtil.cpp')
-rw-r--r--Source/Core/Common/MemoryUtil.cpp63
1 files changed, 7 insertions, 56 deletions
diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp
index 4eb2e1f2d3..305d779c3f 100644
--- a/Source/Core/Common/MemoryUtil.cpp
+++ b/Source/Core/Common/MemoryUtil.cpp
@@ -29,74 +29,25 @@
#endif
#endif
-// Valgrind doesn't support MAP_32BIT.
-// Uncomment the following line to be able to run Dolphin in Valgrind.
-//#undef MAP_32BIT
-
namespace Common
{
-#if !defined(_WIN32) && defined(_M_X86_64) && !defined(MAP_32BIT)
-#include <unistd.h>
-static uintptr_t RoundPage(uintptr_t addr)
-{
- uintptr_t mask = getpagesize() - 1;
- return (addr + mask) & ~mask;
-}
-#endif
-
// This is purposely not a full wrapper for virtualalloc/mmap, but it
// provides exactly the primitive operations that Dolphin needs.
-void* AllocateExecutableMemory(size_t size, bool low)
+void* AllocateExecutableMemory(size_t size)
{
#if defined(_WIN32)
- void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#else
- static char* map_hint = nullptr;
-#if defined(_M_X86_64) && !defined(MAP_32BIT)
- // This OS has no flag to enforce allocation below the 4 GB boundary,
- // but if we hint that we want a low address it is very likely we will
- // get one.
- // An older version of this code used MAP_FIXED, but that has the side
- // effect of discarding already mapped pages that happen to be in the
- // requested virtual memory range (such as the emulated RAM, sometimes).
- if (low && (!map_hint))
- map_hint = (char*)RoundPage(512 * 1024 * 1024); /* 0.5 GB rounded up to the next page */
-#endif
- void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE
-#if defined(_M_X86_64) && defined(MAP_32BIT)
- | (low ? MAP_32BIT : 0)
-#endif
- ,
- -1, 0);
-#endif /* defined(_WIN32) */
+ void* ptr =
+ mmap(nullptr, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
-#ifdef _WIN32
- if (ptr == nullptr)
- {
-#else
if (ptr == MAP_FAILED)
- {
ptr = nullptr;
#endif
- PanicAlert("Failed to allocate executable memory. If you are running Dolphin in Valgrind, try "
- "'#undef MAP_32BIT'.");
- }
-#if !defined(_WIN32) && defined(_M_X86_64) && !defined(MAP_32BIT)
- else
- {
- if (low)
- {
- map_hint += size;
- map_hint = (char*)RoundPage((uintptr_t)map_hint); /* round up to the next page */
- }
- }
-#endif
-#if _M_X86_64
- if ((u64)ptr >= 0x80000000 && low == true)
- PanicAlert("Executable memory ended up above 2GB!");
-#endif
+ if (ptr == nullptr)
+ PanicAlert("Failed to allocate executable memory");
return ptr;
}
@@ -104,7 +55,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
void* AllocateMemoryPages(size_t size)
{
#ifdef _WIN32
- void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
+ void* ptr = VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE);
#else
void* ptr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);