UVM_MAP(9)
π UVM_MAP(9) π
okay so bestie, this is the Kernel Developer's Manual page for uvm_map, and it is literally the virtual address space management interface. UVM is the whole facility here, and this page is its little group chat for mapping, unmapping, protecting, and managing address spaces. π
πΈ NAME πΈ
uvm_map β virtual address space management interface
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <uvm/uvm.h>
int
uvm_map(struct vm_map *map, vaddr_t *startp, vsize_t size,
struct uvm_object *uobj, voff_t uoffset, vsize_t align,
uvm_flag_t flags);
void
uvm_unmap(struct vm_map *map, vaddr_t start, vaddr_t end);
int
uvm_map_pageable(struct vm_map *map, vaddr_t start, vaddr_t end,
bool new_pageable, int lockflags);
bool
uvm_map_checkprot(struct vm_map *map, vaddr_t start, vaddr_t end,
vm_prot_t protection);
int
uvm_map_protect(struct vm_map *map, vaddr_t start, vaddr_t end,
vm_prot_t new_prot, bool set_max);
int
uvm_map_protect_user(struct lwp *l, vaddr_t start, vaddr_t end,
vm_prot_t new_prot);
int
uvm_deallocate(struct vm_map *map, vaddr_t start, vsize_t size);
struct vmspace *
uvmspace_alloc(vaddr_t min, vaddr_t max);
void
uvmspace_exec(struct lwp *l, vaddr_t start, vaddr_t end);
struct vmspace *
uvmspace_fork(struct vmspace *vm);
void
uvmspace_free(struct vmspace *vm);
void
uvmspace_share(struct proc *p1, struct proc *p2);
vaddr_t
uvm_uarea_alloc(void);
void
uvm_uarea_free(vaddr_t uaddr);
vaddr_t
uvm_uarea_system_alloc(void);
void
uvm_uarea_system_free(vaddr_t uaddr);
π DESCRIPTION π
bestie, UVM is the facility for virtual address space management. That's the vibe: address-space admin, no cap. β¨
π«Ά FUNCTIONS π«Ά
okay so here's the function-by-function rundown, and yes, we are keeping every single detail because that's the whole point. π₯
π uvm_map()
uvm_map() establishes a valid mapping in the map map, which must be unlocked. The new mapping has size size, which must be a multiple of PAGE_SIZE. π
The uobj and uoffset arguments can have four meanings:
- When
uobjisNULLanduoffsetisUVM_UNKNOWN_OFFSET,uvm_map()does not use the machine-dependentPMAP_PREFERfunction. - When
uobjisNULLanduoffsetis any other value, it is used as the hint toPMAP_PREFER. - When
uobjis notNULLanduoffsetisUVM_UNKNOWN_OFFSET,uvm_map()finds the offset based upon the virtual address, passed asstartp. - When
uobjis notNULLanduoffsetis any other value, then a regular mapping is performed at this offset. The start address of the map will be returned instartp.
If uobj is supplied, then uvm_map() consumes the caller's reference to uobj on success; uvm_unmap() will release it when removing this mapping. On failure, uvm_map() leaves the reference count of uobj unmodified. fr fr, that reference-count detail matters. π«Ά
align specifies alignment of mapping unless UVM_FLAG_FIXED is specified in flags. align must be a power of 2.
flags passed to uvm_map() are typically created using the UVM_MAPFLAG(vm_prot_t prot, vm_prot_t maxprot, vm_inherit_t inh, int advice, int flags) macro, which uses the following values.
The values that prot and maxprot can take are:
UVM_PROT_NONEβ no protection bits.UVM_PROT_Rβ read.UVM_PROT_Wβ write.UVM_PROT_Xβ exec.UVM_PROT_MASKβ mask for extracting the protection bits.
Additionally, the following constants for ORed values are available: UVM_PROT_RW, UVM_PROT_RX, UVM_PROT_WX and UVM_PROT_RWX.
The values that inh can take are:
UVM_INH_SHAREβ share the map.UVM_INH_COPYβ copy the map.UVM_INH_NONEβ no inheritance.UVM_INH_MASKβ mask to extract inherit flags.
The values that advice can take are:
UVM_ADV_NORMALβ "Normal" use.UVM_ADV_RANDOMβ "Random" access likelihood.UVM_ADV_SEQUENTIALβ "Sequential" access likelihood.UVM_ADV_MASKβ mask to extract the advice flags.
The values that flags can take are:
UVM_FLAG_FIXEDβ attempt to map on the address specified bystartp. Otherwise, it is used just as a hint.UVM_FLAG_OVERLAYβ establish overlay.UVM_FLAG_NOMERGEβ do not merge map entries, if such merge is possible.UVM_FLAG_COPYONWβ use copy-on-write, i.e. do not fault in the pages immediately.UVM_FLAG_AMAPPADβ used for BSS: allocate larger amap, if extending is likely.UVM_FLAG_TRYLOCKβ fail if cannot acquire the lock immediately.UVM_FLAG_NOWAITβ not allowed to sleep. Fail, in such case.UVM_FLAG_QUANTUMβ indicates that map entry cannot be split once mapped.UVM_FLAG_WAITVAβ sleep until VA space is available, if it is not.UVM_FLAG_VAONLYβ unmap only VA space. Used byuvm_unmap().UVM_FLAG_UNMAPβ any existing entries in the range for this mapping should be unmapped as part of creating the new mapping.
β οΈ bestie, heads up: use ofUVM_FLAG_UNMAPwithout also specifyingUVM_FLAG_FIXEDis a bug. not a cute look π
The UVM_MAPFLAG macro arguments can be combined with an or operator. There are several special purpose macros for checking protection combinations, e.g., the UVM_PROT_WX. There are also some additional macros to extract bits from the flags. The UVM_PROTECTION, UVM_INHERIT, UVM_MAXPROTECTION and UVM_ADVICE macros return the protection, inheritance, maximum protection, and advice, respectively. uvm_map() returns zero on success or error number otherwise.
π§ uvm_unmap()
uvm_unmap() removes a valid mapping, from start to end, in the map map, which must be unlocked.
π¦ uvm_map_pageable()
uvm_map_pageable() changes the pageability of the pages in the range from start to end in the map map to new_pageable. uvm_map_pageable() returns zero on success or error number otherwise.
πΈ uvm_map_checkprot()
uvm_map_checkprot() checks the protection of the range from start to end in the map map against protection. This returns either true or false. β¨
π uvm_map_protect()
uvm_map_protect() changes the protection of the range from start to end in the map map to new_prot, also setting the maximum protection to the region to new_prot if set_max is true. This function returns a standard UVM return value.
π uvm_map_protect_user()
uvm_map_protect_user() verifies that the new permissions honor PAX restrictions if applicable and forwards to uvm_map_protect() on passing. slay, permission-checked π
π uvm_deallocate()
uvm_deallocate() deallocates kernel memory in the map map from address start to start + size.
π uvmspace_alloc()
uvmspace_alloc() allocates and returns a new address space, with ranges from min to max.
π uvmspace_exec()
uvmspace_exec() either reuses the address space of thread l (its process) if there are no other references to it, or creates a new one with uvmspace_alloc(). The range of valid addresses in the address space is reset to start through end.
π¦ uvmspace_fork()
uvmspace_fork() creates and returns a new address space based upon the vm address space, typically used when allocating an address space for a child process.
π uvmspace_free()
uvmspace_free() lowers the reference count on the address space vm, freeing the data structures if there are no other references.
π uvmspace_share()
uvmspace_share() causes process p2 to share the address space of p1.
π§ uvm_uarea_alloc()
uvm_uarea_alloc() allocates memory for a u-area (i.e. kernel stack, PCB, etc) and returns the address.
πΈ uvm_uarea_free()
uvm_uarea_free() frees a u-area allocated with uvm_uarea_alloc().
π uvm_uarea_system_alloc() and uvm_uarea_system_free()
uvm_uarea_system_alloc() and uvm_uarea_system_free() are optimized routines, which are used for kernel threads. main character energy for kernel threads only π
π₯ SEE ALSO π₯
go read these too, bestie, iykyk π«Ά
π HISTORY π
UVM and uvm_map first appeared in NetBSD 1.4.
This page's source/version is Debian, dated May 20, 2017, and the manual page is UVM_MAP(9) β okay bye bestie, hydrate and map safely ππ
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 1998 Matthew R. Green
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms