Anonymous objects are used for the uninitialized data memory and for the stack. No file descriptors are associated with these objects, and so it is impossible to use fcntl to lock byte ranges here. To enable memory locking using system calls, processes have to create an empty temporary file (or /dev/zero) and mmap it into memory.
The user-visible behavior difference occurs only when the user program sets an alarm(2) without setting a signal handler. The sleep code will ``eat'' the signal rather than re-deliver the signal. (See comment in CVS log for sleep.c.)
File locking code is in the kernel, in src/sys/kern/kern_lockf.c. The locks are kept on a linked list kept on the filesystem-specific node structure (src/sys/ufs/ufs/inode.h, src/sys/isofs/cd9660/cd9660_node.h, src/sys/nfs/nsfnode.h), and operated on via the vnode routines advlock (src/sys/ufs/ufs/ufs_vnops.c, src/sys/nfs/nfs_vnops.c, src/sys/miscfs/union/union_vnops.c, src/sys/miscfs/specfs/spec_vnops.c, src/sys/miscfs/fifofs/fifo_vnops.c) which typically use src/sys/kern/kern_descrip.c internally. The lockf structure is a linked list because the total number of byte range locks on a file -- even for all files in the whole system -- should be small, and so there's no need for a fancier data structure.
The fcntl syscall into the kernel is handled thus: kern_descrip.c's fcntl syscall handler checks the arguments, then passes to the vnode routine via VOP_ADVLOCK. The vnode interface calls, for example, ufs_advlock in ufs_vnops.c, which in turn calls lf_advlock from kern_lockf.c to actually do the byte-range locking.
There are also a global linked list for kernel locks used in the kernel -- this is src/sys/kern/kern_lock.c, which implements shared locks for kernel code used esp for multiprocessors (this is code inherited from Mach). The idea is you can get a shared lock on an object for read access, and an exclusive lock for write access. This is used at various places, e.g. for the vnode locks (VOP_LOCK) which is used in the kernel to control access to the vnode by the various kernel threads; see, for example, src/sys/kern/vfs_default.c's vop_nolock routine. (You should look at simple_lock and compare these with the struck lock objects implemented in kern_lock.c.
bsy+cse121.f00@cs.ucsd.edu, last updated
email bsy.