The stack walk checks memory before it reads it, so VICTORY_PROFILE no longer crashes the game (VICTORY_UNWIND_CHECKS=0 for the old walk) #343

Open
github-bot wants to merge 1 commit from github-bot/gh-343 into rx9070xt AGit
Owner

@⁠thejacte on GitHub · 2026-11-26 21:17 UTC · original
thejacte:codex/rx9070xt-profile-unwind → rx9070xt · +450 −15 · 2 files · 1 commits · open

On an RX 9070 XT, VICTORY_PROFILE crashed the game after about 4 minutes. The access violation was in unwind_into: the profiler walks the stacks of suspended threads with RtlVirtualUnwind, and a bad RIP or RSP in a sample makes it read memory that isn't there. The crash report and VICTORY_STACKS use the same walk.

With VICTORY_UNWIND_CHECKS on (the default), each step of the walk checks first:

  • RIP is in committed, executable image memory, and the function entry belongs to that image;
  • the unwind record, any chained records, and the stack span they describe can be read, and that span is inside the thread's stack;
  • the PC is not on an epilogue instruction (pop, add rsp, lea rsp), where Windows would simulate the epilogue from the code instead of the record;
  • RSP grows from frame to frame.

A record it can't bound (unknown opcodes, version-2 epilogue codes) ends the walk early rather than guessing. Memory is read through ReadProcessMemory, which returns an error instead of faulting.

Code without unwind data still gets the leaf rule (return address at RSP), but only at the first frame. That keeps the caller of a crash inside our own thunks and stubs, which are VirtualAlloc'd and so not image memory.

VICTORY_UNWIND_CHECKS=0 gives the old walk. The switch is read once, before title code runs, so the exception handler never reads the environment.

Measured (Windows 11, RX 9070 XT, driver 32.0.32029.2010, Ryzen 7 9800X3D, 64 GB), rx9070xt at cd8dfc0, diagnostics build:

Old walk With the checks
VICTORY_PROFILE over a 9-minute window crashed after ~4 min full window, ~52,000 stacks, ~20 frames deep, no crash

One thing to know: each frame now costs about ten VirtualQuery/ReadProcessMemory calls, so a sampled thread stays suspended longer than before (not measured yet). If that skews profiles, a follow-up can remember each image's ranges once per walk.

Tests (crates/victory-loader/src/crash.rs), all on synthetic unwind records and the test's own stack:

  • the parser bounds allocations, saves (near, far, XMM) and machine frames, and reads a chained entry after the padded code array;
  • it refuses records whose stack use it can't bound;
  • the walk stops at a PC outside an image, and keeps the caller when the first frame is in executable memory outside an image;
  • the existing unwinds_like_the_system_walk runs the checked walk over real frames.

Checked:

  • cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features: no new warnings. Checked with #341's four lines applied, since rx9070xt fails both without them.
  • cargo test --workspace --locked --no-fail-fast: passes, except emit::size_tests::the_record_count_of_a_structured_buffer_read_by_index, the AMD compiler crash that #339 works around.
  • cargo xtask policy: passes.

Written with Codex; reviewed by Claude Code (a rust-reviewer pass against upstream/rx9070xt, whose one finding, about the first frame in our own stubs, is fixed here).

🤖 Generated with Claude Code

**@⁠thejacte** on GitHub · 2026-11-26 21:17 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/343) `thejacte:codex/rx9070xt-profile-unwind` → `rx9070xt` · +450 −15 · 2 files · 1 commits · open On an RX 9070 XT, `VICTORY_PROFILE` crashed the game after about 4 minutes. The access violation was in `unwind_into`: the profiler walks the stacks of suspended threads with `RtlVirtualUnwind`, and a bad RIP or RSP in a sample makes it read memory that isn't there. The crash report and `VICTORY_STACKS` use the same walk. With `VICTORY_UNWIND_CHECKS` on (the default), each step of the walk checks first: - RIP is in committed, executable image memory, and the function entry belongs to that image; - the unwind record, any chained records, and the stack span they describe can be read, and that span is inside the thread's stack; - the PC is not on an epilogue instruction (`pop`, `add rsp`, `lea rsp`), where Windows would simulate the epilogue from the code instead of the record; - RSP grows from frame to frame. A record it can't bound (unknown opcodes, version-2 epilogue codes) ends the walk early rather than guessing. Memory is read through `ReadProcessMemory`, which returns an error instead of faulting. Code without unwind data still gets the leaf rule (return address at RSP), but only at the first frame. That keeps the caller of a crash inside our own thunks and stubs, which are `VirtualAlloc`'d and so not image memory. `VICTORY_UNWIND_CHECKS=0` gives the old walk. The switch is read once, before title code runs, so the exception handler never reads the environment. **Measured** (Windows 11, RX 9070 XT, driver 32.0.32029.2010, Ryzen 7 9800X3D, 64 GB), `rx9070xt` at cd8dfc0, diagnostics build: | | Old walk | With the checks | |---|---|---| | `VICTORY_PROFILE` over a 9-minute window | crashed after ~4 min | full window, ~52,000 stacks, ~20 frames deep, no crash | **One thing to know:** each frame now costs about ten `VirtualQuery`/`ReadProcessMemory` calls, so a sampled thread stays suspended longer than before (not measured yet). If that skews profiles, a follow-up can remember each image's ranges once per walk. **Tests** (`crates/victory-loader/src/crash.rs`), all on synthetic unwind records and the test's own stack: - the parser bounds allocations, saves (near, far, XMM) and machine frames, and reads a chained entry after the padded code array; - it refuses records whose stack use it can't bound; - the walk stops at a PC outside an image, and keeps the caller when the first frame is in executable memory outside an image; - the existing `unwinds_like_the_system_walk` runs the checked walk over real frames. **Checked:** - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same with `--all-features`: no new warnings. Checked with #341's four lines applied, since `rx9070xt` fails both without them. - `cargo test --workspace --locked --no-fail-fast`: passes, except `emit::size_tests::the_record_count_of_a_structured_buffer_read_by_index`, the AMD compiler crash that #339 works around. - `cargo xtask policy`: passes. Written with Codex; reviewed by Claude Code (a rust-reviewer pass against `upstream/rx9070xt`, whose one finding, about the first frame in our own stubs, is fixed here). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The profiler walks the stacks of suspended threads with RtlVirtualUnwind,
and a bad RIP or RSP in a sample made it read unmapped memory: the game
crashed after about 4 minutes of VICTORY_PROFILE. With
VICTORY_UNWIND_CHECKS on (the default), each step first checks that RIP
is in executable image memory, that the unwind records and the stack span
they describe are readable and inside the thread's stack, that the PC is
not on an epilogue instruction, and that RSP grows. A record it cannot
bound ends the walk. The leaf rule is kept for the first frame only, also
in our own VirtualAlloc'd stubs. VICTORY_UNWIND_CHECKS=0 gives the old
walk; the switch is read once, before title code runs.

Co-Authored-By: Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:58:00 +00:00
Author
Owner

@⁠JonyWater on GitHub · 2026-11-26 21:23 UTC · original

Review notes by Claude

Thanks for this. Bounding every read before RtlVirtualUnwind touches it is a clean fix, and I checked the UNWIND_INFO parsing (slot counts, scaling, the padded chained entry, overflow checks) without finding problems. Some things I'd like settled before merge:

Before merge

  • CI hasn't run. The workflow on acbeb30 is waiting for maintainer approval, so clippy and tests haven't been checked by CI yet.
  • Merge order. The description says clippy needs #341 and one test fails until #339 lands. It's probably best to merge those first, then rebase this so CI is green on its own.

Questions

  • Version-2 records with UWOP_EPILOG codes end the walk. Recent MSVC output, and I believe many Windows system DLLs, use these records. If so, threads paused in system code (waits, for example) would come back 1–3 frames deep. Do you know how often walks stop at this rule in the 52k-stack run?

  • Truncation is silent. A walk also stops early when:

    • the PC is on an epilogue instruction;
    • the PC is in a partial prologue whose frame register doesn't yet point into the stack;
    • a chained record pushes or allocates.

    All of these yield a short stack that looks like a real one, which can skew a profile. Could the walk count (or tag) stacks it stopped because of a check, so we can see how often that happens?

  • Suspension time. You mention about 10 VirtualQuery/ReadProcessMemory calls per frame. Could you add a before/after number for how long a sampled thread stays suspended? If it's significant, the per-walk cache of image ranges you suggest seems worth doing here.

