feat(libc): export the versioned std::__sce_v2 filesystem primitives #10989

Merged
edubox merged 7 commits from upstream-pr/10989 into main 2026-11-02 10:26:32 +00:00
edubox commented 2026-10-25 12:28:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-25T12:28:46Z.


What

The std::__sce_v2 filesystem primitives are missing from libc.prx. PPSA28416 imports all seven from it (_Stat Pr1S2l2SpPE, _Open_dir XQgLZdwqACM, _Read_dir YaXPSk7yIqY, _Close_dir 2voXFbF1zkU, _Current_get 3y6Rg-iaDY8, and the two _Xfilesystem_error overloads PA+HkSsicW8/MxYQlfxPQzY).

  • Move the directory primitives' shared implementation from libSceLibcInternal/Filesystem.cpp into libc/include/GuestFilesystemPrimitives.hpp; the unversioned exports keep their behaviour and guest_libc_filesystem still passes.
  • _Stat cannot use that shared helper: it calls stat_nid_postfix, which only libkernel.prx defines, and a libkernel import in libc.prx makes every host target that links only libc.prx fail to link (agc_shader_replay, agc_shader_replay_requests, host_libstdcxx_exception and the libc test executables). The versioned _Stat resolves the guest path and reads the type and permission bits with the host filesystem instead; guest_sce_v2_filesystem still cross-checks type, permission bits and errno against stat_nid_postfix.
  • Export the versioned five from libc/src/VersionedFilesystem.cpp. The console's libc.prx bundled with PPSA28416 shows the same semantics: _Stat (0xcb9b0, 0xd7 bytes) maps the type from st_mode and keeps the same four not-found errors, _Open_dir (0xcb640, 0xe9) and _Read_dir (0xcb730, 0x15b) filter dot entries and report file type 8, _Close_dir (0xcb890, 0x2b) closes the handle, and _Current_get (0xcb8c0, 8) writes "/" and returns true. The versioned _Current_get uses that measured value; the unversioned call still returns the current directory.
  • Export both _Xfilesystem_error overloads as NotImplemented_nid_no_patch, like the unversioned pair, so the imports resolve; std::__sce_v2::filesystem_error does not exist yet.
  • New guest_sce_v2_filesystem test (GuestSceV2Filesystem.cpp) covers stat types and permission bits, missing paths, empty and missing directories, entry enumeration, close, and the two-byte "/" write of _Current_get.

Tested

  • Linux (CachyOS, kernel 7.3.0-3-cachyos, GCC 16.2.1, Release): ctest --test-dir build -R 'guest_sce_v2_filesystem|guest_libc_filesystem' → 2/2 passed.
  • nid_patcher libc on the built unpatched/libc.prx exports all seven NIDs (Pr1S2l2SpPE, XQgLZdwqACM, YaXPSk7yIqY, 2voXFbF1zkU, 3y6Rg-iaDY8, PA+HkSsicW8, MxYQlfxPQzY).
  • Console evidence is the libc.prx bundled with PPSA28416 (disassembly; sizes and offsets above).
  • Not run on Windows or macOS, and not exercised by a title: PPSA28416 still stops in sceNpGetSandboxInfo and still imports the versioned locale exports, so these calls were not reached at runtime.
  • Full ninja (2992 targets) and ctest -j16 (2218 tests) on the rebased head: 2217 passed. The only failure is progress_history, which asserts the English git message and fails under a Spanish locale; it passes with LC_ALL=C.
  • python3 tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch feat/libc-sce-v2-filesystem --jobs 32: no PR exports the same NIDs or creates the same files; the only shared file is docs/dev/debt/libc.md (textual append).

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: PPSA28416 #3086 (partial: 7 of its 22 missing libc.prx exports; the 15 versioned locale exports remain)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004725830 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10989). Originally posted by [edubox](https://github.com/edubox) on 2026-10-25T12:28:46Z. --- ### What The `std::__sce_v2` filesystem primitives are missing from `libc.prx`. PPSA28416 imports all seven from it (`_Stat` `Pr1S2l2SpPE`, `_Open_dir` `XQgLZdwqACM`, `_Read_dir` `YaXPSk7yIqY`, `_Close_dir` `2voXFbF1zkU`, `_Current_get` `3y6Rg-iaDY8`, and the two `_Xfilesystem_error` overloads `PA+HkSsicW8`/`MxYQlfxPQzY`). - Move the directory primitives' shared implementation from `libSceLibcInternal/Filesystem.cpp` into `libc/include/GuestFilesystemPrimitives.hpp`; the unversioned exports keep their behaviour and `guest_libc_filesystem` still passes. - `_Stat` cannot use that shared helper: it calls `stat_nid_postfix`, which only `libkernel.prx` defines, and a `libkernel` import in `libc.prx` makes every host target that links only `libc.prx` fail to link (`agc_shader_replay`, `agc_shader_replay_requests`, `host_libstdcxx_exception` and the libc test executables). The versioned `_Stat` resolves the guest path and reads the type and permission bits with the host filesystem instead; `guest_sce_v2_filesystem` still cross-checks type, permission bits and `errno` against `stat_nid_postfix`. - Export the versioned five from `libc/src/VersionedFilesystem.cpp`. The console's `libc.prx` bundled with PPSA28416 shows the same semantics: `_Stat` (`0xcb9b0`, 0xd7 bytes) maps the type from `st_mode` and keeps the same four not-found errors, `_Open_dir` (`0xcb640`, 0xe9) and `_Read_dir` (`0xcb730`, 0x15b) filter dot entries and report file type 8, `_Close_dir` (`0xcb890`, 0x2b) closes the handle, and `_Current_get` (`0xcb8c0`, 8) writes "/" and returns true. The versioned `_Current_get` uses that measured value; the unversioned call still returns the current directory. - Export both `_Xfilesystem_error` overloads as `NotImplemented_nid_no_patch`, like the unversioned pair, so the imports resolve; `std::__sce_v2::filesystem_error` does not exist yet. - New `guest_sce_v2_filesystem` test (`GuestSceV2Filesystem.cpp`) covers stat types and permission bits, missing paths, empty and missing directories, entry enumeration, close, and the two-byte "/" write of `_Current_get`. ### Tested - Linux (CachyOS, kernel 7.3.0-3-cachyos, GCC 16.2.1, Release): `ctest --test-dir build -R 'guest_sce_v2_filesystem|guest_libc_filesystem'` → 2/2 passed. - `nid_patcher libc` on the built `unpatched/libc.prx` exports all seven NIDs (`Pr1S2l2SpPE`, `XQgLZdwqACM`, `YaXPSk7yIqY`, `2voXFbF1zkU`, `3y6Rg-iaDY8`, `PA+HkSsicW8`, `MxYQlfxPQzY`). - Console evidence is the `libc.prx` bundled with PPSA28416 (disassembly; sizes and offsets above). - Not run on Windows or macOS, and not exercised by a title: PPSA28416 still stops in `sceNpGetSandboxInfo` and still imports the versioned locale exports, so these calls were not reached at runtime. - Full `ninja` (2992 targets) and `ctest -j16` (2218 tests) on the rebased head: 2217 passed. The only failure is `progress_history`, which asserts the English git message and fails under a Spanish locale; it passes with `LC_ALL=C`. - `python3 tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch feat/libc-sce-v2-filesystem --jobs 32`: no PR exports the same NIDs or creates the same files; the only shared file is `docs/dev/debt/libc.md` (textual append). ### 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) - [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: PPSA28416 #3086 (partial: 7 of its 22 missing `libc.prx` exports; the 15 versioned locale exports remain) - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-25 12:35:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T12:35:54Z.

Review: CHANGES_REQUESTED


Requesting one blocking fix before merge: the new GuestFilesystem::StatType helper is compiled into the base libc by VersionedFilesystem.cpp, but it calls stat_nid_postfix, which is declared in prx/libkernel/include/Api.hpp and defined in libkernel/File/src/Stdio.cpp. The base libc target does not link libkernel; only the other PRX targets do (see core/libs/CMakeLists.txt). This leaves an unresolved kernel symbol in the Windows libc.prx link. The PR reports no Windows build, and the hosted Windows job here is only the relinker job, not the libc product build.

I confirmed the changed source files pass C++20 syntax checks, but a MinGW object compile of VersionedFilesystem.cpp leaves stat_nid_postfix undefined. MinGW also rejects a shared-library link with an unresolved symbol. Please keep the kernel-dependent stat operation in a target that already links libkernel, or provide a Windows link arrangement that resolves it without introducing a target cycle, and validate the Windows libc link/test before resubmitting.

