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]>
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.
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]>
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]>