feat(libc): add std::system_category and keep error_code values at offset 4 #9014

Merged
hypermoist merged 1 commit from upstream-pr/9014 into main 2026-10-23 22:59:59 +00:00
hypermoist commented 2026-10-21 09:48:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-21T09:48:46Z.


What

Adds std::system_category() (aotaAaQK6yc) and moves the error_code/error_condition value to byte offset 4, where the console keeps it.

PPSA29340's eboot imports system_category. So do the SDK modules shipped with PPSA08427. In PPSA29340 the call comes from its std::filesystem code: it builds an error_code by writing 0 to +0 and the category to +8, reads value() at +4, and compares the category pointer with system_category() (around eboot 0xaa7a5a–0xaa7b2f).

Behaviour from the decrypted PS5 13.60 libSceLibcInternal:

Console Here
error_code layout error_category::equivalent(const error_code&, int) (0x1b760) compares the value at +4 and the category at +8. Both default_error_condition overrides (0x1b710, 0x1bba0) return the value shifted into the high half of the first qword. system_error stores the code as those two qwords ErrorCode is {reserved, value, category}; the condition overrides return {0, value, category}
system_category() (0x1b6e0) Returns a static _System_error_category Same, with a vtable next to the generic one
name (0x1bb00) "system" Same
message (0x1bb10) The same table lookup and "unknown error" fallback as the generic message (0x1b900) Shares the generic message function
default_error_condition (0x1bba0) A value with a table entry maps to the generic category; others stay in the system category Same, using _Syserror_map's table
equivalent(int, const error_condition&) (0x1b730) Base implementation shared by both categories. Calls the object's own default_error_condition and compares the result Shared by both vtables and goes through slot 4. The generic one previously compared directly, which gives the same answer for the generic category only
typeinfo St22_System_error_category, deriving from St14error_category Same

The deleting destructor throws, as the generic one already does on main. The code is written from the observed behaviour; nothing from the module is copied.

Not changed here:

  • The console table numbers ENOTRECOVERABLE and EOWNERDEAD as 107 and 108, where main uses 95 and 96. It also has 1040, 1050, 1051 and 1074, which main lacks. I'll send that as a separate PR.
  • __sce_v2::system_error was not assessed. It is built differently (libc++-style). My #8901 still writes the old two-field ErrorCode, so whichever of the two lands second gets adjusted.
  • iostream_category still returns the host library's object.

Tested

Linux (CachyOS, GCC, Release). guest_generic_category now also checks:

  • the system category's typeinfo and name;
  • the raw condition qword is value << 32;
  • errno 2 maps to the generic category, and 44 (no message) stays in the system category;
  • the shared equivalent overloads go through the system mapping;
  • messages match the generic ones;
  • the deleting destructor throws.

The generic condition is also checked for the reserved dword and for equivalent. GuestAmprCppError.cpp and GuestAmprThreads.cpp read system_error::code through their own copies of the layout, and both copies now match it.

