fix(libkernel): give flock BSD semantics on Windows #1755
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1755"
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 Zurisen on 2026-10-08T18:33:42Z.
What
Fixes #1754. On Windows,
flocknow tracks the one lock each descriptor holds (FileLock.cpp), as FreeBSDflock(2)defines it:LOCK_UNwithout a lock and a repeat of the held mode return 0.LOCK_SHandLOCK_EXreleases the held lock and takes the new one. As on FreeBSD, the conversion is not atomic, and a failedLOCK_NBconversion leaves no lock.closeandsceKernelCloseforget the descriptor's lock, so a reused descriptor number starts unlocked.sys_flockdoes, before either host sees it:LOCK_UNoverLOCK_EXoverLOCK_SH, other bits ignored, and an operation with none of the three fails withEBADF. Before, Linux rejected such operations withEINVALand Windows took them as a shared lock. An invalid descriptor setsEBADF.LockFileEx, so a wait on one descriptor does not blockflockon others.Contention still throws from
flock_nid_postfix, as before and as on Linux. On Linux only the operation decoding changes.Tested
Windows 11 (10.0.26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, RTX 4070 Laptop:
guest_filesystemgainsflockcases: unlock without a lock, repeatedLOCK_EX,LOCK_EX→LOCK_SH→LOCK_EXconversions, shared locks on two descriptors, repeatedLOCK_SHreleased by oneLOCK_UN, descriptor reuse aftercloseandsceKernelClose, and malformed operations (0andLOCK_NB | 0x10fail withEBADF,LOCK_EX | LOCK_NB | 0x10locks,LOCK_UN | LOCK_EXunlocks).LOCK_UN(error=158); with the change they pass. Without the decoding commit the malformed cases abort (error=87).ctestwithANYPS5_REQUIRE_VULKAN=1 --repeat until-fail:3: 506/507 passed ond70b8998.libstarget builds. The failure,pr_overlap_encoding, also fails on main locally: it patchessubprocess._text_encoding, which Python 3.10 does not have.guest_filesystemon the earlier head, and nauroth ran it on Ubuntu 24.04 in #1764.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T20:58:54Z.
The Linux Build run for this PR has one failure:
agc_driver_buffer_formattimed out; the other tests passed. This is the slow lavapipe case tracked in #1762, so it may be unrelated to this Windows-only change. The comparison Build run onmainaa277b3(37840594063) was cancelled duringcmake --buildbefore CTest started. A new Build run on currentmain0447793(37844230361) is queued and may provide a CTest baseline. This PR head is 21 commits behind currentmain; CONTRIBUTING asks to keep the branch current, so please rebase and rerun the final checks.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:36:04Z.
Update to the baseline noted above: the Build run on
main364a56b(37845561389) was cancelled before Linux CTest completed when #1826 advancedmain. The replacement main Build onaa258760(37847684141) is running. The PR Linux failure remainsagc_driver_buffer_format; there is still no completed current-main baseline to determine whether it reproduces without this PR.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:37:13Z.
Further baseline update:
mainadvanced todc79e9b1when #938 merged, cancelling theaa258760Build run (37847684141) before CTest. A replacement Build (37847982017) is queued ondc79e9b1. There is still no completed current-main Linux baseline foragc_driver_buffer_format.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:43:05Z.
One more main-baseline update:
mainadvanced to94b1eecb(#533), cancelling thedc79e9b1Build (37847982017) before CTest finished. The replacement Build (37848560105) is running on94b1eecb. No completed current-main comparison is available yet.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:46:19Z.
Additional local evidence for #1762: after rebuilding
agc_driver_buffer_format_testson Debian 12/GCC 12.2 with llvmpipe LLVM 15.0.6,ctest -R ^agc_driver_buffer_format$ --timeout 120passed in 1.40 s (ANYPS5_NO_SHADER_CACHE=1). This does not reproduce the 93–108 s GitHub runner timing and cannot establish whether the PR failure is baseline behavior. The latest-main Build baseline is still running on94b1eecb.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:51:44Z.
The current-main baseline has completed: Build
37848560105on94b1eecbpassed Linux and Windows, and Linux CTest passed 492/492.agc_driver_buffer_formatpassed all three--repeat until-fail:3 --parallel 4runs in 16.03 s, 15.97 s and 16.03 s withANYPS5_NO_SHADER_CACHE=1. This does not reproduce the earlier PR-branch timeout. Please rebase this PR onto currentmainand rerun its checks to determine whether the old-head timeout remains.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:55:33Z.
Current-base update: this PR head is now 30 commits behind
main94b1eecb(merge base4ddbf049). The latest-main Build completed successfully (37848560105);agc_driver_buffer_formatpassed its three parallel CI repeats in about 16 s each. Please rebase this Windows flock change onto currentmainand rerun CI; the old head’s timeout does not match the current-main result.Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-09T06:38:47Z.
Rebased onto
f1451396; the full suite passes locally on Windows (488/488). CI re-runs on the new head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T13:45:59Z.
One Windows/Linux parity case is missing in
File::Flock:modemasks the three operation bits, and the function only tests that masked value, so any other bits are silently ignored. For example,LOCK_EX | 0x10acquires an exclusive lock on Windows, while the native Linuxflockrejects an invalid operation withEINVAL. Please rejectoperation & ~(LOCK_SH | LOCK_EX | LOCK_NB | LOCK_UN)and add a regression case; otherwise malformed guest flags behave differently by host. Linux documentsEINVALfor an invalidop: https://www.man7.org/linux/man-pages/man2/flock.2.html.Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-09T16:22:17Z.
@MarcZX100 Agreed that the masked bits made the hosts differ. I matched FreeBSD rather than Linux, since the console's
flockis FreeBSD'ssys_flock: it takesLOCK_UNoverLOCK_EXoverLOCK_SH, ignores other bits, and fails withEBADFwhen none of the three is set. Rejecting unknown bits withEINVALwould move both hosts away from the console.flock_nid_postfixnow decodes the operation that way before either host sees it (e9f28257), so Windows, Linux and the console agree. Regression cases inguest_filesystem:0andLOCK_NB | 0x10fail withEBADF,LOCK_EX | LOCK_NB | 0x10locks, andLOCK_UN | LOCK_EXunlocks; they abort without the commit. Rebased ontod70b8998; 506/507 pass locally on Windows, the failure beingpr_overlap_encoding, which also fails on main with Python 3.10.Imported from boykopovar/AnyPS5. Originally posted by Zurisen on 2026-10-10T04:58:42Z.
Rebased onto
bc40a6b5to resolve the include conflict with #1727 inOpen.cpp(kept both includes). Full suite locally on Windows: 604/606. The failures arepr_overlap_encoding, which also fails on main with Python 3.10, and onevideo_out_flip_controlscrash under--parallel(#2520); the latter passes 20/20 alone.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T05:40:48Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/File/include/FileLock.hppcore/libs/prx/libkernel/File/src/FileLock.cpp