fix(libc): make flock advisory on Windows so other descriptors can read and write #4958
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4958"
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 milescoviello on 2026-10-13T06:31:16Z.
What
Fixes #4957. Carries @DavidSamir's fix branch from that issue (
DavidSamir:fix/libc-flock-advisory-windows,e4a1b54a, three commits), keeping the commits and their authorship. The fix and the test apply to currentmainwithout changes. After rebasing, the debt commit keeps the entriesmainhas added or changed next to theflockline it edits.On Windows, while one descriptor held a
flockon a file, reads and writes through any other open of that file failed: with an exclusive lock everything failed (EIO/EACCES), with a shared lock every write.GuestFileLock_nid_no_patchlocked the whole file withLockFileEx, and a Windows byte-range lock is enforced on every read and write that touches it. FreeBSD'sflock(2)locks are advisory ("processes may still access files without using advisory locks"), and the Linux build reads and writes normally;docs/dev/debt/libc.mdrecorded the gap. The lock and the unlock now take one byte at offset 2^63 - 2 instead of the whole file: no read or write reaches it, while twoflockcalls still meet on the same byte, so shared and exclusive locks exclude each other as before between descriptors, duplicates and processes. Linux is unchanged.The commits are the fix (
FileLock.cpp), a test inguest_file_lock_conversion(with an exclusive lock held,sceKernelPwrite,sceKernelWriteandsceKernelPreadthrough the other open succeed and read back what was written, andflock(LOCK_SH|LOCK_NB)through it still fails with errno 35), and the debt entry describing the byte.Tested
main'sFileLock.cppguest_file_lock_conversionfails and with the fix the sixguest_file_lock_*tests pass 5/5, includingprocess, which takes the lock from a second process; a 54-line probe matches the Linux build on every line, a 95-line probe of shared/exclusive/upgrade/dupcases shows no lock line differing from Linux, and probes of 122, 188, 15 and 313 lines over the descriptor, file and stream functions are unchanged; no measurable cost; twelve catalog titles end the same way with both sets of libraries; fullctest1026/1028, the two failures being GPU tests that fail the same way onmainon that machine.mesa_cache.dbandmesa_cache.idx,fdopens each with"r+b"and locks them. Without this PR, the nextfflushon one of those streams fails and libc throwsfflush: flush failed: VLC after 2 s, XPSemu after 6 s. With it, VLC runs for the whole 60 s run, and XPSemu goes on to compile its SPIR-V cache and start its emulation; it then stops on a GPU timeout, a separate issue.main18c438b1with #5061 and #5187. Without this PR the write after Mesa's cacheflockfails withEACCESabout 14 s in, andfflushthrows. With it (8941af9d) the cache files get real data, and the title runs on to its GPU probe.main30f961266: the build is clean and all 345guest_*tests pass in two runs. The changed code and the new test are Windows only, so this shows only that the Linux build is unaffected; a MinGW-w64 GCC 13-fsyntax-only -Wall -Wextracompile ofFileLock.cppandGuestFileLock.cppis clean. I could not run Windows myself.tools/check_conventions.py --base upstream/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T07:05:43Z.
Windows test of this PR.
Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release,
BUILD_TESTING=ON,-j2,libusb-cmakefrom a local checkout. Built frommainea2bbefb2with this PR and six other open PRs (#4958, #4956, #4954, #4953, #4946, #4942, #4927) merged together; the merges had no conflict.Result: guest_file_lock_duplicate, guest_file_lock_lifetime, guest_file_lock_conversion, guest_file_lock_threads, guest_file_lock_streams, guest_file_lock_process (6 of 6) pass.
Not checked: whether the test fails without the change in the library code; the PR was not tested alone, only in the combined merge (the tests of the other PRs in the batch also pass); no title run; Linux not tested.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T15:00:29Z.
Title evidence for this PR, Windows 11, MinGW GCC 15.2.0, Release, on
main3faa9cb40merged with the open PRs these titles need to load (#4377, #4105, #5061, #5187 and others) and converted with--windows-fixed-base 0x400000(#4140, for their fixed-base GOT reads):mesa_cache.dbandmesa_cache.idxwithO_RDWR|O_CREAT|O_CLOEXEC,fdopens each with"r+b"(VLC guest 0x1827B70) and locks them. Without this PR, the nextfflushon one of those streams fails and libc throwsfflush: flush failed(VLC after 2 s, XPSemu after 6 s).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T18:48:13Z.
A title this fixes on Windows: XPSemu (PPSA97358, an xemu port). Windows 11, RTX 3080, WinLibs GCC 15.2, Release. Built on
main18c438b1with #5061 (getdtablesize) and #5187 (RLIMIT_NOFILE) merged, relinked with--windows-fixed-base 0x400000(#4013).radv_builtin_shaders/part0/mesa_cache.dband.idx) takes itsflock, and the next write fails withEACCES. Thefflushthen throwsfflush: flush failedand the title exits with 0xC0000409..db1663 B and 4209 B,.idx216 B and 244 B, in part0 of each cache). The title runs on to xemu's GPU probe, a separate stop (see #5061).