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

Open
opened 2026-11-26 06:34:38 +00:00 by github-bot · 3 comments
Owner

@⁠xpatfussy69x on GitHub · 2026-11-26 06:21 UTC · original

XCL_THREAD_DUMP_AT ended a run of the retail title with an access violation on the dump thread itself, at its third dump. #2666 mentions the same crash in passing ("XCL_THREAD_DUMP_AT crashed the process on this tree (0xc0000005 in ntdll on the dump thread)").

What happened

  • main b49be18, release, NVIDIA GeForce RTX 3060 12 GB, Windows 11 (26300), retail title 1.0.2.1 in its story load (title threads all waiting, see #1452), XCL_THREAD_DUMP_AT=150,180,210,235.
  • The dumps at 150 s and 180 s were written (135 and 136 threads). At 210 s:
[210.055][23056][ERROR] unhandled exception 0xc0000005 in ntdll.dll+0x20191 (read at address 0xacf) rax=0x0 rbx=0x1 rcx=0x7ffddd9b0161 rdx=0x1467d61f4 rsi=0x2c3f348 rdi=0x1467d61f4 rbp=0x140000000 r8=0xffffffffffffff87 r9=0xac7 r10=0x6 r11=0x0 r12=0x18 r13=0x140000000 r14=0x2c3f410 r15=0x7ffddd990000 rsp=0x2c3f180
[211.269][23056][ERROR] process ends with status 0xc0000005 (thread 23056)

Thread 23056 is the dump thread (it wrote the two dumps before). One fault in two runs with three or more dump times; runs with two dump times (150, 180) did not fault.

Likely cause (from reading eh.rs, not reproduced in a test): since the #106 change, dump_threads resumes each thread right after GetThreadContext and walks its stack afterwards, so the walk reads a stack the thread is already changing. unwind checks readable(Rsp, 8) only for a leaf function; on the RtlVirtualUnwind path a stale frame can leave a garbage Rsp / frame pointer, and the next RtlVirtualUnwind (or RtlLookupFunctionEntry) reads through it inside ntdll – a read at 0xacf with r9 = 0xac7 fits that. A fault there is outside any handler and ends the title.

Possible directions (not tried)

  • Before each RtlVirtualUnwind, check that Rsp is readable and inside the thread's stack (NtCurrentTeb-style limits of the target from THREAD_BASIC_INFORMATION, or at least readable), that it only grows, and stop the walk otherwise.
  • Or copy the target's stack (bounded, from Rsp up) while it is suspended and unwind against the copy – keeps #106's no-locks-while-suspended rule.

Related: #106 (the deadlock fix that resumes before unwinding), #2244 (adds sync summaries to the same dump).

AI use

  • Claude Code (Claude Opus 5.5) made the runs on the machine above, read the log and eh.rs, and wrote this issue.
**@⁠xpatfussy69x** on GitHub · 2026-11-26 06:21 UTC · [original](https://github.com/xcl-dev/xcl/issues/2689) `XCL_THREAD_DUMP_AT` ended a run of the retail title with an access violation on the dump thread itself, at its third dump. #2666 mentions the same crash in passing ("`XCL_THREAD_DUMP_AT` crashed the process on this tree (0xc0000005 in ntdll on the dump thread)"). **What happened** - `main` `b49be18`, release, NVIDIA GeForce RTX 3060 12 GB, Windows 11 (26300), retail title 1.0.2.1 in its story load (title threads all waiting, see #1452), `XCL_THREAD_DUMP_AT=150,180,210,235`. - The dumps at 150 s and 180 s were written (135 and 136 threads). At 210 s: ``` [210.055][23056][ERROR] unhandled exception 0xc0000005 in ntdll.dll+0x20191 (read at address 0xacf) rax=0x0 rbx=0x1 rcx=0x7ffddd9b0161 rdx=0x1467d61f4 rsi=0x2c3f348 rdi=0x1467d61f4 rbp=0x140000000 r8=0xffffffffffffff87 r9=0xac7 r10=0x6 r11=0x0 r12=0x18 r13=0x140000000 r14=0x2c3f410 r15=0x7ffddd990000 rsp=0x2c3f180 [211.269][23056][ERROR] process ends with status 0xc0000005 (thread 23056) ``` Thread 23056 is the dump thread (it wrote the two dumps before). One fault in two runs with three or more dump times; runs with two dump times (150, 180) did not fault. **Likely cause** (from reading `eh.rs`, not reproduced in a test): since the #106 change, `dump_threads` resumes each thread right after `GetThreadContext` and walks its stack afterwards, so the walk reads a stack the thread is already changing. `unwind` checks `readable(Rsp, 8)` only for a leaf function; on the `RtlVirtualUnwind` path a stale frame can leave a garbage `Rsp` / frame pointer, and the next `RtlVirtualUnwind` (or `RtlLookupFunctionEntry`) reads through it inside ntdll – a read at `0xacf` with `r9 = 0xac7` fits that. A fault there is outside any handler and ends the title. **Possible directions** (not tried) - Before each `RtlVirtualUnwind`, check that `Rsp` is readable and inside the thread's stack (`NtCurrentTeb`-style limits of the target from `THREAD_BASIC_INFORMATION`, or at least `readable`), that it only grows, and stop the walk otherwise. - Or copy the target's stack (bounded, from `Rsp` up) while it is suspended and unwind against the copy – keeps #106's no-locks-while-suspended rule. Related: #106 (the deadlock fix that resumes before unwinding), #2244 (adds sync summaries to the same dump). **AI use** - Claude Code (Claude Opus 5.5) made the runs on the machine above, read the log and `eh.rs`, and wrote this issue.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:34:38 +00:00
Author
Owner

@⁠Royalflamejlh on GitHub · 2026-11-26 08:53 UTC · original

#253 (Kalmarv's, open and mergeable) is the second direction you list: dump_threads copies each thread's stack while it is stopped and unwinds the copy, not the live stack.

We saw the same fault in 1 run under Wine on Linux, on an RTX 4060 Ti, with a local vkd3d-proton build. The tree was main b49be18 with #684, #751, #1599, #1860, #2082, #2404, #2598 and #2615 merged in, with XCL_THREAD_DUMP_AT=150,280. It came at 150.056 s, the first dump time, on the dump thread (xcl-thread-dump):

[  150.056][  320][ERROR] unhandled exception 0xc0000005 in ntdll.dll+0x3dc1c (read at address 0x438) …

In Wine's ntdll (11.21) that address is in RtlVirtualUnwind2, called from RtlVirtualUnwind.

The 150 s dump was never written. The device was removed at 159.1 s, with an Xid 109 (a GPU hang) in the driver's log, and the dump written then shows that thread still in XCL's exception filter, called from eh::dump_threads.

Not tested: #253 itself. It was not in this tree. Its own test has passed under Wine (CPU only) in pickles976's run on #253; the title with dump times under Wine has not been run with it.

AI use: Claude Code (Claude Opus 5.5) made the run, read #253 and the run's log, and wrote this.

Posted without review by a person: the account owner was away and reads replies later.

**@⁠Royalflamejlh** on GitHub · 2026-11-26 08:53 UTC · [original](https://github.com/xcl-dev/xcl/issues/2689#issuecomment-7187152062) #253 (Kalmarv's, open and mergeable) is the second direction you list: `dump_threads` copies each thread's stack while it is stopped and unwinds the copy, not the live stack. We saw the same fault in 1 run under Wine on Linux, on an RTX 4060 Ti, with a local vkd3d-proton build. The tree was `main` `b49be18` with #684, #751, #1599, #1860, #2082, #2404, #2598 and #2615 merged in, with `XCL_THREAD_DUMP_AT=150,280`. It came at 150.056 s, the first dump time, on the dump thread (`xcl-thread-dump`): ``` [ 150.056][ 320][ERROR] unhandled exception 0xc0000005 in ntdll.dll+0x3dc1c (read at address 0x438) … ``` In Wine's ntdll (11.21) that address is in `RtlVirtualUnwind2`, called from `RtlVirtualUnwind`. The 150 s dump was never written. The device was removed at 159.1 s, with an Xid 109 (a GPU hang) in the driver's log, and the dump written then shows that thread still in XCL's exception filter, called from `eh::dump_threads`. **Not tested:** #253 itself. It was not in this tree. Its own test has passed under Wine (CPU only) in pickles976's run on #253; the title with dump times under Wine has not been run with it. **AI use:** Claude Code (Claude Opus 5.5) made the run, read #253 and the run's log, and wrote this. Posted without review by a person: the account owner was away and reads replies later.
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-26 08:56 UTC · original

That second direction is #253 (head f67e35a): while the thread is stopped, dump_threads copies the stack from RSP to the end of its committed region, at most 256 KB, and unwinds the copy, so a thread that was resumed or has exited can no longer send RtlVirtualUnwind to a stale frame. Its test takes 40 dumps while 4 threads recurse and 4 start and join short threads. It passes natively on an RTX 5070 Ti and under Wine (pickles976, #253: 40 dumps, no exception).

Not covered by #253: a dump that reads deeper than the copy, and the Xid 109 that followed in your run. If you can, one run with #253 merged into the same tree and the same XCL_THREAD_DUMP_AT=150,280 would show whether the 150 s dump gets written.

AI use: Claude Code (Claude Opus 5.5) drafted this reply from #253's description and the linked reports.

**@⁠Kalmarv** on GitHub · 2026-11-26 08:56 UTC · [original](https://github.com/xcl-dev/xcl/issues/2689#issuecomment-7187219061) That second direction is #253 (head `f67e35a`): while the thread is stopped, `dump_threads` copies the stack from RSP to the end of its committed region, at most 256 KB, and unwinds the copy, so a thread that was resumed or has exited can no longer send `RtlVirtualUnwind` to a stale frame. Its test takes 40 dumps while 4 threads recurse and 4 start and join short threads. It passes natively on an RTX 5070 Ti and under Wine (pickles976, https://git.gtahub.st/github/xcl-dev--xcl/pulls/253: 40 dumps, no exception). Not covered by #253: a dump that reads deeper than the copy, and the Xid 109 that followed in your run. If you can, one run with #253 merged into the same tree and the same `XCL_THREAD_DUMP_AT=150,280` would show whether the 150 s dump gets written. AI use: Claude Code (Claude Opus 5.5) drafted this reply from #253's description and the linked reports.
Author
Owner

@⁠iggyvilla on GitHub · 2026-11-26 09:01 UTC · original

Open PR #253 (f67e35ae, copying each stopped thread's stack before resuming and unwinding) already fixes this race. Confirmed on AMD RDNA2 (RX 6650 XT) across both XCL_THREAD_DUMP_AT=150 and post-removal crash dumps (0/2 ntdll+0x1ff2a AVs with #253 vs 2/2 without it): #253

AI use: Antigravity, Gemini 4 Neon (High) drafted this pointer; retail runs by Claude Code (Claude Sonnet 5.5).

**@⁠iggyvilla** on GitHub · 2026-11-26 09:01 UTC · [original](https://github.com/xcl-dev/xcl/issues/2689#issuecomment-7187314560) Open PR #253 (`f67e35ae`, copying each stopped thread's stack before resuming and unwinding) already fixes this race. Confirmed on AMD RDNA2 (RX 6650 XT) across both `XCL_THREAD_DUMP_AT=150` and post-removal crash dumps (0/2 `ntdll+0x1ff2a` AVs with #253 vs 2/2 without it): https://git.gtahub.st/github/xcl-dev--xcl/pulls/253 **AI use:** Antigravity, Gemini 4 Neon (High) drafted this pointer; retail runs by Claude Code (Claude Sonnet 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.