feat(libc): export the error_category members and std::future_error #11241
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11241"
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 edubox on 2026-10-25T22:28:40Z.
What
Export the
std::error_categorybase members that titles import: the 16-byte_ZTISt14error_categoryclass type info,~error_category,default_error_condition(int)and bothequivalentoverloads. They call the same code the generic and system category vtables already use, so a title'serror_codemaps and compares as the console's libc does. The console keeps the value in the second dword; the test pins nonzeroreservedpadding in both overloads.Implement
std::future_categoryandstd::future_errorfrom the samelibc.prx._Future_error_categoryderives from_Generic_error_category, is namedfuture, and its messages for 1..4 arebroken promise,future already retrieved,promise already satisfiedandno state; other values fall back to the generic table, whilefuture_error::what()returns a null pointer for them as the console helper does.future_erroris 0x40 bytes (vtable,GuestLocale::Stringat 0x8, 16-byteerror_codeat 0x30), its vtable is 0x30 bytes with a_Doraiseslot, and_Throw_future_errorallocates that size and throws with the console type info._Rethrow_future_exceptiondelegates torethrow_exception.Evidence: disassembled the
libc.prxbundled in PPSA02530'ssce_module. The base members are at0x161a0,0x161c0,0x161e0and0x16210; the type infos and vtables at0x18c818,0x18f470,0x18f488,0x18f4b8and0x18f500; the future category andfuture_errorat0xb7540,0xb7590,0xb7680,0xb7390,0xb74a0,0xb7760,0xb7850and0xb7860. The debt entry records the differences (the static future category's deleting destructor throws instead of freeing it, and the string destructor frees the block directly).Tested
ctest -R '^(guest_generic_category|guest_future_category|guest_ampr_cpp_error)$'(Linux, CachyOS, GCC 16.2.1): 3/3 pass. The newguest_future_categorypins the base type info name and size, nonzero padding in bothequivalentoverloads,default_error_condition, the future category name/messages/fallback, thefuture_errorsize/offsets/vtable, the thrown type andwhat()for 1..4 (and null outside), and the destructor.nm -D -Son the patchedlibc.prx: the new NIDs are exported with the console sizes (cbvW20xPgyc0x10,3aZN32UTqqk0x18,DCY9coLQcVI0x18,6-LMlTS1nno0x30,YHfG3-K23CY0x48).python3 tools/check_conventions.py --base origin/main: pass.python3 tools/pr_overlap.py --branch feat/libc-future-category --jobs 32: no overlapping exports. The PRs whose shared files could not be compared touch onlyCMakeLists.txt,Api.hppor the debt file, notStandardExceptions.cpp.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T22:34:53Z.
Review: APPROVED
I reviewed the complete diff and the new guest test. The class-type-info record, base error_category vtable slots, future-category inheritance, and 0x40-byte future_error object layout are internally consistent with the ABI layouts claimed in the PR. The implementation keeps category comparison on the existing generic/system helpers, handles inline versus allocated GuestLocale strings, and copies heap-backed messages before throwing. The regression covers nonzero reserved fields, category identity, all four future messages, generic fallback, thrown type/what(), and the future_error destructor.
git diff --checkandpython3 tools/check_conventions.py --base upstream/main --head refs/remotes/upstream/pr/11241pass. The author reports the three focused Linux guest tests passing 3/3; I did not rerun the libc product test locally because the availablebuild-reviewconfiguration is relinker-only. Hosted eligibility, intake, labels, report, Ubuntu register-context and ASan pass; Windows/macOS relinker and macOS register-context jobs are still pending, while product builds are skipped by policy. No concrete defect found in this review.Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-25T23:12:22Z.
Review: CHANGES_REQUESTED
Found one allocation-failure cleanup issue at exact head
e859215335e34c1fd566130ab0c36223864ec064.future_error's_Doraisevtable entry first allocates an exception block with__cxa_allocate_exception_nid_postfix, thenCopyFutureErrorallocates again through guestoperator newwhen the source message is heap-backed (capacity > 15). If that second allocation fails,std::bad_allocescapes before__cxa_throw_nid_postfixreceives ownership. The first block is never released. This affects the heap-backed-message copy path, not every_Throw_future_errorcall (that helper creates an empty inline message).I reproduced this on native Windows with the complete production
Runtime.cpp,StandardExceptions.cpp,StdioExtras.cppandApplicationHeap.cpp. The registered guest allocator returns null at the copy allocation, so the real application-heap/new code produces the failure. Runtime malloc/free calls are redirected to observing wrappers that use normal host malloc/free. The actual exception allocation/free bodies are retained. A capture adapter replaces the final throw handoff for successful-copy controls; the failing-copy cases never reach that adapter. This is allocation-ownership validation, not full guest unwinding/RTTI-catch validation.Results with GCC 16.2.0-6 UCRT, C++20,
-O1 -g -fno-inline -flto, static C++ runtime:The matrix crosses message lengths 0, 1, 15, 16, 24, 31, 47 and 95, codes 1..4/99, and normal/failing guest allocation. Each of the 25 failing heap-copy cases at the head has one exception allocation and zero frees before the probe manually cleans it up. With the patch, the original
bad_allocpropagates and the block is freed exactly once. All successful copies retain vtable/code fields and separate heap storage; all source-object bytes and message bytes stay intact, and source destruction still frees the original allocation. The head log's final live count is zero because the probe cleans up after recording each leak, not because the head frees it.Reviewable repair: ee91bab13f84, branch
codex/review-future-error-copy-cleanup. The commit changes one production file, 6 insertions/1 deletion. Its parent is a clean local merge of this PR with current-main snapshot49d1f9b07ec7f6f989ace1c504bbe9dd6748dcbb; all 133 libc files were identical to this PR before applying the patch. The committed candidate's actual source was then rebuilt and passed the full 80-case fixture (CTest 1/1, 0 skipped, 0.12 s). Conventions against that pinnedorigin/mainand whitespace checks pass; the candidate checkout is clean. This is a support commit for cherry-picking, not another PR or an imposed merge order.Please free only the raw exception allocation if copying throws, then rethrow. Calling the future-error destructor on that partially copied object would risk freeing the source's aliased string pointer.
I did not run the full libc/product build, the committed three guest-category tests, Linux/macOS, console/title execution, or a canonical PR-overlap scan. The successful-control adapter does not establish the guest unwinder or catch ABI. AI-assisted implementation and replay: Codex.
Complete fault-injection replay (four production sources, five fixture files)
Check out the exact PR head and support commit separately. Save the five files below in another directory, set
REPOto the PR-head checkout andFIXED_SOURCEto the support checkout'score/libs/prx/libc/src/exception/StandardExceptions.cpp, and build with GCC/MinGW on Windows:Run
build/head_probe.exefor the negative control: exit 1 with 25 failed checks/leak cases.build/fixed_probe.exeexits 0 with 0 failures/leaks. CTest registers only the fixed version.Production.cppkeeps Runtime before StandardExceptions as in the library'sexception/Exports.cpp; it replaces only the allocator observation and final throw boundary, while omitting the full product's exception-export aliases. The typed vtable accessors avoid declaring the vtable with a conflicting type. Uncalled default-heap paths fail loudly if reached. The objcopy step follows the project's Windows unwind-section handling for exceptions crossing the guest ABI.CMakeLists.txt
Support.hpp
Production.cpp
Support.cpp
Probe.cpp
Imported from boykopovar/AnyPS5. Originally posted by thepoppfish on 2026-10-26T01:12:28Z.
Review: APPROVED
Re-reviewed exact head
45ea48c5aa1d3a612822d373944b5ba9817c1737. The allocation-cleanup finding is addressed, and I approve this revision.The complete
StandardExceptions.cppblob isa04b42a966ad33fa11d78cda7bc21d9f8e93d635, byte-identical to the tested repair in ee91bab13f84. The catch frees only the raw exception allocation and rethrows; it leaves the source-owned message intact.I rebuilt the unchanged 80-case ownership probe from my original review against both:
5b85225ef39b9321d8f5c251ecb391b8331e8aea, commitad3f17baefc1e50667eaf0983eab236674d0fa08/ tree93150b24d736af1a33eac6c1ca1b4862c4766a3f: the same 80 / 3,310 / 0 / 0, CTest 1/1 in 0.13s, zero skips.Both are fresh six-step builds on Windows 11 build 26200, GCC 16.2.0-6 UCRT64, CMake 4.3.1 and Ninja 1.13.2. Each uses its own actual headers. Runtime, StandardExceptions, StdioExtras and ApplicationHeap production blobs are identical between the two trees. The five original fixture files match the code published in the original review.
The matrix covers eight message lengths across the inline/heap boundary, five error codes and successful/failing guest allocation. Every raw exception block is freed exactly once, heap copies remain separate from the source, source bytes remain intact, and both exception/guest allocation trackers end at zero. For the 25 heap-copy failures,
bad_allocpropagates without reaching the final throw adapter.Conventions against pinned
origin/mainand whitespace checks pass on both trees; both builds have no compiler warnings. I also inspected the new committed allocation-failure check inGuestFutureCategory.cpp. These runs use the original real Runtime allocator and guest-new/ApplicationHeap path, with observational malloc/free wrappers and the explicit final-throw capture adapter described previously. They do not run the complete committed guest fixture, full product/unwinder/RTTI catch ABI, Linux/macOS, a title or console. The original negative controls are historical and were not rerun. AI-assisted: yes.The original inline thread is now outdated but remains unresolved; please resolve it.
Fresh-build replay
Keep the five original fixture files from the linked review in a directory named
native-future11241. Save this CMake file in a sibling directory and configure it with-DREPO=<absolute-head-checkout>, then build and run CTest. Repeat with the integration checkout for the second run. The source tree is selected byREPO; no production file is replaced with the old scratch candidate.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T06:40:03Z.
Review: APPROVED
Re-reviewed exact head
45ea48c5aa1d3a612822d373944b5ba9817c1737. The_Doraisepath now frees the raw exception allocation ifCopyFutureErrorthrows and rethrows without running the partially initialized object destructor, which could otherwise free the source-owned aliased message. The new guest regression exercises heap-backed source text with guest allocation failure and checksbad_allocpropagation plus source-text integrity. I verified the current-main diff andgit diff --check; hosted conventions, relinker matrix, relinker ASan and register-context checks pass. Product Linux/Windows builds are skipped by repository policy. The focused guest tests and ownership probe are reported by the author and an independent reviewer; I did not rerun a local libc product build.