feat(libc): add std::__sce_v2::_Random_device, _Fiopen and setw #9526

Closed
AlxcBTW wants to merge 4 commits from upstream-pr/9526 into main
AlxcBTW commented 2026-10-22 00:14:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-22T00:14:23Z.


What

Adds three std::__sce_v2 exports next to their unversioned counterparts, each written from the console's libc.prx disassembly (a title's copy, read only):

Export (NID) File Behaviour
std::__sce_v2::_Random_device() (MQ8-UG0KYnQ) RuntimeSupport.cpp same body as _ZSt14_Random_devicev (Nmtr628eA3A): both call one routine, so it returns the unversioned call's value
std::__sce_v2::_Fiopen(const char*, int, int) (lEeJadNvMbo) FileAndHeap.cpp not the unversioned body: the open-mode bits are the standard Dinkumware ones (binary 0x20, no-create 0x40, no-replace 0x80) and the unversioned _Fiopen here uses 0x80, 0x20 and 0x40 for them. A mode with any other bit set, or outside the console's table of twenty combinations, returns null; no-create reads as in, app as `out
std::__sce_v2::setw(long long) (I0vuMo7qix8) LocaleSupport.cpp returns the two-register manipulator (function pointer, 64-bit width); the function stores the width as 8 bytes at offset 0x28 of the stream, where the unversioned manipulator stores 4 bytes at 0x20. A width above INT_MAX is kept whole

The disassembly for _Fiopen was decoded to its mode table (jump table and string table, with relocations applied) and checked against the implementation for every mode below 0x10000 and for -1: the same string, or null, in all of them.

Not in this PR:

  • std::__sce_v2::_Xregex_error(regex_constants::error_type) (luv6hxzFAhY) is left out. The console's body throws a std::__sce_v2::regex_error (0x18 bytes, message chosen from a table of fifteen texts by the error code, its own typeinfo and destructor), not the unversioned std::regex_error (0x38 bytes) that _ZSt13_Xregex_error throws. That type belongs to the versioned exception hierarchy of #8901, which does not define regex_error, so a thrower written now would throw the wrong type. A debt entry says so; it can follow #8901 as its own PR.
  • The four _Stolx, _Stoulx, _Stollx and _Stoullx v2 forwards wait for #8384.

Known differences, in docs/dev/debt/libc.md: this libc exports no versioned ios_base, so the v2 setw manipulator only suits streams built by a title's own libc.prx, and a null stream throws where the console faults.

Titles that import these: Minecraft Dungeons II (PPSA16064) imports all four of the listed functions, including the one left out.

