feat(libc): export the std::__sce_v2 _Makeloc family with the standard facet objects #16178

Merged
Danigamer05 merged 5 commits from upstream-pr/16178 into main 2026-11-17 20:52:57 +00:00
Danigamer05 commented 2026-11-05 19:58:41 +00:00 (Migrated from github.com)

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


What

Builds on #16165 and #15923: this branch contains their commits, and #16165 contains #16113. Until they merge, only the last commit is this PR's change.

Export the versioned std::__sce_v2 locale::_Locimp functions that build the standard facets of a locale, and the facet objects they install.

Export NID Original address Original size
_ZNSt8__sce_v26locale7_Locimp8_MakelocERKNS_8_LocinfoEiPS1_PKS0_ V-xbiecN6hk 0xF19F0 1268
_ZNSt8__sce_v26locale7_Locimp9_MakexlocERKNS_8_LocinfoEiPS1_PKS0_ vwBEHHisimo 0xF2980 1832
_ZNSt8__sce_v26locale7_Locimp9_MakewlocERKNS_8_LocinfoEiPS1_PKS0_ eluUL39Y-Aw 0xF4410 2956
_ZNSt8__sce_v26locale7_Locimp11_MakeushlocERKNS_8_LocinfoEiPS1_PKS0_ PSGlrerN-7s 0xF6600 3020

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

  • _Makeloc(info, category, self, locale) installs ctype<char>, num_get, num_put, numpunct and codecvt<char>, then calls the other three functions. It ORs the category into the mask, takes the name from the _Locinfo and returns self.
  • _Makexloc installs the remaining char facets, and _Makewloc and _Makeushloc install the wchar_t and unsigned short sets. The order is the module's, so facet ids are assigned in the same order. Together the four functions install 39 facets: 6 for ctype, 9 for numeric, 3 for collate, 3 for messages, 12 for monetary and 6 for time.
  • Without a source locale, each facet is allocated with the module's size and starts with no references. Its fields come from localeconv where the module reads them.
  • With a source locale, a facet comes from that locale, then from the global locale if the source is transparent, then from a default built once per facet type. A default keeps a reference of its own. Its numpunct uses . and ,, and its moneypunct uses the $+xv patterns. A bad locale name throws runtime_error, but only when a default has to be built.
  • The unsigned short numpunct, moneypunct and time_get facets own heap copies of their strings, and their destructors free them. A failed string allocation frees what was built and throws bad_alloc.

Only the retain, release, destroy and delete slots of these facets work. Every other virtual throws NotImplemented_nid_no_patch, so stream output through a locale built here stops at the first facet call. The classic _Locimp keeps its one-slot vector, so its users do not reach those virtuals. Implementing the virtuals by family and filling the classic locale are follow-ups.

