libkernel: flock on a directory descriptor aborts the process on Windows, where FreeBSD succeeds; fix branch ready #9100
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 xXPBSXx on 2026-10-21T12:16:18Z.
On Windows,
flock(fd, LOCK_SH)on a descriptor opened on a directory (open(path, O_DIRECTORY)) throwsstd::runtime_error(flock failed ... error=87) and the process aborts. FreeBSD 11.4'ssys_flockonly rejects descriptors that are not vnodes (EOPNOTSUPP) and an invalidhow(EBADF), soflockon a directory returns 0. A caller that locks a directory it opened, which some programs do for a lock directory, crashes instead of getting a lock.Cause.
flock_nid_postfixpasses every descriptor toGuestFileLock, which callsLockFileEx; Windows rejects a directory handle there withERROR_INVALID_PARAMETER(87), and the function turns any unexpected failure into aruntime_error.Observed on
main3e91c8edf5, Windows 10 (10.0.19045), WinLibs GCC 15.2.0 r7, Release (probe callingflock_nid_postfixon a directory descriptor, other calls from the same probe for comparison):flock(pipe, LOCK_SH)flock(file, 0)/flock(file, LOCK_NB)flock(file, LOCK_SH | LOCK_EX)flock(dir, LOCK_SH)runtime_error, error 87)I have not found a title that stops on this.
Fix.
xXPBSXx:fix/flock-directory-windows(0e2252f638, one commit onmain3e91c8edf5, four files, +23/-1). A directory descriptor returns 0 on Windows without taking a lock; the debt entry records that two descriptors of one directory never conflict (a secondLOCK_EX | LOCK_NBsucceeds where FreeBSD fails withEWOULDBLOCK). The newguest_file_lock_directorycase fails without the change (exit code 0xc0000409, 3 of 3) and passes with it (3 of 3); the otherguest_file_lock_*tests and the filesystem, fcntl, dup and append tests pass (13 of 13).AI-assisted (Claude Code).