Repository navigation
fix(libc): make flock advisory on Windows so other descriptors can read and write - #4958
Conversation
|
Windows test of this PR. Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, 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). |
87eb65c to
8941af9
Compare
|
Title evidence for this PR, Windows 11, MinGW GCC 15.2.0, Release, on
AI-assisted (Claude Code). |
|
A title this fixes on Windows: XPSemu (PPSA97358, an xemu port). Windows 11, RTX 3080, WinLibs GCC 15.2, Release. Built on
|
8941af9 to
773e7f2
Compare
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.main18c438b with feat(libkernel): add getdtablesize #5061 and feat(libkernel): report RLIMIT_NOFILE through getrlimit #5187. Without this PR the write after Mesa's cacheflockfails withEACCESabout 14 s in, andfflushthrows. With it (8941af9) the cache files get real data, and the title runs on to its GPU probe.main30f9612: 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