app: a fatal signal is logged before the process dies by it (#392) #478
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!478
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-474"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@AnastasisKon on GitHub · 2026-11-27 21:50 UTC · original
AnastasisKon:vibe/fatal-signal-4f9c68→main· +204 −1 · 4 files · 3 commits · openWhat this changes
Refs #395.
A run that ends in a segfault leaves
runs/<date>/victory.logwithout a line naming the fault: nothing on the native host says anything when the game's own code faults. In #395 the run reached frame 1678 and died at 122 s withSegmentation fault: 11, after GPU errors, and the log had to be read backwards from the last unrelated line to guess what happened.log_fatal_signals()installs a handler forSIGSEGV,SIGBUS,SIGILLandSIGFPEthat writes one fixed line —— the signal, its
si_codeandsi_addr(), through async-signal-safe calls only: a 65-byte line built on the stack,write(2), no allocation, notracing. It then re-raises the fault;SA_RESETHANDrestored the default action, so the process still dies by the signal with the same exit status and the same crash report as before. Nothing about how a run ends changes — the log just says why.Compiled on
cfg(unix)only, and the call site inmainis#[cfg(unix)], so Windows is untouched.How it was tested
cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass — victory bin 14, victory-hle 327 plus native_probe 17, victory-loader 29, 0 failed.cargo test -p victoryon the arm64 host: the bin's 9 tests pass, the new one (fatal_signal_tests::a_fatal_signal_is_logged_before_the_process_dies_by_it) included.cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: no warnings.cargo xtask policy: 398 files ok.victory: fatal signal …line invictory.logbefore the fault, and the run still ends with the status it ended with before.The new test forks a child, has it install the logger and raise
SIGSEGV, reads the line from its stderr, and assertsWIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV— so it would catch a handler that swallows the signal or changes the exit status, not just one that prints nothing.Checklist
VICTORY_*variable and documented: not a diagnostic switch — it writes one line only when the process is already dying, allocates nothing and can be turned off by not crashing. Say the word if you would rather have it behindVICTORY_LOG_FATAL_SIGNALS=1.github-bot referenced this pull request2026-11-27 21:59:42 +00:00
@Olima34 on GitHub · 2026-11-28 00:41 UTC · original · requested changes
Thanks @AnastasisKon, a line naming the fault is worth having, and keeping the handler async-signal-safe is right. We read the whole diff (
e5bc7a3d) while helping the maintainer clear the queue, and there's one problem with how it interacts with the loader's own handler:In a real run,
SA_RESETHANDnever applies, so the re-raise can loop instead of ending the process.log_fatal_signals()runs at the start ofmain. Later, when the title's first thread is set up,victory_loader::native::seh::install()(called fromteb.rs) installs its ownSIGSEGV/SIGBUS/SIGILL/SIGFPEhandler and saves the previous action (this logger) inOLDfor faults that aren't the title's. So the kernel delivers to the loader'son_signal, which calls the logger throughchain(), not the kernel. The disposition is still the loader's handler. The logger'sraise(sig)then stays pending (the signal is blocked inside the handler) and comes back toon_signalonce it returns, and the faulting instruction runs again too. TheSIG_DFLbranch inchain()is what used to end the process there, and it no longer runs. As we read it, a crash would become a loop of "fatal signal" lines rather than a dead process (we haven't run it).Suggested fix: in
fatal, set the disposition back toSIG_DFLyourself beforeraise(sigactionis async-signal-safe), rather than relying onSA_RESETHAND. That covers both the direct and the chained path. The test would catch it if, afterlog_fatal_signals(), the child installs a second handler that chains to the saved one the wayseh::signal::chaindoes (or callsseh::install()itself on x86_64), then faults. It should still see one line andWTERMSIG == SIGSEGV.Smaller, optional: the docs don't mention the line. One sentence in docs/native-host.md (near the stop-on-signal paragraph) would help testers know to look for
victory: fatal signal. CI is green on this head.@AnastasisKon on GitHub · 2026-11-28 12:31 UTC · original
Re-requesting review: conflicts with current main are resolved, CI is green on the latest head, and the earlier approval was noted as still standing. Ready to merge when you are.
@AnastasisKon on GitHub · 2026-11-28 15:30 UTC · original
Fixed as suggested, on top of a merge of current public
main(26817285):fatalnow resets the disposition toSIG_DFLwithsigaction(async-signal-safe) beforeraise, instead of relying onSA_RESETHAND— so the chained path (seh::install()replaced the handler,seh::signal::chaincalls the logger from the loader'son_signal) also ends the process instead of looping.a_chained_fatal_signal_is_logged_once_and_still_kills: afterlog_fatal_signals(), the child installs a secondSA_SIGINFOhandler that forwards to the saved previous action exactly likechaindoes, then faults. It asserts onevictory: fatal signal 11 (code …)line andWTERMSIG == SIGSEGV. Verified it is not vacuous: with thesigactionreset removed, this test hangs in the loop (killed at 60 s); with it, it passes in 0.17 s.docs/native-host.md(stop-on-signal paragraph) telling testers to look for thevictory: fatal signalline.Gates on the new head
e1a6d54d:cargo test -p victory-hle -p victory -p victory-gpu -p xtask(host) green incl. both fatal-signal tests;cargo test --target x86_64-apple-darwin -p victorygreen;cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warningsclean;cargo xtask policy404 files ok.@AnastasisKon on GitHub · 2026-11-28 18:16 UTC · original
The suggested fix is already the current head
e1a6d54d:fatalnow callssigaction(sig, SIG_DFL)itself (async-signal-safe) beforeraise, instead of relying onSA_RESETHAND, so the chained path —seh::install()having replaced the disposition andseh::signal::chaincalling the logger from the loader'son_signal— also ends the process rather than looping. The regression testa_chained_fatal_signal_is_logged_once_and_still_killsinstalls a second SA_SIGINFO handler that forwards to the saved previous action exactly likechaindoes, then faults: it asserts one log line andWTERMSIG == SIGSEGV(and hangs without the sigaction reset). The docs line is there too, at docs/native-host.md ("logs one line naming it first —victory: fatal signal <n> ...— and then dies by the signal as before"). The branch contains publicmain26817285with no conflicts, and CI is green one1a6d54d. Could you re-read the head and dismiss the older review if it holds up?View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.