feat(libc): implement random, srandom, initstate and setstate #3229

Merged
adriadam10 merged 2 commits from upstream-pr/3229 into main 2026-10-11 02:15:28 +00:00
adriadam10 commented 2026-10-11 02:08:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T02:08:39Z.


What

Carries @screamm's branch from #3164 (feat/libc-random-state, commit dd2e0716 kept as is, with its authorship). Intake is paused for new contributors and the issue asks a maintainer to carry it.

It adds the BSD random, srandom, initstate and setstate (w1o05aHJT4c, sPC7XE6hfFY, IIUY-5hk-4k, woQta4WRpk0, from libSceLibcInternal), following FreeBSD 11 lib/libc/stdlib/random.c. Details are in #3164.

Titles:

  • PS5MC (PPSA99420) on main f1ae427b6 for Windows. I relinked the sha256-checked catalog release with relinker --windows --registry and walked its imports in the order the entry stub resolves them (WindowsEntryStubBuilder, first unresolved import fails). With the bundled libc.prx searched as the stub does, the first import nothing exports is setstate. This comes from that walk, not from a run.
  • PS5VR, Jelly5 and Emby5 (PPSA99177, PPSA99505, PPSA99515) import random, initstate and setstate too, and so do the other titles listed in #3164. They stop earlier, on exports other PRs cover.

My commit only moves the TechnicalDebt line from the end of "Functional" to "Unknown function info", next to the other libc lines, since the console's generator isn't verified.

Tested

Linux (CachyOS), GCC 16, Release.

  • guest_random_state passes.
  • I checked the pinned sequences independently: FreeBSD 11's random.c (releng/11.0), compiled unchanged apart from srandomdev, gives the same first values for the default state (1408992891, 1638182910, 83848093, 145962118, 627851256) and for srandom(12345) (1052984060, 1639322404, 1971525204, 2097956667, 2012147915).
  • Negative checks: changing the good_rand constant, the output shift or the number of seeding rounds each makes the test fail.
  • @screamm ran it on Windows 11 with MinGW-w64 GCC 15.2.0 (#3164).
  • tools/check_conventions.py passes.

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:4815943552 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3229). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T02:08:39Z. --- ### What Carries @screamm's branch from #3164 (`feat/libc-random-state`, commit `dd2e0716` kept as is, with its authorship). Intake is paused for new contributors and the issue asks a maintainer to carry it. It adds the BSD `random`, `srandom`, `initstate` and `setstate` (`w1o05aHJT4c`, `sPC7XE6hfFY`, `IIUY-5hk-4k`, `woQta4WRpk0`, from `libSceLibcInternal`), following FreeBSD 11 `lib/libc/stdlib/random.c`. Details are in #3164. **Titles:** - PS5MC (PPSA99420) on `main` f1ae427b6 for Windows. I relinked the sha256-checked catalog release with `relinker --windows --registry` and walked its imports in the order the entry stub resolves them (`WindowsEntryStubBuilder`, first unresolved import fails). With the bundled `libc.prx` searched as the stub does, the first import nothing exports is `setstate`. This comes from that walk, not from a run. - PS5VR, Jelly5 and Emby5 (PPSA99177, PPSA99505, PPSA99515) import `random`, `initstate` and `setstate` too, and so do the other titles listed in #3164. They stop earlier, on exports other PRs cover. My commit only moves the TechnicalDebt line from the end of "Functional" to "Unknown function info", next to the other libc lines, since the console's generator isn't verified. ### Tested Linux (CachyOS), GCC 16, Release. - `guest_random_state` passes. - I checked the pinned sequences independently: FreeBSD 11's `random.c` (releng/11.0), compiled unchanged apart from `srandomdev`, gives the same first values for the default state (1408992891, 1638182910, 83848093, 145962118, 627851256) and for `srandom(12345)` (1052984060, 1639322404, 1971525204, 2097956667, 2012147915). - Negative checks: changing the `good_rand` constant, the output shift or the number of seeding rounds each makes the test fail. - @screamm ran it on Windows 11 with MinGW-w64 GCC 15.2.0 (#3164). - `tools/check_conventions.py` passes. ### 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
github-actions[bot] commented 2026-10-11 02:09:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T02:09:13Z.


Progress report (84cc975 → b1267b3)

📈 System libraries: 85.99% (+0.02%, +4 implemented functions)

✅ 4 implemented
Library Name
libc initstate_nid_postfix
libc random_nid_postfix
libc setstate_nid_postfix
libc srandom_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104485486 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3229#issuecomment-6104485486). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T02:09:13Z. --- <!-- progress-report --> ### Progress report (84cc975 → b1267b3) 📈 **System libraries**: 85.99% (+0.02%, +4 implemented functions) <details> <summary>✅ 4 implemented</summary> | Library | Name | | - | - | | libc | `initstate_nid_postfix` | | libc | `random_nid_postfix` | | libc | `setstate_nid_postfix` | | libc | `srandom_nid_postfix` | </details>
adriadam10 commented 2026-10-11 02:42:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T02:42:04Z.


Merged: Linux CI is red only on agc_unit_shadow, which main has failed since #2864 (reported in #3215). Windows passed, and guest_random_state passed on both.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104709824 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3229#issuecomment-6104709824). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T02:42:04Z. --- Merged: Linux CI is red only on `agc_unit_shadow`, which main has failed since #2864 (reported in #3215). Windows passed, and `guest_random_state` passed on both.
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!3229
No description provided.