feat(libSceIcu): search UTF-16 strings through guest copies #25528
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25528"
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 pinewhite on 2026-11-22T07:27:31Z.
What
u_strFindFirstandu_strFindLastnow copy both operands in from guest memory and run the ICU search on the copies, instead of passing guest addresses straight to the linkedustring.cpproutines and pre-measuring a NUL-terminated operand with a local loop that threwNotImplemented_nid_no_patchonce the length no longer fitINT32_MAX.GuestCopyInin page-sized chunks; a-1length stops after the terminator, which stays in the copy so ICU still sees a NUL-terminated operand and takes the same path it did before.text + (found - copy), andnullptrwhen ICU finds nothing.needleCountbelow-1,countbelow-1and empty-needle shortcuts keep ICU's order and results, and an empty needle still returns the text without reading it.std::invalid_argumentinstead of faulting on the guest address.NotImplemented_nid_no_patchbranch are gone, sotools/progress.pycounts both exports.python3 tools/progress.py --module libSceIcu: done 321 -> 323 of 2766 (11.61% -> 11.68%).u_strFindFirstandu_strFindLastno longer reachNotImplemented_nid_no_patch; nothing else moved.Tested
Host proof on Ubuntu 24.04 aarch64, g++ 13.3.0,
-std=c++20 -O1 -ffunction-sections -fdata-sections -Icore/libs, linked with-Wl,--gc-sections:core/libs/prx/libSceIcu/Utf16Search.cppcompiled by hand into a runner. Shimmed seams:GuestCopyIn_nid_no_patch(memcpy over host memory plus a registry of inaccessible ranges),u_strFindFirst/u_strFindLastforwarded tou_strFindFirst_74/u_strFindLast_74of host ICU 74,GuestArenaBeginHostWrite_nid_postfix,GuestArenaEndHostWrite_nid_postfixandNotImplementedAt_nid_no_patch.core/libs/tests/GuestIcuSearch.cpp(Substrings), the new long-operand cases, and the new mapped cases repeated overmmappages: text and needle crossing a page boundary, a needle ending exactly at the boundary, a surrogate pair inside the mapped text, a count that excludes the pair, and a read-only first page. All pass.-1and counted variants, first and last) return the same offset ornullptr.std::invalid_argument, exit 0.Not run: the CMake/ctest guest suites (no PS5 toolchain, ICU 78.1 build or emulator run in this environment), Windows direct-memory behaviour, and any console comparison.
Note: PR #22390 edits the include block at the top of
Utf16Search.cpp. This branch adds one ICU include there, so the overlap is a rebase on merge, not a functional conflict.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-22T07:28:34Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d20a820d2e:tools/check_conventions.pypassed.guest_icu_utf16_search_testsbuilt cleanly.guest_icu_utf16_search):core/libs/prx/libSceIcu/Utf16Search.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T07:42:44Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: preserve UTF-16 code unit alignment when copying operands across page boundaries.
What I ran
d20a820d2e493b3da35b583a7f0e6c8195bfbfc1usingrepo_read.py.Results
Findings
Blocking
core/libs/prx/libSceIcu/Utf16Search.cpp:29— For an operand whose address is not 2-byte aligned, a page boundary can split a UTF-16 code unit. The chunk length is chosen to end exactly at the 4 KiB boundary, then the next chunk starts at the next page, so scanning at offsets0, 2, 4, ...inReadOperandresumes on the wrong byte parity. This can miss the terminator or assemble different code units, leading to incorrect search results or an unreadable-memory exception even when the full UTF-16 operand is mapped. Preserve the operand’s code-unit alignment across chunks, for example by making each non-final chunk length even.Non-blocking
None.
Not verified
core/libs/prx/libSceIcu/Utf16Search.cpp,core/libs/tests/GuestIcuSearch.cpp, anddocs/dev/debt/changes/feat-icu-string-utf16-find.md. All three files listed in the manifest were read; no changed files were excluded.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-22T08:30:51Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
1476b1e39a:tools/check_conventions.pypassed.guest_icu_utf16_search_testsbuilt cleanly.guest_icu_utf16_search):core/libs/prx/libSceIcu/Utf16Search.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T08:34:50Z.
Review: APPROVED
Reviewed — looks good
The changed search wrappers and added guest tests were reviewed at head
1476b1e39a9db11cc1d870558c63bddacea6fb5d; no verified blocking defects were found, and the author reports host-side checks that I did not run.What I ran
No commands were run. I read the prepared diff, manifest, description, commit list, both included changed source files, and the added debt note. Repository context was inspected through the pinned reader
repo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run the reported host proof, CMake/ctest guest suites, or a console comparison. The full repository test harness and CI results were not inspected. The files excluded from the prepared diff by rule were not listed in the supplied bundle; their contents were not reviewed.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by throny on 2026-11-22T16:56:53Z.
Review: COMMENTED
Review: ⚠️ the search wrappers match ICU 78.1, but the tests also pass on
mainBasis: code read against
3rdparty/icu049e0d6a42(ustring.cppu_strFindFirst/u_strFindLast) · head1476b1e39aChecked
countunits, so ICU sees the same window, including the surrogate-boundary checks.Utf16Search.cpp:65maps the match back to the guest pointer. -1 operands are read in chunks that end on a page boundary, stopping at the NUL.offset & ~1.Findings
guest_icu_utf16_searchPassed withUtf16Search.cppreverted tomain, so the new cases don't pin the change. The behaviour that changes is that an unreadable operand throws instead of faulting. Please add a case with an unmapped (PROT_NONE) operand that expects a throw, and one with unreadable text and an empty needle that expects the text back.Utf16Search.cpp:24-33: a counted operand is now copied in full up front. A guest that passes acountlarger than its mapping, where the match comes first, used to succeed because ICU stops at the match; it now throws. A count nearINT32_MAXalso grows a host buffer toward 4 GB before the copy fails. Please mention this in the fragment.Suggested action: add the throwing test (1) and the fragment note (2); then merge
AI-assisted review (Claude Code) · head
1476b1e39a· basemain23b8772462