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).

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