feat(libc): add the std::__sce_v2 exception types and throwers #8901

Merged
hypermoist merged 4 commits from upstream-pr/8901 into main 2026-10-24 11:21:55 +00:00
hypermoist commented 2026-10-21 05:09:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-21T05:09:05Z.


What

The versioned C++ library (std::__sce_v2) throws its own exception types, not the unversioned std:: ones libc has. In the decrypted libSceLibcInternal.sprx (PS5 13.60), the versioned throwers hand __cxa_throw typeinfo named NSt8__sce_v212length_errorE, NSt8__sce_v212system_errorE and so on. A catch clause compiled against these headers names the versioned types too, so throwing an unversioned object never reaches it. Upstream's existing versioned _Xbad_function_call has this bug: it throws the unversioned std::bad_function_call.

The hierarchy, read from the module's typeinfo records:

std::exception (shared)
├─ std::__sce_cxxvers::_Error_exception        (exported, NID fs-9cvP-VCo)
│   ├─ __sce_v2::logic_error → length_error, out_of_range, invalid_argument
│   └─ __sce_v2::runtime_error → overflow_error, range_error,
│                                _System_error → system_error → ios_base::failure
└─ __sce_v2::bad_function_call, bad_optional_access, bad_weak_ptr, bad_variant_access

_Xbad_alloc is the exception: it throws the shared std::bad_alloc.

This PR adds:

