fix(prof): a stack walk that faults cuts its sample short instead of ending the game #2790

Merged
HumanBean merged 2 commits from HumanBean/Longshot:fix/prof-walk-fault into main 2026-11-29 17:09:51 +00:00
Owner

Summary

With profiling on (HOS_PROFILE=1, HOS_SAMPLE, HOS_SAMPLE_ALL, HOS_SLOW_FRAMES), the game could crash on Linux. Linux's thread sampler (host/posix/prof.c) walks each thread's stack from a signal, with libgcc's unwinder, starting from whatever instruction the thread was stopped on. Where the unwind data doesn't hold at that instruction (a driver's code, a function's prologue), the unwinder reads through a bad frame and faults. On an RX 580 (Mesa RADV, CachyOS) it took the game down twice in one evening of profiling:

  • CRASH: exception 0xc0000005 (read 0xc) at libgcc_s.so.1+0x27869, which is _Unwind_Backtrace + 201, on mkw_vk recorder. Its last samples were inside libvulkan_radeon.so.
  • CRASH: exception 0xc0000005 (read 0) at libgcc_s.so.1+0x26617, inside libgcc's unwinder, on BaseProcExecutor5.

Each crash then left a core dump of the game's ~10 GB of shared guest memory, which used up the PC's RAM for over ten minutes.

Now a fault during a walk jumps back to the sample that started it. walk_fault is the first vectored handler; it siglongjmps to on_sample, which keeps the frames found so far (the interrupted rip at least). The run goes on, and the log says so once: prof: a stack walk faulted (unwind data that does not hold there): its sample cut short, the run goes on. sampling_init now runs once through pthread_once, so when HOS_SAMPLE and HOS_SAMPLE_ALL start their samplers together, neither samples before the other has registered walk_fault and warmed up the unwinder. Windows already checks each step against the thread's stack (unwind_step, tests/test_sampler_stack_walk.py), so this brings Linux's walk to the same footing.

Read first: host/posix/prof.c (walk_fault, on_sample), then tests/test_prof_walk_fault.py.

Testing

