feat(libSceLibcInternal): complete global locale lifecycle #22370
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22370"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-11-17T13:10:43Z.
What
Implements three unversioned locale exports of
libSceLibcInternalincore/libs/prx/libSceLibcInternal/LocaleObjects.cppbacked by shared unversioned global-locale state and_Locimpvtable helpers incore/libs/prx/libc/src/LocaleSupport.cpp:_ZNSt6locale6globalERKS_(ptwhA0BQVeE): validates arguments, checks non-"*"locale names withsetlocale_nid_postfix, swapsg_globalLocaleunderg_localeInitMutexand transfers the previous global reference to the returned locale viasret(GuestLocaleFacade*). Swapping to the existing global locale retains an additional reference for the returned locale. Updates_ZNSt6locale5_InitEvand_ZNSt6locale16_GetgloballocaleEvto readg_globalLocaleinstead of hardcoding&g_classicLocale, without alteringstd::__sce_v2._ZNSt6locale7_LocimpC2Eb(zrmR88ClfOs): initializesGuestLocale::ImplementationwithLibcLocimpVtable_nid_no_patch(),references = 1,facets = nullptr,facetCount = 0,category = 0,transparent, andname = "*";DestroyLocimp/DeleteLocimpreleasefacetsviaApplicationHeapFree_nid_no_patchand deleteselfvia_ZdlPv_nid_postfix._ZNSt8_LocinfoC1EiPKc(L1Ze94yof2I): validatesselfand STL_M_*category bitmasks0..0x3f(_X_COLLATE.._X_MESSAGES), then delegates"C"validation and 64-byte initialization to_ZNSt8_LocinfoC1EPKc_nid_postfix.Sources: Microsoft STL commit
165a67afdd(xlocale,xlocinfo,locale0.cpp,locale.cpp), C++[locale.statics], and existingGuestLocalestructures incore/libs/prx/libc/include/GuestLocale.hpp. The_Locinfo(int, const char*)overload and STL category mask definitions are cited at pinned xlocinfo lines 28–44 and 259–270. Known limits (not verified against consolelibSceLibcInternal.sprxdisassembly,_Locimpfreesfacetswithout per-facet decref to match_Locimp::_Addfac, only"C"supported) are recorded indocs/dev/debt/changes/feat-libcinternal-locale-state.md. The category effect is not independently observable with only"C"supported. When a stream's transparent locale falls back to the global one, the lookup retains the global_Locimpthrough aGuestLocale::GlobalLocaleHold(LibcAcquireGlobalLocale_nid_no_patchunderg_localeInitMutex, released through the vtable when the hold leaves scope). Each caller keeps the hold for as long as it uses the facet, so a concurrentlocale::globalfollowed by the destruction of the previous locale cannot free it underneath. This covers the libc stream helpers,TimeGetFields.cppandNumGet.cpp._Getgloballocaleitself still returns a borrowed pointer, as the console export does.Tested
At head
c4c91b1c38:guest_libc_internal_locale_state3/3, and^guest_(libc|exception)108/108.CheckGlobalFacetHeldAcrossSwapholds a facet of global locale A, swaps the global to B and destroys the returned A, then requires that A and its facet vector are still alive and that the facet still reads its value; releasing the hold frees A exactly once. With the retain removed fromLibcAcquireGlobalLocale_nid_no_patchit fails on "held global locale A must not be freed after the swap".guest_libc_internal_locale_state3/3.Earlier runs:
Coordinator final verification at
17437fc05514104ea1114ad13a1793a6eb196e37: focused rebuild (nice -n 19,--parallel 7), three repeated locale-state runs including two concurrent swap/consumer threads (300 iterations each), and the 13-test neighbor suite all passed. Conventions/header audit/diff checks passed. Clean merge-tree against upstream/main9dcf9837ff7b7d51cdfa9057b0ad5ed2ac0fd651; fresh names scan examined all 1689 open PRs with no competing implementation.guest_libc_internal_locale_state(3/3consecutive runs passed,0.01 seach), covering_LocimpC2Eb(false/true)with guard canaries and_Addfacheap cleanup,_LocinfoC1EiPKcacross single and combined category masks (0..0x3f) and invalid category/name errors, andlocale::globaltransitions (classic -> A -> B -> B -> classic) verified through_Getgloballocale,_Init,sretlifetime after caller releases,num_put<char>formatting ("1.5"/"1,5"/"1;5"), and negative-input state preservation.13/13passed,0.24 s):patched_libraries(libSceLibcInternal.prxexportsptwhA0BQVeE,zrmR88ClfOs,L1Ze94yof2I),guest_sce_v2_locale_basics,guest_locale,guest_rune_locale,guest_sce_v2_locale,guest_libc_internal_num_get,guest_libc_internal_numpunct,guest_libc_internal_wide_numpunct,guest_libc_internal_time_get,guest_time_get_order,guest_libc_internal_locale_objects,guest_libc_internal_locale_state, andguest_libc_internal_time_get_fields.core/libs/prx/libSceLibcInternal/LocaleObjects.cpp): bypassing global swap in_ZNSt6locale6globalERKS__nid_postfixfailedguest_libc_internal_locale_state(exit 8, aborting onglobal(A) retains A while caller holds A); ignoringcategoryin_ZNSt8_LocinfoC1EiPKc_nid_postfixfailed (exit 8, aborting on_LocinfoC1EiPKc rejects invalid category); byte-exact restore (sha256verified) and 3/3 positive re-runs passed.python3 tools/check_conventions.py --base upstream/mainpassed (All conventions checks passed.);python3 core/libs/tests/test_public_headers.py --audit-onlypassed (413 libraries, 34705 exports);git diff --checkclean; scratchdebt_fold.py --checkexcludingmain's pre-existingfix-libc-wcstombs-zero-capacity.mdduplicate exited0.Checked on November 18, 2026: head
41a8dec3df970b72ef15e78e73de75203eca0499has a clean merge withmainat02650d94a5f171dc333d13fc5abed43faf440a1aand passesgit diff --check. The current code also validates the facet vector and reads the locale name through the guest string helper. The detailed focused runs above are from the stated historical head.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T13:35:03Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
17437fc055:tools/check_conventions.pypassed.guest_libc_internal_locale_state_testsbuilt cleanly.guest_libc_internal_locale_state):core/libs/prx/libSceLibcInternal/InventoryExports6.cpp,core/libs/prx/libSceLibcInternal/LocaleObjects.cpp,core/libs/prx/libSceLibcInternal/TimeGetFields.cpp,core/libs/prx/libSceLibcInternal/include/Api.hpp,core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T21:47:41Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
41a8dec3df:tools/check_conventions.pypassed.guest_libc_internal_locale_state_testsbuilt cleanly.guest_libc_internal_locale_state):core/libs/prx/libSceLibcInternal/InventoryExports6.cpp,core/libs/prx/libSceLibcInternal/LocaleObjects.cpp,core/libs/prx/libSceLibcInternal/TimeGetFields.cpp,core/libs/prx/libSceLibcInternal/include/Api.hpp,core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T21:55:37Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
41a8dec3df970b72ef15e78e73de75203eca0499using the prepared diff and pinned repository reader (repo_read.py). No commands or tests were run. The description reports historical Linux tests at a prior head; those results were not independently verified here.Results
Findings
Blocking
None.
Non-blocking
LibcFindGlobalFacet_nid_no_patchprotects the facet-vector lookup with the mutex, then returns a borrowed facet pointer. A concurrent global-locale swap can release the old implementation and free its facet vector after the lock is released, while the consumer still uses that facet (core/libs/prx/libc/src/LocaleSupport.cpp:2063). The debt note documents this lifetime limitation. Consider retaining the selected facet or otherwise extending the locale lifetime across use.Not verified
No build, tests, or console behavior were run. The description’s test claims concern historical head
17437fc05514104ea1114ad13a1793a6eb196e37, not the reviewed head. All changed files listed in the manifest were included; the prepared diff excludes lockfiles, minified files,dist/,build/, and.svgfiles by rule. No additional excluded changed files were listed.To get this to a good state
Nothing is required. Optional: extend ownership of the borrowed facet pointer across its use during concurrent locale swaps.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T04:14:31Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f2de27a74e:tools/check_conventions.pypassed.guest_libc_internal_locale_state_testsbuilt cleanly.guest_libc_internal_locale_state):core/libs/prx/libSceLibcInternal/InventoryExports6.cpp,core/libs/prx/libSceLibcInternal/LocaleObjects.cpp,core/libs/prx/libSceLibcInternal/TimeGetFields.cpp,core/libs/prx/libSceLibcInternal/include/Api.hpp,core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T05:54:33Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: ensure a locale and its facets remain alive for the full duration of concurrent reads during global locale swaps.
What I ran
Reviewed head
f2de27a74e1ea4682ee88c3fce1e3fb7971b1dd0from the prepared diff and repository reader. No commands or tests were run.Results
Findings
Blocking
core/libs/prx/libc/src/LocaleSupport.cpp:255returns a borrowed facet pointer after releasingg_localeInitMutex. A concurrent swap can release and destroy the previous locale, freeing its facet vector while the caller is still using the returned facet. The changedNumGet.cppfallback still reads global locale state without this helper, and the existing consumers use the facet after lookup. Protect the locale and facet lifetime through consumption, or retain the relevant locale/facet before releasing the lock. The swap path must also correctly transfer or release the old global reference; the current changed logic retains the incoming locale but returns the outgoing locale without releasing the global ownership reference.Non-blocking
None.
Not verified
No tests were run, and the claimed build and focused runs were reported by the author/coordinator rather than performed in this review. The full text of all nine changed files was included in the review bundle; targeted reads were made of the changed locale implementation, its facet consumers, and lifecycle test. Other changed-file context was not read. Excluded files: none were listed in the manifest.
To get this to a good state
Make global locale replacement and concurrent facet consumption preserve ownership for the full read, then rerun the locale-state and neighbor tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T13:13:43Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
c4c91b1c380c12584757871e44166e3aeae85d95usingrepo_read.py. I did not run commands or tests; the test results below are author-reported. I read the prepared description, commits, manifest, and diff, then targeted source ranges for the lifecycle implementation and its consumers.Results
Findings
Blocking
None.
Non-blocking
locale::globalvalidates and applies a named locale withsetlocalebefore acquiring the mutex and swapping the global locale (core/libs/prx/libc/src/LocaleSupport.cpp:2112). Concurrent calls can therefore interleave their C locale changes with a different global-locale swap. Consider moving locale validation/application into the same critical section or otherwise synchronizing it with swaps. This is not confirmed as a defect for the supportedClocale, but merits attention if support expands.Not verified
The console
_Locimpvtable and ownership behavior were not checked against console binary disassembly, as recorded in the change description. I did not run the reported Linux or Windows tests, negative controls, or build checks.files.jsonwas not available through the reader, so the excluded-file list could not be checked. All 11 changed paths in the manifest are marked included; I read the full changed contents forLocaleObjects.cpp,GuestLocale.hpp,GuestLibcInternalLocaleState.cpp, and the debt note, plus relevant ranges ofCMakeLists.txt,NumGet.cpp,TimeGetFields.cpp, andLocaleSupport.cpp. I reviewed the diff forInventoryExports6.cpp,Api.hpp, andInventoryExports6.hppbut did not read their full head contents.To get this to a good state
Nothing is required. Optional: synchronize locale validation/application with the global swap if named locale support is extended beyond
C.Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T13:14:15Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
c4c91b1c38:tools/check_conventions.pypassed.guest_libc_internal_locale_state_testsbuilt cleanly.guest_libc_internal_locale_state):core/libs/prx/libSceLibcInternal/InventoryExports6.cpp,core/libs/prx/libSceLibcInternal/LocaleObjects.cpp,core/libs/prx/libSceLibcInternal/NumGet.cpp,core/libs/prx/libSceLibcInternal/TimeGetFields.cpp,core/libs/prx/libSceLibcInternal/include/Api.hpp,core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T00:27:00Z.
Review: COMMENTED
Reviewed — comments
The review covers head
04ddb983b2ff0685b5fc964f9c0667a014f362cf; no verified blocking defect was found, but I did not run the reported checks or independently verify console ABI behavior, so a formal approval is not justified.What I ran
Read the prepared diff and changed files using
repo_read.pyat the pinned head. I ran no build, tests, or other programmatic checks. The test results in the PR description are author-reported and refer to earlier revisions.Results
Findings
Blocking
None.
Non-blocking
_Locimpvtable and facet-vector ownership behavior are based on Microsoft STL and the project's modeled ABI; the PR notes they were not verified against console disassembly. Verify this against the console implementation when that evidence is available.Not verified
libSceLibcInternal.sprxbehavior and ABI were not independently confirmed.core/libs/prx/libSceLibcInternal/CMakeLists.txt,core/libs/prx/libSceLibcInternal/InventoryExports6.cpp,core/libs/prx/libSceLibcInternal/LocaleObjects.cpp,core/libs/prx/libSceLibcInternal/NumGet.cpp,core/libs/prx/libSceLibcInternal/TimeGetFields.cpp,core/libs/prx/libSceLibcInternal/include/Api.hpp,core/libs/prx/libSceLibcInternal/include/InventoryExports6.hpp,core/libs/prx/libc/include/GuestLocale.hpp,core/libs/prx/libc/src/LocaleSupport.cpp,core/libs/tests/GuestLibcInternalLocaleState.cpp, anddocs/dev/debt/changes/feat-libcinternal-locale-state.md. The manifest lists all 11 as included; none were excluded.To get this to a good state
Nothing is required. Optional: verify the modeled
_LocimpABI and ownership against console disassembly when available.