feat(libc): implement generic error category messages #5102

Merged
Dripl1x merged 1 commit from upstream-pr/5102 into main 2026-10-13 13:08:30 +00:00
Dripl1x commented 2026-10-13 11:41:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-13T11:41:49Z.


What

Calling message() on the generic category stored in a guest std::system_error currently throws std::_Generic_error_category::message not implemented. Return an owned guest string instead, and export the related runtime entry points:

  • std::_Syserror_map(int) — PDX01ziUz+4
  • std::generic_category() — YxwfcCH5Q0I
  • std::_Generic_error_category::message(int) const — KZ++filsCL4

The map covers the 72 distinct Dinkumware errc values present in FreeBSD 11.4's errno header. Unmapped values return null from _Syserror_map and produce unknown error from the category. Lookup follows the first matching entry: FreeBSD aliases EAGAIN/EWOULDBLOCK select operation would block, and ENOTSUP/EOPNOTSUPP select not supported. Use the same lookup for the suffix of _Throw_Cpp_error's message; its EAGAIN case previously assumed both parts were identical.

Messages use the existing GuestLocale::String model and the registered guest allocator. The accessor returns the same category object stored by _Throw_Cpp_error. Enable the existing assembly exception fixture on Linux as well as MinGW.

Semantics are based on VC12 system_error, its syserror.cpp, Microsoft STL's table, and FreeBSD 11.4 errno.h.

Tested

Windows, WinLibs MinGW-w64 GCC 15.2.0 r7, Release; WSL2 Ubuntu 26.04, GCC, Release. A focused CMake harness builds the complete libc, libkernel and libSceAmpr targets from this branch.

On the final commit, all six selected CTests pass on both hosts: guest_generic_category, guest_ampr_cpp_error, guest_errors, guest_collate, guest_new_handler, guest_new_handler_default_heap.

The new test checks direct and virtual message calls, the 15-character inline boundary, allocated strings, independent ownership, surrounding sentinels, errno preservation, unknown/extreme values and null-result rejection. The existing exception fixture checks the category attached to the actual guest exception. With the previous StandardExceptions.cpp restored through a separate baseline build source, the updated Windows fixture fails with std::_Generic_error_category::message not implemented; restoring the change passes.

An independent comparison of the source tables and FreeBSD errno assignments matches all 72 map entries. Patching the built Windows libc succeeds, and the PE export table contains all three NIDs above. Conventions and whitespace checks pass.

No console or title run, full top-level graphics build, or performance claim. The 40-byte string model and virtual return ABI are not validated against a console library; this is recorded in TechnicalDebt. A title's inline category in a bundled libc may still have a different object identity. STREAMS errno assignments absent from the FreeBSD header are not invented.

The locally available public DOOM libc was inspected for these symbols, but they point to a shared zero-return stub; it is not used as a semantic or ABI oracle.

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
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4842669400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5102). Originally posted by [Dripl1x](https://github.com/Dripl1x) on 2026-10-13T11:41:49Z. --- ### What Calling `message()` on the generic category stored in a guest `std::system_error` currently throws `std::_Generic_error_category::message not implemented`. Return an owned guest string instead, and export the related runtime entry points: - `std::_Syserror_map(int)` — `PDX01ziUz+4` - `std::generic_category()` — `YxwfcCH5Q0I` - `std::_Generic_error_category::message(int) const` — `KZ++filsCL4` The map covers the 72 distinct Dinkumware errc values present in FreeBSD 11.4's errno header. Unmapped values return null from `_Syserror_map` and produce `unknown error` from the category. Lookup follows the first matching entry: FreeBSD aliases EAGAIN/EWOULDBLOCK select `operation would block`, and ENOTSUP/EOPNOTSUPP select `not supported`. Use the same lookup for the suffix of `_Throw_Cpp_error`'s message; its EAGAIN case previously assumed both parts were identical. Messages use the existing GuestLocale::String model and the registered guest allocator. The accessor returns the same category object stored by `_Throw_Cpp_error`. Enable the existing assembly exception fixture on Linux as well as MinGW. Semantics are based on [VC12 system_error](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/system_error), its [syserror.cpp](https://github.com/ganboing/crt.vc12/blob/f1d47126bf13d1c9dccaa6c53b72217fd0474968/src/syserror.cpp), [Microsoft STL's table](https://github.com/microsoft/STL/blob/da52dc0fcadbd83690cfd1ed32408d2847439493/stl/src/syserror.cpp), and [FreeBSD 11.4 errno.h](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/sys/errno.h). ### Tested Windows, WinLibs MinGW-w64 GCC 15.2.0 r7, Release; WSL2 Ubuntu 26.04, GCC, Release. A focused CMake harness builds the complete libc, libkernel and libSceAmpr targets from this branch. On the final commit, all six selected CTests pass on both hosts: `guest_generic_category`, `guest_ampr_cpp_error`, `guest_errors`, `guest_collate`, `guest_new_handler`, `guest_new_handler_default_heap`. The new test checks direct and virtual message calls, the 15-character inline boundary, allocated strings, independent ownership, surrounding sentinels, errno preservation, unknown/extreme values and null-result rejection. The existing exception fixture checks the category attached to the actual guest exception. With the previous StandardExceptions.cpp restored through a separate baseline build source, the updated Windows fixture fails with `std::_Generic_error_category::message not implemented`; restoring the change passes. An independent comparison of the source tables and FreeBSD errno assignments matches all 72 map entries. Patching the built Windows libc succeeds, and the PE export table contains all three NIDs above. Conventions and whitespace checks pass. No console or title run, full top-level graphics build, or performance claim. The 40-byte string model and virtual return ABI are not validated against a console library; this is recorded in TechnicalDebt. A title's inline category in a bundled libc may still have a different object identity. STREAMS errno assignments absent from the FreeBSD header are not invented. The locally available public DOOM libc was inspected for these symbols, but they point to a shared zero-return stub; it is not used as a semantic or ABI oracle. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code: none - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 11:46:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:46:45Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4164 docs/dev/debt/libc.md L65
#4546 docs/dev/debt/libc.md L65
#4958 docs/dev/debt/libc.md L64-65
#5087 docs/dev/debt/libc.md L65
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144829401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5102#issuecomment-6144829401). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T11:46:45Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4164 | `docs/dev/debt/libc.md` [L65](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/docs/dev/debt/libc.md#L65) | | | | #4546 | `docs/dev/debt/libc.md` [L65](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/docs/dev/debt/libc.md#L65) | | | | #4958 | `docs/dev/debt/libc.md` [L64-65](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/docs/dev/debt/libc.md#L64-L65) | | | | #5087 | `docs/dev/debt/libc.md` [L65](https://github.com/boykopovar/AnyPS5/blob/0f2683cb7daf0d92a2b38c8ed2a00e03e12380a0/docs/dev/debt/libc.md#L65) | | |
github-actions[bot] commented 2026-10-13 11:47:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T11:47:39Z.


Progress report (2f969f1 → e3cef33)

📈 System libraries: 87.85% (+0.01%, +3 implemented functions)

✅ 3 implemented
Library Name
libc _ZNKSt23_Generic_error_category7messageEi_nid_postfix
libc _ZSt13_Syserror_mapi_nid_postfix
libc _ZSt16generic_categoryv_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144844395 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5102#issuecomment-6144844395). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T11:47:39Z. --- <!-- progress-report --> ### Progress report (2f969f1 → e3cef33) 📈 **System libraries**: 87.85% (+0.01%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libc | `_ZNKSt23_Generic_error_category7messageEi_nid_postfix` | | libc | `_ZSt13_Syserror_mapi_nid_postfix` | | libc | `_ZSt16generic_categoryv_nid_postfix` | </details>
adriadam10 commented 2026-10-13 13:03:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:03:19Z.


Checked the message table against VC12 syserror.cpp and FreeBSD 11.4 errno.h (72 entries, first-match aliases for EAGAIN and ENOTSUP), built libc/libkernel/libSceAmpr merged onto main, and ran the scoped ctest (97 tests, all pass, including guest_generic_category and guest_ampr_cpp_error); the new tests need the new exports. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146174178 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5102#issuecomment-6146174178). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T13:03:19Z. --- Checked the message table against VC12 `syserror.cpp` and FreeBSD 11.4 `errno.h` (72 entries, first-match aliases for EAGAIN and ENOTSUP), built libc/libkernel/libSceAmpr merged onto main, and ran the scoped ctest (97 tests, all pass, including `guest_generic_category` and `guest_ampr_cpp_error`); the new tests need the new exports. Merging once the full Build is green.
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!5102
No description provided.