fix(runtime): keep the crash report filter when the C runtime replaces it #16

Closed
github-bot wants to merge 5 commits from gh-pr/16/head into gh-pr/16/base
Owner

@⁠Callimann8 on GitHub · 2026-11-21 12:32 UTC · original
Callimann8:claude/project-thread-25z91v → main · +58 −4 · 5 files · 5 commits · closed without merging

What

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 (__tmainCRTStartup in crtexe.c) call SetUnhandledExceptionFilter(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 after ab_runtime.dll's DllMain has 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 puts UnhandledException back 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.
  • UnhandledException writes 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 returning EXCEPTION_CONTINUE_EXECUTION for an uncaught GCC C++ exception so std::terminate runs). A guard makes it return EXCEPTION_CONTINUE_SEARCH when 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.py no longer skips the report check when e2e_crash writes no report, a new crash_chained scenario installs a chaining title filter and expects one call, a crash report and exit 0xC0000005, and the debt fragment removes the old runtime entry and lists the vectored handler running on every first-chance exception.

Tested

  • Cross-built every library and the test title on Linux with mingw-w64 GCC 13 (Ubuntu), Release: builds cleanly.
  • python tools/check_conventions.py and python tools/debt_fold.py --check pass.
  • Not run on Windows: the fork has no Actions, and Wine is not available in my environment. The Windows CI job is the real check: e2e_crash now fails if no report is written.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • python tools/check_conventions.py passes (no comments in code, one declaration per export, Conventional Commit subjects)
  • Unimplemented paths stop (AbxNotImplemented / AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragment
  • Known gaps added, changed or removed through docs/dev/debt/changes/<branch>.md
  • Generic behaviour, not specific to one title
  • No game files, keys, notes or logs added to the repository
  • Depends on: none
  • Fixes: Fixes #7
  • Unblocks: none
  • Source of behaviour: mingw-w64 crtexe.c source (commits 742bad4b, a1007192); Win32 SetUnhandledExceptionFilter / AddVectoredExceptionHandler documentation
  • AI-assisted: yes
**@⁠Callimann8** on GitHub · 2026-11-21 12:32 UTC · [original](https://github.com/Dark3581/AnyBox/pull/16) `Callimann8:claude/project-thread-25z91v` → `main` · +58 −4 · 5 files · 5 commits · closed without merging ### What Fixes the missing crash report on the GitHub Windows runner (#7). Cause: mingw-w64 commit [742bad4b](https://github.com/mingw-w64/mingw-w64/commit/742bad4b9df6b7102b430736faad0f16967918c5) (2025-12-25, "crt: crt_handler: Remove registration of _gnu_exception_handler as UnhandledExceptionFilter") made the executable startup code (`__tmainCRTStartup` in `crtexe.c`) call `SetUnhandledExceptionFilter(cpp_unhandled_exception_filter)`, and [a1007192](https://github.com/mingw-w64/mingw-w64/commit/a10071925a41a8cbb0997c8882ec48b8266ebeab) (2026-05-29) removed `__mingw_oldexcpt_handler`, so the new filter no longer chains to the previous one. It runs after `ab_runtime.dll`'s `DllMain` has 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 puts `UnhandledException` back 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. - `UnhandledException` writes 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 returning `EXCEPTION_CONTINUE_EXECUTION` for an uncaught GCC C++ exception so `std::terminate` runs). A guard makes it return `EXCEPTION_CONTINUE_SEARCH` when 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.py` no longer skips the report check when `e2e_crash` writes no report, a new `crash_chained` scenario installs a chaining title filter and expects one call, a crash report and exit `0xC0000005`, and the debt fragment removes the old runtime entry and lists the vectored handler running on every first-chance exception. ### Tested - Cross-built every library and the test title on Linux with mingw-w64 GCC 13 (Ubuntu), Release: builds cleanly. - `python tools/check_conventions.py` and `python tools/debt_fold.py --check` pass. - Not run on Windows: the fork has no Actions, and Wine is not available in my environment. The Windows CI job is the real check: `e2e_crash` now fails if no report is written. ### Checklist <!-- Rules behind each item: CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] `python tools/check_conventions.py` passes (no comments in code, one declaration per export, Conventional Commit subjects) - [x] Unimplemented paths stop (`AbxNotImplemented` / `AbxUnsupported`); silent stubs are listed under Silent stubs through a debt fragment - [x] Known gaps added, changed or removed through `docs/dev/debt/changes/<branch>.md` - [x] Generic behaviour, not specific to one title - [x] No game files, keys, notes or logs added to the repository - [x] Depends on: none - [x] Fixes: Fixes #7 - [x] Unblocks: none - [x] Source of behaviour: mingw-w64 `crtexe.c` source (commits 742bad4b, a1007192); Win32 `SetUnhandledExceptionFilter` / `AddVectoredExceptionHandler` documentation - [x] AI-assisted: yes
mingw-w64 since late 2025 installs its own unhandled exception filter in
the executable's startup code without chaining to the previous one. That
runs after ab_runtime.dll has set its filter in DllMain, so a title built
with it (the MSYS2 UCRT64 test title on the Windows runner) crashed without
a report. A vectored exception handler now puts the AnyBox filter back on
top before any exception is dispatched, and the filter chains to the one it
replaced. e2e_crash checks the report again.

Fixes #7

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YZ2PrBT9JBfR78QFWmowGE
A title filter that chains to the filter it replaced (Breakpad, Crashpad,
Sentry and most engine crash reporters) called UnhandledException, which
chained back to the title filter without end. UnhandledException now
returns EXCEPTION_CONTINUE_SEARCH when it is entered again during its own
call. The crash_chained e2e scenario installs such a filter and expects
one call, a crash report and the access violation exit code. The runtime
debt lists the vectored handler running on every first-chance exception.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YZ2PrBT9JBfR78QFWmowGE
# Conflicts:
#	core/libs/tests/CMakeLists.txt
On a C runtime that still chains to the previous filter (WinLibs GCC 15.2),
one crash entered UnhandledException twice in sequence: once from the
CRT's handler through __mingw_oldexcpt_handler, then again from
KERNELBASE as the top-level filter, so a chaining title filter ran twice
and e2e_crash_chained failed. The filter now records the thread it handled
and returns EXCEPTION_CONTINUE_SEARCH for a second call in the same
dispatch; the vectored handler clears the mark at the start of the next
dispatch on that thread. The runtime debt lists the report written for a
fault the title's filter recovers from and the process-wide guard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YZ2PrBT9JBfR78QFWmowGE
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:14:08 +00:00
github-bot closed this pull request 2026-11-26 19:14:08 +00:00
Author
Owner

@⁠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 current main (ddd30ef). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.

Results

Check Result Note
MinGW full build passed no warnings
CTest passed 39/39; e2e_crash writes its report with this CRT, as before
Chained title filter (probe below) failed the title's filter is re-entered without end
tools/check_conventions.py, tools/debt_fold.py --check passed
CI pending the Windows job had not finished when I ran this; it is the real check for the MSYS2 CRT

Findings

Blocking

  • core/libs/runtime/src/Runtime.cpp:289 together with :292: crash reporters (Breakpad, Crashpad, Sentry and most engines' own) install their filter with prev = SetUnhandledExceptionFilter(Mine) and call prev at the end. Once ab_runtime.dll is loaded, prev is UnhandledException. On the crash, KeepFilter puts UnhandledException back on top and stores Mine in g_previousFilter. So UnhandledException → 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. On main it runs once, the report is written, and the process ends with the access violation. The older mingw-w64 _gnu_exception_handler chains the same way through __mingw_oldexcpt_handler.
    Fix: make UnhandledException refuse to be entered twice, for example
    std::atomic<bool> g_inFilter{};
    
    LONG WINAPI UnhandledException(EXCEPTION_POINTERS* pointers) {
        if (g_inFilter.exchange(true)) {
            return EXCEPTION_CONTINUE_SEARCH;
        }
        ...
    
    With that change applied locally, the probe calls the title's filter once, the report records 0xc0000005 in the probe, and e2e_crash still 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 exit 0xC0000005, a crash report, 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 calls SetUnhandledExceptionFilter, which also changes what a title gets back from its own SetUnhandledExceptionFilter call 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.

**@⁠Dark3581** on GitHub · 2026-11-21 12:35 UTC · [original](https://github.com/Dark3581/AnyBox/pull/16#pullrequestreview-6005215252) · **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 current `main` (`ddd30ef`). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory. ## Results | Check | Result | Note | | - | - | - | | MinGW full build | passed | no warnings | | CTest | passed | 39/39; `e2e_crash` writes its report with this CRT, as before | | Chained title filter (probe below) | **failed** | the title's filter is re-entered without end | | `tools/check_conventions.py`, `tools/debt_fold.py --check` | passed | | | CI | pending | the Windows job had not finished when I ran this; it is the real check for the MSYS2 CRT | ## Findings ### Blocking - `core/libs/runtime/src/Runtime.cpp:289` together with `:292`: crash reporters (Breakpad, Crashpad, Sentry and most engines' own) install their filter with `prev = SetUnhandledExceptionFilter(Mine)` and call `prev` at the end. Once `ab_runtime.dll` is loaded, `prev` is `UnhandledException`. On the crash, `KeepFilter` puts `UnhandledException` back on top and stores `Mine` in `g_previousFilter`. So `UnhandledException` → `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. On `main` it runs once, the report is written, and the process ends with the access violation. The older mingw-w64 `_gnu_exception_handler` chains the same way through `__mingw_oldexcpt_handler`. Fix: make `UnhandledException` refuse to be entered twice, for example ```cpp std::atomic<bool> g_inFilter{}; LONG WINAPI UnhandledException(EXCEPTION_POINTERS* pointers) { if (g_inFilter.exchange(true)) { return EXCEPTION_CONTINUE_SEARCH; } ... ``` With that change applied locally, the probe calls the title's filter once, the report records `0xc0000005` in the probe, and `e2e_crash` still 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 exit `0xC0000005`, a `crash` report, 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 calls `SetUnhandledExceptionFilter`, which also changes what a title gets back from its own `SetUnhandledExceptionFilter` call 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.
Author
Owner

@⁠Callimann8 on GitHub · 2026-11-21 12:40 UTC · original

Thanks for the probe. Pushed d26c0e1:

  • UnhandledException now returns EXCEPTION_CONTINUE_SEARCH if 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.
  • New e2e scenario 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 exit 0xC0000005, a crash report from title.exe, and exactly one title filter line.
  • The debt fragment adds a runtime entry: the vectored handler re-asserts the filter on every first-chance exception, a title's later SetUnhandledExceptionFilter gets 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 --check pass. Not run on Windows here, so CI is the check for both crash scenarios.

**@⁠Callimann8** on GitHub · 2026-11-21 12:40 UTC · [original](https://github.com/Dark3581/AnyBox/pull/16#issuecomment-7062725858) Thanks for the probe. Pushed d26c0e1: - `UnhandledException` now returns `EXCEPTION_CONTINUE_SEARCH` if 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. - New e2e scenario `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 exit `0xC0000005`, a `crash` report from `title.exe`, and exactly one `title filter` line. - The debt fragment adds a runtime entry: the vectored handler re-asserts the filter on every first-chance exception, a title's later `SetUnhandledExceptionFilter` gets 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 --check` pass. Not run on Windows here, so CI is the check for both crash scenarios.
Author
Owner

@⁠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_chained test fails on every run there.

What I ran

Head 2080d81, applied onto current main (4625f54, after #17). It applies without conflicts. MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.

Results

Check Result Note
MinGW full build passed no warnings
CTest failed 42/43; e2e_crash_chained fails with title filter printed twice
crash_chained repeated failed 15/15 runs print the title filter line twice
e2e_crash passed report written, as before
check_conventions.py passed
debt_fold.py --check passed 12 fragments apply cleanly
CI not run no Windows job on this head

Findings

Blocking

  • core/libs/runtime/src/Runtime.cpp:276, UnhandledException: on a CRT that still chains (WinLibs GCC 15.2, which docs/dev/BUILD.md lists as tested), one crash enters UnhandledException twice in sequence, not nested, so g_inFilter does not catch it. Stack traces from an instrumented fake_title:

    1. ntdll → _gnu_exception_handler (title.exe, the call *__mingw_oldexcpt_handler at the end) → UnhandledException → ChainingFilter → _gnu_exception_handler → UnhandledException (guard, returns EXCEPTION_CONTINUE_SEARCH).
    2. ntdll → KERNELBASE!UnhandledExceptionFilter → UnhandledException → ChainingFilter again.

    The CRT saved the AnyBox filter as __mingw_oldexcpt_handler at 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.

     std::atomic<bool> g_inFilter{};
    +std::atomic<DWORD> g_handledThread{};
    
     LONG WINAPI UnhandledException(EXCEPTION_POINTERS* pointers) {
         if (g_inFilter.exchange(true)) {
             return EXCEPTION_CONTINUE_SEARCH;
         }
    +    if (g_handledThread.load() == GetCurrentThreadId()) {
    +        g_inFilter.store(false);
    +        return EXCEPTION_CONTINUE_SEARCH;
    +    }
         ...
         const LONG result = previous != nullptr ? previous(pointers) : EXCEPTION_CONTINUE_SEARCH;
    +    g_handledThread.store(GetCurrentThreadId());
         g_inFilter.store(false);
         return result;
     }
    
     LONG WINAPI KeepFilter(EXCEPTION_POINTERS*) {
    +    if (!g_inFilter.load() && g_handledThread.load() == GetCurrentThreadId()) {
    +        g_handledThread.store(0);
    +    }
    

    With this: CTest 43/43, e2e_crash and e2e_crash_chained each 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 returned EXCEPTION_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 with EXCEPTION_CONTINUE_EXECUTION, then crashes on the main thread, on a std::thread, or with an uncaught throw:

    Runtime main-thread crash thread crash uncaught throw
    main filter 1 + 1 1 + 1 1, exit 0xc0000409
    this PR 1 + 2 1 + 1 1, exit 0xc0000409
    with the fix 1 + 1 1 + 1 1, exit 0xc0000409

    So 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

  • A fault that the title's own filter recovers from (EXCEPTION_CONTINUE_EXECUTION) still gets a crash report, because the AnyBox filter writes before it chains. A clean exit overwrites it with none. A later death that writes nothing (the 0xc0000409 row above) leaves the stale report, which points at the recovered fault. On main this already happens through the WinLibs CRT path. With KeepFilter keeping AnyBox on top, it now happens on every CRT. It's worth a line in the debt fragment.
  • g_inFilter is process-wide, so a second thread that crashes while the first is in the filter returns EXCEPTION_CONTINUE_SEARCH without 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.

**@⁠Dark3581** on GitHub · 2026-11-21 12:53 UTC · [original](https://github.com/Dark3581/AnyBox/pull/16#pullrequestreview-6005308321) · **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_chained` test fails on every run there. ## What I ran Head `2080d81`, applied onto current `main` (`4625f54`, after #17). It applies without conflicts. MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory. ## Results | Check | Result | Note | | - | - | - | | MinGW full build | passed | no warnings | | CTest | **failed** | 42/43; `e2e_crash_chained` fails with `title filter` printed twice | | `crash_chained` repeated | **failed** | 15/15 runs print the title filter line twice | | `e2e_crash` | passed | report written, as before | | `check_conventions.py` | passed | | | `debt_fold.py --check` | passed | 12 fragments apply cleanly | | CI | not run | no Windows job on this head | ## Findings ### Blocking - `core/libs/runtime/src/Runtime.cpp:276`, `UnhandledException`: on a CRT that still chains (WinLibs GCC 15.2, which `docs/dev/BUILD.md` lists as tested), one crash enters `UnhandledException` twice **in sequence**, not nested, so `g_inFilter` does not catch it. Stack traces from an instrumented `fake_title`: 1. `ntdll` → `_gnu_exception_handler` (`title.exe`, the `call *__mingw_oldexcpt_handler` at the end) → `UnhandledException` → `ChainingFilter` → `_gnu_exception_handler` → `UnhandledException` (guard, returns `EXCEPTION_CONTINUE_SEARCH`). 2. `ntdll` → `KERNELBASE!UnhandledExceptionFilter` → `UnhandledException` → `ChainingFilter` again. The CRT saved the AnyBox filter as `__mingw_oldexcpt_handler` at 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. ```diff std::atomic<bool> g_inFilter{}; +std::atomic<DWORD> g_handledThread{}; LONG WINAPI UnhandledException(EXCEPTION_POINTERS* pointers) { if (g_inFilter.exchange(true)) { return EXCEPTION_CONTINUE_SEARCH; } + if (g_handledThread.load() == GetCurrentThreadId()) { + g_inFilter.store(false); + return EXCEPTION_CONTINUE_SEARCH; + } ... const LONG result = previous != nullptr ? previous(pointers) : EXCEPTION_CONTINUE_SEARCH; + g_handledThread.store(GetCurrentThreadId()); g_inFilter.store(false); return result; } LONG WINAPI KeepFilter(EXCEPTION_POINTERS*) { + if (!g_inFilter.load() && g_handledThread.load() == GetCurrentThreadId()) { + g_handledThread.store(0); + } ``` With this: CTest 43/43, `e2e_crash` and `e2e_crash_chained` each 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 returned `EXCEPTION_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 with `EXCEPTION_CONTINUE_EXECUTION`, then crashes on the main thread, on a `std::thread`, or with an uncaught `throw`: | Runtime | main-thread crash | thread crash | uncaught throw | | - | - | - | - | | `main` | filter 1 + 1 | 1 + 1 | 1, exit `0xc0000409` | | this PR | 1 + **2** | 1 + 1 | 1, exit `0xc0000409` | | with the fix | 1 + 1 | 1 + 1 | 1, exit `0xc0000409` | So 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 - A fault that the title's own filter recovers from (`EXCEPTION_CONTINUE_EXECUTION`) still gets a `crash` report, because the AnyBox filter writes before it chains. A clean exit overwrites it with `none`. A later death that writes nothing (the `0xc0000409` row above) leaves the stale report, which points at the recovered fault. On `main` this already happens through the WinLibs CRT path. With `KeepFilter` keeping AnyBox on top, it now happens on every CRT. It's worth a line in the debt fragment. - `g_inFilter` is process-wide, so a second thread that crashes while the first is in the filter returns `EXCEPTION_CONTINUE_SEARCH` without 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.
Author
Owner

@⁠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 main into the branch:

  • UnhandledException records the thread it handled (g_handledThread) after the chained filter returns, and returns EXCEPTION_CONTINUE_SEARCH for a second call in the same dispatch on that thread. KeepFilter clears 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.
  • The debt fragment now also lists that a fault the title's own filter recovers from (EXCEPTION_CONTINUE_EXECUTION) still gets a crash report, since AnyBox writes before it chains, and that g_inFilter is 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.py and debt_fold.py --check pass. I couldn't run it on Windows, so your WinLibs run and CI on the new head are the checks for e2e_crash_chained.

**@⁠Callimann8** on GitHub · 2026-11-21 13:01 UTC · [original](https://github.com/Dark3581/AnyBox/pull/16#issuecomment-7062979152) Thanks for tracing the WinLibs double entry and for the verified fix. I pushed it as written, and also merged current `main` into the branch: - `UnhandledException` records the thread it handled (`g_handledThread`) after the chained filter returns, and returns `EXCEPTION_CONTINUE_SEARCH` for a second call in the same dispatch on that thread. `KeepFilter` clears 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. - The debt fragment now also lists that a fault the title's own filter recovers from (`EXCEPTION_CONTINUE_EXECUTION`) still gets a `crash` report, since AnyBox writes before it chains, and that `g_inFilter` is 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.py` and `debt_fold.py --check` pass. I couldn't run it on Windows, so your WinLibs run and CI on the new head are the checks for `e2e_crash_chained`.
Author
Owner

@⁠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 current main (4625f54). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory. main was built the same way for the comparison.

Results

Check Result Note
MinGW full build passed no warnings
CTest passed 43/43
e2e_crash, e2e_crash_chained repeated passed 25/25 each
Probe title (table below) failed 2 of 6 cases differ from main
check_conventions.py passed
debt_fold.py --check passed 12 fragments apply cleanly
CI passed all jobs green on d3f0b1b

The 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 with EXCEPTION_CONTINUE_EXECUTION, then:

Case main this PR with the fix below
null write, main thread 1 call, crash at +0x1874, 0xc0000005 same same
null write, std::thread 1 call, crash at +0x1874, 0xc0000005 same same
recovered fault, then exit 0 report none report crash at the recovered fault report none
recovered fault, then null write crash at +0x1874 crash at +0x18b9, the recovered fault crash at +0x1874
uncaught throw no report, 0xc0000409 same same
FreeLibrary(ab_runtime.dll), then a caught throw caught, exit 0 0xc0000005 caught, exit 0

Findings

Blocking

  • core/libs/runtime/src/Runtime.cpp:296: the report is written before the chained filter runs, and AbxWriteReport writes only once per process (g_reportWritten, :335). When the title's filter recovers (EXCEPTION_CONTINUE_EXECUTION), the crash report stays: a clean exit cannot replace it with none, and a later real crash cannot replace it either, so the report points at the fault that was recovered. On main the title's filter replaced ours, so neither happened. The debt fragment says "a clean exit overwrites it with none", which g_reportWritten prevents.
    Fix, verified with the probe above: keep writing before chaining (a crash reporter that calls TerminateProcess still leaves a report), and re-arm the report when the chained filter recovers.
         const LONG result = previous != nullptr ? previous(pointers) : EXCEPTION_CONTINUE_SEARCH;
    +    if (result == EXCEPTION_CONTINUE_EXECUTION) {
    +        g_reportWritten.store(false);
    +    }
         g_handledThread.store(GetCurrentThreadId());
    
    The mingw-w64 path for an uncaught GCC exception also returns EXCEPTION_CONTINUE_EXECUTION, but std::terminate ends the process without another report, so the crash file on disk stays. Please add an e2e scenario crash_recovered: the fake title installs a filter that fixes up a write to a PAGE_READONLY page and returns EXCEPTION_CONTINUE_EXECUTION, then returns 0. Expect exit 0 and a none report. 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. If ab_runtime.dll is unloaded with FreeLibrary, 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:
    +PVOID g_keepFilter = nullptr;
     ...
    -    AddVectoredExceptionHandler(0, KeepFilter);
    +    g_keepFilter = AddVectoredExceptionHandler(0, KeepFilter);
     ...
    +    } else if (reason == DLL_PROCESS_DETACH && reserved == nullptr && g_keepFilter != nullptr) {
    +        RemoveVectoredExceptionHandler(g_keepFilter);
         } else if (reason == DLL_PROCESS_DETACH && reserved != nullptr) {
    
    With both changes: CTest 43/43, and e2e_crash and e2e_crash_chained 25/25 each.
  • g_handledThread holds 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-wide g_inFilter already 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:27 UTC · [original](https://github.com/Dark3581/AnyBox/pull/16#pullrequestreview-6005462986) · **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 current `main` (`4625f54`). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory. `main` was built the same way for the comparison. ## Results | Check | Result | Note | | - | - | - | | MinGW full build | passed | no warnings | | CTest | passed | 43/43 | | `e2e_crash`, `e2e_crash_chained` repeated | passed | 25/25 each | | Probe title (table below) | **failed** | 2 of 6 cases differ from `main` | | `check_conventions.py` | passed | | | `debt_fold.py --check` | passed | 12 fragments apply cleanly | | CI | passed | all jobs green on `d3f0b1b` | The 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 with `EXCEPTION_CONTINUE_EXECUTION`, then: | Case | `main` | this PR | with the fix below | | - | - | - | - | | null write, main thread | 1 call, `crash` at `+0x1874`, `0xc0000005` | same | same | | null write, `std::thread` | 1 call, `crash` at `+0x1874`, `0xc0000005` | same | same | | recovered fault, then exit 0 | report `none` | **report `crash` at the recovered fault** | report `none` | | recovered fault, then null write | `crash` at `+0x1874` | **`crash` at `+0x18b9`, the recovered fault** | `crash` at `+0x1874` | | uncaught `throw` | no report, `0xc0000409` | same | same | | `FreeLibrary(ab_runtime.dll)`, then a caught `throw` | caught, exit 0 | **`0xc0000005`** | caught, exit 0 | ## Findings ### Blocking - `core/libs/runtime/src/Runtime.cpp:296`: the report is written before the chained filter runs, and `AbxWriteReport` writes only once per process (`g_reportWritten`, `:335`). When the title's filter recovers (`EXCEPTION_CONTINUE_EXECUTION`), the `crash` report stays: a clean exit cannot replace it with `none`, and a later real crash cannot replace it either, so the report points at the fault that was recovered. On `main` the title's filter replaced ours, so neither happened. The debt fragment says "a clean exit overwrites it with `none`", which `g_reportWritten` prevents. Fix, verified with the probe above: keep writing before chaining (a crash reporter that calls `TerminateProcess` still leaves a report), and re-arm the report when the chained filter recovers. ```diff const LONG result = previous != nullptr ? previous(pointers) : EXCEPTION_CONTINUE_SEARCH; + if (result == EXCEPTION_CONTINUE_EXECUTION) { + g_reportWritten.store(false); + } g_handledThread.store(GetCurrentThreadId()); ``` The mingw-w64 path for an uncaught GCC exception also returns `EXCEPTION_CONTINUE_EXECUTION`, but `std::terminate` ends the process without another report, so the `crash` file on disk stays. Please add an e2e scenario `crash_recovered`: the fake title installs a filter that fixes up a write to a `PAGE_READONLY` page and returns `EXCEPTION_CONTINUE_EXECUTION`, then returns 0. Expect exit 0 and a `none` report. 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. If `ab_runtime.dll` is unloaded with `FreeLibrary`, 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: ```diff +PVOID g_keepFilter = nullptr; ... - AddVectoredExceptionHandler(0, KeepFilter); + g_keepFilter = AddVectoredExceptionHandler(0, KeepFilter); ... + } else if (reason == DLL_PROCESS_DETACH && reserved == nullptr && g_keepFilter != nullptr) { + RemoveVectoredExceptionHandler(g_keepFilter); } else if (reason == DLL_PROCESS_DETACH && reserved != nullptr) { ``` With both changes: CTest 43/43, and `e2e_crash` and `e2e_crash_chained` 25/25 each. - `g_handledThread` holds 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-wide `g_inFilter` already 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.
Author
Owner

@⁠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 onto main (4625f54) as 2612937, plus the follow-up b5bac96. MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.

Results

Check Result Note
MinGW full build passed no warnings
CTest passed 45/45 with the follow-up
e2e_crash, e2e_crash_chained, e2e_crash_recovered repeated passed 25/25 each
e2e_crash_recovered without the re-arm failed as expected report stays crash after exit 0
Probe title passed all 6 cases (chained crash, thread crash, recovered fault then exit, recovered fault then crash, uncaught throw, unload then throw) match main
check_conventions.py, debt_fold.py --check passed
CI passed all jobs green on d3f0b1b

Follow-up in b5bac96

  • UnhandledException re-arms the report when the replaced filter returns EXCEPTION_CONTINUE_EXECUTION, so a recovered fault no longer leaves a crash report behind and a later crash reports its own address.
  • DllMain removes the vectored handler on a FreeLibrary unload.
  • New scenario crash_recovered: the fake title fixes up a write to a read-only page from its own filter and exits 0; expects a none report.
  • The fragment drops the recovered-fault entry and adds the single-thread g_handledThread mark 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](https://github.com/Dark3581/AnyBox/pull/16#pullrequestreview-6005559153) · **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 onto `main` (`4625f54`) as `2612937`, plus the follow-up `b5bac96`. MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory. ## Results | Check | Result | Note | | - | - | - | | MinGW full build | passed | no warnings | | CTest | passed | 45/45 with the follow-up | | `e2e_crash`, `e2e_crash_chained`, `e2e_crash_recovered` repeated | passed | 25/25 each | | `e2e_crash_recovered` without the re-arm | failed as expected | report stays `crash` after exit 0 | | Probe title | passed | all 6 cases (chained crash, thread crash, recovered fault then exit, recovered fault then crash, uncaught throw, unload then throw) match `main` | | `check_conventions.py`, `debt_fold.py --check` | passed | | | CI | passed | all jobs green on `d3f0b1b` | ## Follow-up in `b5bac96` - `UnhandledException` re-arms the report when the replaced filter returns `EXCEPTION_CONTINUE_EXECUTION`, so a recovered fault no longer leaves a `crash` report behind and a later crash reports its own address. - `DllMain` removes the vectored handler on a `FreeLibrary` unload. - New scenario `crash_recovered`: the fake title fixes up a write to a read-only page from its own filter and exits 0; expects a `none` report. - The fragment drops the recovered-fault entry and adds the single-thread `g_handledThread` mark 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.
Author
Owner

@⁠Dark3581 on GitHub · 2026-11-21 13:38 UTC · original

Landed on main as 2612937, with the follow-up b5bac96 (report re-arm after a recovered fault, handler removal on unload, e2e_crash_recovered). Closing here.

**@⁠Dark3581** on GitHub · 2026-11-21 13:38 UTC · [original](https://github.com/Dark3581/AnyBox/pull/16#issuecomment-7063445069) Landed on main as 2612937, with the follow-up b5bac96 (report re-arm after a recovered fault, handler removal on unload, `e2e_crash_recovered`). Closing here.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.