feat(libc): count the std::__sce_v2 _Winit and ios_base::Init initializations #15602

Merged
Danigamer05 merged 2 commits from upstream-pr/15602 into main 2026-11-07 20:36:12 +00:00
Danigamer05 commented 2026-11-03 21:19:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-03T21:19:26Z.


What

Add the versioned std::__sce_v2 stream initialization counters to libc:

Export NID Original RVA
_ZNSt8__sce_v26_Winit9_Init_cntE (data, int) RHJsm6Tv-hE 0x1939E0
_ZNSt8__sce_v26_WinitC1Ev ++NWMgKWsek 0x10C130
_ZNSt8__sce_v26_WinitC2Ev 9GII7ZFbzH4 0x10C130
_ZNSt8__sce_v26_WinitD1Ev N5sgKofpQtY 0x10C150
_ZNSt8__sce_v26_WinitD2Ev 8CsRpCsiGzQ 0x10C150
_ZNSt8__sce_v28ios_base4Init9_Init_cntE (data, int) mpVSzo64joI 0x1939E8
_ZNSt8__sce_v28ios_base4Init10_Init_ctorEPS1_ TY4Lfh4lHn8 0x10D7B0
_ZNSt8__sce_v28ios_base4Init10_Init_dtorEPS1_ DXtdV6bncOA 0x10D7D0
_ZNSt8__sce_v28ios_base4Init14_Init_cnt_funcEv whkr2W9X2ZQ 0x10D7A0

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6). A title whose <iostream> uses the versioned library calls the _Winit and ios_base::Init constructors and destructors from its static initializers and finalizers.

  • Both _Init_cnt counters start at -1, as in the module's .data.
  • The constructors and _Init_ctor raise a negative count to 1 and otherwise add 1.
  • The destructors and _Init_dtor subtract 1.
  • _Init_cnt_func returns the address of the ios_base::Init counter.

When a count reaches 0 the module flushes its versioned wide or narrow standard streams through their _Ptr_* pointers. This libc has no versioned standard stream objects, so there is nothing to flush; the debt entry records it. The code is in a new VersionedStreamInit.cpp.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main 04a9eb4fa28. Exact tested commit: 0ff5d61b646.

  • Built libc, libkernel, their NID-patched production libraries and the related tests. The new guest_sce_v2_stream_init passes, along with public_headers, guest_math_exact, guest_sce_v2_float_helpers, guest_sce_v2_filesystem_calls and guest_random_device_seed.
  • The new test checks the initial -1 of both counters, counting up from -1 and from 1, counting down through 0 to -1, restarting from -5, that the two counters are independent, and the address _Init_cnt_func returns.
  • The original functions were loaded from the bundled module with its relocations applied, without running its initializers, so its stream pointers were null as here. They ran side by side with the patched production library on 400,002 calls per seed, over two seeds. Each was a random walk of 200,000 constructor and destructor calls per counter, mixing C1 and C2 and D1 and D2, plus _Init_cnt_func. The module's counters and the exported counters were equal after every call.
  • Negative control: four lines were altered one at a time: the initial value, the restart of a negative count, _Init_dtor, and the counter _Init_cnt_func returns. The new CTest and the side-by-side run failed on each. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and both passed again.
  • Code conventions and git diff --check pass.
  • tools/pr_overlap.py read 1,774 open PRs before the rebases onto 086c0686c8a and 04a9eb4fa28 and reports no overlap; both rebases were clean. It keeps exit 2 for 30 branches that already conflict with main. Merging each with this branch and with main using git merge-tree gives the same conflict blocks; only #13486 names related symbols, the unversioned _Winit and ios_base::Init constructors in a table. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552 and #15561.

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:5144675480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15602). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-03T21:19:26Z. --- ### What Add the versioned `std::__sce_v2` stream initialization counters to libc: | Export | NID | Original RVA | | --- | --- | --- | | `_ZNSt8__sce_v26_Winit9_Init_cntE` (data, `int`) | `RHJsm6Tv-hE` | `0x1939E0` | | `_ZNSt8__sce_v26_WinitC1Ev` | `++NWMgKWsek` | `0x10C130` | | `_ZNSt8__sce_v26_WinitC2Ev` | `9GII7ZFbzH4` | `0x10C130` | | `_ZNSt8__sce_v26_WinitD1Ev` | `N5sgKofpQtY` | `0x10C150` | | `_ZNSt8__sce_v26_WinitD2Ev` | `8CsRpCsiGzQ` | `0x10C150` | | `_ZNSt8__sce_v28ios_base4Init9_Init_cntE` (data, `int`) | `mpVSzo64joI` | `0x1939E8` | | `_ZNSt8__sce_v28ios_base4Init10_Init_ctorEPS1_` | `TY4Lfh4lHn8` | `0x10D7B0` | | `_ZNSt8__sce_v28ios_base4Init10_Init_dtorEPS1_` | `DXtdV6bncOA` | `0x10D7D0` | | `_ZNSt8__sce_v28ios_base4Init14_Init_cnt_funcEv` | `whkr2W9X2ZQ` | `0x10D7A0` | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). A title whose `<iostream>` uses the versioned library calls the `_Winit` and `ios_base::Init` constructors and destructors from its static initializers and finalizers. - Both `_Init_cnt` counters start at -1, as in the module's `.data`. - The constructors and `_Init_ctor` raise a negative count to 1 and otherwise add 1. - The destructors and `_Init_dtor` subtract 1. - `_Init_cnt_func` returns the address of the `ios_base::Init` counter. When a count reaches 0 the module flushes its versioned wide or narrow standard streams through their `_Ptr_*` pointers. This libc has no versioned standard stream objects, so there is nothing to flush; the debt entry records it. The code is in a new `VersionedStreamInit.cpp`. ### 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 `04a9eb4fa28`. Exact tested commit: `0ff5d61b646`. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_sce_v2_stream_init` passes, along with `public_headers`, `guest_math_exact`, `guest_sce_v2_float_helpers`, `guest_sce_v2_filesystem_calls` and `guest_random_device_seed`. - The new test checks the initial -1 of both counters, counting up from -1 and from 1, counting down through 0 to -1, restarting from -5, that the two counters are independent, and the address `_Init_cnt_func` returns. - The original functions were loaded from the bundled module with its relocations applied, without running its initializers, so its stream pointers were null as here. They ran side by side with the patched production library on 400,002 calls per seed, over two seeds. Each was a random walk of 200,000 constructor and destructor calls per counter, mixing C1 and C2 and D1 and D2, plus `_Init_cnt_func`. The module's counters and the exported counters were equal after every call. - Negative control: four lines were altered one at a time: the initial value, the restart of a negative count, `_Init_dtor`, and the counter `_Init_cnt_func` returns. The new CTest and the side-by-side run failed on each. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and both passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,774 open PRs before the rebases onto `086c0686c8a` and `04a9eb4fa28` and reports no overlap; both rebases were clean. It keeps exit 2 for 30 branches that already conflict with main. Merging each with this branch and with main using `git merge-tree` gives the same conflict blocks; only #13486 names related symbols, the unversioned `_Winit` and `ios_base::Init` constructors in a table. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552 and #15561. 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!15602
No description provided.