VM_MAP_PROTECT(9)
π VM_MAP_PROTECT(9) π
okay so bestie, welcome to the Kernel Developer's Manual corner of the internet β this is the page for vm_map_protect, and honestly? it's giving gatekeeper-of-memory-permissions and we're obsessed π
β¨ NAME β¨
vm_map_protect β apply protection bits to a virtual memory region π‘οΈ
πΈ 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, vm_prot_t new_maxprot, int flags);
π DESCRIPTION π
so the vm_map_protect() function sets the protection bits and the maximum protection bits of the address region bounded by start and end within the map map. that's the whole vibe. it's like a glow-up but for permissions π
if the flags argument has the VM_MAP_PROTECT_SET_PROT bit set, then the effective protection gets set to new_prot. slay.
if the flags argument has the VM_MAP_PROTECT_SET_MAXPROT bit set, then the maximum protection gets set to new_maxprot. and heads up: protection bits not included in new_maxprot will be cleared from existing entries. it's not a maybe-clearing, it's a definitely-clearing π
the values specified by new_prot and new_maxprot are not allowed to include any protection bits that aren't set in the existing max_protection on every entry within the range. like, every single entry. the operation will fail if this condition is violated. the classic example: this is what prevents upgrading a shared mapping of a read-only file from read-only to read-write. read-only means read-only, no cap π«
and the specified range must not contain sub-maps. none. zero. don't even try it π
π§ IMPLEMENTATION NOTES π§
the function acquires a lock on the map for the duration, by calling vm_map_lock(9). locking her down, as she should be π
also, any in-progress wiring operation on the map that affects the specified range will cause vm_map_protect to sleep, waiting for completion. not a nap, just a little resty until the wiring situation resolves itself π΄
π RETURN VALUES π
KERN_SUCCESSβ the specified protection bits were set successfully β¨KERN_INVALID_ARGUMENTβ a sub-map entry was encountered in the range,KERN_PROTECTION_FAILUREβ the value of new_prot or new_maxprot exceedmax_protectionfor an entry within the range.KERN_PROTECTION_FAILUREβ the map does not allow simultaneous setting of write and execute permissions, but new_prot has bothVM_PROT_WRITEandVM_PROT_EXECUTEset.KERN_RESOURCE_SHORTAGEβ a copy-on-write mapping is transitioned from read-only to read-write, and not enough swap space is available to back the copied pages. oof, out of room πKERN_OUT_OF_BOUNDSβ both new protection and new maximum protection updates were requested, but the specified new_prot is not a subset of new_maxprot. bestie those don't nest, pick better π«Ά
π SEE ALSO π
β AUTHORS β
this manual page was written by Bruce M Simpson <bms@spc.org> β king behavior, we thank him for his service π
so yeah, that's the whole page π this one came to you from Debian, dated January 23, 2021, filed under VM_MAP_PROTECT(9) β that's a wrap, bestie, go protect some memory responsibly π¦π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2003 Bruce M Simpson <bms@spc.org>
- Copyright (c) 2021 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms