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 of new_prot would exceed max_protection for 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