Loader unit test gets an empty system stack walk on current main (Windows/Rust 1.98.1) #1012

Open
opened 2026-11-26 03:55:53 +00:00 by github-bot · 3 comments
Owner

@⁠Demon12377 on GitHub · 2026-11-25 16:02 UTC · original

Reproduced on unmodified main 39731795d2 in a separate checkout on Windows, Rust 1.98.1. The loader suite has 26 passing unit tests and one failure. The isolated failure also reproduces.

cargo test -p victory-loader --locked -- --test-threads=1
cargo test -p victory-loader --locked crash::tests::unwinds_like_the_system_walk -- --exact --test-threads=1

Failure:

thread 'crash::tests::unwinds_like_the_system_walk' panicked at crates/victory-loader/src/crash.rs:681:9:
[]

The failure is the walked.len() >= 4 assertion: RtlCaptureStackBackTrace returns an empty vector, before the custom unwinder's frames are compared. The same isolated test passes in an unchanged f85101b checkout on this machine. crash.rs itself is unchanged between those revisions, so this may depend on another build/runtime or environment difference; the cause is not established.

This also reproduces in the contribution branch #1001, with the identical 26/1 result. Reporting it separately rather than weakening the assertion or treating the failed check as passed. No game executable/assets or derived fixtures are needed for this repro.

**@⁠Demon12377** on GitHub · 2026-11-25 16:02 UTC · [original](https://github.com/fxceless/victory-fork/issues/1012) Reproduced on unmodified main 39731795d2d5117e6f90939273ee130428d28137 in a separate checkout on Windows, Rust 1.98.1. The loader suite has 26 passing unit tests and one failure. The isolated failure also reproduces. ``` cargo test -p victory-loader --locked -- --test-threads=1 cargo test -p victory-loader --locked crash::tests::unwinds_like_the_system_walk -- --exact --test-threads=1 ``` Failure: ``` thread 'crash::tests::unwinds_like_the_system_walk' panicked at crates/victory-loader/src/crash.rs:681:9: [] ``` The failure is the `walked.len() >= 4` assertion: RtlCaptureStackBackTrace returns an empty vector, before the custom unwinder's frames are compared. The same isolated test passes in an unchanged f85101b checkout on this machine. crash.rs itself is unchanged between those revisions, so this may depend on another build/runtime or environment difference; the cause is not established. This also reproduces in the contribution branch #1001, with the identical 26/1 result. Reporting it separately rather than weakening the assertion or treating the failed check as passed. No game executable/assets or derived fixtures are needed for this repro.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:55:53 +00:00
Author
Owner

@⁠fladit123 on GitHub · 2026-11-25 17:57 UTC · original

I attempted to reproduce this on Windows 11 Pro 26H2 (build 26300.10075), ntdll.dll 10.0.26100.10068, Rust 1.98.1, x86_64-pc-windows-msvc.

The original, unmodified test passed in all 300 fresh-process runs:

Revision Debug Release
d510ee4 50/50 50/50
3973179 50/50 50/50
f85101b 50/50 50/50

The loader unit suites also passed in both profiles for all three revisions.

A standalone synthetic probe collected another 3,072 samples using the original capture arguments. All returned nonempty results, including 706 calls during which StackLimit decreased by 4 KiB.

This does not invalidate the reported failure, but stack growth alone was insufficient to reproduce it on my system. Since the negative control did not fail, I have not proposed a patch or weakened the original assertion.

Could you share your exact Windows build, ntdll.dll version, and any non-default Rust compiler/linker flags or environment variables used for the failing checkout? Those differences may help narrow down the cause.

No title data was used.

**@⁠fladit123** on GitHub · 2026-11-25 17:57 UTC · [original](https://github.com/fxceless/victory-fork/issues/1012#issuecomment-7170227440) I attempted to reproduce this on Windows 11 Pro 26H2 (build 26300.10075), ntdll.dll 10.0.26100.10068, Rust 1.98.1, x86_64-pc-windows-msvc. The original, unmodified test passed in all 300 fresh-process runs: | Revision | Debug | Release | |---|---:|---:| | d510ee4 | 50/50 | 50/50 | | 3973179 | 50/50 | 50/50 | | f85101b | 50/50 | 50/50 | The loader unit suites also passed in both profiles for all three revisions. A standalone synthetic probe collected another 3,072 samples using the original capture arguments. All returned nonempty results, including 706 calls during which StackLimit decreased by 4 KiB. This does not invalidate the reported failure, but stack growth alone was insufficient to reproduce it on my system. Since the negative control did not fail, I have not proposed a patch or weakened the original assertion. Could you share your exact Windows build, ntdll.dll version, and any non-default Rust compiler/linker flags or environment variables used for the failing checkout? Those differences may help narrow down the cause. No title data was used.
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 18:16 UTC · original

I couldn't reproduce this on Windows 11. It looks like the same failure as upstream Marvisak/VIctory#742, which has a measured root cause and an upstream fix.

Environment: Windows 11 Home 10.0.26200.9974, ntdll.dll 10.0.26100.9974, Intel i7-14650HX, Rust 1.98.1 x86_64-pc-windows-msvc from rust-toolchain.toml, unmodified origin/main d510ee4, no extra RUSTFLAGS.

Run (fresh process each) Debug Release
test binary, crash::tests::unwinds_like_the_system_walk --exact --test-threads=1 100/100 pass 100/100 pass
cargo test -p victory-loader --locked <same> -- --exact --test-threads=1 30/30 pass 30/30 pass
full cargo test -p victory-loader --locked -- --test-threads=1 27 + 2 + 1 pass, 0 fail 27 + 2 + 1 pass, 0 fail

Likely cause (upstream #742). On Windows 10 (19044/19045), DrTardis1963 measured that a fresh Rust test thread often starts only 0x260..0x6c0 bytes above TEB.StackLimit. When RtlCaptureStackBackTrace runs into the stack guard page partway through its walk, Windows moves StackLimit down by 0x1000 and the call returns 0 frames. A second call right after returns 8. Several people counted it on Windows 10, all with Rust 1.98.1, Intel and AMD:

  • 61/100 and 52/100 empty walks (debug/release)
  • 22 of 25 runs failed
  • 19 of 40 runs failed
  • 69 of 100 runs failed
  • 12 of 20 runs failed

Touching 4 KiB of stack before the walk (559756c) brought this to 0 failures in every rerun. Our custom unwind() doesn't rely on that walk, so it still returns frames. Every Windows 11 report there passed.

That matches what I see. A standalone probe (no game data) walked 300 fresh threads down through their guard page, debug and release, calling RtlCaptureStackBackTrace(0, 8, …) at each step. That was 13,038 calls, including 600 that moved StackLimit during the call. None returned 0, so on this build the walk survives the guard-page fault. fladit123's 26300 results above fit this too.

Microsoft's CaptureStackBackTrace/RtlCaptureStackBackTrace docs only say it returns "the number of captured frames". They don't say when it can return 0, and they don't say the function sets last-error, so GetLastError won't help here. The test's arguments are fine: FramesToSkip = 0, FramesToCapture = 8, well under the old 63-frame limit.

About "passes on f85101b". Between f85101b and 3973179, crash.rs, Cargo.lock, the root/loader Cargo.toml and rust-toolchain.toml are unchanged, and the loader crate only changed in console_insn*.rs. Since Windows 10 fails this intermittently (roughly 45–90% of runs in the counts above), a passing f85101b run doesn't show a difference between revisions unless each was run many times.

Fix status. Upstream merged Marvisak/VIctory#1159 (121412b). It checks unwind() against known caller frames and only compares with the system walk when that walk returned frames. That commit is already in this fork's open upstream-sync PR #653. #411 proposed the stricter headroom fix (559756c) here and was closed in favour of the upstream one.

Diagnostic for @⁠Demon12377. Could you share your Windows build and ntdll version? Could you also run this patch on 3973179 about 20 times, plus a matching count on f85101b? It is an extra 10 lines in the test, keeps the assertion, and prints the stack gap and whether an immediate retry succeeds:

             let mut walked = [null_mut(); 8];
+            let (rsp, before): (usize, usize);
+            std::arch::asm!("mov {}, rsp", "mov {}, gs:[0x10]", out(reg) rsp, out(reg) before);
             let n = RtlCaptureStackBackTrace(0, 8, walked.as_mut_ptr(), null_mut());
+            let after: usize;
+            std::arch::asm!("mov {}, gs:[0x10]", out(reg) after);
+            let mut again = [null_mut(); 8];
+            let retry = RtlCaptureStackBackTrace(0, 8, again.as_mut_ptr(), null_mut());
+            eprintln!(
+                "n={n} retry={retry} rsp-StackLimit={:#x} StackLimit {before:#x} -> {after:#x}",
+                rsp - before
+            );
cargo test -p victory-loader --locked crash::tests::unwinds_like_the_system_walk -- --exact --test-threads=1 --nocapture

If you see n=0 retry=8, a small rsp-StackLimit and StackLimit dropping by 0x1000 when it fails, it's #742. Here, in 8 runs of the real test (5 debug, 3 release), rsp-StackLimit was 0x120–0x940. In 6 of those runs StackLimit dropped by 0x1000 during that very call, and it still returned n=8 retry=8. So the test does hit the guard page on Windows 11 26200 too; this build's walk just doesn't give up when it does.

I'm not opening a PR because I couldn't get a failing case on this machine.

AI use: Claude Code (Claude Opus 5.5).

**@⁠KainanP** on GitHub · 2026-11-25 18:16 UTC · [original](https://github.com/fxceless/victory-fork/issues/1012#issuecomment-7170689708) I couldn't reproduce this on Windows 11. It looks like the same failure as upstream Marvisak/VIctory#742, which has a measured root cause and an upstream fix. **Environment:** Windows 11 Home 10.0.26200.9974, ntdll.dll 10.0.26100.9974, Intel i7-14650HX, Rust 1.98.1 x86_64-pc-windows-msvc from `rust-toolchain.toml`, unmodified `origin/main` d510ee4, no extra RUSTFLAGS. | Run (fresh process each) | Debug | Release | |---|---:|---:| | test binary, `crash::tests::unwinds_like_the_system_walk --exact --test-threads=1` | 100/100 pass | 100/100 pass | | `cargo test -p victory-loader --locked <same> -- --exact --test-threads=1` | 30/30 pass | 30/30 pass | | full `cargo test -p victory-loader --locked -- --test-threads=1` | 27 + 2 + 1 pass, 0 fail | 27 + 2 + 1 pass, 0 fail | **Likely cause (upstream #742).** On Windows 10 (19044/19045), DrTardis1963 measured that a fresh Rust test thread often starts only `0x260..0x6c0` bytes above `TEB.StackLimit`. When `RtlCaptureStackBackTrace` runs into the stack guard page partway through its walk, Windows moves `StackLimit` down by 0x1000 and the call returns 0 frames. A second call right after returns 8. Several people counted it on Windows 10, all with Rust 1.98.1, Intel and AMD: - 61/100 and 52/100 empty walks (debug/release) - 22 of 25 runs failed - 19 of 40 runs failed - 69 of 100 runs failed - 12 of 20 runs failed Touching 4 KiB of stack before the walk (`559756c`) brought this to 0 failures in every rerun. Our custom `unwind()` doesn't rely on that walk, so it still returns frames. Every Windows 11 report there passed. That matches what I see. A standalone probe (no game data) walked 300 fresh threads down through their guard page, debug and release, calling `RtlCaptureStackBackTrace(0, 8, …)` at each step. That was 13,038 calls, including 600 that moved `StackLimit` during the call. None returned 0, so on this build the walk survives the guard-page fault. fladit123's 26300 results above fit this too. Microsoft's [CaptureStackBackTrace/RtlCaptureStackBackTrace docs](https://learn.microsoft.com/en-us/windows/win32/debug/capturestackbacktrace) only say it returns "the number of captured frames". They don't say when it can return 0, and they don't say the function sets last-error, so `GetLastError` won't help here. The test's arguments are fine: `FramesToSkip = 0`, `FramesToCapture = 8`, well under the old 63-frame limit. **About "passes on f85101b".** Between f85101b and 3973179, `crash.rs`, `Cargo.lock`, the root/loader `Cargo.toml` and `rust-toolchain.toml` are unchanged, and the loader crate only changed in `console_insn*.rs`. Since Windows 10 fails this intermittently (roughly 45–90% of runs in the counts above), a passing f85101b run doesn't show a difference between revisions unless each was run many times. **Fix status.** Upstream merged Marvisak/VIctory#1159 (`121412b`). It checks `unwind()` against known caller frames and only compares with the system walk when that walk returned frames. That commit is already in this fork's open upstream-sync PR #653. #411 proposed the stricter headroom fix (`559756c`) here and was closed in favour of the upstream one. **Diagnostic for @⁠Demon12377.** Could you share your Windows build and ntdll version? Could you also run this patch on 3973179 about 20 times, plus a matching count on f85101b? It is an extra 10 lines in the test, keeps the assertion, and prints the stack gap and whether an immediate retry succeeds: ```diff let mut walked = [null_mut(); 8]; + let (rsp, before): (usize, usize); + std::arch::asm!("mov {}, rsp", "mov {}, gs:[0x10]", out(reg) rsp, out(reg) before); let n = RtlCaptureStackBackTrace(0, 8, walked.as_mut_ptr(), null_mut()); + let after: usize; + std::arch::asm!("mov {}, gs:[0x10]", out(reg) after); + let mut again = [null_mut(); 8]; + let retry = RtlCaptureStackBackTrace(0, 8, again.as_mut_ptr(), null_mut()); + eprintln!( + "n={n} retry={retry} rsp-StackLimit={:#x} StackLimit {before:#x} -> {after:#x}", + rsp - before + ); ``` ``` cargo test -p victory-loader --locked crash::tests::unwinds_like_the_system_walk -- --exact --test-threads=1 --nocapture ``` If you see `n=0 retry=8`, a small `rsp-StackLimit` and `StackLimit` dropping by `0x1000` when it fails, it's #742. Here, in 8 runs of the real test (5 debug, 3 release), `rsp-StackLimit` was 0x120–0x940. In 6 of those runs `StackLimit` dropped by 0x1000 during that very call, and it still returned `n=8 retry=8`. So the test does hit the guard page on Windows 11 26200 too; this build's walk just doesn't give up when it does. I'm not opening a PR because I couldn't get a failing case on this machine. _AI use: Claude Code (Claude Opus 5.5)._
Author
Owner

@⁠fladit123 on GitHub · 2026-11-25 19:27 UTC · original

Thanks @⁠KainanP for the thorough independent investigation. Your Windows 11 results are consistent with mine, particularly the successful captures during StackLimit changes.

The Windows-version-dependent behavior looks like a strong lead. I agree that the original reporter's Windows build, ntdll version and immediate-retry results would help distinguish this from a revision-specific regression.

Given the existing upstream fix in #653, I will hold off on proposing a separate patch.

**@⁠fladit123** on GitHub · 2026-11-25 19:27 UTC · [original](https://github.com/fxceless/victory-fork/issues/1012#issuecomment-7172333285) Thanks @⁠KainanP for the thorough independent investigation. Your Windows 11 results are consistent with mine, particularly the successful captures during StackLimit changes. The Windows-version-dependent behavior looks like a strong lead. I agree that the original reporter's Windows build, ntdll version and immediate-retry results would help distinguish this from a revision-specific regression. Given the existing upstream fix in #653, I will hold off on proposing a separate patch.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/fxceless--victory-fork#1012
No description provided.