Repository navigation
fix(libkernel): answer F_GETLK with F_UNLCK on Linux and macOS - #7073
Merged
oneandonlydean merged 2 commits intoOct 17, 2026
Merged
Conversation
fcntl threw for F_GETLK with an F_UNLCK request on the hosts that use POSIX locks, as Linux's F_GETLK rejects that type. FreeBSD 11.4's kern_fcntl accepts it and lf_getlock reports the first overlapping lock that lf_blocks lets conflict: another owner's lock, one of the two being a write lock. For an F_UNLCK request that is exactly another owner's write lock, the same set an F_RDLCK request finds, so the host is asked with F_RDLCK and the reply is written back as for the other types.
The fcntl tests only ever held locks in the guest's own process, where FreeBSD's lf_blocks never reports a conflict, so the host lock path that answers F_GETLK was not exercised. A forked process now holds a read lock, a write lock and a write lock to the end of the file through the host. F_GETLK with F_UNLCK reports only the write locks, F_RDLCK the same and F_WRLCK the read lock, each with the owner's pid and SEEK_SET; F_SETLK over the read lock fails with EAGAIN, and nothing is reported once the owner exits.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On Linux and macOS,
fcntl(F_GETLK)withl_type = F_UNLCKhitNotImplemented_nid_no_patch. Only the Windows path handled it. FreeBSD 11.4 accepts the request: inlf_getlock/lf_blocks, anF_UNLCKrequest conflicts only with another owner's overlapping write lock, exactly like anF_RDLCKrequest. The host query is now made withF_RDLCKforF_GETLK, so the reply matches FreeBSD.F_SETLK/F_SETLKWwithF_UNLCKstill map to the host'sF_UNLCK.Two commits:
fix(libkernel): answer F_GETLK with F_UNLCK on Linux and macOS: the mapping change inDescriptorControl.cpp. The existing fcntl test's unlock query moves out of its#ifdef _WIN32block and now also covers a reader descriptor and aSEEK_CURrange. Adds a libkernel debt note.test(libkernel): cover F_GETLK against another process's record locks: the existing tests only took locks in the test's own process, which never conflicts, so the host lock path was never exercised. A forked process now holds a read lock, a write lock, and a write lock to the end of the file. The test checks thatF_UNLCKandF_RDLCKreport only the write locks andF_WRLCKreports the read lock, each with the owner's pid andSEEK_SET. It also checks thatF_SETLKover the read lock fails withEAGAINand that nothing is reported after the owner exits. UNIX-only, because it usesfork.Tested
Linux x86_64:
guest_kernel_fcntland the newguest_record_lock_ownersboth passed 5 of 5 runs. With the fix reverted,guest_record_lock_ownersaborts with "not implemented" and leaves no stray child process.tools/check_conventions.py --base upstream/mainpasses. The progress report is unchanged against the merge-base. Not run on Windows (that path already handledF_UNLCKand its code is unchanged) or macOS. Note:guest_kernel_fcntlhas occasionally aborted on the first ctest run after a rebuild, also on branches that don't touch fcntl. I couldn't reproduce it in 200+ reruns, so it looks pre-existing and unrelated.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)