feat(libc): implement ios_base::_Addstd #6975

Merged
T3cm0 merged 2 commits from upstream-pr/6975 into main 2026-10-19 17:35:58 +00:00
T3cm0 commented 2026-10-17 00:22:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by T3cm0 on 2026-10-17T00:22:18Z.


What

std::ios_base::_Addstd (LTov9gMEqCU) registers a stream in Dinkumware's standard stream table, as VC12's ios.cpp does: it takes the first of slots 1 to 7 that is free or already holds the stream, and slot 8 (NSTDSTR) when none is, stores that 1-based index in _Stdstr (offset 0x8 of ios_base) and raises the slot's open count. ios_base::~ios_base now decrements that count and skips the rest of the destruction while it stays positive, as _Ios_base_dtor does. Registration never fails: every stream past the first seven shares slot 8.

PPSA28997 (God of War Sons of Sparta) stops at this export when it is a stub, as reported in #2040 ("On main (as of Oct 8) the title stops earlier, at LTov9gMEqCU").

Measured

PS5, firmware 13.60, from a homebrew payload (ps5-payload-sdk) linked against the system libSceLibcInternal export, calling _Addstd on 0x80-byte objects filled with 0xCC and listing every byte that changed:

call bytes written
first stream 0x08..0x0f = 08 00 00 00 00 00 00 00
the same stream again 0x08..0x0f = 8
eleven more distinct streams each 0x08..0x0f = 8, no failure

No other byte of the objects changed. In that process the system library's own standard streams already hold slots 1 to 7, so every new stream lands in the shared slot 8; that is VC12's ++_Stdstr < NSTDSTR loop, not a table of 8 free slots that can run out. The order in which fresh streams take slots 1 to 7 is not observable there and follows VC12; this is recorded in docs/dev/debt/libc.md.

