Skip to content

feat(libSceLibcInternal): implement std::exception::_Set_raise_handler - #19767

Merged
oneandonlydean merged 5 commits into
boykopovar:mainfrom
nexus7super-ship-it:feat/libc-internal-raise-handler
Nov 26, 2026
Merged

oneandonlydean merged 5 commits into
boykopovar:mainfrom
nexus7super-ship-it:feat/libc-internal-raise-handler

Conversation

@nexus7super-ship-it

Copy link
Copy Markdown
Contributor

What

Implements std::exception::_Set_raise_handler(void (*)(const std::exception&)) (libSceLibcInternal, NID Bin7e2UR+a0), which threw through NotImplemented_nid_no_patch.

It follows Dinkumware's VC12 exception header: _Set_raise_handler stores the new handler and returns the previous one, and exception::_Raise calls the handler with the exception before it throws. The handler is kept in libc next to _Raise (an atomic exchanged through LibcExchangeRaiseHandler_nid_no_patch), and libc's _Raise now calls it. No export of the console's std::_Raise_handler variable is known, so a title that writes that variable directly is not seen; this is recorded in docs/dev/debt/libSceLibcInternal.md.

Tested

Linux (Ubuntu, GCC), Release build with BUILD_TESTING=ON: guest_libc_internal_exception_virtuals gains a check that the handler is installed, called once with the raised object, swapped and cleared; all 44 guest_libc_internal_* tests and exception_runtime pass, as do public_headers, conventions_* and progress_report (129 tests). python3 tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py reports only shared files, no shared exports. No title was run.

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

🤖 Generated with Claude Code

Swap the handler that exception::_Raise calls before it throws and
return the previous one, as Dinkumware's exception header does.

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

Copy link
Copy Markdown
Contributor

Linux test report for e8e14a8, merged onto main 19b5d78. Ubuntu 24.04 under WSL2, GCC 13.3.0, glibc 2.39, Ninja, Release, BUILD_TESTING=ON.

  • ninja -C build guest_libc_internal_exception_virtuals_tests, then ctest -R '^guest_libc_internal_exception_virtuals$' --output-on-failure: passed (1/1).
  • Source: _Set_raise_handler returns the previous handler, and exception::_Raise calls the handler before raising. Both match the cited VC12 header at f1d47126bf L229-L272.

An observation outside this PR's lines, since the PR cites that header: the same _Raise (L265-L271) does three things in order. It calls the handler, then calls the virtual _Doraise(), and only then _RAISE(*this). main's _ZNKSt9exception6_RaiseEv_nid_postfix (StandardExceptions.cpp:434) goes straight to ThrowPlain(_ZTVSt9exception_nid_postfix) and never dispatches through the object's vtable to _Doraise. A _Raise on a bad_cast or logic_error therefore throws a plain std::exception instead of the derived type that its _Doraise (:449, :520) would throw. This PR doesn't change that. It might be worth a debt note or a follow-up, since the handler call now sits right before that point.

@github-actions

github-actions Bot commented Nov 13, 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 19602 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp L301-311

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 12682 core/libs/prx/libc/include/Api.hpp
PR 12688 core/libs/prx/libc/include/Api.hpp
PR 12700 core/libs/prx/libc/include/Api.hpp
PR 12965 core/libs/prx/libc/include/Api.hpp
PR 13778 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
docs/dev/debt/libSceLibcInternal.md
PR 17746 docs/dev/debt/libSceLibcInternal.md
PR 18135 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp
core/libs/prx/libc/include/Api.hpp
docs/dev/debt/libSceLibcInternal.md
PR 18190 core/libs/prx/libc/include/Api.hpp
PR 24748 docs/dev/debt/libSceLibcInternal.md
PR 25573 core/libs/prx/libSceLibcInternal/InventoryExports6.cpp
core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp

@ycbuzi

ycbuzi commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Tested e8e14a823e merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 2 tests failed out of 5394; 99% tests passed, 3 tests failed out of 5394. 2 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 1 tests failed out of 5394; 100% tests passed, 0 tests failed out of 5394. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@JJenkx

