Skip to content

fix(libc): write the run report when the run ends in std::terminate - #16757

Merged
oneandonlydean merged 5 commits into
boykopovar:mainfrom
milescoviello:fix/run-report-terminate
Nov 13, 2026
Merged

oneandonlydean merged 5 commits into
boykopovar:mainfrom
milescoviello:fix/run-report-terminate

Conversation

@milescoviello

@milescoviello milescoviello commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

What

A run that ends in std::terminate now writes its run report, with exit abort and reason runtime-stop. When a function that is not implemented threw, the stop is missing-function with that function's source and the schema fixture's "Called …, which is not implemented." message; otherwise it is other with the exception's text. With the runtime's own terminate handler the report is written before it runs; a game's own handler runs first, so one that exits writes its own clean report. LibcException::InvokeTerminate (libc's exception runtime, which the host libraries and the title both throw through) finishes the report before it calls the terminate handler, through a new LibcRunReportTerminate_nid_no_patch. The terminate handler then runs as before, so the terminate called after throwing ... line and the abort are unchanged.

Before, only exit, _exit and an entry that returns wrote the report, and docs/dev/debt/libc.md said so ("A run that crashes, aborts or is killed writes no report"). The report format already had the abort exit and the runtime-stop reason ("The runtime stopped the run on an error it reported."), but nothing produced them.

DefaultTerminate's lookup of the caught exception's what() moves into CaughtWhat, so the report and the default handler read it the same way. On Windows its guest what() call now spells the calling convention with APS5_VABI, which is the same __attribute__((sysv_abi)) there.

Why

A function that is not implemented throws (NotImplementedAt_nid_no_patch), and when nothing catches it the throw ends in std::terminate. That is how most titles stop today, and none of those runs wrote a report, so nothing could be uploaded for them. On main 090f57166a tonight:

  • MXGP 2026 (PPSA30839) stops 7 s in on sceHttp2SendRequestAsync not implemented, with no anyps5-report.json.
  • Crimson Desert (PPSA25286) stops 1 s in on the same function, with no report either.

The missing-function table was already filled in before the throw (NoteMissingFunction). With this change it reaches the report.

Test

The first commit adds child-uncaught-missing-function to run_report (core/libs/tests/RunReport.cpp), in the same child-process harness as child-missing-function. The child calls NotImplemented_nid_no_patch("sceNpUncaught") on a thread of its own that catches nothing, the way a title's thread does. The test then requires that:

  • the child ends through abort;
  • its report has "exit": "abort", "reason": "runtime-stop", "kind": "other" and "message": "sceNpUncaught not implemented";
  • the missing-function table lists sceNpUncaught once.

On the test commit the child aborts without writing a report, so the test fails there.

The debt entry now describes the terminate path, and still lists what writes no report: a crash on a signal, a direct abort and a killed run. It also notes that the child-process tests are built on Linux and macOS only.

Tested

  • MXGP 2026 (PPSA30839), release libs built from this head: 7 s in, the run now leaves anyps5-report.json with "exit": "abort", stop {"kind": "other", "reason": "runtime-stop", "message": "sceHttp2SendRequestAsync not implemented"} and stage presents. On main the same run leaves no report.
  • Windows 11 VM, GT 1030, WinLibs GCC 15.2, Release, test commit vs head:
    • the build passes on both, which compiles the _WIN32 CaughtWhat path;
    • run_report, guest_sce_v2_exceptions and exception_personality pass 3 of 3 on each;
    • exception_runtime and exception_c_cleanup are not built on Windows;
    • the run report's child-process tests are #ifndef _WIN32, so the new case does not run there.
  • Linux, RTX 4070 Ti, GCC 15.2: run_report fails 3 of 3 on the test commit 807251284d (... lacks "exit": "abort": the child aborts without a report) and passes 3 of 3 at the head de2eeea8f7; exception_runtime, exception_c_cleanup, exception_personality and guest_sce_v2_exceptions pass on both. (A first run had the child throw inside the harness's own try in main(); the case now throws on a thread of its own, as a title's thread does.)
  • -fsyntax-only with the build's flags and tools/check_conventions.py --base upstream/main pass.

