Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
adriadam10:carry/libc-random-state
Oct 11, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
adriadam10:carry/libc-random-state

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

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 f1ae427 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 libc: random, srandom, initstate and setstate are absent imports of eight catalog titles; fix branch ready #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 (libc: random, srandom, initstate and setstate are absent imports of eight catalog titles; fix branch ready #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

David and others added 2 commits October 11, 2026 04:07
Port FreeBSD 11 lib/libc/stdlib/random.c (freebsd-src 4ab2e064): the
additive feedback generator with the default 128-byte TYPE_3 table,
good_rand seeding, state sizes rounded down to 8, 32, 64, 128 or 256
bytes, setstate returning the previous state, and initstate returning
null below 8 bytes without setting errno. Calls are serialised by one
lock; a null state throws.

The import audit of the homebrew catalog on main 262c031 lists them as
absent libSceLibcInternal imports:
- random: PPSA74126 Stremio Plus, PPSA85300 VLC, PPSA99169 RetroArch,
  PPSA99177 PS5VR, PPSA99420 PS5MC, PPSA99505 Jelly5, PPSA99515 Emby5,
  PPSA99810 PSBox Cloud Gaming
- srandom: PPSA85300, PPSA99169, PPSA99420, PPSA99810
- initstate, setstate: PPSA99177, PPSA99420, PPSA99505, PPSA99515

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

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

@adriadam10
adriadam10 merged commit aac0f1b into boykopovar:main Oct 11, 2026
15 checks passed
@adriadam10 adriadam10 mentioned this pull request Oct 11, 2026
9 tasks done
@adriadam10

Copy link
Copy Markdown
Collaborator Author

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant