feat(libc): implement unlocked character I/O #1765
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1765"
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 MarcZX10 on 2026-10-08T18:42:01Z.
What
Implement the missing
getc_unlockedandputc_unlockedimports. Use no-lock host CRT operations on Windows and POSIX unlocked operations elsewhere, while keeping the guest stream state in sync. Both imports appear in the audit in #1578.Tested
Linux: built
libcandguest_standard_stream_tests;ctest --test-dir build -R ^guest_standard_streams$ --output-on-failurepassed.python3 tools/check_conventions.py --base upstream/mainpassed. Windows and PS5 hardware not tested.Checklist
main; no other open PR implements these functionsImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-08T19:22:16Z.
No title reaches
getc_unlocked/putc_unlockedon main yet: the homebrew audit lists the import, but those titles stop earlier at other missing imports. Closing for now; reopen when it's a title's next stop on main, with the log line.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T07:39:01Z.
@MarcZX100
putc_unlockedis now a title's next stop onmainb6f649d9. With yourdirname(#3261) merged, Porpoise (PPSA99764) reports this on Linux (catalog build,sce_module/libc.prxunwrapped as #2605 requires):app.elf: symbol lookup error: app.elf: undefined symbol: H-QeERgWuTMThis head (
151814a3) merges cleanly ontob6f649d9,guest_standard_streamspasses 5/5 (--repeat until-fail:5), and Porpoise then stops atpathconf(oc98+zOImus).Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-11T08:56:51Z.
PPSA99902 validation and unlocked-status correction (2026-10-11, 2e12a9f4)
Validated the exact unmerged head
151814a3on pinned mainccf9ff90. This adapts MarcZX100's existing work; no new PR has been opened. Proposed correction/tests are preserved in our fork commit2e12a9f4. AI-assisted adaptation and investigation: Codex.Confirmed Linux behavior to correct: both new functions call
stream->SyncStatus()after the unlocked byte operation.SyncStatususesstd::feofandstd::ferror; glibc can acquire the FILE lock there. See pinned feof.c and ferror.c. Actual productionStandardStreams.cpp+FileStream.hppwere compiled into a native probe on Ubuntu 24.04 WSL, x86_64, glibc 2.39. With one thread holdingflockfilebut performing no I/O, an unlocked read/write from another thread did not finish within 1 second; the probe releases the lock and joins both threads before failing. 5/5 reads and 5/5 writes reproducedunlocked call waited for another thread's stream lock. The source link is glibc 2.42; the live probe separately establishes the behavior on installed 2.39.The correction adds
SyncUnlockedStatus, usingfeof_unlocked/ferror_unlockedon POSIX and the observed non-locking UCRTfeof/ferroron Windows, and uses it from both functions. It preserves guest EOF/error bits, encoding-error state, other stream flags, and resets guest read/write macro counters. Native byte I/O still uses the original PR'sgetc_unlocked/putc_unlockedand_fgetc_nolock/_fputc_nolock.guest_standard_streamsguest_standard_streamsctest -j12, RTX 5080, cache disabledThe full-suite failures are
agc_driver_f32_compare_constantand flat-aperture parts 0, 2, 3, 4, 5; several record device loss or crashes. All six reproduce serially. Their relationship to current upstream GPU changes is unresolved; GPU observations and failing byte-read controls are recorded on #3291. New I/O tests in GuestStandardStreams.cpp cover unsigned-byte conversion (including high-bit bytes), EOF/reset, write failure without file modification, guest macro state, encoding-error retention, and both held-stream-lock operations. The Windows standalone exception harness was not accepted as null/closed-stream proof; those refusal probes passed on Linux. No Linux full runtime/GPU build, other CRT or PS5-console equivalence is claimed.Title validation: PPSA99902, Sonic Unleashed Recompiled 01.003.000, original ELF SHA-256
c34f5b0848ef49e96a855076d8254254047e966e4fe56589d0e504fe13828479. Fresh default conversion uses relinker source exactly matchingf60923bfand the zero-return fallback protection from merged #2705. Runtime is our previously validated experimental integrationdff875a7, with pending/local prerequisites; this is not an unmodified-main startup claim.Before:
FAIL: unresolved ELF import H-QeERgWuTM from libSceLibcInternal.prx(putc_unlocked), 0.146 s.After replacing only
libc.prx(other 121 libraries, executable and guest module unchanged): five launches stop atFAIL: unresolved ELF import 0hlfW1O4Aa4 from libSceLibcInternal.prx(localeconv), 0.112–0.130 s. All exit0xC0000139, no timeout, before guest entry. An audit of all 122 native libraries confirmslibc.prxnow provides both unlocked NIDs and no native provider provideslocaleconv. This establishes loader progress, not successful guest execution of either I/O function. Each run restored/hash-verified the exact 123-library baseline population, guest module and original ELF/module. Locale follow-up belongs on existing #3249 / #1578.Fork integration preserved and revalidated (2026-10-11, 8f2b7210)
The correction is also carried into experimental integration
8f2b7210, branchcodex/experimental-ppsa99902-unlocked-io, directly afterdff875a7. Only the same three I/O source/test files and the debt entry change; all three I/O files exactly match the focused current-main commit. The integration retains its pinnedf60923bfbase and pending/local runtime prerequisites. Updating it toccf9ff90produced 11 graphics/debt conflicts; that merge was cleanly aborted and careful merge/validation remains pending. The standalone focused branch is based onccf9ff90.Windows 11 / RTX 5080, Vulkan required, shader cache disabled: full build and all 122 libraries pass; 823/828 full-suite tests pass, 5 documented display/no-Vulkan skips, 0 failures, max passed test 16.40 s (
ctest -j4). Extended stream tests then pass 5/5 again (max 0.19 s). Five fresh-conversion title launches stop atlocaleconv/0hlfW1O4Aa4,0xC0000139, 0.121–0.147 s, no timeout, before guest entry. Every replay restores the exact 123-library baseline/guest module and verifies original hashes. This second profile uses the complete rebuilt experimental runtime; the earlier libc-only profile remains the controlled replacement experiment.The integration's different base/runtime does not resolve or isolate the six failures on the newer-main focused build: all five corresponding aperture groups pass here, but newer main's
agc_driver_f32_compare_constantis not registered in this older integration. Both fork refs and their four changed-file Git blobs are verified from GitHub. No PR opened, no gameplay/console equivalence claim. AI-assisted: Codex.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T09:25:09Z.
Thanks @babyhuey for the Porpoise import trace, and @Amoenus for the controlled held-lock probes. The probes exposed that the original wrappers could still block: after the unlocked byte operation,
SyncStatus()calledfeof/ferror, which can reacquire the stream lock.I preserved the original implementation commit and carried the lock-free status correction as a separate credited commit in replacement PR #3375. That PR is based on current
main(5ad2cb8) and adds guest coverage for byte values, EOF/error state, and reads/writes while another thread holds the stream lock.mainguest_standard_streamspassed 5/5; conventions and diff checks passedccf9ff9guest_standard_streamspassed 5/5; five held-lock reads and writes passed (reported by @Amoenus)app.elf: symbol lookup error: app.elf: undefined symbol: H-QeERgWuTM. The report used original head151814a3and then stopped atpathconf; it does not validate the corrected headAmoenus's separate Sonic Unleashed run reports advancing from
putc_unlockedtolocaleconvafter replacinglibc.prx; it used a local experimental integration, not an unmodified-main startup.I tried to reopen #1765 after the new title evidence met the original request, but GitHub keeps its closed head frozen. The original description has been restored, and #3375 is the reviewable current-head replacement.
Pull request closed