feat(libc): implement index string search #8842

Merged
UnhealthyKraken merged 1 commit from upstream-pr/8842 into main 2026-10-21 03:35:21 +00:00
UnhealthyKraken commented 2026-10-21 02:32:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T02:32:24Z.


What

Adds the legacy index(const char*, int) string search to the common libc exports, beside the existing strchr and rindex. It returns the first matching byte, including the terminating NUL, by forwarding to the existing strchr implementation. There is no allocation or new mutable state.

Name and NID t3RFHn0bTPg appear in the public PS5 3.20 libSceLibcInternal inventory. The public PS5 payload SDK declaration supplies the prototype. FreeBSD 11.4 strchr.c makes index a weak alias of strchr. These establish the public interface and reference behavior; this was not measured on a PS5, and the inventory does not establish module/library versions. Null string pointers are outside the reference function's defined input domain.

Tested

Windows x86-64, supported WinLibs MinGW-w64 GCC 15.2.0, Release full configuration with BUILD_TESTING=ON in an independent checkout of cd700fe9ec.

  • Added the behavioral regression before production code. Built baseline libc, preserved it, then compared baseline and candidate with identical test binaries and CTest selection: ^(guest_index|guest_allocating_strings|guest_strings|guest_wide_strings)$.
  • Baseline: the three existing suites pass; guest_index fails with index is missing from libc. Candidate: all four pass, no skips. The new test covers first matches, absence, empty strings, NUL, high bytes, integer conversion from -512 through 512 and INT_MIN/INT_MAX, unchanged input, returned original writable storage, and 257 string lengths ending immediately before a protected page.
  • Built libc, nid_patcher and the affected test targets; the existing string suites also built their libkernel, Net, NetCtl and PosixForWebKit dependencies. Patched a separate candidate libc with the project's NID patcher and confirmed t3RFHn0bTPg in its PE export table.
  • Subsequently built the complete Windows libs target and ran ctest -R '^patched_libraries$' -V: all 354 patched libraries loaded, zero failed. This is structural/load validation. Configuration initially inherited an empty processor name from the tool environment; a fresh configure with the verified PROCESSOR_ARCHITECTURE=AMD64 restored selected mimalloc's correct x64 redirect dependency, with no source changes.
  • Conventions, whitespace and test registration checks pass. Independent code review reported no actionable findings. No games run; no console measurement, Linux run or full-project test-suite claim.
  • tools/pr_overlap.py --branch feat/libc-index --repo boykopovar/AnyPS5 completed after fetching missing partial-clone objects. It reported no confirmed same-export or merge collisions, but could not compare shared files for 12 PRs already conflicting with main (#3965, #5021, #6044, #6819, #6879, #7081, #7201, #7715, #8150, #8352, #8520, #8711). Manually inspected their shared-file diffs: none adds index, changes the strchr/rindex region, or adds this test. #6044 reorganizes test paths and registration, so that broad reorganization would require integrating this new test if it lands later.

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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4945467792 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8842). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T02:32:24Z. --- ### What Adds the legacy `index(const char*, int)` string search to the common libc exports, beside the existing `strchr` and `rindex`. It returns the first matching byte, including the terminating NUL, by forwarding to the existing `strchr` implementation. There is no allocation or new mutable state. Name and NID `t3RFHn0bTPg` appear in the public [PS5 3.20 libSceLibcInternal inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c). The [public PS5 payload SDK declaration](https://github.com/ps5-payload-dev/sdk/blob/a7685ce8e97ce1f8a4f38253a41d54241c9124f1/include/freebsd/strings.h#L60) supplies the prototype. [FreeBSD 11.4 strchr.c](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/lib/libc/string/strchr.c) makes `index` a weak alias of `strchr`. These establish the public interface and reference behavior; this was not measured on a PS5, and the inventory does not establish module/library versions. Null string pointers are outside the reference function's defined input domain. ### Tested Windows x86-64, supported WinLibs MinGW-w64 GCC 15.2.0, Release full configuration with `BUILD_TESTING=ON` in an independent checkout of `cd700fe9ec`. - Added the behavioral regression before production code. Built baseline libc, preserved it, then compared baseline and candidate with identical test binaries and CTest selection: `^(guest_index|guest_allocating_strings|guest_strings|guest_wide_strings)$`. - Baseline: the three existing suites pass; `guest_index` fails with `index is missing from libc`. Candidate: all four pass, no skips. The new test covers first matches, absence, empty strings, NUL, high bytes, integer conversion from -512 through 512 and INT_MIN/INT_MAX, unchanged input, returned original writable storage, and 257 string lengths ending immediately before a protected page. - Built libc, nid_patcher and the affected test targets; the existing string suites also built their libkernel, Net, NetCtl and PosixForWebKit dependencies. Patched a separate candidate libc with the project's NID patcher and confirmed `t3RFHn0bTPg` in its PE export table. - Subsequently built the complete Windows `libs` target and ran `ctest -R '^patched_libraries$' -V`: all 354 patched libraries loaded, zero failed. This is structural/load validation. Configuration initially inherited an empty processor name from the tool environment; a fresh configure with the verified `PROCESSOR_ARCHITECTURE=AMD64` restored selected mimalloc's correct x64 redirect dependency, with no source changes. - Conventions, whitespace and test registration checks pass. Independent code review reported no actionable findings. No games run; no console measurement, Linux run or full-project test-suite claim. - `tools/pr_overlap.py --branch feat/libc-index --repo boykopovar/AnyPS5` completed after fetching missing partial-clone objects. It reported no confirmed same-export or merge collisions, but could not compare shared files for 12 PRs already conflicting with main (#3965, #5021, #6044, #6819, #6879, #7081, #7201, #7715, #8150, #8352, #8520, #8711). Manually inspected their shared-file diffs: none adds `index`, changes the strchr/rindex region, or adds this test. #6044 reorganizes test paths and registration, so that broad reorganization would require integrating this new test if it lands later. ### 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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 02:33:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T02:33:00Z.


