fix(libc): support character reads from random device streams #8150
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8150"
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 Dellz36 on 2026-10-20T00:31:02Z.
What
Make character reads on the existing
/dev/randomand/dev/urandomstdio streams use the same host-entropy backend asfread, instead of throwing throughGetNativeStream.fgetcandgetc_unlockedproduce an unsigned byte throughHostEntropy_nid_no_patch; existinggetcand__srgetaliases use that path too.EOF/errno 9 handling and status synchronization are unchanged.file_streams_random_character_inputregression and include it in the ordinary file-stream test. Cover both random devices, all four readers, sticky errors, mixed block input and buffer guards, closed streams, and ordinary binary bytes/EOF.Tested
Head
6a9b1285c596904698bb0511c14f7c04302b708b, based onmain34b1b77abfc013ffe740cf11cd76e02c6ccbafaf.cmake --build build --target file_streams_tests guest_standard_stream_tests --parallel 4passes.ctest --test-dir build -R '^(file_streams(_random_character_input)?|guest_standard_streams(_closed_stdout|_exclusive_stdout)?)$' --output-on-failure --repeat until-fail:5: all five cases pass five repetitions each, 25/25 executions, no skips/failures, 2.47 seconds after rebase.6a9b1285cmerged cleanly ontomaina569f47cb; Ubuntu 24.04 container, GCC 13, Release,BUILD_TESTING=ON, full linked build succeeds with no warnings inStandardStreams.cpporFileStreams.cpp.ctest -R 'file_streams|guest_standard_streams' --repeat until-fail:5passes all five relevant cases five times each (25/25 executions). These are the contributor's reported results, not a run performed by the PR author; they cover a full build and focused tests, not the entire Linux test suite or formal approval.python tools/check_conventions.py --base origin/mainandgit diff --check origin/main HEADpass.Please run the maintainer-only full Windows/Linux Build workflow for this PR when appropriate; local focused results are not a substitute for that CI run.
Overlap review
Ran the repository's unmodified
tools/pr_overlap.py --branch local/random-stream-character-input --repo boykopovar/AnyPS5 --jobs 4before opening. Disabled recursive submodule fetching only for that command: the default fetch encountered an unavailable LibAtrac9 submodule object in another PR; no repository source was changed to run the checker.getc_unlockedcall. That PR removes the::qualification (also onputc_unlocked); it does not add random-stream behavior. There is no semantic dependency. If it lands first, the resolution is to retain this PR's entropy conditional and its unqualified host call. This conflict is disclosed, not claimed absent.FileStreams.cppunchanged intotests/files/and changes test registration toadd_library_test. If it lands first, carry these checks to the relocated fixture and register the new case with its wrapper. It is test organization, not a competing implementation.No other open PR found implementing random-device character input. This is not a claim that every listed PR merges cleanly; several already conflict with main. No merge order has been agreed with their authors.
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)Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-20T01:07:12Z.
Full linked Linux run of this head (
6a9b1285c), since the description notes it was tested only as an isolated fixture there. Merged ontomaina569f47cb(clean merge). Ubuntu 24.04 container, GCC 13, Release,BUILD_TESTING=ON, full build.StandardStreams.cpporFileStreams.cpp.ctest -R 'file_streams|guest_standard_streams' --repeat until-fail:5:guest_standard_streams,guest_standard_streams_closed_stdout,guest_standard_streams_exclusive_stdout,file_streamsand the newfile_streams_random_character_inputall pass 5 of 5.Imported from boykopovar/AnyPS5. Originally posted by Dellz36 on 2026-10-20T01:12:01Z.
Thank you, @babyhuey, for independently validating this head on Linux and reporting the exact environment and merged base. I've credited your results in the Tested section: full linked build succeeds, no warnings in the two changed C++ files, and all five focused stream tests pass five repetitions each (25/25).
That fills the full-linked Linux build/focused-test gap in my original validation. I'm keeping the scope explicit: this is not a full Linux test-suite result or formal approval, and full Windows runtime CI and maintainer review remain outstanding.
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T11:30:06Z.
Windows run of
6a9b1285cmerged onto currentmain02fb1ce53(clean merge). Windows 11 (10.0.26300), Ryzen 5 9600X, WinLibs GCC 15.2.0 UCRT, Release,BUILD_TESTING=ON.ctest -R "^(file_streams|guest_standard_streams)": 5 of 5 pass, 3 runs out of 3. The build log has no warnings.StandardStreams.cppreverted,file_streamsandfile_streams_random_character_inputabort withFileStream: this function is not implemented on a /dev/random or /dev/urandom stream.fread. They fill fromHostEntropy_nid_no_patch, ignore a sticky error, never set EOF, and leave the other operations throwing throughGetNativeStream.getwc/fgetwc/getwchargo throughfgetcand now also read entropy. They decode it as UTF-8, so, going by the code, a random byte that is not a valid lead sets the error indicator withEILSEQ(86). That is consistent, but not listed in the updated debt line.fgetc_nid_postfixandgetc_unlocked_nid_postfixlines. #8226 hoistsauto* native = GetNativeStream(stream);above the read, andGetNativeStreamthrows on a random-device stream (FileStream.hppL208-210). If the second PR to land keeps that hoisted call and adds this PR'sIsRandomDevice()ternary after it, these reads throw again. The random-device check has to come beforeGetNativeStreamandSwitchToReading.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T16:02:37Z.
Thanks. CI (run 39373036404) shows
guest_filesystemaborting on Linux and Windows, and the cause is an existing test, not the new code.core/libs/tests/GuestFilesystem.cpp(around line 1320 on currentmain) still checks the old behaviour, thatfgetcon a/dev/urandomor/dev/randomstream throws:With this PR
fgetcreturns a byte, soRequire(unsupported)aborts. (On Windows, 0xc0000409 is howabort()exits.) Please update that check to the new behaviour, for example:No other existing test expects the throw: I grepped every test that opens a random device for
fgetc/getc/getc_unlocked.The branch also conflicts with
mainnow (#8116 just merged and touched the samecore/libs/prx/libc/CMakeLists.txtanddocs/dev/debt/libc.md), so please rebase while you're at it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:35:41Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the code inspected; the behavior and focused regression look consistent with the stated goal, but I did not run the reported checks.
What I ran
Reviewed head
6a9b1285c596904698bb0511c14f7c04302b708busing the prepared review bundle andrepo_read.py. I did not run build or test commands.Results
Negative control
Not run by me. The description reports a Windows negative control and a Linux source-level negative control; neither is a run I performed.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
I read the prepared description, commit list, manifest and diff, plus all four changed files in the repository at the pinned head. For
CMakeLists.txtanddocs/dev/debt/libc.md, I read the relevant sections; forStandardStreams.cppandFileStreams.cpp, I read their full text.files.jsonwas not available through the review reader. I did not run builds, tests, the negative control, or PS5 console checks.To get this to a good state
Nothing is required. Optional: run the maintainer-only full Windows/Linux Build workflow mentioned in the description.
Pull request closed