feat(libSceLibcInternal): implement the wide std::_Fiopen #23846

Merged
GiannisG1 merged 1 commit from upstream-pr/23846 into main 2026-11-19 20:42:28 +00:00
GiannisG1 commented 2026-11-19 19:08:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GiannisG1 on 2026-11-19T19:08:19Z.


What

std::_Fiopen(const wchar_t*, ios_base::openmode, int) (inventory 246, NID aqyjhIx7jaY) was a parameterless placeholder that threw. basic_filebuf<..>::open calls it for a wide file name, and so do basic_ifstream/basic_ofstream constructed from one.

It now follows Dinkumware V6.50's fiopen.cpp, the same mirror the library already cites:

  • convert the name with wcstombs into a FILENAME_MAX (1024-byte, FreeBSD) buffer;
  • return null when the conversion fails;
  • otherwise open the converted name through the narrow _Fiopen already in libc, so its mode table and its ate handling apply.

Where Dinkumware would pass a name that fills the buffer on unterminated, this throws. A null name throws too. The guest wcstombs encodes every 16-bit unit, so its failure path is kept but not reached.

The mangled name hashes to the inventory NID (tools/nid_names.py), so the export is named and the placeholder is gone. The new header is included by the library umbrella. The debt fragment removes the table row and adds a Functional entry: not verified on a console.

Tested

Linux Mint 22.3, GCC 13.3.0, Release, head on main e4cee4952b.

  • New test guest_libc_internal_wide_fiopen:
    • a wide name with a non-ASCII character (U+00E9) opens for binary output, takes a write, and creates the file named by its UTF-8 conversion;
    • the same wide name opens for input and reads the bytes back;
    • a mode the narrow _Fiopen refuses (in | trunc) returns null, and so does a missing file opened for input;
    • a 1024-character name and a null name throw std::invalid_argument.
  • main: the test does not link, because the export does not exist there (the NID reaches the throwing placeholder). This PR: passes 3/3.
  • Split suite (tools/suite.py) on this branch: GPU tests on a GTX 1050 Ti (NVIDIA 580.178.04), an HD 630 (Mesa 25.2.8 ANV) and llvmpipe 25.2.8, everything else once.
    • guest_libc_internal_wide_fiopen and public_headers pass.
    • The failures are those of the main baseline (HD 630 10, llvmpipe 3) plus agc_driver_pm4_order_signal on all three. That test checks for a median below 0.1 ms and does not load libSceLibcInternal. Interleaved with a main e4cee4952b build, 5 runs per GPU, both builds failed 7 of 15.
    • After the suite, the two refusals changed from NotImplemented_nid_no_patch to std::invalid_argument, since they are invalid arguments, not unimplemented paths, and tools/progress.py counts a reachable NotImplemented as a stub. On that tree, public_headers and its compile tests, every guest_libc_internal_* test and the conventions and checker tests (344) pass. progress.py --module libSceLibcInternal no longer lists the export as pending.
  • check_conventions.py, check_test_registration.py, check_main_sync.py (merges cleanly), check_compile.py and debt_fold.py --check are clean.
  • pr_overlap.py --branch: #17300 (rename-only) names the same alias. #13778, #14834, #17300, #18135 and #21704 could not be compared because they conflict with main. A trial merge with each adds no conflicting file beyond those it already has. It merges cleanly with #23809 and #23837.

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:5401231877 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23846). Originally posted by [GiannisG1](https://github.com/GiannisG1) on 2026-11-19T19:08:19Z. --- ### What `std::_Fiopen(const wchar_t*, ios_base::openmode, int)` (inventory 246, NID `aqyjhIx7jaY`) was a parameterless placeholder that threw. `basic_filebuf<..>::open` calls it for a wide file name, and so do `basic_ifstream`/`basic_ofstream` constructed from one. It now follows Dinkumware V6.50's [`fiopen.cpp`](https://github.com/bergsteiger/realwork/blob/19b446ce8ad2adf82ab8ce7988bc003221accad2/common/components/rtl/external/Embarcadero/DelphiBerlin/cpprtl/Source/dinkumware64/source/fiopen.cpp), the same mirror the library already cites: - convert the name with `wcstombs` into a `FILENAME_MAX` (1024-byte, FreeBSD) buffer; - return null when the conversion fails; - otherwise open the converted name through the narrow `_Fiopen` already in libc, so its mode table and its `ate` handling apply. Where Dinkumware would pass a name that fills the buffer on unterminated, this throws. A null name throws too. The guest `wcstombs` encodes every 16-bit unit, so its failure path is kept but not reached. The mangled name hashes to the inventory NID (`tools/nid_names.py`), so the export is named and the placeholder is gone. The new header is included by the library umbrella. The debt fragment removes the table row and adds a Functional entry: not verified on a console. ### Tested Linux Mint 22.3, GCC 13.3.0, Release, head on `main` `e4cee4952b`. - New test `guest_libc_internal_wide_fiopen`: - a wide name with a non-ASCII character (U+00E9) opens for binary output, takes a write, and creates the file named by its UTF-8 conversion; - the same wide name opens for input and reads the bytes back; - a mode the narrow `_Fiopen` refuses (`in | trunc`) returns null, and so does a missing file opened for input; - a 1024-character name and a null name throw `std::invalid_argument`. - `main`: the test does not link, because the export does not exist there (the NID reaches the throwing placeholder). This PR: passes 3/3. - Split suite (`tools/suite.py`) on this branch: GPU tests on a GTX 1050 Ti (NVIDIA 580.178.04), an HD 630 (Mesa 25.2.8 ANV) and llvmpipe 25.2.8, everything else once. - `guest_libc_internal_wide_fiopen` and `public_headers` pass. - The failures are those of the `main` baseline (HD 630 10, llvmpipe 3) plus `agc_driver_pm4_order_signal` on all three. That test checks for a median below 0.1 ms and does not load libSceLibcInternal. Interleaved with a `main` `e4cee4952b` build, 5 runs per GPU, both builds failed 7 of 15. - After the suite, the two refusals changed from `NotImplemented_nid_no_patch` to `std::invalid_argument`, since they are invalid arguments, not unimplemented paths, and `tools/progress.py` counts a reachable `NotImplemented` as a stub. On that tree, `public_headers` and its compile tests, every `guest_libc_internal_*` test and the conventions and checker tests (344) pass. `progress.py --module libSceLibcInternal` no longer lists the export as pending. - `check_conventions.py`, `check_test_registration.py`, `check_main_sync.py` (merges cleanly), `check_compile.py` and `debt_fold.py --check` are clean. - `pr_overlap.py --branch`: #17300 (rename-only) names the same alias. #13778, #14834, #17300, #18135 and #21704 could not be compared because they conflict with `main`. A trial merge with each adds no conflicting file beyond those it already has. It merges cleanly with #23809 and #23837. ### 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)
PrivacyOnion commented 2026-11-19 19:30:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T19:30:04Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 1c23feaf49:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_internal_wide_fiopen_tests built cleanly.
  • CTest (guest_libc_internal_wide_fiopen):
    1/1 Test #4436: guest_libc_internal_wide_fiopen ...   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceLibcInternal/InventoryExports.cpp, core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp, core/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp, core/libs/prx/libSceLibcInternal/Fiopen.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified libSceLibcInternal/Fiopen.cpp: filename null check properly throws std::invalid_argument before dereferencing
    • Verified wcstombs_nid_postfix conversion with 1024-byte buffer (FILENAME_MAX), checking error return static_caststd::size_t(-1) returning nullptr
    • Verified buffer truncation check (length >= sizeof(name)) correctly throws std::invalid_argument instead of passing unterminated buffer
    • Verified call forwards valid converted narrow path and mode/protection to narrow _Fiopen export _ZSt7_FiopenPKcNSt5_IosbIiE9_OpenmodeEi_nid_postfix
    • Verified header declarations, NID removal from InventoryExports.cpp/hpp, technical debt fragment, and CMake test configuration
    • Verified test coverage in GuestLibcInternalWideFiopen.cpp for non-ASCII path, read/write, invalid mode, missing file, null name, and buffer overflow edge cases

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5981903191 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23846#pullrequestreview-5981903191). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T19:30:04Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `1c23feaf49`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_internal_wide_fiopen_tests` built cleanly. - **CTest** (`guest_libc_internal_wide_fiopen`): ``` 1/1 Test #4436: guest_libc_internal_wide_fiopen ... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceLibcInternal/InventoryExports.cpp`, `core/libs/prx/libSceLibcInternal/include/InventoryExports.hpp`, `core/libs/prx/libSceLibcInternal/libSceLibcInternal.hpp`, `core/libs/prx/libSceLibcInternal/Fiopen.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified libSceLibcInternal/Fiopen.cpp: filename null check properly throws std::invalid_argument before dereferencing - Verified wcstombs_nid_postfix conversion with 1024-byte buffer (FILENAME_MAX), checking error return static_cast<std::size_t>(-1) returning nullptr - Verified buffer truncation check (length >= sizeof(name)) correctly throws std::invalid_argument instead of passing unterminated buffer - Verified call forwards valid converted narrow path and mode/protection to narrow _Fiopen export _ZSt7_FiopenPKcNSt5_IosbIiE9_OpenmodeEi_nid_postfix - Verified header declarations, NID removal from InventoryExports.cpp/hpp, technical debt fragment, and CMake test configuration - Verified test coverage in GuestLibcInternalWideFiopen.cpp for non-ASCII path, read/write, invalid mode, missing file, null name, and buffer overflow edge cases 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!23846
No description provided.