feat(libc): export the versioned std::__sce_v2 locale runtime #14585

Merged
edubox merged 3 commits from upstream-pr/14585 into main 2026-11-03 08:07:57 +00:00
edubox commented 2026-11-01 16:00:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-01T16:00:42Z.


What

PPSA28416 imports the versioned std::__sce_v2 locale and stream runtime from libc.prx; none of it was exported. This adds the measured objects and accessors:

  • Facet ids ctype<char> (MmytiDdoGBA), ctype<wchar_t> (b61-ZHIQuns), numpunct<char> (5+FD4VpX+nw), num_put<char> (3ZotGOwzi9k) and codecvt<wchar_t,char,_Mbstatet> (OVV3+UimpiY), plus locale::id::_Id_cnt (EIyErVBW9QI). In the console's libc.prx they are BSS objects of 8 and 4 bytes, so they start at zero.
  • _sceLibcClassicLocale (Mcrl2crhxu0), which points at this library's classic Implementation.
  • locale::_Init(bool) (Mt6co-yzyjg), locale::_Getgloballocale() (xE51MX+B2G4), ios_base::_Addstd (LfjFksmiu4Y), ios_base::_Ios_base_dtor (Ze2I81YNykw) and _Facet_Register (aFxknk3hTog).
  • _Locimp::_New_Locimp (ynwqogpIbL0) and _Locimp::_Addfac (7KPYZ-jSAto), whose 0x30-byte object layout matches the existing GuestLocale::Implementation, so they reuse this library's copy constructor and facet insertion.
  • The cout (9Qe7XFSQ4Lk), cerr (Jk7KrKMQzDw), wcout (7ipah7h7Wjk), wcerr (+ROCBP8cIyY), cin (T1cG+xkSd-g) and wcin (RhFDPGxQ4sA) objects, which PPSA01341 imports. They are zeroed storage like the unversioned objects: the console initializes them as 0x68/0x70-byte streams with a working vtable and streambuf, which is not modelled yet.

Evidence is the disassembly of the libc.prx bundled with PPSA28416 (build J03848509):

Export NID vaddr size
locale::_Init(bool) Mt6co-yzyjg 0xcfe60 3887
locale::_Getgloballocale() xE51MX+B2G4 0xcfd40 8
_Facet_Register aFxknk3hTog 0xcfd00 47
ios_base::_Addstd LfjFksmiu4Y 0x10d680 279
ios_base::_Ios_base_dtor Ze2I81YNykw 0x10d580 253
_Locimp::_New_Locimp ynwqogpIbL0 0xd0f60 124
_Locimp::_Addfac 7KPYZ-jSAto 0xf2680 365

_Init returns the global _Locimp and takes a reference on it when its flag is set; _Getgloballocale only loads the global pointer. The versioned ios_base is 0x48 bytes, not the 0x40 of the unversioned one: _Addstd writes the 1-based slot at 0x08 and uses slots 1-7 before slot 8, and _Ios_base_dtor decrements that slot's count, frees the 32-byte node list at 0x30, invokes and frees the 24-byte callback list at 0x38, and releases the locale at 0x40.

Not included on purpose: _Getctype and _Getcvt are the subject of #9466. The streams are storage-only and the debt entry records what a real console stream would need.

Review evidence

PPSA28416's relinker registry references 13 of the 20 exports this PR adds. The locale entry points and data are:

Registry position (0-based) NID Export
3629 3ZotGOwzi9k#3#2 num_put<char>::id
3630 EIyErVBW9QI#3#2 locale::id::_Id_cnt
3631 5+FD4VpX+nw#3#2 numpunct<char>::id
3632 MmytiDdoGBA#3#2 ctype<char>::id
3633 Mcrl2crhxu0#3#2 _sceLibcClassicLocale
4290 aFxknk3hTog#3#2 _Facet_Register
4292 xE51MX+B2G4#3#2 locale::_Getgloballocale()
4312 Ze2I81YNykw#3#2 ios_base::_Ios_base_dtor
4313 LfjFksmiu4Y#3#2 ios_base::_Addstd
6183 Mt6co-yzyjg#3#2 locale::_Init(bool)

nm -D on main's unpatched/libc.prx has none of them; this branch's has the corresponding _nid_postfix definitions. The title stops earlier on main: the run log ends at +77.132252 s with what(): sceNpGetSandboxInfo not implemented, before it reaches any of these imports. There is therefore no stop log tying these exports to the stop; the registry positions above are the import references the change covers.

Tested

Linux x86-64 (CachyOS), GCC 16.2.1, Release:

  • ctest --test-dir build -R '^(guest_locale|guest_multibyte_locale|guest_sce_v2_locale)$' passes 3/3. The new guest_sce_v2_locale covers the zero-initialised ids, _Init/_Getgloballocale/_sceLibcClassicLocale, facet registration, the _Locimp copy with _Addfac, and _Addstd followed by _Ios_base_dtor.
  • nid_patcher libc on the rebuilt unpatched/libc.prx exports all the NIDs above plus the six stream objects (3ZotGOwzi9k, 5+FD4VpX+nw, 7ipah7h7Wjk, 7KPYZ-jSAto, 9Qe7XFSQ4Lk, aFxknk3hTog, b61-ZHIQuns, EIyErVBW9QI, Jk7KrKMQzDw, LfjFksmiu4Y, Mcrl2crhxu0, MmytiDdoGBA, Mt6co-yzyjg, OVV3+UimpiY, RhFDPGxQ4sA, T1cG+xkSd-g, xE51MX+B2G4, ynwqogpIbL0, Ze2I81YNykw, +ROCBP8cIyY).
  • tools/check_conventions.py --base origin/main and git diff --check are clean; tools/pr_overlap.py --branch feat/libc-sce-v2-locale reports no overlap with open pull requests.

Not run on Windows or macOS, and not exercised by a title: PPSA28416 still stops earlier at sceNpGetSandboxInfo.

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: PPSA28416 #3086
  • GPUs tested: n/a
  • AI-assisted: yes

Shared files only, no shared exports: #10989 and #11421 also touch libc/CMakeLists.txt, libc/include/Api.hpp and docs/dev/debt/libc.md; the three can land in any order after a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5109042562 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14585). Originally posted by [edubox](https://github.com/edubox) on 2026-11-01T16:00:42Z. --- ### What PPSA28416 imports the versioned `std::__sce_v2` locale and stream runtime from `libc.prx`; none of it was exported. This adds the measured objects and accessors: - Facet ids `ctype<char>` (`MmytiDdoGBA`), `ctype<wchar_t>` (`b61-ZHIQuns`), `numpunct<char>` (`5+FD4VpX+nw`), `num_put<char>` (`3ZotGOwzi9k`) and `codecvt<wchar_t,char,_Mbstatet>` (`OVV3+UimpiY`), plus `locale::id::_Id_cnt` (`EIyErVBW9QI`). In the console's `libc.prx` they are BSS objects of 8 and 4 bytes, so they start at zero. - `_sceLibcClassicLocale` (`Mcrl2crhxu0`), which points at this library's classic `Implementation`. - `locale::_Init(bool)` (`Mt6co-yzyjg`), `locale::_Getgloballocale()` (`xE51MX+B2G4`), `ios_base::_Addstd` (`LfjFksmiu4Y`), `ios_base::_Ios_base_dtor` (`Ze2I81YNykw`) and `_Facet_Register` (`aFxknk3hTog`). - `_Locimp::_New_Locimp` (`ynwqogpIbL0`) and `_Locimp::_Addfac` (`7KPYZ-jSAto`), whose 0x30-byte object layout matches the existing `GuestLocale::Implementation`, so they reuse this library's copy constructor and facet insertion. - The `cout` (`9Qe7XFSQ4Lk`), `cerr` (`Jk7KrKMQzDw`), `wcout` (`7ipah7h7Wjk`), `wcerr` (`+ROCBP8cIyY`), `cin` (`T1cG+xkSd-g`) and `wcin` (`RhFDPGxQ4sA`) objects, which PPSA01341 imports. They are zeroed storage like the unversioned objects: the console initializes them as `0x68`/`0x70`-byte streams with a working vtable and streambuf, which is not modelled yet. Evidence is the disassembly of the `libc.prx` bundled with PPSA28416 (build J03848509): | Export | NID | vaddr | size | |---|---|---|---| | `locale::_Init(bool)` | `Mt6co-yzyjg` | `0xcfe60` | 3887 | | `locale::_Getgloballocale()` | `xE51MX+B2G4` | `0xcfd40` | 8 | | `_Facet_Register` | `aFxknk3hTog` | `0xcfd00` | 47 | | `ios_base::_Addstd` | `LfjFksmiu4Y` | `0x10d680` | 279 | | `ios_base::_Ios_base_dtor` | `Ze2I81YNykw` | `0x10d580` | 253 | | `_Locimp::_New_Locimp` | `ynwqogpIbL0` | `0xd0f60` | 124 | | `_Locimp::_Addfac` | `7KPYZ-jSAto` | `0xf2680` | 365 | `_Init` returns the global `_Locimp` and takes a reference on it when its flag is set; `_Getgloballocale` only loads the global pointer. The versioned `ios_base` is 0x48 bytes, not the 0x40 of the unversioned one: `_Addstd` writes the 1-based slot at `0x08` and uses slots 1-7 before slot 8, and `_Ios_base_dtor` decrements that slot's count, frees the 32-byte node list at `0x30`, invokes and frees the 24-byte callback list at `0x38`, and releases the locale at `0x40`. Not included on purpose: `_Getctype` and `_Getcvt` are the subject of #9466. The streams are storage-only and the debt entry records what a real console stream would need. ### Review evidence PPSA28416's relinker registry references 13 of the 20 exports this PR adds. The locale entry points and data are: | Registry position (0-based) | NID | Export | |---|---|---| | 3629 | `3ZotGOwzi9k#3#2` | `num_put<char>::id` | | 3630 | `EIyErVBW9QI#3#2` | `locale::id::_Id_cnt` | | 3631 | `5+FD4VpX+nw#3#2` | `numpunct<char>::id` | | 3632 | `MmytiDdoGBA#3#2` | `ctype<char>::id` | | 3633 | `Mcrl2crhxu0#3#2` | `_sceLibcClassicLocale` | | 4290 | `aFxknk3hTog#3#2` | `_Facet_Register` | | 4292 | `xE51MX+B2G4#3#2` | `locale::_Getgloballocale()` | | 4312 | `Ze2I81YNykw#3#2` | `ios_base::_Ios_base_dtor` | | 4313 | `LfjFksmiu4Y#3#2` | `ios_base::_Addstd` | | 6183 | `Mt6co-yzyjg#3#2` | `locale::_Init(bool)` | `nm -D` on `main`'s `unpatched/libc.prx` has none of them; this branch's has the corresponding `_nid_postfix` definitions. The title stops earlier on `main`: the run log ends at `+77.132252 s` with `what(): sceNpGetSandboxInfo not implemented`, before it reaches any of these imports. There is therefore no stop log tying these exports to the stop; the registry positions above are the import references the change covers. ### Tested Linux x86-64 (CachyOS), GCC 16.2.1, Release: - `ctest --test-dir build -R '^(guest_locale|guest_multibyte_locale|guest_sce_v2_locale)$'` passes 3/3. The new `guest_sce_v2_locale` covers the zero-initialised ids, `_Init`/`_Getgloballocale`/`_sceLibcClassicLocale`, facet registration, the `_Locimp` copy with `_Addfac`, and `_Addstd` followed by `_Ios_base_dtor`. - `nid_patcher libc` on the rebuilt `unpatched/libc.prx` exports all the NIDs above plus the six stream objects (`3ZotGOwzi9k`, `5+FD4VpX+nw`, `7ipah7h7Wjk`, `7KPYZ-jSAto`, `9Qe7XFSQ4Lk`, `aFxknk3hTog`, `b61-ZHIQuns`, `EIyErVBW9QI`, `Jk7KrKMQzDw`, `LfjFksmiu4Y`, `Mcrl2crhxu0`, `MmytiDdoGBA`, `Mt6co-yzyjg`, `OVV3+UimpiY`, `RhFDPGxQ4sA`, `T1cG+xkSd-g`, `xE51MX+B2G4`, `ynwqogpIbL0`, `Ze2I81YNykw`, `+ROCBP8cIyY`). - `tools/check_conventions.py --base origin/main` and `git diff --check` are clean; `tools/pr_overlap.py --branch feat/libc-sce-v2-locale` reports no overlap with open pull requests. Not run on Windows or macOS, and not exercised by a title: PPSA28416 still stops earlier at `sceNpGetSandboxInfo`. ### 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: PPSA28416 #3086 - [x] GPUs tested: n/a - [x] AI-assisted: yes Shared files only, no shared exports: #10989 and #11421 also touch `libc/CMakeLists.txt`, `libc/include/Api.hpp` and `docs/dev/debt/libc.md`; the three can land in any order after a rebase.
CnRJay commented 2026-11-01 19:48:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:48:53Z.