Overlap: #14298 reports fatal host signals on Linux in the log file, and #16591 adds an include to RunReport.cpp. Neither touches the terminate path, and both merge cleanly with this.

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 (MXGP PPSA30839 and Crimson Desert PPSA25286 stop on a missing function on main and leave no report)
  • GPUs tested: n/a (libc change; tests run on Linux and the Windows VM)
  • AI-assisted: yes

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 16791 core/libs/prx/libc/src/exception/Runtime.cpp L3-4

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4847 docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6924 docs/user/USAGE.md
PR 7447 docs/dev/debt/libc.md
PR 7642 docs/user/USAGE.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9087 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9345 docs/user/USAGE.md
PR 9447 docs/dev/debt/libc.md
PR 9466 docs/dev/debt/libc.md
PR 9508 docs/user/USAGE.md
PR 9526 docs/dev/debt/libc.md
PR 10193 docs/user/USAGE.md
PR 10397 docs/dev/debt/libc.md
PR 10780 docs/dev/debt/libc.md
PR 10792 docs/user/USAGE.md
PR 10861 docs/user/USAGE.md
PR 11172 docs/dev/debt/libc.md
PR 11266 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11661 docs/dev/debt/libc.md
PR 11689 docs/dev/debt/libc.md
PR 11698 docs/dev/debt/libc.md
PR 12678 docs/user/USAGE.md
PR 12682 docs/dev/debt/libc.md
PR 12688 docs/dev/debt/libc.md
PR 12700 docs/dev/debt/libc.md
PR 12746 docs/user/USAGE.md
PR 12849 docs/dev/debt/libc.md
PR 12965 docs/dev/debt/libc.md
PR 13928 docs/user/USAGE.md
PR 13929 docs/user/USAGE.md
PR 15245 docs/user/USAGE.md
PR 15456 docs/user/USAGE.md
PR 15973 core/libs/prx/libc/include/RunReport.hpp
core/libs/prx/libc/src/RunReport.cpp
core/libs/tests/RunReport.cpp
docs/dev/debt/libc.md
docs/user/USAGE.md
docs/user/run-report.md
tools/tests/test_run_report_docs.py
PR 16354 docs/user/USAGE.md
PR 17557 docs/dev/debt/libc.md
docs/user/USAGE.md
PR 17558 docs/dev/debt/libc.md
docs/user/USAGE.md
PR 17652 docs/user/USAGE.md
PR 18082 docs/user/USAGE.md
PR 18085 docs/user/USAGE.md
PR 18848 docs/dev/debt/libc.md

@milescoviello
milescoviello force-pushed the fix/run-report-terminate branch from 67d6e9e to de2eeea Compare November 7, 2026 16:37
@milescoviello

Copy link
Copy Markdown
Contributor Author

Results, each case 3 times:

Machine Test commit 807251284d Head de2eeea8f7
Linux, RTX 4070 Ti, GCC 15.2, run_report + exception_runtime, exception_c_cleanup, exception_personality, guest_sce_v2_exceptions run_report fails 3 of 3, the other 4 pass all 5 pass 3 of 3
Windows 11 VM, WinLibs GCC 15.2, run_report, exception_personality, guest_sce_v2_exceptions (the child-process cases are not built on Windows) 3 of 3 pass 3 of 3 pass

The failure on the test commit is the one the case is there for. The child ends through abort but leaves no report: child-uncaught-missing-function: the report of the run that ended in std::terminate lacks "exit": "abort".

The Windows runs used the earlier head 67d6e9ec38. It has the same libc code; only the Linux/macOS child mode changed since.

A title, MXGP 2026 (PPSA30839), on release libs built from this change: it stops 7 s in on sceHttp2SendRequestAsync not implemented and now writes anyps5-report.json with exit abort and that message as a runtime-stop stop. On main it writes none.

AI-assisted: yes (Claude Code)

@milescoviello
milescoviello marked this pull request as ready for review November 7, 2026 17:02

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read de2eeea8f7 against main.

The terminate path now takes the stderr stream lock. Runtime.cpp:19-20 says terminate paths write raw because another, possibly suspended, thread may hold the CRT stream lock. InvokeTerminate (Runtime.cpp:94-98) now runs the report's Finish first, and Finish prints with std::fprintf(stderr, …) (RunReport.cpp:1599-1604). If another thread holds the stderr lock and isn't running, for example one suspended by the Windows sceKernelRaiseException path, the terminating thread blocks there and the run hangs instead of aborting. Not reproduced; skipping those lines when exit is Abort, or printing them with the raw writer, removes it. The collector's own locks are fine: mutex is only held to flip state, the tables use try_lock_for, and a second terminate waits at most 3 s (:1571-1573) and returns.

A terminate handler that exits is reported as abort. The report is finished before the handler runs, so a title handler that calls exit(3) reaches LibcRunReportFinishExit_nid_no_patch with the report already done: it says abort with a null exit code while the process exits with 3. Writing it first only for DefaultTerminate / std::abort, and otherwise after the handler returns, keeps both cases right.

User docs. docs/user/run-report.md:15 and docs/user/USAGE.md:506 still say "A run that is killed, crashes or aborts writes no report", run-report.md:46 lists only guest-exit, and tools/tests/test_run_report_docs.py:49-52 pins the old USAGE sentence. Only the debt entry was updated.

Stop kind. The schema already has kind: missing-function with a source (docs/run-report-fixtures/stop-missing-function.json), and NotImplementedAt_nid_no_patch knows the file and line, yet the motivating case is reported as other with a null source.

Template. GPUs tested should read n/a for a change outside AGC, the shader recompiler and VideoOut.

CI. The new child-process case is #ifndef _WIN32 and the Linux job doesn't run on pull requests, so it has only run on the author's machine.

Not run here; this is from reading the code.

AI-assisted: yes.

milescoviello added a commit to milescoviello/AnyPS5 that referenced this pull request Nov 7, 2026
…ction, run a game's handler first

Review on boykopovar#16757 (gabichuuuuu):
- Finish prints nothing on an abort exit. The terminate path writes raw
  because another, possibly suspended, thread may hold the stderr
  stream lock, and the report's fprintf would block on it.
- A terminate that a function that is not implemented threw is
  reported as kind missing-function with that function's library,
  name and source (the last one noted on the thread), as the schema
  fixture shows. Other exceptions stay kind other with their text.
- With the runtime's own handler (DefaultTerminate, std::abort) the
  report is written before it runs. With a game's handler it is
  written after the handler returns, so a handler that exits writes
  its own clean report with the exit code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @gabichuuuuu, all of it holds. The fixes are three commits on top:

  • stderr lock (320bd1f656): Finish prints nothing when the exit is abort, so the terminate path never touches the CRT stream lock. The other abort paths stay raw.
  • A handler that exits (320bd1f656): the report is written before the handler only when the handler is the runtime's own (DefaultTerminate or std::abort). A game's handler runs first, and the report is written only if that handler returns, so exit(3) from it writes the clean report with exit code 3. The new child-terminate-handler-exits case in 8aebd14c50 pins that.
  • Stop kind (320bd1f656): the last missing function noted on the thread is kept. When the terminate's what() is its "<name> not implemented", the stop is missing-function with that function's source and the fixture's "Called , which is not implemented." message. Other exceptions stay other with their text. child-uncaught-missing-function now checks the kind and message.
  • User docs (954b00b1ae): run-report.md (the write rule and the Stop section) and USAGE.md describe the abort report. test_run_report_docs.py now pins "A run that is killed or crashes writes no report" (10 of 10 pass).
  • Template: GPUs tested is now n/a.

The Linux (test commit 8aebd14c50 against head 954b00b1ae) and Windows reruns are queued. I'll add their results here.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

Results for the review fixes, 3 runs each:

Machine Test commit 8aebd14c50 Head 954b00b1ae
Linux, RTX 4070 Ti, GCC 15.2: run_report, exception_runtime, exception_c_cleanup, exception_personality, guest_sce_v2_exceptions run_report fails 3 of 3, the other 4 pass 5 of 5 pass 3 of 3
Windows 11 VM, WinLibs GCC 15.2: run_report, exception_personality, guest_sce_v2_exceptions 3 of 3 pass 3 of 3 pass, built with the reworked InvokeTerminate

On the test commit, both new cases fail as intended:

  • child-uncaught-missing-function ... lacks "kind": "missing-function"
  • child-terminate-handler-exits ... lacks "exit": "clean"

tools/tests/test_run_report_docs.py passes (10 tests).

AI-assisted: yes (Claude Code)

@gabichuuuuu

Copy link
Copy Markdown
Contributor

Ran 954b00b1ae merged on main 302864d on Windows 11 x64 (WinLibs GCC 15.2), ctest -R '^run_report', three times: run_report and run_report_revision pass each time, with "run report tests: 39 passed, 0 failed, 8 not run", the same counts as main.

So Windows doesn't cover the fix. child-uncaught-missing-function and child-terminate-handler-exits sit in the #ifndef _WIN32 block of main() with the other child-process cases, so they aren't built here. The Runtime.cpp change does apply on Windows, though: std::terminate from an uncaught NotImplemented on a guest thread now writes the report there too. A Windows variant of the two cases would cover it. The only claim this run supports is that nothing else in run_report changed on Windows.

AI-assisted: yes.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Right, thanks @gabichuuuuu: my Windows rows only show that nothing else in run_report moved. Both new cases sit in the #ifndef _WIN32 block with the other child-process cases, because RunChild starts the child through the POSIX shell. Covering the terminate path on Windows needs a CreateProcess-based RunChild (environment, working directory and exit status), and that applies to every child case, not only these two. I'll open that as a follow-up PR on top of this one, so the Windows harness can be reviewed on its own.

AI-assisted: yes (Claude Code)

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 954b00b1ae, merged onto main 62e7ca8676 (aebc405955, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • run_report passes in 3 of 3 runs, none skipped.

AI-assisted: yes.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @JJenkx. One note on what that run covers: the child-process cases (child-exit through child-terminate-handler-exits, including the two this PR adds) are compiled only on POSIX, so on Windows run_report passes without them, as gabichuuuuu pointed out above. The Windows harness for them is the follow-up I mentioned. I'm holding it until #15973 lands, because that PR adds more child cases through the same RunChild.

AI-assisted: yes (Claude Code)

milescoviello and others added 4 commits November 12, 2026 18:28
A child run that leaves an unimplemented function's exception uncaught
must end through abort and still write anyps5-report.json, with exit
abort, reason runtime-stop, the exception's text as the stop message and
the function in the missing-function table. On main it writes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LibcException::InvokeTerminate now finishes the run report before the
terminate handler runs: exit abort, reason runtime-stop, and the caught
exception's what() as the stop message. Before, only exit, _exit and a
returning entry wrote the report, so a title that stopped on a function
that is not implemented (the throw ends in std::terminate) left none.
The report format already had the abort exit and the runtime-stop
reason; nothing produced them.

DefaultTerminate's what() lookup moves into CaughtWhat so both use it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nate handler that exits

The uncaught unimplemented function's report must carry kind
missing-function and the "Called ..., which is not implemented."
message the schema fixture uses. A child whose own terminate handler
calls exit(3) must exit with 3 and leave a clean report with exit
code 3, not an abort one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ction, run a game's handler first

Review on boykopovar#16757 (gabichuuuuu):
- Finish prints nothing on an abort exit. The terminate path writes raw
  because another, possibly suspended, thread may hold the stderr
  stream lock, and the report's fprintf would block on it.
- A terminate that a function that is not implemented threw is
  reported as kind missing-function with that function's library,
  name and source (the last one noted on the thread), as the schema
  fixture shows. Other exceptions stay kind other with their text.
- With the runtime's own handler (DefaultTerminate, std::abort) the
  report is written before it runs. With a game's handler it is
  written after the handler returns, so a handler that exits writes
  its own clean report with the exit code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello
milescoviello force-pushed the fix/run-report-terminate branch from 954b00b to e5a2cfb Compare November 12, 2026 23:30
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@milescoviello the debt file now has two Run report bullets at e5a2cfb. The merge of main kept main's old bullet (line 374, which says a run that crashes or aborts writes no report and does not mention std::terminate) next to your new bullet at line 377, so the two contradict each other. Please delete the old bullet and keep the new one. The rest of the head matches the version that was reviewed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello
milescoviello force-pushed the fix/run-report-terminate branch from e5a2cfb to 8e20e9b Compare November 12, 2026 23:37
@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @oneandonlydean — fixed in 8e20e9b33b. The rebase's merge kept main's older Run-report bullet next to my updated one; I deleted the old one, since my bullet already covers the crash / abort / killed → no report case and adds the std::terminate path. One Run-report bullet now, no contradiction.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit 33e7cbd into boykopovar:main Nov 13, 2026
22 checks passed
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@milescoviello one thing from this on Windows: lastMissing() in RunReport.cpp uses a thread_local MissingFunctionStop, and our prx_thread_local_destructors check fails on it (on Windows a thread_local destructor in a module runs after emulated TLS has freed the object). #19347 moves it to HostThreadLocal, like Radix64.cpp; no change needed on your side, just a heads-up for future module code.

oneandonlydean added a commit that referenced this pull request Nov 13, 2026
#16757 added 'thread_local MissingFunctionStop missing;' in RunReport.cpp
lastMissing(). On Windows a thread_local destructor in a module runs after
emulated TLS has freed the object, so prx_thread_local_destructors fails on
main. Use HostThreadLocal (fiber-local storage on Windows, thread_local
elsewhere), like Radix64.cpp.
@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @oneandonlydean, and for the fix in #19347. Understood — I'll use HostThreadLocal (as in Radix64.cpp's L64aBufferTag) for any module-side thread-local state going forward. The Linux build doesn't surface the emulated-TLS teardown ordering, so I'd have missed it; good to know the prx_thread_local_destructors check guards it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants