feat(libSceLibcInternal): implement exception what and _Doraise members #16024
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16024"
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 B-Howell on 2026-11-05T11:12:15Z.
What
Implements seven
libSceLibcInternalvirtual members of the standard exception classes. Each one now runs the member thatlibcalready puts in the guest vtable of the same class, so a direct call and a virtual call give the same result. Before this change all seven threw throughNotImplemented_nid_no_patch._ZNKSt9bad_alloc8_DoraiseEvpS-t9AJblSMstd::bad_allocthroughlibc_ZSt11_Xbad_allocv(ThrowPlain(_ZTVSt9bad_alloc))_ZNKSt10bad_typeid8_DoraiseEvWMw8eIs0kjMstd::bad_typeidthroughlibc__cxa_bad_typeid(ThrowPlain(_ZTVSt10bad_typeid))_ZNKSt12system_error8_DoraiseEvuWZBRxLAvEg*thisinto a new exception withlibc_ZNSt12system_errorC1ERKS_and throws it as_ZTISt12system_error; the thrown copy is destroyed with_ZNSt12system_errorD1Ev_ZNKSt12future_error4whatEv5sfbtNAdt-M_ZTVSt12future_errorslotwhat(FutureErrorWhat)_ZNKSt12future_error8_DoraiseEv-syPONaWjqw_ZTVSt12future_errorslot_Doraise(RaiseFutureError: copies the message and code, then throws)_ZNKSt18bad_variant_access4whatEv+5IOQncui3c_ZTVSt18bad_variant_accessslotwhat(GuestPlainWhat)_ZNKSt22_Future_error_category7messageEinWfZplDjbxQ_ZTVSt22_Future_error_categoryslotmessage(FutureCategoryMessage)References:
_Doraisethrows a copy of*this(virtual void _Doraise() const { _RAISE(*this); }, where_RAISE(x)isthrow x). Thebad_allocandbad_typeidversions follow the existinglibc_ZNKSt8bad_cast8_DoraiseEv, which runsif (!self) throw std::invalid_argument("exception object is null"); LibcException::ThrowPlain(_ZTVSt8bad_cast_nid_postfix);.thisis handled the waylibc/src/exception/StandardExceptions.cpphandles it in each family. Everylibc_Doraiseand_Raisethere (exception,bad_cast,logic_error) starts withif (!self) throw std::invalid_argument("exception object is null");, so all four_Doraisemembers here (bad_alloc,bad_typeid,system_errorandfuture_error) start with the same line. Thelibcwhatmembers (_ZNKSt9exception4whatEv,_ZNKSt12system_error4whatEvand the others) have no null check and read the object, so the twowhatmembers here call the vtable slot without one._Future_error_category::messagedoes not read the category object, as inlibc.what,_Doraiseandmessagebodies are the functionslibc/src/exception/StandardExceptions.cppalready places in_ZTVSt12future_error_nid_postfix {0, &_ZTISt12future_error_nid_postfix, DestroyFutureError_nid_no_patch, DeleteFutureError_nid_no_patch, FutureErrorWhat_nid_no_patch, RaiseFutureError_nid_no_patch}, in_ZTVSt18bad_variant_access_nid_postfix(GuestPlainWhat_nid_no_patch) and in_ZTVSt22_Future_error_category_nid_postfix(FutureCategoryMessage_nid_no_patch).libcones:ExceptionObject,SystemErrorObject(sizeof == 32,codeat 16), andFutureErrorObject(sizeof == 0x40,messageat 0x8,codeat 0x30).The code is in a new
ExceptionVirtuals.cpp, declared ininclude/ExceptionVirtuals.hpp, whichlibSceLibcInternal.hppincludes.StandardExceptions.cppis not touched, so this does not conflict with #15552, which edits it. The seven stubs are removed fromExport.cppandInventoryExports2.cpp, and their debt entries are removed or cut indocs/dev/debt/libSceLibcInternal.md.tools/progress.pycollect_libraries():origin/mainb11c7bf84fhas 9921 done of 37146 andlibSceLibcInternal92 done, 1045 todo. This branch has 9928 done of 37146 andlibSceLibcInternal99 done, 1038 todo: +7 done, -7 todo, no new todo.libcis unchanged at 1628 done, 19 todo.Tested
Only the focused test targets and their libraries were built, on head
0e0f234240rebased ontoorigin/mainb11c7bf84f. No title was run.New guest test
guest_libc_internal_exception_virtuals(core/libs/tests/GuestLibcInternalExceptionVirtuals.cpp) checks:bad_allocandbad_typeid_Doraisethrow a new object carrying thelibcvtable, type name andwhat(). They are caught asstd::bad_allocandstd::bad_typeid, and a nullthisthrowsstd::invalid_argument.bad_variant_access::whatreturns the same pointer as the vtablewhat.future_error::whatreturns the four future messages for codes 1-4, matching the vtable, andnullptrfor codes 0, 5, 22 and -1.future_error::_Doraisethrows a distinctstd::future_errorcopy. A heap message gets new storage and keeps its size and capacity, an inline message is copied inline, the code is copied, and the source is left intact. A nullthisthrowsstd::invalid_argument._Future_error_category::messagegives the four future messages and the generic_Syserror_maptext, orunknown error, for 0, 5, 22 and 99.system_error::_Doraiserethrows a_Throw_Cpp_errorobject and a hand-built one as a distinctstd::system_errorthat shares the reference-counted message and copies the code. It can be caught asstd::runtime_error. A nullthisthrowsstd::invalid_argument.Results (
ctest -R '^(guest_libc_internal_exception_virtuals|guest_libc_internal_exception_destructors|guest_future_category)$'; the last two are the existing tests of the neighbouring destructors and of thelibcfuture category):future_error::_Doraisenull check removed, the test fails 1 of 1 (SEGFAULT,0xc0000005in the nullthiscase). With the check restored it passes again.MSYS_NO_PATHCONV=1 python3 tools/check_conventions.py --base origin/main --title "<title>" --body <this body>: "All conventions checks passed."core/libs/tests/test_public_headers.py --audit-only(Windows): "406 libraries, 28350 exports: unique declarations and umbrella coverage verified".python3 tools/pr_overlap.py --branch feat/r2-exception-virtualsexited 2 and printed "pr_overlap: overlap check failed closed; manually compare every reported PR branch before opening this one". It found no PR with the same exports or the same new files. It reported conflicting lines with #15678, #15692, #15695, #15696 and #15714, and could not compare #5021, #13486, #13778, #13782, #13881, #14212, #14401, #14837 and #14936. I compared every one of them by hand: for each I diffed the PR head against its merge base, searched the diff for the seven NIDs, the seven symbol names andExceptionVirtuals, and rangit merge-treeof the PR head againstmainand against this branch.libSceLibcInternal.hppinclude list.basic_stringmembers): its only hit is a rewrapped debt-file line that still lists_ZNKSt10bad_typeid8_DoraiseEv(WMw8eIs0kjM) as unimplemented; text conflicts inInventoryExports2.cppand the debt file.type_infodestructors): no hits; text conflict on the neighbouringCMakeLists.txtline.codecvt_basequeries): its only hits are rewrapped debt-file lines that still listfuture_error::what,future_error::_Doraise,system_error::_Doraise,bad_variant_access::whatand_Future_error_category::messageas unimplemented; it does not implement them. Text conflicts inCMakeLists.txt,InventoryExports2.cppand the debt file.ctype<char>widen and narrow): no hits; it touches the same debt-file block (lines 372-377) butgit merge-treemerges it with this branch cleanly.git merge-treeconflicts are the same against this branch as againstmain, so this branch adds none.StandardExceptions.cpp) was not reported; it has no hits and merges with this branch with no new conflict.These are text conflicts only; whichever merges second rebases.
Independent test evidence
0e0f234240:guest_libc_internal_exception_virtualspassed 3/3.4639eff: the build passed with no new failures or Vulkan validation IDs relative to main.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)Supersedes #15722, which the open-PR limit closed; same branch and head.
🤖 Generated with Claude Code
🤖 Updated with Codex