Review: COMMENTED


Withdrawn. There is no main stop log at these imports: PPSA28416 stops earlier at sceNpGetSandboxInfo not implemented, before the locale runtime is used. Import-registry evidence is the applicable proof here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729920522 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14585#pullrequestreview-5729920522). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:48:53Z. **Review:** COMMENTED --- Withdrawn. There is no `main` stop log at these imports: PPSA28416 stops earlier at `sceNpGetSandboxInfo not implemented`, before the locale runtime is used. Import-registry evidence is the applicable proof here.
MarcZX10 commented 2026-11-02 07:21:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T07:21:07Z.

Review: COMMENTED


Reviewed — no blocking findings; the sce_v2 locale test passed on Windows, and the PS5 measurements are not verified

This PR exports the versioned std::__sce_v2 locale runtime from libc: the locale and facet accessors, the ios_base standard-stream table, the _Locimp copy and facet installation, and the stream and locale id objects. The Windows CTest run passed guest_sce_v2_locale and the other locale cases. The PR says its layouts and facet ids were measured from a PS5 libc.prx. I cannot check that measurement from here.

What I ran

  • Head 01e53151db2518b96c46b0ac941fece014246dc9; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 6 files, +270: libc/CMakeLists.txt (+12, the new test target), libc/include/Api.hpp (+7), libc/include/GuestLocale.hpp (+14, the SceV2IosBase layout with static_asserts), libc/src/LocaleSupport.cpp (+110, the new exports and helpers), tests/GuestSceV2Locale.cpp (+124), and a debt doc (+3).
  • Read the LocaleSupport.cpp additions, the header, and the CMake change in full. The existing code around the additions is unchanged.
  • Read the test's Require checks (lines 49 to 123): the id objects, the classic locale and getglobal, the copy and facet growth to slot 41, the standard-stream slots 1 to 8, and the reference counts. Did not read the test setup code.
  • Hosted, Windows CTest: 2595 of 2595 passed. guest_sce_v2_locale (Test #737) passed, and so did guest_sce_v2_exceptions (Test #575), guest_locale (Test #735) and the other locale cases. CTest counts skipped cases as passed in its total.
  • Hosted, other jobs: relinkers and relinker-asan, register-context, write-watch and library-portability succeeded. Linux skipped.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors).
  • ABI audit passed with warnings: 1465 warnings. The first listed are public-declaration-not-found for AssignCString and the Codecvt* names. I did not compare this count with the base.
  • The test-quality helper flagged GuestSceV2Locale.cpp as possibly unregistered. The CMake fragment names it through ${LIBS_INCLUDE_DIR}/tests/GuestSceV2Locale.cpp, and the Windows run executed guest_sce_v2_locale.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check: no declared dependencies, no errors