The versioned _Facet_Register now prepends a {next, facet} node as the module does, and the versioned locale debt entry drops that sentence. A new debt entry lists what still differs.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, on top of #16165 (b24626696c2) and #15923 (aae14a4ddc6). The branch merges cleanly with main c4469b60daf. Exact tested commit: 67d850c1423.

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

  • The NID-patched libc contains the four new NIDs.

  • The new test checks:

    • how many facets each category and each function installs, the mask, the name and the references;
    • the sizes and fields of the ctype, codecvt, numpunct, moneypunct, time_get and time_put facets;
    • that moneypunct follows localeconv for digits, separators, patterns and the unsigned short strings;
    • sharing facets from a source locale and from the global locale, the default facets, their reuse and the reference they keep;
    • a bad name with and without a cached default;
    • that the last release frees every facet and string, and that a ctype frees a table it owns;
    • that a failed string allocation throws bad_alloc and frees the strings of the unfinished facet.
  • 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. Both sides' _Xbad_alloc and _Xruntime_error were redirected to one recorder, which exits by longjmp. The heap log stops at the failed allocation, because the longjmp skips the module's landing pads. Allocation failures were injected in calloc and in the facet vector, not in operator new. Both sides use the same fake _Locinfo, and the global locale was set with _Setgloballocale instead of the module's _Init.

  • Side by side with the patched production library, over two seeds with 200,000 random steps each: about 116,600 builds per seed (80,600 without a source locale and 36,000 with one), 3,900 bad_alloc throws, 116,600 deleted locales, 16,700 changes to localeconv's monetary and numeric fields, 16,600 changes of the global locale, 48,000 facet retains and releases, and 2,200 edits of destructor-owned fields. A default facet is built once per process, so 30 more processes ran with 6,000 steps and different seeds; they hit 56 bad names. Each build compared:

    • each slot's facet type, references and fields, comparing strings and tables by content;
    • the _Locimp's references, mask, name and count, and the id counter;
    • the sequence and sizes of malloc, calloc, realloc and free calls.

    The module's free(NULL) calls are ignored. No comparison differed across about 795,000 comparisons. The side-by-side run found one bug during development: the wide ctype destructor frees the table for any nonzero mode. #16165's side-by-side run also still passes with two seeds. The non-lifetime virtuals were not compared, because they throw here.

  • Negative control: seven changes were made one at a time:

    • _Makeloc did not update the mask;
    • a default facet was built without its default values;
    • the wide ctype freed its table only for a positive mode;
    • the unsigned short numpunct did not free one string;
    • a default facet did not keep its reference;
    • the moneypunct pattern index was wrong;
    • _Makewloc installed num_get<wchar_t> where num_put<wchar_t> goes.

    CTest failed on each. The side-by-side run reported differences on five and crashed on the other two (the missing reference and the wrong num_put step). The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the tests and side-by-side run passed again.

  • Code conventions and git diff --check pass.

  • tools/pr_overlap.py read 1,898 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 33 branches that already conflict with main. Merging each of the 33 with this branch and with main using git merge-tree adds no conflict block in the files this PR touches. For #5021, #9371, #9447 and #9526 the new debt entry lands inside the conflict block they already have in docs/dev/debt/libc.md. #13486 adds the unversioned names of these functions to another debt file, and no open PR adds the versioned names or NIDs. The debt position adds no conflict with the 141 open PRs that touch that file, apart from #16165, which this branch contains. 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, #16083, #16113 and #16165.

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: #15923, #16165
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5177839081 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16178). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-05T19:58:41Z. --- ### What Builds on #16165 and #15923: this branch contains their commits, and #16165 contains #16113. Until they merge, only the last commit is this PR's change. Export the versioned `std::__sce_v2` `locale::_Locimp` functions that build the standard facets of a locale, and the facet objects they install. | Export | NID | Original address | Original size | | --- | --- | --- | --- | | `_ZNSt8__sce_v26locale7_Locimp8_MakelocERKNS_8_LocinfoEiPS1_PKS0_` | `V-xbiecN6hk` | `0xF19F0` | 1268 | | `_ZNSt8__sce_v26locale7_Locimp9_MakexlocERKNS_8_LocinfoEiPS1_PKS0_` | `vwBEHHisimo` | `0xF2980` | 1832 | | `_ZNSt8__sce_v26locale7_Locimp9_MakewlocERKNS_8_LocinfoEiPS1_PKS0_` | `eluUL39Y-Aw` | `0xF4410` | 2956 | | `_ZNSt8__sce_v26locale7_Locimp11_MakeushlocERKNS_8_LocinfoEiPS1_PKS0_` | `PSGlrerN-7s` | `0xF6600` | 3020 | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). As in the module: - `_Makeloc(info, category, self, locale)` installs `ctype<char>`, `num_get`, `num_put`, `numpunct` and `codecvt<char>`, then calls the other three functions. It ORs the category into the mask, takes the name from the `_Locinfo` and returns `self`. - `_Makexloc` installs the remaining `char` facets, and `_Makewloc` and `_Makeushloc` install the `wchar_t` and `unsigned short` sets. The order is the module's, so facet ids are assigned in the same order. Together the four functions install 39 facets: 6 for `ctype`, 9 for `numeric`, 3 for `collate`, 3 for `messages`, 12 for `monetary` and 6 for `time`. - Without a source locale, each facet is allocated with the module's size and starts with no references. Its fields come from `localeconv` where the module reads them. - With a source locale, a facet comes from that locale, then from the global locale if the source is transparent, then from a default built once per facet type. A default keeps a reference of its own. Its `numpunct` uses `.` and `,`, and its `moneypunct` uses the `$+xv` patterns. A bad locale name throws `runtime_error`, but only when a default has to be built. - The `unsigned short` `numpunct`, `moneypunct` and `time_get` facets own heap copies of their strings, and their destructors free them. A failed string allocation frees what was built and throws `bad_alloc`. Only the retain, release, destroy and delete slots of these facets work. Every other virtual throws `NotImplemented_nid_no_patch`, so stream output through a locale built here stops at the first facet call. The classic `_Locimp` keeps its one-slot vector, so its users do not reach those virtuals. Implementing the virtuals by family and filling the classic locale are follow-ups. The versioned `_Facet_Register` now prepends a `{next, facet}` node as the module does, and the versioned locale debt entry drops that sentence. A new debt entry lists what still differs. ### 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`, on top of #16165 (`b24626696c2`) and #15923 (`aae14a4ddc6`). The branch merges cleanly with main `c4469b60daf`. Exact tested commit: `67d850c1423`. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_sce_v2_makeloc` passes, along with `guest_sce_v2_locimp_references`, `guest_sce_v2_locale`, `guest_sce_v2_locale_basics`, `guest_sce_v2_facet_ids`, `guest_locale`, `guest_sce_v2_exceptions` and `public_headers`. - The NID-patched libc contains the four new NIDs. - The new test checks: - how many facets each category and each function installs, the mask, the name and the references; - the sizes and fields of the `ctype`, `codecvt`, `numpunct`, `moneypunct`, `time_get` and `time_put` facets; - that `moneypunct` follows `localeconv` for digits, separators, patterns and the `unsigned short` strings; - sharing facets from a source locale and from the global locale, the default facets, their reuse and the reference they keep; - a bad name with and without a cached default; - that the last release frees every facet and string, and that a `ctype` frees a table it owns; - that a failed string allocation throws `bad_alloc` and frees the strings of the unfinished facet. - 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. Both sides' `_Xbad_alloc` and `_Xruntime_error` were redirected to one recorder, which exits by `longjmp`. The heap log stops at the failed allocation, because the `longjmp` skips the module's landing pads. Allocation failures were injected in `calloc` and in the facet vector, not in `operator new`. Both sides use the same fake `_Locinfo`, and the global locale was set with `_Setgloballocale` instead of the module's `_Init`. - Side by side with the patched production library, over two seeds with 200,000 random steps each: about 116,600 builds per seed (80,600 without a source locale and 36,000 with one), 3,900 `bad_alloc` throws, 116,600 deleted locales, 16,700 changes to `localeconv`'s monetary and numeric fields, 16,600 changes of the global locale, 48,000 facet retains and releases, and 2,200 edits of destructor-owned fields. A default facet is built once per process, so 30 more processes ran with 6,000 steps and different seeds; they hit 56 bad names. Each build compared: - each slot's facet type, references and fields, comparing strings and tables by content; - the `_Locimp`'s references, mask, name and count, and the id counter; - the sequence and sizes of `malloc`, `calloc`, `realloc` and `free` calls. The module's `free(NULL)` calls are ignored. No comparison differed across about 795,000 comparisons. The side-by-side run found one bug during development: the wide `ctype` destructor frees the table for any nonzero mode. #16165's side-by-side run also still passes with two seeds. The non-lifetime virtuals were not compared, because they throw here. - Negative control: seven changes were made one at a time: - `_Makeloc` did not update the mask; - a default facet was built without its default values; - the wide `ctype` freed its table only for a positive mode; - the `unsigned short` `numpunct` did not free one string; - a default facet did not keep its reference; - the `moneypunct` pattern index was wrong; - `_Makewloc` installed `num_get<wchar_t>` where `num_put<wchar_t>` goes. CTest failed on each. The side-by-side run reported differences on five and crashed on the other two (the missing reference and the wrong `num_put` step). The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the tests and side-by-side run passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,898 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 33 branches that already conflict with main. Merging each of the 33 with this branch and with main using `git merge-tree` adds no conflict block in the files this PR touches. For #5021, #9371, #9447 and #9526 the new debt entry lands inside the conflict block they already have in `docs/dev/debt/libc.md`. #13486 adds the unversioned names of these functions to another debt file, and no open PR adds the versioned names or NIDs. The debt position adds no conflict with the 141 open PRs that touch that file, apart from #16165, which this branch contains. 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, #16083, #16113 and #16165. 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: #15923, #16165 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-16 22:29:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T22:29:24Z.

Review: APPROVED


Reviewed — looks good

Nothing in the inspected changes blocks merging; the reported test results are author supplied, and this review did not run checks.

What I ran

Reviewed prepared diff for head f9d7de6cace80e7573b4125c4abf33482a9c92f1 and inspected targeted source context through repo_read.py. No build or tests were run.

Results

Check Result Note
Diff and targeted code review passed Inspected implementation and ownership paths
Build and tests not run Results in the description are author reported

Findings

Blocking

None identified in the code inspected.

Non-blocking

None.

Not verified

The full source contents of core/libs/prx/libc/CMakeLists.txt, core/libs/prx/libc/include/Api.hpp, core/libs/tests/GuestSceV2Makeloc.cpp, and docs/dev/debt/libc.md were not read; relevant diff portions were inspected. The rest of core/libs/prx/libc/src/LocaleSupport.cpp beyond inspected ranges was not read. The review manifest lists these five changed files as included; all five were represented in the prepared diff, but only LocaleSupport.cpp was read from the repository at head. Build, tests, console behavior, and author-reported experiments were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5928970376 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16178#pullrequestreview-5928970376). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T22:29:24Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the inspected changes blocks merging; the reported test results are author supplied, and this review did not run checks. ## What I ran Reviewed prepared diff for head `f9d7de6cace80e7573b4125c4abf33482a9c92f1` and inspected targeted source context through `repo_read.py`. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | Inspected implementation and ownership paths | | Build and tests | not run | Results in the description are author reported | ## Findings ### Blocking None identified in the code inspected. ### Non-blocking None. ## Not verified The full source contents of `core/libs/prx/libc/CMakeLists.txt`, `core/libs/prx/libc/include/Api.hpp`, `core/libs/tests/GuestSceV2Makeloc.cpp`, and `docs/dev/debt/libc.md` were not read; relevant diff portions were inspected. The rest of `core/libs/prx/libc/src/LocaleSupport.cpp` beyond inspected ranges was not read. The review manifest lists these five changed files as included; all five were represented in the prepared diff, but only `LocaleSupport.cpp` was read from the repository at head. Build, tests, console behavior, and author-reported experiments were not independently verified. ## To get this to a good state Nothing is required.
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!16178
No description provided.