feat(libSceLibcInternal): implement basic_string erase, append, assign, _Xran and _Xlen #15692
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15692"
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 B-Howell on 2026-11-04T06:41:41Z.
What
Implements eight
libSceLibcInternalexports of the unversionedstd::string(std::basic_string<char>, mangledSs) that were stubs throwing throughNotImplemented_nid_no_patch. Each mangled name was checked against its NID withtools/nid_names.py'scompute_nid:_ZNSs5eraseEmm0Ir3jiT4V6QsceLibcInternalPending4_110_ZNSs6appendERKSsmmqiR-4jx1abEsceLibcInternalPending4_111_ZNSs6appendEmcQqBWUNEfIAosceLibcInternalPending4_112_ZNSs6assignEPKcmxSxPHmpcNzYsceLibcInternalPending4_113_ZNSs6assignERKSsmmpGxNI4JKfmYsceLibcInternalPending4_114_ZNSs6assignEmcikjnoeemspQsceLibcInternalPending4_115_ZNKSs5_XranEvAzBnOt1DouUsceLibcInternalUnknown_AzBnOt1DouU_ZNKSs5_XlenEvpDtTdJ2sIz0sceLibcInternalUnknown_pDtTdJ2sIz0Where the behaviour comes from:
erase(pos, n):out_of_rangeifpos > size(), removesmin(n, size() - pos)characters), [string.append] (append(str, pos, n)andappend(n, c):out_of_rangeifpos > str.size(),length_errorpastmax_size()) and [string.assign] (assign(s, n),assign(str, pos, n),assign(n, c)). Self-referencing calls (assignfrom a pointer into*this,append(*this, ...),assign(*this, pos, n)) keep their source valid across a reallocation.GuestLocale::String(static_assert(sizeof(String) == 0x28)inlibc/include/GuestLocale.hpp; buffer at 0x8, size at 0x18, capacity at 0x20, inline while capacity is 15) andGuestLocale::AllocateStringStoragefromlibc/src/LocaleSupport.cpp(32-byte aligned with the raw pointer at[-1]from 0x1000 bytes). A grown string gets capacitysize | 15, the policy libc'sCollateTransformandAssignCStringuse. To share them,StringInlineCapacityandStringCapacityMaskmove fromLocaleSupport.cppintoGuestLocale.hpp, and the release half ofReleaseStringStoragebecomesGuestLocale::DeallocateStringStorage, whichTakeStringnow also uses. Behaviour of the libc code is unchanged._Xranand_Xlenforward to libc's_ZSt14_Xout_of_rangePKcand_ZSt14_Xlength_errorPKc. The messages are microsoft/STL's ate1ed302683e5e822f663fbb0f44cee7e9ddc6af0,stl/inc/xstringL481-L482_Xout_of_range("invalid string position");and L573-L574_Xlength_error("string too long");._ZNSs5_CopyEmm(9HILqEoh24E,sceLibcInternalPending4_109) and_ZNSs6insertEmmckeep throwing:_Copyis the console's internal growth step and was not confirmed by disassembly.The stubs are removed from
Export.cppandInventoryExports2.cpp, and the new functions are declared once ininclude/Api.hpp. The debt file loses these NIDs from its stub entries and gains one entry for what is still unverified: the console'slibSceLibcInternal.sprxwas not read, so its growth factor may differ fromsize | 15, andmax_size()is taken asSIZE_MAX - 1.Who calls them: guest C++ code built against the unversioned
std::stringcalls these out-of-line modifiers; the rest ofbasic_stringis inlined into the title.tools/progress.pycollect_libraries()againstorigin/mainc2eafe4461:donegoes from 9863 to 9871 (+8). ForlibSceLibcInternal,donegoes from 84 to 92 andtodofrom 1045 to 1037; no other library changes and no todo is added.Tested
guest_libc_internal_basic_string(core/libs/tests/GuestLibcInternalBasicString.cpp), using the existingGuestSceV2Exceptions.Sguest catch harness. It checks every function's result and returned*this, inline and heap storage, capacity after growth, storage reuse on shrink and on assignment from inside*this, self-append across a reallocation, a 5005-character string in 32-byte aligned large storage, embedded nulls, the untouched first 8 bytes, theout_of_range/length_errortype and message thrown by each range or length failure, and that every allocation is released.guest_libc_internal_basic_stringpassed 3/3 runs.guest_collate,guest_filesystem_error,guest_future_category,guest_generic_category,guest_libc_internal_exception_destructors,guest_localeandguest_sce_v2_locale(the users of the moved libc string helpers) passed 7/7.public_headers(the single-declaration check) passed 1/1.guest_libc_internal_basic_stringpassed 3/3 runs. The same seven libc and libSceLibcInternal tests passed 7/7.main's production files (Export.cpp,InventoryExports2.cpp,include/Api.hpp,GuestLocale.hpp,LocaleSupport.cpp, withoutBasicString.cpp) plus the new test fail to build on both Windows and Linux:StringInlineCapacityis not a member ofGuestLocaleand the_ZNSs/_ZNKSsfunctions are not declared.python3 tools/check_conventions.py --base origin/mainprinted "All conventions checks passed." Theconventions_*anddebt_splitctest entries are self-tests of the checker scripts and were not run separately.python3 tools/pr_overlap.py --branch feat/lci-stringfound no open PR with the same exports or new files. It failed closed for PRs it could not compare automatically (5021, 13486, 13778, 13782, 13881, 14085, 14212, 14401, 14837, 14936). The added lines of each were checked by hand: none contains_ZNSs,_ZNKSsor any of these NIDs. PR 14158 touches neighbouring lines inlibSceLibcInternal/CMakeLists.txtand the debt file, and PRs 14373 and 14834 touch neighbouring lines ininclude/Api.hpp.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
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-11-06T08:03:10Z.
Review: COMMENTED
Checked head
d887251dd09150e78aa57a56e6be070b5b27a409, PR basead6cb554308afba4bfc3664ebb961f9a22885b4b, on Linux/WSL with GCC 13.3. The existingguest_libc_internal_basic_stringtest and conventions check pass. A separate probe calls the actual assignment export through the built libSceLibcInternal/libc/libkernel modules.The pointer/count overload at
BasicString.cpp:114-116loses a character when an alias range includes the existing terminator. For"abc",assign(data()+1, 3)returns size 2, with bytes62 63. It should return size 3, with bytes62 63 00, plus its final terminator. The delegated substring overload clamps the count tosize - position. The cited STL pointer/count implementation preserves the full count.The probe also gets size 15 instead of 16 for an inline 15-byte string with offset 0/count 16, and 19 instead of 20 for a heap string with offset 1/count 20. All ranges use initialized bytes plus the existing terminator. Six controls pass. A temporary correction that snapshots the source before assignment makes all nine cases pass; restoring the head restores the three failures.
Could you preserve the pointer/count range across overlap and growth, and add these cases? No console or allocation-policy claim here.