Minor

  • stops_at_a_pc_outside_an_image sets RIP to a stack address, so it really tests "not executable" rather than "executable but outside an image". The stub test covers the second case. Maybe rename it, or add a case for executable memory outside an image beyond the first frame.
  • Another thread can still unload a DLL between the VirtualQuery check and RtlVirtualUnwind's read. That's rare, and probably fine to leave, but worth a comment.
**@⁠JonyWater** on GitHub · 2026-11-26 21:23 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/343#issuecomment-7203683865) ## Review notes by Claude Thanks for this. Bounding every read before `RtlVirtualUnwind` touches it is a clean fix, and I checked the UNWIND_INFO parsing (slot counts, scaling, the padded chained entry, overflow checks) without finding problems. Some things I'd like settled before merge: **Before merge** - **CI hasn't run.** The workflow on `acbeb30` is waiting for maintainer approval, so clippy and tests haven't been checked by CI yet. - **Merge order.** The description says clippy needs #341 and one test fails until #339 lands. It's probably best to merge those first, then rebase this so CI is green on its own. **Questions** - **Version-2 records with UWOP_EPILOG codes end the walk.** Recent MSVC output, and I believe many Windows system DLLs, use these records. If so, threads paused in system code (waits, for example) would come back 1–3 frames deep. Do you know how often walks stop at this rule in the 52k-stack run? - **Truncation is silent.** A walk also stops early when: - the PC is on an epilogue instruction; - the PC is in a partial prologue whose frame register doesn't yet point into the stack; - a chained record pushes or allocates. All of these yield a short stack that looks like a real one, which can skew a profile. Could the walk count (or tag) stacks it stopped because of a check, so we can see how often that happens? - **Suspension time.** You mention about 10 `VirtualQuery`/`ReadProcessMemory` calls per frame. Could you add a before/after number for how long a sampled thread stays suspended? If it's significant, the per-walk cache of image ranges you suggest seems worth doing here. **Minor** - `stops_at_a_pc_outside_an_image` sets RIP to a stack address, so it really tests "not executable" rather than "executable but outside an image". The stub test covers the second case. Maybe rename it, or add a case for executable memory outside an image beyond the first frame. - Another thread can still unload a DLL between the `VirtualQuery` check and `RtlVirtualUnwind`'s read. That's rare, and probably fine to leave, but worth a comment.
Author
Owner

@⁠JonyWater on GitHub · 2026-11-26 21:30 UTC · original

Follow-up (review notes by Claude): I checked my version-2 question on a Windows 11 machine, and it's mostly a non-issue. Records the checked walk would reject (v2 with UWOP_EPILOG): ntdll 70/4,136 (1.7%), KernelBase 0/3,529, kernel32 0/760, d3d12 0/241, ucrtbase 2/2,799. The ntdll ones are mostly the *_s string helpers, RtlInterlocked*SList, __chkstk and KiUserExceptionDispatcher. No wait functions, so threads paused in waits keep their full stacks. I haven't checked the title's own binaries. The other questions (counting truncated walks, suspension time) still stand.

We're still reviewing the rest of the PR in more depth and will follow up with anything else we find.

**@⁠JonyWater** on GitHub · 2026-11-26 21:30 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/343#issuecomment-7203794522) **Follow-up (review notes by Claude):** I checked my version-2 question on a Windows 11 machine, and it's mostly a non-issue. Records the checked walk would reject (v2 with UWOP_EPILOG): ntdll 70/4,136 (1.7%), KernelBase 0/3,529, kernel32 0/760, d3d12 0/241, ucrtbase 2/2,799. The ntdll ones are mostly the `*_s` string helpers, `RtlInterlocked*SList`, `__chkstk` and `KiUserExceptionDispatcher`. No wait functions, so threads paused in waits keep their full stacks. I haven't checked the title's own binaries. The other questions (counting truncated walks, suspension time) still stand. We're still reviewing the rest of the PR in more depth and will follow up with anything else we find.
Author
Owner

