Skip to content

d3d12_xs: add guarded vtables for DeviceProxy and HeapProxy and refused tail for HeapProxy - #8252

Open
auswhalen999-debug wants to merge 1 commit into
ItsNotRexed:mainfrom
auswhalen999-debug:pr/xs-guarded-vtables
Open

auswhalen999-debug wants to merge 1 commit into
ItsNotRexed:mainfrom
auswhalen999-debug:pr/xs-guarded-vtables

Conversation

@auswhalen999-debug

Copy link
Copy Markdown

Claimed in the coordination issue as: #8047 (comment)

What and why

Queue, fence, and command allocator proxies in runtime/shims/d3d12_xs_device.cpp already place their vtables at the end of page 0 of a 64 KiB VirtualAlloc(..., MEM_RESERVE, PAGE_NOACCESS) guard region backed by table_overrun_handler, and refuse slots past their PC public chain with E_NOTIMPL + a 4-argument first-call log.

DeviceProxy and HeapProxy did not:

  • DeviceProxy kept its vtable in a plain static void* storage[kMaxSlots] buffer, so a vtable read at slot >= kMaxSlots silently read past .bss (often crashing at rip=0 without naming the slot).
  • HeapProxy had only static void* storage[11] — no refused tail and no guard region — so any console descriptor-heap slot >= 11 read unguarded .bss memory with zero diagnostic output.

This change brings DeviceProxy and HeapProxy to parity with the command-object proxies while leaving kMaxSlots = 128, proxy_slot, device_slot_overridden, heap_slot_overridden, heap slot 8, and queue slot 18 untouched:

  • Expands HeapProxy to kHeapPublicSlots = 11, kHeapSlots = 64, refusing slots 11..63 in heap_slot<Slot> with E_NOTIMPL, per-slot hit/first-call tracking, and a 4-argument first-call log matching child_slot.
  • Places both get_vtable() (DeviceProxy) and get_heap_vtable() (HeapProxy) at the end of page 0 of 64 KiB MEM_RESERVE guard regions (protected PAGE_READONLY, with static .bss fallback if reservation fails and SRWLOCK + atomic initialization introducing zero function-local static init guards).
  • Factors report_guarded_table_overrun and registers both device and heap tables in table_overrun_handler, logging [rt] d3d12_xs: <device|heap> slot <N> is past the proxy table; the vtable read faults.
  • Exposes heap_proxy_table_size(), heap_table_overruns(), device_proxy_table_size(), device_table_overruns(), and device_and_heap_tables_guarded() in runtime/shims/d3d12_xs_device.h, and clears device/heap overrun and g_heap_beyond_warned state in reset_device_proxy_stats().
  • Extends runtime/test/xs_proxy_mock_test.cpp with a mock descriptor heap, refused tail tests for heap slots 11..63, synthetic SEH overrun tests at {table, table + 512, table + 7000} for both device and heap tables, reset_device_proxy_stats() overrun reset checks, and device_and_heap_tables_guarded() checks across --fail-virtualalloc, --fail-virtualprotect, and --fail-veh.

Tested

Windows 11 x64, NVIDIA GeForce GTX 1070 (driver 581.80), clang-cl 23.1.6 + lld-link 23.1.6 + Windows SDK 10.0.26100 (RelWithDebInfo, Ninja, 0 compiler warnings in modified files), synthetic tests only (no game data):

  • Negative control (on main dde82f27e before the d3d12_xs_device.{h,cpp} fix): xs_proxy_mock_test.exe failed (read_slot_guarded(dev_vtbl, 128) == EXCEPTION_ACCESS_VIOLATION, exit 1 — unguarded .bss read succeeded without faulting).
  • After fix (69dc8d674):
    • xs_proxy_mock_test.exe (default): PASS (9 allocations refused on purpose, device slots 128/640/7128 and heap slots 64/576/7064 faulted in guard regions and counted, heap tail 11..63 refused with E_NOTIMPL)
    • xs_proxy_mock_test.exe --fail-virtualalloc: PASS (VirtualAlloc refused 5 time(s), tables unguarded, tails refused)
    • xs_proxy_mock_test.exe --fail-virtualprotect: PASS (VirtualProtect refused 5 time(s), tables stay guarded, overruns fault and count)
    • xs_proxy_mock_test.exe --fail-veh: PASS (AddVectoredExceptionHandler refused 1 time(s), tables unguarded, tails refused)
    • xs_proxy_mock_test.exe --env-slots & --env-slots-invalid: PASS
    • device_proxy_test.exe (default & --trace-d3d12): PASS (OK (0 failures))
    • queue_proxy_test.exe: PASS (3 backend(s) passed: WARP + GTX 1070 D3D12 + Vulkan D3D12)
    • allocator_proxy_test.exe: PASS (3 backend(s) passed)
    • scripts/check_no_game_data.py: exit 0; git diff --check: clean; 0 CRLF.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — runtime proxy safety/testing change only, no shader translator changes.)

