feat(libc): implement gets line input #9342
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9342"
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 UnhealthyKraken on 2026-10-21T18:55:38Z.
What
Implement the missing
getsexport (Ok+SYcoL19Y) through the guest stdin stream. The call holds the stream lock until the whole line is consumed, strips the newline, preserves every other byte, and null-terminates a returned line. EOF or read error before any byte leaves the destination untouched and returns null; a partial final line is returned. A null destination throws explicitly.The signature follows the pinned public SDK stdio.h. The name/NID is independently present in the 3.20 firmware inventory and symbol database. Input and EOF behavior follows FreeBSD 11.4 gets.c. This is an implementation using existing guest I/O, not copied third-party source.
PS5 equivalence and module/library versions remain unmeasured. The debt entry records null-destination policy, stream orientation uncertainty, and that FreeBSD emits a one-time diagnostic while this implementation emits none; console diagnostic behavior is unknown.
Tested
Windows x86-64, WinLibs GCC 15.2 Release, isolated branch based on
ee67ebcf2d9521fde1f09823fc226ae81cde88b8. No title, game, firmware module, Linux/macOS or PS5 execution.Regression first:
guest_getsfails withmissing gets export; three adjacent suites pass. Using identical final test executables and arguments and swapping only the selected unpatched libc, baseline remains one missing-export failure/three passes, candidate is 4/4 pass (guest_gets,guest_standard_streams,file_streams,guest_bounds_checking).guest_getspasses 20 consecutive runs.The new test covers all 255 byte values other than newline, including embedded NUL and 0xff; exact return pointers and destination guards; empty lines, carriage returns, partial EOF and repeated EOF; guest status flags; a real write-only-stream read error; closed input and null destination; and 2,048 uniquely numbered lines read exactly once by eight concurrent host threads. Partial input followed by a read error is not injected; partial EOF is covered. The stress test checks line integrity but is not a deterministic scheduler proof.
A separate native probe loads the canonical
Ok+SYcoL19Yexport from a privately patched copy of the candidate DLL: 8,806 checks per run, five runs pass. It checks byte contents, newline removal, partial EOF, initial EOF and destination guards through the real NID. The initial attempt used the normal patched output before the full build reached its patch step and found the old missing export; the private copy was made from the tested candidate and patched with the project'snid_patchercommand. This is separate from the final full-build validation below.Full Windows
libsandpatched_libraries_teststargets build successfully. Final CTest selection is 7/7 pass, including the two additional closed/exclusive stdout controls and a loader check reporting 360 patched libraries loaded, zero failures. Loading verifies linkage, not semantics of all libraries. The canonical probe also passes five runs against the normal final build output; its DLL is byte-identical to the privately patched copy (SHA25619413fea30462ff2090c8a519aa57fb202aa8ae6f5b3b3694d3c49c06acf112f). The complete 1,867-test CTest suite was not run. Current main38d3c0858ab364944274ebd3c6769393bc050035was inspected before publication: no changes to the touched libc files or FileStream since the tested base, and a merge-tree preflight is clean.Conventions and whitespace checks pass on the committed change. Independent read-only review found no actionable defect and did not rerun tests. Required overlap scan has no directly compared conflict or duplicate export. Fifteen base-conflicted shared-file warnings were reviewed: fourteen heads match the previously reviewed set; their additional StandardStreams hunks concern macOS unlocked-call spelling or random-device reads, and #8965 changes separate secure-copy tests/debt. #6044 is a test-directory migration consideration. No competing
getsimplementation was found by current exact symbol/NID searches and the refreshed all-state history index.Independent Linux validation by wachi35676 reports this head
7462ce5c1cmerged onto maina6dcea927, WSL2 Ubuntu 24.04/GCC 13.3.0 Release:guest_getsand all threeguest_standard_streams*tests pass in five runs, including the eight-thread case. Replacing only StandardStreams.cpp with main produces the expected missing-export failure; conventions pass. These are attributed reviewer results, not an own Linux run.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 wachi35676 on 2026-10-21T23:40:25Z.
Linux run, the platform the description doesn't list.
Head
7462ce5c1cmerged onto maina6dcea927(clean). WSL2 Ubuntu 24.04, GCC 13.3.0, Release.guest_getsplus the threeguest_standard_streams*tests: 4/4, 5 runs, including the 8-threadCheckThreadscase.libc/src/StandardStreams.cppfrom main,guest_getsaborts (missing gets export).check_conventions.py --base a6dcea927: passes.Ok+SYcoL19Yis in the PS5 3.20 libSceLibcInternal list (L17688). EOF and partial-line handling match FreeBSD 11.4gets.c: NULL only when EOF or an error comes before the first byte.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T03:16:31Z.
Recorded your Linux results in the Tested section with your attribution, exact PR/main heads and environment: four stream tests passing in five runs, the missing-export negative control, and conventions. The eight-thread case is included in that reported coverage. These remain your independent Linux results; I have not claimed an own Linux run. No code change is needed from this report.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:40:41Z.
Review: APPROVED
Checked against main
8b3e39832aand FreeBSD 11.4 lib/libc/stdio/gets.c:getsyet (onlyfgets/gets_s), so nothing is duplicated.fgetc_nid_postfixon the guest__stdinp, so buffering and the EOF/error flags stay consistent withgetchar,fgetsandgets_son main. The whole line is read under the stream lock, as FreeBSD'sFLOCKFILE(stdin)does.breakpath, and a closed stdin givesEBADFas__srefilldoes. No issues found.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T14:28:23Z.
Recorded the independent source review against FreeBSD 11.4 and current main. The partial-line/error behavior and stream locking are intentional, and no code change is needed for this review. The original Windows baseline/candidate evidence remains in the description; the hosted product jobs being skipped are not counted as runtime validation by me.