Export (NID) Behaviour
_Error_exception C1/C2 (const char*) (EvS9U4rxAQk …), copy C1/C2, D0/D1/D2, what (3PxvyV7qPPQ), typeinfo (fs-9cvP-VCo) The message base class: a 16-byte {vtable, refcounted message} object, built on upstream's existing refcounted Message helpers. A null message gives "".
_Xlength_error (d08RCvZNNR8), _Xout_of_range (bRPUrNROyOI), _Xinvalid_argument (fPHZ-n-uRWQ), _Xruntime_error (Rlnw-UcmA5k), _Xoverflow_error (xRrps2kelWU) throw the versioned type with the message
_Xbad_alloc (klLbZjteYdw) throws the shared std::bad_alloc
_Xbad_function_call (g0mZgRTFPoQ, existing) now throws __sce_v2::bad_function_call
_Throw(const bad_optional_access&) (13wBGJrxnSc), bad_weak_ptr (Dk+iDUjUdk8), bad_variant_access (P30mDR3cUlA) throw a fresh 8-byte object. what() returns Bad optional access, bad_weak_ptr and bad variant access (and bad function call for the above), as the console's vtables do.
_Throw(const range_error&) (okSBuQ1sJdQ), _Throw(const system_error&) (aFYb4pr4bjI), ios_base::_Throw(const failure&) (HFLNP4R4Elc) throw a copy of the caller's object (16 or 32 bytes; the copy shares the message and copies the error code)
_Throw_Cpp_error (ShHKOkWgZRM) throws a __sce_v2::system_error. Upstream's unversioned body becomes a helper that takes the exception table, so both share one code/message mapping.
_Syserror_map (4ITMYcbipA0) the unversioned map, except that code 0 gives success and unknown codes give unknown error instead of null (the console's versioned table has one more entry, for 0, and a non-null default)
_Xtime_get_ticks (XXOOIxrIKDM) the unversioned call: microseconds since the epoch, as on the console

The versioned typeinfo and vtables for the derived types are internal, as on the console: only _Error_exception's typeinfo is exported. The bodies are written from this observed behaviour; nothing from the module is copied.

Titles import these (local dumps):

  • PPSA03671: its eboot, libRenoirCore.PS5.prx and libcohtml.Prospero.prx import _Error_exception C2/D2/what, _Xlength_error, _Xout_of_range, _Xruntime_error, ios_base::_Throw, _Throw_Cpp_error, _Syserror_map and _Xtime_get_ticks. libcohtml also imports _Throw(system_error), _Throw(bad_weak_ptr), _Throw(bad_variant_access) and _Xbad_function_call.
  • PPSA29340 (Halloween): kitt-ps5-shipping.prx, kitt_support-ps5-shipping.prx, kitt_webkit-ps5-shipping.prx and resonanceaudio.prx import most of the same set, plus _Xbad_alloc and _Throw(bad_optional_access). Its libSceJobManager.prx imports _Xbad_function_call.

_Xinvalid_argument, _Xoverflow_error and _Throw(range_error) are not imported by these dumps. They are included because they are the same family and shape.

Not verified / not included:

  • The message text of the versioned _Throw_Cpp_error reuses the unversioned one, which the existing libc.md entry already marks as unverified on the console.
  • _Error_exception::_Data::_Empty::_Instance is not exported. No title imports it, and here an empty message is allocated instead of shared.
  • Versioned _Throw(future_error / format_error / bad_any_cast), _Xregex_error and filesystem::_Xfilesystem_error: their objects carry extra fields that are not pinned down yet.

Tested

Linux (CachyOS, GCC, Release): full build. All 541 guest_*, kernel and Ampr tests pass.

New guest_sce_v2_exceptions uses an assembly fixture with a real landing pad and runtime-set catch types (the pattern of guest_ampr_cpp_error). The catch types are test-local typeinfo records that carry only the versioned names, as a title's own copies would. For each thrower it checks the caught type name, what() and the selector:

  • versioned length_error is caught as __sce_v2::logic_error, and not as the unversioned std::length_error;
  • versioned _Throw_Cpp_error is not caught as std::system_error;
  • the _Throw(const T&) copies keep the message and the error code;
  • _Error_exception construction, copying and destruction;
  • _Syserror_map against the unversioned map;
  • _Xtime_get_ticks against the unversioned clock.

exception_runtime used to expect the versioned _Xbad_function_call to be caught as std::bad_function_call. It now expects NSt8__sce_v217bad_function_callE with what() "bad function call", caught as std::exception and not as std::bad_function_call, and it checks that the unversioned _Xbad_function_call still throws std::bad_function_call.

The existing guest_ampr_cpp_error covers the refactored unversioned _Throw_Cpp_error. Renaming the versioned length_error to St12length_error makes the new test fail.

tools/check_conventions.py is clean. No open PR adds these names or NIDs (#7201 only calls the existing _Xbad_function_call in a test), and a three-way merge against every open PR touching these files adds no conflicts.

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 (#8885 no longer adds the versioned _Throw_Cpp_error; it lives here)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (libc only)
  • AI-assisted: yes (Claude Code), reviewed by the contributor

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946714296 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8901). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-21T05:09:05Z. --- ### What The versioned C++ library (`std::__sce_v2`) throws its own exception types, not the unversioned `std::` ones libc has. In the decrypted `libSceLibcInternal.sprx` (PS5 13.60), the versioned throwers hand `__cxa_throw` typeinfo named `NSt8__sce_v212length_errorE`, `NSt8__sce_v212system_errorE` and so on. A catch clause compiled against these headers names the versioned types too, so throwing an unversioned object never reaches it. Upstream's existing versioned `_Xbad_function_call` has this bug: it throws the unversioned `std::bad_function_call`. The hierarchy, read from the module's typeinfo records: ``` std::exception (shared) ├─ std::__sce_cxxvers::_Error_exception (exported, NID fs-9cvP-VCo) │ ├─ __sce_v2::logic_error → length_error, out_of_range, invalid_argument │ └─ __sce_v2::runtime_error → overflow_error, range_error, │ _System_error → system_error → ios_base::failure └─ __sce_v2::bad_function_call, bad_optional_access, bad_weak_ptr, bad_variant_access ``` `_Xbad_alloc` is the exception: it throws the shared `std::bad_alloc`. This PR adds: | Export (NID) | Behaviour | |---|---| | `_Error_exception` C1/C2 `(const char*)` (`EvS9U4rxAQk` …), copy C1/C2, D0/D1/D2, `what` (`3PxvyV7qPPQ`), typeinfo (`fs-9cvP-VCo`) | The message base class: a 16-byte `{vtable, refcounted message}` object, built on upstream's existing refcounted `Message` helpers. A null message gives `""`. | | `_Xlength_error` (`d08RCvZNNR8`), `_Xout_of_range` (`bRPUrNROyOI`), `_Xinvalid_argument` (`fPHZ-n-uRWQ`), `_Xruntime_error` (`Rlnw-UcmA5k`), `_Xoverflow_error` (`xRrps2kelWU`) | throw the versioned type with the message | | `_Xbad_alloc` (`klLbZjteYdw`) | throws the shared `std::bad_alloc` | | `_Xbad_function_call` (`g0mZgRTFPoQ`, existing) | now throws `__sce_v2::bad_function_call` | | `_Throw(const bad_optional_access&)` (`13wBGJrxnSc`), `bad_weak_ptr` (`Dk+iDUjUdk8`), `bad_variant_access` (`P30mDR3cUlA`) | throw a fresh 8-byte object. `what()` returns `Bad optional access`, `bad_weak_ptr` and `bad variant access` (and `bad function call` for the above), as the console's vtables do. | | `_Throw(const range_error&)` (`okSBuQ1sJdQ`), `_Throw(const system_error&)` (`aFYb4pr4bjI`), `ios_base::_Throw(const failure&)` (`HFLNP4R4Elc`) | throw a copy of the caller's object (16 or 32 bytes; the copy shares the message and copies the error code) | | `_Throw_Cpp_error` (`ShHKOkWgZRM`) | throws a `__sce_v2::system_error`. Upstream's unversioned body becomes a helper that takes the exception table, so both share one code/message mapping. | | `_Syserror_map` (`4ITMYcbipA0`) | the unversioned map, except that code 0 gives `success` and unknown codes give `unknown error` instead of null (the console's versioned table has one more entry, for 0, and a non-null default) | | `_Xtime_get_ticks` (`XXOOIxrIKDM`) | the unversioned call: microseconds since the epoch, as on the console | The versioned typeinfo and vtables for the derived types are internal, as on the console: only `_Error_exception`'s typeinfo is exported. The bodies are written from this observed behaviour; nothing from the module is copied. Titles import these (local dumps): - **PPSA03671**: its `eboot`, `libRenoirCore.PS5.prx` and `libcohtml.Prospero.prx` import `_Error_exception` C2/D2/`what`, `_Xlength_error`, `_Xout_of_range`, `_Xruntime_error`, `ios_base::_Throw`, `_Throw_Cpp_error`, `_Syserror_map` and `_Xtime_get_ticks`. `libcohtml` also imports `_Throw(system_error)`, `_Throw(bad_weak_ptr)`, `_Throw(bad_variant_access)` and `_Xbad_function_call`. - **PPSA29340 (Halloween)**: `kitt-ps5-shipping.prx`, `kitt_support-ps5-shipping.prx`, `kitt_webkit-ps5-shipping.prx` and `resonanceaudio.prx` import most of the same set, plus `_Xbad_alloc` and `_Throw(bad_optional_access)`. Its `libSceJobManager.prx` imports `_Xbad_function_call`. `_Xinvalid_argument`, `_Xoverflow_error` and `_Throw(range_error)` are not imported by these dumps. They are included because they are the same family and shape. Not verified / not included: - The message text of the versioned `_Throw_Cpp_error` reuses the unversioned one, which the existing `libc.md` entry already marks as unverified on the console. - `_Error_exception::_Data::_Empty::_Instance` is not exported. No title imports it, and here an empty message is allocated instead of shared. - Versioned `_Throw(future_error / format_error / bad_any_cast)`, `_Xregex_error` and `filesystem::_Xfilesystem_error`: their objects carry extra fields that are not pinned down yet. ### Tested Linux (CachyOS, GCC, Release): full build. All 541 `guest_*`, kernel and Ampr tests pass. New `guest_sce_v2_exceptions` uses an assembly fixture with a real landing pad and runtime-set catch types (the pattern of `guest_ampr_cpp_error`). The catch types are test-local typeinfo records that carry only the versioned names, as a title's own copies would. For each thrower it checks the caught type name, `what()` and the selector: - versioned `length_error` is caught as `__sce_v2::logic_error`, and not as the unversioned `std::length_error`; - versioned `_Throw_Cpp_error` is not caught as `std::system_error`; - the `_Throw(const T&)` copies keep the message and the error code; - `_Error_exception` construction, copying and destruction; - `_Syserror_map` against the unversioned map; - `_Xtime_get_ticks` against the unversioned clock. `exception_runtime` used to expect the versioned `_Xbad_function_call` to be caught as `std::bad_function_call`. It now expects `NSt8__sce_v217bad_function_callE` with `what()` "bad function call", caught as `std::exception` and not as `std::bad_function_call`, and it checks that the unversioned `_Xbad_function_call` still throws `std::bad_function_call`. The existing `guest_ampr_cpp_error` covers the refactored unversioned `_Throw_Cpp_error`. Renaming the versioned length_error to `St12length_error` makes the new test fail. `tools/check_conventions.py` is clean. No open PR adds these names or NIDs (#7201 only calls the existing `_Xbad_function_call` in a test), and a three-way merge against every open PR touching these files adds no conflicts. ### 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 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: none (#8885 no longer adds the versioned `_Throw_Cpp_error`; it lives here) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (libc only) - [x] AI-assisted: yes (Claude Code), reviewed by the contributor 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
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!8901
No description provided.