@ECHOZwei

Copy link
Copy Markdown

Tested 69dc8d6747f14c7a6744ed8dfc2a76184ac6e7ef merged onto origin/main 23060e087 (clean merge) on Windows 11 (MSVC 14.51 / Visual Studio Community 2026, RelWithDebInfo, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1) on two GPUs (synthetic tests only; no game files): pass

  • Built xs_proxy_mock_test, device_proxy_test, queue_proxy_test, and allocator_proxy_test cleanly (0 new warnings).
  • xs_proxy_mock_test.exe across all 6 modes (default, --fail-virtualalloc, --fail-virtualprotect, --fail-veh, --env-slots, --env-slots-invalid): all pass (exit 0).
  • device_proxy_test.exe (default and --trace-d3d12): pass (OK (0 failures)).
  • NVIDIA GeForce RTX 4080 SUPER (driver 621.01, validation on):
    • ctest --test-dir runtime/build -C RelWithDebInfo -R ^(xs_proxy_mock|device_proxy|queue_proxy|allocator_proxy)$ --output-on-failure: 4/4 passed (12.32s), 0 validation errors.
  • AMD Radeon(TM) Graphics iGPU (driver 25.10, LEONIDA_VK_DEVICE=AMD, validation on):
    • ctest --test-dir runtime/build -C RelWithDebInfo -R ^(queue_proxy|allocator_proxy)$ --output-on-failure: 2/2 passed (10.93s), 0 validation errors.
  • git diff --check and python -I scripts/check_no_game_data.py runtime/shims/d3d12_xs_device.cpp runtime/shims/d3d12_xs_device.h runtime/test/xs_proxy_mock_test.cpp: clean (exit 0).
  • Code review: init_guarded_vtable uses SRWLOCK + acquire/release atomics (no function-local static guards), protects page 0 PAGE_READONLY with clean VirtualFree / .bss fallback paths, and logs overruns via WriteFile in the VEH.

AI-assisted.

@lohant27-netizen

Copy link
Copy Markdown

Tested 69dc8d674 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 23060e087 together with #8314, #8252, #8326 and #8270 (no conflicts): pass.

@MartinIndra02

Copy link
Copy Markdown

Independent build + test: PASS

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

Head 69dc8d674, merged locally with current main 0c6ff794c (clean merge).

Test Result
xs_proxy_mock_test.exe exit 0, PASS (9 allocations refused on purpose). Includes the new guarded device/heap table checks (device_proxy_table_size() == 128, heap_proxy_table_size() == 64, heap slots 11-63 refused, the guard region names the slot)
allocator_proxy_test.exe exit 0, 3 backend(s) passed (host WARP, host RTX 3080, Vulkan RTX 3080). The child-table guard still names reads past the table after the report_table_overrun refactor
dxgi_device_test.exe exit 0, 3 backend(s) passed (uses the device proxy and its IDXGIDevice view)

The new test can't be run against main (it uses device_proxy_table_size / heap_proxy_table_size, which main doesn't have, and gets C2039 there), so I didn't do a fail-without-fix run.

Notes:

  • The device and heap tables are now PAGE_READONLY. Nothing in runtime/shims writes into get_vtable()[...] / get_heap_vtable()[...] after the fill, so that's safe today.
  • d3d12_xs: a device forward refuses a 'this' that is not the proxy #7923 adds a self->vtable != get_vtable() check in the device forward path. Both PRs touch the same function area, and with this PR get_vtable() becomes an acquire load plus a branch, which is fine on that path. Whichever merges second should be rebuilt and retested together.

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