Skip to content

d3d12_xs: the device proxy table reaches console slot 133 instead of jumping to address 0 (RT-5) - #7183

Closed
sneylol wants to merge 1 commit into
ItsNotRexed:mainfrom
sneylol:d3d12-xs-device-slots-256
Closed

sneylol wants to merge 1 commit into
ItsNotRexed:mainfrom
sneylol:d3d12-xs-device-slots-256

Conversation

@sneylol

@sneylol sneylol commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: #6910 (comment) (new D3D item, RT-5)

Depends on: none (applies to main b66e184, which includes #6935).

Problem

The device proxy's vtable has kMaxSlots = 128 entries. The retail executable (1.0.2.1, measured under gta6rt --run) calls device slot 133 during startup. It passes the address of a range it mapped through the physical-page calls, a buffer D3D12_RESOURCE_DESC, 0xffffffff, null, IID_ID3D12Resource and an output. That reads past the end of the proxy's static table, finds a null pointer and jumps to address 0 (rip = 0, return address in the title). The proxy already has the right answer for a console method past the PC device, refuse_beyond_device (E_NOTIMPL, logged once), but the table never reaches it.

Fix

  • kMaxSlots 128 → 256, with the static_assert raised to cover the measured slot 133 and a comment saying why.
  • device_proxy_test calls slots 128, 133 and 255 through raw function pointers and expects a non-null entry, E_NOTIMPL and a null output.

What slot 133 should really do (the console's unified memory: a GPU buffer over memory the title mapped itself) is not in this PR. It's a design question for D3D-546 / docs/d3d12_vulkan.md §3.3, written up in #313: #313 (comment)

Tested

Windows 11 26200, RX 9070 XT, MSVC 14.44 RelWithDebInfo:

No game data, bytes or traces are included. AI-assisted (Claude Code).

🤖 Generated with Claude Code

The retail executable calls device slot 133 during startup (a buffer placed
at an address the title mapped). The proxy's table had 128 entries, so that
call read past the end of the table, found a null pointer and jumped to
address 0, instead of reaching refuse_beyond_device's E_NOTIMPL.

The table now has 256 entries. device_proxy_test calls slots 128, 133 and
255 and expects the refusal with a null output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dadsmallbuk1

Copy link
Copy Markdown

Heads-up: #6953 (@Pipodi, opened earlier today) makes the same change: kMaxSlots raised past 133 in runtime/shims/d3d12_xs_device.cpp, with an xs_proxy_mock_test check that slot 133 is refused with E_NOTIMPL. It passed here on an RTX 5090 (4/4 xs_proxy_mock). The two will conflict on the same constant; could you compare and keep one?

AI-assisted (Claude Code).

@tikD1337

Copy link
Copy Markdown
Contributor

Still on the PR #7183 review: I've checked the proxy table code paths against the diff, and here's the review body.

Review: d3d12_xs device proxy table extended to 256 slots (RT-5)

Environment: Windows 11, CPython 3.13; runtime built with MSVC (cmake -S runtime -B runtime/build, RelWithDebInfo).

What changed

kMaxSlots in runtime/shims/d3d12_xs_device.cpp goes from 128 to 256. The static_assert now guards the measured console slot 133 instead of the PC ID3D12Device14 count (83). device_proxy_test calls slots 128, 133 and 255 through the proxy vtable and expects E_NOTIMPL with the output left untouched.

Why the fix is correct

The root cause and the fix agree with the code:

  • Root cause. get_vtable() (d3d12_xs_device.cpp:1585) backs the proxy vtable with static void* storage[kMaxSlots]. The title indexes the vtable directly, so slot 133 read 40 bytes past a 128-entry array into whatever static data follows. That was zero, so the title called address 0. Nothing on our side could catch this at call time, because the read happens in the title's own code. Making the table larger is the only fix that works inside the proxy.

  • The new slots refuse correctly. fill_vtable creates a proxy_slot<I> for every I < kMaxSlots. Slots 128–255 match none of the if constexpr overrides, so they go to the generic branch:

    • note_slot(Slot) is bounded by kMaxSlots (line 159).
    • The Xbox route checks (frame_interval/schedule_event/wait_event/queue_x/list_x, defaults 78/79/80/48/73) can't match, because env_device_slot limits them to 3..127.
    • Slot >= self->slot_count then reaches refuse_beyond_device (line 1126), which returns E_NOTIMPL and logs once per slot through g_beyond_warned[slot].

    The real PC vtable is never indexed past slot_count, so the larger table can't cause an out-of-bounds read on the PC side.

  • The per-slot state grows with the table. g_hits, g_first, g_beyond_warned (lines 88–90), the logged[kMaxSlots] array at line 230 and the reset_device_proxy_stats() loop (line 1842) are all sized by kMaxSlots. None of them still assumes 128 entries.

  • Cost. The change adds 128 more proxy_slot<> template instances: about 1 KB more static table and a little more code. That is negligible.

Test

The new block calls each slot with the proxy as this, which is correct because the title also calls through the proxy. It passes &out in the sixth position and checks that the refusal leaves it null. That is a fair check that the generic branch writes nothing. Slot 255 covers the last entry of the table and slot 128 covers the old boundary.

One minor point: these calls come before the hit-counter section. Under the counter semantics, the first-call flags for 128/133/255 are set and their hit counts are not. No later assertion reads those slots, so this is harmless. If someone adds a hit-count check for a console slot later, it should go after reset_device_proxy_stats().

Limitations and follow-ups (none of them block this PR)

  1. 256 is spare room, not a measurement. A title call at slot ≥ 256 would fail the same way as before. The comment and the static_assert say this clearly enough. If the startup log ever shows a "beyond the PC device vtable" line near 255, the table needs to grow again.
  2. The env route override still stops at 127. env_device_slot (d3d12_xs_device.cpp:191) rejects values outside 3..127, and docs/d3d12_vulkan.md:3435 documents the same range. Once slot 133 is identified, it can't be routed through LEONIDA_XS_*_SLOT without widening that range to kMaxSlots - 1. That could be a one-line follow-up here, or a finding: in the coordination issue.
  3. Slot 133 isn't recorded as an unknown method. It is now refused silently apart from the one log line. A short note in docs/xbox_d3d12_xs.md would help: say that slot 133 is called at startup, that it is not yet identified, and that it currently returns E_NOTIMPL. That way whoever works out its signature knows startup currently continues past a refusal. The description says the slot was measured under gta6rt --run without quoting any log, which is the right call under the no-game-data rule.

Verification (no game files needed)

Check Result
git diff --check PASS
python -m compileall -q make_game.py tools tests PASS
python -I scripts/check_no_game_data.py on the changed files PASS
python -I make_game.py --help PASS
Targeted Python tests none apply (C++-only change)

The checks above don't build or run device_proxy_test. Before merging, please run:

cmake --build runtime/build --config RelWithDebInfo
ctest --test-dir runtime/build -C RelWithDebInfo -R device_proxy --output-on-failure

The test runs on WARP, so any Windows machine works. It exits 77 (skip) under Wine. Please put the result and the machine in the PR description.

Adherence

  • No game data: none. The diff is C++ source and a hand-written test. The retail slot number appears as a measured fact, not as a log excerpt or binary content.
  • No keys, decryption or protection workarounds: none. The change only touches how the vtable is filled.
  • Nothing online: no network code or services touched.
  • Fix, don't disable: met. The crash is replaced by the documented refusal path (E_NOTIMPL plus a one-time log line); no slot is skipped or hidden. The translator contract table in docs/design.md doesn't apply because this is not a translator rule.

Verdict: Approve once the device_proxy_test ctest result is posted. Follow-ups 2 and 3 can be separate findings.

AI-assisted.

@sneylol

sneylol commented Nov 23, 2026

Copy link
Copy Markdown
Author

Retail-executable confirmation (one run; own 1.0.2.1 copy, Windows 11, RX 9070 XT, LEONIDA_D3D12=vulkan): on an integration of main 8575d36 with #6919, #6964, #4313, #6582, #4348, #7076 and this PR, with no local stand-ins, the title reaches device slot 133 after its 581 command lists and its physical-page maps. With this PR the call logs device slot 133 (forwarded) is beyond the PC device vtable (80 slots); returning E_NOTIMPL, and the title reports the failure through its own assert (0x80000003). Without it, the same call jumps to address 0. Details of what slot 133 asks for: #313 (comment). AI-assisted (Claude Code).

@sneylol

sneylol commented Nov 23, 2026

Copy link
Copy Markdown
Author

Closing as a duplicate of #6953 (@Pipodi), which covers slot 133 the same way and was opened first. The retail confirmation above applies to it equally: with the table reaching 133, the title gets a logged E_NOTIMPL there instead of a jump to address 0. I'll test the slot 133 implementations (#7218, #7075) on the retail executable next. 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.

3 participants