feat(libc): add BSD string and memory helpers #2277

Closed
obojeoboje wants to merge 1 commit from upstream-pr/2277 into main
obojeoboje commented 2026-10-09 14:17:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by obojeoboje on 2026-10-09T14:17:49Z.


What

Implement six missing libc exports: bcopy, index, rindex, memrchr, wcscspn, and flsl.

bcopy preserves the BSD source-before-destination argument order and supports overlapping buffers. Reverse searches preserve the last matching address, character-to-byte conversion and the requested memory bounds. wcscspn operates on 16-bit guest code units instead of host wchar_t. flsl accepts a 64-bit guest long, including on Windows, and returns a one-based highest-set-bit position or zero for zero.

Contracts follow FreeBSD bcopy(3), string(3), memchr(3), wcscspn(3), and fls(3). Export names are present in the shadPS4 aerolib table.

Checked current open PR descriptions and the relevant patches in #2193, #1772 and #1423; no duplicate implementations found. The existing strcasestr in libScePosixForWebKit is left with its current owner.

The progress scanner changes from 2578/3044 (84.69%) to 2584/3050 (84.72%). Both counts grow because these are newly declared exports. This branch is independent of the other open libc contributions.

Tested

  • Windows, WinLibs GCC 15.2, Release with testing enabled: full default build and libs target passed.
  • Final full CTest run, four workers, 30-second per-test limit: 507 passed, one skipped (guest_video_out_wqhd_detection_no_vulkan), zero failures; 42.44 seconds total.
  • New runtime fixture checks 4,352 overlapping-copy combinations with canaries, 6,144 bounded reverse-memory searches with integer-to-byte conversion, first/last character and terminator searches, UTF-16 units including non-ASCII and surrogate values, and all 64 bit positions plus signed limits.
  • Guard pages before and after readable memory check reverse searches, zero-length reads, character searches and wide-string terminators at page boundaries.
  • Linux, Ubuntu 24.04 under WSL, GCC 13.3: built the new implementation as a separate shared library and ran the same fixture with AddressSanitizer and UndefinedBehaviorSanitizer; passed. This is a focused runtime check, not a full Linux project build or a NID-patched library run.
  • Test registration, conventions and whitespace checks passed. No game tested.
  • Full Linux/Windows Build and the relinker matrix still require a collaborator to dispatch the workflow for this PR head.

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 in TechnicalDebt
  • 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: none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4801668186 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2277). Originally posted by [obojeoboje](https://github.com/obojeoboje) on 2026-10-09T14:17:49Z. --- ### What Implement six missing libc exports: `bcopy`, `index`, `rindex`, `memrchr`, `wcscspn`, and `flsl`. `bcopy` preserves the BSD source-before-destination argument order and supports overlapping buffers. Reverse searches preserve the last matching address, character-to-byte conversion and the requested memory bounds. `wcscspn` operates on 16-bit guest code units instead of host `wchar_t`. `flsl` accepts a 64-bit guest `long`, including on Windows, and returns a one-based highest-set-bit position or zero for zero. Contracts follow FreeBSD [bcopy(3)](https://man.freebsd.org/cgi/man.cgi?query=bcopy&sektion=3&manpath=FreeBSD+14.0-RELEASE), [string(3)](https://man.freebsd.org/cgi/man.cgi?query=string&sektion=3&manpath=FreeBSD+14.0-RELEASE), [memchr(3)](https://man.freebsd.org/cgi/man.cgi?query=memchr&sektion=3&manpath=FreeBSD+14.0-RELEASE), [wcscspn(3)](https://man.freebsd.org/cgi/man.cgi?query=wcscspn&sektion=3&manpath=FreeBSD+14.0-RELEASE), and [fls(3)](https://man.freebsd.org/cgi/man.cgi?query=fls&sektion=3&manpath=FreeBSD+14.0-RELEASE). Export names are present in the [shadPS4 aerolib table](https://github.com/shadps4-emu/shadPS4/blob/0fe263a4760dfbfa973366890061749b4af0de97/src/core/aerolib/aerolib.inl). Checked current open PR descriptions and the relevant patches in #2193, #1772 and #1423; no duplicate implementations found. The existing `strcasestr` in libScePosixForWebKit is left with its current owner. The progress scanner changes from 2578/3044 (84.69%) to 2584/3050 (84.72%). Both counts grow because these are newly declared exports. This branch is independent of the other open libc contributions. ### Tested - Windows, WinLibs GCC 15.2, Release with testing enabled: full default build and `libs` target passed. - Final full CTest run, four workers, 30-second per-test limit: 507 passed, one skipped (`guest_video_out_wqhd_detection_no_vulkan`), zero failures; 42.44 seconds total. - New runtime fixture checks 4,352 overlapping-copy combinations with canaries, 6,144 bounded reverse-memory searches with integer-to-byte conversion, first/last character and terminator searches, UTF-16 units including non-ASCII and surrogate values, and all 64 bit positions plus signed limits. - Guard pages before and after readable memory check reverse searches, zero-length reads, character searches and wide-string terminators at page boundaries. - Linux, Ubuntu 24.04 under WSL, GCC 13.3: built the new implementation as a separate shared library and ran the same fixture with AddressSanitizer and UndefinedBehaviorSanitizer; passed. This is a focused runtime check, not a full Linux project build or a NID-patched library run. - Test registration, conventions and whitespace checks passed. No game tested. - Full Linux/Windows Build and the relinker matrix still require a collaborator to dispatch the workflow for this PR head. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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: none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-09 20:11:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:11:14Z.


Closing for the same reason as #2271: no title is shown to reach these on main. Reopen with the title ID and log line if one does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088460490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2277#issuecomment-6088460490). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:11:14Z. --- Closing for the same reason as #2271: no title is shown to reach these on main. Reopen with the title ID and log line if one does.

Pull request closed

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!2277
No description provided.