feat(libc): implement gets line input #9342

Merged
UnhealthyKraken merged 2 commits from upstream-pr/9342 into main 2026-10-24 07:48:07 +00:00
UnhealthyKraken commented 2026-10-21 18:55:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T18:55:38Z.


What

Implement the missing gets export (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_gets fails with missing 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_gets passes 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+SYcoL19Y export 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's nid_patcher command. This is separate from the final full-build validation below.

Full Windows libs and patched_libraries_tests targets 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 (SHA256 19413fea30462ff2090c8a519aa57fb202aa8ae6f5b3b3694d3c49c06acf112f). The complete 1,867-test CTest suite was not run. Current main 38d3c0858ab364944274ebd3c6769393bc050035 was 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 gets implementation was found by current exact symbol/NID searches and the refreshed all-state history index.

Independent Linux validation by wachi35676 reports this head 7462ce5c1c merged onto main a6dcea927, WSL2 Ubuntu 24.04/GCC 13.3.0 Release: guest_gets and all three guest_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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4956764969 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9342). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T18:55:38Z. --- ### What Implement the missing `gets` export (`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](https://github.com/ps5-payload-dev/sdk/blob/a7685ce8e97ce1f8a4f38253a41d54241c9124f1/include/freebsd/stdio.h#L270). The name/NID is independently present in the [3.20 firmware inventory](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c) and [symbol database](https://github.com/zecoxao/sce_symbols/blob/2883963a0a514ba6e77407a08ef4730a65e88254/aerolib.csv). Input and EOF behavior follows [FreeBSD 11.4 gets.c](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/lib/libc/stdio/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_gets` fails with `missing 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_gets` passes 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+SYcoL19Y` export 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's `nid_patcher` command. This is separate from the final full-build validation below. Full Windows `libs` and `patched_libraries_tests` targets 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 (SHA256 `19413fea30462ff2090c8a519aa57fb202aa8ae6f5b3b3694d3c49c06acf112f`). The complete 1,867-test CTest suite was not run. Current main `38d3c0858ab364944274ebd3c6769393bc050035` was 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 `gets` implementation was found by current exact symbol/NID searches and the refreshed all-state history index. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Independent [Linux validation by wachi35676](https://github.com/boykopovar/AnyPS5/pull/9342#issuecomment-6329021826) reports this head `7462ce5c1c` merged onto main `a6dcea927`, WSL2 Ubuntu 24.04/GCC 13.3.0 Release: `guest_gets` and all three `guest_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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
wachi35676 commented 2026-10-21 23:40:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:40:25Z.


Linux run, the platform the description doesn't list.

Head 7462ce5c1c merged onto main a6dcea927 (clean). WSL2 Ubuntu 24.04, GCC 13.3.0, Release.

  • guest_gets plus the three guest_standard_streams* tests: 4/4, 5 runs, including the 8-thread CheckThreads case.
  • Negative control: with libc/src/StandardStreams.cpp from main, guest_gets aborts (missing gets export).
  • check_conventions.py --base a6dcea927: passes.
  • Ok+SYcoL19Y is in the PS5 3.20 libSceLibcInternal list (L17688). EOF and partial-line handling match FreeBSD 11.4 gets.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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329021826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9342#issuecomment-6329021826). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T23:40:25Z. --- Linux run, the platform the description doesn't list. Head `7462ce5c1c` merged onto main `a6dcea927` (clean). WSL2 Ubuntu 24.04, GCC 13.3.0, Release. - `guest_gets` plus the three `guest_standard_streams*` tests: 4/4, 5 runs, including the 8-thread `CheckThreads` case. - Negative control: with `libc/src/StandardStreams.cpp` from main, `guest_gets` aborts (`missing gets export`). - `check_conventions.py --base a6dcea927`: passes. - `Ok+SYcoL19Y` is in the PS5 3.20 [libSceLibcInternal](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libSceLibcInternal.c) list (L17688). EOF and partial-line handling match FreeBSD 11.4 [`gets.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/stdio/gets.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.
UnhealthyKraken commented 2026-10-22 03:16:31 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331808461 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9342#issuecomment-6331808461). Originally posted by [UnhealthyKraken](https://github.com/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.
harisibrar1 commented 2026-10-22 13:40:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:40:41Z.

Review: APPROVED


Checked against main 8b3e39832a and FreeBSD 11.4 lib/libc/stdio/gets.c:

  • This still merges cleanly onto current main, and main has no gets yet (only fgets/gets_s), so nothing is duplicated.
  • It reads byte by byte through fgetc_nid_postfix on the guest __stdinp, so buffering and the EOF/error flags stay consistent with getchar, fgets and gets_s on main. The whole line is read under the stream lock, as FreeBSD's FLOCKFILE(stdin) does.
  • An error after a partial line returns the buffer, matching FreeBSD's break path, and a closed stdin gives EBADF as __srefill does. No issues found.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5615145082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9342#pullrequestreview-5615145082). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T13:40:41Z. **Review:** APPROVED --- Checked against main 8b3e39832a and FreeBSD 11.4 lib/libc/stdio/gets.c: - This still merges cleanly onto current main, and main has no `gets` yet (only `fgets`/`gets_s`), so nothing is duplicated. - It reads byte by byte through `fgetc_nid_postfix` on the guest `__stdinp`, so buffering and the EOF/error flags stay consistent with `getchar`, `fgets` and `gets_s` on main. The whole line is read under the stream lock, as FreeBSD's `FLOCKFILE(stdin)` does. - An error after a partial line returns the buffer, matching FreeBSD's `break` path, and a closed stdin gives `EBADF` as `__srefill` does. No issues found. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
UnhealthyKraken commented 2026-10-22 14:28:23 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6343234346 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9342#issuecomment-6343234346). Originally posted by [UnhealthyKraken](https://github.com/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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9342
No description provided.