feat(libSceLibcInternal): forward _new_setup and the two-path _Xfilesystem_error to libc #24573

Merged
PostMalloy merged 1 commit from upstream-pr/24573 into main 2026-11-22 01:22:55 +00:00
PostMalloy commented 2026-11-20 20:03:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PostMalloy on 2026-11-20T20:03:13Z.


What

libSceLibcInternal exported two NIDs as throwing stubs although libc already implements both:

Export NID libSceLibcInternal stub libc implementation
_new_setup KNNNbyRieqQ libSceLibcInternalInventory_275 (InventoryExports.cpp) RuntimeSupport.cpp, from the libc.prx of PPSA01341
_ZNSt10filesystem18_Xfilesystem_errorEPKcRKNS_4pathES4_St10error_code Wut42WAe7Rw sceLibcInternalPending4_123 (Export.cpp) StandardExceptions.cpp, from the libc.prx of PPSA06416

A title importing either NID from libSceLibcInternal reached the stub. The libc debt entry for std::filesystem::_Xfilesystem_error already describes it as a libSceLibcInternal export implemented in libc.

  • libc keeps the two bodies in CrtNewSetup_nid_no_patch and FilesystemErrorTwoPaths_nid_no_patch, and its own exports call them, so their behaviour is unchanged.
  • The libSceLibcInternal stubs take the libc prototypes and call the same helpers. Calling the _nid_no_patch helpers instead of the libc exports keeps the forwards from binding to themselves after NID patching, as 6c5bee0 did for the other libSceLibcInternal forwards. _new_setup therefore records its CRT table in libc's slots whichever module the title imports it from.
  • The debt fragment removes the Wut42WAe7Rw "import resolution only" entry and adds one for the two forwards. It says that neither libSceLibcInternal.sprx body was read, so whether it differs from the libc.prx one is not known.

I found these by matching every throwing stub's NID against the implemented exports of the other libraries. Of the 2308 open pull requests, 25 change one of the touched source files. By their GitHub file patches, none changes either export: #17300 and #18135, both already conflicting with main, and #19486 show them only as diff context. gh search prs finds no open PR mentioning _new_setup or _Xfilesystem_error other than #17300.

Tested

Windows 11 x64 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0, Release.

  • guest_libc_internal_libc_forwards, new CheckNewSetup and CheckFilesystemErrorTwoPaths, through the libSceLibcInternal exports:
    • _new_setup accepts a null table, refuses a table shorter than 0x50 bytes, accepts a table without slots and refuses a partly filled slot group, as libc's rule does.
    • _Xfilesystem_error with two short guest paths throws a guest exception that a std::system_error handler catches, with type name NSt10filesystem16filesystem_errorE.
    • A null second path throws std::invalid_argument.
  • As a negative control, making the _new_setup forward return 0 and the _Xfilesystem_error forward throw std::invalid_argument without reaching libc makes the test fail: both _new_setup refusal checks fail, and the guest catch of the filesystem error aborts the process.
  • All 84 tests matching guest_libc_internal, guest_crt_setup, guest_filesystem_error and guest_sce_v2_exceptions pass after rebuilding them on current main with this commit.
  • tools/check_conventions.py --base origin/main and tools/debt_fold.py --check pass.
  • tools/nid_names.py gives KNNNbyRieqQ for _new_setup and Wut42WAe7Rw for the _Xfilesystem_error name, the NIDs the stubs exported.

