Skip to content

eh: unwind thread dump while thread is suspended - #2851

Open
guinpereira wants to merge 1 commit into
xcl-dev:mainfrom
guinpereira:fix/eh-thread-dump-unwind
Open

guinpereira wants to merge 1 commit into
xcl-dev:mainfrom
guinpereira:fix/eh-thread-dump-unwind

Conversation

@guinpereira

@guinpereira guinpereira commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #2689.

Unwinds while the thread is still suspended instead of after ResumeThread, avoiding the ntdll fault on a resumed thread.

What is in it

  • crates/xcl/src/eh.rs: unwind performed while the thread is suspended.

Tested

  • Windows 11, NVIDIA GeForce RTX 5060 Ti, Rust stable (x86_64-pc-windows-msvc), debug build.
  • cargo test -p xcl --lib -- --test-threads=4: 1315 passed, 4 failed (GPU OOM in dxil fuzz tests, environment), 27 ignored.
  • cargo build -p xcl: clean.

Regression run

xcl-smoke v1
commit: 05adb5a9cfc718119c0c9c097365983e67982d05
gpu: NVIDIA GeForce RTX 5060 Ti
title: gta6
seconds: 60
exit: 0x0
frames shown: 1043 (PresentX 1043)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15536 MB

Reference run on the author's local main (05adb5a). A run on ivall/xcl main and on this PR's head commit is still pending (cold shader cache crashes the title's startup precompile on this machine).

Not tested

  • Smoke on ivall/xcl main baseline and on this PR's head commit (pending, see above).
  • The thread-dump path itself not exercised in a unit test.

AI use
OpenCode, Beam Free - drafted the change; smoke run and review by the author.

@pickles976

Copy link
Copy Markdown

Source-review concern at 7e6e2f095233331a4df7dbfe0b3c9bac0067c79d: this closes the resumed-stack race, but moves allocating/locking work into the suspended interval.

The unchanged unwind implementation in crates/xcl/src/eh.rs:623-644 starts with Vec::new() and out.push(rip) (first push allocates), then calls RtlLookupFunctionEntry and RtlVirtualUnwind. This patch calls it before ResumeThread. The adjacent existing comment explicitly identifies locks a suspended thread may own (#106).

Risk, not a reproduced hang: if the stopped thread owns an allocator/lookup lock needed by those calls, the dumper can wait for a thread it will only resume after unwinding returns. Preallocating the output alone does not establish that the runtime lookup/unwind path is lock-free. An early failure/unwind also needs guaranteed resume/handle cleanup rather than relying on a later straight-line call.

Our earlier Wine trace implicated RtlVirtualUnwind on the resumed live stack (matching PE/PDB, xcl+0x54e01d return site); I agree that race needs fixing. But I have not launched this revised probe against the title or deliberately reproduced a deadlock, and do not consider it cleared for the diagnostic path yet.

Suggested owner direction: an allocation-free, bounded snapshot while suspended with unconditional resume cleanup, followed by unwinding the stable snapshot; coordinate with #253 rather than independently restoring suspend-time work. #253's fixed stack-copy/unwind bounds also have known large-frame/copy-boundary limitations, so it is not a blanket drop-in certification. Add an isolated, externally timed lock-contention/large-frame regression before enabling title dumps again.

This is a static safety review, not a test failure or claim that this patch caused a GPU stall. AI-assisted review (OpenAI GPT-6 Astra).

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
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.

XCL_THREAD_DUMP_AT: a dump can fault in ntdll while unwinding a thread that was already resumed

2 participants