Skip to content

fix(libkernel): answer F_GETLK with F_UNLCK on Linux and macOS - #7073

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
AlexOfTheForest:fix/getlk-unlock
Oct 17, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
AlexOfTheForest:fix/getlk-unlock

Conversation

@AlexOfTheForest

Copy link
Copy Markdown
Contributor

What

On Linux and macOS, fcntl(F_GETLK) with l_type = F_UNLCK hit NotImplemented_nid_no_patch. Only the Windows path handled it. FreeBSD 11.4 accepts the request: in lf_getlock/lf_blocks, an F_UNLCK request conflicts only with another owner's overlapping write lock, exactly like an F_RDLCK request. The host query is now made with F_RDLCK for F_GETLK, so the reply matches FreeBSD. F_SETLK/F_SETLKW with F_UNLCK still map to the host's F_UNLCK.

Two commits:

  • fix(libkernel): answer F_GETLK with F_UNLCK on Linux and macOS: the mapping change in DescriptorControl.cpp. The existing fcntl test's unlock query moves out of its #ifdef _WIN32 block and now also covers a reader descriptor and a SEEK_CUR range. 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 that F_UNLCK and F_RDLCK report only the write locks and F_WRLCK reports the read lock, each with the owner's pid and SEEK_SET. It also checks that F_SETLK over the read lock fails with EAGAIN and that nothing is reported after the owner exits. UNIX-only, because it uses fork.

Tested

Linux x86_64: guest_kernel_fcntl and the new guest_record_lock_owners both passed 5 of 5 runs. With the fix reverted, guest_record_lock_owners aborts with "not implemented" and leaves no stray child process. tools/check_conventions.py --base upstream/main passes. The progress report is unchanged against the merge-base. Not run on Windows (that path already handled F_UNLCK and its code is unchanged) or macOS. Note: guest_kernel_fcntl has 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

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.
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
core/libs/tests/GuestKernelFcntl.cpp
PR 6222 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6287 core/libs/prx/libkernel/CMakeLists.txt
PR 6510 docs/dev/debt/libkernel.md
PR 6710 docs/dev/debt/libkernel.md
PR 6962 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt

@oneandonlydean
oneandonlydean merged commit ee14990 into boykopovar:main Oct 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants