feat(libc): export the std::__sce_v2 filesystem calls #15210

Merged
Danigamer05 merged 1 commit from upstream-pr/15210 into main 2026-11-03 08:12:18 +00:00
Danigamer05 commented 2026-11-02 20:46:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-02T20:46:11Z.


What

Export the sixteen std::__sce_v2::filesystem calls that are still missing from libc, next to the _Stat, directory and _Current_get primitives already there:

Export NID Original RVA
_ZNSt8__sce_v210filesystem6_LstatEPKcPNS0_5permsEPi LXwQTUlXqkY 0xCBA90
_ZNSt8__sce_v210filesystem6_LstatEPKcPNS0_5permsE kaQWSDpGvYk 0xCC140
_ZNSt8__sce_v210filesystem10_File_sizeEPKcPi 9hFiV-SYaBg 0xCBB70
_ZNSt8__sce_v210filesystem10_File_sizeEPKc Er2vLEXb274 0xCC1F0
_ZNSt8__sce_v210filesystem16_Last_write_timeEPKc 9uld+FKJiM8 0xCC240
_ZNSt8__sce_v210filesystem16_Last_write_timeEPKcPlS3_ orU+cOLgqH0 0xCBBE0
_ZNSt8__sce_v210filesystem20_Set_last_write_timeEPKcl O1TzFSNuL+8 0xCBC60
_ZNSt8__sce_v210filesystem9_Make_dirEPKcS2_ H7pVgeH6+0Y 0xCB900
_ZNSt8__sce_v210filesystem11_Remove_dirEPKc z2t8wjOcyl8 0xCB9A0
_ZNSt8__sce_v210filesystem7_UnlinkEPKc JyYWGwYKbfc 0xCBDD0
_ZNSt8__sce_v210filesystem7_RenameEPKcS2_ 1rbp++nl5s4 0xCBD70
_ZNSt8__sce_v210filesystem7_ResizeEPKcm S0HHbMy6i9o 0xCBDA0
_ZNSt8__sce_v210filesystem6_ChmodEPKcNS0_5permsE nwYv13CyIIs 0xCC060
_ZNSt8__sce_v210filesystem10_Copy_fileEPKcS2_ ZG4QXp4iMRk 0xCBE00
_ZNSt8__sce_v210filesystem8_StatvfsEPKcRNS0_10space_infoE bqk0d4F9WME 0xCBD50
_ZNSt8__sce_v210filesystem13_Current_set2EPKc 3W0yl-6AWxk 0xCB8D0

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).

Most of these functions are thin wrappers over libkernel. They call sceKernelStat, sceKernelMkdir, sceKernelUnlink, sceKernelRename, sceKernelTruncate, sceKernelChmod, sceKernelUtimes, sceKernelOpen, sceKernelRead, sceKernelWrite, sceKernelFstat, sceKernelFchmod, sceKernelClose, stat and rmdir. A kernel error in the errno range (0x8002xxxx) gives its errno, and any other kernel error gives 1. Some cases do not follow that pattern:

  • _File_size with an error output stores the kernel error code itself, such as 0x80020002.
  • _Lstat reports ENOENT, ENOTDIR, EINVAL and ENAMETOOLONG as not found and other errors as none.
  • _Make_dir returns 1, 0 for EEXIST, or the negated errno, and takes the mode of an existing template.
  • _Set_last_write_time takes microseconds, floors them to seconds and microseconds and keeps the access time.
  • _Copy_file copies 64 KiB at a time, then copies the source permissions masked with 06777.
  • _Statvfs returns ENOSYS with unknown space.
  • _Current_set2 returns 0 only for "/" and EOPNOTSUPP (45) otherwise.

