feat(libc): implement unlocked character I/O #3375

Merged
MarcZX10 merged 2 commits from upstream-pr/3375 into main 2026-10-11 09:31:03 +00:00
MarcZX10 commented 2026-10-11 09:24:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T09:24:19Z.


What

Implement the missing getc_unlocked and putc_unlocked imports with host unlocked byte I/O while keeping guest EOF/error state and read/write macro counters synchronized.

This replaces closed #1765. The original PR was closed when no title reached these imports; new title evidence in its discussion now identifies them as a blocker. GitHub froze the closed PR head, so this branch carries the corrected change on current main. The original implementation commit is preserved, and Romans Pokrovskis's lock-free status fix is a separate commit adapted from his fork commit.

Linux feof and ferror may reacquire the stream lock, so status synchronization after unlocked byte I/O uses feof_unlocked and ferror_unlocked. Windows uses _fgetc_nolock and _fputc_nolock; the UCRT status queries were exercised while another thread held the stream lock. Console and other host CRT behavior remain unverified; the limitation is recorded in TechnicalDebt.md.

The Porpoise (PPSA99764) report on #1765 identifies putc_unlocked as its next unresolved import. Its startup log after #3261 was app.elf: symbol lookup error: app.elf: undefined symbol: H-QeERgWuTM. The run used original head 151814a3 and then stopped at pathconf; that is evidence of import reachability, not validation of this corrected head. The separate Sonic Unleashed Recompiled (PPSA99902) validation reports that replacing only libc.prx advances startup from putc_unlocked to localeconv. That run used a local experimental integration and prerequisites, so it is not an unmodified-main startup claim.

Tested

On Linux x86-64, GCC 12.2, Release, current main (5ad2cb8):

  • Built guest_standard_stream_tests.
  • guest_standard_streams passed five consecutive runs (--repeat until-fail:5), including held-lock reads and writes, byte conversion, EOF/error status, and error clearing.
  • python3 tools/check_conventions.py --base upstream/main and git diff upstream/main...HEAD --check passed.

Independent validation of the same corrective patch on an earlier base (ccf9ff9):

  • Windows 11 / WinLibs GCC 15.2 UCRT: guest_standard_streams passed 5/5; held-lock native probes passed for five reads and five writes. This was not rerun on the current head.
  • Linux glibc 2.39 native probes passed for five reads and five writes; the original status sync blocked in five runs each. These results were reported by Amoenus in the PR discussion.

Windows on the current head and PS5 hardware were not tested.

Checklist

  • Based on current main; no other open PR implements these functions
  • One topic per PR; follow-ups go in a new pull request
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); no stub added
  • No notes, investigation .md files or images added
  • No third-party code added
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818036199 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3375). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T09:24:19Z. --- ### What Implement the missing `getc_unlocked` and `putc_unlocked` imports with host unlocked byte I/O while keeping guest EOF/error state and read/write macro counters synchronized. This replaces closed [#1765](https://github.com/boykopovar/AnyPS5/pull/1765). The original PR was closed when no title reached these imports; new title evidence in its discussion now identifies them as a blocker. GitHub froze the closed PR head, so this branch carries the corrected change on current `main`. The original implementation commit is preserved, and Romans Pokrovskis's lock-free status fix is a separate commit adapted from [his fork commit](https://github.com/Amoenus/AnyPS5/commit/2e12a9f478b1356353d463374c2e7bffb1984a3c). Linux `feof` and `ferror` may reacquire the stream lock, so status synchronization after unlocked byte I/O uses `feof_unlocked` and `ferror_unlocked`. Windows uses `_fgetc_nolock` and `_fputc_nolock`; the UCRT status queries were exercised while another thread held the stream lock. Console and other host CRT behavior remain unverified; the limitation is recorded in `TechnicalDebt.md`. The Porpoise (PPSA99764) report on #1765 identifies `putc_unlocked` as its next unresolved import. Its startup log after #3261 was `app.elf: symbol lookup error: app.elf: undefined symbol: H-QeERgWuTM`. The run used original head `151814a3` and then stopped at `pathconf`; that is evidence of import reachability, not validation of this corrected head. The separate Sonic Unleashed Recompiled (PPSA99902) validation reports that replacing only `libc.prx` advances startup from `putc_unlocked` to `localeconv`. That run used a local experimental integration and prerequisites, so it is not an unmodified-main startup claim. ### Tested On Linux x86-64, GCC 12.2, Release, current `main` (`5ad2cb8`): - Built `guest_standard_stream_tests`. - `guest_standard_streams` passed five consecutive runs (`--repeat until-fail:5`), including held-lock reads and writes, byte conversion, EOF/error status, and error clearing. - `python3 tools/check_conventions.py --base upstream/main` and `git diff upstream/main...HEAD --check` passed. Independent validation of the same corrective patch on an earlier base (`ccf9ff9`): - Windows 11 / WinLibs GCC 15.2 UCRT: `guest_standard_streams` passed 5/5; held-lock native probes passed for five reads and five writes. This was not rerun on the current head. - Linux glibc 2.39 native probes passed for five reads and five writes; the original status sync blocked in five runs each. These results were reported by Amoenus in the PR discussion. Windows on the current head and PS5 hardware were not tested. ### Checklist - [x] Based on current `main`; no other open PR implements these functions - [x] One topic per PR; follow-ups go in a new pull request - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); no stub added - [x] No notes, investigation `.md` files or images added - [x] No third-party code added - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 09:24:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T09:24:40Z.


Progress report (09bd4aa → 228532e)

📈 System libraries: 85.49% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libc getc_unlocked_nid_postfix
libc putc_unlocked_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107560560 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3375#issuecomment-6107560560). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T09:24:40Z. --- <!-- progress-report --> ### Progress report (09bd4aa → 228532e) 📈 **System libraries**: 85.49% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `getc_unlocked_nid_postfix` | | libc | `putc_unlocked_nid_postfix` | </details>
adriadam10 commented 2026-10-11 09:31:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:31:00Z.


Checked the unlocked byte I/O and status sync (feof_unlocked/ferror_unlocked), the held-lock tests and the TechnicalDebt entry; guest_standard_streams passes on Linux, and fails to link without the change. Windows held-lock results by @Amoenus noted; merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107607076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3375#issuecomment-6107607076). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:31:00Z. --- Checked the unlocked byte I/O and status sync (`feof_unlocked`/`ferror_unlocked`), the held-lock tests and the TechnicalDebt entry; `guest_standard_streams` passes on Linux, and fails to link without the change. Windows held-lock results by @Amoenus noted; merging once CI is green.
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!3375
No description provided.