No title was found calling either export through libSceLibcInternal, and no PS5 hardware was used.

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: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5419505034 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24573). Originally posted by [PostMalloy](https://github.com/PostMalloy) on 2026-11-20T20:03:13Z. --- ### What `libSceLibcInternal` exported two NIDs as throwing stubs although `libc` already implements both: | Export | NID | `libSceLibcInternal` stub | `libc` implementation | | --- | --- | --- | --- | | `_new_setup` | `KNNNbyRieqQ` | `libSceLibcInternalInventory_275` (`InventoryExports.cpp`) | `RuntimeSupport.cpp`, from the `libc.prx` of PPSA01341 | | `_ZNSt10filesystem18_Xfilesystem_errorEPKcRKNS_4pathES4_St10error_code` | `Wut42WAe7Rw` | `sceLibcInternalPending4_123` (`Export.cpp`) | `StandardExceptions.cpp`, from the `libc.prx` of PPSA06416 | A title importing either NID from `libSceLibcInternal` reached the stub. The `libc` debt entry for `std::filesystem::_Xfilesystem_error` already describes it as a `libSceLibcInternal` export implemented in `libc`. - `libc` keeps the two bodies in `CrtNewSetup_nid_no_patch` and `FilesystemErrorTwoPaths_nid_no_patch`, and its own exports call them, so their behaviour is unchanged. - The `libSceLibcInternal` stubs take the `libc` prototypes and call the same helpers. Calling the `_nid_no_patch` helpers instead of the `libc` exports keeps the forwards from binding to themselves after NID patching, as 6c5bee0 did for the other `libSceLibcInternal` forwards. `_new_setup` therefore records its CRT table in `libc`'s slots whichever module the title imports it from. - The debt fragment removes the `Wut42WAe7Rw` "import resolution only" entry and adds one for the two forwards. It says that neither `libSceLibcInternal.sprx` body was read, so whether it differs from the `libc.prx` one is not known. I found these by matching every throwing stub's NID against the implemented exports of the other libraries. Of the 2308 open pull requests, 25 change one of the touched source files. By their GitHub file patches, none changes either export: #17300 and #18135, both already conflicting with `main`, and #19486 show them only as diff context. `gh search prs` finds no open PR mentioning `_new_setup` or `_Xfilesystem_error` other than #17300. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 x64 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0, Release. - `guest_libc_internal_libc_forwards`, new `CheckNewSetup` and `CheckFilesystemErrorTwoPaths`, through the `libSceLibcInternal` exports: - `_new_setup` accepts a null table, refuses a table shorter than 0x50 bytes, accepts a table without slots and refuses a partly filled slot group, as `libc`'s rule does. - `_Xfilesystem_error` with two short guest paths throws a guest exception that a `std::system_error` handler catches, with type name `NSt10filesystem16filesystem_errorE`. - A null second path throws `std::invalid_argument`. - As a negative control, making the `_new_setup` forward return 0 and the `_Xfilesystem_error` forward throw `std::invalid_argument` without reaching `libc` makes the test fail: both `_new_setup` refusal checks fail, and the guest catch of the filesystem error aborts the process. - All 84 tests matching `guest_libc_internal`, `guest_crt_setup`, `guest_filesystem_error` and `guest_sce_v2_exceptions` pass after rebuilding them on current `main` with this commit. - `tools/check_conventions.py --base origin/main` and `tools/debt_fold.py --check` pass. - `tools/nid_names.py` gives `KNNNbyRieqQ` for `_new_setup` and `Wut42WAe7Rw` for the `_Xfilesystem_error` name, the NIDs the stubs exported. No title was found calling either export through `libSceLibcInternal`, and no PS5 hardware was used. ### 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: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-20 20:24:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:24:12Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected implementation and tests support merging.

What I ran

Reviewed head 53ecbfe76529811a75209276e4ec56954ffae75c using repo_read.py to inspect the prepared diff, all changed files, and targeted declarations and callers. No commands or tests were run here. The Windows, GCC, test, convention, and debt-check results in the description are author-reported.

Results

Check Result Note
Changed source review passed All eight changed files read
Tests and checks here not run No local execution performed
Author-reported checks passed Reported in the PR description

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run during this review; author-reported test results were not independently verified. No PS5 hardware behavior or title imports were verified. All files marked reviewed in the manifest were read; files.json was not available through the reader, and no excluded repository files were identified in the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5998866167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24573#pullrequestreview-5998866167). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T20:24:12Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected implementation and tests support merging. ## What I ran Reviewed head `53ecbfe76529811a75209276e4ec56954ffae75c` using `repo_read.py` to inspect the prepared diff, all changed files, and targeted declarations and callers. No commands or tests were run here. The Windows, GCC, test, convention, and debt-check results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed source review | passed | All eight changed files read | | Tests and checks here | not run | No local execution performed | | Author-reported checks | passed | Reported in the PR description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run during this review; author-reported test results were not independently verified. No PS5 hardware behavior or title imports were verified. All files marked `reviewed` in the manifest were read; `files.json` was not available through the reader, and no excluded repository files were identified in the manifest. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-21 00:47:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T00:47:05Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 53ecbfe765:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_libc_forwards_tests built cleanly.
  • CTest (guest_libc_internal_libc_forwards):
    1/1 Test #4441: guest_libc_internal_libc_forwards ...   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/Export.cpp, core/libs/prx/libSceLibcInternal/InventoryExports.cpp, core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/RuntimeSupport.cpp, core/libs/prx/libc/src/exception/StandardExceptions.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4441: guest_libc_internal_libc_forwards ...Subprocess aborted***Exception:   0.37 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified libSceLibcInternal Export.cpp: sceLibcInternalPending4_123_nid_no_patch forwards arguments to FilesystemErrorTwoPaths_nid_no_patch without modification or ABI mismatch
    • Verified libc StandardExceptions.cpp: FilesystemErrorTwoPaths_nid_no_patch validates both path1 and path2 for nullptr and throws std::invalid_argument, matching libc standard exception behavior
    • Verified InventoryExports.cpp & Api.hpp: libSceLibcInternalInventory_275_nid_no_patch forwards table parameter to CrtNewSetup_nid_no_patch without regression or recursion
    • Verified debt fragment docs/dev/debt/changes/feat-libcinternal-forward-libc-twins.md: properly formatted, removes Wut42WAe7Rw and documents forwarding to libc counterparts
    • Verified GuestLibcInternalLibcForwards.cpp test cases: CheckNewSetup exercises null, truncated, valid, and partial table configurations, and CheckFilesystemErrorTwoPaths verifies both paths exception throwing and null path rejection

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6001442861 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24573#pullrequestreview-6001442861). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T00:47:05Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `53ecbfe765`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_internal_libc_forwards_tests` built cleanly. - **CTest** (`guest_libc_internal_libc_forwards`): ``` 1/1 Test #4441: guest_libc_internal_libc_forwards ... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/Export.cpp`, `core/libs/prx/libSceLibcInternal/InventoryExports.cpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/src/RuntimeSupport.cpp`, `core/libs/prx/libc/src/exception/StandardExceptions.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4441: guest_libc_internal_libc_forwards ...Subprocess aborted***Exception: 0.37 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified libSceLibcInternal Export.cpp: sceLibcInternalPending4_123_nid_no_patch forwards arguments to FilesystemErrorTwoPaths_nid_no_patch without modification or ABI mismatch - Verified libc StandardExceptions.cpp: FilesystemErrorTwoPaths_nid_no_patch validates both path1 and path2 for nullptr and throws std::invalid_argument, matching libc standard exception behavior - Verified InventoryExports.cpp & Api.hpp: libSceLibcInternalInventory_275_nid_no_patch forwards table parameter to CrtNewSetup_nid_no_patch without regression or recursion - Verified debt fragment docs/dev/debt/changes/feat-libcinternal-forward-libc-twins.md: properly formatted, removes Wut42WAe7Rw and documents forwarding to libc counterparts - Verified GuestLibcInternalLibcForwards.cpp test cases: CheckNewSetup exercises null, truncated, valid, and partial table configurations, and CheckFilesystemErrorTwoPaths verifies both paths exception throwing and null path rejection Looks Good To Me
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!24573
No description provided.