feat(libc): export the versioned std::__sce_v2 locale runtime #14585
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14585"
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 edubox on 2026-11-01T16:00:42Z.
What
PPSA28416 imports the versioned
std::__sce_v2locale and stream runtime fromlibc.prx; none of it was exported. This adds the measured objects and accessors:ctype<char>(MmytiDdoGBA),ctype<wchar_t>(b61-ZHIQuns),numpunct<char>(5+FD4VpX+nw),num_put<char>(3ZotGOwzi9k) andcodecvt<wchar_t,char,_Mbstatet>(OVV3+UimpiY), pluslocale::id::_Id_cnt(EIyErVBW9QI). In the console'slibc.prxthey are BSS objects of 8 and 4 bytes, so they start at zero._sceLibcClassicLocale(Mcrl2crhxu0), which points at this library's classicImplementation.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 existingGuestLocale::Implementation, so they reuse this library's copy constructor and facet insertion.cout(9Qe7XFSQ4Lk),cerr(Jk7KrKMQzDw),wcout(7ipah7h7Wjk),wcerr(+ROCBP8cIyY),cin(T1cG+xkSd-g) andwcin(RhFDPGxQ4sA) objects, which PPSA01341 imports. They are zeroed storage like the unversioned objects: the console initializes them as0x68/0x70-byte streams with a working vtable and streambuf, which is not modelled yet.Evidence is the disassembly of the
libc.prxbundled with PPSA28416 (build J03848509):locale::_Init(bool)Mt6co-yzyjg0xcfe60locale::_Getgloballocale()xE51MX+B2G40xcfd40_Facet_RegisteraFxknk3hTog0xcfd00ios_base::_AddstdLfjFksmiu4Y0x10d680ios_base::_Ios_base_dtorZe2I81YNykw0x10d580_Locimp::_New_LocimpynwqogpIbL00xd0f60_Locimp::_Addfac7KPYZ-jSAto0xf2680_Initreturns the global_Locimpand takes a reference on it when its flag is set;_Getgloballocaleonly loads the global pointer. The versionedios_baseis 0x48 bytes, not the 0x40 of the unversioned one:_Addstdwrites the 1-based slot at0x08and uses slots 1-7 before slot 8, and_Ios_base_dtordecrements that slot's count, frees the 32-byte node list at0x30, invokes and frees the 24-byte callback list at0x38, and releases the locale at0x40.Not included on purpose:
_Getctypeand_Getcvtare 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:
3ZotGOwzi9k#3#2num_put<char>::idEIyErVBW9QI#3#2locale::id::_Id_cnt5+FD4VpX+nw#3#2numpunct<char>::idMmytiDdoGBA#3#2ctype<char>::idMcrl2crhxu0#3#2_sceLibcClassicLocaleaFxknk3hTog#3#2_Facet_RegisterxE51MX+B2G4#3#2locale::_Getgloballocale()Ze2I81YNykw#3#2ios_base::_Ios_base_dtorLfjFksmiu4Y#3#2ios_base::_AddstdMt6co-yzyjg#3#2locale::_Init(bool)nm -Donmain'sunpatched/libc.prxhas none of them; this branch's has the corresponding_nid_postfixdefinitions. The title stops earlier onmain: the run log ends at+77.132252 swithwhat(): 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 newguest_sce_v2_localecovers the zero-initialised ids,_Init/_Getgloballocale/_sceLibcClassicLocale, facet registration, the_Locimpcopy with_Addfac, and_Addstdfollowed by_Ios_base_dtor.nid_patcher libcon the rebuiltunpatched/libc.prxexports 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/mainandgit diff --checkare clean;tools/pr_overlap.py --branch feat/libc-sce-v2-localereports 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
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)Shared files only, no shared exports: #10989 and #11421 also touch
libc/CMakeLists.txt,libc/include/Api.hppanddocs/dev/debt/libc.md; the three can land in any order after a rebase.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:48:53Z.
Review: COMMENTED
Withdrawn. There is no
mainstop log at these imports: PPSA28416 stops earlier atsceNpGetSandboxInfo not implemented, before the locale runtime is used. Import-registry evidence is the applicable proof here.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_v2locale runtime from libc: the locale and facet accessors, theios_basestandard-stream table, the_Locimpcopy and facet installation, and the stream and locale id objects. The Windows CTest run passedguest_sce_v2_localeand the other locale cases. The PR says its layouts and facet ids were measured from a PS5libc.prx. I cannot check that measurement from here.What I ran
01e53151db2518b96c46b0ac941fece014246dc9; basef2d874c1fdccf781c0fa5d86619bb5dd8894b958. 6 files, +270:libc/CMakeLists.txt(+12, the new test target),libc/include/Api.hpp(+7),libc/include/GuestLocale.hpp(+14, theSceV2IosBaselayout withstatic_asserts),libc/src/LocaleSupport.cpp(+110, the new exports and helpers),tests/GuestSceV2Locale.cpp(+124), and a debt doc (+3).LocaleSupport.cppadditions, the header, and the CMake change in full. The existing code around the additions is unchanged.Requirechecks (lines 49 to 123): the id objects, the classic locale andgetglobal, 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.guest_sce_v2_locale(Test #737) passed, and so didguest_sce_v2_exceptions(Test #575),guest_locale(Test #735) and the other locale cases. CTest counts skipped cases as passed in its total.public-declaration-not-foundforAssignCStringand theCodecvt*names. I did not compare this count with the base.GuestSceV2Locale.cppas possibly unregistered. The CMake fragment names it through${LIBS_INCLUDE_DIR}/tests/GuestSceV2Locale.cpp, and the Windows run executedguest_sce_v2_locale.Results
public-declaration-not-foundguest_sce_v2_localeand the other locale cases (hosted, Windows)libc.prx; not checkable hereRead-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_dtordecrements the open count of a standard-stream slot, but it never clearsg_sceV2StandardStreams[slot]. Nothing dereferences the table (agit grepfinds reads only in_Addstdand 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.Sources
github.com/boykopovar/AnyPS5@01e53151db/core/libs/prx/libc/src/LocaleSupport.cppgithub.com/boykopovar/AnyPS5@01e53151db/core/libs/prx/libc/include/GuestLocale.hppgithub.com/boykopovar/AnyPS5@01e53151db/core/libs/tests/GuestSceV2Locale.cppwindowson 01e53151db2518b96c46b0ac941fece014246dc9Not verified
SceV2IosBasesize and offsets), export names, facet ids and the id objects against the PS5libc.prx. The PR says they were measured; I did not check that.GuestSceV2Locale.cpp.To get this to a good state
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_dtorfrees the0x30node list before it runs theerase_eventcallbacks. 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-ffintomain9090972b7e91fd266819cbd77a8b058e177b5682. Debian 13 VM, GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.Results
git diff --checkcheck_conventions.pymainfailures (AGC denormal cases,guest_interfaces,unwrap_selfand others) are unrelated to this PR. Theguest_net_ctlskip is known onmain.guest_sce_v2_locale,guest_locale,guest_multibyte_locale,guest_sce_v2_exceptionsstreamNodes == nullptrgit status --porcelainempty)Probe output
Negative control
I restored
LocaleSupport.cpp,Api.hppandGuestLocale.hppfrommainand kept the PR's test. The test no longer compiles, for exampleerror: '_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_dtorruns theerase_eventcallbacks after it frees the0x30list (LocaleSupport.cpp#L830-L842).What happens: the loop at
core/libs/prx/libc/src/LocaleSupport.cpp:830-835freesstreamNodesand sets it to null. Only after that does the loop at:836-842invoke each callback.Who reported it: B-Howell, with disassembly of PPSA08329's
libc.prx. I add a local reproduction: the probe above printsarrayVisibleInCallback=0.It contradicts the PR's own debt entry: the entry (
docs/dev/debt/libc.md:295) says the console "calls the0x38callbacks, frees the0x30/0x38node lists".Why it matters: an
erase_eventcallback normally readsiword/pwordto release what it stored there.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->callbackNodesstill points at the head of the list. A callback that walks or changes the callback list (for example throughregister_callbackorcopyfmt) would touch freed nodes. The console frees nothing until every callback has run.Suggested fix: follow the Dinkumware
_Tidyorder:0x30list and set it to null.0x38list and set it to null.Add a test case that fills both lists and checks, inside the callback, that
streamNodesis 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.0x30/0x38lists, so the node-freeing and callback paths have no coverage at all. The blocking fix should add that coverage.Not verified
libc.prx: I have no console binary here._Addstdputs in slot 8 might be returned early by the destructor rather than torn down; the PR decrements its count and tears it down.To get this to a good state
_Ios_base_dtor: callbacks first, freeing nothing, then the0x30list, then the0x38list, then the locale.GuestSceV2Locale.cppwith a stream that has one0x30node and one callback node, and require that the callback runs once withstreamNodesstill set. Check that this new case fails against the current order.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:33:12Z.
Review: APPROVED
Re-checked — approved
Commit
f88d648692changes_Ios_base_dtorso it runs everyerase_eventcallback first, then frees the0x30list, then the0x38list. 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
f88d648692("fix(libc): run ios_base callbacks before freeing the node lists"). The two earlier commits are unchanged (range-diffshows=).LocaleSupport.cpp: the destructor now walks the0x38list and calls each callback without freeing anything. After that it frees the0x30list and the0x38list, then releases the locale. This is the Dinkumware_Tidyorder from B-Howell's disassembly. It also matches the debt entry.GuestSceV2Locale.cpp: a new case gives a stream one0x30node and one callback node with id 7. It requires that the callback runs exactly once and thatstreamNodesis still set while it runs. It also requires that both lists are null afterwards.What I ran
Head
f88d6486927d3ea06a3dbd9a082b609ccd1c6ba0, merged with--no-ffintomain9090972b7e91fd266819cbd77a8b058e177b5682(merged tree21e38f43727e2cbc4cb4b4c3ce910083d5140bb6). Debian 13 VM, GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.git diff --checkcheck_conventions.pymainfailures (AGC denormal cases,guest_interfaces,unwrap_selfand others) and theguest_net_ctlskip also occur onmain.guest_sce_v2_locale,guest_locale,guest_multibyte_locale,guest_sce_v2_exceptionsguest_sce_v2_localefails (Subprocess aborted)git status --porcelainis emptyPrevious findings
_Ios_base_dtorran the callbacks after freeing the0x30list. 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._Facet_Registeraccepts a null facet and duplicates. Still open.core/libs/prx/libc/src/LocaleSupport.cpp:857-860is unchanged, while the unversioned_Register(:748) rejects both. This is not a merge blocker.New findings
Blocking
None.
Non-blocking
None.
Not verified
libc.prx. I have no console binary here.sceNpGetSandboxInfo.