Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-system-category
Oct 23, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
hypermoist:feat/libc-system-category

Conversation

@hypermoist

@hypermoist hypermoist commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

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 feat(libc): add the std::__sce_v2 exception types and throwers #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

…ffset 4

The console error_code and error_condition keep the value in the second
dword: the shared error_category::equivalent reads it at +4, the
default_error_condition overrides return it shifted into the high half,
and title code built against the SDK headers stores 0 at +0 and reads
value() at +4. The generic category returned and compared the value at
+0.

system_category returns a static _System_error_category named "system"
that shares the generic message table and maps a value with a message
to the generic category in default_error_condition. The equivalent
overloads are shared by both categories and go through the object's own
default_error_condition, as the console's base implementation does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 21, 2026
@github-actions

Copy link
Copy Markdown

Progress report (1381826 → 1860f90)

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

✅ 1 implemented
Library Name
libc _ZSt15system_categoryv_nid_postfix

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

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
PR 8658 core/libs/tests/GuestGenericCategory.cpp L56-59
PR 9416 core/libs/prx/libc/src/exception/StandardExceptions.cpp L132, L238-240, L242-243, L253, L262, L265-266, L512 _ZSt15system_categoryv

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 6044 core/libs/tests/GuestAmprCppError.cpp
core/libs/tests/GuestAmprThreads.cpp
core/libs/tests/GuestGenericCategory.cpp
PR 7201 core/libs/tests/GuestGenericCategory.cpp
PR 7648 core/libs/tests/GuestAmprCppError.cpp

@hypermoist

hypermoist commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Overlap notes for the reports above:

🤖 Generated with Claude Code

@hypermoist

Copy link
Copy Markdown
Contributor Author

Correction: I mislabelled the firmware. The decrypted modules I read are firmware 13.60, not 12.00 (each module's module-param segment records SDK 13.60). The behaviour described is unchanged; only the version label was wrong. I've updated the description.

Assisted With AI: Yes But all test done locally on actual hardware

@adriadam10 adriadam10 self-assigned this Oct 23, 2026
@adriadam10
adriadam10 merged commit 3635d65 into boykopovar:main Oct 23, 2026
20 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked every use of ErrorCode/SystemErrorObject in libc (copies, _Throw_Cpp_error) and the two Ampr tests that read the layout; the new guest_generic_category checks pin value << 32, the generic/system mapping and the throwing destructor, so they fail without the change. Conventions and relinker green; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants