feat(libc): implement srandomdev using host entropy #8730

Merged
p3n1cillin merged 2 commits from upstream-pr/8730 into main 2026-10-24 16:52:30 +00:00
p3n1cillin commented 2026-10-20 22:40:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-20T22:40:00Z.


What

Add the missing srandomdev export (NID a2MOZf++Wjg) named in the firmware 3.20 libSceLibcInternal inventory. It fills the active random() state with host OS entropy and resets additive feedback positions, following FreeBSD 11 random.c. It shares the existing generator lock, state and entropy provider. Console parity is unverified and recorded in technical debt.

Tested

Windows 11, WinLibs GCC 15.2.0: all 133 tests registered under core/libs/prx/libc pass. WSL Ubuntu 26.04, GCC 15.2.0: all 111 tests registered under core/libs/prx/libc pass, including both focused random tests. The new test fails to link on the original source because srandomdev_nid_postfix is absent; it passes after the implementation.

Deterministic entropy injection covers all five generator sizes, an unaligned state, complete word filling, untouched header and guards, reset positions, no warm-up, linear-generator output and propagated entropy failure. The shared-library test also uses real OS entropy for every state size. No title run or console measurement.

tools/check_conventions.py --base origin/main passes. Ran tools/pr_overlap.py --branch codex/libc-srandomdev-20261020; no competing export or confirmed merge conflict remains. Manually reviewed the stale shared-file PR diffs reported as uncompared: they change other behavior or reorganize tests, and do not implement srandomdev.

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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4943480163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8730). Originally posted by [p3n1cillin](https://github.com/p3n1cillin) on 2026-10-20T22:40:00Z. --- ### What Add the missing `srandomdev` export (NID `a2MOZf++Wjg`) named in the [firmware 3.20 libSceLibcInternal inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c). It fills the active `random()` state with host OS entropy and resets additive feedback positions, following [FreeBSD 11 random.c](https://github.com/freebsd/freebsd-src/blob/4ab2e064d7950be84256d671a7ae93f87cc6aa36/lib/libc/stdlib/random.c#L252-L270). It shares the existing generator lock, state and entropy provider. Console parity is unverified and recorded in technical debt. ### Tested Windows 11, WinLibs GCC 15.2.0: all 133 tests registered under `core/libs/prx/libc` pass. WSL Ubuntu 26.04, GCC 15.2.0: all 111 tests registered under `core/libs/prx/libc` pass, including both focused random tests. The new test fails to link on the original source because `srandomdev_nid_postfix` is absent; it passes after the implementation. Deterministic entropy injection covers all five generator sizes, an unaligned state, complete word filling, untouched header and guards, reset positions, no warm-up, linear-generator output and propagated entropy failure. The shared-library test also uses real OS entropy for every state size. No title run or console measurement. `tools/check_conventions.py --base origin/main` passes. Ran `tools/pr_overlap.py --branch codex/libc-srandomdev-20261020`; no competing export or confirmed merge conflict remains. Manually reviewed the stale shared-file PR diffs reported as uncompared: they change other behavior or reorganize tests, and do not implement `srandomdev`. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
MarcZX10 commented 2026-10-20 22:48:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T22:48:51Z.

Review: APPROVED


Reviewed the current diff. srandomdev shares g_randomLock and the active state, fills the generator words after the type header through the existing OS entropy provider, and resets the additive front/rear positions without changing generator type. The tests exercise all five state sizes, unaligned state storage, guards/header preservation, feedback reset, linear-state output and entropy failure propagation. The author reports complete libc suites passing on Windows and Linux, with macOS relinker/write-watch and sanitizer checks also green; full platform build jobs are skipped. Console parity remains explicitly unverified. Approval is based on the focused implementation and reported test coverage. AI-assisted review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5592758299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8730#pullrequestreview-5592758299). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T22:48:51Z. **Review:** APPROVED --- Reviewed the current diff. `srandomdev` shares `g_randomLock` and the active state, fills the generator words after the type header through the existing OS entropy provider, and resets the additive front/rear positions without changing generator type. The tests exercise all five state sizes, unaligned state storage, guards/header preservation, feedback reset, linear-state output and entropy failure propagation. The author reports complete libc suites passing on Windows and Linux, with macOS relinker/write-watch and sanitizer checks also green; full platform build jobs are skipped. Console parity remains explicitly unverified. Approval is based on the focused implementation and reported test coverage. AI-assisted review.
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!8730
No description provided.