ABI audit (main-checkout tool) passed with warnings 1465 warnings, not compared with the base; first ones are public-declaration-not-found
guest_sce_v2_locale and the other locale cases (hosted, Windows) passed Test #737, #735, #736, #575 and others
Production change (read) passed by reading no blocking defect found in the read
Layouts, export names and facet ids against the PS5 binary not verified the PR says they were measured from PPSA28416's libc.prx; not checkable here
Stream-table behaviour (read) passed by reading see the non-blocking note
Linux build and runtime tests not run Linux is skipped on pull requests
Negative controls not run no local build
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed with warnings (1465). Stack check: passed, no errors. Hosted: gh api repos/boykopovar/AnyPS5/commits/01e53151db2518b96c46b0ac941fece014246dc9/check-runs, and the Windows job log.

Negative control

Not run here. A negative control needs a local build and run of the locale tests, and code from this head is not run here.

Findings

Blocking

None from the code read.

Non-blocking

  • _ZNSt8__sce_v28ios_base14_Ios_base_dtor decrements the open count of a standard-stream slot, but it never clears g_sceV2StandardStreams[slot]. Nothing dereferences the table (a git grep finds reads only in _Addstd and the destructor, and both compare pointers). Still, a destroyed stream's address stays in its slot, so after eight standard streams the slots are not reused: later streams share slot 8, and its entry is overwritten on each new stream. This is a design note, not a crash in this code.
  • The ABI audit's 1465 warnings were not compared with the base count, so I cannot say whether this PR adds any.

Sources

Not verified

  • The layouts (SceV2IosBase size and offsets), export names, facet ids and the id objects against the PS5 libc.prx. The PR says they were measured; I did not check that.
  • The test setup code in GuestSceV2Locale.cpp.
  • The ABI audit warnings beyond the first few lines.

To get this to a good state

  • Nothing blocking. Clear the stale stream-table entries on destruction if the slot reuse is meant to work.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5733188288 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14585#pullrequestreview-5733188288). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T07:21:07Z. **Review:** COMMENTED --- # Reviewed — no blocking findings; the sce_v2 locale test passed on Windows, and the PS5 measurements are not verified This PR exports the versioned `std::__sce_v2` locale runtime from libc: the locale and facet accessors, the `ios_base` standard-stream table, the `_Locimp` copy and facet installation, and the stream and locale id objects. The Windows CTest run passed `guest_sce_v2_locale` and the other locale cases. The PR says its layouts and facet ids were measured from a PS5 `libc.prx`. I cannot check that measurement from here. ## What I ran - Head `01e53151db2518b96c46b0ac941fece014246dc9`; base `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. 6 files, +270: `libc/CMakeLists.txt` (+12, the new test target), `libc/include/Api.hpp` (+7), `libc/include/GuestLocale.hpp` (+14, the `SceV2IosBase` layout with `static_assert`s), `libc/src/LocaleSupport.cpp` (+110, the new exports and helpers), `tests/GuestSceV2Locale.cpp` (+124), and a debt doc (+3). - Read the `LocaleSupport.cpp` additions, the header, and the CMake change in full. The existing code around the additions is unchanged. - Read the test's `Require` checks (lines 49 to 123): the id objects, the classic locale and `getglobal`, the copy and facet growth to slot 41, the standard-stream slots 1 to 8, and the reference counts. Did not read the test setup code. - Hosted, Windows CTest: 2595 of 2595 passed. `guest_sce_v2_locale` (Test #737) passed, and so did `guest_sce_v2_exceptions` (Test #575), `guest_locale` (Test #735) and the other locale cases. CTest counts skipped cases as passed in its total. - Hosted, other jobs: relinkers and relinker-asan, register-context, write-watch and library-portability succeeded. Linux skipped. - Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed (no declared dependencies, no errors). - ABI audit passed with warnings: 1465 warnings. The first listed are `public-declaration-not-found` for `AssignCString` and the `Codecvt*` names. I did not compare this count with the base. - The test-quality helper flagged `GuestSceV2Locale.cpp` as possibly unregistered. The CMake fragment names it through `${LIBS_INCLUDE_DIR}/tests/GuestSceV2Locale.cpp`, and the Windows run executed `guest_sce_v2_locale`. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | stack check: no declared dependencies, no errors | | ABI audit (main-checkout tool) | passed with warnings | 1465 warnings, not compared with the base; first ones are `public-declaration-not-found` | | `guest_sce_v2_locale` and the other locale cases (hosted, Windows) | passed | Test #737, #735, #736, #575 and others | | Production change (read) | passed by reading | no blocking defect found in the read | | Layouts, export names and facet ids against the PS5 binary | not verified | the PR says they were measured from PPSA28416's `libc.prx`; not checkable here | | Stream-table behaviour (read) | passed by reading | see the non-blocking note | | Linux build and runtime tests | not run | Linux is skipped on pull requests | | Negative controls | not run | no local build | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: passed with warnings (1465). Stack check: passed, no errors. Hosted: `gh api repos/boykopovar/AnyPS5/commits/01e53151db2518b96c46b0ac941fece014246dc9/check-runs`, and the Windows job log. </details> ## Negative control Not run here. A negative control needs a local build and run of the locale tests, and code from this head is not run here. ## Findings **Blocking** None from the code read. **Non-blocking** - `_ZNSt8__sce_v28ios_base14_Ios_base_dtor` decrements the open count of a standard-stream slot, but it never clears `g_sceV2StandardStreams[slot]`. Nothing dereferences the table (a `git grep` finds reads only in `_Addstd` and the destructor, and both compare pointers). Still, a destroyed stream's address stays in its slot, so after eight standard streams the slots are not reused: later streams share slot 8, and its entry is overwritten on each new stream. This is a design note, not a crash in this code. - The ABI audit's 1465 warnings were not compared with the base count, so I cannot say whether this PR adds any. ## Sources - Implementation: https://github.com/boykopovar/AnyPS5/blob/01e53151db2518b96c46b0ac941fece014246dc9/core/libs/prx/libc/src/LocaleSupport.cpp - Layout and declarations: https://github.com/boykopovar/AnyPS5/blob/01e53151db2518b96c46b0ac941fece014246dc9/core/libs/prx/libc/include/GuestLocale.hpp - Test: https://github.com/boykopovar/AnyPS5/blob/01e53151db2518b96c46b0ac941fece014246dc9/core/libs/tests/GuestSceV2Locale.cpp - Windows job log: check-run `windows` on 01e53151db2518b96c46b0ac941fece014246dc9 ## Not verified - The layouts (`SceV2IosBase` size and offsets), export names, facet ids and the id objects against the PS5 `libc.prx`. The PR says they were measured; I did not check that. - The test setup code in `GuestSceV2Locale.cpp`. - The ABI audit warnings beyond the first few lines. ## To get this to a good state - Nothing blocking. Clear the stale stream-table entries on destruction if the slot reuse is meant to work.
