Commit Graph
13 Commits
Author SHA1 Message Date
Dean bf38c3bc34 Merge pull request #11208 from orezraey/fix/libc-random-state-measured-ps5
fix(libc): save the random state on a short initstate and take any setstate rear as measured on a PS5
2026-10-27 11:03:11 +13:00
Dean 6cc5ec671d Merge pull request #10394 from JJenkx/windows/libc-drand48-upper-bits
fix(libc): return the upper 32 bits of the state from drand48 and erand48 as titles' libc.prx does
2026-10-26 11:05:43 +13:00
orezraeyandClaude Opus 5.5 61ae4c52df fix(libc): save the random state on a short initstate and take any setstate rear as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 18:47:19 -03:00
boykopovar f38d29fd08 refactor(sdk): add canonical headers for remaining libraries 2026-10-24 23:17:42 +03:00
Dean Galvin cac82f55d1 Merge main into codex/libc-srandomdev-20261020 2026-10-25 03:29:34 +13:00
JJenkxandClaude Opus 5.5 8251179fc2 fix(libc): return the upper 32 bits of the state from drand48 and erand48 as titles' libc.prx does
drand48 and erand48 returned the whole 48-bit state over 2^48, as FreeBSD
does. The libc.prx bundled with eleven titles returns its upper 32 bits
over 2^32, so the low 16 bits never reach the result; both functions now
do the same. The generator and the other rand48 functions are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 16:52:02 -04:00
ionut27001 741c96ca89 fix(libc): seed random() and its default state as measured on a PS5
The libSceLibcInternal of a payload process on a PS5 (firmware 12.70) seeds
the additive feedback generator with a good_rand that reads its argument as an
int32, turns 0 into 123459876 and applies x = 16807 * (x % 127773) - 2836 * (x / 127773),
adding 0x7fffffff to a negative result. Its default state is the state after
srandom(1), not a precomputed table.

Replace the good_rand, build the default state by seeding it with 1 and add a
guest test that pins the first values of a fresh process, the values after each
measured seed and the saved state words of every measured initstate size.
2026-10-21 10:26:06 +03:00
p3nicillin 1002d28117 feat(libc): implement srandomdev using host entropy 2026-10-20 23:39:05 +01:00
ionut27001andClaude Opus 5.5 46f518997e fix(libc): return jrand48 and mrand48 zero-extended as measured on a PS5
In a payload process on a PS5 (firmware 12.70), jrand48 and mrand48
return the high 32 bits of the new 48-bit state zero-extended to the
64-bit long, as FreeBSD 11.0 does, so a result with bit 31 set comes
back between 0x80000000 and 0xFFFFFFFF. Here they sign-extended it, as
FreeBSD 11.1 and later do with an (int32_t) cast. lrand48 and nrand48
already matched the payload process. The tests now pin its results for
three seeds and the first six mrand48 values after srand48(1), compare
with the host as 32-bit values, and the debt entry records the
measurement.

AI-assisted: yes

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-19 07:09:32 +03:00
T3cm0andClaude Opus 5.5 26898755e5 feat(libc): implement seed48 and lcong48
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-17 20:44:32 -05:00
virp-mta 302a8774ac feat(libc): implement drand48, lrand48, mrand48 and srand48 2026-10-11 21:48:56 +04:00
Achraf ReyaniandClaude Opus 5.5 f85ae8d6f2 feat(libc): implement erand48, nrand48 and jrand48
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-11 19:02:32 +09:00
DavidandClaude Fable 5.1 1671179c4f feat(libc): implement random, srandom, initstate and setstate
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 262c0316 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 <[email protected]>
2026-10-11 04:07:38 +02:00