@⁠JonyWater on GitHub · 2026-11-26 21:38 UTC · original

Review notes by Claude: deeper pass

One regression in crash reports: a bad instruction pointer loses its caller. For a call through a null or garbage function pointer (or a jump into data that DEP blocks), the faulting RIP isn't executable. On rx9070xt, unwind_into found no function entry, applied the leaf rule, and read the caller's return address at [rsp], which is usually the most useful line in the report. With checks on, readable_region/executable fails at the first step and the walk breaks, so the report shows only the bad address. stops_at_a_pc_outside_an_image asserts this one-frame result. Profiles aren't affected (a suspended thread's RIP is real code).

Suggested fix: let the first frame take the leaf rule whatever RIP points at. [rsp] is already read through ReadProcessMemory, and the next step checks that the recovered RIP is executable image code:

let code_image = if checks {
    match readable_region(context.Rip as usize) {
        Some(region) if executable(&region) && region.Type == MEM_IMAGE => {
            Some(region.AllocationBase as usize)
        }
        // Not image code: only the first frame takes the leaf rule
        // (a call through a bad pointer, or one of our stubs).
        _ if frames.len() == 1 => None,
        _ => break,
    }
} else {
    None
};

with a test like stops_at_a_pc_outside_an_image but RIP = 0, expecting frames.starts_with(&[0, pc]). The current test could move to a non-image PC at the second frame.

Not from this PR, but related: the clzero and write-site stubs (console_insn.rs, write_sites.rs) are VirtualAlloc'd and entered by jmp, not call. A sample inside one takes the leaf rule, but [rsp] there is the title function's local data, not a return address, so the second frame is junk. The old walk did the same. A real fix would unwind through the title function the stub stands in for. Possibly worth an issue.

Checked and fine:

  • No return address is left in our own non-image code: import stubs jmp to their handler, TLS thunks are leaves reached by call from the title, and the clzero/write-site stubs are jmp in and out. Samples inside any of them are first frames, which the checked walk accepts.
  • Chained records on Windows 11 (ntdll, KernelBase, kernel32, ucrtbase, user32, combase, d3d12): around 6,500 chained entries, none moves RSP, none changes the frame-register byte. AMD's amdxc64.dll: 3 of 47,155 records would be rejected. So the chain and version-2 rules barely bite on real binaries, and the "chained record pushes or allocates" case from my first comment doesn't come up in them.
  • The env switch is read before any thread is suspended, and both callers are updated. The walk's own reads go through VirtualQuery/ReadProcessMemory; RtlLookupFunctionEntry/RtlVirtualUnwind still read directly, after the PR bounds the ranges (though RtlVirtualUnwind's epilogue scan can read more code than the 8 bytes checked).

Correction to my earlier follow-up: "no wait functions" went by exported names only; 57 of the rejected ntdll functions are internal and unnamed.

The regression is confirmed by reading the old and new code side by side, not by a test run.

**@⁠JonyWater** on GitHub · 2026-11-26 21:38 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/343#issuecomment-7203917059) **Review notes by Claude: deeper pass** **One regression in crash reports: a bad instruction pointer loses its caller.** For a call through a null or garbage function pointer (or a jump into data that DEP blocks), the faulting RIP isn't executable. On `rx9070xt`, `unwind_into` found no function entry, applied the leaf rule, and read the caller's return address at `[rsp]`, which is usually the most useful line in the report. With checks on, `readable_region`/`executable` fails at the first step and the walk breaks, so the report shows only the bad address. `stops_at_a_pc_outside_an_image` asserts this one-frame result. Profiles aren't affected (a suspended thread's RIP is real code). Suggested fix: let the first frame take the leaf rule whatever RIP points at. `[rsp]` is already read through `ReadProcessMemory`, and the next step checks that the recovered RIP is executable image code: ```rust let code_image = if checks { match readable_region(context.Rip as usize) { Some(region) if executable(&region) && region.Type == MEM_IMAGE => { Some(region.AllocationBase as usize) } // Not image code: only the first frame takes the leaf rule // (a call through a bad pointer, or one of our stubs). _ if frames.len() == 1 => None, _ => break, } } else { None }; ``` with a test like `stops_at_a_pc_outside_an_image` but RIP = 0, expecting `frames.starts_with(&[0, pc])`. The current test could move to a non-image PC at the second frame. **Not from this PR, but related:** the `clzero` and write-site stubs (`console_insn.rs`, `write_sites.rs`) are `VirtualAlloc`'d and entered by `jmp`, not `call`. A sample inside one takes the leaf rule, but `[rsp]` there is the title function's local data, not a return address, so the second frame is junk. The old walk did the same. A real fix would unwind through the title function the stub stands in for. Possibly worth an issue. **Checked and fine:** - No return address is left in our own non-image code: import stubs `jmp` to their handler, TLS thunks are leaves reached by `call` from the title, and the `clzero`/write-site stubs are `jmp` in and out. Samples inside any of them are first frames, which the checked walk accepts. - Chained records on Windows 11 (ntdll, KernelBase, kernel32, ucrtbase, user32, combase, d3d12): around 6,500 chained entries, none moves RSP, none changes the frame-register byte. AMD's `amdxc64.dll`: 3 of 47,155 records would be rejected. So the chain and version-2 rules barely bite on real binaries, and the "chained record pushes or allocates" case from my first comment doesn't come up in them. - The env switch is read before any thread is suspended, and both callers are updated. The walk's own reads go through `VirtualQuery`/`ReadProcessMemory`; `RtlLookupFunctionEntry`/`RtlVirtualUnwind` still read directly, after the PR bounds the ranges (though `RtlVirtualUnwind`'s epilogue scan can read more code than the 8 bytes checked). Correction to my earlier follow-up: "no wait functions" went by exported names only; 57 of the rejected ntdll functions are internal and unnamed. _The regression is confirmed by reading the old and new code side by side, not by a test run._
Author
Owner

@⁠thejacte on GitHub · 2026-11-26 22:54 UTC · original

Thanks, good catch. Since #343 is already merged into a-publier, the fix is in #378, the way you suggested: the first frame takes the leaf rule whatever RIP points at. It also covers one more edge case, a caller whose return address is the stack's last word. The clzero/write-site stub note is left for its own issue.

**@⁠thejacte** on GitHub · 2026-11-26 22:54 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/343#issuecomment-7205083474) Thanks, good catch. Since #343 is already merged into a-publier, the fix is in #378, the way you suggested: the first frame takes the leaf rule whatever RIP points at. It also covers one more edge case, a caller whose return address is the stack's last word. The `clzero`/write-site stub note is left for its own issue.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-27 06:25 UTC · original

Tested on RX 7900 XT (RDNA3), driver 32.0.32029.2010, Windows 11 26300, Rust 1.98.1. a-publier at 4eb6cfd (contains this PR as d6f95b2), cargo test --profile diag -p victory-loader --features diagnostics. CPU only. No game run: the title was not launched. This is a follow-up on the merged code, on the suspension-time question above. #378 does not change this path.

Suspension time, checked walk vs VICTORY_UNWIND_CHECKS=0 (medians of 5 interleaved rounds; other load was on the machine, so compare ratios, not absolute times):

  • stacks::frames_of in the test binary, 10k calls, thread 12 calls deep: waiting thread 11.3 us -> 257.5 us (about 23x, 22 frames); spinning thread 12.6 us -> 332.9 us (about 26x, 18 frames). p99 20-29 us -> 415-570 us.
  • Walk alone, same suspended context: about 0.1 us -> about 17 us per frame.
  • Title model: the title exe mapped as a read-only image resource (not executed), its 97,534 KiB code section set to WRITECOPY so it is one region, as in a loaded image. Per frame at 3,990 of its function records: old walk 195 ns, checked walk 526 us (about 2,700x).
  • So a 20-frame stack that is mostly in title code stays suspended for roughly 10 ms, against about 10 us before. With up to 28 threads per round (BUSIEST in profile.rs), one round takes about 0.3 s, for any <ms> interval below that.
  • If the ~52,000 stacks over 9 minutes are samples and not distinct stack lines, that is about 96 per second, one every 10.4 ms. That fits a sampler bound by the walk. This is an inference, not measured.

Cause: VirtualQuery on image code gets slower with the distance from the queried page to the end of its region, once those pages are mapped in.

  • Test exe code: 4.6 us with 884 KiB to the region end, 0.7 us with 12 KiB.
  • Title code section: one query at a function start costs 135-196 us median, 267-458 us p90. Before its pages were touched or reprotected, the same mapping answered in 7-12 us even 180 MB from the region end.
  • Each title frame queries the code section twice: readable_region(rip), then read_image of the 8 bytes at the PC. The record and unwind-info reads add at least three more image queries per frame (not timed separately).
  • The other calls are small: stack VirtualQuery 0.46-0.8 us, 8-byte ReadProcessMemory 0.44 us, RtlLookupFunctionEntry 20 ns.

What a cache would save (estimate from the per-call costs above, not measured):

  • Per-walk cache of the regions VirtualQuery returns: helps only partly. A returned region starts at the queried page, so it only covers higher addresses. It removes the second code query of a frame, since the PC bytes are in the region just returned, but a frame at a lower address still pays a full query.
  • Image ranges read once from each loaded image's section headers, with ReadProcessMemory alone as the fault guard: no image queries are left. What remains per frame is about four small reads, one stack query and RtlVirtualUnwind, about 3 us. That is about 60 us for a 20-frame title stack, against about 10 ms now and about 10 us for the old walk.

Title records and truncation (asked above):

  • Title exe: 299,257 exception-directory entries, all version 1, no UWOP_EPILOG codes. The record and chain rules refuse 0 of them. 515 have chained records, longest chain 3.
  • In memory, stack_reads_end refused 1 of 3,991 sampled title records, through the epilogue-instruction rule.
  • Paired walks in the test binary: the checked stack was never different from the old one, only sometimes a prefix.
    • Spinning thread: 0/10,000 truncated.
    • Waiting thread (park_timeout): 4 to 158 per 10,000, depending on the run.
    • Every truncation in the second run was the epilogue rule at frame 1, in the test exe's park path and at one ntdll PC. It ends the walk after 1 of 19-40 frames.
  • So the record and chain rules do not truncate title stacks. What is left are the rules that depend on the PC and registers (epilogue instruction, frame register in a partial prologue) and the stack checks. Their rate needs PCs sampled from the running title.

#378 at 01d3f8c: crash:: and stacks:: pass 27/27, with VICTORY_UNWIND_CHECKS unset and with it set to 0.

Not tested:

  • No in-game profile run. Runtime patches (write sites, VirtualProtect) may split the code section into smaller regions in the real process, which would make the queries cheaper than in this model.
  • No cache implementation.
**@⁠adrianmjim** on GitHub · 2026-11-27 06:25 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/343#issuecomment-7211518106) Tested on RX 7900 XT (RDNA3), driver 32.0.32029.2010, Windows 11 26300, Rust 1.98.1. a-publier at 4eb6cfd (contains this PR as d6f95b2), `cargo test --profile diag -p victory-loader --features diagnostics`. CPU only. No game run: the title was not launched. This is a follow-up on the merged code, on the suspension-time question above. #378 does not change this path. **Suspension time, checked walk vs `VICTORY_UNWIND_CHECKS=0`** (medians of 5 interleaved rounds; other load was on the machine, so compare ratios, not absolute times): - `stacks::frames_of` in the test binary, 10k calls, thread 12 calls deep: waiting thread 11.3 us -> 257.5 us (about 23x, 22 frames); spinning thread 12.6 us -> 332.9 us (about 26x, 18 frames). p99 20-29 us -> 415-570 us. - Walk alone, same suspended context: about 0.1 us -> about 17 us per frame. - Title model: the title exe mapped as a read-only image resource (not executed), its 97,534 KiB code section set to WRITECOPY so it is one region, as in a loaded image. Per frame at 3,990 of its function records: old walk 195 ns, checked walk 526 us (about 2,700x). - So a 20-frame stack that is mostly in title code stays suspended for roughly 10 ms, against about 10 us before. With up to 28 threads per round (`BUSIEST` in profile.rs), one round takes about 0.3 s, for any `<ms>` interval below that. - If the ~52,000 stacks over 9 minutes are samples and not distinct stack lines, that is about 96 per second, one every 10.4 ms. That fits a sampler bound by the walk. This is an inference, not measured. **Cause:** `VirtualQuery` on image code gets slower with the distance from the queried page to the end of its region, once those pages are mapped in. - Test exe code: 4.6 us with 884 KiB to the region end, 0.7 us with 12 KiB. - Title code section: one query at a function start costs 135-196 us median, 267-458 us p90. Before its pages were touched or reprotected, the same mapping answered in 7-12 us even 180 MB from the region end. - Each title frame queries the code section twice: `readable_region(rip)`, then `read_image` of the 8 bytes at the PC. The record and unwind-info reads add at least three more image queries per frame (not timed separately). - The other calls are small: stack `VirtualQuery` 0.46-0.8 us, 8-byte `ReadProcessMemory` 0.44 us, `RtlLookupFunctionEntry` 20 ns. **What a cache would save** (estimate from the per-call costs above, not measured): - Per-walk cache of the regions `VirtualQuery` returns: helps only partly. A returned region starts at the queried page, so it only covers higher addresses. It removes the second code query of a frame, since the PC bytes are in the region just returned, but a frame at a lower address still pays a full query. - Image ranges read once from each loaded image's section headers, with `ReadProcessMemory` alone as the fault guard: no image queries are left. What remains per frame is about four small reads, one stack query and `RtlVirtualUnwind`, about 3 us. That is about 60 us for a 20-frame title stack, against about 10 ms now and about 10 us for the old walk. **Title records and truncation** (asked above): - Title exe: 299,257 exception-directory entries, all version 1, no UWOP_EPILOG codes. The record and chain rules refuse 0 of them. 515 have chained records, longest chain 3. - In memory, `stack_reads_end` refused 1 of 3,991 sampled title records, through the epilogue-instruction rule. - Paired walks in the test binary: the checked stack was never different from the old one, only sometimes a prefix. - Spinning thread: 0/10,000 truncated. - Waiting thread (`park_timeout`): 4 to 158 per 10,000, depending on the run. - Every truncation in the second run was the epilogue rule at frame 1, in the test exe's park path and at one ntdll PC. It ends the walk after 1 of 19-40 frames. - So the record and chain rules do not truncate title stacks. What is left are the rules that depend on the PC and registers (epilogue instruction, frame register in a partial prologue) and the stack checks. Their rate needs PCs sampled from the running title. #378 at 01d3f8c: `crash::` and `stacks::` pass 27/27, with `VICTORY_UNWIND_CHECKS` unset and with it set to 0. Not tested: - No in-game profile run. Runtime patches (write sites, `VirtualProtect`) may split the code section into smaller regions in the real process, which would make the queries cheaper than in this model. - No cache implementation.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/343/head:github-bot/gh-343'
git switch 'github-bot/gh-343'

Merge

Merge the changes and update on Forgejo.
git switch 'rx9070xt'
git merge --no-ff 'github-bot/gh-343'
git switch 'github-bot/gh-343'
git rebase 'rx9070xt'
git switch 'rx9070xt'
git merge --ff-only 'github-bot/gh-343'
git switch 'github-bot/gh-343'
git rebase 'rx9070xt'
git switch 'rx9070xt'
git merge --no-ff 'github-bot/gh-343'
git switch 'rx9070xt'
git merge --squash 'github-bot/gh-343'
git switch 'rx9070xt'
git merge --ff-only 'github-bot/gh-343'
git switch 'rx9070xt'
git merge 'github-bot/gh-343'
git push origin 'rx9070xt'
This discussion has been locked. Commenting is limited to contributors.
No description provided.