feat(libc): throw std::filesystem::filesystem_error from _Xfilesystem_error as the console's libc does #11504

Merged
verusferro merged 1 commit from upstream-pr/11504 into main 2026-10-29 12:47:46 +00:00
verusferro commented 2026-10-26 17:34:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by verusferro on 2026-10-26T17:34:32Z.


What

Both std::filesystem::_Xfilesystem_error overloads that libSceLibcInternal exports, B0CeIhQty7Y (message, error_code) and C6-7Mo5WbwU (message, path, error_code), threw NotImplemented. The SDK's <filesystem> calls them when an operation fails, so a title stopped there instead of getting a std::filesystem::filesystem_error it can catch. They now throw that exception as the SDK 7.00 libc.prx that PPSA06416 ships in sce_module/ does (0x80270 and 0x80490), read from its disassembly (REVERSE_ENGINEERING, source 2):

  • The module allocates a 0x90-byte exception and builds its system_error part with Dinkumware's _Makestr (0x14300): the message, then ": " if the message is not empty, then the text from code.category().message(code.value()), called through the category's vtable.
  • The error code is at 0x30. path1 (0x40) is a copy of the path, or empty for the first overload, and path2 (0x68) is empty.
  • The vtable (0x10dcb8) uses runtime_error::what and system_error::_Doraise. The type info (0x10dc90) is named NSt10filesystem16filesystem_errorE, with std::system_error as its base. The module does not export it, so a title catches the exception through its own copy of the type info, which this library's catch matching compares by name.

The code is in libc, next to the other exception types, as srandomdev and the fenv functions of libSceLibcInternal are. The two stubs leave libSceLibcInternal, so both NIDs resolve to libc.

code(), path1() and path2() are inline in the SDK headers, so those offsets follow the module. Bytes 0x08 to 0x30 belong to runtime_error and are private. They hold this library's message pointer, as all of its runtime_errors do, so its exported runtime_error copy and what functions still work on the object. The module's own std::system_error is 0x40 bytes with the code at 0x30, while this library's std::system_error (from _Throw_Cpp_error) is 32 bytes with the code at 16. This PR leaves that alone; the new debt entry records it.

AllocateStringStorage moves out of LocaleSupport's anonymous namespace into GuestLocale, next to a new ReleaseStringStorage, which frees with the console's large-allocation rule. The path copies need both, and so does a guest category's message string. A null message, path or category throws std::invalid_argument, where the module dereferences it.

#10989 adds the versioned std::__sce_v2::filesystem::_Xfilesystem_error pair as throwing stubs. They could reuse ThrowFilesystemError if the versioned type has the same layout, which I have not checked. The two PRs merge without conflicts.

Tested

Ubuntu 24.04 (WSL2) x86-64, GCC 13.3, Release, full build with BUILD_TESTING=ON, on main 2227f13661:

  • New guest_filesystem_error test, which uses the guest catch frame of guest_sce_v2_exceptions:

    • catches the exception as std::system_error, and by name as filesystem_error;
    • checks what() with and without a message, and the code value and category at 0x30;
    • checks path1 copies of 5, 26 and 4,200 bytes (inline, heap and large allocation), and that path2 is empty;
    • uses a guest-defined category whose message is inline, on the heap, or over 5,000 bytes and freed with the large-allocation rule;
    • checks that a null message, path or category throws.

    Always adding ": " fails it.

  • ctest -R '^(guest_filesystem_error|guest_sce_v2_exceptions|guest_future_category|guest_locale|guest_libc_filesystem|patched_libraries|conventions_unknown_nids)$': 7/7 pass. guest_future_category covers #11241's std::future_error, which main added to StandardExceptions.cpp since this PR was opened.

  • The patched libc.prx exports B0CeIhQty7Y and C6-7Mo5WbwU, and the patched libSceLibcInternal.prx no longer does.

  • tools/progress.py: +2 implemented. libSceLibcInternal goes from 72/76 to 72/74 (94.74% to 97.30%), libc from 1419/1436 to 1421/1438.

  • python3 tools/check_conventions.py --base origin/main: passed. python3 tools/pr_overlap.py --branch feat/libc-xfilesystem-error: two conflicts and no same exports. #10749 adds its siginterrupt entry right after the libSceLibcInternal debt entry this PR removes; its author accepts either order. #11773 moves AssignCString, whose AllocateStringStorage call this PR qualifies with GuestLocale::; I asked to go first. Of the pull requests it could not compare, #9526 and #7081 change other parts of LocaleSupport.cpp.

Windows: ycbuzi ran guest_filesystem_error on the previous head 66140677ec with WinLibs GCC 15.2.0; it passed. Not tested: macOS, a title that throws filesystem_error, a console run.

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: #10749
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5021886555 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11504). Originally posted by [verusferro](https://github.com/verusferro) on 2026-10-26T17:34:32Z. --- ### What Both `std::filesystem::_Xfilesystem_error` overloads that libSceLibcInternal exports, `B0CeIhQty7Y` (message, `error_code`) and `C6-7Mo5WbwU` (message, `path`, `error_code`), threw `NotImplemented`. The SDK's `<filesystem>` calls them when an operation fails, so a title stopped there instead of getting a `std::filesystem::filesystem_error` it can catch. They now throw that exception as the SDK 7.00 `libc.prx` that PPSA06416 ships in `sce_module/` does (0x80270 and 0x80490), read from its disassembly ([REVERSE_ENGINEERING](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/REVERSE_ENGINEERING.md), source 2): - The module allocates a 0x90-byte exception and builds its `system_error` part with Dinkumware's `_Makestr` (0x14300): the message, then `": "` if the message is not empty, then the text from `code.category().message(code.value())`, called through the category's vtable. - The error code is at 0x30. `path1` (0x40) is a copy of the path, or empty for the first overload, and `path2` (0x68) is empty. - The vtable (0x10dcb8) uses `runtime_error::what` and `system_error::_Doraise`. The type info (0x10dc90) is named `NSt10filesystem16filesystem_errorE`, with `std::system_error` as its base. The module does not export it, so a title catches the exception through its own copy of the type info, which this library's catch matching compares by name. The code is in libc, next to the other exception types, as `srandomdev` and the `fenv` functions of libSceLibcInternal are. The two stubs leave libSceLibcInternal, so both NIDs resolve to libc. `code()`, `path1()` and `path2()` are inline in the SDK headers, so those offsets follow the module. Bytes 0x08 to 0x30 belong to `runtime_error` and are private. They hold this library's message pointer, as all of its `runtime_error`s do, so its exported `runtime_error` copy and `what` functions still work on the object. The module's own `std::system_error` is 0x40 bytes with the code at 0x30, while this library's `std::system_error` (from `_Throw_Cpp_error`) is 32 bytes with the code at 16. This PR leaves that alone; the new debt entry records it. `AllocateStringStorage` moves out of LocaleSupport's anonymous namespace into `GuestLocale`, next to a new `ReleaseStringStorage`, which frees with the console's large-allocation rule. The path copies need both, and so does a guest category's message string. A null message, path or category throws `std::invalid_argument`, where the module dereferences it. #10989 adds the versioned `std::__sce_v2::filesystem::_Xfilesystem_error` pair as throwing stubs. They could reuse `ThrowFilesystemError` if the versioned type has the same layout, which I have not checked. The two PRs merge without conflicts. ### 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. --> Ubuntu 24.04 (WSL2) x86-64, GCC 13.3, Release, full build with `BUILD_TESTING=ON`, on `main` `2227f13661`: - New `guest_filesystem_error` test, which uses the guest catch frame of `guest_sce_v2_exceptions`: - catches the exception as `std::system_error`, and by name as `filesystem_error`; - checks `what()` with and without a message, and the code value and category at 0x30; - checks `path1` copies of 5, 26 and 4,200 bytes (inline, heap and large allocation), and that `path2` is empty; - uses a guest-defined category whose message is inline, on the heap, or over 5,000 bytes and freed with the large-allocation rule; - checks that a null message, path or category throws. Always adding `": "` fails it. - `ctest -R '^(guest_filesystem_error|guest_sce_v2_exceptions|guest_future_category|guest_locale|guest_libc_filesystem|patched_libraries|conventions_unknown_nids)$'`: 7/7 pass. `guest_future_category` covers #11241's `std::future_error`, which `main` added to `StandardExceptions.cpp` since this PR was opened. - The patched `libc.prx` exports `B0CeIhQty7Y` and `C6-7Mo5WbwU`, and the patched `libSceLibcInternal.prx` no longer does. - `tools/progress.py`: +2 implemented. libSceLibcInternal goes from 72/76 to 72/74 (94.74% to 97.30%), libc from 1419/1436 to 1421/1438. - `python3 tools/check_conventions.py --base origin/main`: passed. `python3 tools/pr_overlap.py --branch feat/libc-xfilesystem-error`: two conflicts and no same exports. #10749 adds its `siginterrupt` entry right after the libSceLibcInternal debt entry this PR removes; its author [accepts either order](https://github.com/boykopovar/AnyPS5/pull/11504#issuecomment-6451403996). #11773 moves `AssignCString`, whose `AllocateStringStorage` call this PR qualifies with `GuestLocale::`; I [asked](https://github.com/boykopovar/AnyPS5/pull/11773#issuecomment-6468611320) to go first. Of the pull requests it could not compare, #9526 and #7081 change other parts of `LocaleSupport.cpp`. Windows: ycbuzi [ran `guest_filesystem_error`](https://github.com/boykopovar/AnyPS5/pull/11504#issuecomment-6451403996) on the previous head `66140677ec` with WinLibs GCC 15.2.0; it passed. Not tested: macOS, a title that throws `filesystem_error`, a console run. ### 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: #10749 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-26 17:50:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T17:50:32Z.

Review: CHANGES_REQUESTED


The implementation and focused test report are substantial, but this branch is based on 349055c1cd5742185a57eb71b3b2e4ab9b6d1cad and is 82 commits behind current main (88795ed448). CONTRIBUTING.md requires branches to stay up to date. Please rebase/sync and rerun the focused libc tests on the updated branch before merge. My changed-path comparison found only docs/dev/debt/libc.md overlapping intervening main changes; I found no specific defect in the implementation during this pass.

Local conventions and git show --check pass. The PR reports a full WSL2 build and its six focused tests passing. Current hosted register-context and ASan checks pass; product Linux/Windows jobs are skipped, and two macOS relinker jobs are still pending. Changes requested for branch freshness and updated validation, not for a demonstrated code defect.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5656548462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11504#pullrequestreview-5656548462). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T17:50:32Z. **Review:** CHANGES_REQUESTED --- The implementation and focused test report are substantial, but this branch is based on `349055c1cd5742185a57eb71b3b2e4ab9b6d1cad` and is 82 commits behind current `main` (`88795ed448`). `CONTRIBUTING.md` requires branches to stay up to date. Please rebase/sync and rerun the focused libc tests on the updated branch before merge. My changed-path comparison found only `docs/dev/debt/libc.md` overlapping intervening main changes; I found no specific defect in the implementation during this pass. Local conventions and `git show --check` pass. The PR reports a full WSL2 build and its six focused tests passing. Current hosted register-context and ASan checks pass; product Linux/Windows jobs are skipped, and two macOS relinker jobs are still pending. Changes requested for branch freshness and updated validation, not for a demonstrated code defect.
THEMANnt commented 2026-10-26 18:06:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T18:06:21Z.

Review: DISMISSED


REQUEST_CHANGES - CONTRIBUTING.md, "Branches and pull requests": keep the branch up to date with main.

Reviewed 268beae7d9db against 88795ed44801. The PR merge base is 349055c1cd57, leaving this branch 82 commits behind the pinned main base. The hosted Linux and Windows product jobs were skipped, so they did not build the change merged into current main.

Validation: MinGW GCC 15.3 Release built the affected libc and test; guest_filesystem_error and guest_sce_v2_exceptions passed (2/2). Added path/category cases below and at the 0x1000 allocation threshold passed; a >= to > negative control failed with "guest allocation is not registered."

Please sync/rebase to current main and rerun the focused libc tests on that head, then request re-review. The local build used PR-head files over cached sources, not a full checkout of the pinned merge base. I found no production-code defect in the reviewed patch.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5656753130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11504#pullrequestreview-5656753130). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T18:06:21Z. **Review:** DISMISSED --- REQUEST_CHANGES - CONTRIBUTING.md, "Branches and pull requests": keep the branch up to date with main. Reviewed `268beae7d9db` against `88795ed44801`. The PR merge base is `349055c1cd57`, leaving this branch 82 commits behind the pinned main base. The hosted Linux and Windows product jobs were skipped, so they did not build the change merged into current main. **Validation:** MinGW GCC 15.3 Release built the affected libc and test; `guest_filesystem_error` and `guest_sce_v2_exceptions` passed (2/2). Added path/category cases below and at the 0x1000 allocation threshold passed; a `>=` to `>` negative control failed with "guest allocation is not registered." Please sync/rebase to current main and rerun the focused libc tests on that head, then request re-review. The local build used PR-head files over cached sources, not a full checkout of the pinned merge base. I found no production-code defect in the reviewed patch.
MarcZX10 commented 2026-10-26 18:15:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T18:15:42Z.

Review: APPROVED


The branch is now current with main (88795ed448; 0 behind, 1 ahead), and the author reports the focused guest_filesystem_error, guest_sce_v2_exceptions, guest_locale, guest_libc_filesystem, patched_libraries and conventions_unknown_nids tests passing on the updated head. The implementation/test patch is unchanged by the sync. The six cases cover both exception layouts, message/path storage including large allocations, guest category messages, catches by system_error and type name, and null arguments. Local conventions and git show --check pass.

The PS5 behavior is backed by the shipped SDK module disassembly described in the PR; no title run or console result is claimed. Hosted product Linux/Windows jobs are skipped; register-context and ASan checks pass, while several macOS jobs remain pending. With the freshness and retest request addressed, I found no remaining blocker and approve.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5656886150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11504#pullrequestreview-5656886150). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T18:15:42Z. **Review:** APPROVED --- The branch is now current with `main` (`88795ed448`; 0 behind, 1 ahead), and the author reports the focused `guest_filesystem_error`, `guest_sce_v2_exceptions`, `guest_locale`, `guest_libc_filesystem`, `patched_libraries` and `conventions_unknown_nids` tests passing on the updated head. The implementation/test patch is unchanged by the sync. The six cases cover both exception layouts, message/path storage including large allocations, guest category messages, catches by `system_error` and type name, and null arguments. Local conventions and `git show --check` pass. The PS5 behavior is backed by the shipped SDK module disassembly described in the PR; no title run or console result is claimed. Hosted product Linux/Windows jobs are skipped; register-context and ASan checks pass, while several macOS jobs remain pending. With the freshness and retest request addressed, I found no remaining blocker and approve.
THEMANnt commented 2026-10-28 15:41:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-28T15:41:07Z.

Review: COMMENTED


Re-reviewed 778c4a74ec4c86e29c48bd3766745debe86a91f5. The earlier sync-and-retest request has been addressed. The filesystem-error implementation and its fixture are unchanged from my earlier review; the branch now uses base 2227f13661. The 14 subsequent commits on pinned main 750cf6cf48 touch none of this PR's changed files, and GitHub reports a clean merge. I found no new production-code defect in this pass.

Validation: Windows, GCC 15.3, Release, isolated pinned checkouts: 6/6 focused CTests passed on the head (filesystem-error, versioned exceptions, future-category, locale, libc-filesystem, and the conventions test suite); the baseline passed its five corresponding CTests and has no filesystem-error target. Additional path cases cover inline/heap transitions, the 0x1000 allocation boundary, empty paths and embedded NULs; guest-category message boundary cases also pass. An unconditional-separator negative control fails the empty-message assertion; restoring the original sources passes. The direct conventions check passes.

Using the freshly built NID patcher on copies of the two built libraries, objdump confirms both NIDs are exported by patched libc and absent from patched libSceLibcInternal.

The current-head hosted Build is still queued, so this is a COMMENT pending CI completion. These are focused Windows checks, not a full product build, a current-main merge execution, or a console/title run. The documented ABI limitations and declared merge ordering remain relevant.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5685430440 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11504#pullrequestreview-5685430440). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-28T15:41:07Z. **Review:** COMMENTED --- Re-reviewed `778c4a74ec4c86e29c48bd3766745debe86a91f5`. The earlier sync-and-retest request has been addressed. The filesystem-error implementation and its fixture are unchanged from my earlier review; the branch now uses base `2227f13661`. The 14 subsequent commits on pinned main `750cf6cf48` touch none of this PR's changed files, and GitHub reports a clean merge. I found no new production-code defect in this pass. **Validation:** Windows, GCC 15.3, Release, isolated pinned checkouts: 6/6 focused CTests passed on the head (filesystem-error, versioned exceptions, future-category, locale, libc-filesystem, and the conventions test suite); the baseline passed its five corresponding CTests and has no filesystem-error target. Additional path cases cover inline/heap transitions, the 0x1000 allocation boundary, empty paths and embedded NULs; guest-category message boundary cases also pass. An unconditional-separator negative control fails the empty-message assertion; restoring the original sources passes. The direct conventions check passes. Using the freshly built NID patcher on copies of the two built libraries, `objdump` confirms both NIDs are exported by patched libc and absent from patched libSceLibcInternal. The current-head [hosted Build](https://github.com/boykopovar/AnyPS5/actions/runs/40691393377) is still queued, so this is a **COMMENT** pending CI completion. These are focused Windows checks, not a full product build, a current-main merge execution, or a console/title run. The documented ABI limitations and declared merge ordering remain relevant.
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!11504
No description provided.