feat(libc): add ios_base::failure constructors #28897

Open
maskym wants to merge 5 commits from upstream-pr/28897 into main
maskym commented 2026-12-04 14:45:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by maskym on 2026-12-04T14:45:45Z.


What

Adds three libc exports for std::ios_base::failure, next to the existing ios_base::failure destructors and what:

  • _ZNSt8ios_base7failureC1EPKcRKSt10error_code (2PxU-rB3ixI) and _ZNSt8ios_base7failureC2EPKcRKSt10error_code (xFkYamgQChU): failure(const char*, const error_code&). As in Microsoft STL xiosbase, the object is built through system_error(error_code, const char*), so the message is "<message>: <category message>", or just the category message when the message is empty. This reuses the existing _ZNSt12system_errorC2ESt10error_codePKc path (LibcExceptionConstructSystemError_nid_no_patch). The constructor then stores the ios_base::failure vtable. The error_code comes in by reference, so it arrives as a pointer and is dereferenced. A null error_code reference calls GuestFault_nid_no_patch, since the console dereferences it (the input this PR names under the new GuestFault rule); a null category throws std::invalid_argument from the shared system_error constructor, as on main.
  • _ZNSt8ios_base7failureC1ERKS0_ (igWZiDXnBC0): the copy constructor. It shares the refcounted message and copies the 16-byte error_code, like the existing system_error copy constructor.

The NIDs are tools/nid_names.py compute_nid of each name. I did not check which console module exports these, so this PR adds no libSceLibcInternal forwarders. The NSt8__sce_v28ios_base7failureE variants are out of scope. The gap is recorded in docs/dev/debt/changes/feat-libc-ios-failure-constructors.md.

Tested

Windows 11, GCC 15.2 (WinLibs UCRT), Ninja Release. The new host test guest_ios_failure_constructors is registered in core/libs/prx/libc/tests/cmake/guest_ios_failure_constructors.cmake. It uses a test category whose message is "Invalid argument" and checks:

  • C1 with "stream": the type record is NSt8ios_base7failureE, what() is stream: Invalid argument, and the code is {0, 22, &category}. D1 then clears the message.
  • C2 with "": what() is Invalid argument.
  • The copy constructor: it shares the message pointer and copies the code. The copy's what() still works after the source is destroyed, and both messages are null after D1.
  • A null error_code pointer reaches GuestFault_nid_no_patch (a std::runtime_error naming the console fault), and a null category throws std::invalid_argument.

Retested after merging main 87a06f59cf: ctest -R "^(guest_ios_failure_constructors|guest_ampr_cpp_error|guest_filesystem_error)$" passed in each of 3 runs.

Red checks:

  • Without the implementation, the test does not link: undefined reference to '_ZNSt8ios_base7failureC1EPKcRKSt10error_code_nid_postfix'.
  • Without the vtable store, the test fails with ios_base::failure constructor check 1 failed.

tools/check_conventions.py --base origin/main and tools/debt_fold.py --check pass. No title or homebrew was run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • New Features
    • Added support for constructing and copying I/O failure exceptions with messages and error codes.
  • Tests
    • Added coverage for exception construction, copying, and invalid error-code inputs.
  • Documentation
    • Documented the new I/O failure exception support.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5648580327 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28897). Originally posted by [maskym](https://github.com/maskym) on 2026-12-04T14:45:45Z. --- ### What Adds three libc exports for `std::ios_base::failure`, next to the existing `ios_base::failure` destructors and `what`: - `_ZNSt8ios_base7failureC1EPKcRKSt10error_code` (`2PxU-rB3ixI`) and `_ZNSt8ios_base7failureC2EPKcRKSt10error_code` (`xFkYamgQChU`): `failure(const char*, const error_code&)`. As in [Microsoft STL `xiosbase`](https://github.com/microsoft/STL/blob/e1ed302683e5e822f663fbb0f44cee7e9ddc6af0/stl/inc/xiosbase#L107-L108), the object is built through `system_error(error_code, const char*)`, so the message is `"<message>: <category message>"`, or just the category message when the message is empty. This reuses the existing `_ZNSt12system_errorC2ESt10error_codePKc` path (`LibcExceptionConstructSystemError_nid_no_patch`). The constructor then stores the `ios_base::failure` vtable. The `error_code` comes in by reference, so it arrives as a pointer and is dereferenced. A null `error_code` reference calls `GuestFault_nid_no_patch`, since the console dereferences it (the input this PR names under the new `GuestFault` rule); a null category throws `std::invalid_argument` from the shared `system_error` constructor, as on `main`. - `_ZNSt8ios_base7failureC1ERKS0_` (`igWZiDXnBC0`): the copy constructor. It shares the refcounted message and copies the 16-byte `error_code`, like the existing `system_error` copy constructor. The NIDs are `tools/nid_names.py` `compute_nid` of each name. I did not check which console module exports these, so this PR adds no libSceLibcInternal forwarders. The `NSt8__sce_v28ios_base7failureE` variants are out of scope. The gap is recorded in `docs/dev/debt/changes/feat-libc-ios-failure-constructors.md`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11, GCC 15.2 (WinLibs UCRT), Ninja Release. The new host test `guest_ios_failure_constructors` is registered in `core/libs/prx/libc/tests/cmake/guest_ios_failure_constructors.cmake`. It uses a test category whose message is `"Invalid argument"` and checks: - C1 with `"stream"`: the type record is `NSt8ios_base7failureE`, `what()` is `stream: Invalid argument`, and the code is `{0, 22, &category}`. D1 then clears the message. - C2 with `""`: `what()` is `Invalid argument`. - The copy constructor: it shares the message pointer and copies the code. The copy's `what()` still works after the source is destroyed, and both messages are null after D1. - A null `error_code` pointer reaches `GuestFault_nid_no_patch` (a `std::runtime_error` naming the console fault), and a null category throws `std::invalid_argument`. Retested after merging `main` `87a06f59cf`: `ctest -R "^(guest_ios_failure_constructors|guest_ampr_cpp_error|guest_filesystem_error)$"` passed in each of 3 runs. Red checks: - Without the implementation, the test does not link: `undefined reference to '_ZNSt8ios_base7failureC1EPKcRKSt10error_code_nid_postfix'`. - Without the vtable store, the test fails with `ios_base::failure constructor check 1 failed`. `tools/check_conventions.py --base origin/main` and `tools/debt_fold.py --check` pass. No title or homebrew was run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added support for constructing and copying I/O failure exceptions with messages and error codes. * **Tests** * Added coverage for exception construction, copying, and invalid error-code inputs. * **Documentation** * Documented the new I/O failure exception support. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-12-04 15:10:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T15:10:44Z.

Review: COMMENTED


Reviewed — comments

The changed code and tests support the described behavior, but console exports and behavior have not been verified.

What I ran

Reviewed head b28afd4581411a187b319c051e01633d7188f301 from the prepared diff and file copies. The repository reader search could not run because it tried to write its call log in the read-only review folder. No tests or builds were run.

Results

Check Result Note
Changed lines passed All five changed files reviewed
Tests and build not run No execution performed
Console verification not run Exporting module and behavior unchecked

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libc/src/exception/StandardExceptions.cpp:685 adds behavior for a console ABI whose implementation and exporting module the author says were not checked. The debt entry records this gap; the implementation is supported by the shared system_error constructor and the included host test, but console compatibility remains unverified.

Not verified

No tests, build, console run, or console export/module inspection was performed. Read the changed lines and relevant context in all five reviewed files: core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/exception/StandardExceptions.cpp, core/libs/prx/libc/tests/cmake/guest_ios_failure_constructors.cmake, core/libs/tests/GuestIosFailureConstructors.cpp, and docs/dev/debt/changes/feat-libc-ios-failure-constructors.md. files.json lists no excluded files.

To get this to a good state

Nothing is required. Optional: compare the constructors and exporting module with the console libc or libSceLibcInternal module.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6191371746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28897#pullrequestreview-6191371746). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-04T15:10:44Z. **Review:** COMMENTED --- # Reviewed — comments The changed code and tests support the described behavior, but console exports and behavior have not been verified. ## What I ran Reviewed head `b28afd4581411a187b319c051e01633d7188f301` from the prepared diff and file copies. The repository reader search could not run because it tried to write its call log in the read-only review folder. No tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Changed lines | passed | All five changed files reviewed | | Tests and build | not run | No execution performed | | Console verification | not run | Exporting module and behavior unchecked | ## Findings ### Blocking None. ### Non-blocking - `core/libs/prx/libc/src/exception/StandardExceptions.cpp:685` adds behavior for a console ABI whose implementation and exporting module the author says were not checked. The debt entry records this gap; the implementation is supported by the shared `system_error` constructor and the included host test, but console compatibility remains unverified. ## Not verified No tests, build, console run, or console export/module inspection was performed. Read the changed lines and relevant context in all five reviewed files: `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/src/exception/StandardExceptions.cpp`, `core/libs/prx/libc/tests/cmake/guest_ios_failure_constructors.cmake`, `core/libs/tests/GuestIosFailureConstructors.cpp`, and `docs/dev/debt/changes/feat-libc-ios-failure-constructors.md`. `files.json` lists no excluded files. ## To get this to a good state Nothing is required. Optional: compare the constructors and exporting module with the console libc or libSceLibcInternal module.
Plyxen commented 2026-12-04 15:47:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-04T15:47:39Z.

Review: APPROVED


Verified head b28afd4581 on Windows 11 with GCC 15.2, applied to main 484b0368d3.

  • guest_ios_failure_constructors: passes.
  • No runtime negative: with the StandardExceptions.cpp and Api.hpp changes reverted, the test does not compile, because the constructors are undeclared.

Read through: C1(const char*, const error_code&) builds a system_error, then switches the vtable to ios_base::failure's. C2 forwards to C1. The copy constructor uses the same LibcException::Copy as the other exception copies and copies code. A null code goes to GuestFault_nid_no_patch, which the debt fragment records.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6191982088 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/28897#pullrequestreview-6191982088). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-04T15:47:39Z. **Review:** APPROVED --- Verified head b28afd4581 on Windows 11 with GCC 15.2, applied to main 484b0368d3. - `guest_ios_failure_constructors`: passes. - No runtime negative: with the `StandardExceptions.cpp` and `Api.hpp` changes reverted, the test does not compile, because the constructors are undeclared. Read through: `C1(const char*, const error_code&)` builds a `system_error`, then switches the vtable to `ios_base::failure`'s. `C2` forwards to `C1`. The copy constructor uses the same `LibcException::Copy` as the other exception copies and copies `code`. A null `code` goes to `GuestFault_nid_no_patch`, which the debt fragment records. AI-assisted: yes (Claude Code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/28897:upstream-pr/28897'
git switch 'upstream-pr/28897'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/28897'
git switch 'upstream-pr/28897'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/28897'
git switch 'upstream-pr/28897'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/28897'
git switch 'main'
git merge --squash 'upstream-pr/28897'
git switch 'main'
git merge --ff-only 'upstream-pr/28897'
git switch 'main'
git merge 'upstream-pr/28897'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!28897
No description provided.