Profiler: unwind a copy of the sampled thread's stack (VICTORY_PROFILE no longer crashes the title) #1224

Manually merged
github merged 1 commit from github-bot/gh-1224 into main 2026-11-29 08:22:18 +00:00 AGit
Owner

@⁠KelvinSilvaDev on GitHub · 2026-11-28 15:56 UTC · original
KelvinSilvaDev:fix/profiler-stack-copy → main · +172 −11 · 2 files · 1 commits · merged 2026-11-29 08:16 UTC

VICTORY_PROFILE crashed the process about when sampling began (twice in a row): an access violation inside ntdll (read 0x10067: nothing mapped there, then read …: reserved, never committed), from victory_loader::stacks::frames_of → victory_loader::crash::unwind_into → RtlVirtualUnwind. Unwinding a live, just-suspended thread with the unwind data can make RtlVirtualUnwind read through a frame register holding anything (after a step taken by rsp), or stack pages the thread never committed.

What changes (2 files, +172/-11: crates/victory-loader/src/crash.rs, crates/victory-loader/src/stacks.rs):

  • frames_of copies the thread's stack (from rsp up, at most 512 KiB, zeros after) with ReadProcessMemory while the thread is suspended (the kernel fails where memory is missing instead of faulting; the buffer is made before the suspend), resumes the thread, and unwinds the copy (crash::unwind_copy): stack registers that point into the copied range are moved into the copy, and a frame register that points elsewhere ends the walk.
  • unwind_into (the crash handler's live walk) stops where a function that keeps a frame register has it outside the thread's stack, instead of letting RtlVirtualUnwind read through it.

Validation (Windows 11, RTX 3090, Ryzen 7 7700):

  • Before: VICTORY_PROFILE=100,340,5,<file> on a diagnostics build ended the title at 100 s both times.
  • After: the same window ran to the end, ~38,000 samples of the submitting thread, symbolized with dbghelp against the build's PDB; then two more profiled runs with no crash.
  • cargo clippy --locked -p victory-loader --features diagnostics: no warnings. cargo test --locked -p victory-loader --features diagnostics --lib: 48 passed. cargo build --locked --profile diag -p victory --features diagnostics: ok.
  • Not run: the full workspace suite. cargo fmt --check already reports files this PR does not touch, so the changed code follows the style around it.

AI-assisted (Claude). No game data, no NVIDIA files.

🤖 Generated with Claude Code

**@⁠KelvinSilvaDev** on GitHub · 2026-11-28 15:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1224) `KelvinSilvaDev:fix/profiler-stack-copy` → `main` · +172 −11 · 2 files · 1 commits · merged 2026-11-29 08:16 UTC `VICTORY_PROFILE` crashed the process about when sampling began (twice in a row): an access violation inside ntdll (`read 0x10067: nothing mapped there`, then `read …: reserved, never committed`), from `victory_loader::stacks::frames_of` → `victory_loader::crash::unwind_into` → `RtlVirtualUnwind`. Unwinding a live, just-suspended thread with the unwind data can make `RtlVirtualUnwind` read through a frame register holding anything (after a step taken by `rsp`), or stack pages the thread never committed. What changes (2 files, +172/-11: `crates/victory-loader/src/crash.rs`, `crates/victory-loader/src/stacks.rs`): - `frames_of` copies the thread's stack (from `rsp` up, at most 512 KiB, zeros after) with `ReadProcessMemory` while the thread is suspended (the kernel fails where memory is missing instead of faulting; the buffer is made before the suspend), resumes the thread, and unwinds the copy (`crash::unwind_copy`): stack registers that point into the copied range are moved into the copy, and a frame register that points elsewhere ends the walk. - `unwind_into` (the crash handler's live walk) stops where a function that keeps a frame register has it outside the thread's stack, instead of letting `RtlVirtualUnwind` read through it. Validation (Windows 11, RTX 3090, Ryzen 7 7700): - Before: `VICTORY_PROFILE=100,340,5,<file>` on a diagnostics build ended the title at 100 s both times. - After: the same window ran to the end, ~38,000 samples of the submitting thread, symbolized with dbghelp against the build's PDB; then two more profiled runs with no crash. - `cargo clippy --locked -p victory-loader --features diagnostics`: no warnings. `cargo test --locked -p victory-loader --features diagnostics --lib`: 48 passed. `cargo build --locked --profile diag -p victory --features diagnostics`: ok. - Not run: the full workspace suite. `cargo fmt --check` already reports files this PR does not touch, so the changed code follows the style around it. AI-assisted (Claude). No game data, no NVIDIA files. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VICTORY_PROFILE ended the process about when sampling began: an access
violation inside ntdll from stacks::frames_of -> crash::unwind_into ->
RtlVirtualUnwind, reading through a frame register that held anything
(after a step taken by rsp) or stack pages the thread never committed.

frames_of now copies the stack (from rsp up, at most 512 KiB, zeros
after) with ReadProcessMemory while the thread is suspended, resumes it,
and unwinds the copy (crash::unwind_copy): stack registers that point
into the copied range are moved into the copy, and a frame register that
points elsewhere ends the walk. unwind_into, the crash handler's live
walk, stops where a frame register lies outside the thread's stack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 15:59:22 +00:00
github manually merged commit 2bc81df8d9 into main 2026-11-29 08:22:18 +00:00
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/trustno1-coder--VIctory-NVIDIA!1224
No description provided.