feat(libc): fill the std::__sce_v2 classic locale with its facets #17610

Open
Danigamer05 wants to merge 51 commits from upstream-pr/17610 into main
Danigamer05 commented 2026-11-09 02:12:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-09T02:12:25Z.


What

Builds on #17607: this branch contains its commits, and through them #17578, #17568, #17539, #17331, #17296, #17277, #16975, #16949, #16944, #16924, #16919, #16560, #16516, #16214, #16178 and #15923, with current main. It needs the facets those PRs implement, so it cannot stand alone. Until they merge, only the last commit is this PR's change.

Give std::__sce_v2's classic locale its facets, as the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6) does. Until now the versioned classic locale, global locale, _Locimp::_Clocptr and _sceLibcClassicLocale were all the unversioned classic _Locimp, which holds no std::__sce_v2 facet. use_facet built each facet the first time a stream asked for it, so formatting worked. But has_facet and the facet vector of locale::classic() found nothing, and the facet ids depended on the order in which a title first used each facet.

What the module does, read from the disassembly of locale::_Init (0xCFE60), classic (0xCFE30), _Getgloballocale (0xCFD40), _Setgloballocale (0xCFD50) and the library's static initializer (0xF2940):

  • When the library loads, its static initializer calls _Init(true) and keeps the result in _sceLibcClassicLocale.

  • The first _Init fills a static classic _Locimp, made with the name *, with 25 facets in this order:

    • char: ctype, num_get, num_put, numpunct, codecvt, collate, messages, money_get, money_put, both moneypunct, time_get and time_put;
    • wchar_t: the same, without codecvt.

    So these facets take ids 1 to 25. Each facet holds two references and the vector has 40 slots.

  • It then names the locale C, gives it every category, and retains it twice. It makes it the global locale and stores it as _Clocptr and as the object classic() returns.

This PR builds the same locale on the first locale call or facet id assignment, which every facet use goes through. It then reaches the state the module has after loading: the 25 facets with two references each in ids 1 to 25, codecvt<wchar_t> and the unsigned short facets left to _Makeloc, name C, categories 0x3F, and four references, counting the one _sceLibcClassicLocale keeps. _Clocptr, _sceLibcClassicLocale and classic() point to that object from the start. _Getgloballocale, _Setgloballocale, global and the transparent-locale fallback of use_facet build it before they use the global locale. The unversioned classic locale is unchanged.

The _Makeloc debt entry records that the facets arrive on first use instead of at load.

Tested