libc cannot link libkernel; libkernel already links libc. So FilesystemForwards.hpp adds a table of those kernel calls that libkernel registers when it loads, as it already does for its thread calls. VersionedFilesystemCalls.cpp makes the calls through that table in the module's order. The 64 KiB copy buffer is a host allocation instead of the module's heap; ENOMEM is still returned when it cannot be allocated.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main 9090972b7e91fd266819cbd77a8b058e177b5682. Exact tested commit: 0f12fc9b7ef02af58412f84c73923befc37be536.

  • Built libc, libkernel, their NID-patched production libraries and the filesystem tests. All 69 selected CTests pass, among them the new guest_sce_v2_filesystem_calls, guest_sce_v2_filesystem, guest_filesystem_error, guest_rename_dot and public_headers.
  • The new test runs every export on files in a fresh directory: regular, read-only and 200,000-byte files, directories with and without entries, missing paths, a file used as a directory, an empty path and a 300-character name. The expected codes, outputs and resulting files were taken from the original module, not from this implementation.
  • The original functions were loaded from the bundled module with its relocations applied. Their kernel imports were bound by NID to this branch's libkernel, __error to its libc and __stack_chk_guard to a local value; every other import would have stopped the run, and none was called. The module's heap is not initialized outside a title, so the two entries of its allocation table that _Copy_file uses were pointed at the host malloc and free.
  • The originals then ran against the patched production libraries in 2,016 scenarios over 24 paths: every export on each path, renames and copies between each pair, ten write times and seven permission values. Each scenario started from the same fresh directory. Return values, outputs, errno and the resulting tree all agree: every entry's kernel stat result, mode, size, write time and content hash.
  • The rule that maps a kernel error outside the errno range to 1 could not be exercised: this libkernel only returns errors in that range.
  • Negative control: three lines were altered one at a time. The not-found set lost ENAMETOOLONG, a remainder of −1 µs was no longer floored, and _Current_set2 compared one character. The new CTest failed on each. With the three alterations applied together, plus one to the unreachable mapping rule, the side-by-side run flagged 21 scenarios across _Lstat, _Set_last_write_time and _Current_set2. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and all 69 tests and all 2,016 scenarios passed again.
  • Code conventions and git diff --check pass.
  • tools/pr_overlap.py read 1,699 open PRs at the tested commit and reports no confirmed overlap. It keeps exit 2 for 42 branches that already conflict with main. 229 open PRs touch at least one of the four shared files: the two CMakeLists.txt lists, libc's Api.hpp and docs/dev/debt/libc.md. None of them adds the sixteen names or NIDs. Merging each with this branch and with main using git merge-tree gives the same conflict blocks, and no block contains this change. The exception is #14212, which reformats the whole libc debt file and conflicts with any new entry there.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5127161209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15210). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-02T20:46:11Z. --- ### What Export the sixteen `std::__sce_v2::filesystem` calls that are still missing from libc, next to the `_Stat`, directory and `_Current_get` primitives already there: | Export | NID | Original RVA | | --- | --- | --- | | `_ZNSt8__sce_v210filesystem6_LstatEPKcPNS0_5permsEPi` | `LXwQTUlXqkY` | `0xCBA90` | | `_ZNSt8__sce_v210filesystem6_LstatEPKcPNS0_5permsE` | `kaQWSDpGvYk` | `0xCC140` | | `_ZNSt8__sce_v210filesystem10_File_sizeEPKcPi` | `9hFiV-SYaBg` | `0xCBB70` | | `_ZNSt8__sce_v210filesystem10_File_sizeEPKc` | `Er2vLEXb274` | `0xCC1F0` | | `_ZNSt8__sce_v210filesystem16_Last_write_timeEPKc` | `9uld+FKJiM8` | `0xCC240` | | `_ZNSt8__sce_v210filesystem16_Last_write_timeEPKcPlS3_` | `orU+cOLgqH0` | `0xCBBE0` | | `_ZNSt8__sce_v210filesystem20_Set_last_write_timeEPKcl` | `O1TzFSNuL+8` | `0xCBC60` | | `_ZNSt8__sce_v210filesystem9_Make_dirEPKcS2_` | `H7pVgeH6+0Y` | `0xCB900` | | `_ZNSt8__sce_v210filesystem11_Remove_dirEPKc` | `z2t8wjOcyl8` | `0xCB9A0` | | `_ZNSt8__sce_v210filesystem7_UnlinkEPKc` | `JyYWGwYKbfc` | `0xCBDD0` | | `_ZNSt8__sce_v210filesystem7_RenameEPKcS2_` | `1rbp++nl5s4` | `0xCBD70` | | `_ZNSt8__sce_v210filesystem7_ResizeEPKcm` | `S0HHbMy6i9o` | `0xCBDA0` | | `_ZNSt8__sce_v210filesystem6_ChmodEPKcNS0_5permsE` | `nwYv13CyIIs` | `0xCC060` | | `_ZNSt8__sce_v210filesystem10_Copy_fileEPKcS2_` | `ZG4QXp4iMRk` | `0xCBE00` | | `_ZNSt8__sce_v210filesystem8_StatvfsEPKcRNS0_10space_infoE` | `bqk0d4F9WME` | `0xCBD50` | | `_ZNSt8__sce_v210filesystem13_Current_set2EPKc` | `3W0yl-6AWxk` | `0xCB8D0` | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). Most of these functions are thin wrappers over libkernel. They call `sceKernelStat`, `sceKernelMkdir`, `sceKernelUnlink`, `sceKernelRename`, `sceKernelTruncate`, `sceKernelChmod`, `sceKernelUtimes`, `sceKernelOpen`, `sceKernelRead`, `sceKernelWrite`, `sceKernelFstat`, `sceKernelFchmod`, `sceKernelClose`, `stat` and `rmdir`. A kernel error in the errno range (`0x8002xxxx`) gives its errno, and any other kernel error gives 1. Some cases do not follow that pattern: - `_File_size` with an error output stores the kernel error code itself, such as `0x80020002`. - `_Lstat` reports `ENOENT`, `ENOTDIR`, `EINVAL` and `ENAMETOOLONG` as not found and other errors as none. - `_Make_dir` returns 1, 0 for `EEXIST`, or the negated errno, and takes the mode of an existing template. - `_Set_last_write_time` takes microseconds, floors them to seconds and microseconds and keeps the access time. - `_Copy_file` copies 64 KiB at a time, then copies the source permissions masked with `06777`. - `_Statvfs` returns `ENOSYS` with unknown space. - `_Current_set2` returns 0 only for "/" and `EOPNOTSUPP` (45) otherwise. libc cannot link libkernel; libkernel already links libc. So `FilesystemForwards.hpp` adds a table of those kernel calls that libkernel registers when it loads, as it already does for its thread calls. `VersionedFilesystemCalls.cpp` makes the calls through that table in the module's order. The 64 KiB copy buffer is a host allocation instead of the module's heap; `ENOMEM` is still returned when it cannot be allocated. ### 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 x86-64, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, main `9090972b7e91fd266819cbd77a8b058e177b5682`. Exact tested commit: `0f12fc9b7ef02af58412f84c73923befc37be536`. - Built libc, libkernel, their NID-patched production libraries and the filesystem tests. All 69 selected CTests pass, among them the new `guest_sce_v2_filesystem_calls`, `guest_sce_v2_filesystem`, `guest_filesystem_error`, `guest_rename_dot` and `public_headers`. - The new test runs every export on files in a fresh directory: regular, read-only and 200,000-byte files, directories with and without entries, missing paths, a file used as a directory, an empty path and a 300-character name. The expected codes, outputs and resulting files were taken from the original module, not from this implementation. - The original functions were loaded from the bundled module with its relocations applied. Their kernel imports were bound by NID to this branch's libkernel, `__error` to its libc and `__stack_chk_guard` to a local value; every other import would have stopped the run, and none was called. The module's heap is not initialized outside a title, so the two entries of its allocation table that `_Copy_file` uses were pointed at the host `malloc` and `free`. - The originals then ran against the patched production libraries in 2,016 scenarios over 24 paths: every export on each path, renames and copies between each pair, ten write times and seven permission values. Each scenario started from the same fresh directory. Return values, outputs, `errno` and the resulting tree all agree: every entry's kernel `stat` result, mode, size, write time and content hash. - The rule that maps a kernel error outside the errno range to 1 could not be exercised: this libkernel only returns errors in that range. - Negative control: three lines were altered one at a time. The not-found set lost `ENAMETOOLONG`, a remainder of −1 µs was no longer floored, and `_Current_set2` compared one character. The new CTest failed on each. With the three alterations applied together, plus one to the unreachable mapping rule, the side-by-side run flagged 21 scenarios across `_Lstat`, `_Set_last_write_time` and `_Current_set2`. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and all 69 tests and all 2,016 scenarios passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,699 open PRs at the tested commit and reports no confirmed overlap. It keeps exit 2 for 42 branches that already conflict with main. 229 open PRs touch at least one of the four shared files: the two `CMakeLists.txt` lists, libc's `Api.hpp` and `docs/dev/debt/libc.md`. None of them adds the sixteen names or NIDs. Merging each with this branch and with main using `git merge-tree` gives the same conflict blocks, and no block contains this change. The exception is #14212, which reformats the whole libc debt file and conflicts with any new entry there. Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded. ### 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: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 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!15210
No description provided.