[HLE] Add strchr/strrchr/memchr/strcat/strncat/strstr libc exports
Summary
Adds six missing libc string/memory search exports to the libc module so that titles which rely on standard C string handling get correct HLE behavior instead of hitting an unresolved import:
strchr— locate first occurrence of a byte (NUL matches the terminator)strrchr— locate last occurrence of a bytememchr— locate a byte within a bounded bufferstrcat— append source string to destination, returns destinationstrncat— append at mostnbytes of source, always NUL-terminates, returns destinationstrstr— locate first occurrence of a substring (empty needle returns the haystack)
These are pure, self-contained functions that games and middleware use constantly (metadata parsing, path handling, string building). They follow the exact pattern of the existing strcpy/strncpy/strcmp/memcmp exports in KernelMemoryCompatExports.cs: guest memory is accessed through the CpuContext compat helpers, arguments come from the SysV AMD64 registers (rdi, rsi, rdx), and results are returned in rax.
Background
The PS5 runs an x86-64 AMD "Zen 2" CPU with a FreeBSD-derived kernel, so its user-mode libc follows the standard System V AMD64 calling convention (integer args in rdi/rsi/rdx/..., return value in rax). The exports here mirror that convention and match the semantics documented for standard C <string.h> functions.
NIDs
Each export's NID was produced with the project's own symbol-hashing scheme (SHA-1 over symbol + suffix key, first 8 bytes, base64url), the same generator used by scripts/generate_aerolib_binary.py. Verified against the already-shipped exports (strlen, strcmp, strcpy, memcpy all reproduce their in-tree NIDs with this generator) and confirmed unique across the codebase — no collisions with existing entries.
| Export | NID |
|---|---|
| strchr | ob5xAW4ln-0 |
| strrchr | 9yDWMxEFdJU |
| memchr | 8u8lPzUEq+U |
| strcat | Ls4tzzhimqQ |
| strncat | kHg45qPC6f0 |
| strstr | viiwFMaNamA |
All are registered for both Generation.Gen4 and Generation.Gen5 under LibraryName = "libc", consistent with the neighboring string exports.
Testing
dotnet build SharpEmu.slnx -c Release— succeeds with 0 warnings / 0 errors.- Wrote a standalone harness that implements
ICpuMemoryover a flat guest heap, drives each export through a realCpuContext, and asserts both the returnedraxpointer/value and the resulting guest memory against native libc semantics. 17 cases pass, covering the important edge cases:strchrmatching the trailing NUL; missing char returns NULL.strrchrlast-match and missing-char (NULL).memchrhonoring the count bound (no over-read) and finding a NUL byte.strcat/strncatreturning the destination pointer, correct concatenation,strncatstopping at the source terminator and always NUL-terminating.strstrlocating a substring, missing needle returning NULL, empty needle returning the haystack, and a match at the very end.
Notes
Bounds and fault handling use the same TryRead*/TryWrite* compat helpers as the surrounding code, so an out-of-range guest pointer yields the project's standard memory-fault result rather than a host crash.