summaryrefslogtreecommitdiff
path: root/Source/Core/Common/MemoryUtil.cpp
diff options
context:
space:
mode:
authorSepalani <sepalani@hotmail.fr>2017-08-17 20:12:44 +0100
committerSepalani <sepalani@hotmail.fr>2017-08-18 20:08:50 +0100
commit4e5fe6366a2041b09616a9a2e3b2ccb038a4d2f1 (patch)
treed0a04d78ee87c80070a963f10341b628c7aaf23c /Source/Core/Common/MemoryUtil.cpp
parent4e40fad248db3dccad901cd200dbc96c03bfbb7f (diff)
CommonFuncs: LastStrerrorString added
Diffstat (limited to 'Source/Core/Common/MemoryUtil.cpp')
-rw-r--r--Source/Core/Common/MemoryUtil.cpp56
1 files changed, 15 insertions, 41 deletions
diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp
index beb594302e..bc2becfa54 100644
--- a/Source/Core/Common/MemoryUtil.cpp
+++ b/Source/Core/Common/MemoryUtil.cpp
@@ -88,20 +88,13 @@ void FreeMemoryPages(void* ptr, size_t size)
{
if (ptr)
{
- bool error_occurred = false;
-
#ifdef _WIN32
if (!VirtualFree(ptr, 0, MEM_RELEASE))
- error_occurred = true;
+ PanicAlert("FreeMemoryPages failed!\nVirtualFree: %s", GetLastErrorString().c_str());
#else
- int retval = munmap(ptr, size);
-
- if (retval != 0)
- error_occurred = true;
+ if (munmap(ptr, size) != 0)
+ PanicAlert("FreeMemoryPages failed!\nmunmap: %s", LastStrerrorString().c_str());
#endif
-
- if (error_occurred)
- PanicAlert("FreeMemoryPages failed!\n%s", GetLastErrorMsg().c_str());
}
}
@@ -119,60 +112,41 @@ void FreeAlignedMemory(void* ptr)
void ReadProtectMemory(void* ptr, size_t size)
{
- bool error_occurred = false;
-
#ifdef _WIN32
DWORD oldValue;
if (!VirtualProtect(ptr, size, PAGE_NOACCESS, &oldValue))
- error_occurred = true;
+ PanicAlert("ReadProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str());
#else
- int retval = mprotect(ptr, size, PROT_NONE);
-
- if (retval != 0)
- error_occurred = true;
+ if (mprotect(ptr, size, PROT_NONE) != 0)
+ PanicAlert("ReadProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str());
#endif
-
- if (error_occurred)
- PanicAlert("ReadProtectMemory failed!\n%s", GetLastErrorMsg().c_str());
}
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))
- error_occurred = true;
+ PanicAlert("WriteProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str());
#else
- int retval = mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ);
-
- if (retval != 0)
- error_occurred = true;
+ if (mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ) != 0)
+ PanicAlert("WriteProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str());
#endif
-
- if (error_occurred)
- PanicAlert("WriteProtectMemory failed!\n%s", GetLastErrorMsg().c_str());
}
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))
- error_occurred = true;
+ PanicAlert("UnWriteProtectMemory failed!\nVirtualProtect: %s", GetLastErrorString().c_str());
#else
- int retval = mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) :
- PROT_WRITE | PROT_READ);
-
- if (retval != 0)
- error_occurred = true;
+ if (mprotect(ptr, size,
+ allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ) != 0)
+ {
+ PanicAlert("UnWriteProtectMemory failed!\nmprotect: %s", LastStrerrorString().c_str());
+ }
#endif
-
- if (error_occurred)
- PanicAlert("UnWriteProtectMemory failed!\n%s", GetLastErrorMsg().c_str());
}
size_t MemPhysical()