loader: unwind a 16-byte aligned copy of the context #313
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/313"
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?
Imported from Marvisak/VIctory. Originally posted by Abdellah-Khanani on 2026-11-24T02:14:41Z.
unwind_intohands its by-valueCONTEXTtoRtlVirtualUnwind, andunwinds_like_the_system_walkhands a stackCONTEXTtoRtlCaptureContext. Both functions want the context 16-byte aligned. windows-sys 0.61 declares the x64CONTEXTas plain#[repr(C)], with noalign(16), so on the stack it can land 8 bytes off.In a debug build here it does.
cargo test --workspaceonmain(d2a4bae) stops the wholevictory-loadertest binary withthread 'crash::tests::unwinds_like_the_system_walk' has overflowed its stackandSTATUS_ACCESS_VIOLATION, so the other 17 loader tests are not counted. A temporary print showed the test's context at an address ending in...838. Release builds happen to get an aligned slot and pass.Aligning only the test's context is not enough: the test still crashes inside
unwind_into, on its own copy. The same copy is what the crash handler (unwind(*context)) andstacks.rs(unwind_into(context.0, …)) unwind with, so a debug or diagnostics build can fault while writing a crash report.What is in it
crates/victory-loader/src/crash.rs: anAligned16(CONTEXT)wrapper (#[repr(C, align(16))], like the privateAlignedinstacks.rsforGetThreadContext).unwind_intocopies its context into one and unwinds that.unwinds_like_the_system_walkcaptures into one.Tested
rust-toolchain.toml.cargo test --workspace --no-fail-fastonmaind2a4bae: 246 passed, 0 failed, 4 ignored, plus thevictory-loaderlib binary aborted (0xc0000005, the stack-overflow message above).cargo test -p victory-loader, debug and--release: 18 + 2 passed in both.unwind_into), the debug test still crashes the same way.cargo fmt --check -p victory-loader: no new differences (10 before and after, all in lines this does not touch).Not tested
VICTORY_STACKS, in a diagnostics build.AI use
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by arminkhaleghirod on 2026-11-24T03:04:17Z.
Confirmed on Windows 11. On main,
unwinds_like_the_system_walkcrashes every run in debug. With this PR it passes.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T07:37:36Z.
Review: APPROVED
Tested
b5c6678on Windows 11, RTX 5070, MSVC:cargo test --workspace --no-fail-fastpasses (264 passed, 0 failed), debug profile.CONTEXTis#[repr(C)]with noalign, and itsM128Afields are plain#[repr(C)]too, so the struct's alignment is 8.RtlCaptureContext/RtlVirtualUnwinduse aligned 16-byte stores (movaps/fxsave-style), so an 8-off stack slot faults.unwinds_like_the_system_walkpasses there. That fits your observation that it depends on the frame layout, and it is exactly why the alignment should be explicit rather than relied on.Aligned16mirrors the privateAlignedalready instacks.rs. Copying into it insideunwind_intocovers both callers (the crash handler andstacks.rs) in one place.No issues found.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by qntic on 2026-11-24T07:49:44Z.
Independent test on a Zen 3 machine: confirms the fix.
Environment: Windows 11 22631, AMD Ryzen 5 5600X (Zen 3), AMD Radeon RX 6600 XT, 32 GB, Rust 1.98.1 from
rust-toolchain.toml, debug,--locked. This PR cherry-picked ontod2a4bae(tree identical tob5c6678).Before (
d2a4bae):cargo test --locked -q -p victory-loader --libaborts in 3 of 3 runs withthread 'crash::tests::unwinds_like_the_system_walk' has overflowed its stackand0xc0000005, STATUS_ACCESS_VIOLATION. The test alone aborts the same way.After (this PR):
victory-loaderlib: 18 passed, 0 failed, in 3 of 3 runs.cargo test --workspace --locked --no-fail-fast: 264 passed, 0 failed, 4 ignored, exit code 0. These are the same totals as in the PR description, on a different CPU generation (Zen 3 here, Zen+ there).Not tested: a release build of the loader tests, the crash handler on a real crash,
VICTORY_STACKS, any title.