From e5e81e1d521c9aff6c2e1d1849d7dc22b4da4968 Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Wed, 21 Jan 2026 21:30:15 -0600 Subject: [PATCH] Properly handle file mmaps with offsets Pretty easy fix to perform while I'm here, so I might as well include it. --- src/core/address_space.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/address_space.cpp b/src/core/address_space.cpp index e6a78fcb2..faa454278 100644 --- a/src/core/address_space.cpp +++ b/src/core/address_space.cpp @@ -242,7 +242,14 @@ struct AddressSpace::Impl { ptr = VirtualAlloc2(process, reinterpret_cast(virtual_addr), size, MEM_RESERVE | MEM_COMMIT | MEM_REPLACE_PLACEHOLDER, PAGE_READWRITE, nullptr, 0); - bool ret = ReadFile(backing, ptr, size, &resultvar, NULL); + + // phys_addr serves as an offset for file mmaps. + // Create an OVERLAPPED with the offset, then supply that to ReadFile + OVERLAPPED param{}; + // Offset is the least-significant 32 bits, OffsetHigh is the most-significant. + param.Offset = phys_addr & 0xffffffffull; + param.OffsetHigh = phys_addr & 0xffffffff00000000ull; + bool ret = ReadFile(backing, ptr, size, &resultvar, ¶m); ASSERT_MSG(ret, "ReadFile failed. {}", Common::GetLastErrorMsg()); ret = VirtualProtect(ptr, size, prot, &resultvar); ASSERT_MSG(ret, "VirtualProtect failed. {}", Common::GetLastErrorMsg());