VSLOCK(9)

πŸ’– VSLOCK(9) β€” lock/unlock user space addresses in memory πŸ’–

ok so bestie, welcome to VSLOCK(9), straight out of the Kernel Developer's Manual. this is the one where we pin a chunk of your own process's memory down so it does not go anywhere. very main character energy, no cap. 🫢


✨ NAME ✨

vslock, vsunlock β€” lock/unlock user space addresses in memory


πŸŽ€ SYNOPSIS πŸŽ€

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

int
vslock(void *addr, size_t len);

void
vsunlock(void *addr, size_t len);

🌸 DESCRIPTION 🌸

okay so here's the tea. vslock() and vsunlock() are literally the lock-and-unlock duo for a range of addresses that belong to the currently running process. vslock() pins them into memory, vsunlock() lets them go. it's giving "you're staying right here" and then "okay you can leave now." πŸ’…

and the amount of memory actually locked? it's a multiple of the machine's page size. not exactly what you asked for β€” more like what the page boundaries decided for you. πŸ™ˆ

here's how the range gets computed, fr fr:

  • the starting page number is worked out by truncating addr to the nearest preceding page boundary
  • and then rounding up addr + len to the next page boundary

so it always snaps outward to whole pages. cute and predictable. ✨

also, the process context used for this whole operation comes from the global variable curproc. that's the one it's doing all this for. πŸ‘‘


⭐ RETURN VALUES ⭐

vslock() comes back with 0 when it slays β€” that's success bestie. otherwise it hands you 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. like, it literally loops back around. not it. 😡
  • [ENOMEM] β€” the size of the specified address range exceeds the system limit on locked memory. you asked for too much, babe.
  • [EFAULT] β€” some portion of the indicated address range is not allocated. there was an error faulting/mapping a page. πŸ’€
bestie reminder: [EFAULT] means part of the range you pointed at isn't actually there β€” the fault/map on a page went wrong. don't skip this one. 🫢

and that's the whole vibe check, queen. this page came to you from Debian, dated August 29, 2012, under the VSLOCK(9) banner. go lock some pages responsibly. mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from