Skip to content

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

Open
AlxcBTW wants to merge 4 commits into
boykopovar:mainfrom
AlxcBTW:pr/libc-sce-v2-random-regex-fiopen-setw
Open

AlxcBTW wants to merge 4 commits into
boykopovar:mainfrom
AlxcBTW:pr/libc-sce-v2-random-regex-fiopen-setw

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

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:

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

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

@github-actions

Copy link
Copy Markdown

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

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3965 docs/dev/debt/libc.md
PR 5021 core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestCrt.cpp
core/libs/tests/GuestFiopen.cpp
docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7447 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7648 core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 7851 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8417 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9087 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9677 docs/dev/debt/libc.md
PR 9761 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 9863 docs/dev/debt/libc.md
PR 9873 docs/dev/debt/libc.md
PR 9929 docs/dev/debt/libc.md
PR 9935 docs/dev/debt/libc.md
PR 9964 docs/dev/debt/libc.md
PR 10002 docs/dev/debt/libc.md
PR 10007 docs/dev/debt/libc.md
PR 10113 docs/dev/debt/libc.md
PR 10158 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 10165 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 10200 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 10226 docs/dev/debt/libc.md
PR 10234 docs/dev/debt/libc.md
PR 10245 docs/dev/debt/libc.md
PR 10250 docs/dev/debt/libc.md
PR 10253 docs/dev/debt/libc.md
PR 10265 docs/dev/debt/libc.md
PR 10270 docs/dev/debt/libc.md
PR 10274 docs/dev/debt/libc.md
PR 10315 docs/dev/debt/libc.md
PR 10321 docs/dev/debt/libc.md
PR 10325 docs/dev/debt/libc.md
PR 10328 docs/dev/debt/libc.md
PR 10345 docs/dev/debt/libc.md
PR 10349 docs/dev/debt/libc.md
PR 10397 docs/dev/debt/libc.md
PR 10405 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 10506 docs/dev/debt/libc.md
PR 10510 docs/dev/debt/libc.md
PR 10512 docs/dev/debt/libc.md
PR 10565 docs/dev/debt/libc.md
PR 10569 docs/dev/debt/libc.md
PR 10749 docs/dev/debt/libc.md
PR 10780 docs/dev/debt/libc.md
PR 10987 docs/dev/debt/libc.md
PR 11109 docs/dev/debt/libc.md
PR 11172 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 11260 docs/dev/debt/libc.md
PR 11262 docs/dev/debt/libc.md
PR 11266 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11621 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 11625 docs/dev/debt/libc.md
PR 11632 docs/dev/debt/libc.md
PR 11634 docs/dev/debt/libc.md
PR 11661 docs/dev/debt/libc.md
PR 11664 docs/dev/debt/libc.md
PR 11689 docs/dev/debt/libc.md
PR 11698 docs/dev/debt/libc.md
PR 11724 docs/dev/debt/libc.md
PR 11726 docs/dev/debt/libc.md
PR 11793 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 11831 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 11848 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 11870 docs/dev/debt/libc.md
PR 11895 docs/dev/debt/libc.md
PR 11907 docs/dev/debt/libc.md
PR 11947 docs/dev/debt/libc.md
PR 12053 docs/dev/debt/libc.md
PR 12057 docs/dev/debt/libc.md
PR 12122 docs/dev/debt/libc.md
PR 12149 docs/dev/debt/libc.md
PR 12184 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12271 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12292 docs/dev/debt/libc.md
PR 12397 docs/dev/debt/libc.md
PR 12428 docs/dev/debt/libc.md
PR 12510 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 12511 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 12514 docs/dev/debt/libc.md
PR 12518 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 12530 docs/dev/debt/libc.md
PR 12532 docs/dev/debt/libc.md
PR 12560 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12574 core/libs/tests/GuestCrt.cpp
docs/dev/debt/libc.md
PR 12581 core/libs/tests/GuestCrt.cpp
PR 12592 docs/dev/debt/libc.md
PR 12593 docs/dev/debt/libc.md
PR 12594 docs/dev/debt/libc.md
PR 12595 docs/dev/debt/libc.md
PR 12598 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12605 docs/dev/debt/libc.md
PR 12622 docs/dev/debt/libc.md
PR 12627 docs/dev/debt/libc.md
PR 12682 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 12688 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 12700 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 12704 core/libs/prx/libc/src/LocaleSupport.cpp
core/libs/tests/GuestLocale.cpp
docs/dev/debt/libc.md
PR 12841 docs/dev/debt/libc.md
PR 12849 docs/dev/debt/libc.md
PR 12920 docs/dev/debt/libc.md
PR 12947 docs/dev/debt/libc.md
PR 12965 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 13119 docs/dev/debt/libc.md
PR 13186 docs/dev/debt/libc.md
PR 13390 docs/dev/debt/libc.md
PR 13449 docs/dev/debt/libc.md
PR 13784 docs/dev/debt/libc.md
PR 13793 docs/dev/debt/libc.md
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 13809 docs/dev/debt/libc.md
PR 13828 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 14020 docs/dev/debt/libc.md
PR 14022 core/libs/prx/libc/src/LocaleSupport.cpp
PR 14085 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md
PR 14235 docs/dev/debt/libc.md
PR 14298 docs/dev/debt/libc.md
PR 14326 docs/dev/debt/libc.md
PR 14373 core/libs/prx/libc/src/LocaleSupport.cpp
PR 14559 core/libs/prx/libc/src/FileAndHeap.cpp
PR 14560 core/libs/prx/libc/src/FileAndHeap.cpp
PR 14585 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 14588 docs/dev/debt/libc.md
PR 14595 docs/dev/debt/libc.md
PR 14610 docs/dev/debt/libc.md
PR 14619 docs/dev/debt/libc.md
PR 14620 docs/dev/debt/libc.md
PR 14623 docs/dev/debt/libc.md
PR 14828 docs/dev/debt/libc.md
PR 14864 docs/dev/debt/libc.md
PR 14878 docs/dev/debt/libc.md
PR 14915 docs/dev/debt/libc.md
PR 14955 docs/dev/debt/libc.md
PR 15004 docs/dev/debt/libc.md
PR 15095 docs/dev/debt/libc.md
PR 15098 docs/dev/debt/libc.md
PR 15099 docs/dev/debt/libc.md

@MarcZX10

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@ycbuzi

ycbuzi commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Windows run of 1da5b7c merged onto main a6646f8 (63e02a0726), the platform the description lists as not run. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release, BUILD_TESTING=ON.

The merge conflicts only in docs/dev/debt/libc.md, as GitHub shows; for this run I took this PR's side of that file. Built libc, guest_crt_tests, guest_fiopen_tests and guest_locale_tests with no errors or warnings. ctest --repeat until-fail:2 on guest_crt, guest_fiopen and guest_locale: all three pass on both repeats. No negative control: guest_fiopen and guest_locale call functions this PR adds, so with main's sources they do not link. Not run: a title.

danielradosa added a commit to danielradosa/AnyPS5 that referenced this pull request Oct 24, 2026
@adriadam10 adriadam10 self-assigned this Oct 25, 2026
@edubox edubox mentioned this pull request Oct 25, 2026
12 tasks done
@Danigamer05 Danigamer05 mentioned this pull request Oct 27, 2026
12 tasks done
@oneandonlydean

Copy link
Copy Markdown
Collaborator

@AlxcBTW the branch conflicts with main in LocaleSupport.cpp, GuestCrt.cpp, GuestFiopen.cpp, GuestLocale.cpp and docs/dev/debt/libc.md; could you rebase? The unversioned _Random_device, _Fiopen and setw are declared in libc/include/Api.hpp, which this PR predates, so the three new std::__sce_v2 functions need declarations there next to their siblings.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libc needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants