Skip to content

[upstream #936] D3D12.X: register x64 .pdata unwind info for stub and guard thunks - #158

Closed
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/936
Closed

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/936

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Registers x64 .pdata (UNWIND_INFO + RUNTIME_FUNCTION via RtlAddFunctionTable) for the RWX thunks emitted by stubs::make_stub_info and d3d12x::guard::thunk, matching what guard::make_call_tracer already does.

Without .pdata, Windows RtlLookupFunctionEntry treats those thunks as leaf functions even though make_stub_info adjusts rsp (sub rsp, 0x28) and guard::thunk pushes rcx/rdx/r8/r9 and allocates 0x68 bytes before calling into Rust. That breaks eh::unwind (eh::dump_threads) and SEH/C++ unwinding whenever a stub hook or guard callback is on the stack.

What is in it

  • crates/xcl/src/stubs.rs: extract alloc_code_with_unwind (appends 4-byte-aligned UNWIND_INFO + RUNTIME_FUNCTION, flushes icache, calls RtlAddFunctionTable) and use it in make_stub_info (UWOP_ALLOC_SMALL for sub rsp, 0x28); add live-stack RtlVirtualUnwind test (stub_thunk_unwinds_through_pdata_to_its_caller).
  • crates/xcl/src/hle/d3d12x/guard.rs: reuse stubs::alloc_code_with_unwind in make_call_tracer and register unwind info for thunk (sub rsp, 0x68 + push r9/r8/rdx/rcx, ending right before the tail jump once the stack is restored to leaf state); add live-stack RtlVirtualUnwind test (guard_thunk_unwinds_through_pdata_to_its_caller).

Tested

  • Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (16337 MiB VRAM, driver 32.0.21045.29003), rustc 1.100.0 (x86_64-pc-windows-msvc), DXC 1.9.2602.17 (debug for tests, release for smoke runs).
  • XCL_REQUIRE_GPU=wave64,mesh + cargo test --workspace --no-fail-fast -- --test-threads=4 on 9a1e188: 715 passed, 3 failed, 41 ignored, 0 GPU skipped (xcl lib: 674 passed / 3 failed / 21 ignored; integration/e2e: 41 passed / 0 failed / 20 ignored; XCL_SAMPLE_* unset).
    • Both new live unwind tests (stubs::tests::stub_thunk_unwinds_through_pdata_to_its_caller and hle::d3d12x::guard::tests::guard_thunk_unwinds_through_pdata_to_its_caller) pass.
    • The 3 failures are exclusively the pre-existing AMD RDNA2 packed-mip failure in placed_title_textures_share_vram_and_preserve_pixels (3D 64x64x64 4 mips: subresource 2 mismatch, failing identically on unmodified main and fixed by open PR D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them xcl-dev/xcl#470) plus its 2 VRAM_TEST_LOCK PoisonError cascades (transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory, which pass when run individually).

Regression run
Both runs below used the same warmed shader/PSO cache on YouKnowWho (60 s):

main (09940bb87fa1):

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 405 (PresentX 405)
presents per 2 s (last 3): 11 12 11
device removals: 0
crashes: 0
peak commit: 15870 MB

PR head (9a1e18804c89):

xcl-smoke v1
commit: 9a1e18804c8903c77f2de6251b855ee41e8dce57
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 370 (PresentX 370)
presents per 2 s (last 3): 9 9 9
device removals: 0
crashes: 0
peak commit: 15874 MB

Not tested

  • Sample-data tests (XCL_SAMPLE_* unset).
  • C++ exception throwing through a live title stub/guard frame (unwinding verified via RtlCaptureContext + RtlLookupFunctionEntry + RtlVirtualUnwind).

AI use

  • Implemented, tested, and verified with Antigravity (Gemini 4 Neon); every change and test result reviewed by the author on local hardware.

Mirror of xcl-dev#936 (auto-synced, do not edit).

guard::make_call_tracer already appended UNWIND_INFO + RUNTIME_FUNCTION and
called RtlAddFunctionTable, but stubs::make_stub_info (sub rsp, 0x28) and
guard::thunk (push rcx/rdx/r8/r9; sub rsp, 0x68) did not. Without .pdata,
RtlLookupFunctionEntry treats those thunks as leaf functions and breaks
eh::unwind / SEH / C++ unwinding whenever a stub hook or guard callback is
on the stack.

Extract stubs::alloc_code_with_unwind and use it for make_stub_info,
make_call_tracer, and guard::thunk (covering the framed span up to the
restored leaf state before the tail jump). Add live-stack RtlVirtualUnwind
tests for both stub and guard thunks.

Assisted-by: Antigravity (Gemini 4 Neon)
@ufoptg

ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner Author

Upstream PR xcl-dev#936 was closed or merged.

@ufoptg ufoptg closed this Nov 25, 2026
@ufoptg
ufoptg deleted the upstream-pr/936 branch November 25, 2026 00:08
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.

2 participants