Skip to content

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

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

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
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head 7e6e2f0

#2689 is fixed on main by commit f67e35a ("xcl run: thread dumps unwind a copy of each stopped thread's stack"). dump_threads in eh.rs now copies the stack while the thread is suspended and unwinds the copy after ResumeThread, and the issue is closed.
This PR instead calls unwind (RtlLookupFunctionEntry) while the thread is suspended. That is what #106 removed: the lookup can take a lock the suspended thread holds, so the dump can deadlock. The comment kept just above the change says so.
Recommendation: close (superseded by main commit f67e35a).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@throny

throny commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded: this change is already on main (f67e35a). f67e35a: dump_threads copies the suspended thread's stack and unwinds the copy (eh.rs); fixes #2689

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

@throny throny added the duplicate This issue or pull request already exists label Dec 1, 2026
@throny throny closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists

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

4 participants