feat(libScePosixForWebKit): implement arc4random_buf #1637

Closed
babyhuey wants to merge 1 commit from upstream-pr/1637 into main
babyhuey commented 2026-10-08 15:24:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T15:24:15Z.


What

Implements arc4random_buf (n1KOc0lTUEs) in libScePosixForWebKit. Part of #1578: PPSA99039 (EVO-PLAYER-PS5) imports it.

It fills the buffer from a thread-local std::random_device, as sceRandomGetRandomNumber in libSceRandom already does (getrandom//dev/urandom with libstdc++ on Linux, rand_s with MinGW), and writes exactly nbytes. Like FreeBSD arc4random_buf, it has no failure result.

Tested

Linux (Ubuntu 24.04, GCC 13, Release): new guest_posix_random and existing guest_resolver pass with --repeat until-fail:3. The test checks that a zero size writes nothing, that sizes 1, 3, 5 and 4098 leave the following bytes untouched, that two 4099-byte buffers differ, and that no byte value occurs 64 or more times in one of them. It fails when the last partial word is written whole. check_test_registration.py and check_conventions.py pass. Windows: both files compile with MinGW-w64 GCC 13 (-Wall -Wextra -fsyntax-only); not run on Windows. No title 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:4789057090 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1637). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T15:24:15Z. --- ### What Implements `arc4random_buf` (`n1KOc0lTUEs`) in libScePosixForWebKit. Part of #1578: PPSA99039 (EVO-PLAYER-PS5) imports it. It fills the buffer from a thread-local `std::random_device`, as `sceRandomGetRandomNumber` in libSceRandom already does (`getrandom`/`/dev/urandom` with libstdc++ on Linux, `rand_s` with MinGW), and writes exactly `nbytes`. Like FreeBSD `arc4random_buf`, it has no failure result. ### Tested Linux (Ubuntu 24.04, GCC 13, Release): new `guest_posix_random` and existing `guest_resolver` pass with `--repeat until-fail:3`. The test checks that a zero size writes nothing, that sizes 1, 3, 5 and 4098 leave the following bytes untouched, that two 4099-byte buffers differ, and that no byte value occurs 64 or more times in one of them. It fails when the last partial word is written whole. `check_test_registration.py` and `check_conventions.py` pass. Windows: both files compile with MinGW-w64 GCC 13 (`-Wall -Wextra -fsyntax-only`); not run on Windows. No title 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
klosixgaming-arch commented 2026-10-08 15:32:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T15:32:34Z.

Review: APPROVED


LGTM. Clean implementation of arc4random_buf using thread-local std::random_device, consistent with the existing sceRandomGetRandomNumber approach in libSceRandom. The 4-byte-at-a-time write pattern is efficient, and the test coverage is thorough - checking zero size, various sizes, buffer boundaries, and randomness quality (no byte value occurring too frequently). Good addition to support EVO-PLAYER-PS5's import requirements.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5459114045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1637#pullrequestreview-5459114045). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T15:32:34Z. **Review:** APPROVED --- LGTM. Clean implementation of arc4random_buf using thread-local std::random_device, consistent with the existing sceRandomGetRandomNumber approach in libSceRandom. The 4-byte-at-a-time write pattern is efficient, and the test coverage is thorough - checking zero size, various sizes, buffer boundaries, and randomness quality (no byte value occurring too frequently). Good addition to support EVO-PLAYER-PS5's import requirements.
babyhuey commented 2026-10-08 17:37:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T17:37:10Z.


Fork CI while the upstream run waits for approval: Build run, all jobs green on 6b16cd65 (Linux 467/467, Windows 458/458, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065574196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1637#issuecomment-6065574196). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T17:37:10Z. --- Fork CI while the upstream run waits for approval: [Build run](https://github.com/babyhuey/AnyPS5/actions/runs/37812363458), all jobs green on 6b16cd65 (Linux 467/467, Windows 458/458, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with `main`.
oneandonlydean commented 2026-10-09 09:29:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:29:35Z.


Closing: EVO-PLAYER (PPSA99039) stops at other imports on main before arc4random_buf, and the Linux run in #1578 needed about 17 other open PRs before the title loaded. Reopen when it's a title's next stop on main, with the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078228657 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1637#issuecomment-6078228657). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:29:35Z. --- Closing: EVO-PLAYER (PPSA99039) stops at other imports on main before `arc4random_buf`, and the Linux run in #1578 needed about 17 other open PRs before the title loaded. Reopen when it's a title's next stop on main, with the log line.
babyhuey commented 2026-10-10 16:53:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T16:53:06Z.


This is now a title's next stop on main, so it is open again as #2865 (GitHub would not reopen this one). ProsperoTV (PPSA99003) on main 57f96fd2: Linux app.elf: symbol lookup error: app.elf: undefined symbol: n1KOc0lTUEs, Windows FAIL: unresolved ELF import n1KOc0lTUEs (arc4random_buf) from libScePosixForWebKit.prx; with the branch it goes on to _umtx_op (#1482). Details and tests are in #2865.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099914155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1637#issuecomment-6099914155). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-10T16:53:06Z. --- This is now a title's next stop on `main`, so it is open again as #2865 (GitHub would not reopen this one). ProsperoTV (PPSA99003) on `main` 57f96fd2: Linux `app.elf: symbol lookup error: app.elf: undefined symbol: n1KOc0lTUEs`, Windows `FAIL: unresolved ELF import n1KOc0lTUEs (arc4random_buf) from libScePosixForWebKit.prx`; with the branch it goes on to `_umtx_op` (#1482). Details and tests are in #2865.

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