XairRrR commented 2026-11-02 21:43:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T21:43:25Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The PR builds and its locale tests pass, but _Ios_base_dtor frees the 0x30 node list before it runs the erase_event callbacks. The console does it the other way round, and so does the PR's own debt entry. I reproduced the ordering problem with a local probe.

What I ran

Head 0176a0307b618e7192d943b5c9b59dd11f8cee46, merged with --no-ff into main 9090972b7e91fd266819cbd77a8b058e177b5682. Debian 13 VM, GCC 14.2.0, Release, Ninja, BUILD_TESTING=ON.

git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...0176a0307b618e7192d943b5c9b59dd11f8cee46
python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale|guest_sce_v2_exceptions)$"
# probe: a temporary addition to GuestSceV2Locale.cpp (one 0x30 node, one 0x38 callback node; the callback records whether streamNodes is still set)
ninja -C build -j32 -l32 guest_sce_v2_locale_tests
ctest --test-dir build -V -R "^guest_sce_v2_locale$"
# negative control: LocaleSupport.cpp, Api.hpp, GuestLocale.hpp from main, original test
ninja -C build -j32 -l32 guest_sce_v2_locale_tests
# restore the merged files, rebuild, rerun
ninja -C build -j32 -l32 libc guest_sce_v2_locale_tests guest_locale_tests guest_multibyte_locale_tests
ctest --test-dir build -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale)$"
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Build (script) ok
Tests in the script run no new failures and no timeouts. The known main failures (AGC denormal cases, guest_interfaces, unwrap_self and others) are unrelated to this PR. The guest_net_ctl skip is known on main.
guest_sce_v2_locale, guest_locale, guest_multibyte_locale, guest_sce_v2_exceptions 4/4 passed
Callback-order probe fails: the callback sees streamNodes == nullptr
Vulkan validation not applicable (no AGC, shader or VideoOut files)
Worktree after restoring clean (git status --porcelain empty)
Probe output
799: PROBE calls=1 arrayVisibleInCallback=0
1/1 Test #799: guest_sce_v2_locale ..............   Passed    0.01 sec

Negative control

I restored LocaleSupport.cpp, Api.hpp and GuestLocale.hpp from main and kept the PR's test. The test no longer compiles, for example error: '_ZNSt8__sce_v26locale5_InitEb_nid_postfix' was not declared in this scope. So the control only shows that the test needs the new exports. It does not show that the test checks behaviour: the test leaves both node lists null, so it does not reach the ordering defect below. I then restored the merged files, rebuilt, and the three locale tests passed again.

Findings

Blocking

  • _Ios_base_dtor runs the erase_event callbacks after it frees the 0x30 list (LocaleSupport.cpp#L830-L842).
    • What happens: the loop at core/libs/prx/libc/src/LocaleSupport.cpp:830-835 frees streamNodes and sets it to null. Only after that does the loop at :836-842 invoke each callback.

    • Who reported it: B-Howell, with disassembly of PPSA08329's libc.prx. I add a local reproduction: the probe above prints arrayVisibleInCallback=0.

    • It contradicts the PR's own debt entry: the entry (docs/dev/debt/libc.md:295) says the console "calls the 0x38 callbacks, frees the 0x30/0x38 node lists".

    • Why it matters: an erase_event callback normally reads iword/pword to release what it stored there.

      • With this order the callback finds the array gone, so the value is lost.
      • If the callback calls pword, it gets a newly allocated node on a list the destructor has already processed, so that node leaks.
    • A second problem: each callback node is freed right after its call, while self->callbackNodes still points at the head of the list. A callback that walks or changes the callback list (for example through register_callback or copyfmt) would touch freed nodes. The console frees nothing until every callback has run.

    • Suggested fix: follow the Dinkumware _Tidy order:

      1. Call every callback without freeing anything.
      2. Free the 0x30 list and set it to null.
      3. Free the 0x38 list and set it to null.
      4. Release the locale.

      Add a test case that fills both lists and checks, inside the callback, that streamNodes is still set.

Non-blocking

  • _Facet_Register (core/libs/prx/libc/src/LocaleSupport.cpp:855-858) accepts a null facet and registers duplicates. The unversioned _ZNSt6locale5facet9_RegisterEv_nid_postfix (:748-755) rejects both. Consider the same checks, so that a bad argument fails loudly instead of being recorded silently.
  • The test checks the destructor only with empty 0x30/0x38 lists, so the node-freeing and callback paths have no coverage at all. The blocking fix should add that coverage.

Not verified

  • The NIDs, the layouts and the disassembly quoted from PPSA28416's libc.prx: I have no console binary here.
  • I did not check whether slot 8 behaves as on the console. On the console, a stream that _Addstd puts in slot 8 might be returned early by the destructor rather than torn down; the PR decrements its count and tears it down.
  • Windows and macOS builds. No title was run, and the title does not reach these imports anyway.

To get this to a good state

  1. Reorder _Ios_base_dtor: callbacks first, freeing nothing, then the 0x30 list, then the 0x38 list, then the locale.
  2. Extend GuestSceV2Locale.cpp with a stream that has one 0x30 node and one callback node, and require that the callback runs once with streamNodes still set. Check that this new case fails against the current order.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5743812294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14585#pullrequestreview-5743812294). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T21:43:25Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The PR builds and its locale tests pass, but `_Ios_base_dtor` frees the `0x30` node list before it runs the `erase_event` callbacks. The console does it the other way round, and so does the PR's own debt entry. I reproduced the ordering problem with a local probe. ## What I ran Head `0176a0307b618e7192d943b5c9b59dd11f8cee46`, merged with `--no-ff` into `main` `9090972b7e91fd266819cbd77a8b058e177b5682`. Debian 13 VM, GCC 14.2.0, Release, Ninja, `BUILD_TESTING=ON`. ``` git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...0176a0307b618e7192d943b5c9b59dd11f8cee46 python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale|guest_sce_v2_exceptions)$" # probe: a temporary addition to GuestSceV2Locale.cpp (one 0x30 node, one 0x38 callback node; the callback records whether streamNodes is still set) ninja -C build -j32 -l32 guest_sce_v2_locale_tests ctest --test-dir build -V -R "^guest_sce_v2_locale$" # negative control: LocaleSupport.cpp, Api.hpp, GuestLocale.hpp from main, original test ninja -C build -j32 -l32 guest_sce_v2_locale_tests # restore the merged files, rebuild, rerun ninja -C build -j32 -l32 libc guest_sce_v2_locale_tests guest_locale_tests guest_multibyte_locale_tests ctest --test-dir build -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale)$" git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Build (script) | ok | | Tests in the script run | no new failures and no timeouts. The known `main` failures (AGC denormal cases, `guest_interfaces`, `unwrap_self` and others) are unrelated to this PR. The `guest_net_ctl` skip is known on `main`. | | `guest_sce_v2_locale`, `guest_locale`, `guest_multibyte_locale`, `guest_sce_v2_exceptions` | 4/4 passed | | Callback-order probe | fails: the callback sees `streamNodes == nullptr` | | Vulkan validation | not applicable (no AGC, shader or VideoOut files) | | Worktree after restoring | clean (`git status --porcelain` empty) | <details><summary>Probe output</summary> ``` 799: PROBE calls=1 arrayVisibleInCallback=0 1/1 Test #799: guest_sce_v2_locale .............. Passed 0.01 sec ``` </details> ## Negative control I restored `LocaleSupport.cpp`, `Api.hpp` and `GuestLocale.hpp` from `main` and kept the PR's test. The test no longer compiles, for example `error: '_ZNSt8__sce_v26locale5_InitEb_nid_postfix' was not declared in this scope`. So the control only shows that the test needs the new exports. It does not show that the test checks behaviour: the test leaves both node lists null, so it does not reach the ordering defect below. I then restored the merged files, rebuilt, and the three locale tests passed again. ## Findings ### Blocking - **`_Ios_base_dtor` runs the `erase_event` callbacks after it frees the `0x30` list** ([LocaleSupport.cpp#L830-L842](https://github.com/boykopovar/AnyPS5/blob/0176a0307b618e7192d943b5c9b59dd11f8cee46/core/libs/prx/libc/src/LocaleSupport.cpp#L830-L842)). - **What happens:** the loop at `core/libs/prx/libc/src/LocaleSupport.cpp:830-835` frees `streamNodes` and sets it to null. Only after that does the loop at `:836-842` invoke each callback. - **Who reported it:** B-Howell, with disassembly of PPSA08329's `libc.prx`. I add a local reproduction: the probe above prints `arrayVisibleInCallback=0`. - **It contradicts the PR's own debt entry:** the entry (`docs/dev/debt/libc.md:295`) says the console "calls the `0x38` callbacks, frees the `0x30`/`0x38` node lists". - **Why it matters:** an `erase_event` callback normally reads `iword`/`pword` to release what it stored there. - With this order the callback finds the array gone, so the value is lost. - If the callback calls `pword`, it gets a newly allocated node on a list the destructor has already processed, so that node leaks. - **A second problem:** each callback node is freed right after its call, while `self->callbackNodes` still points at the head of the list. A callback that walks or changes the callback list (for example through `register_callback` or `copyfmt`) would touch freed nodes. The console frees nothing until every callback has run. - **Suggested fix:** follow the Dinkumware `_Tidy` order: 1. Call every callback without freeing anything. 2. Free the `0x30` list and set it to null. 3. Free the `0x38` list and set it to null. 4. Release the locale. Add a test case that fills both lists and checks, inside the callback, that `streamNodes` is still set. ### Non-blocking - `_Facet_Register` (`core/libs/prx/libc/src/LocaleSupport.cpp:855-858`) accepts a null facet and registers duplicates. The unversioned `_ZNSt6locale5facet9_RegisterEv_nid_postfix` (`:748-755`) rejects both. Consider the same checks, so that a bad argument fails loudly instead of being recorded silently. - The test checks the destructor only with empty `0x30`/`0x38` lists, so the node-freeing and callback paths have no coverage at all. The blocking fix should add that coverage. ## Not verified - The NIDs, the layouts and the disassembly quoted from PPSA28416's `libc.prx`: I have no console binary here. - I did not check whether slot 8 behaves as on the console. On the console, a stream that `_Addstd` puts in slot 8 might be returned early by the destructor rather than torn down; the PR decrements its count and tears it down. - Windows and macOS builds. No title was run, and the title does not reach these imports anyway. ## To get this to a good state 1. Reorder `_Ios_base_dtor`: callbacks first, freeing nothing, then the `0x30` list, then the `0x38` list, then the locale. 2. Extend `GuestSceV2Locale.cpp` with a stream that has one `0x30` node and one callback node, and require that the callback runs once with `streamNodes` still set. Check that this new case fails against the current order. <!-- anyps5-bots job=2195 head=0176a0307b618e7192d943b5c9b59dd11f8cee46 -->
XairRrR commented 2026-11-02 22:33:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:33:12Z.

Review: APPROVED


Re-checked — approved

Commit f88d648692 changes _Ios_base_dtor so it runs every erase_event callback first, then frees the 0x30 list, then the 0x38 list. It also adds a test case that fails with the old order. This resolves the blocking finding from my last review.

What changed since my last review

  • One new commit, f88d648692 ("fix(libc): run ios_base callbacks before freeing the node lists"). The two earlier commits are unchanged (range-diff shows =).
  • LocaleSupport.cpp: the destructor now walks the 0x38 list and calls each callback without freeing anything. After that it frees the 0x30 list and the 0x38 list, then releases the locale. This is the Dinkumware _Tidy order from B-Howell's disassembly. It also matches the debt entry.
  • GuestSceV2Locale.cpp: a new case gives a stream one 0x30 node and one callback node with id 7. It requires that the callback runs exactly once and that streamNodes is still set while it runs. It also requires that both lists are null afterwards.

What I ran

Head f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0, merged with --no-ff into main 9090972b7e91fd266819cbd77a8b058e177b5682 (merged tree 21e38f43727e2cbc4cb4b4c3ce910083d5140bb6). Debian 13 VM, GCC 14.2.0, Release, Ninja, BUILD_TESTING=ON.

git diff 0176a0307b618e7192d943b5c9b59dd11f8cee46 f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0
git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0
python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale|guest_sce_v2_exceptions)$"
# negative control: LocaleSupport.cpp from the previously reviewed head 0176a0307b (old order), new test kept
git show 0176a0307b618e7192d943b5c9b59dd11f8cee46:core/libs/prx/libc/src/LocaleSupport.cpp > core/libs/prx/libc/src/LocaleSupport.cpp
ninja -C build -j32 -l32 guest_sce_v2_locale_tests
ctest --test-dir build --output-on-failure -R "^guest_sce_v2_locale$"
# restore
git show 21e38f43727e2cbc4cb4b4c3ce910083d5140bb6:core/libs/prx/libc/src/LocaleSupport.cpp > core/libs/prx/libc/src/LocaleSupport.cpp
ninja -C build -j32 -l32 libc guest_sce_v2_locale_tests guest_locale_tests guest_multibyte_locale_tests
ctest --test-dir build -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale)$"
git status --porcelain
Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Build (script) ok
Script test run No new failures and no timeouts. The known main failures (AGC denormal cases, guest_interfaces, unwrap_self and others) and the guest_net_ctl skip also occur on main.
guest_sce_v2_locale, guest_locale, guest_multibyte_locale, guest_sce_v2_exceptions 4/4 passed
Negative control (old destructor order, new test) guest_sce_v2_locale fails (Subprocess aborted)
After restoring 3/3 locale tests pass, and git status --porcelain is empty
Vulkan validation not applicable (no AGC, shader or VideoOut files)

