vm_map_protect(9)

vm_map_protect9

Apply protection bits to a virtual memory region

Usage

#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);

Overview

The vm_map_protect() function sets the protection bits and maximum protection bits of the address region bounded by start and end within the map map.

If the flags argument has the VM_MAP_PROTECT_SET_PROT bit set, then the effective protection is set to new_prot.

If the flags argument has the VM_MAP_PROTECT_SET_MAXPROT bit set, then the maximum protection is set to new_maxprot. Protection bits not included into new_maxprot will be cleared from existing entries.

The values specified by new_prot and new_maxprot are not allowed to include any protection bits that are not set in existing max_protection on every entry within the range. The operation will fail if this condition is violated. For instance, this prevents upgrading a shared mapping of a read-only file from read-only to read-write.

The specified range must not contain sub-maps.

Implementation notes

The function acquires a lock on the map for the duration, by calling vm_map_lock(9). Also, any in-progress wiring operation on the map affecting the specified range will cause vm_map_protect to sleep, waiting for completion.

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 exceed max_protection for an entry within the range.

KERN_PROTECTION_FAILURE

The map does not allow simultaneous setting of write and execute permissions, but new_prot has both VM_PROT_WRITE and VM_PROT_EXECUTE set.

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.

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.

Releases

54 releases since FreeBSD 5.2-RELEASE; the text changed 36 times.

  1. 5.2–5.2.1
  2. 5.3–5.5
  3. 6.0–6.3
  4. 6.4
  5. 7.0
  6. 7.1
  7. 7.2
  8. 7.3
  9. 7.4
  10. 8.0
  11. 8.1
  12. 8.2
  13. 8.3
  14. 8.4
  15. 9.0
  16. 9.1
  17. 9.2
  18. 9.3
  19. 10.0
  20. 10.1
  21. 10.2
  22. 10.3
  23. 10.4
  24. 11.0
  25. 11.1
  26. 11.2
  27. 11.3
  28. 11.4
  29. 12.0
  30. 12.1
  31. 12.2
  32. 12.3
  33. 12.4
  34. 13.0–13.2
  35. 13.3–13.5
  36. 14.0–14.2
  37. 14.3–16.0

Authors

This manual page was written by Bruce M Simpson ⟨[email protected]⟩.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.