Windows 11, MinGW GCC 15.2, Release, head on top of #17607. Not run on Linux or macOS. Not run in a title: PPSA03671 ships its own libc.prx, which AnyPS5 converts and looks up before this library, so its std::__sce_v2 calls never reach this code.

  • guest_sce_v2_locale_basics now checks the classic locale's facets, references, name, categories and ids. guest_sce_v2_locimp_references now takes the classic locale's own vtable for copies, and keeps its borrowed-vector case on the unversioned classic locale, the only one that still has that static vector.
  • Differential harness against the module's own code, loaded and relocated, with the module's static initializer run first.
    • Before and after _Init(true), it compares the classic locale's references, slot count, category, name, the facets present with their references, and the ids of ctype<char>, ctype<wchar_t>, codecvt<wchar_t>, num_put<char> and time_put<wchar_t>. It also checks _Init, _Getgloballocale, classic(), _Clocptr and _sceLibcClassicLocale, which all give the same object.
    • It changes the classic numpunct<char>'s decimal point and prints a double through a stream on the classic locale and on a transparent empty() locale. It then moves the global locale to a copy and back with global, compares the references of the classic locale, the copy and the facet, and prints again after the switch.
    • Both libraries give identical output.
  • The facet harnesses of #16516 to #17607, 20,000 calls each for char and wchar_t and again for unsigned short: 0 differences.
  • The libc tests built from this head, without the tests that drive the GPU, audio, video or controllers (208): all pass, with guest_fopen_errors skipped.
  • check_conventions, git diff --check: clean. Merges cleanly with main.
  • pr_overlap reports no open PR with the same functions or conflicting code. It could not compare 48 PRs that conflict with main on shared files. None of the 4 that touch LocaleSupport.cpp (#9526, #11172, #12518 and #12704) touches the versioned classic or global locale.

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: #17607
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5217606574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17610). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-09T02:12:25Z. --- ### What Builds on #17607: this branch contains its commits, and through them #17578, #17568, #17539, #17331, #17296, #17277, #16975, #16949, #16944, #16924, #16919, #16560, #16516, #16214, #16178 and #15923, with current `main`. It needs the facets those PRs implement, so it cannot stand alone. Until they merge, only the last commit is this PR's change. Give `std::__sce_v2`'s classic locale its facets, as the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`) does. Until now the versioned classic locale, global locale, `_Locimp::_Clocptr` and `_sceLibcClassicLocale` were all the unversioned classic `_Locimp`, which holds no `std::__sce_v2` facet. `use_facet` built each facet the first time a stream asked for it, so formatting worked. But `has_facet` and the facet vector of `locale::classic()` found nothing, and the facet ids depended on the order in which a title first used each facet. What the module does, read from the disassembly of `locale::_Init` (`0xCFE60`), `classic` (`0xCFE30`), `_Getgloballocale` (`0xCFD40`), `_Setgloballocale` (`0xCFD50`) and the library's static initializer (`0xF2940`): - When the library loads, its static initializer calls `_Init(true)` and keeps the result in `_sceLibcClassicLocale`. - The first `_Init` fills a static classic `_Locimp`, made with the name `*`, with 25 facets in this order: - `char`: `ctype`, `num_get`, `num_put`, `numpunct`, `codecvt`, `collate`, `messages`, `money_get`, `money_put`, both `moneypunct`, `time_get` and `time_put`; - `wchar_t`: the same, without `codecvt`. So these facets take ids 1 to 25. Each facet holds two references and the vector has 40 slots. - It then names the locale `C`, gives it every category, and retains it twice. It makes it the global locale and stores it as `_Clocptr` and as the object `classic()` returns. This PR builds the same locale on the first locale call or facet id assignment, which every facet use goes through. It then reaches the state the module has after loading: the 25 facets with two references each in ids 1 to 25, `codecvt<wchar_t>` and the `unsigned short` facets left to `_Makeloc`, name `C`, categories `0x3F`, and four references, counting the one `_sceLibcClassicLocale` keeps. `_Clocptr`, `_sceLibcClassicLocale` and `classic()` point to that object from the start. `_Getgloballocale`, `_Setgloballocale`, `global` and the transparent-locale fallback of `use_facet` build it before they use the global locale. The unversioned classic locale is unchanged. The `_Makeloc` debt entry records that the facets arrive on first use instead of at load. ### 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, MinGW GCC 15.2, Release, head on top of #17607. Not run on Linux or macOS. Not run in a title: PPSA03671 ships its own `libc.prx`, which AnyPS5 converts and looks up before this library, so its `std::__sce_v2` calls never reach this code. - `guest_sce_v2_locale_basics` now checks the classic locale's facets, references, name, categories and ids. `guest_sce_v2_locimp_references` now takes the classic locale's own vtable for copies, and keeps its borrowed-vector case on the unversioned classic locale, the only one that still has that static vector. - Differential harness against the module's own code, loaded and relocated, with the module's static initializer run first. - Before and after `_Init(true)`, it compares the classic locale's references, slot count, category, name, the facets present with their references, and the ids of `ctype<char>`, `ctype<wchar_t>`, `codecvt<wchar_t>`, `num_put<char>` and `time_put<wchar_t>`. It also checks `_Init`, `_Getgloballocale`, `classic()`, `_Clocptr` and `_sceLibcClassicLocale`, which all give the same object. - It changes the classic `numpunct<char>`'s decimal point and prints a `double` through a stream on the classic locale and on a transparent `empty()` locale. It then moves the global locale to a copy and back with `global`, compares the references of the classic locale, the copy and the facet, and prints again after the switch. - Both libraries give identical output. - The facet harnesses of #16516 to #17607, 20,000 calls each for `char` and `wchar_t` and again for `unsigned short`: 0 differences. - The libc tests built from this head, without the tests that drive the GPU, audio, video or controllers (208): all pass, with `guest_fopen_errors` skipped. - `check_conventions`, `git diff --check`: clean. Merges cleanly with `main`. - `pr_overlap` reports no open PR with the same functions or conflicting code. It could not compare 48 PRs that conflict with `main` on shared files. None of the 4 that touch `LocaleSupport.cpp` (#9526, #11172, #12518 and #12704) touches the versioned classic or global locale. ### 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: #17607 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-20 11:50:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:50:49Z.

Review: APPROVED


Reviewed — looks good

The changed locale initialization and facet registration are consistent with the described classic-locale state; no blocking defect was verified in the source and tests reviewed.

What I ran

No commands or tests were run. Inspected the prepared diff at head 7a47c466550322502e069127e765449611048d77 and targeted source context with the PR reader. The description reports Windows 11/MinGW testing and differential harness results; these were not independently run.

Results

Check Result Note
Source review passed Initialization and locale callers inspected
Tests in this session not run Author-reported results only
Console behavior not verified Description says no title run

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read the complete diff and all 18 changed files listed as included in the manifest: core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/GuestLocale.hpp, core/libs/prx/libc/src/LocaleSupport.cpp, the 14 changed core/libs/tests/GuestSceV2*.cpp files, and docs/dev/debt/libc.md. The manifest marked all changed files included; no changed file was excluded. Targeted source ranges were additionally read for locale initialization, facet ID assignment, installation, global switching, and the modified locale tests. No build, test suite, Linux/macOS run, or console run was performed here.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5992205239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17610#pullrequestreview-5992205239). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T11:50:49Z. **Review:** APPROVED --- # Reviewed — looks good The changed locale initialization and facet registration are consistent with the described classic-locale state; no blocking defect was verified in the source and tests reviewed. ## What I ran No commands or tests were run. Inspected the prepared diff at head `7a47c466550322502e069127e765449611048d77` and targeted source context with the PR reader. The description reports Windows 11/MinGW testing and differential harness results; these were not independently run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Initialization and locale callers inspected | | Tests in this session | not run | Author-reported results only | | Console behavior | not verified | Description says no title run | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read the complete diff and all 18 changed files listed as included in the manifest: `core/libs/prx/libc/CMakeLists.txt`, `core/libs/prx/libc/include/GuestLocale.hpp`, `core/libs/prx/libc/src/LocaleSupport.cpp`, the 14 changed `core/libs/tests/GuestSceV2*.cpp` files, and `docs/dev/debt/libc.md`. The manifest marked all changed files included; no changed file was excluded. Targeted source ranges were additionally read for locale initialization, facet ID assignment, installation, global switching, and the modified locale tests. No build, test suite, Linux/macOS run, or console run was performed here. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-21 07:13:25 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — comments

The review is incomplete because only selected changed lines and source ranges were read; the remaining changed behavior was not verified.

What I ran

Reviewed head dc68baffe91c2c3b85d3317c89b6f8386f283c9b from the prepared bundle. No commands or tests were run.

Results

Check Result Note
Bundle and change summary passed Description, commits and diff inspected
Targeted source review passed Locale initialization and facet lookup inspected
Full changed-line review not run Not every changed line was read
Tests not run Author-reported results were not independently run

Findings

Blocking

None identified in the inspected lines.

Non-blocking

None.

Not verified

The bundle lists 19 changed files; I read the description, commits, review README, manifest, selected diff ranges, and targeted ranges in core/libs/prx/libc/src/LocaleSupport.cpp. I did not read every changed line or the full contents of the changed test files, core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/GuestLocale.hpp, or docs/dev/debt/libc.md. Their behavior is not verified. No tests or build checks were run.

To get this to a good state

Complete the changed-line review and run the applicable checks before making a formal review decision.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6003743332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17610#pullrequestreview-6003743332). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T07:13:25Z. **Review:** COMMENTED --- # Reviewed — comments The review is incomplete because only selected changed lines and source ranges were read; the remaining changed behavior was not verified. ## What I ran Reviewed head `dc68baffe91c2c3b85d3317c89b6f8386f283c9b` from the prepared bundle. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Bundle and change summary | passed | Description, commits and diff inspected | | Targeted source review | passed | Locale initialization and facet lookup inspected | | Full changed-line review | not run | Not every changed line was read | | Tests | not run | Author-reported results were not independently run | ## Findings ### Blocking None identified in the inspected lines. ### Non-blocking None. ## Not verified The bundle lists 19 changed files; I read the description, commits, review README, manifest, selected diff ranges, and targeted ranges in `core/libs/prx/libc/src/LocaleSupport.cpp`. I did not read every changed line or the full contents of the changed test files, `core/libs/prx/libc/CMakeLists.txt`, `core/libs/prx/libc/include/GuestLocale.hpp`, or `docs/dev/debt/libc.md`. Their behavior is not verified. No tests or build checks were run. ## To get this to a good state Complete the changed-line review and run the applicable checks before making a formal review decision.
ligmaSec commented 2026-12-03 13:12:38 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Built the branch’s locale implementation and matching headers against the existing Linux runtime, with the branch’s SceV2 exception assembly linked into the fixture. The focused locale-basics test passed.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6170471486 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17610#pullrequestreview-6170471486). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:12:38Z. **Review:** COMMENTED --- Built the branch’s locale implementation and matching headers against the existing Linux runtime, with the branch’s SceV2 exception assembly linked into the fixture. The focused locale-basics test passed. 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/17610:upstream-pr/17610'
git switch 'upstream-pr/17610'

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