Skip to content

Commit

Permalink
vm: Fix memory mirror performance regression
Browse files Browse the repository at this point in the history
  • Loading branch information
kd-11 committed Jul 14, 2018
1 parent c35d0d1 commit 46abe0f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Utilities/VirtualMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,17 @@ namespace utils
#ifdef _WIN32
for (u64 addr = (u64)pointer, end = addr + size; addr < end;)
{
// Query current region
::MEMORY_BASIC_INFORMATION mem;
verify(HERE), ::VirtualQuery((void*)addr, &mem, sizeof(mem));
const u64 boundary = (addr + 0x10000) & -0x10000;
const u64 block_size = std::min(boundary, end) - addr;

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());
}

// Next region
addr = (u64)mem.BaseAddress + mem.RegionSize;
addr += block_size;
}
#else
verify(HERE), ::mprotect((void*)((u64)pointer & -4096), ::align(size, 4096), +prot) != -1;
Expand Down

0 comments on commit 46abe0f

Please sign in to comment.