common: report crashes that reach no handler #409
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!409
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/409/head"
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?
@MehmetCambaz on GitHub · 2026-08-29 22:02 UTC · original
<html>MehmetCambaz:fix/crash-report→main· +179 −0 · 6 files · 1 commits · closed without mergingProblem
KytyExceptionHandlerreports access violations and illegal instructions, which is why a null dereference already produces a stack trace. Nothing else does.HostException's filter returnsEXCEPTION_CONTINUE_SEARCHfor every other exception code, so those faults never reach that handler, and an uncaught throw never goes near it at all — it goes tostd::terminate.The result is a class of session that ends with no record of why. #307 describes it exactly: "The process terminates before Kyty can flush a crash record to the log", and that reporter had to inspect a minidump to find
RIP=0.Measured on Tetris Forever with a fault injected at a fixed point, before and after:
The bottom two are the ones I would worry about. The tree has one
catchsite against 129newexpressions and 52.at()calls, so abad_allocor anout_of_rangeis a realistic way to lose a session silently.The fix
Three hooks, because no single one covers the ground:
SetUnhandledExceptionFiltertakes the faults the guest page-fault handler declined.std::terminatecovers an uncaught throw — but the Microsoft CRT keeps that handler per thread, so on Windows it only covers the thread that installed it. I found this by testing, not by reading: the first version reported nothing when the throw happened on a guest thread.SIGABRTis process-wide and is what actually catches a throw on a guest or graphics thread.All three build the same report
EXIT()builds, and hand the fault back to the default handling afterwards, so Windows Error Reporting and dump collection are unchanged. Reporting is latched so a fault inside the reporter cannot loop.The terminate and SIGABRT hooks are portable and run everywhere; on POSIX
std::terminateis process-wide, so uncaught throws are covered there without the per-thread caveat. Only the fault hook is Windows-only —SIGSEGV,SIGBUSandSIGILLalready carry the guest page-fault handler, so a second handler there has to chain rather than replace it, and I have no POSIX machine to verify that on.SysInstallCrashHandlerreturns false until someone does.What this does not cover
If the fault happens inside the logger itself, no report is produced. I tested that case specifically by faulting inside
RawFormatter::formatwhile the sink mutex was held: nothing is written, with or without this change, because the handler does not run. That is pre-existing and unchanged here, not something this patch introduces.I also checked whether re-entering the logger from a crashing thread could hang, since that would be worse than the silence it replaces. It cannot: MSVC's
std::mutexdetects recursive acquisition and throwsresource deadlock would occurrather than blocking, and spdlog swallows it.Test plan
Windows 11 25H2, clang-cl 20.1.8, RTX 2060.
ctest: 35/35.AI use
Written with AI assistance (Claude). It traced the existing fault paths, found that access violations were already covered and the gap was elsewhere, wrote the change, and ran the builds, injected-fault runs and measurements on my machine. I reviewed the diff and the results.
</html>ProblemKytyExceptionHandler reports access violations and illegal instructions, which is why a null dereference already produces a stack trace. Nothing else does. HostException's filter returns EXCEPTION_CONTINUE_SEARCH for every other exception code, so those faults never reach that handler, and an uncaught throw never goes near it at all — it goes to std::terminate.
The result is a class of session that ends with no record of why. #307 describes it exactly: "The process terminates before Kyty can flush a crash record to the log", and that reporter had to inspect a minidump to find RIP=0.
Measured on Tetris Forever with a fault injected at a fixed point, before and after:
access violation reported unchanged
stack overflow nothing reported
integer divide by zero nothing reported
uncaught throw nothing reported
.at() out of range nothing reported
The bottom two are the ones I would worry about. The tree has one catch site against 129 new expressions and 52 .at() calls, so a bad_alloc or an out_of_range is a realistic way to lose a session silently.
The fix
Three hooks, because no single one covers the ground:
SetUnhandledExceptionFilter takes the faults the guest page-fault handler declined.
std::terminate covers an uncaught throw — but the Microsoft CRT keeps that handler per thread, so on Windows it only covers the thread that installed it. I found this by testing, not by reading: the first version reported nothing when the throw happened on a guest thread.
SIGABRT is process-wide and is what actually catches a throw on a guest or graphics thread.
All three build the same report EXIT() builds, and hand the fault back to the default handling afterwards, so Windows Error Reporting and dump collection are unchanged. Reporting is latched so a fault inside the reporter cannot loop.
The terminate and SIGABRT hooks are portable and run everywhere; on POSIX std::terminate is process-wide, so uncaught throws are covered there without the per-thread caveat. Only the fault hook is Windows-only — SIGSEGV, SIGBUS and SIGILL already carry the guest page-fault handler, so a second handler there has to chain rather than replace it, and I have no POSIX machine to verify that on. SysInstallCrashHandler returns false until someone does.
What this does not cover
If the fault happens inside the logger itself, no report is produced. I tested that case specifically by faulting inside RawFormatter::format while the sink mutex was held: nothing is written, with or without this change, because the handler does not run. That is pre-existing and unchanged here, not something this patch introduces.
I also checked whether re-entering the logger from a crashing thread could hang, since that would be worse than the silence it replaces. It cannot: MSVC's std::mutex detects recursive acquisition and throws resource deadlock would occur rather than blocking, and spdlog swallows it.
Test plan
Windows 11 25H2, clang-cl 20.1.8, RTX 2060.
ctest: 35/35.
Each row of the table above produced by injecting that fault into a real run and reading the log, before and after.
Normal run unaffected: 1531 flips in 25 s, zero spurious reports, log size unchanged.
No new test — this only produces diagnostic output on a dying process, which the suite has no way to observe.
AI use
Written with AI assistance (Claude). It traced the existing fault paths, found that access violations were already covered and the gap was elsewhere, wrote the change, and ran the builds, injected-fault runs and measurements on my machine. I reviewed the diff and the results.
Pull request closed