feat(libc): implement libc++ streambuf defaults #26224

Open
mihai1859 wants to merge 2 commits from upstream-pr/26224 into main
mihai1859 commented 2026-11-23 14:00:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihai1859 on 2026-11-23T14:00:00Z.


What

Implements the six base virtual methods of libc++’s narrow basic_streambuf imported by the separately converted Azahar core in #5927. sync and showmanyc return zero, setbuf returns the existing stream buffer, and overflow, pbackfail, and underflow return EOF. These results and the absence of state changes match the implementations in ios.instantiations.cpp.o from the PS5 Payload SDK v0.42.

The branch merges cleanly into main at dba06f681a. #25289 adds a different source file at the same place in the libc CMake list. Both source entries can be kept when the later branch is rebased.

Tested

Windows 11 x64 and WinLibs GCC 16.2. guest_libc_static_imports passed with assertions for all six methods, including high byte inputs, a 64-bit buffer size, and preservation of the stream and buffer contents. Conventions and whitespace checks passed.

Compared patched libc.prx from main 3f12e824a4 and this change 9a8458e627 in the same separately converted Azahar startup diagnostic, with the same libkernel.prx. The number of unresolved names dropped from 205 to 199. The exact difference was these six imports.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

Summary by CodeRabbit

  • New Features
    • Added default handling for character-based stream-buffer operations, including synchronization, buffer configuration, input, output, putback, and availability checks. Operations now return consistent default results, with unsupported character reads and writes reporting end-of-input.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5454517471 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26224). Originally posted by [mihai1859](https://github.com/mihai1859) on 2026-11-23T14:00:00Z. --- ### What Implements the six base virtual methods of libc++’s narrow `basic_streambuf` imported by the separately converted Azahar core in #5927. `sync` and `showmanyc` return zero, `setbuf` returns the existing stream buffer, and `overflow`, `pbackfail`, and `underflow` return EOF. These results and the absence of state changes match the implementations in `ios.instantiations.cpp.o` from the PS5 Payload SDK v0.42. The branch merges cleanly into main at `dba06f681a`. #25289 adds a different source file at the same place in the libc CMake list. Both source entries can be kept when the later branch is rebased. ### 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 11 x64 and WinLibs GCC 16.2. `guest_libc_static_imports` passed with assertions for all six methods, including high byte inputs, a 64-bit buffer size, and preservation of the stream and buffer contents. Conventions and whitespace checks passed. Compared patched `libc.prx` from main `3f12e824a4` and this change `9a8458e627` in the same separately converted Azahar startup diagnostic, with the same `libkernel.prx`. The number of unresolved names dropped from 205 to 199. The exact difference was these six imports. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Added default handling for character-based stream-buffer operations, including synchronization, buffer configuration, input, output, putback, and availability checks. Operations now return consistent default results, with unsupported character reads and writes reporting end-of-input. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
PrivacyOnion commented 2026-11-23 14:05:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-23T14:05:01Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 9a8458e627:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_libc_static_imports_tests built cleanly.
  • CTest (guest_libc_static_imports):
    1/1 Test #1348: guest_libc_static_imports ........   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/LibcxxStreambuf.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified mangled symbols and signatures in Api.hpp and LibcxxStreambuf.cpp match libc++ std::__1::basic_streambuf<char, std::__1::char_traits> virtual defaults for sync, setbuf, overflow, pbackfail, showmanyc, and underflow
    • Verified calling convention compatibility (APS5_VABI and extern "C" thiscall ABI mapping across Linux SysV and Windows x64)
    • Verified LP64 vs LLP64 parameter and return types (std::int64_t for streamsize count and showmanyc, matching SysV long / 64-bit integer)
    • Verified return values conform to standard semantics: sync and showmanyc return 0, setbuf returns stream (this), and overflow, pbackfail, and underflow return EOF
    • Verified absence of invalid memory dereferences or unsafe pointer mutations across all methods
    • Verified compliance with AGENTS.md: clean code without disallowed comments, technical debt fragment provided in docs/dev/debt/changes/, and CMake target registration verified

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6023029511 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26224#pullrequestreview-6023029511). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-23T14:05:01Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `9a8458e627`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_libc_static_imports_tests` built cleanly. - **CTest** (`guest_libc_static_imports`): ``` 1/1 Test #1348: guest_libc_static_imports ........ Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/src/LibcxxStreambuf.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified mangled symbols and signatures in Api.hpp and LibcxxStreambuf.cpp match libc++ std::__1::basic_streambuf<char, std::__1::char_traits<char>> virtual defaults for sync, setbuf, overflow, pbackfail, showmanyc, and underflow - Verified calling convention compatibility (APS5_VABI and extern "C" thiscall ABI mapping across Linux SysV and Windows x64) - Verified LP64 vs LLP64 parameter and return types (std::int64_t for streamsize count and showmanyc, matching SysV long / 64-bit integer) - Verified return values conform to standard semantics: sync and showmanyc return 0, setbuf returns stream (this), and overflow, pbackfail, and underflow return EOF - Verified absence of invalid memory dereferences or unsafe pointer mutations across all methods - Verified compliance with AGENTS.md: clean code without disallowed comments, technical debt fragment provided in docs/dev/debt/changes/, and CMake target registration verified Looks Good To Me
MarcZX10 commented 2026-11-25 08:21:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T08:21:06Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and regression test support the stated narrow streambuf defaults.

What I ran

Reviewed head 9a8458e62709da3806b5aae50a8fbc6e678cfe57 using the prepared diff and pinned source reader. No commands or tests were run. The author reports tests on Windows 11 x64 with WinLibs GCC 16.2.

Results

Check Result Note
Diff and changed sources passed All five changed files read
Test execution not run Author reports the static import test passed
Targeted context passed Build registration and test integration checked

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not run the reported tests, verify the author’s comparison against the PS5 Payload SDK object, or test on physical firmware or with a full title. All changed files marked included in the manifest were read: core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/Api.hpp, core/libs/prx/libc/src/LibcxxStreambuf.cpp, core/libs/tests/GuestLibcStaticImports.cpp, and docs/dev/debt/changes/feat-libc-libcxx-streambuf-defaults.md. The manifest reports no excluded changed files; files.json was unavailable as a review document.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6054046796 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26224#pullrequestreview-6054046796). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T08:21:06Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and regression test support the stated narrow streambuf defaults. ## What I ran Reviewed head `9a8458e62709da3806b5aae50a8fbc6e678cfe57` using the prepared diff and pinned source reader. No commands or tests were run. The author reports tests on Windows 11 x64 with WinLibs GCC 16.2. ## Results | Check | Result | Note | |---|---|---| | Diff and changed sources | passed | All five changed files read | | Test execution | not run | Author reports the static import test passed | | Targeted context | passed | Build registration and test integration checked | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Did not run the reported tests, verify the author’s comparison against the PS5 Payload SDK object, or test on physical firmware or with a full title. All changed files marked included in the manifest were read: `core/libs/prx/libc/CMakeLists.txt`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/prx/libc/src/LibcxxStreambuf.cpp`, `core/libs/tests/GuestLibcStaticImports.cpp`, and `docs/dev/debt/changes/feat-libc-libcxx-streambuf-defaults.md`. The manifest reports no excluded changed files; `files.json` was unavailable as a review document. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-12-01 19:41:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T19:41:27Z.

Review: APPROVED


Reviewed — looks good

The six stream-buffer defaults return the expected values, and the added tests cover their results and preservation of the stream and buffer.

What I ran

Reviewed head 300c279cff3a01c83837f032f59e42da07678e51 using repo_read.py in the review environment. No compiler or build tool was run; PR-reported test and diagnostic results were not independently reproduced.

python3 repo_read.py search _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE4syncEv_nid_postfix
python3 repo_read.py cat core/libs/prx/libc/src/LibcxxStreambuf.cpp 1 31
python3 repo_read.py cat core/libs/tests/GuestLibcStaticImports.cpp 110 222
python3 repo_read.py cat core/libs/prx/libc/include/Api.hpp 1290 1315
python3 repo_read.py cat core/libs/prx/libc/CMakeLists.txt 252 278
python3 repo_read.py cat docs/dev/debt/changes/feat-libc-libcxx-streambuf-defaults.md 1 5

Results

Check Result Note
Source review passed All five changed files reviewed
PR-reported checks not run Not independently reproduced
Build and tests not run Would require compilation
Negative control not run No test execution

Negative control

Not run; no test or source mutation was performed.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

The author-reported Windows test run and import comparison were not independently reproduced. Physical firmware export provenance and full title execution are also unverified, as noted in the change documentation. All five files listed as reviewed in files.json were reviewed; no files were excluded. For the large CMake, API, and test files, review covered the changed lines and relevant context rather than every line.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6138688184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26224#pullrequestreview-6138688184). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-12-01T19:41:27Z. **Review:** APPROVED --- # Reviewed — looks good The six stream-buffer defaults return the expected values, and the added tests cover their results and preservation of the stream and buffer. ## What I ran Reviewed head `300c279cff3a01c83837f032f59e42da07678e51` using `repo_read.py` in the review environment. No compiler or build tool was run; PR-reported test and diagnostic results were not independently reproduced. ```text python3 repo_read.py search _ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE4syncEv_nid_postfix python3 repo_read.py cat core/libs/prx/libc/src/LibcxxStreambuf.cpp 1 31 python3 repo_read.py cat core/libs/tests/GuestLibcStaticImports.cpp 110 222 python3 repo_read.py cat core/libs/prx/libc/include/Api.hpp 1290 1315 python3 repo_read.py cat core/libs/prx/libc/CMakeLists.txt 252 278 python3 repo_read.py cat docs/dev/debt/changes/feat-libc-libcxx-streambuf-defaults.md 1 5 ``` ## Results | Check | Result | Note | |---|---|---| | Source review | passed | All five changed files reviewed | | PR-reported checks | not run | Not independently reproduced | | Build and tests | not run | Would require compilation | | Negative control | not run | No test execution | ## Negative control Not run; no test or source mutation was performed. ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [CMake source registration](https://github.com/boykopovar/AnyPS5/blob/300c279cff3a01c83837f032f59e42da07678e51/core/libs/prx/libc/CMakeLists.txt#L269) - [API declarations](https://github.com/boykopovar/AnyPS5/blob/300c279cff3a01c83837f032f59e42da07678e51/core/libs/prx/libc/include/Api.hpp#L1303-L1308) - [Stream-buffer implementations](https://github.com/boykopovar/AnyPS5/blob/300c279cff3a01c83837f032f59e42da07678e51/core/libs/prx/libc/src/LibcxxStreambuf.cpp#L7-L28) - [Static import coverage](https://github.com/boykopovar/AnyPS5/blob/300c279cff3a01c83837f032f59e42da07678e51/core/libs/tests/GuestLibcStaticImports.cpp#L127-L152) - [Technical debt entry](https://github.com/boykopovar/AnyPS5/blob/300c279cff3a01c83837f032f59e42da07678e51/docs/dev/debt/changes/feat-libc-libcxx-streambuf-defaults.md#L1-L5) ## Not verified The author-reported Windows test run and import comparison were not independently reproduced. Physical firmware export provenance and full title execution are also unverified, as noted in the change documentation. All five files listed as reviewed in `files.json` were reviewed; no files were excluded. For the large CMake, API, and test files, review covered the changed lines and relevant context rather than every line. ## To get this to a good state Nothing is required.
Plyxen commented 2026-12-03 07:34:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T07:34:45Z.

Review: APPROVED


I read the diff at 300c279cff. Merged into main at 35e34b1a7f0 together with other open PRs (so not an isolated build), Release, on Windows 11 (GCC 15.2) and Ubuntu 24.04 under WSL2 (GCC 13.3).

  • guest_libc_static_imports: passes on both.
  • The other guest_libcxx_* tests of that tree pass too (39 on Linux).
  • No control: the test needs exports that main does not have.

Not checked: a title.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6165441474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26224#pullrequestreview-6165441474). Originally posted by [Plyxen](https://github.com/Plyxen) on 2026-12-03T07:34:45Z. **Review:** APPROVED --- I read the diff at `300c279cff`. Merged into `main` at `35e34b1a7f0` together with other open PRs (so not an isolated build), Release, on Windows 11 (GCC 15.2) and Ubuntu 24.04 under WSL2 (GCC 13.3). - `guest_libc_static_imports`: passes on both. - The other `guest_libcxx_*` tests of that tree pass too (39 on Linux). - No control: the test needs exports that `main` does not have. Not checked: a title. AI-assisted: yes (Claude Code)
ligmaSec commented 2026-12-03 10:38:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T10:38:15Z.

Review: COMMENTED


The GuestLibcStaticImports fixture coverage passed on Linux with the exact implementation from this head. The fixture checks the default streambuf return values and verifies that the stream and source buffer stay intact.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6168111718 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26224#pullrequestreview-6168111718). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T10:38:15Z. **Review:** COMMENTED --- The GuestLibcStaticImports fixture coverage passed on Linux with the exact implementation from this head. The fixture checks the default streambuf return values and verifies that the stream and source buffer stay intact. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/26224:upstream-pr/26224'
git switch 'upstream-pr/26224'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/26224'
git switch 'upstream-pr/26224'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/26224'
git switch 'upstream-pr/26224'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/26224'
git switch 'main'
git merge --squash 'upstream-pr/26224'
git switch 'main'
git merge --ff-only 'upstream-pr/26224'
git switch 'main'
git merge 'upstream-pr/26224'
git push origin 'main'
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!26224
No description provided.