xcl run: thread dumps unwind a copy of each stopped thread's stack #253
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!253
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-253"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Kalmarv on GitHub · 2026-11-23 21:55 UTC · original
Kalmarv:fix/thread-dump-stack-copy→main· +95 −11 · 1 files · 1 commits · openRefs #106 (the crash in
eh::dump_threads, withXCL_THREAD_DUMP_AT: an access violation inRtlVirtualUnwind2reading0xf8).dump_threadsresumed each thread right afterGetThreadContext, then unwound its stack from live memory. By that time the thread has either gone on, so the saved registers and return addresses are overwritten, or ended, so its stack is freed. A stale frame register sendsRtlVirtualUnwindto a near-null address: the report's read. The fault is insideRtlVirtualUnwind, so no check after the call can catch it. Now, while the thread is stopped, the dump also copies its stack, and the unwinding reads the copy.Seen in a run: a long run of a retail title on a local diagnostic build (
main'sdump_threadswith other local changes; this PR was not in it) crashed in ntdll's unwinder (ntdll+0x20047, a read at0xfb0, betweenRtlVirtualUnwind2andRtlVirtualUnwind) 75 ms into a thread dump the stalled-heartbeat check took, on the thread taking it. Its registers point into an Opus-decoding thread (MSOpusDecoder.dll), whichdump_threadshad already resumed when it unwound its stack. Two earlier long runs of builds with the samedump_threadstook 11 dumps each without a crash.What is in it
copy_stack: from RSP to the end of its committed region, at most 256 KB. It uses system calls only (VirtualQuery,ReadProcessMemory) into a buffer allocated before any thread is stopped, so it takes no lock the stopped thread may hold. If the copy fails, for example because the thread is exiting, that thread is left out, as whenGetThreadContextfails.unwindreads the copy:UNWIND_INFO), would leave the copy;unwindhas no other caller.Test
eh::tests::thread_dumps_while_threads_run_and_exit: 40 dumps, with 4 threads busy in a recursion whose frames keep changing and 4 threads starting and joining short-lived threads.Overlaps:
dump_threads()on an unhandled exception, so it gets this fix.eh.rsand merge with this without conflicts.Tested
cargo test --workspace -- --test-threads=4onf67e35a(this PR, rebased onto main930e8b4without conflicts; the same patch as4d05d43): 752 passed, 0 failed, 41 ignored (thexcllibrary: 708 passed, 21 ignored),eh::tests::thread_dumps_while_threads_run_and_exitamong them. SKIPPED GPU tests: 2, bothno wave64(gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware).4d05d43, on maindd2ae9a: 691 passed, 0 failed, 41 ignored, the same two SKIPPED.cargo test -p xcl --lib -- --exact eh::tests::thread_dumps_while_threads_run_and_exiton4d05d43, 3 runs: 3 of 3 passed (4.1–4.3 s).--exact, CPU only (no device), under a debugger that passes first-chance exceptions on and catches the second-chance one with its thread and stack. 20 runs each, interleaved:60565c4with the test added: 15 of 20 crashed, all fromeh::unwind←dump_threads. 4 were atntdll+0x1ff2ainRtlVirtualUnwind2, reading a near-null address: the instruction in the report. 11 were atntdll+0x1ff9f, reading other threads' stacks.60565c4; the same code as12328ac): 20 of 20 passed.RtlUserThreadStart.12328ac.scripts/test.ps1: 652 passed, 0 failed, 40 ignored; SKIPPED only the 2no wave64tests; the e2e test title test passed.XCL_THREAD_DUMP_AT, run by @Natakout (https://github.com/ivall/xcl/pull/253#issuecomment-7135997990): RTX 3060 12 GB (NVIDIA 621.14), Windows 11 25H2, release,4d05d43(the same patch as this head) and main47efa2e, dumps at 140, 170, 200, 230, 250 and 260 s. On main the run dies at 200.13 s on the dumping thread, during the third dump (0xc0000005inntdll.dll+0x79a67, a read at0x376). With this PR all six dumps are written (168–170 threads each).f67e35aand main930e8b4, a dump every 5 s from 70 s. On main the second dump (75.17 s) faults on the dumping thread inntdll.dll+0x20191(a read at0xffffffffffffffff) and the process hangs. With this PR all 9 dumps are written (70–105 s, 173–176 threads each). Their smoke pair of the same two commits: 1571 / 1585 frames (99 %), peak commit 22979 / 20665 MB (111 %), no crash or device removal.Regression run
Our own runs, one after the other on the machine under Tested (RTX 5070 Ti), release builds, no uncommitted changes:
mainat930e8b4(this PR's base), then this PR's head. 98 % ofmain's frames, 99 % of its peak commit.main:
PR:
Not tested
RtlInstallFunctionTableCallback.RtlVirtualUnwindreads that frame's return address before the bound check, so it could read past the buffer and its 64 KB slack.AI use
🤖 Generated with Claude Code
@Kalmarv on GitHub · 2026-11-23 22:39 UTC · original
Regression run wanted. We have no title on our machine. If you can run
scripts/smoke.ps1 -Game <your title folder>twice, once built frommain(9ab7d76) and once from this PR's head (12328ac), please paste bothxcl-smokeblocks here. I'll copy them into the description under Regression run, with your name and hardware.🤖 Claude Opus 5.5
@MesshM on GitHub · 2026-11-24 04:33 UTC · original
Test run of
4d05d437d8c9d47a3f0f39fd9a17fada072f4536on AMD RDNA4. I merged it onto currentmain64b3f35locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 702 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 661 passed, 0 failed, 21 ignoredSKIPPED; theehtests pass (no thread dump was triggered here).Review: Copying each stopped thread's stack (from
rspto the end of its committed region, at most 256 KiB) before resuming it removes the read of a live stack that crashed in #106. A question I could not settle from the diff: frames that use RBP as a frame pointer, and any pointer the unwinder follows from the context, still hold addresses of the original stack, soRtlVirtualUnwindmay read the live stack there rather than the copy. If the unwind only ever reads relative to the copied RSP that is fine; otherwise the context registers that point into the stack would need the same rebase.Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@Kalmarv on GitHub · 2026-11-24 04:35 UTC · original
@MesshM Thanks for the RDNA4 run. On the question: the unwind already moves those registers to the copy (
eh.rs,unwind, 4d05d43):RtlVirtualUnwind, the same is done again. A frame register or a saved RBP that the unwinder restored from the copy still holds an address of the original stack, and it's moved into the copy before the next frame.So the unwinder reads only the copy, plus a 64 KiB margin after it in the same buffer, never the stopped thread's live stack. What it doesn't fix up is a pointer to the stack that sits in memory outside the stack: an unwind of x64 code doesn't follow one.
🤖 Claude Opus 5.5
@Natakout on GitHub · 2026-11-24 15:25 UTC · original
Test report: thread dumps no longer crash the run (RTX 3060)
Commit tested: this PR's head 4d05d43, against
main47efa2e.Tested
XCL_PRESS_ATto get past the menus into the world load andXCL_THREAD_DUMP_AT=140,170,200,230,250,260.main: the dumps at 140 s and 170 s are written. The run then dies at 200.13 s inside the dumping thread itself, during the third dump:unhandled exception 0xc0000005 in ntdll.dll+0x79a67 (read at address 0x376). This is theRtlVirtualUnwindcrash from #106.Not tested
f4ce27c, so the title's shaders were recompiled for this run. Shader cache state therefore differs from themainrun; it does not affect the dump path.AI use
Claude (claude-opus-5-5, through Hermes) ran the builds and the title runs on the hardware above over SSH, read the logs and drafted this report.
@Anon64 on GitHub · 2026-11-24 15:25 UTC · original
Regression run, as asked: this PR's head
f67e35aandmain930e8b4(its merge base). RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s.main
930e8b4:this PR:
No device removals or crashes; 99 % of main's frames, 111 % of its peak commit.
The crash this PR fixes, reproduced on
main930e8b4: a 150 s world-loading run withXCL_THREAD_DUMP_ATevery 5 s from 70 s took the first dump (143 threads) and then, at the second (75.17 s), faulted on the dumping thread inntdll.dll+0x20191, a read at0xffffffffffffffff. The process did not end; it hung until I stopped it.The same run on this PR's head: all 9 dumps were written (70 s to 105 s, 173–176 threads each), no fault in the unwinder. The run ended at 105 s in the title's own hang watchdog during world loading, which
mainhits on this card without dumps too (104–116 s in earlier runs).Not tested: the whole suite; AMD.
Written with Claude Code (Claude Opus 5.5) from runs on this machine.
@Kalmarv on GitHub · 2026-11-24 17:13 UTC · original
@Natakout, @Anon64 thank you. These are the first runs of the case from the report: a title with
XCL_THREAD_DUMP_AT, crashing onmaininside the unwinder and writing every dump with this PR. Both runs are now in the description under Tested, Anon64's smoke pair included, and "a title withXCL_THREAD_DUMP_AT" is no longer under Not tested.AI use: Claude Code (Claude Opus 5.5)
@DavidM1911 on GitHub · 2026-11-25 15:14 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
@thehollowedone on GitHub · 2026-11-26 01:21 UTC · original
Independent Windows check of #253 head
f67e35amerged locally, without a commit or conflict, onto current mainb49be18. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / driver 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11. The test checkout had only the staged merge changes.Tested
cargo test --offline --locked -p xcl --lib eh::tests::thread_dumps_while_threads_run_and_exit -- --exact --nocapture --test-threads=1: five consecutive processes passed, 1/0/0 each, no skips. The checked-in test exercises concurrent thread activity and exits while taking dumps.cargo build --offline --locked --workspace: passed.cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4: 1,436 passed, 0 failed, 47 ignored, with 25SKIPPEDnotices. The thread-dump test passed within this run too. TheInvalid bitcode signatureline belongs to the passing malformed-container test.Not tested
AI use
@pickles976 on GitHub · 2026-11-26 07:24 UTC · original
Tested — Wine CPU-only follow-through
Exact production head
f67e35aeb09291534ff47a627e42c1f6a91c67b3, no source changes. Linux6.17 / Wine11.0, Rust1.98.1 MSVC target. FreshCompiling xclline names the selectedxcl-pr253checkout; touchedsrc/lib.rsandbuild.rsbefore this shared-target worktree switch (including regenerated IDs).1 passed, 0 failed, 0 ignored, 0.46s; fresh build15.81s. Log contains 40 actual dumps, 9–9 threads each, with multi-frame traces including kernel32/ntdll frames. No exception or timeout. Scope MemoryMax9GiB / MemorySwapMax512MiB, 180s timeout. Evidence
.compat-xcl/logs/verify-pr253-wine-thread-dumps.log.This fills a focused Wine-test gap, not the title regression requirement. Our earlier title dump had a near-null
ntdll+0x38a26AV; matching PE/PDB and bounded disassembly put its captured return atxcl::eh::dump_threads+0x21d, immediately after thekernel32!RtlVirtualUnwindimport call: scoped evidence in #106. I did not rerun that unchanged crashing title probe.Not tested
Retail title with this PR, dump-at-crash timing, callback function tables, or the already-described deep-stack/large-frame read beyond the copy/slack. That known boundary gap remains; this pass is not a blanket unwind-safety claim. No GPU workload in this fixture, no frame-time/gameplay claim. The shared Wine prefix contains the lab's diagnostic-relaxed vkd3d build, but this test does not create a GPU device.
AI use: omp, harness model
openai-codex/gpt-6-astra, ran the check and drafted this report. No upstream code changes.@Kalmarv on GitHub · 2026-11-26 07:31 UTC · original
Thanks @pickles976 for running this under Wine on
f67e35a(CPU only):thread_dumps_while_threads_run_and_exitpassed 1 of 1, with 40 dumps of 9 threads each and no exception or timeout. It covers the Wine side of the fix. As you note, it does not cover the title probe or the deep-stack read past the copy, and both are still open.AI use: Claude Code (Claude Opus 5.5) drafted this comment from the linked report.
@iggyvilla on GitHub · 2026-11-26 09:00 UTC · original
Test report on AMD RDNA2 (RX 6650 XT), including crash/removal-time thread dumps (two items under Not tested).
Commit tested:
f67e35aeb09291534ff47a627e42c1f6a91c67b3(applied cleanly without code changes ontomainb49be183for the unit/workspace suite, and cherry-picked cleanly onto a local test stack08db802+#2615+#2598+#751+#2404for the retail runs).Tested
32.0.21045.29003), Ryzen 7 5700X, 32 GB RAM, Windows 11,stable-x86_64-pc-windows-msvc.cargo test -p xcl --lib eh::(debug, onmainb49be183+f67e35ae): 7 passed, 0 failed, 0 ignored (note:thread_dumps_while_threads_run_and_exitalso passed 5/5 on unfixedb49be183here).cargo test --workspace --no-fail-fast -- --test-threads=4(debug, same tree):xcllib 1309 passed, 1 failed, 27 ignored;e2e3 passed, 1 failed; 0 failures elsewhere. Both failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 783 ande2e::test_title_runs_and_game_folder_is_untouchedatcrates/xcl/tests/e2e.rs:249) reproduce identically on unmodifiedmainb49be183(checked by stashing). 7SKIPPEDGPU tests (6 f16/f32 programs refused per#1426;pso_measurement_compiles_an_exact_synthetic_recordcannot disable driver cache without Developer Mode).XCL_THREAD_DUMP_AT=150+ crash/removal-time dumps (release, interactive session,XCL_NETWORK=0,XCL_DIRECT_DXIL=1precompiled cache, on the test stack above):f67e35ae(2 runs):0x887a0006device removal completed cleanly in both runs at high thread count: 229 threads at 178.0 s (run 1) and 261 threads at 184.7 s (run 2, after the title's post-removal breakpoint).ntdll+0x1ff2aaccess violations in the dump thread; 0 WER dumps.f67e35ae(2 control runs on the same stack):0xc0000005atntdll+0x1ff2aduring the post-removal thread dump (run 1: read at0xfffffffffffffffe, 0.18 s after removal; run 2: read at0x7, ~20 s after removal), producing 2 WER dumps (same crash as#2689, also seen in 2/4 earlier runs without this PR).Not tested
scripts/smoke.ps1pair on standalonemain+f67e35ae(the retail runs above were on the local test stack noted above, not standalonemain).RtlInstallFunctionTableCallback.AI use
f67e35ae, ran the unit/workspace suite and retail runs, and recorded the counts/logs.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.