My exact-head local checks were check_conventions.py, git diff --check, and syntax checks for both filesystem exports and the new test; those passed. They do not cover this link dependency.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643220682 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10989#pullrequestreview-5643220682). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T12:35:54Z. **Review:** CHANGES_REQUESTED --- Requesting one blocking fix before merge: the new `GuestFilesystem::StatType` helper is compiled into the base `libc` by `VersionedFilesystem.cpp`, but it calls `stat_nid_postfix`, which is declared in `prx/libkernel/include/Api.hpp` and defined in `libkernel/File/src/Stdio.cpp`. The base `libc` target does not link `libkernel`; only the other PRX targets do (see `core/libs/CMakeLists.txt`). This leaves an unresolved kernel symbol in the Windows `libc.prx` link. The PR reports no Windows build, and the hosted Windows job here is only the relinker job, not the libc product build. I confirmed the changed source files pass C++20 syntax checks, but a MinGW object compile of `VersionedFilesystem.cpp` leaves `stat_nid_postfix` undefined. MinGW also rejects a shared-library link with an unresolved symbol. Please keep the kernel-dependent stat operation in a target that already links `libkernel`, or provide a Windows link arrangement that resolves it without introducing a target cycle, and validate the Windows libc link/test before resubmitting. My exact-head local checks were `check_conventions.py`, `git diff --check`, and syntax checks for both filesystem exports and the new test; those passed. They do not cover this link dependency.
MarcZX10 commented 2026-10-25 13:54:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T13:54:50Z.

Review: DISMISSED


The head addresses my earlier stat_nid_postfix link concern: VersionedFilesystem.cpp now uses host filesystem status instead, and the compiled object has no undefined stat_nid_postfix reference.

One blocking semantic issue remains in the new StatType error branch. When std::filesystem::status sets failure, the code always returns TypeNotFound (lines 46–52). The existing GuestFilesystem::StatType contract returns TypeNotFound only for NoSuchFile, NotDirectory, Invalid and NameTooLong; other failures return TypeNone. Therefore errors such as permission denied or a symlink loop are currently reported as “not found” even though errno carries another error. Please use IsNotFound(code) to choose between TypeNotFound and TypeNone after mapping the failure, and add a regression for a non-not-found status error where the host platform permits a deterministic fixture. The successful-path type and permission checks and the missing-path checks do not exercise this case.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643540187 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10989#pullrequestreview-5643540187). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T13:54:50Z. **Review:** DISMISSED --- The head addresses my earlier `stat_nid_postfix` link concern: `VersionedFilesystem.cpp` now uses host filesystem status instead, and the compiled object has no undefined `stat_nid_postfix` reference. One blocking semantic issue remains in the new `StatType` error branch. When `std::filesystem::status` sets `failure`, the code always returns `TypeNotFound` (lines 46–52). The existing `GuestFilesystem::StatType` contract returns `TypeNotFound` only for `NoSuchFile`, `NotDirectory`, `Invalid` and `NameTooLong`; other failures return `TypeNone`. Therefore errors such as permission denied or a symlink loop are currently reported as “not found” even though `errno` carries another error. Please use `IsNotFound(code)` to choose between `TypeNotFound` and `TypeNone` after mapping the failure, and add a regression for a non-not-found `status` error where the host platform permits a deterministic fixture. The successful-path type and permission checks and the missing-path checks do not exercise this case.
MarcZX10 commented 2026-10-29 09:05:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:05:34Z.

Review: APPROVED


The exact current head fixes the previously reported StatType error-classification issue: failures are mapped through IsNotFound, and TestStatError covers a symlink loop as TypeNone with the original error and permissions preserved. The earlier stat-link concern is also addressed by resolving paths without a libkernel import, including app0.zar entries. The author reports the focused libc filesystem tests and full Linux Release suite passing apart from locale-sensitive progress_history (which passes with LC_ALL=C); conventions pass and the branch includes current main. I did not rerun those tests locally or test Windows/macOS or a title. No blocking issue remains in this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5695205480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10989#pullrequestreview-5695205480). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T09:05:34Z. **Review:** APPROVED --- The exact current head fixes the previously reported StatType error-classification issue: failures are mapped through IsNotFound, and TestStatError covers a symlink loop as TypeNone with the original error and permissions preserved. The earlier stat-link concern is also addressed by resolving paths without a libkernel import, including app0.zar entries. The author reports the focused libc filesystem tests and full Linux Release suite passing apart from locale-sensitive progress_history (which passes with LC_ALL=C); conventions pass and the branch includes current main. I did not rerun those tests locally or test Windows/macOS or a title. No blocking issue remains in this review.
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!10989
No description provided.