Repository navigation
feat(libc): throw std::bad_cast and the std::__sce_v2 bad_any_cast, format_error and future_error - #15552
Conversation
…ormat_error and future_error Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Progress report (1c8c0ef → d5a7a58)📈 System libraries: 26.65% (+0.01%, +4 implemented functions) ✅ 4 implemented
Changed libraries (implemented exports)
|
✅ AMD GPU test: passedPR head
Unstable on main (2, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (15, not counted against this PR)Validation IDs already present on main (4 IDs in 765 tests)Skipped (61)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
XairRrR
left a comment
There was a problem hiding this comment.
Reviewed — approved
The four new throwers (std::_Throw(const bad_cast&) and the std::__sce_v2 _Throw for bad_any_cast, format_error and future_error) merge cleanly, build, and pass the extended guest_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, main 086c0686c8adff3ee648fdbe34e0b0b647e1d511, merged tree f3b27126c6910ae6eaa4b22b96aad52e054af9c3. Debian 13 VM, GCC 14.2.0, Release, Ninja, BUILD_TESTING=ON.
git diff --check 086c0686c8adff3ee648fdbe34e0b0b647e1d511...e92455a5f4bc902b32775437bdf5231e782f9313
python3 tools/check_conventions.py --base 086c0686c8adff3ee648fdbe34e0b0b647e1d511
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^guest_sce_v2_exceptions$|^public_headers$"
# negative control
git show 086c0686c8adff3ee648fdbe34e0b0b647e1d511:core/libs/prx/libc/include/Api.hpp > core/libs/prx/libc/include/Api.hpp
git show 086c0686c8adff3ee648fdbe34e0b0b647e1d511:core/libs/prx/libc/src/exception/StandardExceptions.cpp > core/libs/prx/libc/src/exception/StandardExceptions.cpp
ninja -C build -j32 -l32 guest_sce_v2_exceptions_tests
# mutation: versioned future_error::what() reads code.value instead of the first word
ninja -C build -j32 -l32 guest_sce_v2_exceptions_tests
build/tests/guest_sce_v2_exceptions_tests
# restore merged files, rebuild, rerun
ninja -C build -j32 -l32 guest_sce_v2_exceptions_tests
ctest --test-dir build --output-on-failure -R "^guest_sce_v2_exceptions$"
git status --porcelain
Results
| Check | Result |
|---|---|
git diff --check |
clean |
check_conventions.py |
All conventions checks passed |
Configure / build / libs (script) |
ok |
| Selected tests (script): 3729 run | 0 new failures, 0 timeouts; the 9 known failures also fail on main |
check_skips.py (script) |
guest_net_ctl skipped, which also happens on main; not caused by this PR |
guest_sce_v2_exceptions |
passed (0.01 s) |
public_headers |
passed (62 s on this shared VM; it is not a new test, and it also runs long on the AMD CI) |
| Vulkan validation | not applicable (no AGC driver, shader or VideoOut change) |
Negative control
- Production files reverted: I restored
Api.hppandStandardExceptions.cppfrommain. The test no longer compiles because the four throwers are not declared, so the test does depend on the new exports. - Targeted mutation: I changed the versioned
FutureErrorWhat_nid_no_patchto readcode.value, the second word, which is what the unversionedfuture_errorreads. The build succeeded and the test failed:
output
_Throw(future_error): got 'NSt8__sce_v212future_errorE|(null)', want 'NSt8__sce_v212future_errorE|promise already satisfied'
After that I restored the merged files and rebuilt; the test passed again, and git status --porcelain was empty.
Findings
Blocking
None.
Non-blocking
- Unclear read of the first code word. At
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). - Possible layout mismatch with
__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
- Module data: I had no access to the PPSA03671
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. - Platforms: Windows/MinGW, macOS and console execution.
- Other tests: the related tests named in the description, other than
guest_sce_v2_exceptionsandpublic_headers, beyond the script's selected run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ AMD GPU test: passedPR head
Unstable on main (4, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (8, not counted against this PR)Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (8 IDs in 777 tests)Skipped (62)ReproduceAutomated build and test on a contributor's AMD machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Checked the thrower types, base classes, |
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: feat(libc): expose 345 read-only runtime data exports #13449 adds the unversionedfuture_errortype-name string as data, and fix(relinker): match AppContent utility import to provider #13486 lists unversionedfuture_errordestructors in a table. The branch also merges cleanly with feat(libc): export the std::__sce_v2 extended-precision helpers #15336, feat(libc): export the std::__sce_v2 multiprecision helpers #15471, feat(libc): export the std::__sce_v2 _Poly and _XLgamma helpers #15484, feat(libc): export the std::__sce_v2 _Xtime_diff_to_millis2 helper #15490, feat(libc): export the std::__sce_v2 _Exp and _FExp helpers #15501 and feat(libc): export the std::__sce_v2 _Pmsw, _FPmsw and _LPmsw helpers #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