VM_MAP_PROTECT(9)
π VM_MAP_PROTECT π
okay so bestie, welcome to vm_map_protect from section 9 of the Kernel Developer's Manual β it's giving kernel internals, it's giving virtual memory, and honestly? we're obsessed π«Ά
β¨ NAME β¨
vm_map_protect β apply protection bits to a virtual memory region
like, it goes in and changes the permissions on a chunk of memory, no big deal π
πΈ SYNOPSIS πΈ
#include <sys/param.h>
#include <vm/vm.h>
#include <vm/vm_map.h>
int
vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end,
vm_prot_t new_prot, boolean_t set_max);
okay so you pull in those three headers β <sys/param.h>, <vm/vm.h>, and <vm/vm_map.h> β and then you call it with a map, a start, an end, a new protection value, and a boolean that decides how spicy you're feeling π₯
π¦ DESCRIPTION π¦
So vm_map_protect() sets the protection bits of the address region bounded by start and end inside the map map, and it sets them to new_prot. Periodt.
But here's the tea β β the value you pass as new_prot may not include any protection bits that aren't already set in max_protection on every single entry within that range. Every. Single. One. No sneaking extra perms past the max, bestie, that's not the vibe π
If set_max is TRUE, then new_prot gets treated as the brand new max_protection setting for each underlying entry. And any protection bits not included in new_prot will get cleared from existing entries. So it's not just a glow-up, it's a full reset of what's allowed. π
If set_max is FALSE, only the protection field is affected β the max stays exactly where it was. Chill. Lowkey. π§
The range MUST be contiguous, and it MUST NOT contain sub-maps. This is not a suggestion, this is the law, and the function will be very dramatic about it if you try.
π IMPLEMENTATION NOTES π
The function acquires a lock on the map for the duration, by calling vm_map_lock(9). So the whole operation is locked down, main character energy, nobody else is touching that map while this is happening π
β RETURN VALUES β
KERN_SUCCESSβ returned if the protection bits could be set successfully. slay β¨KERN_INVALID_ARGUMENTβ returned if a sub-map entry was encountered in the range. you were told. πKERN_PROTECTION_FAILUREβ returned if the value ofnew_protwould exceedmax_protectionfor an entry within the range. the ceiling said no. π«
π SEE ALSO π
π AUTHORS π
This manual page was written by Bruce M Simpson <bms@spc.org>. king behavior, fr fr π
and that's the whole page, bestie π this one's from the Debian crew and it's dated June 20, 2019 β so yeah, it's a classic, and now you know it, and honestly? iykyk π¦
π¦ 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) 2003 Bruce M Simpson <bms@spc.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms