Skip to content
Permalink
Browse files

Merge pull request #12553 from hrydgard/no-more-MAP_32BIT

Don't use the MAP_32BIT flag on any platform.
  • Loading branch information
unknownbrackets committed Jan 5, 2020
2 parents bca7835 + a04720e commit 33cca186c0c45a34a8b3b5143de23b7378dfb0be
Showing with 5 additions and 17 deletions.
  1. +5 −17 Common/MemoryUtil.cpp
@@ -117,11 +117,6 @@ static void *SearchForFreeMem(size_t size) {

// This is purposely not a full wrapper for virtualalloc/mmap, but it
// provides exactly the primitive operations that PPSSPP needs.

#if PPSSPP_PLATFORM(MAC)
#undef MAP_32BIT
#endif

void *AllocateExecutableMemory(size_t size) {
#if defined(_WIN32)
void *ptr = nullptr;
@@ -161,17 +156,15 @@ void *AllocateExecutableMemory(size_t size) {
}
#else
static char *map_hint = 0;
#if defined(_M_X64) && !defined(MAP_32BIT)
#if defined(_M_X64)
// 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) {
if ((uintptr_t) &hint_location > 0xFFFFFFFFULL)
map_hint = (char*)round_page(&hint_location) - 0x20000000; // 0.5gb lower than our approximate location
else
map_hint = (char*)0x20000000; // 0.5GB mark in memory
}
else if ((uintptr_t) map_hint > 0xFFFFFFFFULL)
{
} else if ((uintptr_t) map_hint > 0xFFFFFFFFULL) {
map_hint -= round_page(size); /* round down to the next page if we're in high memory */
}
#endif
@@ -180,13 +173,7 @@ void *AllocateExecutableMemory(size_t size) {
if (PlatformIsWXExclusive())
prot = PROT_READ | PROT_WRITE; // POST_EXEC is added later in this case.

void* ptr = mmap(map_hint, size, prot,
MAP_ANON | MAP_PRIVATE
#if defined(_M_X64) && defined(MAP_32BIT)
| MAP_32BIT
#endif
, -1, 0);

void* ptr = mmap(map_hint, size, prot, MAP_ANON | MAP_PRIVATE, -1, 0);
#endif /* defined(_WIN32) */

#if !defined(_WIN32)
@@ -200,7 +187,8 @@ void *AllocateExecutableMemory(size_t size) {
ERROR_LOG(MEMMAP, "Failed to allocate executable memory (%d) errno=%d", (int)size, errno);
PanicAlert("Failed to allocate executable memory\n%s", GetLastErrorMsg());
}
#if defined(_M_X64) && !defined(_WIN32) && !defined(MAP_32BIT)

#if defined(_M_X64) && !defined(_WIN32)
else if ((uintptr_t)map_hint <= 0xFFFFFFFF) {
// Round up if we're below 32-bit mark, probably allocating sequentially.
map_hint += round_page(size);

0 comments on commit 33cca18

Please sign in to comment.
You can’t perform that action at this time.