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
addrto the nearest preceding page boundary - and then rounding up
addr + lento 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]β theaddrandlenparameters 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
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1996 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms