Skip to content

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

Merged
oneandonlydean merged 5 commits into
boykopovar:mainfrom
maskym:feat/libc-ios-failure-constructors
Dec 6, 2026
Merged

oneandonlydean merged 5 commits into
boykopovar:mainfrom
maskym:feat/libc-ios-failure-constructors

Conversation

@maskym

@maskym maskym commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

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.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: ios_base::failure constructors

Layer / File(s) Summary
Constructor declarations and implementation
core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/exception/StandardExceptions.cpp
Adds message/error-code and copy-constructor exports. The message constructor faults on a null error-code pointer, initializes the system error, and sets the failure vtable. The copy constructor copies the base exception and error code.
Constructor tests and documentation
core/libs/tests/GuestIosFailureConstructors.cpp, core/libs/prx/libc/tests/cmake/guest_ios_failure_constructors.cmake, docs/dev/debt/changes/feat-libc-ios-failure-constructors.md
Adds guest tests for constructor results, message lifetime, copying, and invalid inputs; registers the test with CTest; documents the constructor exports and behavior.

Possibly related PRs

  • boykopovar/AnyPS5#27582: Adds overlapping ios_base::failure constructors and related exports, including system-error-based message handling.
  • boykopovar/AnyPS5#27519: Defines the system_error layout and construction path used by this PR.

Suggested labels: libc, prx, docs, build

Suggested reviewers: marczx10, privacyonion, b-howell

Change: Feature

Merge Risk: Minimal · up to b28af

This change adds exported ios_base::failure constructors with tests and documentation. No concrete defect was identified, and the main remaining uncertainty is how closely the behavior matches the console module, which the change documents.

Security architecture risk: Minimal · up to b28af

The new constructors reuse libc’s existing exception and message-ownership rules. The review found no material increase in security or failure-containment risk. Compatibility with the console’s exporting module remains unverified.

Security review details

Security Blast Radius

  • inferred — The change adds callable symbols for guests that use libc without showing a new authority boundary. The pre-existing system_error constructors already let guest ABI callers supply category and message inputs and retain shared exception messages through the same helpers.

Trust Boundaries and Controls

  • observed — The ABI accepts caller-provided object pointers. Null code and category inputs are rejected before dispatch, but those checks do not validate arbitrary non-null pointers. With a valid category, message lookup uses the category’s virtual method through the existing system_error helper.

Dependencies

  • observed — The implementation targets libc and deliberately leaves libSceLibcInternal forwarding out of scope. The matching console module and constructor behavior have not been confirmed, so the libc implementation alone does not establish compatibility for imports targeting libSceLibcInternal.

Resilience and Maintainability Implications

  • observed — A null error-code reference takes the nonreturning GuestFault path, which throws std::runtime_error. A non-null code with a null category throws std::invalid_argument. Neither path writes the destination object. This describes libc’s behavior at the call boundary, not how the console faults or how an uncaught exception is handled.
  • observed — Copy construction retains the message and copies the error code by value. Either completed object can be destroyed first without invalidating the other’s message; the last release frees it. This requires a live source throughout the copy. Atomic message references do not synchronize concurrent destruction of that source object or extend the category object’s lifetime.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 863bc003-e761-45cf-bddf-8ec5631aef8c
Commits

Reviewing files that changed from the base of the PR and between 8037ad5 and b28afd4.

Files selected for processing: 5

  • 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
  • docs/dev/debt/changes/feat-libc-ios-failure-constructors.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 12682 core/libs/prx/libc/include/Api.hpp
PR 12688 core/libs/prx/libc/include/Api.hpp
PR 12700 core/libs/prx/libc/include/Api.hpp
PR 12965 core/libs/prx/libc/include/Api.hpp
PR 18190 core/libs/prx/libc/include/Api.hpp
PR 19864 core/libs/prx/libc/src/exception/StandardExceptions.cpp
PR 27540 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/exception/StandardExceptions.cpp
PR 27568 core/libs/prx/libc/include/Api.hpp
PR 27569 core/libs/prx/libc/include/Api.hpp
PR 27815 core/libs/prx/libc/include/Api.hpp
PR 27823 core/libs/prx/libc/include/Api.hpp
PR 28657 core/libs/prx/libc/include/Api.hpp
core/libs/prx/libc/src/exception/StandardExceptions.cpp

@maskym

maskym commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Checked the four shared-file entries by hand before opening: #12682, #12688, #12700 and #12965 are libkernel changes (POSIX read/write/accept cancellation and blocking sockets) whose Api.hpp hunks touch none of the ios_base, failure or system_error declarations this PR adds, so there is no overlap. tools/pr_overlap.py --names also reports none of the three exports on main or in any open pull request.

AI-assisted: yes (Claude Code).

@Plyxen Plyxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified head b28afd4 on Windows 11 with GCC 15.2, applied to main 484b036.

  • 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)

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Progress report (8037ad5 → b28afd4)

📈 System libraries: 48.03% (+0.0039%, +3 implemented functions)

✅ 3 implemented
Library Name
libc _ZNSt8ios_base7failureC1EPKcRKSt10error_code_nid_postfix
libc _ZNSt8ios_base7failureC1ERKS0__nid_postfix
libc _ZNSt8ios_base7failureC2EPKcRKSt10error_code_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1934/1943 (99.54%) 1937/1946 (99.54%) +0.0007%

@ycbuzi

ycbuzi commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Tested b28afd4581 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 4 tests failed out of 7629; 99% tests passed, 3 tests failed out of 7629. 3 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 7629; 99% tests passed, 1 tests failed out of 7629. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@NobleBrains

Copy link
Copy Markdown
Contributor

Linux x86_64 check (Ubuntu 24.04 container) at head b28afd4, merged into origin/main fdd3f98, NVIDIA GeForce RTX 3070 (driver 620.73.04), ANYPS5_REQUIRE_VULKAN=1. The changed test passes: `guest_ios_failure_constructors` (1 of 1), none skipped. With `Api.hpp` and `StandardExceptions.cpp` reverted to `origin/main`, the test no longer builds (the new exports are missing). python3 tools/check_conventions.py passes. Not tested: Windows, macOS, the full suite.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit fae95f4 into boykopovar:main Dec 6, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants