Stop the unwind where RtlVirtualUnwind would read outside the stack #140
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!140
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-140"
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?
@Garu667 on GitHub · 2026-11-27 03:58 UTC · original
Garu667:fix/profiler-unwind-reach→main· +209 −0 · 1 files · 1 commits · closed without mergingWhat happened: a
VICTORY_PROFILErun (RTX 3080, Series S, open world, standing) ended about a minute into sampling with an access violation in the profiler's own thread. It faulted insideRtlVirtualUnwind, called fromcrash::unwind_intowhile walking another thread, on a read of reserved, never-committed memory. The title itself was fine.Why:
unwind_intochecked only thatrsplies in the sampled thread's stack. ButRtlVirtualUnwindreads the whole frame up to the return address. Once the prolog has set the frame register, it reads from that register instead, and in another thread the register can hold anything. So a frame near the top of a stack, or a strayrbp, sends the read out of the stack.Fix (
crates/victory-loader/src/crash.rsonly):UNWIND_INFO: pushes, small and large allocations, machine frames, the frame register (only once itsSET_FPREGhas run), and chained entries.low..high. Unknown versions or malformed data also stop it.Tests:
unwinds_like_the_system_walkstill passes, so real stacks are not cut short.cargo test -p victory-loader: 59 pass. Clippy with-D warningsandcargo xtask policyare clean.In the game: the same profile run with this change went 7 minutes without a fault and wrote its profile.
🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 04:07 UTC · original
Thanks for tracking this down to the profiler thread, @Garu667. I reproduced all 59 loader tests passing at
fa2f5fe. The seven-minute profiling run gives us a useful real-world check alongside the tests.The next revision needs to keep the suspended-thread walk allocation-free.
stacks.rscallsunwind_intobetweenSuspendThreadandResumeThread, so theto_vec()calls inframe_reachandreach_ofcan wait on the allocator while the suspended thread holds it. A fixed scratch buffer and bounded reads would preserve that existing contract.I’d also tighten the stack bounds around saved-register restores. The
SAVE_NONVOLandSAVE_XMM128cases currently advance the opcode cursor without accounting for the memory those restores read. Please include the saved offset and register width in the range check, and keep unwind-record reads bounded before handing the frame to Windows. A positive case and a boundary case for register restores would help cover this. Microsoft’s x64 unwind reference@TaynanGT on GitHub · 2026-11-27 04:22 UTC · original
Thanks for the profiling investigation, @Garu667. The bounded walk is now on
mainthrough #151, with your authorship preserved. The follow-up keeps the sampled-thread path allocation-free and checks saved-register reads and guard pages. All 65 loader tests with diagnostics and the Windows workflow passed. A repeat of your longer sampling run on currentmainwould give us the matching gameplay confirmation.@Garu667 on GitHub · 2026-11-27 04:24 UTC · original
Thanks for the careful review. Both points are fixed in
eeb4419:reach_ofnow borrows the unwind info in place: it takes slices, and chained infos come back as slices too, so there is noto_vecleft. The header, codes and chained entry are read only after checking that they lie inside the image. The image size isSizeOfImagefrom its PE headers, and an image without valid headers stops the walk.SAVE_NONVOLuses offset × 8 and 8 bytes; the_FARform uses its unscaled offset.SAVE_XMM128uses offset × 16 and 16 bytes, with the same_FARhandling. Version 1's 6/7 are treated as XMM saves, and version 2's 6 as the epilog mark.reach_covers_the_saved_registers_it_restores: a save inside the frame, one exactly at its boundary, one past it (which widens the range), an XMM save, and the far form.cargo test -p victory-loader: 60 pass.clippy -D warningsandcargo xtask policyare clean. I'll repeat the in-game profile run with this revision and post the result.🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 04:25 UTC · original
Thanks for following up with the saved-register cases, @Garu667. The merged build in #151 uses fixed buffers and checks the full restore width plus page readability. Your longer profile run would be most useful on the merged revision
02b693e, so it can validate the implementation people will use. Please include the elapsed sampling time and whether it wrote the profile.@Garu667 on GitHub · 2026-11-27 04:37 UTC · original
In-game check of
eeb4419: same profile settings (VICTORY_PROFILE=120,300,5,<file>, RTX 3080, Series S, open world, standing). The run lasted about 9 minutes with no fault and wrote a 43 MB profile.The new bound doesn't cut stacks short: the sample-weighted mean depth is 12.6 frames, against 12.0 with
fa2f5fe.🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 04:42 UTC · original
Thanks for the longer profile run, @Garu667. About nine minutes without a fault, a 43 MB profile and a mean depth of 12.6 frames are the result for
eeb4419. The remaining check is the same sampling run on currentmainwith the #151 implementation. The elapsed time and whether it wrote a profile are enough.@Garu667 on GitHub · 2026-11-27 06:23 UTC · original
Check of the #151 implementation, as you asked: main
f944962, same settings (VICTORY_PROFILE=120,300,5,<file>, RTX 3080, Series S, the cell, standing).eeb4419).🤖 Generated with Claude Code
@TaynanGT on GitHub · 2026-11-27 06:40 UTC · original
@Garu667 Thanks for checking the #151 implementation on
f944962. The run completed the full 180 s sampling window and wrote 723k samples without an unwind fault. That confirms the stack-walk fix for the cell run on the RTX 3080. I’ll keep its 11.5-frame mean with the cell result, since the 12.6-frame run sampled the open world.Pull request closed