Skip to content

xmem: the title never commits inside a window, and the 64 KiB shift holds at the unmap sites - #7799

Open
bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:xmem-physical-pages
Open

bobcatchris wants to merge 1 commit into
ItsNotRexed:mainfrom
bobcatchris:xmem-physical-pages

Conversation

@bobcatchris

Copy link
Copy Markdown
Contributor

The last two tools/exe_checklist.py lines that waited on the executable are runtime/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. VirtualAlloc never lands in a window. The image imports VirtualAlloc, VirtualFree and VirtualQueryEx from api-ms-win-core-memory-l1-1-0.dll, and referencing those IAT slots directly from .text (no thunk exists for them) gives: VirtualAlloc 1 reference, VirtualFree 23 calls + 1 tail jump + 1 pointer load, VirtualQueryEx 1. The single call site is RVA 0x2216459:

142216427: xorl %ecx, %ecx        ; lpAddress = null
142216429: movl $0x3000, %r8d     ; MEM_COMMIT | MEM_RESERVE
14221642f: movl $0x4, %r9d        ; PAGE_READWRITE
142216459: callq *0x457d609(%rip) ; VirtualAlloc

A null lpAddress commits 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 XMemFreePhysicalPages sites show no shr $0x10. That was a bug in my scan — an inverted comparison (s - c instead of c - s), not a property of the image — and I re-measured it properly: 19 of the 21 physical-page call sites have a shr $0x10 within 0x800 bytes before the call (4 of 4 allocate, 12 of 12 map, 3 of 3 free). Four shifts in a row at RVA 0x24730da..0x24730de feed the calls at 0x24730e9..0x247311f, and add $0xffff then shr $0x10 at 0x2216435..0x221643f rounds a byte size up to pages before XMemAllocatePhysicalPages at 0x2216493. The two XMemMapPhysicalPagesScatter sites 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, and flags still means nothing to the shim.

Checks. tools/exe_checklist.py: 14 items in this tree (16 on main), with both xmem lines gone. tests/test_exe_checklist.py OK. 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.

…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.
@MartinIndra02

Copy link
Copy Markdown

AI-assisted review/test.

PASS on commit �0f6610f0fee8160107fcdb9f1b43e5367ea4059.

  • Environment: Windows 11 x64, MSVC 19.44.35220, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.1, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124 / 621.24).
  • Build: cmake --build --target xmem_test (Ninja, RelWithDebInfo) — succeeded cleanly.
  • Test: xmem_test.exe — OK (173 checks).

@bobcatchris

Copy link
Copy Markdown
Contributor Author

Correction to the checks line in the description: the counts were inferred when I wrote it, not measured after main moved. Measured: 17 items on origin/main, 15 in this branch (both xmem lines gone). The 16 -> 14 in the description and the commit message is off by one; nothing else in either changes. AI-assisted.

@Kerwinss

Copy link
Copy Markdown

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 -DLEONIDA_VULKAN_HEADERS_FETCH=ON: pass, no regression (Merged onto main 867d922 (clean), full runtime build, ctest -C RelWithDebInfo -j4: 237/239, the two failures are main's own on this GPU (d3d12_depth_resolve, #7985; d3d12_vulkan_device:6574); xmem passes). The change is comments and docs only.

One concern about content, not code: the new comments in runtime/shims/xmem.cpp and the lines added to docs/xmem_exe_calls.md quote executable addresses (RVA 0x2216459, 0x24730da..0x24730de, 0x24730e9..0x247311f, 0x2216435..0x221643f). main has none of these in either file. The boot-chain issue's rule 2 (#7154) says no "bytes, addresses, offsets, RVAs, strings, logs or dumps from the executable" ("counts are fine"). The same findings would read the same with the counts only ("one VirtualAlloc call site, null address, MEM_COMMIT | MEM_RESERVE"; "19 of 21 physical-page call sites shift by 16 before the call"), so I'd drop the RVAs.

AI-assisted (Claude Code). No game files.

@BeetjeMatig

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants