From ead180aa601eaa9620c06b9bfffc66a51e247421 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sun, 10 Jan 2021 20:26:17 +0300 Subject: [PATCH] win32: Be a bit more optimistic with allocated ranges; we get contiguous ranges more often than not --- rpcs3/util/vm_native.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rpcs3/util/vm_native.cpp b/rpcs3/util/vm_native.cpp index 681bc298c4..a6f2fbd869 100644 --- a/rpcs3/util/vm_native.cpp +++ b/rpcs3/util/vm_native.cpp @@ -221,12 +221,18 @@ namespace utils void memory_protect(void* pointer, usz size, protection prot) { #ifdef _WIN32 + + DWORD old; + if (::VirtualProtect(pointer, size, +prot, &old)) + { + return; + } + for (u64 addr = reinterpret_cast(pointer), end = addr + size; addr < end;) { const u64 boundary = (addr + 0x10000) & -0x10000; const u64 block_size = std::min(boundary, end) - addr; - DWORD old; if (!::VirtualProtect(reinterpret_cast(addr), block_size, +prot, &old)) { fmt::throw_exception("VirtualProtect failed (%p, 0x%x, addr=0x%x, error=%#x)", pointer, size, addr, GetLastError());