CommonFuncs: LastStrerrorString added

This commit is contained in:
Sepalani
2017-08-17 20:12:44 +01:00
parent 4e40fad248
commit 4e5fe6366a
6 changed files with 69 additions and 78 deletions

View File

@ -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()