feat(libc): export the std::__sce_v2 resetiosflags, setiosflags, setbase and setprecision manipulators #15809

Merged
Danigamer05 merged 2 commits from upstream-pr/15809 into main 2026-11-08 04:11:24 +00:00
Danigamer05 commented 2026-11-04 16:40:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-04T16:40:55Z.


What

Export the versioned std::__sce_v2 resetiosflags, setiosflags, setbase and setprecision manipulators from libc.

Export NID Original RVA
_ZNSt8__sce_v213resetiosflagsEi HeqRSMqwwwY 0xCFB80
_ZNSt8__sce_v211setiosflagsEi lztvX9nXnR8 0xCFBB0
_ZNSt8__sce_v27setbaseEi IqXrM0jIFDw 0xCFBD0
_ZNSt8__sce_v212setprecisionEx 3EDeSsnqsYc 0xCFC20

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).

Each one returns a function and its argument in two registers, as SceV2StreamManipulator. The int argument is returned zero-extended to 64 bits and the long long one as is. The function changes the versioned ios_base as the module's does:

  • resetiosflags clears the given bits of the 32-bit flags at 0x18;
  • setiosflags stores (flags & ~mask) | (mask & 0xFFFF), so it also clears the high bits of the mask, which it does not set;
  • setbase replaces the base field (bits 9 to 11) with 0x400 for 8, 0x200 for 10, 0x800 for 16 and 0 for any other base;
  • setprecision stores the 64-bit precision at 0x20.

They sit in LocaleSupport.cpp after the versioned ios_base calls and use main's SceV2IosBase, reading and writing the flags and precision at their offsets. This libc exports no versioned stream class, so they only suit streams laid out by a title's own libc.prx. The debt entry records that, and that a null stream throws std::invalid_argument where the console faults. #9526 adds the versioned setw in the same file; these four are not part of it.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main b11c7bf84f5. Exact tested commit: dfbb31ac9ac. The head 35ac394278b only renames the four helpers with the _nid_no_patch suffix; it was rebuilt and passed the new CTest, guest_locale, guest_sce_v2_locale, code conventions and 1,000,000 more side-by-side calls with no difference.

  • Built libc, libkernel, their NID-patched production libraries and the related tests. The new guest_sce_v2_iomanip passes, along with guest_locale, guest_sce_v2_locale, guest_sce_v2_exceptions and public_headers.

  • The new test checks 19 calls: masks with low, high, all and no bits, bases 8, 10, 16, 0, 2, -8 and 24, and precisions 6, 0, -1 and one above 32 bits. Each applies the returned function to a guarded 72-byte object and checks the returned argument, the flags, the precision, that no other byte changes, and that a null stream throws. Every expected value was taken from the original module, not from this implementation.

  • The original functions were loaded from the bundled module with their relocations applied. Their imports were bound by NID to this branch's libc and libkernel, with __stack_chk_guard pointing at a local value.

  • Side by side with the patched production library, the returned argument, all 96 bytes around the stream, errno, MXCSR and the x87 control and status words agree in all 10,000,000 calls over two seeds. The arguments mixed edge values, random 32- and 64-bit values and small bases; the starting stream bytes were random, with all-zero and all-one flags.

  • Negative control: four lines were altered one at a time:

    • setiosflags kept the high bits;
    • setbase swapped the octal and decimal fields;
    • resetiosflags kept the mask instead of clearing it;
    • setprecision stored 32 bits.

    The new CTest failed on each, and the side-by-side run reported differences for each altered function. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again.

  • Code conventions and git diff --check pass.

  • tools/pr_overlap.py read 1,876 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 25 branches that already conflict with main. Merging each of the 25 with this branch and with main using git merge-tree gives the same conflict blocks. Only #13486 names a related symbol: it lists the unversioned std::resetiosflags and std::setbase in a table, not these four. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667, #15683, #15791 and #15796.

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:5157980428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15809). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-04T16:40:55Z. --- ### What Export the versioned `std::__sce_v2` `resetiosflags`, `setiosflags`, `setbase` and `setprecision` manipulators from libc. | Export | NID | Original RVA | | --- | --- | --- | | `_ZNSt8__sce_v213resetiosflagsEi` | `HeqRSMqwwwY` | `0xCFB80` | | `_ZNSt8__sce_v211setiosflagsEi` | `lztvX9nXnR8` | `0xCFBB0` | | `_ZNSt8__sce_v27setbaseEi` | `IqXrM0jIFDw` | `0xCFBD0` | | `_ZNSt8__sce_v212setprecisionEx` | `3EDeSsnqsYc` | `0xCFC20` | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). Each one returns a function and its argument in two registers, as `SceV2StreamManipulator`. The `int` argument is returned zero-extended to 64 bits and the `long long` one as is. The function changes the versioned `ios_base` as the module's does: - `resetiosflags` clears the given bits of the 32-bit flags at 0x18; - `setiosflags` stores `(flags & ~mask) | (mask & 0xFFFF)`, so it also clears the high bits of the mask, which it does not set; - `setbase` replaces the base field (bits 9 to 11) with `0x400` for 8, `0x200` for 10, `0x800` for 16 and 0 for any other base; - `setprecision` stores the 64-bit precision at 0x20. They sit in `LocaleSupport.cpp` after the versioned `ios_base` calls and use main's `SceV2IosBase`, reading and writing the flags and precision at their offsets. This libc exports no versioned stream class, so they only suit streams laid out by a title's own `libc.prx`. The debt entry records that, and that a null stream throws `std::invalid_argument` where the console faults. #9526 adds the versioned `setw` in the same file; these four are not part of it. ### 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 `b11c7bf84f5`. Exact tested commit: `dfbb31ac9ac`. The head `35ac394278b` only renames the four helpers with the `_nid_no_patch` suffix; it was rebuilt and passed the new CTest, `guest_locale`, `guest_sce_v2_locale`, code conventions and 1,000,000 more side-by-side calls with no difference. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_sce_v2_iomanip` passes, along with `guest_locale`, `guest_sce_v2_locale`, `guest_sce_v2_exceptions` and `public_headers`. - The new test checks 19 calls: masks with low, high, all and no bits, bases 8, 10, 16, 0, 2, -8 and 24, and precisions 6, 0, -1 and one above 32 bits. Each applies the returned function to a guarded 72-byte object and checks the returned argument, the flags, the precision, that no other byte changes, and that a null stream throws. Every expected value was taken from the original module, not from this implementation. - The original functions were loaded from the bundled module with their relocations applied. Their imports were bound by NID to this branch's libc and libkernel, with `__stack_chk_guard` pointing at a local value. - Side by side with the patched production library, the returned argument, all 96 bytes around the stream, `errno`, MXCSR and the x87 control and status words agree in all 10,000,000 calls over two seeds. The arguments mixed edge values, random 32- and 64-bit values and small bases; the starting stream bytes were random, with all-zero and all-one flags. - Negative control: four lines were altered one at a time: - `setiosflags` kept the high bits; - `setbase` swapped the octal and decimal fields; - `resetiosflags` kept the mask instead of clearing it; - `setprecision` stored 32 bits. The new CTest failed on each, and the side-by-side run reported differences for each altered function. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,876 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 25 branches that already conflict with main. Merging each of the 25 with this branch and with main using `git merge-tree` gives the same conflict blocks. Only #13486 names a related symbol: it lists the unversioned `std::resetiosflags` and `std::setbase` in a table, not these four. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667, #15683, #15791 and #15796. 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!15809
No description provided.