feat(libc): implement system_category and future_category error categ… #9416
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9416"
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 Delciob on 2026-10-21T21:10:45Z.
What
Implement std::system_category() and std::future_category() error category singleton classes in libc with correct vtables, matching the PS5 ABI layout. Export new NIDs for both categories and their message()/name()/default_error_condition() virtual methods.
Tested
Windows 10 x64, linked against libc; error_code and error_condition round-trip.
Checklist
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T21:11:33Z.
Progress report (
0c6a5bd→714d17e)📈 System libraries: 42.2% (+0.1%, +23 implemented, -6 removed functions)
✅ 23 implemented
_Thrd_id_nid_postfix_ZNKSt14error_category10equivalentERKSt10error_codei_nid_postfix_ZNKSt14error_category10equivalentEiRKSt15error_condition_nid_postfix_ZNKSt14error_category23default_error_conditionEi_nid_postfix_ZNKSt22_System_error_category23default_error_conditionEi_nid_postfix_ZNKSt22_System_error_category4nameEv_nid_postfix_ZNKSt22_System_error_category7messageEi_nid_postfix_ZNSt14error_categoryD0Ev_nid_postfix_ZNSt14error_categoryD1Ev_nid_postfix_ZNSt14error_categoryD2Ev_nid_postfix_ZNSt8__sce_v212_Thrd_detachEP7pthread_nid_postfix_ZNSt8__sce_v214_Cnd_broadcastEPP12pthread_cond_nid_postfix_ZNSt8__sce_v228_Cnd_register_at_thread_exitEPP12pthread_condPP13pthread_mutexPi_nid_postfix_ZNSt8__sce_v26_ThrowERKNS_12future_errorE_nid_postfix_ZSt12setprecisioni_nid_postfix_ZSt14_Atomic_assertPKcS0__nid_postfix_ZSt15future_categoryv_nid_postfix_ZSt15system_categoryv_nid_postfix_ZSt19_Throw_future_errorRKSt10error_code_nid_postfix_ZSt22_Throw_bad_node_accessPKc_nid_postfix_ZSt25_Rethrow_future_exceptionSt13exception_ptr_nid_postfix_ZSt6_ThrowRKSt20bad_array_new_length_nid_postfix_ZSt6_ThrowRKSt8bad_cast_nid_postfix⚪ 15 behaviourally empty (constant return or throw)
_Thrd_id_nid_postfix_ZNSt14error_categoryD0Ev_nid_postfix_ZNSt14error_categoryD1Ev_nid_postfix_ZNSt14error_categoryD2Ev_nid_postfix_ZNSt8__sce_v212_Thrd_detachEP7pthread_nid_postfix_ZNSt8__sce_v214_Cnd_broadcastEPP12pthread_cond_nid_postfix_ZNSt8__sce_v228_Cnd_register_at_thread_exitEPP12pthread_condPP13pthread_mutexPi_nid_postfix_ZNSt8__sce_v26_ThrowERKNS_12future_errorE_nid_postfix_ZSt12setprecisioni_nid_postfix_ZSt14_Atomic_assertPKcS0__nid_postfix_ZSt19_Throw_future_errorRKSt10error_code_nid_postfix_ZSt22_Throw_bad_node_accessPKc_nid_postfix_ZSt25_Rethrow_future_exceptionSt13exception_ptr_nid_postfix_ZSt6_ThrowRKSt20bad_array_new_length_nid_postfix_ZSt6_ThrowRKSt8bad_cast_nid_postfix🗑️ 6 removed
_ZNKSt19bad_optional_access4whatEv_nid_postfix_ZNSt19bad_optional_accessC1Ev_nid_postfix_ZNSt19bad_optional_accessC2Ev_nid_postfix_ZNSt19bad_optional_accessD0Ev_nid_postfix_ZNSt19bad_optional_accessD1Ev_nid_postfix_ZNSt19bad_optional_accessD2Ev_nid_postfixImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:41:43Z.
Code review location:
core/libs/prx/libc/src/exception/StandardExceptions.cpp; line 245ErrorCodematches the observed guest layout{ int value; const CategoryObject* category; }: on x86_64 the pointer is at offset 8, leaving bytes 4–7 as alignment padding.value_highoverlays that padding, which callers do not initialize as a second value. If the padding happens to equal the queried code while the actualvaluediffers, this returns true for an unrelated error. The same extra-word comparison appears in the generic/system/future equivalence methods and the exported base-category equivalence methods below. Please compare the actual 32-bitvalueonly and add a regression case that poisons the padding bytes.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:41:47Z.
Review: CHANGES_REQUESTED
Requesting one correctness fix before approval: the equivalence implementations compare
value_high, which is the alignment padding in the observed{ int value; category pointer; }guest layout. That can report equality for a different error code when padding matches. I left an inline comment at the first comparison; the same issue occurs in the system/future category and base-category comparisons. Please remove the padding comparisons and add a regression case with nonzero padding. The current hosted run also has a failing macOS x86_64 relinker test and a conventions failure; I could not retrieve the hosted failure log throughghduring this review.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T22:41:58Z.
Windows run of
714d17eda7merged ontomaina6dcea9279(6e4850c067, clean), the description lists no platform. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.libc.prxdoes not link:The four already exist in
src/VectorAlgorithms.cpp,src/LocaleSupport.cppandsrc/Threads.cppon this PR's own base (0c6a5bd593), and the PR adds second definitions inExport.cppwith placeholder bodies (_ZSt4setwireturns its argument,_Thrd_idreturns 1,__std_find_trivial_1returnsnullptr,__std_reverse_trivially_swappable_1does nothing). Duplicate strong definitions are a link error on any platform, so this is not specific to Windows. Not run: the tests, since the library does not build.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:34:35Z.
Review: CHANGES_REQUESTED
Review
I found a blocking duplicate definition and additional behavior that needs to be brought within the repository’s implementation rules before this PR can be considered.
Duplicate _Thrd_id_nid_postfix
This PR adds a strong C-linkage _Thrd_id_nid_postfix definition in libc/Export.cpp returning 1, while the existing definition in libc/src/Threads.cpp remains in this branch. The libc target includes both files in target_sources, so the library has two definitions of the same symbol. The current product Linux/Windows jobs were skipped, which explains why this has not been caught by those jobs.
There is also an open PR, #9170, that replaces the existing stub with a scePthreadSelf() forward based on two console-body readings and a focused test. Please remove the duplicate placeholder here and coordinate the single implementation and landing order with that author; update Depends on if the PRs are intentionally stacked. The constant 1 is not supported by the evidence cited in #9170.
Silent placeholders and scope
The new exports also include silent no-op/null placeholders, including _Cnd_broadcast, _Cnd_register_at_thread_exit, _Thrd_detach, __std_find_trivial_1, and __std_reverse_trivially_swappable_1. These are not category implementations, and the latter two return/do nothing for all inputs. CONTRIBUTING requires unimplemented paths to throw or to be explicitly recorded under the library’s Silent stubs debt. Please remove these unrelated placeholders from this PR or implement and test them, with the required debt entries if any are intentionally silent.
Category behavior
SystemCategoryEquivalentCondition accepts a condition from self even when GenericErrorMessage(value) selects GenericCategory. The category contract compares against default_error_condition(value); the MSVC STL implementation does that exact comparison. As written, a system-category condition can compare equivalent where the default condition is generic. Please remove that extra acceptance and add a regression check for both the expected generic match and the rejected system-category match.
The PR also adds no committed tests for the new category names, messages, default conditions, or equivalence behavior. The reported Windows round-trip is useful but not reproducible from this branch. Please add focused tests for those behaviors.
Current validation
The new category objects merit focused validation, but the duplicate symbol, silent placeholders, and system-category equivalence mismatch need correction first.
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T12:52:20Z.
@Delciob the overlap report lists
_ZSt15system_categoryvhere and in #9014, which I opened about eleven hours earlier. The two also change the same lines ofStandardExceptions.cpp: theErrorCodestruct and the generic category's condition functions. #8901 touches the same file around line 253, too.The two differ in where the value lives. #9014 took the layout from the 12.00
libSceLibcInternal(read from disassembly, not measured on a console):error_category::equivalent(const error_code&, int)(0x1b760) compares the value at +4 and the category at +8.default_error_conditionoverrides (0x1b710, 0x1bba0) return the value in the high half of the first qword, so +0 stays 0.This PR stores the value at both +0 and +4 and accepts a match on either. A guest that builds an
error_codeitself, as PPSA29340'sstd::filesystemcode does (0 at +0, the category at +8,value()read from +4), gets the right answer from both PRs. But a condition this PR returns has a non-zero first dword, which the console never produces.A proposal, since everything else here is new:
system_categoryand the +4 layout.SystemCategory, thevalue_highfield and the double compare, and keepsfuture_category, theerror_categorybase exports and the rest. It would sayDepends on: #9014.If you'd rather have it the other way round, I'm fine with that as long as the layout matches the console; then I'll rebase #9014 onto yours and keep only the layout fix and its tests.
Separately, the
PlainWhathunk removes thebad_variant_accessandbad_optional_accessnames. That looks unrelated to the categories. Was it intended?🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:24:51Z.
Review: COMMENTED
Checked against main
830ccd121fand the PR's own tests (core/libs/tests/GuestBadOptionalAccess.cpp, ExceptionRuntime.cpp):PlainWhatquestion: the same hunk removes thebad_optional_accesstype info, vtable and ctor/dtor exports, and thebad_variant_accesstype info and vtable, which main defines inStandardExceptions.cpp.GuestBadOptionalAccess.cppstill references_ZTISt19bad_optional_access_nid_postfix,_ZTVSt19bad_optional_access_nid_postfixand_ZNSt19bad_optional_accessC1Ev_nid_postfix, soguest_bad_optional_access_testsno longer links. Could the removal be reverted?_ZSt26__throw_bad_variant_accessvand_ZSt26_Throw_bad_optional_accessvnow throwstd::runtime_error(Export.cpp:36-37, 48) instead of main'sThrowPlain(...)with the guest vtable.ExceptionRuntime.cpp:257-260catchesstd::bad_variant_access&/std::bad_optional_access&, so the exception escapes and the test aborts. A guestcatchon those types would miss in the same way. Keeping main's versions would fix both._ZSt6_ThrowRKSt8bad_cast,_ZSt6_ThrowRKSt20bad_array_new_length,_Throw_future_errorand_Rethrow_future_exceptionalso throw a hoststd::runtime_error, so guest handlers forbad_cast/future_errorwon't match. These probably belong in their own PR, built withThrowPlain-style guest objects._ZSt14_Atomic_assertloses itsNotImplemented_nid_no_patch(Export.cpp:23) and becomes a silent stub with no debt entry. Was that intended?Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Pull request closed