feat(libc): add the std::__sce_v2 exception types and throwers #8901
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8901"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 unversionedstd::ones libc has. In the decryptedlibSceLibcInternal.sprx(PS5 13.60), the versioned throwers hand__cxa_throwtypeinfo namedNSt8__sce_v212length_errorE,NSt8__sce_v212system_errorEand 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_callhas this bug: it throws the unversionedstd::bad_function_call.The hierarchy, read from the module's typeinfo records:
_Xbad_allocis the exception: it throws the sharedstd::bad_alloc.This PR adds:
_Error_exceptionC1/C2(const char*)(EvS9U4rxAQk…), copy C1/C2, D0/D1/D2,what(3PxvyV7qPPQ), typeinfo (fs-9cvP-VCo){vtable, refcounted message}object, built on upstream's existing refcountedMessagehelpers. A null message gives""._Xlength_error(d08RCvZNNR8),_Xout_of_range(bRPUrNROyOI),_Xinvalid_argument(fPHZ-n-uRWQ),_Xruntime_error(Rlnw-UcmA5k),_Xoverflow_error(xRrps2kelWU)_Xbad_alloc(klLbZjteYdw)std::bad_alloc_Xbad_function_call(g0mZgRTFPoQ, existing)__sce_v2::bad_function_call_Throw(const bad_optional_access&)(13wBGJrxnSc),bad_weak_ptr(Dk+iDUjUdk8),bad_variant_access(P30mDR3cUlA)what()returnsBad optional access,bad_weak_ptrandbad variant access(andbad function callfor 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_Cpp_error(ShHKOkWgZRM)__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)successand unknown codes giveunknown errorinstead of null (the console's versioned table has one more entry, for 0, and a non-null default)_Xtime_get_ticks(XXOOIxrIKDM)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):
eboot,libRenoirCore.PS5.prxandlibcohtml.Prospero.prximport_Error_exceptionC2/D2/what,_Xlength_error,_Xout_of_range,_Xruntime_error,ios_base::_Throw,_Throw_Cpp_error,_Syserror_mapand_Xtime_get_ticks.libcohtmlalso imports_Throw(system_error),_Throw(bad_weak_ptr),_Throw(bad_variant_access)and_Xbad_function_call.kitt-ps5-shipping.prx,kitt_support-ps5-shipping.prx,kitt_webkit-ps5-shipping.prxandresonanceaudio.prximport most of the same set, plus_Xbad_allocand_Throw(bad_optional_access). ItslibSceJobManager.prximports_Xbad_function_call._Xinvalid_argument,_Xoverflow_errorand_Throw(range_error)are not imported by these dumps. They are included because they are the same family and shape.Not verified / not included:
_Throw_Cpp_errorreuses the unversioned one, which the existinglibc.mdentry already marks as unverified on the console._Error_exception::_Data::_Empty::_Instanceis not exported. No title imports it, and here an empty message is allocated instead of shared._Throw(future_error / format_error / bad_any_cast),_Xregex_errorandfilesystem::_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_exceptionsuses an assembly fixture with a real landing pad and runtime-set catch types (the pattern ofguest_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:length_erroris caught as__sce_v2::logic_error, and not as the unversionedstd::length_error;_Throw_Cpp_erroris not caught asstd::system_error;_Throw(const T&)copies keep the message and the error code;_Error_exceptionconstruction, copying and destruction;_Syserror_mapagainst the unversioned map;_Xtime_get_ticksagainst the unversioned clock.exception_runtimeused to expect the versioned_Xbad_function_callto be caught asstd::bad_function_call. It now expectsNSt8__sce_v217bad_function_callEwithwhat()"bad function call", caught asstd::exceptionand not asstd::bad_function_call, and it checks that the unversioned_Xbad_function_callstill throwsstd::bad_function_call.The existing
guest_ampr_cpp_errorcovers the refactored unversioned_Throw_Cpp_error. Renaming the versioned length_error toSt12length_errormakes the new test fail.tools/check_conventions.pyis clean. No open PR adds these names or NIDs (#7201 only calls the existing_Xbad_function_callin a test), and a three-way merge against every open PR touching these files adds no conflicts.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)_Throw_Cpp_error; it lives here)🤖 Generated with Claude Code
https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK