diff options
| author | JMC47 <JMC4789@gmail.com> | 2023-09-02 12:45:39 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-02 12:45:39 -0400 |
| commit | bd57d17dee609bf6100651ef1cee862bae420da5 (patch) | |
| tree | a7d0ce15879a297a0dee887fe9001e1a6f3f5704 /Source/Core/Common/MemoryUtil.cpp | |
| parent | 6beaee078baeaa80f9f1c21ce372ce28fd8273b6 (diff) | |
| parent | 4131dffae92c22ed938118d196ffc94da63246e1 (diff) | |
Merge pull request #12079 from JosJuice/blr-no-fastmem
Jit: Allow BLR optimization without fastmem
Diffstat (limited to 'Source/Core/Common/MemoryUtil.cpp')
| -rw-r--r-- | Source/Core/Common/MemoryUtil.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/Source/Core/Common/MemoryUtil.cpp b/Source/Core/Common/MemoryUtil.cpp index b473705411..2cd393d098 100644 --- a/Source/Core/Common/MemoryUtil.cpp +++ b/Source/Core/Common/MemoryUtil.cpp @@ -160,18 +160,25 @@ void* AllocateAlignedMemory(size_t size, size_t alignment) return ptr; } -void FreeMemoryPages(void* ptr, size_t size) +bool FreeMemoryPages(void* ptr, size_t size) { if (ptr) { #ifdef _WIN32 if (!VirtualFree(ptr, 0, MEM_RELEASE)) + { PanicAlertFmt("FreeMemoryPages failed!\nVirtualFree: {}", GetLastErrorString()); + return false; + } #else if (munmap(ptr, size) != 0) + { PanicAlertFmt("FreeMemoryPages failed!\nmunmap: {}", LastStrerrorString()); + return false; + } #endif } + return true; } void FreeAlignedMemory(void* ptr) @@ -186,39 +193,56 @@ void FreeAlignedMemory(void* ptr) } } -void ReadProtectMemory(void* ptr, size_t size) +bool ReadProtectMemory(void* ptr, size_t size) { #ifdef _WIN32 DWORD oldValue; if (!VirtualProtect(ptr, size, PAGE_NOACCESS, &oldValue)) + { PanicAlertFmt("ReadProtectMemory failed!\nVirtualProtect: {}", GetLastErrorString()); + return false; + } #else if (mprotect(ptr, size, PROT_NONE) != 0) + { PanicAlertFmt("ReadProtectMemory failed!\nmprotect: {}", LastStrerrorString()); + return false; + } #endif + return true; } -void WriteProtectMemory(void* ptr, size_t size, bool allowExecute) +bool WriteProtectMemory(void* ptr, size_t size, bool allowExecute) { #ifdef _WIN32 DWORD oldValue; if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READ : PAGE_READONLY, &oldValue)) + { PanicAlertFmt("WriteProtectMemory failed!\nVirtualProtect: {}", GetLastErrorString()); + return false; + } #elif !(defined(_M_ARM_64) && defined(__APPLE__)) // MacOS 11.2 on ARM does not allow for changing the access permissions of pages // that were marked executable, instead it uses the protections offered by MAP_JIT // for write protection. if (mprotect(ptr, size, allowExecute ? (PROT_READ | PROT_EXEC) : PROT_READ) != 0) + { PanicAlertFmt("WriteProtectMemory failed!\nmprotect: {}", LastStrerrorString()); + return false; + } #endif + return true; } -void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) +bool UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) { #ifdef _WIN32 DWORD oldValue; if (!VirtualProtect(ptr, size, allowExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE, &oldValue)) + { PanicAlertFmt("UnWriteProtectMemory failed!\nVirtualProtect: {}", GetLastErrorString()); + return false; + } #elif !(defined(_M_ARM_64) && defined(__APPLE__)) // MacOS 11.2 on ARM does not allow for changing the access permissions of pages // that were marked executable, instead it uses the protections offered by MAP_JIT @@ -227,8 +251,10 @@ void UnWriteProtectMemory(void* ptr, size_t size, bool allowExecute) allowExecute ? (PROT_READ | PROT_WRITE | PROT_EXEC) : PROT_WRITE | PROT_READ) != 0) { PanicAlertFmt("UnWriteProtectMemory failed!\nmprotect: {}", LastStrerrorString()); + return false; } #endif + return true; } size_t MemPhysical() |
