VSLOCK(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

okay bestie, welcome to VSLOCK(9) β€” straight out of the Kernel Developer's Manual ✨ this one is short but it's literally about locking user space addresses in memory, so let's go πŸ’…

πŸŽ€ NAME πŸŽ€

vslock, vsunlock β€” lock/unlock user space addresses in memory πŸ’–

✨ SYNOPSIS ✨

first, grab the include squad 🫢:

#include <sys/param.h>
#include <sys/proc.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>

then the function signatures, exactly as they are:

int
vslock(void *addr, size_t len);

void
vsunlock(void *addr, size_t len);

πŸ¦‹ DESCRIPTION πŸ¦‹

so like, vslock() and vsunlock() are the lock/unlock duo. vslock() locks a range of addresses belonging to the currently running process into memory, and vsunlock() unlocks that range. no cap. πŸ”’

the actual amount of memory locked is a multiple of the machine's page size β€” that's the vibe. the starting page number is computed by truncating addr to the nearest preceding page boundary, and by rounding up addr + len to the next page boundary. boundaries are lowkey main character energy. 🫢

the process context to use for this operation is taken from the global variable curproc. that's the whole context situation, periodt. πŸ’«

πŸ’« RETURN VALUES πŸ’«

vslock() returns 0 on success. otherwise it returns one of the errors listed below. 😭

πŸ”₯ ERRORS πŸ”₯

vslock() will fail if:

  • [EINVAL] β€” the addr and len parameters specify a memory range that wraps around the end of the machine address space. πŸ’€
  • [ENOMEM] β€” the size of the specified address range exceeds the system limit on locked memory. 😭
  • [EFAULT] β€” some portion of the indicated address range is not allocated. there was an error faulting/mapping a page. 🫠

that's the whole page, bestie. this one came from Debian, dated August 29, 2012. now go forth and lock those addresses responsibly πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from