Repository navigation
Conversation
dump_threads resumed each thread right after GetThreadContext and only then unwound its stack, from the live memory: by then the thread had gone on (its saved registers and return addresses overwritten) or ended (its stack freed). RtlVirtualUnwind followed a stale frame register to a near-null address, or read a freed stack: an access violation in the dump thread (ivall#106). While the thread is stopped, the dump now also copies its stack (from RSP, up to 256 KB, with system calls only); the unwinding reads the copy, with addresses into the stack moved to it, and stops where a frame would leave it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Kalmarv
force-pushed
the
fix/thread-dump-stack-copy
branch
from
November 23, 2026 22:05
5c77a39 to
12328ac
Compare
Contributor
Author
|
Regression run wanted. We have no title on our machine. If you can run 🤖 Claude Opus 5.5 |
|
Tested on a second machine — this PR has no hardware report yet, so here is one.
Not tested: AMD (no card here), and no retail title — no game package is unpacked on this machine yet, so the AI use: real run on the machine above; turned into this comment by Hermes Agent with DeepSeek v4.1-flash. The counts are read off the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #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.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=4on12328ac(this PR, on main9ab7d76): 652 passed, 0 failed, 40 ignored (thexcllibrary: 612 passed, 20 ignored). SKIPPED GPU tests: 2, bothno wave64(gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware). An earlier run hung in an unrelated deadlock on main (D3D12.X: replacing the sparse state deadlocks when the old state still holds placed buffers #344).--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.Regression run
Our own runs, one after the other on the machine under Tested (RTX 5070 Ti), release builds, no uncommitted changes.
main:
PR:
Not tested
XCL_THREAD_DUMP_AT(the report's case).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