fix(libSceLibcInternal): take the end iterator of _Getloctxt by reference #23988
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23988"
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 ToRaNek on 2026-11-20T00:12:38Z.
What
std::_Getloctxt<char, istreambuf_iterator<char>>(bsohl1ZrRXE) was declared with its end iterator by value:The symbol says otherwise.
RT0_S5_is two references, and it demangles toint std::_Getloctxt<char, std::istreambuf_iterator<char>>(std::istreambuf_iterator<char>&, std::istreambuf_iterator<char>&, unsigned long, char const*). The reading of firmware 13.42'slibSceLibcInternal.sprxin #22452 says the same: "rdithe first iterator by reference,rsithe last iterator by reference,rdxasize_tfield count,rcxtheconst char*field table".GuestLocale::InputIteratoris 16 bytes and trivially copyable, so by value it travels in two registers. A real caller puts&lastinrsi, the count inrdxand the table inrcx; the export read the end iterator fromrsi:rdx, the field count fromrcx(the table's address) and the table fromr8, which the caller never set. Every call from guest code was therefore wrong (this library's owntime_getcode calls the internal matcher directly and was not affected). The tests did not see it because they called the export through the same by-value prototype.This PR takes the end iterator by pointer, as
_Getintin the same file already does for both of its iterators, and returns -2 for a null one like the other null arguments. The matching itself is untouched.Tested
Windows 11 IoT Enterprise LTSC 2024 (10.0.26100), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.CheckGroup6Getloctxtincore/libs/tests/GuestLibcInternalTimeGetFields.cppnow calls the export with&endIterin all 29 calls, and a null end iterator is checked.main5b6fb5480c, with the test's function pointer cast to the prototype of the symbol (InputIterator*, InputIterator*, size_t, const char*),guest_libc_internal_time_get_fieldsdies with an access violation (0xc0000005) in the first call.ctest -R "^guest_libc_internal_(time|locale|facet|num|ctype|collate|messages|money)"passes 13 of 13 after a full rebuild.python tools/check_conventions.py --base origin/mainpasses. No debt change: no entry describes the prototype.python tools/pr_overlap.py --branch fix/libscelibcinternal-getloctxt-end-by-reference(2017 open) reports two textual neighbours, neither of which changes the prototype: #22462 rewrites the body line that passes the end iterator on (it copies the guest table and iterator safely and keeps&last), and #23809 adds two declarations right after this one inTimeGetFields.hpp. Whichever lands second needs a small rebase.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-20T00:22:35Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ff85b6ccac:tools/check_conventions.pypassed.guest_libc_internal_time_get_fields_testsbuilt cleanly.guest_libc_internal_time_get_fields):core/libs/prx/libSceLibcInternal/TimeGetFields.cpp,core/libs/prx/libSceLibcInternal/include/TimeGetFields.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me