feat(libSceLibcInternal): implement the messages facet members #21170
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21170"
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 Herolias on 2026-11-15T22:10:01Z.
What
libSceLibcInternal's
messages<char>andmessages<wchar_t>get,open,closeanddo_getthrew throughNotImplemented_nid_no_patch, and libc's exportedmessages<char>vtable (_ZTVSt8messagesIcE, NIDFnEnECMJGag, #10158) was nine zeroed slots, so a virtual call through a facet that uses it jumped to address 0. This change follows the Microsoft STLxlocmesfor these.get,openandclose(NIDsXxsPrrWJ52I,U2t+WvMQj8A,EeBQ7253LkE; wideEa+awuQ5Bm8,TPq0HfoACeI,GGoH7e6SZSY) call the facet'sdo_get,do_openanddo_closethrough its vtable and return what they return. The newGuestLocale::MessagesVtableplaces them at 0x20, 0x28 and 0x30 past the vtable pointer, after the two destructors and_Incref/_Decrefthat every facet vtable here starts with;static_asserts pin the offsets.getreturns a string by value, so it takes the result pointer first and the facet second, as thecollatetransformslot already does inGuestLocale.hpp.do_get(NIDsvbgCuYKySLI,UM6rGQxnEMg) ignores the catalog, set and message and returns a copy of the default string. The copy followsbasic_string's copy constructor (_Construct_lv_contents) on the 0x28-byte guest string:wchar_t) copies the whole 16-byte buffer and records capacity 15 (7);size | 15(size | 7) andcapacity + 1elements from the shared guest string allocator, with the terminator copied;_Myptrdoes, so a short string held on the heap is copied inline.messages<char>vtable now holds, in slots 2 to 8, theDestroyCollate,DeleteCollate,RetainFacetandReleaseFacetfunctions thecollate<char>vtable uses (c66f61ff52), thendo_openreturning -1,do_getmaking the copy above anddo_closedoing nothing. Offset-to-top and typeinfo stay zero, as forcollate.LibcCopyString_nid_no_patchandLibcCopyWideString_nid_no_patch, next to the existingLibcAssignWideCString_nid_no_patch.do_openreturning -1 anddo_closedoing nothing agree with the firmware 13.42 reading behind40c1005030, which answers the existingdo_openanddo_closeexports (NIDsHeBwePMtuFs,rRmMX83UL1E,zSehLdHI0FA,AjkxQBlsOOY). Those four are unchanged.What still throws, and why:
get,openorclosethrowsstd::invalid_argumentwithout calling anything. The console would fault reading through the null pointer.do_get: a null result or default, a default whose capacity says heap but whose pointer is null, and a size abovemax_size()throwstd::invalid_argument.max_size()is assumed to beSIZE_MAX - 1(SIZE_MAX / 2 - 1forwchar_t), as in the existingbasic_stringdebt entry; the console's value was not read. A copy too large to allocate throwsstd::bad_allocfrom the allocator.messages<char>::_Getcat(NID96Ev+CE1luE) and themessagesconstructors still throw; no available source settles their console layout. So nothing in this tree builds amessagesfacet yet; the wrappers run only on facets the title builds, with its own vtable or libc's.messages<wchar_t>vtable is exported, so the wide wrappers run only on a facet whose vtable the title supplies.Debt:
docs/dev/debt/changes/feat-messages-facet.mdremoves the eight "declaration is for import resolution only" entries, adds one Functional entry tolibSceLibcInternal.mdand changes themessages<char> vtableentry inlibc.md. Each entry is under the 1000-character limit.Overlap:
tools/pr_overlap.py --namesbefore starting, for 13messagesnames (the narrow members, destructors,_Getcatand vtable, and the wideget,do_getand vtable): the only open pull request it lists is #17300 (refactor, changes requested), which renames the placeholders to their mangled names without implementing them. #17296 implementsstd::__sce_v2::messages, a different class, under its ownSceV2Messages*names.tools/pr_overlap.py --branch feat/messages-facetexits 2. It reports one conflict, #19359, and eight pull requests it cannot compare because they already conflict withmain. I compared each withgit merge-tree --write-treeagainstmainand against this branch:_Doraiseon the lines directly above themessages<char>::getstub inExport.cppandPendingExports.hpp, so the two hunks touch. Neither changes the other's lines; the resolution keeps both changes.Export.cppand from 2 to 3 inApi.hpp, because it renames the samesceLibcInternalPending4_005to_012functions this branch implements. The stubs are replaced in place to keep that small.mainin the files this branch changes, with the same number of hunks as with this branch. #13778 conflicts withmainonly in files this branch does not change.Not in this PR:
messagesconstructors and_Getcat.messages<wchar_t>vtable export.numpunct<char>,codecvt<wchar_t>and others). #11172 wirescodecvt<wchar_t>.Tested
Fedora 44 x86-64, GCC 16.2.1, GNU ld 2.46.1, CMake 4.3.0, Ninja 1.13.2, Release with
-DBUILD_TESTING=ON, onmainatff36fea157. I ran no title, homebrew or console, because I have none. Nothing was built or run on Windows or macOS.cmake --build buildbuilt the whole tree.tools/select_tests.py(BUILD.md, "Selective test builds") was 5594 tests, because libc and libSceLibcInternal are linked into almost every test. 5591 passed and 3 failed:agc_driver_image_table_packed_guards,audio_out2_port_layoutsandguest_http. All three fail the same way onmainat2454441420, the previous base of this branch: I checked outmainin the same tree, rebuilt their executables and ran each alone. The same three failed with this branch on that base.guest_httpandaudio_out2_port_layoutsabort, andagc_driver_image_table_packed_guardslogs "invalid format" image-table write-backs. 59 tests skipped themselves: 57 AGC and VideoOut tests,guest_environment_binding_unloadandguest_net_raw_protocol. In an earlier run of the selection, two rebases back,guest_kernel_stack_protectalso aborted once under-j 16. It passed when run alone and in the final run.guest_libc_internal_messages(new):get,openandcloseexports calls only its own slot of a recording vtable, passes the result, facet, catalog, set, message, default, name and locale through unchanged, and returns the slot's result;do_getforcharandwchar_t:size | 15orsize | 7;wchar_t) gets aligned storage from the large-allocation path;_ZTVSt8messagesIcE:openreturns -1,getcopies the default,closereturns;guest_locale(extended): libc'smessages<char>vtable has zero offset-to-top and typeinfo and non-null slots 2 to 8. It checks destroy, retain and release,openreturning -1,close, a short and a longget(capacitylength | 15, new storage, same bytes), a null default throwing, and the deleting destructor on a facet fromoperator new.size + 1elements into the inline buffer;do_openreturning 0;do_closeslot;getswapping set and message;do_getusing the narrow layout.tools/check_conventions.py --base origin/mainreports "All conventions checks passed." With--titleand--bodyset to this title and body, it also passes.tools/debt_fold.py --checkpasses.tools/pr_overlap.py --branch feat/messages-facet: see Overlap above.Sources
Microsoft STL links are to
219514876ea86491de191ceaa88632616bbc0f19, the first public release, the pin thestd::_MP_*entry inlibSceLibcInternal.mdalready uses.open,getandclosecalldo_open,do_getanddo_closeand return their resultstl/inc/xlocmeslines 38-49do_openreturns -1,do_getreturns the default,do_closedoes nothingstl/inc/xlocmeslines 84-94;do_openanddo_closealso agree with the firmware 13.42 reading in40c1005030do_open,do_get,do_close, in declaration orderstl/inc/xlocmeslines 79-94; the facet's_Incref/_Decrefvirtuals instl/inc/xlocalelines 136-146; the first four slots as in the existingGuestLocale::FacetVtableand thecollate<char>vtable (c66f61ff52)_BUF_SIZEcopies_BUF_SIZEelements and sets capacity_BUF_SIZE - 1; otherwise capacitymin(size | _ALLOC_MASK, max_size()),capacity + 1elements allocated andsize + 1copiedstl/inc/xstringlines 2461-2479_BUF_SIZE16 / 8 and_ALLOC_MASK15 / 7 for 1- and 2-byte elementsstl/inc/xstringlines 2040-2046_BUF_SIZEstl/inc/xstringlines 2047-2066 (_Myptr,_Large_string_engaged)GuestLocale::Stringincore/libs/prx/libc/include/GuestLocale.hpp;GuestStringStorage::Allocateincore/libs/prx/libc/GuestStringStorage.hppst_size) in thelibc.prxbundled with PPSA26344Checklist
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-16T00:31:50Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
0bd059835e:tools/check_conventions.pypassed;git diff --checkclean.guest_libc_internal_messages_tests,guest_locale_testsbuilt cleanly.guest_locale,guest_libc_internal_messages):core/libs/prx/libSceLibcInternal/Export.cpp,core/libs/prx/libSceLibcInternal/include/Api.hpp,core/libs/prx/libSceLibcInternal/include/PendingExports.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