vm: Fix memory mirror performance regression

This commit is contained in:
kd-11 2018-07-14 14:51:41 +03:00 committed by kd-11
parent c35d0d16e7
commit 46abe0f315

View file

@ -107,18 +107,17 @@ namespace utils
#ifdef _WIN32 #ifdef _WIN32
for (u64 addr = (u64)pointer, end = addr + size; addr < end;) for (u64 addr = (u64)pointer, end = addr + size; addr < end;)
{ {
// Query current region const u64 boundary = (addr + 0x10000) & -0x10000;
::MEMORY_BASIC_INFORMATION mem; const u64 block_size = std::min(boundary, end) - addr;
verify(HERE), ::VirtualQuery((void*)addr, &mem, sizeof(mem));
DWORD old; DWORD old;
if (!::VirtualProtect(mem.BaseAddress, std::min<u64>(end - (u64)mem.BaseAddress, mem.RegionSize), +prot, &old)) if (!::VirtualProtect((LPVOID)addr, block_size, +prot, &old))
{ {
fmt::throw_exception("VirtualProtect failed (%p, 0x%x, addr=0x%x, error=%#x)", pointer, size, addr, GetLastError()); fmt::throw_exception("VirtualProtect failed (%p, 0x%x, addr=0x%x, error=%#x)", pointer, size, addr, GetLastError());
} }
// Next region // Next region
addr = (u64)mem.BaseAddress + mem.RegionSize; addr += block_size;
} }
#else #else
verify(HERE), ::mprotect((void*)((u64)pointer & -4096), ::align(size, 4096), +prot) != -1; verify(HERE), ::mprotect((void*)((u64)pointer & -4096), ::align(size, 4096), +prot) != -1;