JJenkx commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Windows check of head e8e14a823e, merged onto main 5f749eee1e (cb1f78a7dc, 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.

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

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Progress report (fbd2175 → 484431d)

📈 System libraries: 46.91% (+0.0025%, +1 implemented function)

✅ 1 implemented
Library Name
libSceLibcInternal _ZNSt9exception18_Set_raise_handlerEPFvRKS_E_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libSceLibcInternal 706/1126 (62.70%) 707/1126 (62.79%) +0.09%

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 14, 2026
Drop both conflicting InventoryExports6.hpp declarations: main implements
messages<wchar_t>::messages in Messages.cpp and this branch implements
exception::_Set_raise_handler in ExceptionVirtuals.cpp.
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@nexus7super-ship-it I merged main into the branch (4e773a5) to clear the conflict in include/InventoryExports6.hpp. Both sides had removed a different inventory declaration on the same line, so I dropped both: main now implements messages<wchar_t>::messages in Messages.cpp and your branch implements _Set_raise_handler in ExceptionVirtuals.cpp. guest_libc_internal_exception_virtuals passes on the merge and debt_fold.py --check is clean. Please pull before your next push.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 17, 2026

@MarcZX10 MarcZX10 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.

Reviewed — no blocking findings

Nothing blocks this; the points below are optional. The diff is consistent with the stated goal, and the tests the author reports were not run here.

Head reviewed: 4e773a54787a997f9045729d0ec33b7ee918c6a5, base main.

What I ran

  • Read the description, commit list, manifest and diff (8 changed files, all in files.json under reviewed).
  • Read the house rules for readable reviews, accuracy and the response format.
  • Targeted reads through repo_read.py:
    • search _Set_raise_handler
    • search LibcExchangeRaiseHandler
    • search Bin7e2UR
    • search "define APS5_EXPORT"
    • cat core/libs/prx/libc/src/exception/StandardExceptions.cpp 402 420
    • cat core/libs/prx/libSceLibcInternal/include/ExceptionVirtuals.hpp 1 8
  • No build and no test run in this review.

Results

Check Result Note
Diff read, all 8 files passed Changed hunks only
Symbol and caller search passed One definition per symbol, no leftover stub
Build and unit tests not run Author-reported only
Export NID binding not verified See Not verified

Findings

Blocking

None.

Non-blocking

None that the code I read shows as a defect.

Sources

  • Handler storage and exchange: core/libs/prx/libc/src/exception/StandardExceptions.cpp:411-417 (commit 4e773a5).
  • Raise call before throw: core/libs/prx/libc/src/exception/StandardExceptions.cpp:443-444.
  • New export and removed stub: core/libs/prx/libSceLibcInternal/ExceptionVirtuals.cpp:81-84 and core/libs/prx/libSceLibcInternal/InventoryExports6.cpp:337 (removed).

Not verified

  • The author's test run (guest_libc_internal_*, exception_runtime, public_headers, conventions_*, progress_report, 129 tests on Linux, GCC, Release). I did not build or run it.
  • The export NID Bin7e2UR+a0. It appears only in docs/dev/debt/libSceLibcInternal.md. The new function has no APS5_EXPORT line, the same as the stub it replaces, so the binding comes from the mangled name. I did not check the generator that maps names to NIDs.
  • Behaviour on a console. Nothing here was run on hardware, and the console's std::_Raise_handler variable is not covered (the debt doc says so).
  • Whole-file review. I read the changed hunks of all 8 files and the surrounding lines of two of them. I did not read the full text of each file.

To get this to a good state

Nothing is required.

Optional: confirm that the author's test run is reproduced on this head, and that the NID mapping for Bin7e2UR+a0 is generated from the new mangled name.

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 4e773a5478, applied with git apply (with -C1, context shifted) on main fd4aeed483 together with the other 26 PRs of one batch (#16367, #16415, #22363, #23103, #23366, #24064, #21547, #21742, #22774, #22852, #23420, #23952, #24346, #16945, #21718, #21780, #21912, #21931, #22061, #22425, #22619, #22657, #18765, #19662, #20899, #21571). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_libc_internal_exception_virtuals (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6523 tests) on the RTX 3080 has 4 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. The 2126 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

# Conflicts:
#	core/libs/prx/libc/include/Api.hpp

@MarcZX10 MarcZX10 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.

Reviewed — looks good

Nothing blocks this change; the reviewed implementation and its focused test support merging.

What I ran

Reviewed head 484431d7cf068a7084ec97f18971f61f1fc21b67 using the prepared review bundle and pinned repository reader. No tests or builds were run.

Results

Check Result Note
Change and targeted source review passed All changed files were included and read.
Tests and build not run Author-reported results were not independently run.

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests/builds, console behavior, or title compatibility were verified. The author reports Linux test results in description.md; these were not run here. All seven changed files listed in manifest.json were read: core/libs/prx/libSceLibcInternal/ExceptionVirtuals.cpp, core/libs/prx/libSceLibcInternal/InventoryExports6.cpp, core/libs/prx/libSceLibcInternal/include/ExceptionVirtuals.hpp, core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/exception/StandardExceptions.cpp, core/libs/tests/GuestLibcInternalExceptionVirtuals.cpp, and docs/dev/debt/libSceLibcInternal.md. None were excluded.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 25, 2026
@oneandonlydean
oneandonlydean merged commit ae1ecaf into boykopovar:main Nov 26, 2026
22 checks passed
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.

7 participants