Tested:

  • tests/test_prof_walk_fault.py compiles prof.c's own sampling code, from "one thread's stack, taken inside it" through sampling_init, with the C compiler run_all.py gives it ({cc}; CC, else cc, on its own). The test starts a thread spinning in a function whose unwind data names a bad frame and sets up with sampling_init. A fault goes only to the vectored handlers sampling_init registered, as win32_posix.c's on_signal sends it. The test then samples the thread 200 times the way sample_one does and needs every sample back with the process alive. Both gcc and clang were checked.
    • On the test commit (main's prof.c), the first sample kills the process: a walk through bad unwind data took the process down (signal 11).
    • On the fix it passes: PASS: 200 walks through bad unwind data, each sample back and the process alive.
    • With the fix but without its AddVectoredExceptionHandler(1, walk_fault) line, it fails.
  • A real build: dev.py pack on the shared base compiled longshot with this prof.c cleanly (Linux), including the pthread_once change.
  • In the game: Linux (CachyOS), AMD RX 580 8 GB, Mesa 26.2.6 RADV, i7-9700K. Build: main 894683cf with this branch (and #2789) merged. HOS_PROFILE=1 for 20.7 minutes of laps: warp to the Market, walk back into Hyrule Field, then forward for 30 s. No crash. The fault this handles happened once and was handled: the log has one prof: a stack walk faulted (unwind data that does not hold there): its sample cut short, the run goes on. perf.py report read the profile as before (45,019 frames). Without this fix, two profiled runs on the same PC crashed the same evening. (That run was before review moved sampling_init onto pthread_once. The compile and the test cover that change; it has not run in the game.)

Still to test: Profiling on Tier 1 Linux hardware (NVIDIA, a newer AMD, the Steam Deck). I don't have it; a Test Farm run would cover it.

Measurements

Nothing to measure: the change only matters when a stack walk faults, and costs a sigsetjmp per sample, which is a few nanoseconds next to the 2 ms interval.

Risks

  • A fault inside the unwinder while it holds a lock would leave the lock held. Both crashes seen were reads of the stack frames themselves, not of the unwinder's tables; glibc ≥ 2.35 finds frame data without a lock (_dl_find_object). The worst case is a hung sampler thread instead of a crashed game.
  • Only profiling runs are affected. Normal play never sends the sample signal.
  • Turning it off: revert the commit.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (Not run yet; the new test and a real build pass.)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary With profiling on (`HOS_PROFILE=1`, `HOS_SAMPLE`, `HOS_SAMPLE_ALL`, `HOS_SLOW_FRAMES`), the game could crash on Linux. Linux's thread sampler (`host/posix/prof.c`) walks each thread's stack from a signal, with libgcc's unwinder, starting from whatever instruction the thread was stopped on. Where the unwind data doesn't hold at that instruction (a driver's code, a function's prologue), the unwinder reads through a bad frame and faults. On an RX 580 (Mesa RADV, CachyOS) it took the game down twice in one evening of profiling: - `CRASH: exception 0xc0000005 (read 0xc) at libgcc_s.so.1+0x27869`, which is `_Unwind_Backtrace + 201`, on `mkw_vk recorder`. Its last samples were inside `libvulkan_radeon.so`. - `CRASH: exception 0xc0000005 (read 0) at libgcc_s.so.1+0x26617`, inside libgcc's unwinder, on `BaseProcExecutor5`. Each crash then left a core dump of the game's ~10 GB of shared guest memory, which used up the PC's RAM for over ten minutes. Now a fault during a walk jumps back to the sample that started it. `walk_fault` is the first vectored handler; it `siglongjmp`s to `on_sample`, which keeps the frames found so far (the interrupted rip at least). The run goes on, and the log says so once: `prof: a stack walk faulted (unwind data that does not hold there): its sample cut short, the run goes on`. `sampling_init` now runs once through `pthread_once`, so when `HOS_SAMPLE` and `HOS_SAMPLE_ALL` start their samplers together, neither samples before the other has registered `walk_fault` and warmed up the unwinder. Windows already checks each step against the thread's stack (`unwind_step`, `tests/test_sampler_stack_walk.py`), so this brings Linux's walk to the same footing. Read first: `host/posix/prof.c` (`walk_fault`, `on_sample`), then `tests/test_prof_walk_fault.py`. ## Testing **Tested:** - `tests/test_prof_walk_fault.py` compiles prof.c's own sampling code, from "one thread's stack, taken inside it" through `sampling_init`, with the C compiler run_all.py gives it (`{cc}`; `CC`, else `cc`, on its own). The test starts a thread spinning in a function whose unwind data names a bad frame and sets up with `sampling_init`. A fault goes only to the vectored handlers `sampling_init` registered, as `win32_posix.c`'s `on_signal` sends it. The test then samples the thread 200 times the way `sample_one` does and needs every sample back with the process alive. Both gcc and clang were checked. - On the test commit (main's prof.c), the first sample kills the process: `a walk through bad unwind data took the process down (signal 11)`. - On the fix it passes: `PASS: 200 walks through bad unwind data, each sample back and the process alive`. - With the fix but without its `AddVectoredExceptionHandler(1, walk_fault)` line, it fails. - A real build: `dev.py pack` on the shared base compiled `longshot` with this `prof.c` cleanly (Linux), including the `pthread_once` change. - **In the game:** Linux (CachyOS), AMD RX 580 8 GB, Mesa 26.2.6 RADV, i7-9700K. Build: main `894683cf` with this branch (and #2789) merged. `HOS_PROFILE=1` for **20.7 minutes** of laps: warp to the Market, walk back into Hyrule Field, then forward for 30 s. **No crash.** The fault this handles happened once and was handled: the log has one `prof: a stack walk faulted (unwind data that does not hold there): its sample cut short, the run goes on`. `perf.py report` read the profile as before (45,019 frames). Without this fix, two profiled runs on the same PC crashed the same evening. (That run was before review moved `sampling_init` onto `pthread_once`. The compile and the test cover that change; it has not run in the game.) **Still to test:** Profiling on Tier 1 Linux hardware (NVIDIA, a newer AMD, the Steam Deck). I don't have it; a Test Farm run would cover it. ## Measurements Nothing to measure: the change only matters when a stack walk faults, and costs a `sigsetjmp` per sample, which is a few nanoseconds next to the 2 ms interval. ## Risks - **A fault inside the unwinder while it holds a lock** would leave the lock held. Both crashes seen were reads of the stack frames themselves, not of the unwinder's tables; glibc ≥ 2.35 finds frame data without a lock (`_dl_find_object`). The worst case is a hung sampler thread instead of a crashed game. - **Only profiling runs are affected.** Normal play never sends the sample signal. - **Turning it off:** revert the commit. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (Not run yet; the new test and a real build pass.) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Linux's thread sampler walks each thread's stack from a signal with libgcc's
unwinder. Where the unwind data does not hold at the stopped instruction (a
driver's code, a prologue) the walk reads through a bad frame and the game
goes down mid-profile: twice in one evening on an RX 580 (Mesa RADV), in
_Unwind_Backtrace on mkw_vk recorder and inside libgcc on BaseProcExecutor5.

tests/test_prof_walk_fault.py compiles prof.c's sampling code with a thread
spinning in a function whose unwind data names a bad frame, and samples it
200 times. On this commit the first sample kills the process (SIGSEGV).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(prof): a stack walk that faults cuts its sample short instead of ending the game
Some checks failed
CI / What the change needs (pull_request) Successful in 9s
CI / Third-party parts and guide screenshots (pull_request) Successful in 14s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 12s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 1m57s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 3m37s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m55s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 5m6s
CI / Website build and checks (pull_request) Successful in 1m29s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m33s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39m50s
PR description / Title and description (pull_request_target) Successful in 5s
c06e8c2353
A fault while on_sample walks (unwind data that does not hold at the
interrupted instruction) now jumps back to the sample that started it:
walk_fault, the first vectored handler, siglongjmps to on_sample, which keeps
the frames found so far (the interrupted rip at least). The log says so once:
"prof: a stack walk faulted ...". HOS_PROFILE=1, HOS_SAMPLE, HOS_SAMPLE_ALL and
HOS_SLOW_FRAMES all sample through it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member

Possibly related, for context:

  • PR #1951 WIP: fix(host): the stack walks run clang's AVX return suffix themselves and every step under a fault guard — Open Windows stack-walk fault-guard work; overlaps the sampler safety problem, though different platform and code path.
  • issue #1584 HOS_SAMPLE_ALL still crashes the game on Windows after #1343: the fault is inside RtlVirtualUnwind, past unwind_step's checks — Open issue tracks profiler crashes from faults during stack unwinding; this is the Linux counterpart.
Possibly related, for context: - PR #1951 WIP: fix(host): the stack walks run clang's AVX return suffix themselves and every step under a fault guard — Open Windows stack-walk fault-guard work; overlaps the sampler safety problem, though different platform and code path. - issue #1584 HOS_SAMPLE_ALL still crashes the game on Windows after #1343: the fault is inside RtlVirtualUnwind, past unwind_step's checks — Open issue tracks profiler crashes from faults during stack unwinding; this is the Linux counterpart.
Author
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The fault recovery works in the reported RX 580 run, but concurrent sampler startup can send a sample before the recovery handler is installed. The regression test also bypasses the production registration, so it would pass if that essential line were removed.

This keeps a Linux profiling run alive when an unwind faults, preserving the frames collected so far. It adds signal-handler recovery and a synthetic fault test; normal play without sampling is unaffected.

Blocking (1): must change before merging.

  1. L1 host/posix/prof.c:225: The recovery handler is installed after the unsynchronized initialization guard has let another sampler proceed. (more on the line) Do: Use a once primitive that makes all sampler threads wait until signal setup, handler registration and unwinder warm-up have completed before sampling starts.

Should fix (3): not blocking, but worth doing before merging.

  • L2 tests/test_prof_walk_fault.py:109: The test excludes sampling_init and calls walk_fault directly from its substitute fault handler, bypassing the production registration. (more on the line) Do: Exercise production initialization and exception dispatch in the harness, including registration of walk_fault, so removing that registration makes the test fail.
  • L3 tests/test_prof_walk_fault.py:22: The test hard-codes clang instead of honoring the configured C compiler. (more on the line) Do: Use the runner's {cc} compiler and the repository's compiler-argument parsing convention, and honor CC for standalone runs.
  • L4 tests/test_prof_walk_fault.py:54: The test publishes spinner between threads using volatile accesses rather than atomic synchronization. (more on the line) Do: Publish and read the thread ID with atomic release and acquire operations.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 host/posix/prof.c:206: The Linux sampler change still needs a run on affected Tier 1 hardware. (more on the line) Do: Run profiling on representative Tier 1 Linux hardware, exercising sampling and confirming the game and profile remain usable.

@fix can do L1, L2, L3 and L4.

Checks: Failing on this head, which is behind its base, where they pass: CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request), CI / Game-free checks (run_all.py, part 1/2) (pull_request), CI / Game-free checks (run_all.py, part 2/2) (pull_request). @rebase (or @fix) brings it up to date and runs them again; not held against it.

More: does it help, other systems, switches, what was read

Does it help: Yes for the reported case: the author reports two crashes before the fix and one handled fault during a 20.7-minute RX 580 run with the fix. The synthetic test reportedly fails on the base and returns all 200 samples with the fix.

Other systems: The change runs on Linux for sampled threads regardless of GPU; Windows uses a separate sampler. The reported game run covers Mesa RADV on an RX 580, but does not cover Tier 1 Linux hardware or another Linux unwinder setup. Normal play without sampling does not enter the new walk path.

Switches: None added, changed or removed. Existing profiling switches enable the affected sampler.

Reviewed: c06e8c2353 against 3ab4db6e91: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, both changed files, the diff and commit messages; read the sampler callers and POSIX exception dispatch around the changes. Skimmed the test runner and profiling switch setup. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded runs, translations or generated files changed.; nothing run (a code review).

Checked and fine:

  • Both commits record AI assistance.
  • The diff contains no game-derived files, generated files or third-party changes.
  • The fault count is updated and read atomically, and the sample completion store publishes the collected frames.
  • The existing reported test and game run exercise a real unwind fault and recovery.

Testing: Read-only review; no builds, tests or project scripts were run. The PR reports a synthetic 200-sample test, a Linux build and an in-game RX 580 run.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The fault recovery works in the reported RX 580 run, but concurrent sampler startup can send a sample before the recovery handler is installed. The regression test also bypasses the production registration, so it would pass if that essential line were removed. This keeps a Linux profiling run alive when an unwind faults, preserving the frames collected so far. It adds signal-handler recovery and a synthetic fault test; normal play without sampling is unaffected. **Blocking (1)**: must change before merging. 1. **L1** `host/posix/prof.c:225`: The recovery handler is installed after the unsynchronized initialization guard has let another sampler proceed. (more on the line) **Do:** Use a once primitive that makes all sampler threads wait until signal setup, handler registration and unwinder warm-up have completed before sampling starts. **Should fix (3)**: not blocking, but worth doing before merging. - **L2** `tests/test_prof_walk_fault.py:109`: The test excludes sampling_init and calls walk_fault directly from its substitute fault handler, bypassing the production registration. (more on the line) **Do:** Exercise production initialization and exception dispatch in the harness, including registration of walk_fault, so removing that registration makes the test fail. - **L3** `tests/test_prof_walk_fault.py:22`: The test hard-codes clang instead of honoring the configured C compiler. (more on the line) **Do:** Use the runner's {cc} compiler and the repository's compiler-argument parsing convention, and honor CC for standalone runs. - **L4** `tests/test_prof_walk_fault.py:54`: The test publishes spinner between threads using volatile accesses rather than atomic synchronization. (more on the line) **Do:** Publish and read the thread ID with atomic release and acquire operations. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `host/posix/prof.c:206`: The Linux sampler change still needs a run on affected Tier 1 hardware. (more on the line) **Do:** Run profiling on representative Tier 1 Linux hardware, exercising sampling and confirming the game and profile remain usable. `@fix` can do L1, L2, L3 and L4. **Checks:** Failing on this head, which is behind its base, where they pass: `CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request)`, `CI / Game-free checks (run_all.py, part 1/2) (pull_request)`, `CI / Game-free checks (run_all.py, part 2/2) (pull_request)`. `@rebase` (or `@fix`) brings it up to date and runs them again; not held against it. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the reported case: the author reports two crashes before the fix and one handled fault during a 20.7-minute RX 580 run with the fix. The synthetic test reportedly fails on the base and returns all 200 samples with the fix. **Other systems:** The change runs on Linux for sampled threads regardless of GPU; Windows uses a separate sampler. The reported game run covers Mesa RADV on an RX 580, but does not cover Tier 1 Linux hardware or another Linux unwinder setup. Normal play without sampling does not enter the new walk path. **Switches:** None added, changed or removed. Existing profiling switches enable the affected sampler. **Reviewed:** c06e8c2353bd against 3ab4db6e9154: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, both changed files, the diff and commit messages; read the sampler callers and POSIX exception dispatch around the changes. Skimmed the test runner and profiling switch setup. docs/review-checklist.md and the adjacent Tooling checkout were absent. No recorded runs, translations or generated files changed.; nothing run (a code review). **Checked and fine:** - Both commits record AI assistance. - The diff contains no game-derived files, generated files or third-party changes. - The fault count is updated and read atomically, and the sample completion store publishes the collected frames. - The existing reported test and game run exercise a real unwind fault and recovery. **Testing:** Read-only review; no builds, tests or project scripts were run. The PR reports a synthetic 200-sample test, a Linux build and an in-game RX 580 run. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -189,0 +203,4 @@
sigjmp_buf escape;
if (!sigsetjmp(escape, 1)) {
walk_escape = &escape;
_Unwind_Backtrace(walk_step, (void *)&w);
Member

L5 (should fix): The Linux sampler change still needs a run on affected Tier 1 hardware.

When: The only reported game run is on an RX 580; Linux Tier 1 NVIDIA, newer AMD and Steam Deck setups can execute the same signal and unwind path.

Do: Run profiling on representative Tier 1 Linux hardware, exercising sampling and confirming the game and profile remain usable.

**L5** (should fix): The Linux sampler change still needs a run on affected Tier 1 hardware. *When:* The only reported game run is on an RX 580; Linux Tier 1 NVIDIA, newer AMD and Steam Deck setups can execute the same signal and unwind path. **Do:** Run profiling on representative Tier 1 Linux hardware, exercising sampling and confirming the game and profile remain usable.
@ -200,6 +222,7 @@ static void sampling_init(void) {
sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK;
sigemptyset(&sa.sa_mask);
sigaction(SAMPLE_SIG, &sa, NULL);
AddVectoredExceptionHandler(1, walk_fault); /* (ahead of the game's: a walk's fault is never the guest's) */
Member

L1 (blocking): The recovery handler is installed after the unsynchronized initialization guard has let another sampler proceed.

When: With HOS_SAMPLE and HOS_SAMPLE_ALL enabled together, both sampler threads can enter sampling_init. One increments done and pauses before registering walk_fault; the other returns from sampling_init and can signal a thread whose unwind faults, taking the game down before the handler is installed.

Do: Use a once primitive that makes all sampler threads wait until signal setup, handler registration and unwinder warm-up have completed before sampling starts.

**L1** (blocking): The recovery handler is installed after the unsynchronized initialization guard has let another sampler proceed. *When:* With HOS_SAMPLE and HOS_SAMPLE_ALL enabled together, both sampler threads can enter sampling_init. One increments done and pauses before registering walk_fault; the other returns from sampling_init and can signal a thread whose unwind faults, taking the game down before the handler is installed. **Do:** Use a once primitive that makes all sampler threads wait until signal setup, handler registration and unwinder warm-up have completed before sampling starts.
@ -0,0 +19,4 @@
import sys
import tempfile
RUN_ALL_ARGS = ["--cc", "clang"]
Member

L3 (should fix): The test hard-codes clang instead of honoring the configured C compiler.

When: On a supported Linux development setup with CC pointing to GCC and no clang on PATH, run_all skips this check even though a usable compiler is configured; it also never exercises the GCC build.

Do: Use the runner's {cc} compiler and the repository's compiler-argument parsing convention, and honor CC for standalone runs.

**L3** (should fix): The test hard-codes clang instead of honoring the configured C compiler. *When:* On a supported Linux development setup with CC pointing to GCC and no clang on PATH, run_all skips this check even though a usable compiler is configured; it also never exercises the GCC build. **Do:** Use the runner's {cc} compiler and the repository's compiler-argument parsing convention, and honor CC for standalone runs.
@ -0,0 +51,4 @@
__asm__(".text\n.globl bad_cfi\n.type bad_cfi,@function\nbad_cfi:\n.cfi_startproc\n"
"mov $0x10, %r12\n.cfi_def_cfa %r12, 0\n1: pause\njmp 1b\n.cfi_endproc\n.size bad_cfi,.-bad_cfi\n");
void bad_cfi(void);
static volatile int spinner;
Member

L4 (should fix): The test publishes spinner between threads using volatile accesses rather than atomic synchronization.

When: The worker writes spinner while the main thread polls and reads it without synchronization, which is a C data race and makes the test's startup behavior undefined.

Do: Publish and read the thread ID with atomic release and acquire operations.

**L4** (should fix): The test publishes spinner between threads using volatile accesses rather than atomic synchronization. *When:* The worker writes spinner while the main thread polls and reads it without synchronization, which is a C data race and makes the test's startup behavior undefined. **Do:** Publish and read the thread ID with atomic release and acquire operations.
@ -0,0 +106,4 @@
print("skip: the walk is Linux's, the bad frame x86-64's")
return
src = (ROOT / "host/posix/prof.c").read_text(encoding="utf-8")
piece = between(src, "/* ---- one thread's stack, taken inside it ---- */", "static void sampling_init(void)")
Member

L2 (should fix): The test excludes sampling_init and calls walk_fault directly from its substitute fault handler, bypassing the production registration.

When: Removing AddVectoredExceptionHandler(1, walk_fault) leaves this test unchanged and passing, while a fault in an actual sampled walk reaches the normal crash handler and ends the game.

Do: Exercise production initialization and exception dispatch in the harness, including registration of walk_fault, so removing that registration makes the test fail.

**L2** (should fix): The test excludes sampling_init and calls walk_fault directly from its substitute fault handler, bypassing the production registration. *When:* Removing AddVectoredExceptionHandler(1, walk_fault) leaves this test unchanged and passing, while a fault in an actual sampled walk reaches the normal crash handler and ends the game. **Do:** Exercise production initialization and exception dispatch in the harness, including registration of walk_fault, so removing that registration makes the test fail.
HumanBean force-pushed fix/prof-walk-fault from c06e8c2353
Some checks failed
CI / What the change needs (pull_request) Successful in 9s
CI / Third-party parts and guide screenshots (pull_request) Successful in 14s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 12s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 1m57s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 3m37s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 4m55s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 5m6s
CI / Website build and checks (pull_request) Successful in 1m29s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m33s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39m50s
PR description / Title and description (pull_request_target) Successful in 5s
to a97818a433
Some checks failed
CI / What the change needs (pull_request) Successful in 19s
CI / Third-party parts and guide screenshots (pull_request) Successful in 22s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 22s
PR description / Title and description (pull_request_target) Failing after 7s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 1m54s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 3m57s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 1m59s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 2m30s
CI / Website build and checks (pull_request) Successful in 1m39s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 18m38s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 39m34s
2026-11-29 16:44:18 +00:00
Compare
Author
Owner

Review addressed in aa9c9e16 (test) and a97818a4 (fix), pushed. Both commits were amended, and the two-commit shape is kept.

  • L1 (line): Fixed. The body of sampling_init (signal setup, walk_fault's registration, unwinder warm-up) is now sampling_setup. sampling_init runs it through pthread_once, so every sampler thread waits until it has finished. (The old done++ guard came from main; it was racy there too, but only now does it guard something that matters.)
  • L2 (line): Fixed. The cut now runs through sampling_init, and the harness calls it. The fault handler goes only through a list of vectored handlers, filled by an AddVectoredExceptionHandler that works like win32_posix.c's. Nothing calls walk_fault by name any more. If the registration line is removed, the test fails: in the cut, walk_fault is then unused, which -Werror rejects, the same warning the real build would give.
  • L3 (line): Fixed. RUN_ALL_ARGS = ["--cc", "{cc}"], the default is CC or else cc, and the value is split with shlex. I ran it with both gcc and clang.
  • L4 (line): Fixed. spinner is now a plain int, stored with __ATOMIC_RELEASE and loaded with __ATOMIC_ACQUIRE.
  • L5 (line): Agreed, but it can't be done from here, because this PC isn't Tier 1 Linux hardware with the profiler on. It is now listed under Still to test, and its Tier 1 box stays unticked. A Test Farm run of a profiled session would settle it.

Results: on the test commit (main's prof.c) the test fails with signal 11. On the fix it passes all 200 samples, with gcc and with clang. One dev.py pack on the shared base compiled cleanly. The in-game RX 580 run in the description predates the pthread_once change.

Review addressed in `aa9c9e16` (test) and `a97818a4` (fix), pushed. Both commits were amended, and the two-commit shape is kept. - **L1** ([line](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2790#issuecomment-90338)): Fixed. The body of `sampling_init` (signal setup, `walk_fault`'s registration, unwinder warm-up) is now `sampling_setup`. `sampling_init` runs it through `pthread_once`, so every sampler thread waits until it has finished. (The old `done++` guard came from main; it was racy there too, but only now does it guard something that matters.) - **L2** ([line](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2790#issuecomment-90339)): Fixed. The cut now runs through `sampling_init`, and the harness calls it. The fault handler goes only through a list of vectored handlers, filled by an `AddVectoredExceptionHandler` that works like `win32_posix.c`'s. Nothing calls `walk_fault` by name any more. If the registration line is removed, the test fails: in the cut, `walk_fault` is then unused, which `-Werror` rejects, the same warning the real build would give. - **L3** ([line](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2790#issuecomment-90340)): Fixed. `RUN_ALL_ARGS = ["--cc", "{cc}"]`, the default is `CC` or else `cc`, and the value is split with `shlex`. I ran it with both gcc and clang. - **L4** ([line](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2790#issuecomment-90341)): Fixed. `spinner` is now a plain `int`, stored with `__ATOMIC_RELEASE` and loaded with `__ATOMIC_ACQUIRE`. - **L5** ([line](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2790#issuecomment-90342)): Agreed, but it can't be done from here, because this PC isn't Tier 1 Linux hardware with the profiler on. It is now listed under Still to test, and its Tier 1 box stays unticked. A Test Farm run of a profiled session would settle it. Results: on the test commit (main's `prof.c`) the test fails with signal 11. On the fix it passes all 200 samples, with gcc and with clang. One `dev.py pack` on the shared base compiled cleanly. The in-game RX 580 run in the description predates the `pthread_once` change.
HumanBean changed title from WIP: fix(prof): a stack walk that faults cuts its sample short instead of ending the game to fix(prof): a stack walk that faults cuts its sample short instead of ending the game 2026-11-29 17:09:44 +00:00
HumanBean deleted branch fix/prof-walk-fault 2026-11-29 17:09:51 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!2790
No description provided.