feat(libSceIcu): implement UTF-16 set searches and tokenization #10962

Merged
AZLisme merged 3 commits from upstream-pr/10962 into main 2026-11-02 10:25:35 +00:00
AZLisme commented 2026-10-25 11:21:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AZLisme on 2026-10-25T11:21:54Z.


What

Implement u_strspn, u_strcspn, u_strpbrk, u_strtok_r and u_memrchr32 using ICU 78.1 semantics and public ABI. Searches handle complete code points and bounded embedded NULs; spans return code-unit offsets. Tokenization preserves the one-code-unit supplementary-delimiter overwrite and continuation behavior. Canonical declarations are reachable through libSceIcu.hpp.

Checked GuestArena::HostWrite scopes cover the continuation pointer and each actual delimiter store. The Windows CTest PATH property retains ICU and kernel directories in one quoted semicolon list. Existing main implementations, throwing unknown exports and their debt are preserved.

The declared predecessor #10961 is merged. The agreed landing order continues #10962 → #10963 → #10964 → #10965 → #10966 → #10967 → #11088; this branch does not include the other open topics.

Tested

Current published head: f5a1913ed0241d33ab21c12e8e98d7e583b8ee82.

Windows Build 41295116289, 2026-11-01, tested that head integrated with frozen main 26fa1212b82f76dd49cf12d65e445d6ff3e0844c: 1,679 selected CTests passed, 904 skipped, zero failed. All nine ICU cases passed, including guest_icu_tokenize. The production ICU module built, linked and was NID-patched. Conventions passed on the same published head.

This is selected Windows coverage for those exact inputs. Full-suite, public-header and skip-audit CTests were not run in that job. It is not validation against today's main. Earlier Linux, Windows and private-composition results in the discussion remain historical and do not become tests of a later commit. Console/native ABI and other untested behavior remain documented coverage limits.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #10961
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5004251700 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10962). Originally posted by [AZLisme](https://github.com/AZLisme) on 2026-10-25T11:21:54Z. --- ### What Implement `u_strspn`, `u_strcspn`, `u_strpbrk`, `u_strtok_r` and `u_memrchr32` using [ICU 78.1 semantics and public ABI](https://github.com/unicode-org/icu/blob/049e0d6a420629ac7db77256987d083a563287b5/icu4c/source/common/ustring.cpp#L435-L621). Searches handle complete code points and bounded embedded NULs; spans return code-unit offsets. Tokenization preserves the one-code-unit supplementary-delimiter overwrite and continuation behavior. Canonical declarations are reachable through `libSceIcu.hpp`. Checked `GuestArena::HostWrite` scopes cover the continuation pointer and each actual delimiter store. The Windows CTest PATH property retains ICU and kernel directories in one quoted semicolon list. Existing main implementations, throwing unknown exports and their debt are preserved. The declared predecessor [#10961](https://github.com/boykopovar/AnyPS5/pull/10961) is merged. The [agreed landing order](https://github.com/boykopovar/AnyPS5/pull/11088#issuecomment-6401505606) continues #10962 → #10963 → #10964 → #10965 → #10966 → #10967 → #11088; this branch does not include the other open topics. ### Tested Current published head: `f5a1913ed0241d33ab21c12e8e98d7e583b8ee82`. [Windows Build 41295116289](https://github.com/boykopovar/AnyPS5/actions/runs/41295116289/job/124815039631), 2026-11-01, tested that head integrated with frozen main `26fa1212b82f76dd49cf12d65e445d6ff3e0844c`: 1,679 selected CTests passed, 904 skipped, zero failed. All nine ICU cases passed, including `guest_icu_tokenize`. The production ICU module built, linked and was NID-patched. [Conventions passed on the same published head](https://github.com/boykopovar/AnyPS5/actions/runs/41298903043/job/124825550522). This is selected Windows coverage for those exact inputs. Full-suite, public-header and skip-audit CTests were not run in that job. It is not validation against today's main. Earlier Linux, Windows and private-composition results in the discussion remain historical and do not become tests of a later commit. Console/native ABI and other untested behavior remain documented coverage limits. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> #10961 - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes
MarcZX10 commented 2026-10-25 11:35:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T11:35:01Z.

Review: CHANGES_REQUESTED


u_strtok_r writes to guest memory in two places without a GuestArena::HostWrite scope: it stores the continuation pointer through state (*state = ...) and replaces the delimiter with NUL (*next++ = 0). These are guest-visible writes, so on the shared guest arena they bypass write-watch/shared-backing notification; on Windows, a protected guest destination may also remain inaccessible to a host write. The current tests use ordinary std::array storage and do not exercise the GuestArena path. Please guard the state pointer write and the conditional text terminator write with appropriately sized HostWrite scopes, and handle an unsuccessful Open() consistently with the neighboring guest-memory APIs. A focused test against guest-backed memory would verify the regression.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642979908 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10962#pullrequestreview-5642979908). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T11:35:01Z. **Review:** CHANGES_REQUESTED --- `u_strtok_r` writes to guest memory in two places without a `GuestArena::HostWrite` scope: it stores the continuation pointer through `state` (`*state = ...`) and replaces the delimiter with NUL (`*next++ = 0`). These are guest-visible writes, so on the shared guest arena they bypass write-watch/shared-backing notification; on Windows, a protected guest destination may also remain inaccessible to a host write. The current tests use ordinary `std::array` storage and do not exercise the GuestArena path. Please guard the state pointer write and the conditional text terminator write with appropriately sized `HostWrite` scopes, and handle an unsuccessful `Open()` consistently with the neighboring guest-memory APIs. A focused test against guest-backed memory would verify the regression.
MarcZX10 commented 2026-10-25 13:24:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T13:24:43Z.

Review: APPROVED


Reviewed exact updated head f1a0d6a5526abe3c02469ce8d0e143d9044eaa68. The saved-state pointer is guarded before the initial continuation write, and the delimiter's UTF-16 NUL is guarded only when that write is needed. The early exhausted-state return still avoids dereferencing delimiters, while a rejected later delimiter write leaves the already-recorded initial state as described. The new guest-mapped tests cover state and text outputs, unchanged contents on rejected writes, and canaries; the existing surrogate and aliased-delimiter cases remain.

I ran python3 tools/check_conventions.py --base upstream/main --head HEAD and git diff --check upstream/main...HEAD; both pass. The author reports a Linux guest-mapping run and ICU 78.3 differential coverage. Windows read-only-view cases are present but not claimed as run; hosted product jobs are skipped. The previously requested guest-write protection gap is addressed. #10961 remains the declared integration predecessor.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643377198 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10962#pullrequestreview-5643377198). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T13:24:43Z. **Review:** APPROVED --- Reviewed exact updated head `f1a0d6a5526abe3c02469ce8d0e143d9044eaa68`. The saved-state pointer is guarded before the initial continuation write, and the delimiter's UTF-16 NUL is guarded only when that write is needed. The early exhausted-state return still avoids dereferencing delimiters, while a rejected later delimiter write leaves the already-recorded initial state as described. The new guest-mapped tests cover state and text outputs, unchanged contents on rejected writes, and canaries; the existing surrogate and aliased-delimiter cases remain. I ran `python3 tools/check_conventions.py --base upstream/main --head HEAD` and `git diff --check upstream/main...HEAD`; both pass. The author reports a Linux guest-mapping run and ICU 78.3 differential coverage. Windows read-only-view cases are present but not claimed as run; hosted product jobs are skipped. The previously requested guest-write protection gap is addressed. #10961 remains the declared integration predecessor.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!10962
No description provided.