texture_cache: protection flags re-worked

* actually I gave up on clang fmt
This commit is contained in:
psucien 2024-04-28 00:57:30 +02:00
parent d2c53d0fde
commit 249373bf0d
1 changed files with 4 additions and 7 deletions

View File

@ -12,14 +12,11 @@
#include <signal.h> #include <signal.h>
#include <sys/mman.h> #include <sys/mman.h>
#define PROT_READ_WRITE #define PAGE_NOACCESS PROT_NONE
(PROT_READ | PROT_WRITE) // There is no option to combine bitflags like this on Windows #define PAGE_READWRITE (PROT_READ | PROT_WRITE)
#else #else
#include <Windows.h> #include <Windows.h>
#define PROT_NONE PAGE_NOACCESS
#define PROT_READ_WRITE PAGE_READWRITE
void mprotect(void* addr, size_t len, int prot) { void mprotect(void* addr, size_t len, int prot) {
DWORD old_prot{}; DWORD old_prot{};
BOOL result = VirtualProtect(addr, len, prot, &old_prot); BOOL result = VirtualProtect(addr, len, prot, &old_prot);
@ -228,9 +225,9 @@ void TextureCache::UpdatePagesCachedCount(VAddr addr, u64 size, s32 delta) {
const u32 interval_size = interval_end_addr - interval_start_addr; const u32 interval_size = interval_end_addr - interval_start_addr;
void* addr = reinterpret_cast<void*>(interval_start_addr); void* addr = reinterpret_cast<void*>(interval_start_addr);
if (delta > 0 && count == delta) { if (delta > 0 && count == delta) {
mprotect(addr, interval_size, PROT_NONE); mprotect(addr, interval_size, PAGE_NOACCESS);
} else if (delta < 0 && count == -delta) { } else if (delta < 0 && count == -delta) {
mprotect(addr, interval_size, PROT_READ_WRITE); mprotect(addr, interval_size, PAGE_READWRITE);
} else { } else {
ASSERT(count >= 0); ASSERT(count >= 0);
} }