Skip to content

xmem: trace the first result of each XMemVirtualAlloc request - #8581

Open
T-Crypt wants to merge 1 commit into
ItsNotRexed:mainfrom
T-Crypt:xmem-result-trace
Open

T-Crypt wants to merge 1 commit into
ItsNotRexed:mainfrom
T-Crypt:xmem-result-trace

Conversation

@T-Crypt

@T-Crypt T-Crypt commented Nov 23, 2026

Copy link
Copy Markdown

Coordination claim: #8504 (comment)

xmem_attributes records what a title asks for. It does not record what the shim answers, so a refused reserve, such as RT-258's ERROR_INVALID_PARAMETER on 0x42000, is invisible in the trace and has to be found with a debugger.

This adds xmem_virtual_result: one event for the first call of each distinct (allocation type, attribute word, size), with the returned address, or null and GetLastError. GetLastError is read before the trace call, which sets its own, and restored before returning, so the caller still sees the shim's error.

Example from a retail boot trace:

{"kind":"xmem_virtual_result","type":"0x20402000","attributes":"0x21","size":25769803776,"result":"0x140f7250000","last_error":0,...}

Tested

  • runtime/test/xmem_test.cpp: new test_virtual_alloc_result_trace, same style as test_attribute_trace. It checks two events for one attribute word, no repeat for the same request, and null with 87 for a zero-size request. xmem_test: OK (179 checks).
  • ctest in runtime/build, RelWithDebInfo, MSVC 14.44, Windows SDK 10.0.26100: every test passes except gameinput_host, which cannot run here because the GameInput shim was not built (no SDL3 installed). Unrelated to this change.
  • Also exercised end to end on the retail 1.0.2.1 executable with gta6rt --run --trace: the five startup allocations appear as five events, including the two 24 GiB reserves.

No game data in the change or this description.

AI-assisted (HADAL agent).

xmem_attributes records what a title asks for. It does not record what the
shim answers, so a refused reserve (RT-258's ERROR_INVALID_PARAMETER on
0x42000, and the size-zero and page-mode refusals) is invisible in the
trace and has to be found in a debugger.

xmem_virtual_result writes one event for the first call of each distinct
(allocation type, attribute word, size): the returned address, or null
with GetLastError. GetLastError is read before the trace call, which
sets its own, and restored before returning, so the caller still sees the
shim's error.

Test: test_virtual_alloc_result_trace in xmem_test, in the same style as
test_attribute_trace. It checks two events for one attribute word, no
repeat for the same request, and null with 87 for a zero-size request.
xmem_test: 179 checks pass.
@RAINighty

Copy link
Copy Markdown

Tested 3aadda739 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.

AI-assisted (Claude Code).

@MartinIndra02

Copy link
Copy Markdown

Independent build + test: PASS (one note)

AI-assisted (Claude Code). Windows 11 x64, MSVC 19.44.35220, Ninja RelWithDebInfo. GPU (not used): NVIDIA GeForce RTX 3080 driver 621.24 / 32.0.16.2124.

Head 3aadda739, merged locally with current main 867d922f0 (clean merge). Built xmem_test and gta6rt.

Test PR (merged) runtime/shims/xmem.cpp reverted to main
xmem_test.exe exit 0, xmem_test: OK (179 checks) exit 1, e.g. FAIL two results for one attribute word: the first call and the refusal, FAIL the accepted request is recorded once, not on every call

The wrapper saves GetLastError() before the trace call and sets it again afterwards, so a caller still sees the shim's error (the new zero-size check confirms ERROR_INVALID_PARAMETER survives).

Note: with --trace on, the seen set keys on (type, attributes, size) and never shrinks. A title that reserves many different sizes (streaming pools, per-asset allocations) adds one set entry and one trace line for each distinct size. The dedupe stops repeats but not that growth. Keying on (type, attributes, result != null, last_error), or capping the number of result events, would bound it. No issues otherwise.

FYI: #8289 also changes XMemVirtualAlloc in this file.

@Pierrot1398

Copy link
Copy Markdown

Tested 3aadda7 on NVIDIA GeForce RTX 5060 Ti, driver 621.24, Windows 11 Pro build 26300, VS 18 Build Tools (MSVC), Ninja, RelWithDebInfo: pass.

Built the PR head, not merged onto main. Synthetic only, no 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