fix(runtime): keep the crash report filter when the C runtime replaces it #16
No reviewers
Labels
No labels
accessibility
bug
ci
docs
documentation
duplicate
enhancement
fixes issue
good first issue
help wanted
invalid
library request
libs
needs rebase
question
relinker
stale
tools
unblocks title
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Dark3581--AnyBox!16
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/16/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?
@Callimann8 on GitHub · 2026-11-21 12:32 UTC · original
Callimann8:claude/project-thread-25z91v→main· +58 −4 · 5 files · 5 commits · closed without mergingWhat
Fixes the missing crash report on the GitHub Windows runner (#7).
Cause: mingw-w64 commit 742bad4b (2025-12-25, "crt: crt_handler: Remove registration of _gnu_exception_handler as UnhandledExceptionFilter") made the executable startup code (
__tmainCRTStartupincrtexe.c) callSetUnhandledExceptionFilter(cpp_unhandled_exception_filter), and a1007192 (2026-05-29) removed__mingw_oldexcpt_handler, so the new filter no longer chains to the previous one. It runs afterab_runtime.dll'sDllMainhas set the AnyBox filter, so the AnyBox filter is dropped. MSYS2 UCRT64 ships this CRT; WinLibs GCC 15.2 still ships the older, chaining one, which is why the report is written locally.Fix, in
Runtime.cpp:Start()also registers a vectored exception handler (KeepFilter). It writes nothing; it only putsUnhandledExceptionback as the top-level filter and remembers the filter it replaced. Vectored handlers run before frame-based handlers, so the AnyBox filter is on top whenever an exception becomes unhandled, whoever replaced it and whenever.UnhandledExceptionwrites the report as before, then calls the replaced filter and returns its result, so the title's or CRT's filter still runs (for example mingw-w64 returningEXCEPTION_CONTINUE_EXECUTIONfor an uncaught GCC C++ exception sostd::terminateruns). A guard makes it returnEXCEPTION_CONTINUE_SEARCHwhen it is entered again during its own call, so a title filter that chains to the previous one (Breakpad, Crashpad, Sentry) runs once instead of looping.e2e.pyno longer skips the report check whene2e_crashwrites no report, a newcrash_chainedscenario installs a chaining title filter and expects one call, a crash report and exit0xC0000005, and the debt fragment removes the old runtime entry and lists the vectored handler running on every first-chance exception.Tested
python tools/check_conventions.pyandpython tools/debt_fold.py --checkpass.e2e_crashnow fails if no report is written.Checklist
main; no other open PR implements the same functionspython tools/check_conventions.pypasses (no comments in code, one declaration per export, Conventional Commit subjects)AbxNotImplemented/AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragmentdocs/dev/debt/changes/<branch>.mdcrtexe.csource (commits 742bad4b, a1007192); Win32SetUnhandledExceptionFilter/AddVectoredExceptionHandlerdocumentation@Dark3581 on GitHub · 2026-11-21 12:35 UTC · original · requested changes
Changes requested
The diagnosis of #7 is convincing and the approach is right, but the new chaining re-enters a title's own filter without end. That turns a crash into an endless loop for any title with a common crash reporter.
What I ran
Head
fcf4cd5, based on currentmain(ddd30ef). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.Results
e2e_crashwrites its report with this CRT, as beforetools/check_conventions.py,tools/debt_fold.py --checkFindings
Blocking
core/libs/runtime/src/Runtime.cpp:289together with:292: crash reporters (Breakpad, Crashpad, Sentry and most engines' own) install their filter withprev = SetUnhandledExceptionFilter(Mine)and callprevat the end. Onceab_runtime.dllis loaded,previsUnhandledException. On the crash,KeepFilterputsUnhandledExceptionback on top and storesMineing_previousFilter. SoUnhandledException→Mine→prev=UnhandledException→Mine→ … and it never ends, rewriting the report on every pass until the stack overflows.Probe: a 30-line program that loads
ab_runtime.dll, installs such a chaining filter, then writes through a null pointer. With this PR the title's filter ran 6 times before the probe's own cutoff killed the process. Onmainit runs once, the report is written, and the process ends with the access violation. The older mingw-w64_gnu_exception_handlerchains the same way through__mingw_oldexcpt_handler.Fix: make
UnhandledExceptionrefuse to be entered twice, for example With that change applied locally, the probe calls the title's filter once, the report records0xc0000005in the probe, ande2e_crashstill passes. Please add an e2e scenario for it: the fake title installs a filter that chains to the previous one, prints once per call, then crashes. Expect exit0xC0000005, acrashreport, and exactly one call.Non-blocking
core/libs/runtime/src/Runtime.cpp:307: the vectored handler runs on every first-chance exception, not only fatal ones: C++ throws,OutputDebugString, thread naming, guard-page probes. Each one callsSetUnhandledExceptionFilter, which also changes what a title gets back from its ownSetUnhandledExceptionFiltercall later. Cheap per call, but worth a line in the runtime debt: the filter is re-asserted on every exception, and the title's filter runs after the report.Not verified
The MSYS2 UCRT64 CRT that #7 is about; CI's Windows job covers it.
Thanks for tracking the cause down to the exact mingw-w64 commits. Happy to merge once the guard and its scenario are in.
@Callimann8 on GitHub · 2026-11-21 12:40 UTC · original
Thanks for the probe. Pushed
d26c0e1:UnhandledExceptionnow returnsEXCEPTION_CONTINUE_SEARCHif it is entered again during its own call (g_inFilter), so a title filter that chains to the previous one runs once. The guard is cleared after the chained call returns, so a later uncaught GCC C++ throw still reaches the CRT's filter.crash_chained: the fake title installs a filter that chains to the previous one and prints once per call, then writes through a null pointer. It expects exit0xC0000005, acrashreport fromtitle.exe, and exactly onetitle filterline.SetUnhandledExceptionFiltergets the AnyBox filter back as the previous one, and the title's filter runs after the report.Cross-built with mingw-w64 GCC 13 on Linux; conventions and
debt_fold.py --checkpass. Not run on Windows here, so CI is the check for both crash scenarios.@Dark3581 on GitHub · 2026-11-21 12:53 UTC · original · requested changes
Changes requested
The re-entry guard fixes the nested loop, but on the WinLibs CRT the title's filter still runs twice per crash. The new
e2e_crash_chainedtest fails on every run there.What I ran
Head
2080d81, applied onto currentmain(4625f54, after #17). It applies without conflicts. MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.Results
e2e_crash_chainedfails withtitle filterprinted twicecrash_chainedrepeatede2e_crashcheck_conventions.pydebt_fold.py --checkFindings
Blocking
core/libs/runtime/src/Runtime.cpp:276,UnhandledException: on a CRT that still chains (WinLibs GCC 15.2, whichdocs/dev/BUILD.mdlists as tested), one crash entersUnhandledExceptiontwice in sequence, not nested, sog_inFilterdoes not catch it. Stack traces from an instrumentedfake_title:ntdll→_gnu_exception_handler(title.exe, thecall *__mingw_oldexcpt_handlerat the end) →UnhandledException→ChainingFilter→_gnu_exception_handler→UnhandledException(guard, returnsEXCEPTION_CONTINUE_SEARCH).ntdll→KERNELBASE!UnhandledExceptionFilter→UnhandledException→ChainingFilteragain.The CRT saved the AnyBox filter as
__mingw_oldexcpt_handlerat startup and calls it from its own handler. The OS then calls it again as the top-level filter. Before this PR, the second entry only rewrote the report. Now each entry also runs the title's filter, so a crash reporter like Crashpad would upload twice. The newer CRT on CI does not chain, which is why the PR's reasoning holds there.Suggested fix, verified here: run once per exception dispatch on a thread. The vectored handler runs at the start of every dispatch, so it can clear the marker.
With this: CTest 43/43,
e2e_crashande2e_crash_chainedeach pass 25 repeats, and the chained title filter runs once in 15/15 runs. A second call in the same dispatch only happens when the first one returnedEXCEPTION_CONTINUE_SEARCH, so returning that again does not change the outcome.I also ran a probe title against
main, this PR and the fix. It installs a filter that fixes up a read-only page fault withEXCEPTION_CONTINUE_EXECUTION, then crashes on the main thread, on astd::thread, or with an uncaughtthrow:main0xc00004090xc00004090xc0000409So the fix keeps a later crash on the same thread reported after a recovered fault, and the uncaught-throw path behaves as on
main.Non-blocking
EXCEPTION_CONTINUE_EXECUTION) still gets acrashreport, because the AnyBox filter writes before it chains. A clean exit overwrites it withnone. A later death that writes nothing (the0xc0000409row above) leaves the stale report, which points at the recovered fault. Onmainthis already happens through the WinLibs CRT path. WithKeepFilterkeeping AnyBox on top, it now happens on every CRT. It's worth a line in the debt fragment.g_inFilteris process-wide, so a second thread that crashes while the first is in the filter returnsEXCEPTION_CONTINUE_SEARCHwithout a report, and may end the process before the first report is complete. Not new, and fine for this PR; a per-thread guard is a later option.Not verified
The MSYS2 UCRT64 CRT locally. CI's Windows job is the check for that path once it runs on the new head.
Thanks, the diagnosis from the mingw-w64 history is spot on; this is the last piece.
@Callimann8 on GitHub · 2026-11-21 13:01 UTC · original
Thanks for tracing the WinLibs double entry and for the verified fix. I pushed it as written, and also merged current
maininto the branch:UnhandledExceptionrecords the thread it handled (g_handledThread) after the chained filter returns, and returnsEXCEPTION_CONTINUE_SEARCHfor a second call in the same dispatch on that thread.KeepFilterclears the mark at the start of the next dispatch on that thread when no filter is running, so a later crash after a recovered fault is still reported.EXCEPTION_CONTINUE_EXECUTION) still gets acrashreport, since AnyBox writes before it chains, and thatg_inFilteris process-wide (closes when the guard is per thread).It cross-builds with mingw-w64 GCC 13 on Linux with no warnings, and
check_conventions.pyanddebt_fold.py --checkpass. I couldn't run it on Windows, so your WinLibs run and CI on the new head are the checks fore2e_crash_chained.@Dark3581 on GitHub · 2026-11-21 13:27 UTC · original · requested changes
Changes requested
The once-per-dispatch guard works: the chained title filter now runs once on every path I tried. Two things still differ from
main, and one of them makes the run report wrong for a title whose own filter recovers from a fault.What I ran
Head
d3f0b1b, based on currentmain(4625f54). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.mainwas built the same way for the comparison.Results
e2e_crash,e2e_crash_chainedrepeatedmaincheck_conventions.pydebt_fold.py --checkd3f0b1bThe probe loads
ab_runtime.dll, installs a title filter that chains to the previous one and fixes up a fault on a read-only page withEXCEPTION_CONTINUE_EXECUTION, then:maincrashat+0x1874,0xc0000005std::threadcrashat+0x1874,0xc0000005nonecrashat the recovered faultnonecrashat+0x1874crashat+0x18b9, the recovered faultcrashat+0x1874throw0xc0000409FreeLibrary(ab_runtime.dll), then a caughtthrow0xc0000005Findings
Blocking
core/libs/runtime/src/Runtime.cpp:296: the report is written before the chained filter runs, andAbxWriteReportwrites only once per process (g_reportWritten,:335). When the title's filter recovers (EXCEPTION_CONTINUE_EXECUTION), thecrashreport stays: a clean exit cannot replace it withnone, and a later real crash cannot replace it either, so the report points at the fault that was recovered. Onmainthe title's filter replaced ours, so neither happened. The debt fragment says "a clean exit overwrites it withnone", whichg_reportWrittenprevents.Fix, verified with the probe above: keep writing before chaining (a crash reporter that calls
TerminateProcessstill leaves a report), and re-arm the report when the chained filter recovers. The mingw-w64 path for an uncaught GCC exception also returnsEXCEPTION_CONTINUE_EXECUTION, butstd::terminateends the process without another report, so thecrashfile on disk stays. Please add an e2e scenariocrash_recovered: the fake title installs a filter that fixes up a write to aPAGE_READONLYpage and returnsEXCEPTION_CONTINUE_EXECUTION, then returns 0. Expect exit 0 and anonereport. The second bullet of the debt fragment then goes away.Non-blocking
core/libs/runtime/src/Runtime.cpp:322: the vectored handler is never removed. Ifab_runtime.dllis unloaded withFreeLibrary, the next first-chance exception of any kind jumps into unmapped memory (last row of the table). A relinked title loads it at startup and never unloads it, so this only affects a host that loads it dynamically, like the probe. Fix: With both changes: CTest 43/43, ande2e_crashande2e_crash_chained25/25 each.g_handledThreadholds one thread ID. If thread A's crash is handled and thread B crashes before A's second, sequential entry from the old CRT, B's mark replaces A's and A's title filter can run a second time. That is narrower than the process-wideg_inFilteralready listed in the fragment, and the same "Closes when: the guard is per thread" covers it, so a mention there is enough.Not verified
The MSYS2 UCRT64 CRT that #7 is about, other than through CI. A real crash reporter (Crashpad, Breakpad); the probe only mimics their chaining.
Thanks for the quick turnaround on both rounds. This is the last thing I found; with the re-arm, its scenario and the fragment updated I'll merge.
@Dark3581 on GitHub · 2026-11-21 13:38 UTC · original · approved these changes
Reviewed — looks good
The fix for #7 is right and the once-per-dispatch guard holds. I landed it with the report re-arm from my last review as a follow-up commit, so you don't need to push again.
What I ran
Head
d3f0b1b, squashed ontomain(4625f54) as2612937, plus the follow-upb5bac96. MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.Results
e2e_crash,e2e_crash_chained,e2e_crash_recoveredrepeatede2e_crash_recoveredwithout the re-armcrashafter exit 0maincheck_conventions.py,debt_fold.py --checkd3f0b1bFollow-up in
b5bac96UnhandledExceptionre-arms the report when the replaced filter returnsEXCEPTION_CONTINUE_EXECUTION, so a recovered fault no longer leaves acrashreport behind and a later crash reports its own address.DllMainremoves the vectored handler on aFreeLibraryunload.crash_recovered: the fake title fixes up a write to a read-only page from its own filter and exits 0; expects anonereport.g_handledThreadmark to the per-thread guard entry.Not verified
The MSYS2 UCRT64 CRT other than through CI, and a real crash reporter (Crashpad, Breakpad).
Thanks for tracking #7 down to the exact mingw-w64 commits and for turning every round around so quickly.
@Dark3581 on GitHub · 2026-11-21 13:38 UTC · original
Landed on main as
2612937, with the follow-upb5bac96(report re-arm after a recovered fault, handler removal on unload,e2e_crash_recovered). Closing here.Pull request closed