feat(libc): implement memccpy #2217

Closed
obojeoboje wants to merge 1 commit from upstream-pr/2217 into main
obojeoboje commented 2026-10-09 11:53:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by obojeoboje on 2026-10-09T11:53:47Z.


What

Implement memccpy in guest libc. Copy through the first byte matching the unsigned-char conversion of the stop value, return the address immediately after that byte, and return null when the count is exhausted. Leave the rest of the destination untouched.

Semantics checked against FreeBSD libc memccpy. The implementation is written locally without importing third-party source.

Extend guest_strings with cases for the first matching byte, repeated matches, embedded zero bytes, no match, a match at the count boundary, a match outside the count, zero count, unsigned-char conversion, and destination canaries.

This adds a previously undeclared export: the progress scanner changes from 2578/3044 (84.69%) to 2579/3045 (84.70%).

Tested

Windows, WinLibs GCC 15.2.0, Release, full-project CMake configuration:

  • cmake --build build --target guest_string_tests nid_patcher --parallel 4 succeeded, rebuilding libc and its relevant dependent libraries.
  • ctest --test-dir build --output-on-failure -R '^guest_strings$' passed (0.02 s).
  • Applied the libc NID patching step to the rebuilt library successfully.
  • git diff --check and python tools/check_conventions.py --base origin/main passed.

No game or homebrew tested. The full all-target build and complete test suite were not run.

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4800041740 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2217). Originally posted by [obojeoboje](https://github.com/obojeoboje) on 2026-10-09T11:53:47Z. --- ### What Implement `memccpy` in guest libc. Copy through the first byte matching the unsigned-char conversion of the stop value, return the address immediately after that byte, and return null when the count is exhausted. Leave the rest of the destination untouched. Semantics checked against [FreeBSD libc memccpy](https://github.com/freebsd/freebsd-src/blob/d39b1d6932dcc16b7c8a399d196fd81d038ca261/lib/libc/string/memccpy.c). The implementation is written locally without importing third-party source. Extend `guest_strings` with cases for the first matching byte, repeated matches, embedded zero bytes, no match, a match at the count boundary, a match outside the count, zero count, unsigned-char conversion, and destination canaries. This adds a previously undeclared export: the progress scanner changes from 2578/3044 (84.69%) to 2579/3045 (84.70%). ### Tested Windows, WinLibs GCC 15.2.0, Release, full-project CMake configuration: - `cmake --build build --target guest_string_tests nid_patcher --parallel 4` succeeded, rebuilding libc and its relevant dependent libraries. - `ctest --test-dir build --output-on-failure -R '^guest_strings$'` passed (0.02 s). - Applied the libc NID patching step to the rebuilt library successfully. - `git diff --check` and `python tools/check_conventions.py --base origin/main` passed. No game or homebrew tested. The full all-target build and complete test suite were not run. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
MarcZX10 commented 2026-10-09 12:09:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T12:09:57Z.


I reviewed the complete diff. The byte-by-byte copy, unsigned-char stop conversion, return pointer, and no-match behavior look correct; the regression cases cover the main boundary and canary cases. The PR reports a successful Windows focused build/test, and Conventions passes on head 4ede8898. CONTRIBUTING says libc changes need the full Linux and Windows Build plus the relinker matrix; those checks are not currently present on this PR. Could a collaborator run Actions → Build for #2217 so the exact head gets the required project checks? I am holding formal approval until those results are available.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080593120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2217#issuecomment-6080593120). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T12:09:57Z. --- I reviewed the complete diff. The byte-by-byte copy, unsigned-char stop conversion, return pointer, and no-match behavior look correct; the regression cases cover the main boundary and canary cases. The PR reports a successful Windows focused build/test, and Conventions passes on head `4ede8898`. CONTRIBUTING says libc changes need the full Linux and Windows Build plus the relinker matrix; those checks are not currently present on this PR. Could a collaborator run Actions → Build for #2217 so the exact head gets the required project checks? I am holding formal approval until those results are available.
obojeoboje commented 2026-10-09 12:14:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by obojeoboje on 2026-10-09T12:14:23Z.


@MarcZX100 Thanks for the review! Could a collaborator with write access run Actions → Build for PR #2217 at head 4ede8898, including the Linux/Windows builds and relinker matrix? I’ll address any failures reported by those checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080662625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2217#issuecomment-6080662625). Originally posted by [obojeoboje](https://github.com/obojeoboje) on 2026-10-09T12:14:23Z. --- @MarcZX100 Thanks for the review! Could a collaborator with write access run Actions → Build for PR #2217 at head 4ede8898, including the Linux/Windows builds and relinker matrix? I’ll address any failures reported by those checks.
oneandonlydean commented 2026-10-09 20:10:14 +00:00 (Migrated from github.com)

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


Closing: no title is shown reaching memccpy on main (#1976 was closed for the same reason). Reopen with the title ID and the log line when one stops at it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088446025 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2217#issuecomment-6088446025). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:10:14Z. --- Closing: no title is shown reaching `memccpy` on main (#1976 was closed for the same reason). Reopen with the title ID and the log line when one stops at it.

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