fix(libc): preserve pushed-back input across stream status operations #27537
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27537"
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 JJenkx on 2026-11-26T16:47:00Z.
What
feof,ferrorand their unlocked forms currently publish status through helpers that also invalidate recorded pushback.clearerrreaches the same invalidation path. Readingabc, pushingQ, querying status and purging consequently readscinstead of the pendingQ.Separate status refresh from the invalidation needed after stream I/O. Queries and error clearing refresh the guest flags while retaining the pending-input record; the existing I/O synchronization helpers still invalidate it. The regression also checks that querying after consuming
Qdoes not bring it back.The pending-byte record is shared by wrappers around the same native file. Consuming input through either wrapper clears the shared record. Reopening clears the record for the previous native file through the alias synchronization introduced on main. The branch includes the current #27505 head, which depends on #27497, and its updated stream-purge fixtures. These status-operation and purge combinations remain unmeasured on console.
Tested
At
61e7c457f815, the merge from #27505 changes fixtures only. On Linux, I linked the updated general purge fixture and all three restore-failure cases against the unchanged libc provider from7a6a06cfeb37. All four passed. At that provider head, all 22 focused CTests and 16 alias matrix cases passed. A separate reopen probe passed all 14 cases at both616fbf3b1350and7a6a06cfeb37. It covered the original wrapper and an alias across six status operations and the no-query control. The selected Windows job for that head passed bothguest_stream_purgeandwindows_write_watch.At
2f17db0b0606, I merged #27505b009a3bd3be3, which includes current mainb396d834cb05and the single-initialization purge fixture update. Linux x86_64 Release built against 49 verified submodule pins. 22/22 focused CTests passed with zero skips, including the six status/pushback cases and all four purge cases. The selected Windows job for this head also passed all six status/pushback cases,guest_stream_purge, andwindows_write_watch.Linux x86_64, glibc 2.44, Release, exact head
2230a9248cb6b38415f2689dd191613fe17bb2a3, 49 pinned independent submodules. Guarded libc/libkernel and focused fixture builds passed. 20/20 focused stream CTests passed, zero skips. The six new cases cover locked/unlockedfeof,ferrorandclearerr; each runs middle-of-file and EOF scenarios and checks status flags, errno, logical position, pending input and consumed-input non-resurrection.Same-executable controls: SHA-256
86ab66a5f6ab7f89c2cc78e7a83d09b6ec22e49f66c1fd6ed9659d768c28fd0e. All six cases abort atpending input survives a status operation and purgeagainst both the unchanged main production provider (fixture-only commitb4eb9e94ec367c1ba32ea939714c1eba5fa750a8) and public prerequisite4a62eed15b6a863fcde6ec12d50eec8275026439; all six pass against this head. The complete baseline CTest selection passes the existing 14 tests and fails those six new tests. Provider hashes and actual loader initialization paths are recorded;ldd -rreports no unresolved symbols.Conventions, debt folding and whitespace checks pass. A full merge with current main
23f6bcf7c7df5b23d518b41fe623a88fb9bef2c7is clean (tree6309a6499b0ec91074f74fee059eff26a15b891a); composition with owned #27494 is also clean. The main composition tree was not built. The #27494 composition (tree09e40c36aea1df84e4b3ae5027e112f4d192fa86) has now passed 20/20 focused CPU tests plus a seven-case same-executable reopening/status probe. Public2230 fails all seven control cases and the composition passes all seven; commands and raw evidence. The current2230 source does not yet contain #27494. These CPU results do not qualify its full patched SDK or game behavior.The final branch scan checked 2,419 open PRs and exited 2 because eight older branches conflict with main: #7447, #8150, #11831, #12682, #12688, #12700, #12965 and #24406. Targeted shared-source/patch review found no duplicate fix. Future composition must preserve #11831's atomic handle/lifetime logic and #24406's bad-descriptor status branches in the refresh helpers. No clean full peer merge or runtime qualification is claimed. Export-overlap #19434 forwards libc-internal queries to libc and does not implement this tracking fix.
Additional Linux CPU qualification at the same exact head: the full patched SDK libraries and relinker built successfully (413 patched modules; 833 frozen bank files), followed by 20/20 focused stream CTests, zero skips. The same NID-linked fixture executable (
161fb1622d2ceb302ee69441bc32b9d6c9cf83dca94eab3da8f719fe04177987) fails all six status-operation cases against patched prerequisite SDK8dccb31affee0c6cf5bed802c6b8181926a68b9dand passes all six against this head. Each passing case covers middle-of-file and EOF scenarios. Actual patched libc initialization paths and provider hashes are recorded; no unpatched provider fallback is used. This qualifies the patched libc guest ABI in a CPU fixture. The first conversion copy retained unresolved guest imports; itsldd -rpreflight caught them before execution, and its receipts are retained.Full SDK build, focused CPU tests and NID-linked control logs — SHA-256
63cddf65198818c8da79b74406073270e3e34b9cf8021e2860d902c423168134, 142,738 bytes, 37 payloads; anonymous download and all payload hashes verified. AGC execution tests were configured as a build selection only and were not run. No game-based HLE-fix, GPU-test, performance, Windows, macOS, console or full-suite qualification is claimed.Evidence SHA-256
e30c73d607bb74ae90ffb836be346053567905c14b7d142b80066a6b9a221e13(29,109 bytes, 62 payloads), anonymous download and every payload hash verified. Exact build/test commands, focused delta, provider hashes and raw logs.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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-26T16:51:40Z.
Review: COMMENTED
Actionable comments posted: 1
162b5f02-d904-445f-a5a0-6eb0e457cffcReviewing files that changed from the base of the PR and between
23f6bcf7c7and2230a9248c.core/libs/prx/libc/include/FileStream.hppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StreamPurge.cppcore/libs/prx/libc/tests/cmake/guest_stream_status_pushback.cmakecore/libs/tests/GuestStreamPurge.cppcore/libs/tests/GuestStreamStatusPushback.cppdocs/dev/debt/changes/fix-libc-fpurge-keep-position.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T17:14:29Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the focused host test results and inspected code support the status-refresh and pushback-preservation fix.
What I ran
Reviewed head
2230a9248cb6b38415f2689dd191613fe17bb2a3. No commands or tests were run; I reviewed the supplied diff and targeted source context. The description reports Linux x86_64 focused builds and 20/20 CTests passing, but those results were not independently run here.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, test, console, platform, or full-suite checks were run independently. The description reports eight older branches conflicting with main and says future composition must preserve their descriptor and lifetime logic; those branches were not inspected.
files.jsonwas not available through the reader; the manifest lists seven changed files, all marked included, and all seven were read. No additional exclusions were confirmed.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-28T16:40:18Z.
Review: COMMENTED
Actionable comments posted: 1
bebc0c5e-9fb7-4cff-ad65-6770f8a3e41dReviewing files that changed from the base of the PR and between
2230a9248cand616fbf3b13.core/libs/prx/libc/include/FileStream.hppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StreamPurge.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T16:55:18Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The purge now reports failure for nonseekable streams with pending pushback, although those streams intentionally discard pushback and the existing pipe test expects success.
What I ran
Reviewed head
616fbf3b1350c6632401c397323c9e627521a203usingrepo_read.py. No tests or builds were run; validation results in the PR description are author-reported.Results
Findings
Blocking
core/libs/prx/libc/src/StreamPurge.cpp:93: WhenTellSeekable()returns a negative value, restoration is skipped, leavingrestoredat zero whilekeptstill contains pushed-back bytes. Thecompletecheck then returns-1. A pipe with pushed-back input hits this path; the existingCheckPipetest expectsfpurgeto succeed while discarding that input. Treat the nonseekable discard case as successful, while retaining failure reporting for an attempted but incomplete restoration.Non-blocking
None.
Not verified
No builds, tests, console behavior, or author-provided logs were independently verified. All seven changed files listed in the manifest were read:
FileStream.hpp,StandardStreams.cpp,StreamPurge.cpp,guest_stream_status_pushback.cmake,GuestStreamPurge.cpp,GuestStreamStatusPushback.cpp, andfix-libc-fpurge-keep-position.md. No changed files were excluded.To get this to a good state
Make purge succeed when pushback is discarded on a nonseekable stream, while preserving the error result for an incomplete restoration attempt. Run the focused stream purge and status-pushback tests on the new head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T20:15:10Z.
Review: COMMENTED
Actionable comments
73807cae-9408-4590-9dc8-79545ecf15f0Reviewing files that changed from the base of the PR and between
616fbf3b13and7a6a06cfeb.core/libs/prx/libc/include/FileStream.hppcore/libs/prx/libc/src/FileAndHeap.cppcore/libs/prx/libc/src/StandardStreams.cppcore/libs/prx/libc/src/StreamPurge.cppcore/libs/tests/GuestStreamStatusPushback.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T20:28:42Z.
Review: COMMENTED
Actionable comments
ebc2c105-8208-41c2-b923-3aae0b09c533Reviewing files that changed from the base of the PR and between
7a6a06cfeband61e7c457f8.core/libs/prx/libc/tests/cmake/guest_stream_purge_restore_failure_tests.cmakecore/libs/tests/GuestStreamPurge.cppcore/libs/tests/GuestStreamPurgeRestoreFailure.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T20:50:08Z.
Review: APPROVED
Reviewed — looks good
The reviewed change separates stream status refresh from pushback invalidation, and I found no verified blocking defects at head
61e7c457f8153d111487bc4708a2f4f57c9171e2.What I ran
Read-only source review at the exact head above using
repo_read.pyand the prepared review materials. No tests, builds, or merged-preview checks were run; no compiler was invoked.Results
Negative control
Not run; no test executable was run during this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
No tests or builds were independently run, and Windows, macOS, console, and game behavior were not verified. The PR description reports Linux CPU test results; those remain author-reported for this review. All 10 files listed under
reviewedinfiles.jsonwere read;files.jsonlists no excluded files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-02T22:48:29Z.
Review: COMMENTED
Actionable comments
ungetwcclears pushed-back input thatfpurgeshould keep.d5470a02-448e-42ef-bb88-f9d26bbe84efReviewing files that changed from the base of the PR and between
61e7c457f8and2f17db0b06.core/libs/prx/libc/include/FileStream.hppcore/libs/prx/libc/src/StreamPurge.cppcore/libs/tests/GuestStreamPurge.cppdocs/dev/debt/changes/fix-libc-fpurge-keep-position.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-02T23:09:37Z.
Review: APPROVED
Reviewed — looks good
Nothing in the reviewed changes blocks merging; the reported CPU checks are author-provided and were not run in this review.
What I ran
Reviewed head
2f17db0b0606f13ddf08fac8c539cddb50c8cdaeusing the prepared diff and included file texts. Inspected targeted source ranges and changed tests; no tests or builds were run. The pinned reader search returned a match but could not write its read log in the read-only workspace. The bundle lists 10 reviewed files and no excluded files.Results
Negative control
The description reports six same-executable controls failing against baseline providers and passing at this head. I did not run those controls.
Findings
Blocking
None.
Non-blocking
None.
Sources
The reviewed changes separate status refresh from pushback invalidation, track pushback on the shared stream gate, and preserve successfully restored bytes when purge restoration fails: FileStream.hpp, StandardStreams.cpp, and StreamPurge.cpp.
Not verified
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:56:27Z.
Review: COMMENTED
Ran the exact changed stream code with the Linux
GuestStreamPurgefixture, all three restore-failure modes, and all sixGuestStreamStatusPushbackmodes. They passed, including locked and unlocked status calls after pushback at both ordinary stream positions and EOF.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T12:36:31Z.
Review: APPROVED
I read the diff at
2f17db0b06. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged intomainatdaa61711afetogether with other open PRs (so not an isolated build).guest_stream_status_pushback_*tests andguest_stream_purge: pass on both.main's, the same six fail too.Not checked: a console.
AI-assisted: yes (Claude Code)
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.