summaryrefslogtreecommitdiff
path: root/Source/Core/Common/MemoryUtil.cpp
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2014-08-10 05:28:00 -0400
committerLioncash <mathew1800@gmail.com>2014-08-10 05:28:00 -0400
commit9a61cfc650c159b8e6b57059fc9f335dd29fe3dd (patch)
tree847f1afbdd6c785cae441fa48eb26ac1b7556e99 /Source/Core/Common/MemoryUtil.cpp
parentbe3428cf8e7698e4efe9c50cd6499516e7f36332 (diff)
Core: Actually show MemoryUtil.cpp allocation error messages on Linux
Diffstat (limited to 'Source/Core/Common/MemoryUtil.cpp')
-rw-r--r--Source/Core/Common/MemoryUtil.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp
index 7a075692ce..7d5eaa0b28 100644
--- a/Source/Core/Common/MemoryUtil.cpp
+++ b/Source/Core/Common/MemoryUtil.cpp
@@ -129,14 +129,20 @@ void FreeMemoryPages(void* ptr, size_t size)
{
if (ptr)
{
+ bool error_occurred = false;
+
#ifdef _WIN32
if (!VirtualFree(ptr, 0, MEM_RELEASE))
- {
- PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg());
- }
+ error_occurred = true;
#else
- munmap(ptr, size);
+ int retval = munmap(ptr, size);
+
+ if (retval != 0)
+ error_occurred = true;
#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)
{
+ bool error_occurred = false;
+
#ifdef _WIN32
DWORD oldValue;
if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue))
- PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg());
+ error_occurred = true;
#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
+
+ if (error_occurred)
+ PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg());
}
void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute)
{
+ bool error_occurred = false;
+
#ifdef _WIN32
DWORD oldValue;
if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue))
- PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
+ error_occurred = true;
#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
+
+ if (error_occurred)
+ PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg());
}
std::string MemUsage()