Core: Actually show MemoryUtil.cpp allocation error messages on Linux

This commit is contained in:
Lioncash 2014-08-10 05:28:00 -04:00
parent be3428cf8e
commit 9a61cfc650

View File

@ -129,14 +129,20 @@ void FreeMemoryPages(void* ptr, size_t size)
{ {
if (ptr) if (ptr)
{ {
bool error_occurred = false;
#ifdef _WIN32 #ifdef _WIN32
if (!VirtualFree(ptr, 0, MEM_RELEASE)) if (!VirtualFree(ptr, 0, MEM_RELEASE))
{ error_occurred = true;
PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
}
#else #else
munmap(ptr, size); int retval = munmap(ptr, size);
if (retval != 0)
error_occurred = true;
#endif #endif
if (error_occurred)
PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
} }
} }
@ -154,24 +160,40 @@ void FreeAlignedMemory(void* ptr)
void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) void WriteProtectMemory(void* ptr, size_t size, bool allowExecute)
{ {
bool error_occurred = false;
#ifdef _WIN32 #ifdef _WIN32
DWORD oldValue; DWORD oldValue;
if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue)) if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue))
PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg()); error_occurred = true;
#else #else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ); int retval = mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
if (retval != 0)
error_occurred = true;
#endif #endif
if (error_occurred)
PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg());
} }
void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
{ {
bool error_occurred = false;
#ifdef _WIN32 #ifdef _WIN32
DWORD oldValue; DWORD oldValue;
if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue)) if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue))
PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg()); error_occurred = true;
#else #else
mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ); int retval = mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ);
if (retval != 0)
error_occurred = true;
#endif #endif
if (error_occurred)
PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
} }
std::string MemUsage() std::string MemUsage()