VM_MAP_LOOKUP(9)

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

πŸ’… VM_MAP_LOOKUP(9) πŸ’…

okay bestie, welcome to the Kernel Developer's Manual page for vm_map_lookup and vm_map_lookup_done β€” the little duo that helps you look up the vm_object backing a given virtual region. it’s giving kernel-internals main character energy, and we’re gonna get through it together 🫢✨


πŸŽ€ NAME πŸŽ€

vm_map_lookup, vm_map_lookup_done β€” lookup the vm_object backing a given virtual region πŸ’–


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_map.h>

int
vm_map_lookup(vm_map_t *var_map, vm_offset_t vaddr,
    vm_prot_t fault_type, vm_map_entry_t *out_entry,
    vm_object_t *object, vm_pindex_t *pindex, vm_prot_t *out_prot,
    boolean_t *wired);

void
vm_map_lookup_done(vm_map_t map, vm_map_entry_t entry);

no cap, those includes and signatures are literally copy-pasted from the source of truth, so keep them exactly like that πŸ”₯


🌸 DESCRIPTION 🌸

so vm_map_lookup() is the function that attempts to find the vm_object, page index and protection for the given virtual address vaddr, in the map var_map β€” assuming a page fault of the type fault_type had occurred. it’s basically doing the β€œwhat’s behind this virtual address?” detective work πŸ”πŸ’…

and this part is important, bestie: the return values are guaranteed until vm_map_lookup_done() is called to release the lock. so don’t go acting brand new and forget the cleanup, okay? 😭✨


πŸ¦‹ IMPLEMENTATION NOTES πŸ¦‹

not me spilling the lock tea: vm_map_lookup() acquires a read-lock on the map *var_map, but it does not release it. the caller should invoke vm_map_lookup_done() in order to release this lock. that’s the whole vibe β€” lookup first, then done to release the lock, periodt πŸ«ΆπŸ”


πŸ’œ RETURN VALUES πŸ’œ

the vm_map_lookup() function returns KERN_SUCCESS, and sets the *object, *pindex, *out_prot, and *out_entry arguments appropriately for the hypothetical page fault. slay, that’s the success path βœ¨πŸ‘‘


🌈 SEE ALSO 🌈

go read that one too, iykyk πŸ“šπŸ’–


πŸŽ€ AUTHORS πŸŽ€

this manual page was written by Bruce M Simpson <bms@spc.org>. iconic behavior, honestly πŸ’…βœ¨


this cutie comes from the Debian manual pages, dated July 19, 2003 β€” mwah, xoxo πŸ’‹πŸŽ€

πŸ“¦ where this page comes from