loader(native): take the VICTORY_DUMP_THREADS=0 dump at an unhandled access violation too #59

Manually merged
github merged 2 commits from gh-pr/59/head into gh-pr/59/base 2026-11-26 14:44:34 +00:00
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 11:35 UTC · original
Sandile-0511:fix/thread-dump-at-fatal-fault → main · +222 −35 · 4 files · 2 commits · merged 2026-11-26 12:58 UTC

What this changes

VICTORY_DUMP_THREADS=0 dumps every thread at the title's first breakpoint. The title's fatal-error path writes to address 0 instead (the watchdog crash in #15 at image+0x23cf683), and when that happens varies by tens of seconds between runs, so a timed dump misses it. With =0 the dump is now also taken at the first access violation that no handler takes.

After review this also changes how every dump is collected:

  • Snapshot, then unwind. Each thread is stopped only while its registers and up to 1 MiB of its stack are copied, then resumed. Unwinding and formatting happen afterwards, from the copy. Before, collect() took the unwind-table mutex and allocated while a peer was suspended, so a peer stopped inside an unwind lookup or the allocator hung the dump. That hazard is on main for the timed and breakpoint dumps too.
  • Non-blocking trigger. report_at_break is replaced by report_at_fault(code, unhandled) with an atomic claim. The report runs on its own thread, as the timed dump does, and the faulting thread waits for it for at most 60 s.
  • A handled access violation no longer uses up the dump. A breakpoint still claims at first chance; an access violation claims only when unhandled, just before the unhandled-exception filter.

Known limits: the stack copy is capped at 1 MiB; a long VICTORY_FIND_QWORD scan can be cut short by the 60 s wait; a fatal write that one of the title's own handlers catches without a further unhandled fault would not trigger the dump.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-loader: 19 passed, 0 failed, 3 ignored (16 before). New tests: a_handled_access_violation_leaves_the_dump_for_the_fatal_one, a_thread_holding_the_unwind_tables_is_snapshotted_and_let_go (fails with a timeout if an unwind lookup is put back under suspension), the_chain_is_unwound_from_the_copied_stack.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (clean, run on a Mac)
  • cargo xtask policy
  • Ran the game (base M5, 24 GB, Series S mode, this branch): at the watchdog crash the dump was written at the unhandled fault, 60 lines, one per thread, and the process then ended as before. No end-to-end test drives a real fault through dispatch.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none made)
  • New diagnostics are behind a VICTORY_* variable and documented (existing switch; docs/native-host.md updated)
**@⁠Sandile-0511** on GitHub · 2026-11-26 11:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/59) `Sandile-0511:fix/thread-dump-at-fatal-fault` → `main` · +222 −35 · 4 files · 2 commits · merged 2026-11-26 12:58 UTC ## What this changes `VICTORY_DUMP_THREADS=0` dumps every thread at the title's first breakpoint. The title's fatal-error path writes to address 0 instead (the watchdog crash in #15 at `image+0x23cf683`), and when that happens varies by tens of seconds between runs, so a timed dump misses it. With `=0` the dump is now also taken at the first access violation that no handler takes. After review this also changes how every dump is collected: - **Snapshot, then unwind.** Each thread is stopped only while its registers and up to 1 MiB of its stack are copied, then resumed. Unwinding and formatting happen afterwards, from the copy. Before, `collect()` took the unwind-table mutex and allocated while a peer was suspended, so a peer stopped inside an unwind lookup or the allocator hung the dump. That hazard is on `main` for the timed and breakpoint dumps too. - **Non-blocking trigger.** `report_at_break` is replaced by `report_at_fault(code, unhandled)` with an atomic claim. The report runs on its own thread, as the timed dump does, and the faulting thread waits for it for at most 60 s. - **A handled access violation no longer uses up the dump.** A breakpoint still claims at first chance; an access violation claims only when unhandled, just before the unhandled-exception filter. Known limits: the stack copy is capped at 1 MiB; a long `VICTORY_FIND_QWORD` scan can be cut short by the 60 s wait; a fatal write that one of the title's own handlers catches without a further unhandled fault would not trigger the dump. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-loader`: 19 passed, 0 failed, 3 ignored (16 before). New tests: `a_handled_access_violation_leaves_the_dump_for_the_fatal_one`, `a_thread_holding_the_unwind_tables_is_snapshotted_and_let_go` (fails with a timeout if an unwind lookup is put back under suspension), `the_chain_is_unwound_from_the_copied_stack`. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (clean, run on a Mac) - [x] `cargo xtask policy` - [x] Ran the game (base M5, 24 GB, Series S mode, this branch): at the watchdog crash the dump was written at the unhandled fault, 60 lines, one per thread, and the process then ended as before. No end-to-end test drives a real fault through `dispatch`. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (none made) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (existing switch; docs/native-host.md updated)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:44:32 +00:00
github manually merged commit ab3f18d7d7 into gh-pr/59/base 2026-11-26 14:44:34 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 11:51 UTC · original · requested changes

=0 still gates the dump, and the call is after signal return. The blocker is that collect() can suspend a peer holding the unwind-table mutex (seh/unwind.rs ~32–35) and then wait for that same mutex. Please keep the exception trigger nonblocking and resume peers before unwinding or formatting their snapshots. Also pin down the first-chance behavior in a synthetic test: a handled access violation can currently use up the dump before the watchdog fault.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 11:51 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/59#pullrequestreview-6073657761) · **requested changes** `=0` still gates the dump, and the call is after signal return. The blocker is that `collect()` can suspend a peer holding the unwind-table mutex (`seh/unwind.rs` ~32–35) and then wait for that same mutex. Please keep the exception trigger nonblocking and resume peers before unwinding or formatting their snapshots. Also pin down the first-chance behavior in a synthetic test: a handled access violation can currently use up the dump before the watchdog fault.
Author
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 12:30 UTC · original

You were right on all three points, and the first two are on main for the timed and breakpoint dumps as well. Changes:

  • Each thread is stopped only while its registers and up to 1 MiB of stack are copied, then resumed; unwinding and formatting run afterwards from the copy, so nothing takes the unwind-table mutex or allocates while a peer is suspended.
  • The trigger is an atomic claim, and the report runs on its own thread while the faulting thread waits at most 60 s.
  • An access violation claims the dump only when unhandled, just before the unhandled-exception filter. A breakpoint still claims at first chance.

Tests: a pure test of the claim decision, one where a thread holds the unwind tables while it is snapshotted (it times out if a lookup is put back under suspension), and one that unwinds from a copied stack. I also ran the game on this branch: the dump was written at the unhandled fault and the process ended as before.

Limits: no test drives a real fault through dispatch, the stack copy is capped at 1 MiB, and a fatal write that the title's own handler catches without a further unhandled fault would not trigger the dump. This grew well past the original five lines, so if you would rather take the collection change as its own PR, I can split it. I updated the title and description to match.

**@⁠Sandile-0511** on GitHub · 2026-11-26 12:30 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/59#issuecomment-7192096034) You were right on all three points, and the first two are on `main` for the timed and breakpoint dumps as well. Changes: - Each thread is stopped only while its registers and up to 1 MiB of stack are copied, then resumed; unwinding and formatting run afterwards from the copy, so nothing takes the unwind-table mutex or allocates while a peer is suspended. - The trigger is an atomic claim, and the report runs on its own thread while the faulting thread waits at most 60 s. - An access violation claims the dump only when unhandled, just before the unhandled-exception filter. A breakpoint still claims at first chance. Tests: a pure test of the claim decision, one where a thread holds the unwind tables while it is snapshotted (it times out if a lookup is put back under suspension), and one that unwinds from a copied stack. I also ran the game on this branch: the dump was written at the unhandled fault and the process ended as before. Limits: no test drives a real fault through `dispatch`, the stack copy is capped at 1 MiB, and a fatal write that the title's own handler catches without a further unhandled fault would not trigger the dump. This grew well past the original five lines, so if you would rather take the collection change as its own PR, I can split it. I updated the title and description to match.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:48 UTC · original · approved these changes

Thanks: no lock or allocation while peers are suspended, the trigger is nonblocking and the claim logic is tested. Approved. Follow-ups: a_thread_holding_the_unwind_tables_is_snapshotted_and_let_go only tests snapshot(), so add a test through collect() (or a comment); and say in the dump when the all-or-nothing stack copy fails, so an empty chain isn't silent.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/59#pullrequestreview-6074391446) · **approved these changes** Thanks: no lock or allocation while peers are suspended, the trigger is nonblocking and the claim logic is tested. Approved. Follow-ups: `a_thread_holding_the_unwind_tables_is_snapshotted_and_let_go` only tests `snapshot()`, so add a test through `collect()` (or a comment); and say in the dump when the all-or-nothing stack copy fails, so an empty chain isn't silent.
This discussion has been locked. Commenting is limited to contributors.
No description provided.