From e33acdc5e9226cb4825de8b9d858f65553a8ed93 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Fri, 21 Jul 2017 07:46:43 +0000 Subject: [PATCH] Common: fix MAP_32BIT after 9f24203ef8f6 9f24203ef8f6 added 0x20000000 as a default fallback address hint which unconditionally disabled MAP_32BIT. FreeBSD cannot use the hints because without adjusting RLIMIT_DATA lower addresses are reserved for brk(2) style heap. So, don't try to use hints with MAP_32BIT. --- Common/MemoryUtil.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Common/MemoryUtil.cpp b/Common/MemoryUtil.cpp index c572ddacab..7ea29b9715 100644 --- a/Common/MemoryUtil.cpp +++ b/Common/MemoryUtil.cpp @@ -157,7 +157,7 @@ void *AllocateExecutableMemory(size_t size) { } #else static char *map_hint = 0; -#if defined(_M_X64) +#if defined(_M_X64) && !defined(MAP_32BIT) // Try to request one that is close to our memory location if we're in high memory. // We use a dummy global variable to give us a good location to start from. if (!map_hint) { @@ -179,7 +179,7 @@ void *AllocateExecutableMemory(size_t size) { void* ptr = mmap(map_hint, size, prot, MAP_ANON | MAP_PRIVATE #if defined(_M_X64) && defined(MAP_32BIT) - | ((uintptr_t) map_hint == 0 ? MAP_32BIT : 0) + | MAP_32BIT #endif , -1, 0); @@ -196,7 +196,7 @@ void *AllocateExecutableMemory(size_t size) { ERROR_LOG(MEMMAP, "Failed to allocate executable memory (%d)", (int)size); PanicAlert("Failed to allocate executable memory\n%s", GetLastErrorMsg()); } -#if defined(_M_X64) && !defined(_WIN32) +#if defined(_M_X64) && !defined(_WIN32) && !defined(MAP_32BIT) else if ((uintptr_t)map_hint <= 0xFFFFFFFF) { // Round up if we're below 32-bit mark, probably allocating sequentially. map_hint += round_page(size);