feat(libc): implement libc++ system_error and generic_category #27519

Merged
kiansaeidnia merged 1 commit from upstream-pr/27519 into main 2026-11-27 07:39:50 +00:00
kiansaeidnia commented 2026-11-26 16:04:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kiansaeidnia on 2026-11-26T16:04:28Z.


What

The RetroArch Azahar core (PPSA99169, import inventory on #5927) imports 11 libc++ std::__1 names for system_error that libc did not define. This PR adds them:

  • generic_category();
  • the system_error constructors taking error_code plus const char* or std::string (C1/C2);
  • the system_error destructors (D1/D2), RTTI and vtable;
  • __throw_system_error(int, const char*);
  • the error_category base destructor (D2) and RTTI.

The layout follows LLVM libc++ 17 system_error.cpp and the Azahar relocations:

  • error_code is 16 bytes, with the int value at 0 and the category pointer at 8.
  • system_error is a libc++ runtime_error with the error_code at 16 (32 bytes in total).
  • The generic category and the private system category derive from __do_message, which derives from error_category. They use the libc++ vtable order: D1, D0, name, default_error_condition, the two equivalent overloads, then message.
  • message() returns a libc++ short or long string through the hidden result pointer. The text comes from the guest strerror_r, and values at or above ELAST give unspecified generic_category error or unspecified system_category error.
  • what() is what_arg + ": " + message() only when the code is nonzero, as in libc++ 17.

#26252 adds the three error_category base members (default_error_condition and both equivalent overloads) as exports. This PR does not export them. The two categories fill those vtable slots with private functions, so either PR can merge first.

The new debt fragment says the layout is taken from libc++ 17 and the Azahar relocations, not from a console module. It also says ELAST is taken as FreeBSD 11's 96, which is unverified for the guest's libc++ build. A null what argument or a null category throws.

pr_overlap could not compare Api.hpp with #11831, #12682, #12688, #12700, #12965, #18135, #25289 and #26224, because they conflict with main. I checked their diffs by hand: none declares these names. The I/O cancellation PRs only throw the host std::system_error.

Tested

Windows 11, MinGW-w64 GCC 16.2, Release. These tests pass: the new guest_libcxx_system_error, plus guest_generic_category, guest_libcxx_regex_error, guest_libcxx_bad_weak_ptr, guest_standard_exception_type_records and guest_libc_doraise_system_error.

The new test checks:

  • for the generic category: the RTTI chain, the name, short and long message strings, a value past ELAST, a negative value, and the base slots;
  • the system category, reached through the code of a thrown exception;
  • both constructors, with value 0, with a guest category whose message comes from its own vtable, with short and long libc++ what strings, and with a null what or a null category, which throw;
  • that __throw_system_error is caught as runtime_error with the libc++ RTTI;
  • that the error_category D2 leaves the object unchanged.

Exports.cpp and the test were syntax-checked with g++ 11 on Linux (WSL Ubuntu). test_public_headers.py --audit-only and debt_fold.py --check pass. Not tested in the Azahar core itself.

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: PPSA99169 #5927 (11 libc++ system_error imports; other imports remain)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added support for libc++ system-error handling, including error categories, error messages, and system-error exceptions. Applications using these facilities can now report and handle system errors through the compatibility layer.
  • Tests
    • Added coverage for error-category behavior, message formatting, constructors, and exception handling, including invalid inputs and unknown error values.
  • Documentation
    • Documented supported libc++ system-error details and error-value behavior.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5513325460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27519). Originally posted by [kiansaeidnia](https://github.com/kiansaeidnia) on 2026-11-26T16:04:28Z. --- ### What The RetroArch Azahar core (PPSA99169, import inventory on #5927) imports 11 libc++ `std::__1` names for `system_error` that libc did not define. This PR adds them: - `generic_category()`; - the `system_error` constructors taking `error_code` plus `const char*` or `std::string` (C1/C2); - the `system_error` destructors (D1/D2), RTTI and vtable; - `__throw_system_error(int, const char*)`; - the `error_category` base destructor (D2) and RTTI. The layout follows LLVM libc++ 17 `system_error.cpp` and the Azahar relocations: - `error_code` is 16 bytes, with the `int` value at 0 and the category pointer at 8. - `system_error` is a libc++ `runtime_error` with the `error_code` at 16 (32 bytes in total). - The generic category and the private system category derive from `__do_message`, which derives from `error_category`. They use the libc++ vtable order: D1, D0, `name`, `default_error_condition`, the two `equivalent` overloads, then `message`. - `message()` returns a libc++ short or long string through the hidden result pointer. The text comes from the guest `strerror_r`, and values at or above `ELAST` give `unspecified generic_category error` or `unspecified system_category error`. - `what()` is `what_arg + ": " + message()` only when the code is nonzero, as in libc++ 17. #26252 adds the three `error_category` base members (`default_error_condition` and both `equivalent` overloads) as exports. This PR does not export them. The two categories fill those vtable slots with private functions, so either PR can merge first. The new debt fragment says the layout is taken from libc++ 17 and the Azahar relocations, not from a console module. It also says `ELAST` is taken as FreeBSD 11's 96, which is unverified for the guest's libc++ build. A null `what` argument or a null category throws. `pr_overlap` could not compare `Api.hpp` with #11831, #12682, #12688, #12700, #12965, #18135, #25289 and #26224, because they conflict with `main`. I checked their diffs by hand: none declares these names. The I/O cancellation PRs only throw the host `std::system_error`. ### Tested Windows 11, MinGW-w64 GCC 16.2, Release. These tests pass: the new `guest_libcxx_system_error`, plus `guest_generic_category`, `guest_libcxx_regex_error`, `guest_libcxx_bad_weak_ptr`, `guest_standard_exception_type_records` and `guest_libc_doraise_system_error`. The new test checks: - for the generic category: the RTTI chain, the name, short and long message strings, a value past `ELAST`, a negative value, and the base slots; - the system category, reached through the code of a thrown exception; - both constructors, with value 0, with a guest category whose `message` comes from its own vtable, with short and long libc++ `what` strings, and with a null `what` or a null category, which throw; - that `__throw_system_error` is caught as `runtime_error` with the libc++ RTTI; - that the `error_category` D2 leaves the object unchanged. `Exports.cpp` and the test were syntax-checked with g++ 11 on Linux (WSL Ubuntu). `test_public_headers.py --audit-only` and `debt_fold.py --check` pass. Not tested in the Azahar core itself. ### 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: PPSA99169 #5927 (11 libc++ system_error imports; other imports remain) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added support for libc++ system-error handling, including error categories, error messages, and system-error exceptions. Applications using these facilities can now report and handle system errors through the compatibility layer. * **Tests** * Added coverage for error-category behavior, message formatting, constructors, and exception handling, including invalid inputs and unknown error values. * **Documentation** * Documented supported libc++ system-error details and error-value behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
MarcZX10 commented 2026-11-26 16:19:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T16:19:25Z.

Review: COMMENTED


Reviewed — no blocking findings

The reviewed changes add libc++ system_error support and its guest ABI tests; no concrete blocking defect was found in the inspected code.

What I ran

Reviewed head a2f3578789035b76de129313c5e4e437767429e7 using the prepared diff and repo_read.py. No tests or build commands were run.

Results

Check Result Note
Changed code review passed Five changed files inspected
Build and tests not run No independent run performed

Findings

Blocking

None.

Non-blocking

The PR description reports that the changes were not tested in the Azahar core. Testing there would add confidence that the imported ABI matches the target application.

Not verified

No build or test results were independently verified. Azahar core behavior and console behavior were not tested. The manifest lists five changed files, all included; diff.patch contained their complete changes. No excluded changed files were listed in the manifest.

To get this to a good state

Nothing is required. Optional: test the new imports in the Azahar core.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6077441583 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27519#pullrequestreview-6077441583). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-26T16:19:25Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The reviewed changes add libc++ `system_error` support and its guest ABI tests; no concrete blocking defect was found in the inspected code. ## What I ran Reviewed head `a2f3578789035b76de129313c5e4e437767429e7` using the prepared diff and `repo_read.py`. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Five changed files inspected | | Build and tests | not run | No independent run performed | ## Findings ### Blocking None. ### Non-blocking The PR description reports that the changes were not tested in the Azahar core. Testing there would add confidence that the imported ABI matches the target application. ## Not verified No build or test results were independently verified. Azahar core behavior and console behavior were not tested. The manifest lists five changed files, all included; `diff.patch` contained their complete changes. No excluded changed files were listed in the manifest. ## To get this to a good state Nothing is required. Optional: test the new imports in the Azahar core.
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!27519
No description provided.