feat(libc): export the std::__sce_v2 locale::global, empty, classic and _Locinfo category calls #16113

Merged
Danigamer05 merged 1 commit from upstream-pr/16113 into main 2026-11-05 22:33:32 +00:00
Danigamer05 commented 2026-11-05 17:41:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-05T17:41:28Z.


What

Export the versioned std::__sce_v2 locale::classic, locale::empty, locale::global, locale::_Setgloballocale, _Locimp::_New_Locimp(bool), _Locimp::_Clocptr, _sceLibcLocinfo, and the _Locinfo constructor and _Addcats that take a category, from libc.

Export NID Original address
_ZNSt8__sce_v26locale16_SetgloballocaleEPv kyDNldAZhv4 0xCFD50
_ZNSt8__sce_v26locale7classicEv f0KW1y+Ea0Q 0xCFE30
_ZNSt8__sce_v26locale5emptyEv KA0vt-WXdqQ 0xD0D90
_ZNSt8__sce_v26locale7_Locimp11_New_LocimpEb VUJZ+pCrRn4 0xD0DF0
_ZNSt8__sce_v26locale6globalERKS0_ v+WMV7IIp7w 0xF18A0
_ZNSt8__sce_v28_Locinfo13_Locinfo_ctorEPS0_iPKc 6cl-GjyMBbU 0xF27F0
_ZNSt8__sce_v28_Locinfo16_Locinfo_AddcatsEPS0_iPKc TM74yWf91xI 0xF2860
_ZNSt8__sce_v215_sceLibcLocinfoEPKc dJM+bL2BU9E 0xF28B0
_ZNSt8__sce_v26locale7_Locimp8_ClocptrE HWch8-MtqmQ 0x197900

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

They build on main's versioned locale, which shares the unversioned 0x30-byte _Locimp and has the classic locale ready from the start. As in the module:

  • classic() returns a static locale that holds the classic _Locimp, and _Clocptr points at that _Locimp;
  • empty() and _New_Locimp(bool) build a _Locimp with one reference, no facets, category 0 and the name *; empty() makes it transparent and _New_Locimp takes the flag;
  • _Setgloballocale stores the global _Locimp, and _Getgloballocale and _Init(bool) now return that global instead of the classic one, so they follow it once it changes; _Init still takes a reference when its flag is set;
  • global() returns the previous global through _Init(true). When the new locale differs, it releases the old global's reference, installs and retains the new one, and calls setlocale with its name for each category in its mask, or once for all six;
  • _sceLibcLocinfo throws runtime_error("bad locale name") unless the name is "" or "C". The two _Locinfo calls ignore the category, check the name the same way, and store setlocale(LC_ALL, nullptr); the constructor first stores the current name, and both store the classic name only after the check.

_Locimp_ctor and _Locimp_dtor are left for a follow-up, since they need reference counting in _Locimp_Addfac and _New_Locimp(const _Locimp&), which main does not do yet. A new debt entry records what differs here. The existing versioned locale entry now says _Init and _Getgloballocale return the global locale.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main d893997f1a6. Exact tested commit: d18e1c71325.

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

  • The NID-patched libc exports all 9 NIDs above.

  • The new test checks:

    • that classic(), _Clocptr, _Getgloballocale and _Init agree on the classic _Locimp;
    • the fields of the _Locimp that empty() and both _New_Locimp(bool) build;
    • the references global() takes and releases when it installs a locale, keeps the same one and restores the classic one;
    • that _Setgloballocale takes no reference, and that a null locale throws and keeps the global;
    • every field the _Locinfo calls write, for accepted names and four categories, and the bad locale name exception and the fields left for six rejected names.
  • 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. The module's heap is not set up outside a console process, so its allocation calls were redirected to the host's. Its _Xruntime_error and this branch's were both redirected to one recorder, so each side's rejections were compared by message.

  • Side by side with the patched production library, over two seeds with 20,000 trials each:

    • 60,000 calls per seed of the three name checks, with random names and categories (about 15,000 accepted, 45,000 rejected), compared by outcome and every field written;
    • the _Locimp that empty() and _New_Locimp build, compared field by field;
    • that classic(), _Clocptr, _Getgloballocale and _Init agree after the module's _Init built its classic locale;
    • 20,000 random global, _Setgloballocale, _Init and _Getgloballocale calls over the classic locale and six other _Locimps, with about 8,000 switches, of which about 3,300 global() calls changed the global. Each step compared the returned locale, the global and every reference count except the classic one's, which differs by design.

    No comparison differed.

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

    • the empty name was rejected;
    • global() kept the old global's reference;
    • empty() built an opaque _Locimp;
    • _Init(true) took no reference;
    • the _Locinfo constructor stored the classic name before checking the name.

    The new CTest failed on each, and the side-by-side run reported differences each time. 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,863 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 38 branches that already conflict with main. Merging each of the 38 with this branch and with main using git merge-tree gives the same conflict blocks, except in docs/dev/debt/libc.md for #5021, #9371, #9447 and #9526: their conflict block there already spans the end of the functional section, which holds the versioned locale entry this PR corrects, so the corrected line and the new entry next to it land inside it. The new entry adds no conflict with any of the 141 open PRs that touch that file. #13486 names the unversioned std::locale::_Setgloballocale in libSceLibcInternal, not these exports. No open PR adds these names or NIDs. The branch also merges cleanly with #14595, #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667, #15683, #15791, #15796, #15809, #15834, #15879, #15923 and #16083.

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:5176001558 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16113). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-05T17:41:28Z. --- ### What Export the versioned `std::__sce_v2` `locale::classic`, `locale::empty`, `locale::global`, `locale::_Setgloballocale`, `_Locimp::_New_Locimp(bool)`, `_Locimp::_Clocptr`, `_sceLibcLocinfo`, and the `_Locinfo` constructor and `_Addcats` that take a category, from libc. | Export | NID | Original address | | --- | --- | --- | | `_ZNSt8__sce_v26locale16_SetgloballocaleEPv` | `kyDNldAZhv4` | `0xCFD50` | | `_ZNSt8__sce_v26locale7classicEv` | `f0KW1y+Ea0Q` | `0xCFE30` | | `_ZNSt8__sce_v26locale5emptyEv` | `KA0vt-WXdqQ` | `0xD0D90` | | `_ZNSt8__sce_v26locale7_Locimp11_New_LocimpEb` | `VUJZ+pCrRn4` | `0xD0DF0` | | `_ZNSt8__sce_v26locale6globalERKS0_` | `v+WMV7IIp7w` | `0xF18A0` | | `_ZNSt8__sce_v28_Locinfo13_Locinfo_ctorEPS0_iPKc` | `6cl-GjyMBbU` | `0xF27F0` | | `_ZNSt8__sce_v28_Locinfo16_Locinfo_AddcatsEPS0_iPKc` | `TM74yWf91xI` | `0xF2860` | | `_ZNSt8__sce_v215_sceLibcLocinfoEPKc` | `dJM+bL2BU9E` | `0xF28B0` | | `_ZNSt8__sce_v26locale7_Locimp8_ClocptrE` | `HWch8-MtqmQ` | `0x197900` | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). They build on main's versioned locale, which shares the unversioned `0x30`-byte `_Locimp` and has the classic locale ready from the start. As in the module: - `classic()` returns a static `locale` that holds the classic `_Locimp`, and `_Clocptr` points at that `_Locimp`; - `empty()` and `_New_Locimp(bool)` build a `_Locimp` with one reference, no facets, category 0 and the name `*`; `empty()` makes it transparent and `_New_Locimp` takes the flag; - `_Setgloballocale` stores the global `_Locimp`, and `_Getgloballocale` and `_Init(bool)` now return that global instead of the classic one, so they follow it once it changes; `_Init` still takes a reference when its flag is set; - `global()` returns the previous global through `_Init(true)`. When the new locale differs, it releases the old global's reference, installs and retains the new one, and calls `setlocale` with its name for each category in its mask, or once for all six; - `_sceLibcLocinfo` throws `runtime_error("bad locale name")` unless the name is `""` or `"C"`. The two `_Locinfo` calls ignore the category, check the name the same way, and store `setlocale(LC_ALL, nullptr)`; the constructor first stores the current name, and both store the classic name only after the check. `_Locimp_ctor` and `_Locimp_dtor` are left for a follow-up, since they need reference counting in `_Locimp_Addfac` and `_New_Locimp(const _Locimp&)`, which main does not do yet. A new debt entry records what differs here. The existing versioned locale entry now says `_Init` and `_Getgloballocale` return the global locale. ### 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 `d893997f1a6`. Exact tested commit: `d18e1c71325`. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_sce_v2_locale_basics` passes, along with `guest_sce_v2_locale`, `guest_locale` and `guest_sce_v2_exceptions`. - The NID-patched libc exports all 9 NIDs above. - The new test checks: - that `classic()`, `_Clocptr`, `_Getgloballocale` and `_Init` agree on the classic `_Locimp`; - the fields of the `_Locimp` that `empty()` and both `_New_Locimp(bool)` build; - the references `global()` takes and releases when it installs a locale, keeps the same one and restores the classic one; - that `_Setgloballocale` takes no reference, and that a null locale throws and keeps the global; - every field the `_Locinfo` calls write, for accepted names and four categories, and the `bad locale name` exception and the fields left for six rejected names. - 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. The module's heap is not set up outside a console process, so its allocation calls were redirected to the host's. Its `_Xruntime_error` and this branch's were both redirected to one recorder, so each side's rejections were compared by message. - Side by side with the patched production library, over two seeds with 20,000 trials each: - 60,000 calls per seed of the three name checks, with random names and categories (about 15,000 accepted, 45,000 rejected), compared by outcome and every field written; - the `_Locimp` that `empty()` and `_New_Locimp` build, compared field by field; - that `classic()`, `_Clocptr`, `_Getgloballocale` and `_Init` agree after the module's `_Init` built its classic locale; - 20,000 random `global`, `_Setgloballocale`, `_Init` and `_Getgloballocale` calls over the classic locale and six other `_Locimp`s, with about 8,000 switches, of which about 3,300 `global()` calls changed the global. Each step compared the returned locale, the global and every reference count except the classic one's, which differs by design. No comparison differed. - Negative control: five lines were altered one at a time: - the empty name was rejected; - `global()` kept the old global's reference; - `empty()` built an opaque `_Locimp`; - `_Init(true)` took no reference; - the `_Locinfo` constructor stored the classic name before checking the name. The new CTest failed on each, and the side-by-side run reported differences each time. 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,863 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 38 branches that already conflict with main. Merging each of the 38 with this branch and with main using `git merge-tree` gives the same conflict blocks, except in `docs/dev/debt/libc.md` for #5021, #9371, #9447 and #9526: their conflict block there already spans the end of the functional section, which holds the versioned locale entry this PR corrects, so the corrected line and the new entry next to it land inside it. The new entry adds no conflict with any of the 141 open PRs that touch that file. #13486 names the unversioned `std::locale::_Setgloballocale` in `libSceLibcInternal`, not these exports. No open PR adds these names or NIDs. The branch also merges cleanly with #14595, #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667, #15683, #15791, #15796, #15809, #15834, #15879, #15923 and #16083. 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!16113
No description provided.