feat(libkernel): implement fcntl record locks on Windows #4480
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4480"
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-12T13:09:41Z.
What
Fixes #4479. Carries @screamm's fix commit from that issue (
screamm:feat/libkernel-record-locks-windows,b7cc2856), keeping the commit and its authorship, as the issue invites. The branch sits on top of #3649's two commits, which this commit does not need (#3649 is only how the titles reach the call); it cherry-picks onto currentmainwithout changes and builds there.On Windows,
fcntlrecord locks (F_GETLK,F_SETLK,F_SETLKWand the oldF_OGETLK/F_OSETLK/F_OSETLKWforms) throwfcntl: record locks are not implemented on Windows, which #3840 recorded as a limit. With #3649 applied, ProsperoRadio (PPSA99001) stops there onF_SETLK, and ProsperoTV (PPSA99003) does too once #4478's fix is applied. This commit applies FreeBSD 11.4's argument checks in FreeBSD's order (kern_fcntl,lf_advlockasync) and then followslf_blocks, where only locks of different owners conflict: every lock belongs to the one guest process, soF_SETLKandF_SETLKWsucceed without waiting andF_GETLKreportsF_UNLCK. Nothing is held on the host, because Windows byte-range locks are mandatory and would fail the guest's own reads and writes through its other descriptors; the fcntl TechnicalDebt entry records that other host processes neither see nor are seen by these locks. ASEEK_ENDlock on a directory and locks on character devices still throw. Linux is unchanged.guest_kernel_fcntlreplaces the old Windows "throws" expectation with the round trip and addsRecordLocksBelongToTheProcess(overlap merge and split, two descriptors on one range, another thread'sF_SETLK/F_SETLKW/F_GETLK,SEEK_CUR/SEEK_END, negative lengths, the 24-byte old struct,EINVAL,EBADFon read-only and write-only descriptors, relock after close); theEOVERFLOW, error-order,F_GETLKwrite-back and directory cases are Windows-only.Tested
guest_kernel_fcntl,guest_poll,guest_dup,guest_file_vector3/3; 620/620 ofctest -j8 -E "^agc_driver_|^video_out_flip"; ProsperoRadio relinked against the build (with #3649) gets past thefcntlstop and reaches #4478's.main33ae282e+ #3649 + #4478's fix + this commit): ProsperoRadio and ProsperoTV get pastpolland the record locks and stop next on the graphics side (#4030).main33ae282e.guest_kernel_fcntl,guest_poll,guest_dupandguest_file_vectorpass, and all 306guest_*tests pass. The new sharedRecordLocksBelongToTheProcesscases also pass withmain'sDescriptorControl.cpp, as expected since Linux forwards record locks to the host. I could not run the Windows path myself.guest_kernel_fcntl3/3 and fails withmain'sDescriptorControl.cpp(fcntl: record locks are not implemented on Windows, command=12, fd=3);ctest -E '^agc_'554/554; ProsperoRadio with #3649 gets past the database's record lock to its HTTP code.maind1fd9372+ #4525 stops atwhat(): fcntl: record locks are not implemented on Windows, command=12, fd=4(F_SETLKon a regular file); with this PR on top it gets past the lock and renders its menu for the full 60 s with no throw.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 LeandroLP23 on 2026-10-12T19:55:10Z.
The PR body says the Windows path wasn't run for this carry, so I ran it. Windows 11 (26300), WinLibs GCC 15.2.0, Ninja, Release,
BUILD_TESTING=ON, head43ffba87emerged ontomain2f4cc8983.Tests
guest_kernel_fcntl: 3/3.ctest -E '^agc_' -j 4: 554/554.main'sDescriptorControl.cpprestored,guest_kernel_fcntlfails withfcntl: record locks are not implemented on Windows, command=12, fd=3. That is the same message as in #4479.ProsperoRadio (PPSA99001, catalog 01.000.010), 60 s runs with
--windows:main+ #36490xc0000409after 40 s.download0/prosperoradio.logends at thesceKernelOpenof/download0/radio-browser.sqlite3(125 lines)main+ #3649 + this PR0xc0000409after 36 s. The log goes past the database to[ProsperoRadio][http] non-blocking sockets: NOT set(143 lines)The title's log redirect doesn't keep the
what()line in my runs, so the table shows how far the log gets, not the stop message. That fits the description: the title gets past the record lock on the database and stops later in its HTTP code, where #4479 expects thePOLLPRIstop (#4525).ProsperoTV (PPSA99003) exits after 10 s both with and without this PR. It needs #4525 first, and #4525 doesn't merge together with #3649: both change
Socket/src/Udp.cppandtests/GuestPoll.cpp. So I couldn't build the combination for it.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T22:11:11Z.
Review: APPROVED
Review of #4480 (fcntl record locks on Windows), head
43ffba87eVerdict: approve, relying on LeandroLP23's Windows run for the host path. One non-blocking note.
Scope first: I ran Linux only. On Linux the
#elsebranch uses the host's POSIX locks, so the WindowsProcessRecordLockis not compiled there. What I could check is the range/ordering/errno logic, by copying it into a stub harness.What I ran (PR head merged onto upstream/main
ee4962190, clean env):length - 1overflow term gives 6,912 mismatches; dropping the F_GETLK unknown-type check gives 241,704; dropping thestart == 0guard gives 0 (when length < 0,start + length < 0already catches it, so the guard is redundant but harmless).git merge-treeof this PR with #4555 (also edits DescriptorControl.cpp InitialEntry) is clean.From LeandroLP23's comment, not run by me: Windows 554/554, guest_kernel_fcntl 3/3, and the failure message with main's DescriptorControl.cpp restored. In their ProsperoRadio runs the title exits 0xc0000409 both before and after this PR; with the PR the log gets past the database open to the HTTP code.
Not checked: the "SEEK_END on a directory still throws" case (the test asserts it under _WIN32 only).
Note: the
start == 0guard in LockRangeError is redundant when length < 0. Fine to leave.Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T01:30:49Z.
A title that needs this: ProsperoTV (PPSA99003) on Windows 11 (WinLibs GCC 15.2, RTX 3080). On
maind1fd9372+ #4525 (POLLPRI under WSAPoll) it gets into its HUI and then stops at:That's F_SETLK on a regular file. With this PR stacked on top (fork
test/verify-tvlock, c28bb5e0; merges clean), it gets past the lock and renders its menu for the full 60 s with no throw:[TV] splash hidden=1, then[TV] frames=600 mean=23.50ms max=25.38ms ... draws=2 shapes=407.guest_kernel_fcntlpasses 5/5 on that head, with no warnings inDescriptorControl.cpporGuestKernelFcntl.cpp.