Tested

  • Linux (Ubuntu 24.04, Mesa lavapipe), fork CI at 469c4f2b5 (the PR head 1da5b7cd5 plus the CI scaffolding commit; run 39690062746, the test filter guest_locale|guest_fiopen|guest_crt): 3 of 3 passed. Not run on Windows, and not run on a console or with a title.
  • guest_locale (GuestLocale.cpp, CheckStreamWidthV2): setw with 12, with INT_MAX + 5, with 0x123456789abcdef0, with -1 and with 0 through the returned function on a guarded 64-byte buffer: the 8 bytes at offset 0x28 hold the value each time and no other byte changes; a null stream throws; the unversioned manipulator still writes the 4 bytes at 0x20 of an ios_base.
  • guest_fiopen (GuestFiopen.cpp): thirteen modes with no table entry (0, ate, trunc, binary alone, no-replace alone, in|trunc, in|no-replace, bits above 0xff, -1) return null and create nothing; read modes and no-create modes on a missing file return null; the file modes are exercised by writing and reading back a temp file (all but a+b, rb-with-ate and a few duplicates of the same string) (out|binary creates, app and in|app append, in|ate and no-create|ate end at offset 6, out|no-create and in|out overwrite from the start, trunc truncates, no-replace creates a missing file and returns null for an existing one); the 0x20 and 0x40 bits mean binary and no-create here, not what they mean in the unversioned call.
  • guest_crt (GuestCrt.cpp): _Random_device returns values that are not all equal in 64 calls.
  • python3 tools/check_conventions.py --base origin/main passes.
  • tools/pr_overlap.py --branch lists no PR with the same exports; textual overlaps only: docs/dev/debt/libc.md line 136 (#6565, #8872, #8880, #9001, #9133, #9170, #9447) and core/libs/tests/GuestFiopen.cpp lines 154-155 (#8658). Neighbours: #8901 (the versioned exceptions that _Xregex_error waits for) and #9416 (its _ZSt4setwi_nid_postfix is the unversioned call).

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 (PPSA16064 imports these; no Game bring-up discussion yet)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4960096643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9526). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-22T00:14:23Z. --- ### What Adds three `std::__sce_v2` exports next to their unversioned counterparts, each written from the console's `libc.prx` disassembly (a title's copy, read only): | Export (NID) | File | Behaviour | |---|---|---| | `std::__sce_v2::_Random_device()` (`MQ8-UG0KYnQ`) | `RuntimeSupport.cpp` | same body as `_ZSt14_Random_devicev` (`Nmtr628eA3A`): both call one routine, so it returns the unversioned call's value | | `std::__sce_v2::_Fiopen(const char*, int, int)` (`lEeJadNvMbo`) | `FileAndHeap.cpp` | not the unversioned body: the open-mode bits are the standard Dinkumware ones (binary 0x20, no-create 0x40, no-replace 0x80) and the unversioned `_Fiopen` here uses 0x80, 0x20 and 0x40 for them. A mode with any other bit set, or outside the console's table of twenty combinations, returns null; no-create reads as `in`, `app` as `out|app`, and `ate` seeks to the end (closing and returning null if the seek fails), as the unversioned call does. The protection argument is ignored | | `std::__sce_v2::setw(long long)` (`I0vuMo7qix8`) | `LocaleSupport.cpp` | returns the two-register manipulator (function pointer, 64-bit width); the function stores the width as 8 bytes at offset 0x28 of the stream, where the unversioned manipulator stores 4 bytes at 0x20. A width above `INT_MAX` is kept whole | The disassembly for `_Fiopen` was decoded to its mode table (jump table and string table, with relocations applied) and checked against the implementation for every mode below 0x10000 and for -1: the same string, or null, in all of them. Not in this PR: - `std::__sce_v2::_Xregex_error(regex_constants::error_type)` (`luv6hxzFAhY`) is left out. The console's body throws a `std::__sce_v2::regex_error` (0x18 bytes, message chosen from a table of fifteen texts by the error code, its own typeinfo and destructor), not the unversioned `std::regex_error` (0x38 bytes) that `_ZSt13_Xregex_error` throws. That type belongs to the versioned exception hierarchy of #8901, which does not define `regex_error`, so a thrower written now would throw the wrong type. A debt entry says so; it can follow #8901 as its own PR. - The four `_Stolx`, `_Stoulx`, `_Stollx` and `_Stoullx` v2 forwards wait for #8384. Known differences, in `docs/dev/debt/libc.md`: this libc exports no versioned `ios_base`, so the v2 `setw` manipulator only suits streams built by a title's own `libc.prx`, and a null stream throws where the console faults. Titles that import these: Minecraft Dungeons II (PPSA16064) imports all four of the listed functions, including the one left out. ### Tested - Linux (Ubuntu 24.04, Mesa lavapipe), fork CI at 469c4f2b5 (the PR head 1da5b7cd5 plus the CI scaffolding commit; run 39690062746, the test filter `guest_locale|guest_fiopen|guest_crt`): 3 of 3 passed. Not run on Windows, and not run on a console or with a title. - `guest_locale` (`GuestLocale.cpp`, `CheckStreamWidthV2`): `setw` with 12, with `INT_MAX + 5`, with `0x123456789abcdef0`, with -1 and with 0 through the returned function on a guarded 64-byte buffer: the 8 bytes at offset 0x28 hold the value each time and no other byte changes; a null stream throws; the unversioned manipulator still writes the 4 bytes at 0x20 of an `ios_base`. - `guest_fiopen` (`GuestFiopen.cpp`): thirteen modes with no table entry (0, `ate`, `trunc`, binary alone, no-replace alone, `in|trunc`, `in|no-replace`, bits above 0xff, -1) return null and create nothing; read modes and no-create modes on a missing file return null; the file modes are exercised by writing and reading back a temp file (all but `a+b`, `rb`-with-`ate` and a few duplicates of the same string) (`out|binary` creates, `app` and `in|app` append, `in|ate` and `no-create|ate` end at offset 6, `out|no-create` and `in|out` overwrite from the start, `trunc` truncates, `no-replace` creates a missing file and returns null for an existing one); the 0x20 and 0x40 bits mean binary and no-create here, not what they mean in the unversioned call. - `guest_crt` (`GuestCrt.cpp`): `_Random_device` returns values that are not all equal in 64 calls. - `python3 tools/check_conventions.py --base origin/main` passes. - `tools/pr_overlap.py --branch` lists no PR with the same exports; textual overlaps only: `docs/dev/debt/libc.md` line 136 (#6565, #8872, #8880, #9001, #9133, #9170, #9447) and `core/libs/tests/GuestFiopen.cpp` lines 154-155 (#8658). Neighbours: #8901 (the versioned exceptions that `_Xregex_error` waits for) and #9416 (its `_ZSt4setwi_nid_postfix` is the unversioned call). ### 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 (PPSA16064 imports these; no Game bring-up discussion yet) - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-22 00:15:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-22T00:15:14Z.


Progress report (a6dcea9 → 1da5b7c)

📈 System libraries: 42.35% (+0.02%, +4 implemented functions)

✅ 4 implemented
Library Name
libc SetStreamWidthV2
libc _ZNSt8__sce_v214_Random_deviceEv_nid_postfix
libc _ZNSt8__sce_v24setwEx_nid_postfix
libc _ZNSt8__sce_v27_FiopenEPKcii_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329488155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9526#issuecomment-6329488155). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-22T00:15:14Z. --- <!-- progress-report --> ### Progress report (a6dcea9 → 1da5b7c) 📈 **System libraries**: 42.35% (+0.02%, +4 implemented functions) <details> <summary>✅ 4 implemented</summary> | Library | Name | | - | - | | libc | `SetStreamWidthV2` | | libc | `_ZNSt8__sce_v214_Random_deviceEv_nid_postfix` | | libc | `_ZNSt8__sce_v24setwEx_nid_postfix` | | libc | `_ZNSt8__sce_v27_FiopenEPKcii_nid_postfix` | </details>
MarcZX10 commented 2026-10-22 00:30:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T00:30:05Z.

Review: CHANGES_REQUESTED


The three added mangled exports independently recompute to the PR's NIDs (lEeJadNvMbo, I0vuMo7qix8, MQ8-UG0KYnQ). The reported mode-table comparison, focused tests, and CI provide useful evidence; I found no additional implementation defect in this pass. These results are author-reported where specified; I did not run a local build or tests. Current eligibility, conventions, intake, labels, report, relinker matrix/ASan, register-context and write-watch checks pass; product Linux/Windows jobs were skipped.

There is a concrete shared-file conflict with #9527: a direct three-way merge conflicts in docs/dev/debt/libc.md. The overlap scan for #9527 also lists this PR. Please choose the landing order, record the agreed prerequisite in the second PR's Depends on line, and rebase/resolve the debt entries before merge. The current Depends on: none does not reflect that conflict.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607865637 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9526#pullrequestreview-5607865637). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T00:30:05Z. **Review:** CHANGES_REQUESTED --- The three added mangled exports independently recompute to the PR's NIDs (`lEeJadNvMbo`, `I0vuMo7qix8`, `MQ8-UG0KYnQ`). The reported mode-table comparison, focused tests, and CI provide useful evidence; I found no additional implementation defect in this pass. These results are author-reported where specified; I did not run a local build or tests. Current eligibility, conventions, intake, labels, report, relinker matrix/ASan, register-context and write-watch checks pass; product Linux/Windows jobs were skipped. There is a concrete shared-file conflict with #9527: a direct three-way merge conflicts in `docs/dev/debt/libc.md`. The overlap scan for #9527 also lists this PR. Please choose the landing order, record the agreed prerequisite in the second PR's `Depends on` line, and rebase/resolve the debt entries before merge. The current `Depends on: none` does not reflect that conflict.
MarcZX10 commented 2026-10-22 11:39:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:39:43Z.


A fresh pairwise merge check found two current debt-file ordering conflicts: #9527 (also your PR) and #9669 both add entries at the same insertion point in docs/dev/debt/libc.md; git merge-tree --write-tree reports content conflicts with each. The #9527 pair also has a cleanly auto-merged FileAndHeap.cpp hunk. Please coordinate the order across these three PRs, set Depends on on each branch that must follow another, and make sure all debt entries survive the final rebases. I also confirmed this head is 4 ahead / 119 behind current main, while its individual merge with main is clean.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6339834033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9526#issuecomment-6339834033). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T11:39:43Z. --- A fresh pairwise merge check found two current debt-file ordering conflicts: #9527 (also your PR) and #9669 both add entries at the same insertion point in `docs/dev/debt/libc.md`; `git merge-tree --write-tree` reports content conflicts with each. The #9527 pair also has a cleanly auto-merged `FileAndHeap.cpp` hunk. Please coordinate the order across these three PRs, set `Depends on` on each branch that must follow another, and make sure all debt entries survive the final rebases. I also confirmed this head is 4 ahead / 119 behind current `main`, while its individual merge with `main` is clean.

Pull request closed

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!9526
No description provided.