Skip to content

xmem: a commit of a 64 KiB-page reservation succeeds instead of failing (EGEN-XMEM-COMMIT-PLACEHOLDER) - #8599

Open
evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/2-xmem-commit-placeholder
Open

evilclanker9000 wants to merge 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/2-xmem-commit-placeholder

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Item: EGEN-XMEM-COMMIT-PLACEHOLDER (claimed in #8344: #8344 (comment))

XMemVirtualAlloc backs every reserve-only guest page-mode range with a Windows placeholder (#6919), and Windows refuses a commit inside a placeholder. The retail executable's own measured calls reserve a 64 KiB-page range and commit it later at the same address (docs/xmem_exe_calls.md: allocation_type 0x20402000 with attributes 0x21, then 0x20401000 with attributes 0x283, one site each). On main that pair now fails: the reserve succeeds and the commit returns NULL with ERROR_INVALID_ADDRESS (487). Before #6919 the reserve was a plain VirtualAlloc reservation, so the commit worked.

The fix splits the committed range out of its placeholder and replaces it with a committed allocation at the same address (VirtualAlloc2 with MEM_REPLACE_PLACEHOLDER | MEM_RESERVE), and cuts that range out of the physical-page window table, so a later page map cannot target committed memory. A commit that does not name a reserved window goes through the unchanged VirtualAlloc path.

Tested

Windows 11, MSVC 14.44 (BuildTools 2022), /MD /O2 with the repository's /W4 /permissive-, upstream/main b763516e8 (before) and this branch (after). No GPU needed.

A scratch driver calls the registered shim exactly as an import does, rt::shims::find("xmem.dll", "XMemVirtualAlloc"), with the measured shapes (driver kept out of the repository):

Before (runtime/shims/xmem.cpp at b763516e8):

PASS reserve 0x20402000 attrs 0x21
FAIL commit the reservation with 0x20401000 -> 0000000000000000 (err 487)
probe: 1 failure(s)

After:

PASS reserve 0x20402000 attrs 0x21
PASS commit the reservation with 0x20401000 -> 000001F70B900000 (err 0)
probe: 0 failure(s)

The same driver also calls every measured XMemVirtualAlloc shape and the 185 MiB MEM_RESERVE_PLACEHOLDER carve; all pass before and after.

runtime/test/xmem_test.cpp, compiled against runtime/shims/xmem.cpp + registry.cpp (the new checks):

# xmem.cpp at b763516e8
FAIL a later commit of that range succeeds at its address
xmem_test: FAILED (176 checks, 1 failure)

# this branch
xmem_test: OK (178 checks)

The rest of xmem_test is unchanged and still covers the physical-page windows: a window stays reserve-only, pages map into it, and the remainder of a carved placeholder is still reserved.

First stop that remains: docs/retail_boot_chain.md's stop 13 (the descriptor heap handle right after CreateDescriptorHeap), which is the D3D12 layer's, not imports. I could not run the retail executable here (no network-isolated run available, and the boot page asks for the network off); the command that would verify this pair at boot is the --run in docs/boot.md with --trace and --trace-d3d12, looking for an xmem_attributes event for 0x20401000 and no int3 in the allocator.

No game data: the diff holds public SDK constants and the two call shapes already recorded in docs/xmem_exe_calls.md; python -I scripts/check_no_game_data.py on both files is clean.

AI-assisted: yes.

Tag: SHAYDERRR

@LocranKing

Copy link
Copy Markdown
Contributor

Tested c81559b9b on Windows 11 Build 26200 (RTX 3060 Ti / driver 621.01, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~): pass

  • git diff --check HEAD~1..HEAD: clean
  • scripts\build_runtime.ps1: exit 0 (built gta6rt.exe, 0 new warnings in xmem.cpp / xmem_test.cpp)
  • runtime\build\xmem_test.exe: OK (178 checks), exit 0 (including the 64 KiB-page reserve + commit-in-place checks)
  • ctest --test-dir runtime/build -C RelWithDebInfo -R "^xmem$" --output-on-failure: 1/1 Passed (0.03 sec)

AI-assisted. No game files.

@lohant27-netizen

Copy link
Copy Markdown

Tested c81559b9b on Windows 11 (10.0.26300), NVIDIA GeForce RTX 5070 (driver 32.0.16.2101, subgroup 32), MSVC with SDK 10.0.26100, Release, merged onto main 867d922f0 together with #8599, #8589, #8591, #8620, #8569 and #8622 (no conflicts): pass.

@RAINighty

Copy link
Copy Markdown

Tested c81559b9b merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Intel Core i7-14650HX, MSVC 19.44.35228, RelWithDebInfo (Ninja), CPU-only tests: pass.

  • xmem passes with this PR.
  • Negative control: this PR's xmem_test.cpp with main's runtime/shims/xmem.cpp fails, so the new test does catch the change.
  • Overlap: xmem: trace the first result of each XMemVirtualAlloc request #8581 also edits xmem.cpp and xmem_test.cpp; the two merge together without a textual conflict (I did not build the combination).
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Game-copy check of this commit, same command before and after, AI-assisted. No game data is quoted (outcomes only).

Environment: Windows 11 x64, MSVC 19.44.35207 (VS 2022 BuildTools), Ninja RelWithDebInfo, -DLEONIDA_SDL3=ON, no Vulkan headers (so the Vulkan D3D12 device is left out). Built only the gta6rt target from this branch (c81559b9b, one commit on main 867d922f0).

gta6rt.exe --run <copy>\game_scarlett_master.exe --game-dir <copy> --overlay <scratch> --trace <scratch>\run.json

Both runs map and bind the same 5 modules (20 unimplemented imports) and reach the title's first five XMemVirtualAlloc shapes (the 2 x 24 GiB reserves, 1.2 GiB, 2.3 GiB at attributes 0x283, 20 MiB at 0x181).

  • main 867d922f0, 3 runs: 2 stopped in the title's init callback immediately after those calls (the callback's error branch is an int3, exception 0x80000003); 1 run got past it and stopped at a virtual call through an invalid interface pointer (0xc0000005) in a static initializer reached through ucrtbase!_initterm.
  • This commit, 2 runs: both got past the init callback and stopped at that same invalid-interface-pointer call in the static initializer (0xc0000005, twice).

So on this machine the title's memory init no longer returns the failure that traps in the init callback with this commit; the next stop is the static-initializer virtual call, which main also reaches sometimes. Two runs are not a distribution, but a single run on main traps 2 times in 3, so please do not A/B a boot change here with one run.

Other observation, unrelated to this diff: the loader maps, binds, installs TLS for and relocates every packaged Xbox DLL in that copy (--dry-run of the FidelityFX upscaler and XCurl.dll included: 0 unimplemented imports), so the boot is not being stopped by PE mapping any more.

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Correction to my comment above, AI-assisted: the "main" runs in it used a local build from a working tree 166 commits behind main, so the int3 stop it reports is a stop of that older build, not of main 867d922f0. Please disregard the causal reading; the numbers below are from a fresh build of each side (cmake --build ... --target gta6rt, Ninja RelWithDebInfo, same flags, only the gta6rt target).

Same command, 3 runs each, stop = the last event the trace records during the title's start-up:

  • main 867d922f0: 2 of 3 stop at a virtual call through an invalid interface pointer (0xc0000005; the pointer is -1 in both), in a static initializer reached through ucrtbase!_initterm. 1 of 3 logged no stop within 14 s.
  • this commit c81559b9b: 3 of 3 stop at that same virtual call (pointer -1, -1, 0xd).

So on this machine this diff neither moves nor causes the first stop: both sides stop inside the same static initializer, and the invalid pointer differs between runs anyway. The title's five XMemVirtualAlloc shapes complete on both sides.

Also, a single run cannot separate a boot change here: the same binary stops at that call in one run and keeps going past 14 s in another.

dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…tion succeeds instead of failing (EGEN-XMEM-COMMIT-PLACEHOLDER)

Squashed from ItsNotRexed#8599 by evilclanker9000, head c81559b (security scan PASS).

Takes the place of ItsNotRexed#8289 (orchestrator's swap), applied as the PR's own diff (gh pr diff); Haiku PASS at c81559b. Conflict with Wave 1's xmem work: this PR's commit-into-window check runs ahead of the large-page reservation branch, which keeps Wave 1's (large_pages || aligned_reservation) condition rather than this PR's older page_mode test.
dadnotdaddy pushed a commit to dadnotdaddy/Leonida that referenced this pull request Nov 23, 2026
…s Wine's PAGE_READWRITE

The commit-into-window path asks the host for PAGE_READWRITE | PAGE_WRITECOMBINE (the console graphics bit dropped). Wine accepts the request but reports the committed region as plain PAGE_READWRITE, the same Wine behaviour d3d12_existing_heap's write-combine check meets; on Windows the check still requires the write-combine bit. The commit itself succeeding at its address and the range being writable are checked unchanged.
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