The 552 tests matching guest_|libc|ampr|exception all pass. Each negative control fails the test:

  • value back at +0 ("line 94", the generic condition's reserved dword);
  • the system condition never mapping to generic ("line 67");
  • equivalent comparing against the object itself instead of its condition ("line 71").

tools/check_conventions.py is clean. No open PR exports system_category under its name or NID. Three-way merges with the open PRs touching these files: #6044, #7201, #8658 and #8901 each gain one or two conflicting hunks in StandardExceptions.cpp; the others merge cleanly.

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 (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: PPSA29340 and PPSA08427 import system_category; neither was run with this change
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4949631944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9014). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-21T09:48:46Z. --- ### What Adds `std::system_category()` (`aotaAaQK6yc`) and moves the `error_code`/`error_condition` value to byte offset 4, where the console keeps it. PPSA29340's eboot imports `system_category`. So do the SDK modules shipped with PPSA08427. In PPSA29340 the call comes from its `std::filesystem` code: it builds an `error_code` by writing 0 to +0 and the category to +8, reads `value()` at +4, and compares the category pointer with `system_category()` (around eboot `0xaa7a5a`–`0xaa7b2f`). Behaviour from the decrypted PS5 13.60 `libSceLibcInternal`: | | Console | Here | |---|---|---| | `error_code` layout | `error_category::equivalent(const error_code&, int)` (0x1b760) compares the value at +4 and the category at +8. Both `default_error_condition` overrides (0x1b710, 0x1bba0) return the value shifted into the high half of the first qword. `system_error` stores the code as those two qwords | `ErrorCode` is `{reserved, value, category}`; the condition overrides return `{0, value, category}` | | `system_category()` (0x1b6e0) | Returns a static `_System_error_category` | Same, with a vtable next to the generic one | | `name` (0x1bb00) | `"system"` | Same | | `message` (0x1bb10) | The same table lookup and `"unknown error"` fallback as the generic `message` (0x1b900) | Shares the generic message function | | `default_error_condition` (0x1bba0) | A value with a table entry maps to the generic category; others stay in the system category | Same, using `_Syserror_map`'s table | | `equivalent(int, const error_condition&)` (0x1b730) | Base implementation shared by both categories. Calls the object's own `default_error_condition` and compares the result | Shared by both vtables and goes through slot 4. The generic one previously compared directly, which gives the same answer for the generic category only | | typeinfo | `St22_System_error_category`, deriving from `St14error_category` | Same | The deleting destructor throws, as the generic one already does on `main`. The code is written from the observed behaviour; nothing from the module is copied. Not changed here: - The console table numbers ENOTRECOVERABLE and EOWNERDEAD as 107 and 108, where `main` uses 95 and 96. It also has 1040, 1050, 1051 and 1074, which `main` lacks. I'll send that as a separate PR. - `__sce_v2::system_error` was not assessed. It is built differently (libc++-style). My #8901 still writes the old two-field `ErrorCode`, so whichever of the two lands second gets adjusted. - `iostream_category` still returns the host library's object. ### Tested Linux (CachyOS, GCC, Release). `guest_generic_category` now also checks: - the system category's typeinfo and `name`; - the raw condition qword is `value << 32`; - errno 2 maps to the generic category, and 44 (no message) stays in the system category; - the shared `equivalent` overloads go through the system mapping; - messages match the generic ones; - the deleting destructor throws. The generic condition is also checked for the reserved dword and for `equivalent`. `GuestAmprCppError.cpp` and `GuestAmprThreads.cpp` read `system_error::code` through their own copies of the layout, and both copies now match it. The 552 tests matching `guest_|libc|ampr|exception` all pass. Each negative control fails the test: - value back at +0 ("line 94", the generic condition's reserved dword); - the system condition never mapping to generic ("line 67"); - `equivalent` comparing against the object itself instead of its condition ("line 71"). `tools/check_conventions.py` is clean. No open PR exports `system_category` under its name or NID. Three-way merges with the open PRs touching these files: #6044, #7201, #8658 and #8901 each gain one or two conflicting hunks in `StandardExceptions.cpp`; the others merge cleanly. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.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: PPSA29340 and PPSA08427 import `system_category`; neither was run with this change - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
github-actions[bot] commented 2026-10-21 09:49:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T09:49:29Z.


Progress report (1381826 → 1860f90)

📈 System libraries: 50.98% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc _ZSt15system_categoryv_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313051396 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9014#issuecomment-6313051396). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T09:49:29Z. --- <!-- progress-report --> ### Progress report (1381826 → 1860f90) 📈 **System libraries**: 50.98% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `_ZSt15system_categoryv_nid_postfix` | </details>
hypermoist commented 2026-10-22 12:52:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T12:52:22Z.


Overlap notes for the reports above:

  • #9416 also adds _ZSt15system_categoryv and rewrites the same ErrorCode lines, but it keeps the value at both +0 and +4. I've proposed on #9416 that this PR goes first (it was opened earlier and its layout comes from the 12.00 firmware) and that #9416 then drops its system category and depends on this one.
  • #8658 only adds const_casts to the vtable reads at lines 56-59 of GuestGenericCategory.cpp, which this PR also edits. Whichever is merged second keeps both: the new checks from here and the casts from there.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341215283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9014#issuecomment-6341215283). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-22T12:52:22Z. --- Overlap notes for the reports above: - **#9416** also adds `_ZSt15system_categoryv` and rewrites the same `ErrorCode` lines, but it keeps the value at both +0 and +4. I've proposed on #9416 that this PR goes first (it was opened earlier and its layout comes from the 12.00 firmware) and that #9416 then drops its system category and depends on this one. - **#8658** only adds `const_cast`s to the `vtable` reads at lines 56-59 of `GuestGenericCategory.cpp`, which this PR also edits. Whichever is merged second keeps both: the new checks from here and the casts from there. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!9014
No description provided.