fix(libc): FileStream::SyncStatus races when two threads use the same stdio stream (ThreadSanitizer: data race) #9222
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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:10Z.
FileStream::SyncStatus()andSyncUnlockedStatus()(core/libs/prx/libc/include/FileStream.hpp) update the guest-visibleFILEprefix after a stdio call with plain writes:readRemaining = 0,writeRemaining = 0andflags = (flags & ~0x60) | ....fputc_nid_postfixcallsstd::fputc(which locks the FILE) and thenSyncStatus()after it has unlocked, so two threads writing to one stream run these writes concurrently, and the read-modify-write offlagscan lose an update (for example an EOF or error bit).Found with ThreadSanitizer (Ubuntu 24.04 WSL2, GCC 13.3, RelWithDebInfo,
-fsanitize=thread, run withsetarch -R,main27fabb6b7):guest_standard_streamsreports 4 data races at FileStream.hpp:205 and :207, fromfputc_nid_postfix(StandardStreams.cpp:107) called by the test's writer thread (GuestStandardStreams.cpp:896) and by the main thread (:900). The same function is used by about 20 call sites in libc, so other tests report it too (SyncUnlockedStatusat :213 and :222).AI-assisted (Claude Code).