fix(libc): store the std::__sce_v2 _Throw_Cpp_error value in the first code word #15667
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15667"
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-04T01:31:55Z.
What
std::__sce_v2::_Throw_Cpp_error(NIDShHKOkWgZRM) stored the error value in the second 32-bit word of the thrownsystem_error's code. The versioned type keeps it in the first word. XairRrR raised this in the review of #15552, and thelibc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6) confirms it:_Throw_Cpp_errorat0x10AB60builds the object through the_System_errorconstructor at0xCD5B0, which stores the value withmov DWORD PTR [r14+0x10],r15dand the category withmov QWORD PTR [r14+0x18],rbx(0xCD72D,0xCD731).future_error::what()reads the same first word._Throw_Cpp_errorat0xB95A0passes the code asvalue << 32, so the unversioned layout keeps the value in the second word, as main already does for it.ThrowCppErrornow takes which word to use. The versioned export asks for the first word, with the second word 0 (the module leaves stack contents there). The unversioned export andThrowCppError_nid_no_patchare unchanged. With the old layout, guest code readingcode().value()on astd::__sce_v2::system_errorfrom_Throw_Cpp_errorgot 0.Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, main1c8c0efc8c4. Exact tested commit:70fdc24e8cb.guest_sce_v2_exceptionsandguest_filesystem_errorpass.guest_sce_v2_exceptionsnow throws_Throw_Cpp_error(1)through its catch frame and checks the copied code: the first word is 22 (EINVAL), the second word is 0, and the category isgeneric_category(). With main'sStandardExceptions.cppthe same test fails on the first two checks, and with this change it passes.__cxa_throw.git diff --checkpass.tools/pr_overlap.pyread 1,827 open PRs and reports no overlap. It keeps exit 2 for 29 branches that already conflict with main. None of them names_Throw_Cpp_errororThrowCppError. Merging each with this branch and with main usinggit merge-treegives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602 and #15614.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