Previous findings

  • Blocking: _Ios_base_dtor ran the callbacks after freeing the 0x30 list. Resolved. The callback loop is now at LocaleSupport.cpp#L830-L832, and it runs before both free loops at :833-844. Nothing is freed while a callback runs, so the second problem I raised (callback nodes freed while the head still pointed at them) is gone as well. The new test case aborts against the old order and passes with the new one.
  • Non-blocking: _Facet_Register accepts a null facet and duplicates. Still open. core/libs/prx/libc/src/LocaleSupport.cpp:857-860 is unchanged, while the unversioned _Register (:748) rejects both. This is not a merge blocker.
  • Non-blocking: the destructor test covered only empty node lists. Resolved. The new case fills both lists and checks the callback count, the id, and that both lists are null afterwards.

New findings

Blocking

None.

Non-blocking

None.

Not verified

  • The NIDs, the layouts and the disassembly quoted from PPSA28416's and PPSA08329's libc.prx. I have no console binary here.
  • Whether slot 8 behaves as on the console, as noted last time.
  • Windows and macOS builds. No title was run, and the title stops earlier at sceNpGetSandboxInfo.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5744380416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14585#pullrequestreview-5744380416). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T22:33:12Z. **Review:** APPROVED --- # Re-checked — approved Commit `f88d648692` changes `_Ios_base_dtor` so it runs every `erase_event` callback first, then frees the `0x30` list, then the `0x38` list. It also adds a test case that fails with the old order. This resolves the blocking finding from my last review. ## What changed since my last review - One new commit, `f88d648692` ("fix(libc): run ios_base callbacks before freeing the node lists"). The two earlier commits are unchanged (`range-diff` shows `=`). - `LocaleSupport.cpp`: the destructor now walks the `0x38` list and calls each callback without freeing anything. After that it frees the `0x30` list and the `0x38` list, then releases the locale. This is the Dinkumware `_Tidy` order from B-Howell's disassembly. It also matches the debt entry. - `GuestSceV2Locale.cpp`: a new case gives a stream one `0x30` node and one callback node with id 7. It requires that the callback runs exactly once and that `streamNodes` is still set while it runs. It also requires that both lists are null afterwards. ## What I ran Head `f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0`, merged with `--no-ff` into `main` `9090972b7e91fd266819cbd77a8b058e177b5682` (merged tree `21e38f43727e2cbc4cb4b4c3ce910083d5140bb6`). Debian 13 VM, GCC 14.2.0, Release, Ninja, `BUILD_TESTING=ON`. ``` git diff 0176a0307b618e7192d943b5c9b59dd11f8cee46 f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0 git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0 python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale|guest_sce_v2_exceptions)$" # negative control: LocaleSupport.cpp from the previously reviewed head 0176a0307b (old order), new test kept git show 0176a0307b618e7192d943b5c9b59dd11f8cee46:core/libs/prx/libc/src/LocaleSupport.cpp > core/libs/prx/libc/src/LocaleSupport.cpp ninja -C build -j32 -l32 guest_sce_v2_locale_tests ctest --test-dir build --output-on-failure -R "^guest_sce_v2_locale$" # restore git show 21e38f43727e2cbc4cb4b4c3ce910083d5140bb6:core/libs/prx/libc/src/LocaleSupport.cpp > core/libs/prx/libc/src/LocaleSupport.cpp ninja -C build -j32 -l32 libc guest_sce_v2_locale_tests guest_locale_tests guest_multibyte_locale_tests ctest --test-dir build -R "^(guest_sce_v2_locale|guest_locale|guest_multibyte_locale)$" git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Build (script) | ok | | Script test run | No new failures and no timeouts. The known `main` failures (AGC denormal cases, `guest_interfaces`, `unwrap_self` and others) and the `guest_net_ctl` skip also occur on `main`. | | `guest_sce_v2_locale`, `guest_locale`, `guest_multibyte_locale`, `guest_sce_v2_exceptions` | 4/4 passed | | Negative control (old destructor order, new test) | `guest_sce_v2_locale` fails (Subprocess aborted) | | After restoring | 3/3 locale tests pass, and `git status --porcelain` is empty | | Vulkan validation | not applicable (no AGC, shader or VideoOut files) | ## Previous findings - **Blocking: `_Ios_base_dtor` ran the callbacks after freeing the `0x30` list.** Resolved. The callback loop is now at [LocaleSupport.cpp#L830-L832](https://github.com/boykopovar/AnyPS5/blob/f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0/core/libs/prx/libc/src/LocaleSupport.cpp#L830-L832), and it runs before both free loops at `:833-844`. Nothing is freed while a callback runs, so the second problem I raised (callback nodes freed while the head still pointed at them) is gone as well. The new test case aborts against the old order and passes with the new one. - **Non-blocking: `_Facet_Register` accepts a null facet and duplicates.** Still open. `core/libs/prx/libc/src/LocaleSupport.cpp:857-860` is unchanged, while the unversioned `_Register` (`:748`) rejects both. This is not a merge blocker. - **Non-blocking: the destructor test covered only empty node lists.** Resolved. The new case fills both lists and checks the callback count, the id, and that both lists are null afterwards. ## New findings ### Blocking None. ### Non-blocking None. ## Not verified - The NIDs, the layouts and the disassembly quoted from PPSA28416's and PPSA08329's `libc.prx`. I have no console binary here. - Whether slot 8 behaves as on the console, as noted last time. - Windows and macOS builds. No title was run, and the title stops earlier at `sceNpGetSandboxInfo`. <!-- anyps5-bots job=2664 head=f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0 -->
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!14585
No description provided.