feat(libc): implement the system_error error_code constructor #16004

Merged
fishingpvalues merged 4 commits from upstream-pr/16004 into main 2026-11-08 14:17:04 +00:00
fishingpvalues commented 2026-11-05 08:44:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fishingpvalues on 2026-11-05T08:44:43Z.


What

libSceLibcInternal exported oly3wSwEJ2A (_ZNSt12system_errorC2ESt10error_codePKc) as a throwing stub, and the patcher failed with duplicate patched export name: oly3wSwEJ2A whenever libc stopped exporting libstdc++'s weak copy of that constructor (#15955). This implements the constructor and makes the NID call it:

  • libc constructs the 32-byte guest std::system_error from the 16-byte error_code and the const char* message. The runtime_error base follows Dinkumware _Makestr: it takes the message, appends ": " only when that message is non-empty, then appends error_code.message() through the category's guest vtable; the code is stored at offset 16. A null category throws std::invalid_argument (the reference would dereference it), and an empty message yields "Invalid argument".
  • libc exports the constructor under its own NID, so libSceLibcInternal's weak libstdc++ copy stays unrenamed under --preserve-export-list and the patcher no longer sees two exports with one NID.
  • libSceLibcInternal's oly3wSwEJ2A inventory entry now forwards to the libc constructor through LibcExceptionConstructSystemError_nid_no_patch, so callers get the object rather than a throw.
  • The tests cover the constructor directly in libc and through the libSceLibcInternal NID, including "invalid argument: Invalid argument", the empty-message "Invalid argument", the null-category throw, the stored code and the destructor.

The branch was rebased onto current main 4ab649f4d8; the earlier review correction (Dinkumware _Makestr, not libstdc++) is included.

Tested

Linux x86-64 (CachyOS, GCC 16.2.1), Release, BUILD_TESTING=ON, base main 105c9e4d91:

  • Built guest_ampr_cpp_error_tests and guest_libc_internal_exception_destructors_tests with the full library dependencies.
  • ctest --test-dir build -R '^(guest_ampr_cpp_error|guest_libc_internal_exception_destructors)$' --output-on-failure: 2/2 passed.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch pr-16004 --jobs 4: exit 2 only because it cannot confirm shared Api.hpp/debt files from conflicting PR heads; it reports no same exports.
  • Not run: Windows, a console or a title.

Checklist

  • Based on current main; no other open PR implements this NID
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: Fixes #15955
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5168677828 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16004). Originally posted by [fishingpvalues](https://github.com/fishingpvalues) on 2026-11-05T08:44:43Z. --- ### What `libSceLibcInternal` exported `oly3wSwEJ2A` (`_ZNSt12system_errorC2ESt10error_codePKc`) as a throwing stub, and the patcher failed with `duplicate patched export name: oly3wSwEJ2A` whenever libc stopped exporting libstdc++'s weak copy of that constructor (#15955). This implements the constructor and makes the NID call it: - libc constructs the 32-byte guest `std::system_error` from the 16-byte `error_code` and the `const char*` message. The `runtime_error` base follows Dinkumware `_Makestr`: it takes the message, appends `": "` only when that message is non-empty, then appends `error_code.message()` through the category's guest vtable; the code is stored at offset 16. A null category throws `std::invalid_argument` (the reference would dereference it), and an empty message yields `"Invalid argument"`. - libc exports the constructor under its own NID, so libSceLibcInternal's weak libstdc++ copy stays unrenamed under `--preserve-export-list` and the patcher no longer sees two exports with one NID. - libSceLibcInternal's `oly3wSwEJ2A` inventory entry now forwards to the libc constructor through `LibcExceptionConstructSystemError_nid_no_patch`, so callers get the object rather than a throw. - The tests cover the constructor directly in libc and through the libSceLibcInternal NID, including `"invalid argument: Invalid argument"`, the empty-message `"Invalid argument"`, the null-category throw, the stored code and the destructor. The branch was rebased onto current `main` `4ab649f4d8`; the earlier review correction (Dinkumware `_Makestr`, not libstdc++) is included. ### Tested Linux x86-64 (CachyOS, GCC 16.2.1), Release, `BUILD_TESTING=ON`, base `main` `105c9e4d91`: - Built `guest_ampr_cpp_error_tests` and `guest_libc_internal_exception_destructors_tests` with the full library dependencies. - `ctest --test-dir build -R '^(guest_ampr_cpp_error|guest_libc_internal_exception_destructors)$' --output-on-failure`: 2/2 passed. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch pr-16004 --jobs 4`: exit 2 only because it cannot confirm shared `Api.hpp`/debt files from conflicting PR heads; it reports no same exports. - Not run: Windows, a console or a title. ### Checklist - [x] Based on current `main`; no other open PR implements this NID - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`) - [x] No notes, investigation `.md` files or images added to the repository - [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: Fixes #15955 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!16004
No description provided.