feat(libc): export the std::__sce_v2 _Locimp_ctor and _Locimp_dtor with facet reference counting #16165
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16165"
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 Danigamer05 on 2026-11-05T19:01:04Z.
What
Builds on #16113: this branch contains its commit, so until it merges only the two commits after it are this PR's change.
Export the versioned
std::__sce_v2locale::_Locimp::_Locimp_ctorand_Locimp_dtorfrom libc, and make the versioned_Locimpfamily count facet references the way the console does._ZNSt8__sce_v26locale7_Locimp12_Locimp_ctorEPS1_RKS1_XBQPgR5196I0xF25E0_ZNSt8__sce_v26locale7_Locimp12_Locimp_dtorEPS1_L2pyahLSGFk0xD1030Changed exports:
_ZNSt8__sce_v26locale7_Locimp11_New_LocimpERKS1_(ynwqogpIbL0,0xD0F60) and_ZNSt8__sce_v26locale7_Locimp14_Locimp_AddfacEPS1_PNS0_5facetEm(7KPYZ-jSAto,0xF2680).The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6). As in the module:_Locimp_ctor(self, source)builds only the facet vector. The caller has already copied the count. A zero count leaves the vector alone. Otherwise it callsmalloc(count * 8), throwsbad_allocon null, and copies the facets from the last to the first, retaining each non-null one._Locimp_dtor(self)releases each non-null facet from the last to the first, callsdeleteObjecton the ones that reach zero, and frees the vector unless it is the classic one. It does not free the_Locimp._New_Locimp(const _Locimp&)allocates0x30bytes and sets the_Locimpvtable, one reference and a null vector. It copies the count, category, transparency and name pointer, then calls_Locimp_ctor. If that throws, it frees the object._Locimp_Addfacgrows the vector withrealloctomax(id + 1, 40)slots and clears the new ones. It retains the new facet, releases the one it replaces (deleting it at zero) and stores the new one._Locimpobjects built by_New_Locimp(const&),_New_Locimp(bool)andempty()get the module's_Locimpvtable. The last release returns the object, anddeleteObjectruns_Locimp_dtorand frees it. Before this PR they used the copy vtable and were never freed.Before this PR, the versioned
_New_Locimp(const&)and_Locimp_Addfaccalled the unversioned copy and insertion, which neither retain nor release. The unversioned functions are unchanged.guest_sce_v2_localepassed facets with a null vtable to_Locimp_Addfacand read the copy after its last release. It now uses a counting facet and checks that the last release deletes the copy and its facet.A new debt entry lists what still differs: the lock, null arguments, size overflow, the one-slot classic vector, and copies of locales built by unversioned calls. The versioned locale entry drops its sentence about the reused unversioned copy and insertion, and #16113's entry drops the one about the copy vtable.
Tested
Windows x86-64, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, on top of #16113 (d18e1c71325, maind893997f1a6); the branch merges cleanly with mainc4469b60daf. Exact tested commit:b24626696c2. It adds one commit to4e7016e6926that renames two internal helpers. The build, the tests, the side-by-side run and the conventions check ran on it; the negative control and the overlap checks below ran on4e7016e6926.Built libc, libkernel, their NID-patched production libraries and the related tests. The new
guest_sce_v2_locimp_referencespasses, along withguest_sce_v2_locale,guest_sce_v2_locale_basics,guest_localeandguest_sce_v2_exceptions;public_headerspassed on4e7016e6926.The NID-patched libc exports both new NIDs.
The new test uses facets that count retains, releases and deletes. It checks:
_New_Locimp(const&)copies, and that the copy owns its vector;id + 1, the cleared slots, replacing a facet and re-adding the same one;_Locimp_ctorleaves the vector alone for a zero count and copies onlycountfacets, and that_Locimp_dtorfrees the vector and deletes facets at zero;_Locimpsharing the classic vector keeps it on destruction and gets a copy of it on growth;bad_alloc, retains nothing, keeps the vector and frees the half-built_New_Locimpobject, and that another thread can still take the lock afterwards;_New_Locimp(bool)andempty()objects are freed with their facets on the last release.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_allocwere redirected to one recorder. The recorder exits bylongjmp, so after a failed_New_Locimp(const&)the harness frees the object as the module's landing pad does.Side by side with the patched production library, over two seeds with 200,000 random steps each: about 64,000
_New_Locimp(const&), 16,000_New_Locimp(bool), 88,000_Locimp_Addfac, 100,000_Locimp_ctor/_Locimp_dtorpairs on caller-owned objects, and 131,000 retains, releases anddestroycalls through the vtable. One step in six made its allocation fail (about 12,000 throws per seed), and about 13,000_Locimps per seed reached zero and were deleted. Each step compared:_Locimp's references, count, category, transparency, name and slots;malloc,reallocandfreecalls.The only difference is that the module also calls
free(NULL), which the harness ignores. No comparison differed. #16113's side-by-side run also still passes with two seeds on4e7016e6926.Negative control: five lines were altered one at a time:
_Locimp_ctordid not retain;_Locimp_dtordid not free the vector;_Locimp_Addfackept the replaced facet;_New_Locimp(const&)did not copy the count;_New_Locimp(bool)kept the copy vtable.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 tests and side-by-side run passed again.
Code conventions and
git diff --checkpass.tools/pr_overlap.pyread 1,871 open PRs at4e7016e6926and reports no overlap. It keeps exit 2 for 36 branches that already conflict with main. Merging each of the 36 with this branch and with main usinggit merge-treegives the same conflict blocks, apart from main's own movement since #16113's base, except indocs/dev/debt/libc.md: for #5021, #9371, #9447 and #9526 the edited_Locimpline and the new entry land inside the conflict block they already have there, as #16113's lines do, and #14212 gets no conflict block beyond the ones it has with #16113. The debt edit adds no conflict over #16113 with any of the 142 open PRs that touch that file. 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, #16083 and #16113.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
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)🤖 Generated with Claude Code