Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
T3cm0:bionic/libc-addstd
Oct 19, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
T3cm0:bionic/libc-addstd

Conversation

@T3cm0

@T3cm0 T3cm0 commented Oct 17, 2026

Copy link
Copy Markdown

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 feat(libc): implement sceLibcBacktraceSelf on Linux #2040)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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

@github-actions github-actions Bot added libc docs needs rebase Conflicts with main, rebase needed labels Oct 17, 2026
@blawesom

Copy link
Copy Markdown
Contributor

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.

@Lorkydey Lorkydey mentioned this pull request Oct 17, 2026
12 tasks done
@T3cm0
T3cm0 force-pushed the bionic/libc-addstd branch 2 times, most recently from 9039f2d to 0bae293 Compare October 17, 2026 20:43
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 17, 2026
@T3cm0

T3cm0 commented Oct 17, 2026

Copy link
Copy Markdown
Author

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 github-actions Bot added unblocks title Names a title ID on the Unblocks line needs rebase Conflicts with main, rebase needed labels Oct 18, 2026
@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Progress report (b106f6f → 6fdb88f)

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

✅ 1 implemented
Library Name
libc _ZNSt8ios_base7_AddstdEPS__nid_postfix

Tecmo and others added 2 commits October 19, 2026 14:41
Queue the stream in the table of the 8 standard stream
slots of Dinkumware's ios.cpp: the first free slot or the one
that already holds the stream, with a reference count per slot,
and the destructor suppresses the destruction of a standard
stream while its slot still has open references.
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@adriadam10
adriadam10 merged commit 6844780 into boykopovar:main Oct 19, 2026
17 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libc unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants