fix(libc): list stack return address candidates in Windows backtrace reports #3887

Merged
reyani-dev merged 2 commits from upstream-pr/3887 into main 2026-10-11 22:14:00 +00:00
reyani-dev commented 2026-10-11 18:44:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T18:44:26Z.


What

On Windows, the abort() and UCRT invalid-parameter reports (ReportBacktrace in CrashReport.cpp) capture the stack with RtlCaptureStackBackTrace. That stops at the first frame without unwind data: guest code, or our own .prx libraries, which are built with -fno-asynchronous-unwind-tables. So these reports usually end two or three frames in, before reaching any caller. The fault report (ReportCrash) already scans the stack for code addresses ("stack return address candidates"). This PR moves that scan into a helper. ReportCrash uses it unchanged (16 entries over 0x2000 bytes), and ReportBacktrace now uses it too, with 32 entries over 0x4000 bytes, since it starts inside our handler and the UCRT's frames.

Where it matters: catalog titles that abort on Windows. On main a11c8f7f, ProsperoTV (PPSA99003) aborts on the poll throw (#3584) and its report ends with:

FATAL: abort() (SIGABRT) on thread 37596
    #0 0x00007ffa04cdac85 libkernel.prx+0x5ac85
    #1 0x00007ffa04cda8d5 libkernel.prx+0x5a8d5
    #2 0x00007ffa04cb49a6 libkernel.prx+0x349a6
    #3 0x00007ffaad09cd30 ucrtbase.dll+0x2cd30

There's no guest frame, so the guest call site has to be found another way. ProsperoLight (PPSA99002), on main plus open PRs for its earlier stops, reports FATAL: UCRT invalid parameter with only libc.prx+0xa9e7, libc.prx+0x9f492 and a stack address. With the scan, the same report lists the libSceNet.prx, libkernel.prx and app.exe return addresses above it, which is how I narrowed it down. That stop isn't on main yet, so I'm not filing it here.

The test's own output with this change:

FATAL: abort() (SIGABRT) on thread 42996
    #0 0x00007ff9620da9f8 libc.prx+0xa9f8
    #1 0x00007ff96216f4e9 libc.prx+0x9f4e9
    #2 0x0000006c3d5ff4f0
  stack return address candidates:
    [rsp+0x8] 0x00007ffaad132139 ucrtbase.dll+0xc2139
    [rsp+0x88] 0x00007ffaad115261 ucrtbase.dll+0xa5261
    [rsp+0xb8] 0x00007ff70388349a windows_backtrace_report_tests.exe+0x349a
    ...

Tested

Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, main a11c8f7f:

  • New windows_backtrace_report test (Windows only). A process that loads libc.prx calls abort(), and CTest's PASS_REGULAR_EXPRESSION requires stack return address candidates: with an rsp+0x line after the FATAL: abort() (SIGABRT) line. It fails with the CrashReport.cpp change reverted and passes with it. (It goes through abort() because a MinGW executable's start-up code installs its own invalid-parameter handler over libc's; relinked titles don't run that code.)
  • ctest -E "^agc_|video_out": 451/454. The 3 failures also fail on main on Windows: windows_exceptions (#3411), guest_kernel_sys (#3510) and guest_filesystem (#3518). guest_exception_* pass.
  • tools/check_conventions.py and tools/pr_overlap.py: clean. The helper sits beside ReportBacktrace, away from #3746's hunk in the same file.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821423460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3887). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T18:44:26Z. --- ### What On Windows, the `abort()` and UCRT invalid-parameter reports (`ReportBacktrace` in `CrashReport.cpp`) capture the stack with `RtlCaptureStackBackTrace`. That stops at the first frame without unwind data: guest code, or our own `.prx` libraries, which are built with `-fno-asynchronous-unwind-tables`. So these reports usually end two or three frames in, before reaching any caller. The fault report (`ReportCrash`) already scans the stack for code addresses ("stack return address candidates"). This PR moves that scan into a helper. `ReportCrash` uses it unchanged (16 entries over 0x2000 bytes), and `ReportBacktrace` now uses it too, with 32 entries over 0x4000 bytes, since it starts inside our handler and the UCRT's frames. **Where it matters:** catalog titles that abort on Windows. On `main` a11c8f7f, ProsperoTV (PPSA99003) aborts on the `poll` throw (#3584) and its report ends with: ``` FATAL: abort() (SIGABRT) on thread 37596 #0 0x00007ffa04cdac85 libkernel.prx+0x5ac85 #1 0x00007ffa04cda8d5 libkernel.prx+0x5a8d5 #2 0x00007ffa04cb49a6 libkernel.prx+0x349a6 #3 0x00007ffaad09cd30 ucrtbase.dll+0x2cd30 ``` There's no guest frame, so the guest call site has to be found another way. ProsperoLight (PPSA99002), on `main` plus open PRs for its earlier stops, reports `FATAL: UCRT invalid parameter` with only `libc.prx+0xa9e7`, `libc.prx+0x9f492` and a stack address. With the scan, the same report lists the `libSceNet.prx`, `libkernel.prx` and `app.exe` return addresses above it, which is how I narrowed it down. That stop isn't on `main` yet, so I'm not filing it here. The test's own output with this change: ``` FATAL: abort() (SIGABRT) on thread 42996 #0 0x00007ff9620da9f8 libc.prx+0xa9f8 #1 0x00007ff96216f4e9 libc.prx+0x9f4e9 #2 0x0000006c3d5ff4f0 stack return address candidates: [rsp+0x8] 0x00007ffaad132139 ucrtbase.dll+0xc2139 [rsp+0x88] 0x00007ffaad115261 ucrtbase.dll+0xa5261 [rsp+0xb8] 0x00007ff70388349a windows_backtrace_report_tests.exe+0x349a ... ``` ### Tested Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, `main` a11c8f7f: - New `windows_backtrace_report` test (Windows only). A process that loads `libc.prx` calls `abort()`, and CTest's `PASS_REGULAR_EXPRESSION` requires `stack return address candidates:` with an `rsp+0x` line after the `FATAL: abort() (SIGABRT)` line. It fails with the `CrashReport.cpp` change reverted and passes with it. (It goes through `abort()` because a MinGW executable's start-up code installs its own invalid-parameter handler over libc's; relinked titles don't run that code.) - `ctest -E "^agc_|video_out"`: 451/454. The 3 failures also fail on `main` on Windows: `windows_exceptions` (#3411), `guest_kernel_sys` (#3510) and `guest_filesystem` (#3518). `guest_exception_*` pass. - `tools/check_conventions.py` and `tools/pr_overlap.py`: clean. The helper sits beside `ReportBacktrace`, away from #3746's hunk in the same file. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-11 22:13:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:13:54Z.


Checked the diff: ReportCrash keeps its 16 entries / 0x2000 bytes through the new helper, ReportBacktrace adds the stack scan, helper is declared in the anonymous namespace before use, and windows_backtrace_report is registered in ctest under if(MINGW) with a regex matching the report. Windows-only, so not built or run here; merging on green CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114449114 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3887#issuecomment-6114449114). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:13:54Z. --- Checked the diff: `ReportCrash` keeps its 16 entries / 0x2000 bytes through the new helper, `ReportBacktrace` adds the stack scan, helper is declared in the anonymous namespace before use, and `windows_backtrace_report` is registered in ctest under `if(MINGW)` with a regex matching the report. Windows-only, so not built or run here; merging on green CI.
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!3887
No description provided.