Remove code for only allocating low memory

This is unnecessary when we have position-independent code.
This commit is contained in:
JosJuice
2017-04-14 12:53:32 +02:00
parent 89535468eb
commit 4b4cf509f8
7 changed files with 26 additions and 84 deletions

View File

@ -7,6 +7,7 @@
#include <set>
#include <string>
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Common/MemArena.h"
@ -125,19 +126,22 @@ void MemArena::ReleaseView(void* view, size_t size)
u8* MemArena::FindMemoryBase()
{
#if _ARCH_64
#if _ARCH_32
const size_t memory_size = 0x31000000;
#else
const size_t memory_size = 0x400000000;
#endif
#ifdef _WIN32
// 64 bit
u8* base = (u8*)VirtualAlloc(0, 0x400000000, MEM_RESERVE, PAGE_READWRITE);
u8* base = static_cast<u8*>(VirtualAlloc(nullptr, memory_size, MEM_RESERVE, PAGE_READWRITE));
if (!base)
{
PanicAlert("Failed to map enough memory space: %s", GetLastErrorMsg().c_str());
return nullptr;
}
VirtualFree(base, 0, MEM_RELEASE);
return base;
#else
// Very precarious - mmap cannot return an error when trying to map already used pages.
// This makes the Windows approach above unusable on Linux, so we will simply pray...
return reinterpret_cast<u8*>(0x2300000000ULL);
#endif
#else // 32 bit
#ifdef ANDROID
// Android 4.3 changed how mmap works.
// if we map it private and then munmap it, we can't use the base returned.
@ -146,14 +150,13 @@ u8* MemArena::FindMemoryBase()
#else
const int flags = MAP_ANON | MAP_PRIVATE;
#endif
const u32 MemSize = 0x31000000;
void* base = mmap(0, MemSize, PROT_NONE, flags, -1, 0);
void* base = mmap(nullptr, memory_size, PROT_NONE, flags, -1, 0);
if (base == MAP_FAILED)
{
PanicAlert("Failed to map 1 GB of memory space: %s", strerror(errno));
return 0;
PanicAlert("Failed to map enough memory space: %s", GetLastErrorMsg().c_str());
return nullptr;
}
munmap(base, MemSize);
munmap(base, memory_size);
return static_cast<u8*>(base);
#endif
}