fix(libc): report integer overflow faults in the Windows crash report #14405

Merged
roboterspinne merged 1 commit from upstream-pr/14405 into main 2026-11-02 19:49:51 +00:00
roboterspinne commented 2026-11-01 11:35:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by roboterspinne on 2026-11-01T11:35:32Z.


What

On 26fa1212b8 (line numbers below refer to it) a guest idiv of INT_MIN by -1 on Windows ends the process without a crash report. Guest code runs natively, and on x64 DIV/IDIV raise the same divide error (#DE) for a zero divisor and for a quotient that does not fit the destination (Intel SDM, DIV and IDIV); Windows reports the first as EXCEPTION_INT_DIVIDE_BY_ZERO (0xC0000094) and the second as EXCEPTION_INT_OVERFLOW (0xC0000095), and since INTO is invalid in 64-bit mode, 0xC0000095 has no other hardware source. The vectored handler ReportCrash (installed at core/libs/prx/libc/src/specifics/windows/CrashReport.cpp:677) reports only codes that IsFatal lists (CrashReport.cpp:72-85), and that list has 0xC0000094 (line 78) but not 0xC0000095, so the overflow returns EXCEPTION_CONTINUE_SEARCH at line 365 and prints no FATAL line, no registers, no call trace and nothing to the ANYPS5_LOG_FILE copy. The repository already treats both codes as one class: ChildProcessWaitStatus maps both to SIGFPE (core/libs/prx/libc/src/Process.cpp:304-305), and open #14298 reports SIGFPE as fatal on Linux, which covers both outcomes there.

  • Rule. IsFatal lists EXCEPTION_INT_OVERFLOW next to EXCEPTION_INT_DIVIDE_BY_ZERO, so both outcomes of the divide error are reported the same way. Nothing else changes: ReportCrash still returns EXCEPTION_CONTINUE_SEARCH after the report (line 477), so whether and how the process ends is unchanged. Vectored handlers added with First=1 after libc loads still run before ReportCrash, and open #7192 calls its HandleHostFault inside ReportCrash before the IsFatal check, so a guest handler keeps the first chance. Floating-point codes, misalignment, breakpoints and single steps stay unlisted.
  • Tests. New windows_integer_overflow_report (Windows only) loads libc, then divides INT_MIN by -1 with cltd; idivl from registers the compiler cannot fold, and expects dividing followed by FATAL: unhandled exception 0xc0000095; did not fault fails it. No existing test raises 0xC0000095 or divides INT_MIN by -1.
  • Overlap. pr_overlap.py --branch finds no shared lines with the open pull requests it can compare and cannot compare 17 that do not merge with main: #7192, #11628, #11661, #11689 and #11698 share windows/CrashReport.cpp, and #5021, #7275, #8650, #9156, #9162, #9293, #9297, #9302, #9383, #12642, #13253 and #13256 share core/libs/CMakeLists.txt. Checked by hand: a trial merge of this branch with each of them conflicts in exactly the files that main with it already conflicts in, so this change adds no conflict.

Tested

Windows 11, WinLibs GCC 15.2.0, Ninja Release build (BUILD_TESTING=ON) of the targets libc, windows_integer_overflow_report_tests and windows_crash_text_tests on 25ee90defa (based on 26fa1212b8; it merges cleanly with main at e67cc81869, which changes none of the three touched files):

  • cmake --build build --target windows_integer_overflow_report_tests windows_crash_text_tests libc, then ctest --test-dir build -R "^(windows_integer_overflow_report|windows_crash_text)$" -V.
  • Counter-check with the new test and the IsFatal of 26fa1212b8: windows_integer_overflow_report fails with Required regular expression not found; its whole output is dividing, and run directly the test exits with 3 from its unhandled-exception filter, so the fault happened but nothing was reported. windows_crash_text passes.
  • With this change both pass: the new test prints dividing, FATAL: unhandled exception 0xc0000095, rip ... windows_integer_overflow_report_tests.exe+0x91b9 (the idiv %r10d, with r10 = 0xffffffff and rax = 0x80000000 in the register dump) and the rest of the report; windows_crash_text still reports its access violation as before.
  • The test executable is registered with configure_host_test_executable (docs/dev/CONVENTIONS.md, host-only test executables), so it links with -static -static-libgcc -static-libstdc++ and objdump -p shows no libstdc++-6.dll import; with that, ctest --test-dir build -R '^(windows_integer_overflow_report|windows_crash_text)$' passes 2/2.
  • python tools/check_conventions.py --base 26fa1212b8 with this title and description passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5106951380 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14405). Originally posted by [roboterspinne](https://github.com/roboterspinne) on 2026-11-01T11:35:32Z. --- ### What On 26fa1212b8 (line numbers below refer to it) a guest `idiv` of `INT_MIN` by `-1` on Windows ends the process without a crash report. Guest code runs natively, and on x64 `DIV`/`IDIV` raise the same divide error (#DE) for a zero divisor and for a quotient that does not fit the destination (Intel SDM, DIV and IDIV); Windows reports the first as `EXCEPTION_INT_DIVIDE_BY_ZERO` (0xC0000094) and the second as `EXCEPTION_INT_OVERFLOW` (0xC0000095), and since `INTO` is invalid in 64-bit mode, 0xC0000095 has no other hardware source. The vectored handler `ReportCrash` (installed at `core/libs/prx/libc/src/specifics/windows/CrashReport.cpp:677`) reports only codes that `IsFatal` lists (`CrashReport.cpp:72-85`), and that list has 0xC0000094 (line 78) but not 0xC0000095, so the overflow returns `EXCEPTION_CONTINUE_SEARCH` at line 365 and prints no `FATAL` line, no registers, no call trace and nothing to the `ANYPS5_LOG_FILE` copy. The repository already treats both codes as one class: `ChildProcessWaitStatus` maps both to `SIGFPE` (`core/libs/prx/libc/src/Process.cpp:304-305`), and open #14298 reports `SIGFPE` as fatal on Linux, which covers both outcomes there. - **Rule.** `IsFatal` lists `EXCEPTION_INT_OVERFLOW` next to `EXCEPTION_INT_DIVIDE_BY_ZERO`, so both outcomes of the divide error are reported the same way. Nothing else changes: `ReportCrash` still returns `EXCEPTION_CONTINUE_SEARCH` after the report (line 477), so whether and how the process ends is unchanged. Vectored handlers added with `First=1` after libc loads still run before `ReportCrash`, and open #7192 calls its `HandleHostFault` inside `ReportCrash` before the `IsFatal` check, so a guest handler keeps the first chance. Floating-point codes, misalignment, breakpoints and single steps stay unlisted. - **Tests.** New `windows_integer_overflow_report` (Windows only) loads libc, then divides `INT_MIN` by `-1` with `cltd; idivl` from registers the compiler cannot fold, and expects `dividing` followed by `FATAL: unhandled exception 0xc0000095`; `did not fault` fails it. No existing test raises 0xC0000095 or divides `INT_MIN` by `-1`. - **Overlap.** `pr_overlap.py --branch` finds no shared lines with the open pull requests it can compare and cannot compare 17 that do not merge with `main`: #7192, #11628, #11661, #11689 and #11698 share `windows/CrashReport.cpp`, and #5021, #7275, #8650, #9156, #9162, #9293, #9297, #9302, #9383, #12642, #13253 and #13256 share `core/libs/CMakeLists.txt`. Checked by hand: a trial merge of this branch with each of them conflicts in exactly the files that `main` with it already conflicts in, so this change adds no conflict. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, WinLibs GCC 15.2.0, Ninja Release build (`BUILD_TESTING=ON`) of the targets `libc`, `windows_integer_overflow_report_tests` and `windows_crash_text_tests` on 25ee90defa (based on 26fa1212b8; it merges cleanly with `main` at e67cc81869, which changes none of the three touched files): - `cmake --build build --target windows_integer_overflow_report_tests windows_crash_text_tests libc`, then `ctest --test-dir build -R "^(windows_integer_overflow_report|windows_crash_text)$" -V`. - Counter-check with the new test and the `IsFatal` of 26fa1212b8: `windows_integer_overflow_report` fails with `Required regular expression not found`; its whole output is `dividing`, and run directly the test exits with 3 from its unhandled-exception filter, so the fault happened but nothing was reported. `windows_crash_text` passes. - With this change both pass: the new test prints `dividing`, `FATAL: unhandled exception 0xc0000095`, `rip ... windows_integer_overflow_report_tests.exe+0x91b9` (the `idiv %r10d`, with `r10` = `0xffffffff` and `rax` = `0x80000000` in the register dump) and the rest of the report; `windows_crash_text` still reports its access violation as before. - The test executable is registered with `configure_host_test_executable` (`docs/dev/CONVENTIONS.md`, host-only test executables), so it links with `-static -static-libgcc -static-libstdc++` and `objdump -p` shows no `libstdc++-6.dll` import; with that, `ctest --test-dir build -R '^(windows_integer_overflow_report|windows_crash_text)$'` passes 2/2. - `python tools/check_conventions.py --base 26fa1212b8` with this title and description passed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/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] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
MarcZX10 commented 2026-11-01 12:47:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-01T12:47:51Z.

Review: COMMENTED


Reviewed — no blocking findings

The one-line change classifies EXCEPTION_INT_OVERFLOW as a fatal fault in IsFatal, next to the existing integer-divide case, and the hosted Windows run for this head passed all 2585 CTest tests, including windows_integer_overflow_report_tests; I found no blocking issue at 25ee90defa.

What I ran

Exact head 25ee90defae602a4526baf0cc1a119debe6252b7; PR base b2620e56d114ef053f8b45433b1d48aff7ec37ba (precheck base), unchanged at completion. No local build and no local test run. Commands:

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14405
python3 tools/pr_abi_audit.py --base b2620e56d114ef053f8b45433b1d48aff7ec37ba --head 25ee90defae602a4526baf0cc1a119debe6252b7 --json
python3 tools/pr_test_quality.py --root <git archive of 25ee90defa: core/libs/tests, core/libs/prx/libc, core/libs/CMakeLists.txt> --json core/libs/tests/WindowsIntegerOverflowReport.cpp

The precheck's ABI and test-quality helpers were missing from the isolated head tree, so both were run by hand. I also read the changed hunk (core/libs/prx/libc/src/specifics/windows/CrashReport.cpp L75-L82) and Process.cpp L305, which maps 0xC0000095 to SIGFPE (8).

Results

Check Result
Diff check (precheck) Passed
Conventions and PR template (precheck) Passed
Live dependency and mergeability (precheck) Passed
ABI audit (by hand) Not applicable: no export declaration changed
Test-quality heuristic (by hand) One possible-unregistered-cpp-test finding; false positive, because the test is registered in core/libs/CMakeLists.txt L683-L685
Hosted Windows, job at this head Success; 100% of 2585 CTest tests passed, including windows_integer_overflow_report_tests
Hosted relinker (Ubuntu, Windows), relinker-asan, register-context (Ubuntu) Success
Hosted macOS jobs, write-watch, register-context (macOS) Queued at this head

Findings

Blocking: none.

Non-blocking: none.

Not verified

  • Nothing was compiled or run locally.
  • The macOS jobs are still queued at this head. Approval is deferred until they finish, which is why this review is COMMENTED.
  • Console behaviour of this fault path is not measured.

To get this to a good state

No change is needed for this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5728130831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14405#pullrequestreview-5728130831). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-01T12:47:51Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The one-line change classifies `EXCEPTION_INT_OVERFLOW` as a fatal fault in `IsFatal`, next to the existing integer-divide case, and the hosted Windows run for this head passed all 2585 CTest tests, including `windows_integer_overflow_report_tests`; I found no blocking issue at `25ee90defa`. ## What I ran Exact head `25ee90defae602a4526baf0cc1a119debe6252b7`; PR base `b2620e56d114ef053f8b45433b1d48aff7ec37ba` (precheck base), unchanged at completion. No local build and no local test run. Commands: ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14405 python3 tools/pr_abi_audit.py --base b2620e56d114ef053f8b45433b1d48aff7ec37ba --head 25ee90defae602a4526baf0cc1a119debe6252b7 --json python3 tools/pr_test_quality.py --root <git archive of 25ee90defa: core/libs/tests, core/libs/prx/libc, core/libs/CMakeLists.txt> --json core/libs/tests/WindowsIntegerOverflowReport.cpp ``` The precheck's ABI and test-quality helpers were missing from the isolated head tree, so both were run by hand. I also read the changed hunk (`core/libs/prx/libc/src/specifics/windows/CrashReport.cpp` L75-L82) and `Process.cpp` L305, which maps `0xC0000095` to SIGFPE (8). ## Results | Check | Result | |---|---| | Diff check (precheck) | Passed | | Conventions and PR template (precheck) | Passed | | Live dependency and mergeability (precheck) | Passed | | ABI audit (by hand) | Not applicable: no export declaration changed | | Test-quality heuristic (by hand) | One `possible-unregistered-cpp-test` finding; false positive, because the test is registered in `core/libs/CMakeLists.txt` L683-L685 | | Hosted Windows, job at this head | Success; 100% of 2585 CTest tests passed, including `windows_integer_overflow_report_tests` | | Hosted relinker (Ubuntu, Windows), relinker-asan, register-context (Ubuntu) | Success | | Hosted macOS jobs, write-watch, register-context (macOS) | Queued at this head | ## Findings **Blocking:** none. **Non-blocking:** none. ## Not verified - Nothing was compiled or run locally. - The macOS jobs are still queued at this head. Approval is deferred until they finish, which is why this review is COMMENTED. - Console behaviour of this fault path is not measured. ## To get this to a good state No change is needed for this review.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14405
No description provided.