feat(libc): throw std::bad_cast and the std::__sce_v2 bad_any_cast, format_error and future_error #15552
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15552"
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 Danigamer05 on 2026-11-03T18:43:07Z.
What
Add four exception throwers to libc:
_ZSt6_ThrowRKSt8bad_castsJ41UnZr6dQ0xCC310_ZNSt8__sce_v26_ThrowERKNS_12bad_any_castEm+y2TtGJp540xCC710_ZNSt8__sce_v26_ThrowERKNS_12format_errorEHfF9zbvHXXE0xCC6A0_ZNSt8__sce_v26_ThrowERKNS_12future_errorEZdF3BhEh5sk0xCC620The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6). Each follows the module's thrower and the type information it throws, read from that module with its relocations applied:_Throw(const bad_cast&)ignores its argument and throws a new 8-bytestd::bad_cast, using the_ZTVSt8bad_castalready in main. The module'swhat()returnsstd::bad_cast, as main's does.bad_any_castalso ignores its argument and throws a new 8-byte object. Its typeNSt8__sce_v212bad_any_castEderives fromstd::bad_cast, andwhat()returnsBad any_cast.format_error(NSt8__sce_v212format_errorE, derived from the versionedruntime_error) copies the message object, through the existingSceV2::ThrowCopy.future_error(NSt8__sce_v212future_errorE, derived from the versionedlogic_error) copies the message and the 16-byte error code into a 32-byte object, through the existingSceV2::ThrowSystemCopy. Itswhat()is the module's own: it reads the first 32-bit word of the code and returnsbroken promise,future already retrieved,promise already satisfiedorno statefor 1 to 4, and a null pointer otherwise. It reuses main'sFutureErrorMessage, which holds the same four texts.The two other free throwers of that module,
_Throw_bad_any_cast(const char*)and_Throw_bad_node_access(const char*), build an object holding astd::stringand are not part of this change.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main1e658521a0a. Exact tested commit:e92455a5f4b.guest_sce_v2_exceptionspasses with the new cases, along withguest_filesystem_error,exception_personality,windows_exceptions,guest_libc_internal_exception_destructors,public_headersand the otherguest_sce_v2_*CTests.guest_sce_v2_exceptionsnow throws each new export through its assembly catch frame and checks the landing selector, the caught type name andwhat():bad_any_castis caught asstd::bad_cast, not as_Error_exception;bad_castis caught asstd::exception;format_erroris caught as the versionedruntime_errorand keeps the copied message;future_erroris caught as the versionedlogic_error, answerspromise already satisfiedfor code word 3, and keeps both code words and the category.what()strings, object sizes and copy layouts were read from the module's typeinfo, vtables,.rodataand throwers. The throwers were not run side by side: they end in__cxa_throw, which a host harness cannot catch for the module's frames.bad_any_casttext, theformat_errorbase class, the word thatfuture_error::what()reads, and the vtable that_Throw(bad_cast)throws.guest_sce_v2_exceptionsfailed on each. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test passed again.git diff --checkpass.tools/pr_overlap.pyread 1,757 open PRs and reports no overlap. It keeps exit 2 for 29 branches that already conflict with main. Merging each of the 29 with this branch and with main usinggit merge-treegives the same conflict blocks. Two of them name a related symbol: #13449 adds the unversionedfuture_errortype-name string as data, and #13486 lists unversionedfuture_errordestructors in a table. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501 and #15519.Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T20:23:27Z.
Review: APPROVED
Reviewed — approved
The four new throwers (
std::_Throw(const bad_cast&)and thestd::__sce_v2_Throwforbad_any_cast,format_errorandfuture_error) merge cleanly, build, and pass the extendedguest_sce_v2_exceptions. The negative control and a targeted mutation both make that test fail. I have two non-blocking notes.What I ran
Head
e92455a5f4bc902b32775437bdf5231e782f9313,main086c0686c8adff3ee648fdbe34e0b0b647e1d511, merged treef3b27126c6910ae6eaa4b22b96aad52e054af9c3. Debian 13 VM, GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.Results
git diff --checkcheck_conventions.pylibs(script)maincheck_skips.py(script)guest_net_ctlskipped, which also happens onmain; not caused by this PRguest_sce_v2_exceptionspublic_headersNegative control
Api.hppandStandardExceptions.cppfrommain. The test no longer compiles because the four throwers are not declared, so the test does depend on the new exports.FutureErrorWhat_nid_no_patchto readcode.value, the second word, which is what the unversionedfuture_errorreads. The build succeeded and the test failed:output
After that I restored the merged files and rebuilt; the test passed again, and
git status --porcelainwas empty.Findings
Blocking
None.
Non-blocking
core/libs/prx/libc/src/exception/StandardExceptions.cpp:586,*reinterpret_cast<const int*>(&...->code)readsErrorCode::reserved, the first member of a standard-layout struct (Api.hpp:99). The extra cast hides that. Writingreinterpret_cast<const SystemErrorObject*>(self)->code.reservedsays the same thing directly, and the test already checks that field by name (inspectedSystem.code.reserved == 3).__sce_v2::_Throw_Cpp_error(pre-existing, outside this PR). The description reports that the module's versionedfuture_error::what()takes the error value from the first 32-bit word of the code. That matches libc++, whereerror_codeis{int value; const error_category* category;}. Onmain, though,ThrowCppErrorfills the versionedsystem_errorwith{0, value, &GenericCategory}, putting the value in the second word (StandardExceptions.cpp:317). If the versionederror_codereally keeps its value at offset 0, guest code callingcode().value()on a__sce_v2::system_errorfrom_Throw_Cpp_errorwould read 0. I did not check this against the module. A separate check and a debt note would help. It does not block this PR, which copies the code unchanged.Not verified
libc.prx. The type names, base classes,what()texts, object sizes and the first-word read are taken from the description and the debt entry.guest_sce_v2_exceptionsandpublic_headers, beyond the script's selected run.