Repository navigation
xmem: the title never commits inside a window, and the 64 KiB shift holds at the unmap sites - #7799
bobcatchris wants to merge 1 commit into
Conversation
…olds at the unmap sites Two more `runtime/shims/xmem.cpp` assumptions settled against the retail executable. **VirtualAlloc cannot land in a window.** The image has exactly one VirtualAlloc call (RVA `0x2216459`, through the api-ms-win-core-memory-l1-1-0 import slot) and it passes a null address with `MEM_COMMIT | MEM_RESERVE` (0x3000) and PAGE_READWRITE, so it commits fresh address space rather than a reserved window. The rest of that import block is 23 VirtualFree call sites (plus one tail jump through the same slot) and one VirtualQueryEx, all on memory the title allocated itself. **The 64 KiB unit is measured at the unmaps too.** An earlier report of mine said the map sites show no shift by 16; that was a bug in my scan (an inverted comparison), not in the image. Re-measured, 19 of the 21 physical-page call sites have a `shr $0x10` within 0x800 bytes before the call — 4 of 4 `XMemAllocatePhysicalPages`, 12 of 12 `XMemMapPhysicalPages`, 3 of 3 `XMemFreePhysicalPages` — including four shifts in a row at RVA `0x24730da`..`0x24730de` ahead of the calls at `0x24730e9`..`0x247311f`, and `add $0xffff` then `shr $0x10` at `0x2216435`..`0x221643f`. The two `XMemMapPhysicalPagesScatter` sites pass a count already in pages (one read from a global, one counted in a loop), so no byte size is shifted there. The attribute word is still not decoded: the 23 reservations use the 64 KiB page mode at 17 sites, the 2 MiB mode at 5, and no page mode at 1. `docs/xmem_exe_calls.md` said the page unit was inferred from the shift and the page mode; it now records the measurement with the RVAs. `tools/exe_checklist.py` goes 16 items to 14 in this tree. AI-assisted.
|
AI-assisted review/test. PASS on commit �0f6610f0fee8160107fcdb9f1b43e5367ea4059.
|
|
Correction to the checks line in the description: the counts were inferred when I wrote it, not measured after |
|
Tested a0f6610 on Windows 11 Pro 10.0.26300, MSVC 14.51 (VS Build Tools 2026), Windows SDK 10.0.26100, NVIDIA GeForce RTX 4060 / 621.24, Khronos Vulkan headers via One concern about content, not code: the new comments in AI-assisted (Claude Code). No game files. |
|
Tested a0f6610 (head of this PR) on RTX 5070 Ti (Blackwell, subgroup 32), NVIDIA 621.01, Windows 11, MSVC 14.44 (VS 2022 17.14 Build Tools), CMake 4.5.1 + Ninja, Vulkan headers sdk-1.4.363.0 (fetched), no game copy: pass (CPU-side check only). I applied the diff (runtime/shims/xmem.cpp and docs/xmem_exe_calls.md) to a clone of main at dfe4e4a (clean git apply), built xmem_test and ran it: exit 0, "xmem_test: OK (173 checks)". The PR adds no test, and unmodified main gives the same exit 0 (xmem_test also passes with the shim reverted), so this shows no regression rather than a verified fix. I did not exercise the title-never-commits-inside-a-window behaviour, which needs the game. AI-assisted (Claude Code): checked by applying the diff to a private clone of main and building and running the tests above. No game data was used. |
The last two
tools/exe_checklist.pylines that waited on the executable areruntime/shims/xmem.cpp:236(does the title commit inside a physical-page window?) and:496(is the page unit 64 KiB?). Both are now measured, one settling the assumption and one correcting a doc sentence.1.
VirtualAllocnever lands in a window. The image importsVirtualAlloc,VirtualFreeandVirtualQueryExfromapi-ms-win-core-memory-l1-1-0.dll, and referencing those IAT slots directly from.text(no thunk exists for them) gives:VirtualAlloc1 reference,VirtualFree23 calls + 1 tail jump + 1 pointer load,VirtualQueryEx1. The single call site is RVA0x2216459:A null
lpAddresscommits fresh address space, so no window can be committed into — the placeholder rule the shim implements is never exercised by this title.2. The 64 KiB shift is at the unmap sites. I reported last round that the three
XMemFreePhysicalPagessites show noshr $0x10. That was a bug in my scan — an inverted comparison (s - cinstead ofc - s), not a property of the image — and I re-measured it properly: 19 of the 21 physical-page call sites have ashr $0x10within 0x800 bytes before the call (4 of 4 allocate, 12 of 12 map, 3 of 3 free). Four shifts in a row at RVA0x24730da..0x24730defeed the calls at0x24730e9..0x247311f, andadd $0xffffthenshr $0x10at0x2216435..0x221643frounds a byte size up to pages beforeXMemAllocatePhysicalPagesat0x2216493. The twoXMemMapPhysicalPagesScattersites pass a count that is already in pages (one loaded from a global, one counted in a loop), so there is nothing to shift there.So
docs/xmem_exe_calls.md's "the code that unmaps shifts byte sizes right by 16" holds, and its "the page unit looks like 64 KiB … that is inferred" becomes measured. What stays open is only the attribute word: the 23 reservations use the 64 KiB page mode (0x20400000) at 17 sites, the 2 MiB mode (0x20000000) at 5 and no page mode at 1, andflagsstill means nothing to the shim.Checks.
tools/exe_checklist.py: 14 items in this tree (16 onmain), with both xmem lines gone.tests/test_exe_checklist.pyOK. Comments and one doc page — no code path moves, so no rebuild was run for it.RVAs, constants and register names only, no game data.
AI-assisted.