Progress report (cd700fe → 20e9537)

➖ System libraries: 62.76% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libc index_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6306555195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8842#issuecomment-6306555195). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T02:33:00Z. --- <!-- progress-report --> ### Progress report (cd700fe → 20e9537) ➖ **System libraries**: 62.76% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `index_nid_postfix` | </details>
github-actions[bot] commented 2026-10-21 02:45:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T02:45:01Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3965 core/libs/prx/libc/CMakeLists.txt
PR 5021 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Strings.cpp
PR 6044 core/libs/prx/libc/CMakeLists.txt
PR 6819 core/libs/prx/libc/CMakeLists.txt
PR 6879 core/libs/prx/libc/src/Strings.cpp
PR 7081 core/libs/prx/libc/CMakeLists.txt
PR 7201 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Strings.cpp
PR 7715 core/libs/prx/libc/CMakeLists.txt
PR 8150 core/libs/prx/libc/CMakeLists.txt
PR 8352 core/libs/prx/libc/CMakeLists.txt
PR 8520 core/libs/prx/libc/CMakeLists.txt
PR 8658 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/src/Strings.cpp
PR 8711 core/libs/prx/libc/src/Strings.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6306720868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8842#issuecomment-6306720868). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T02:45:01Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3965](https://www.github.com/boykopovar/AnyPS5/pull/3965) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/CMakeLists.txt`<br>`core/libs/prx/libc/src/Strings.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libc/src/Strings.cpp` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/CMakeLists.txt`<br>`core/libs/prx/libc/src/Strings.cpp` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 8150](https://www.github.com/boykopovar/AnyPS5/pull/8150) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 8352](https://www.github.com/boykopovar/AnyPS5/pull/8352) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `core/libs/prx/libc/CMakeLists.txt` | | [PR 8658](https://www.github.com/boykopovar/AnyPS5/pull/8658) | `core/libs/prx/libc/CMakeLists.txt`<br>`core/libs/prx/libc/src/Strings.cpp` | | [PR 8711](https://www.github.com/boykopovar/AnyPS5/pull/8711) | `core/libs/prx/libc/src/Strings.cpp` |
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!8842
No description provided.