|
|
@ -16,7 +16,7 @@
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
|
|
|
|
#if !defined(_WIN32) && defined(ARCHITECTURE_X64) && !defined(MAP_32BIT)
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#define PAGE_MASK (getpagesize() - 1)
|
|
|
|
#define PAGE_MASK (getpagesize() - 1)
|
|
|
|
#define round_page(x) ((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
|
|
|
|
#define round_page(x) ((((unsigned long)(x)) + PAGE_MASK) & ~(PAGE_MASK))
|
|
|
@ -31,7 +31,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
|
|
|
|
void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
void* ptr = VirtualAlloc(0, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
static char *map_hint = 0;
|
|
|
|
static char *map_hint = 0;
|
|
|
|
#if defined(__x86_64__) && !defined(MAP_32BIT)
|
|
|
|
#if defined(ARCHITECTURE_X64) && !defined(MAP_32BIT)
|
|
|
|
// This OS has no flag to enforce allocation below the 4 GB boundary,
|
|
|
|
// 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
|
|
|
|
// but if we hint that we want a low address it is very likely we will
|
|
|
|
// get one.
|
|
|
|
// get one.
|
|
|
@ -43,7 +43,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
void* ptr = mmap(map_hint, size, PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
MAP_ANON | MAP_PRIVATE
|
|
|
|
MAP_ANON | MAP_PRIVATE
|
|
|
|
#if defined(__x86_64__) && defined(MAP_32BIT)
|
|
|
|
#if defined(ARCHITECTURE_X64) && defined(MAP_32BIT)
|
|
|
|
| (low ? MAP_32BIT : 0)
|
|
|
|
| (low ? MAP_32BIT : 0)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
, -1, 0);
|
|
|
|
, -1, 0);
|
|
|
@ -62,7 +62,7 @@ void* AllocateExecutableMemory(size_t size, bool low)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
LOG_ERROR(Common_Memory, "Failed to allocate executable memory");
|
|
|
|
LOG_ERROR(Common_Memory, "Failed to allocate executable memory");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if !defined(_WIN32) && defined(__x86_64__) && !defined(MAP_32BIT)
|
|
|
|
#if !defined(_WIN32) && defined(ARCHITECTURE_X64) && !defined(MAP_32BIT)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (low)
|
|
|
|
if (low)
|
|
|
|