Tested

  • Linux (WSL Ubuntu), GCC 15, Release: guest_locale_tests passes; with the loop bound changed back to <= it fails.
  • The console measurement above.

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
  • Unblocks: PPSA28997 (stop reported in #2040)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4895800255 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6975). Originally posted by [T3cm0](https://github.com/T3cm0) on 2026-10-17T00:22:18Z. --- ### What `std::ios_base::_Addstd` (`LTov9gMEqCU`) registers a stream in Dinkumware's standard stream table, as [VC12's ios.cpp](https://github.com/ganboing/crt.vc12/blob/master/src/ios.cpp) does: it takes the first of slots 1 to 7 that is free or already holds the stream, and slot 8 (`NSTDSTR`) when none is, stores that 1-based index in `_Stdstr` (offset 0x8 of `ios_base`) and raises the slot's open count. `ios_base::~ios_base` now decrements that count and skips the rest of the destruction while it stays positive, as `_Ios_base_dtor` does. Registration never fails: every stream past the first seven shares slot 8. PPSA28997 (God of War Sons of Sparta) stops at this export when it is a stub, as reported in #2040 ("On main (as of Oct 8) the title stops earlier, at `LTov9gMEqCU`"). ### Measured PS5, firmware 13.60, from a homebrew payload (ps5-payload-sdk) linked against the system `libSceLibcInternal` export, calling `_Addstd` on 0x80-byte objects filled with 0xCC and listing every byte that changed: | call | bytes written | | --- | --- | | first stream | 0x08..0x0f = `08 00 00 00 00 00 00 00` | | the same stream again | 0x08..0x0f = 8 | | eleven more distinct streams | each 0x08..0x0f = 8, no failure | No other byte of the objects changed. In that process the system library's own standard streams already hold slots 1 to 7, so every new stream lands in the shared slot 8; that is VC12's `++_Stdstr < NSTDSTR` loop, not a table of 8 free slots that can run out. The order in which fresh streams take slots 1 to 7 is not observable there and follows VC12; this is recorded in `docs/dev/debt/libc.md`. ### Tested - Linux (WSL Ubuntu), GCC 15, Release: `guest_locale_tests` passes; with the loop bound changed back to `<=` it fails. - The console measurement above. ### 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] Unblocks: PPSA28997 (stop reported in #2040) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-17 00:37:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T00:37:07Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6565 docs/dev/debt/libc.md L117

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 5021 core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestLocale.cpp
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 7081 core/libs/prx/libc/src/LocaleSupport.cpp
docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/src/RuntimeSupport.cpp
PR 7332 core/libs/prx/libc/src/RuntimeSupport.cpp
docs/dev/debt/libc.md
PR 7417 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227427073 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6975#issuecomment-6227427073). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T00:37:07Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6565](https://www.github.com/boykopovar/AnyPS5/pull/6565) | `docs/dev/debt/libc.md` [L117](https://github.com/boykopovar/AnyPS5/blob/dbac9fa15b6144958d9718c9ee6a649d8ceb8a43/docs/dev/debt/libc.md#L117) | | | 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 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/RuntimeSupport.cpp`<br>`docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestLocale.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/src/LocaleSupport.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/RuntimeSupport.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libc/src/RuntimeSupport.cpp`<br>`docs/dev/debt/libc.md` | | [PR 7417](https://www.github.com/boykopovar/AnyPS5/pull/7417) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` |
blawesom commented 2026-10-17 19:00:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T19:00:13Z.


Rebase handoff — rebased onto current main (both commits, authorship unchanged). One docs conflict: your PS5-measured slot-8-sharing debt entry replaces main's older _Addstd description (main's unrelated fopen_s entry kept).

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the known main regression (agc_driver_tessellation segfault — Mesa, #5444), not this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/6975
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 9039f2df6.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6239094685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6975#issuecomment-6239094685). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-17T19:00:13Z. --- **Rebase handoff** — rebased onto current `main` (both commits, authorship unchanged). One docs conflict: your PS5-measured slot-8-sharing debt entry replaces `main`'s older `_Addstd` description (main's unrelated `fopen_s` entry kept). Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; conventions pass; **full suite green apart from the known `main` regression** (`agc_driver_tessellation` segfault — Mesa, #5444), not this PR. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/6975 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `9039f2df6`.
T3cm0 commented 2026-10-17 21:38:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by T3cm0 on 2026-10-17T21:38:17Z.


Rebased onto current main again (head 0bae293d8): #6133 added __modti3 right above the _Addstd stub this PR removes, so the resolution keeps __modti3 and drops only the stub. The change is the same four files as before.

Checked after the rebase: guest_locale and guest_crt pass on Windows 11 (MinGW GCC 15.2, Release) and check_conventions passes; the earlier Linux run by @blawesom covers the same code. Thanks for the first rebase.

When convenient, could a maintainer run the full build workflow for this PR?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6241539718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6975#issuecomment-6241539718). Originally posted by [T3cm0](https://github.com/T3cm0) on 2026-10-17T21:38:17Z. --- Rebased onto current `main` again (head `0bae293d8`): #6133 added `__modti3` right above the `_Addstd` stub this PR removes, so the resolution keeps `__modti3` and drops only the stub. The change is the same four files as before. Checked after the rebase: `guest_locale` and `guest_crt` pass on Windows 11 (MinGW GCC 15.2, Release) and `check_conventions` passes; the earlier Linux run by @blawesom covers the same code. Thanks for the first rebase. When convenient, could a maintainer run the full build workflow for this PR?
github-actions[bot] commented 2026-10-19 12:40:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T12:40:54Z.


Progress report (b106f6f → 6fdb88f)

📈 System libraries: 81.69% (+0.02%, +1 implemented functions)

✅ 1 implemented
Library Name
libc _ZNSt8ios_base7_AddstdEPS__nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6267441045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6975#issuecomment-6267441045). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T12:40:54Z. --- <!-- progress-report --> ### Progress report (b106f6f → 6fdb88f) 📈 **System libraries**: 81.69% (+0.02%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `_ZNSt8ios_base7_AddstdEPS__nid_postfix` | </details>
adriadam10 commented 2026-10-19 17:37:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:37:34Z.


Checked the _Addstd loop and slot-8 sharing against VC12's ios.cpp and the PS5 measurements in the description, the destructor count and early return, the out-of-range slot throw, and that the new test pins the < bound. main gained setw at the same spot; rebased onto it keeping both sides (no logic change), guest_locale and the libc-scope ctest pass; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273355692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6975#issuecomment-6273355692). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T17:37:34Z. --- Checked the `_Addstd` loop and slot-8 sharing against VC12's `ios.cpp` and the PS5 measurements in the description, the destructor count and early return, the out-of-range slot throw, and that the new test pins the `<` bound. `main` gained `setw` at the same spot; rebased onto it keeping both sides (no logic change), `guest_locale` and the libc-scope ctest pass; merged.
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!6975
No description provided.