fix(libc): read /dev/random and /dev/urandom through fopen #6541
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6541"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-15T19:28:08Z.
What
fopen("/dev/urandom", "rb")(and/dev/random) failed withENOENT:fopen_nid_postfixresolved the path to a host file that does not exist, while libkernel'sopenandsceKernelOpenalready serve both paths from host entropy (RandomDevice.cpp, #1777, #4200).A read-only
fopenof exactly/dev/randomor/dev/urandomnow returns a stream over the host null device, marked as a random device, andfreadon it fills the buffer withHostEntropy_nid_no_patch, as the libkernel descriptors do (FreeBSDrandom(4): reads never block and never hit end of file).setvbuf,feof,ferror,clearerr,fcloseand the stream locks (flockfile,ftrylockfile,funlockfile,_Lockfilelock,_Unlockfilelock) work on it.fflushreturns 0, as FreeBSD's__sflushdoes for a stream that is not writing.GetNativeStream, so nothing silently reads the null device. Opening the paths for writing throws, as in libkernel.freopenclears the mark;freopenonto these paths still fails withENOENT(listed in the libc debt file with the rest).Title: ProsperoTV (PPSA99003, 01.000.070, the author's GPL-3.0 release) reads its phone-pairing code with
fopen("/dev/urandom", "rb")+fread(src/iptv_remote.cpp,Random()). Onmain, Settings → Pair a phone starts the remote server but always shows "Code expired or unavailable" (3 of 3 runs). With this change it shows a 6-digit code and a countdown (3 of 3 runs).Tested
guest_filesystemgets a check (open,setvbuf, twofreads that differ,feof/ferror, the locks,fflush, an unsupported call throws,fclose). Onmainit fails at thefopen(null stream, guest errno 2); with this change it passes.guest_filesystem,file_streams,guest_standard_streams,guest_host_streams,guest_file_lock_*,guest_formatting,guest_random*, …).guest_filesystempasses; full tree build passes, including NID patching of every library.main44df21632, after #5632 (closed-stream checks), which this keeps in front of the new code.python tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T20:24:07Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libc.mdL83-84Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
docs/dev/debt/libc.mdcore/libs/prx/libc/include/FileStream.hppcore/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/src/StandardStreams.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/GuestFilesystem.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mdcore/libs/tests/GuestFilesystem.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/src/FileAndHeap.cppdocs/dev/debt/libc.mdcore/libs/prx/libc/include/FileStream.hppcore/libs/prx/libc/src/FileAndHeap.cppcore/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/include/FileStream.hppcore/libs/prx/libc/src/FileAndHeap.cppcore/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/src/StandardStreams.cppdocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mddocs/dev/debt/libc.mdImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T10:15:42Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head
48e967497merged on main5d9dcc42d(clean merge):libs: pass, apart from the known MinGW 64 KiBalignasAGC test object that fails onmaintoo (#6452/#6478).guest_filesystem,--repeat until-fail:3: 3 of 3 pass. 14 related stream, file-lock and random tests also pass.mainand the new test kept,guest_filesystemfails at the newRequire(stream != nullptr)afterfopen("/dev/urandom", "rb")(guest errno 2); with the sources restored it passes again.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 829 of 837 pass, 2 skipped, 6 timeouts on a heavily loaded host. On serial rerunsconventions_function_bodies,tls_function_coverage_register_address_loadsand two conventions shards pass;conventions_function_bodies_shard_2still hits its 30 s limit under load but its script takes about the same time on this branch and onmainwhen timed directly (15-17 s vs 14 s);hardware_oracle_comparealso hits its 20 s limit onmain. None of them is about libc streams.tools/check_conventions.py --base origin/mainandgit diff --check: pass.main: 3 of 3 runs that reached the dialog show "Code expired or unavailable / Press X for a new code" (a fourth run lost an R1 press and ended on Sources). No stop line; the title keeps running and is killed at the limit.main, 5489 and 3908 with the PR (20-46 FPS because the host was busy).Not checked: pairing an actual phone end to end, Linux/macOS,
freopenonto these paths.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T00:20:47Z.
Validated against a second title: VLC (PPSA85300, ZiZc3/VLC v0.4.6), relinked with
--windows --windows-fixed-base 0x400000, onmain8e7904b20with and without this PR, 3 runs each.main, every run logsnet: no /dev/urandom: HTTPS won't work.net: /dev/urandom ok.Windows 11 26300, RTX 5070 Ti (32.0.16.1742), WinLibs GCC 15.2.0, Release.
AI-assisted: yes (Claude Code); results above were run on this machine.