fix(libc): publish the guest FILE status of a stream with atomic accesses #9223
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9223"
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 xXPBSXx on 2026-10-21T15:33:26Z.
What
FileStream::SyncStatusandSyncUnlockedStatuswrotereadRemaining,writeRemainingand theflagsword of the guest FILE after the stdio call without the FILE lock, so two threads on the same stream race, and the read-modify-write offlagscan drop an EOF or error bit. The status is now published through one helper,PublishStatus, which stores the two counters atomically and updates the flag word with a compare-exchange loop. The values written are unchanged; only the access is atomic. libc/stdio, but a thread-safety change only, no change of behaviour.Fixes #9222
Tested
guest_standard_streams(3 tests): 4 data race reports without the change, 0 with it, 3 of 3 pass. No new test: the plain build cannot observe the race; the existingguest_standard_streamstest is the one that fails under the sanitizer.python tools/check_conventions.py --base upstream/mainpasses;git merge-treeagainstmainis clean.__atomicbuiltins).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)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:54:05Z.
Review: APPROVED
Reviewed the focused
FileStreamchange against the reported TSan race. Both status-sync paths now publish the counters atomically and update the shared flags with a compare-exchange loop, so concurrent status publications no longer race or overwrite unrelated flag bits. Initialization, reopen and close assignments remain lifecycle operations; this PR does not expand into other stream state. The author reports 3/3guest_standard_streamsTSan tests and 45/45 Windows stdio/file-stream tests; hosted eligibility, conventions, intake, labels, progress report, and all relinker/register-context/write-watch jobs pass, with Linux and Windows aggregate jobs skipped by the workflow. I checked the automated FileStream overlaps manually: the macOS PRs change only thefeof_unlockedqualification inSyncUnlockedStatus, and archive PR #7447 changes lifecycle hooks; those hunks are distinct from this atomic publication fix.