xref: /openbsd-src/share/man/man9/uvm_map.9 (revision 1b7151727215288417e1805f320461d0d9d7ecd0)
1*1b715172Sjmc.\"	$OpenBSD: uvm_map.9,v 1.3 2022/12/09 21:19:53 jmc Exp $
28f128fcdSmpi.\"	$NetBSD: uvm.9,v 1.14 2000/06/29 06:08:44 mrg Exp $
38f128fcdSmpi.\"
48f128fcdSmpi.\" Copyright (c) 1998 Matthew R. Green
58f128fcdSmpi.\" All rights reserved.
68f128fcdSmpi.\"
78f128fcdSmpi.\" Redistribution and use in source and binary forms, with or without
88f128fcdSmpi.\" modification, are permitted provided that the following conditions
98f128fcdSmpi.\" are met:
108f128fcdSmpi.\" 1. Redistributions of source code must retain the above copyright
118f128fcdSmpi.\"    notice, this list of conditions and the following disclaimer.
128f128fcdSmpi.\" 2. Redistributions in binary form must reproduce the above copyright
138f128fcdSmpi.\"    notice, this list of conditions and the following disclaimer in the
148f128fcdSmpi.\"    documentation and/or other materials provided with the distribution.
158f128fcdSmpi.\"
168f128fcdSmpi.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
178f128fcdSmpi.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
188f128fcdSmpi.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
198f128fcdSmpi.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
208f128fcdSmpi.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
218f128fcdSmpi.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
228f128fcdSmpi.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
238f128fcdSmpi.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
248f128fcdSmpi.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
258f128fcdSmpi.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
268f128fcdSmpi.\" SUCH DAMAGE.
278f128fcdSmpi.\"
28123a6750Sderaadt.Dd $Mdocdate: December 9 2022 $
298f128fcdSmpi.Dt UVM_MAP 9
308f128fcdSmpi.Os
318f128fcdSmpi.Sh NAME
328f128fcdSmpi.Nm uvm_map ,
338f128fcdSmpi.Nm uvm_map_pageable ,
348f128fcdSmpi.Nm uvm_map_pageable_all ,
358f128fcdSmpi.Nm uvm_map_checkprot ,
368f128fcdSmpi.Nm uvm_map_protect ,
378f128fcdSmpi.Nm uvmspace_alloc ,
388f128fcdSmpi.Nm uvmspace_exec ,
398f128fcdSmpi.Nm uvmspace_fork ,
408f128fcdSmpi.Nm uvmspace_free ,
418f128fcdSmpi.Nm uvmspace_share ,
428f128fcdSmpi.Nm uvm_uarea_alloc ,
438f128fcdSmpi.Nm uvm_uarea_free ,
448f128fcdSmpi.Nm UVM_MAPFLAG
458f128fcdSmpi.Nd virtual address space management interface
468f128fcdSmpi.Sh SYNOPSIS
478f128fcdSmpi.In sys/param.h
488f128fcdSmpi.In uvm/uvm.h
498f128fcdSmpi.Ft int
508f128fcdSmpi.Fn uvm_map "vm_map_t map" "vaddr_t *startp" "vsize_t size" "struct uvm_object *uobj" "voff_t uoffset" "vsize_t alignment" "unsigned int flags"
518f128fcdSmpi.Ft int
528f128fcdSmpi.Fn uvm_map_pageable "vm_map_t map" "vaddr_t start" "vaddr_t end" "boolean_t new_pageable" "int lockflags"
538f128fcdSmpi.Ft int
548f128fcdSmpi.Fn uvm_map_pageable_all "vm_map_t map" "int flags" "vsize_t limit"
558f128fcdSmpi.Ft boolean_t
568f128fcdSmpi.Fn uvm_map_checkprot "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t protection"
578f128fcdSmpi.Ft int
58123a6750Sderaadt.Fn uvm_map_protect "vm_map_t map" "vaddr_t start" "vaddr_t end" "vm_prot_t new_prot" "int et" "boolean_t set_max" "boolean_t checkimmutable"
598f128fcdSmpi.Ft struct vmspace *
608f128fcdSmpi.Fn uvmspace_alloc "vaddr_t min" "vaddr_t max" "boolean_t pageable" "boolean_t remove_holes"
618f128fcdSmpi.Ft void
628f128fcdSmpi.Fn uvmspace_exec "struct proc *p" "vaddr_t start" "vaddr_t end"
638f128fcdSmpi.Ft struct vmspace *
648f128fcdSmpi.Fn uvmspace_fork "struct process *pr"
658f128fcdSmpi.Ft void
668f128fcdSmpi.Fn uvmspace_free "struct vmspace *vm"
678f128fcdSmpi.Ft struct vmspace *
688f128fcdSmpi.Fn uvmspace_share "struct process *pr"
698f128fcdSmpi.Ft vaddr_t
708f128fcdSmpi.Fn uvm_uarea_alloc "void"
718f128fcdSmpi.Ft void
728f128fcdSmpi.Fn uvm_uarea_free "struct proc *p"
738f128fcdSmpi.Ft unsigned int
748f128fcdSmpi.Fn UVM_MAPFLAG "vm_prot_t prot" "vm_prot_t maxprot" "vm_inherit_t inh" "int advice" "int flags"
758f128fcdSmpi.Sh DESCRIPTION
768f128fcdSmpiThe
778f128fcdSmpi.Fn uvm_map
788f128fcdSmpifunction establishes a valid mapping in map
798f128fcdSmpi.Fa map ,
808f128fcdSmpiwhich must be unlocked.
818f128fcdSmpiThe new mapping has size
828f128fcdSmpi.Fa size ,
838f128fcdSmpiwhich must be in
848f128fcdSmpi.Dv PAGE_SIZE
858f128fcdSmpiunits.
868f128fcdSmpiIf
878f128fcdSmpi.Fa alignment
888f128fcdSmpiis non-zero, it describes the required alignment of the list, in
898f128fcdSmpipower-of-two notation.
908f128fcdSmpiThe
918f128fcdSmpi.Fa uobj
928f128fcdSmpiand
938f128fcdSmpi.Fa uoffset
948f128fcdSmpiarguments can have four meanings.
958f128fcdSmpiWhen
968f128fcdSmpi.Fa uobj
978f128fcdSmpiis
988f128fcdSmpi.Dv NULL
998f128fcdSmpiand
1008f128fcdSmpi.Fa uoffset
1018f128fcdSmpiis
1028f128fcdSmpi.Dv UVM_UNKNOWN_OFFSET ,
1038f128fcdSmpi.Fn uvm_map
1048f128fcdSmpidoes not use the machine-dependent
1058f128fcdSmpi.Dv PMAP_PREFER
1068f128fcdSmpifunction.
1078f128fcdSmpiIf
1088f128fcdSmpi.Fa uoffset
1098f128fcdSmpiis any other value, it is used as the hint to
1108f128fcdSmpi.Dv PMAP_PREFER .
1118f128fcdSmpiWhen
1128f128fcdSmpi.Fa uobj
1138f128fcdSmpiis not
1148f128fcdSmpi.Dv NULL
1158f128fcdSmpiand
1168f128fcdSmpi.Fa uoffset
1178f128fcdSmpiis
1188f128fcdSmpi.Dv UVM_UNKNOWN_OFFSET ,
1198f128fcdSmpi.Fn uvm_map
1208f128fcdSmpifinds the offset based upon the virtual address, passed as
1218f128fcdSmpi.Fa startp .
1228f128fcdSmpiIf
1238f128fcdSmpi.Fa uoffset
1248f128fcdSmpiis any other value, we are doing a normal mapping at this offset.
1258f128fcdSmpiThe start address of the map will be returned in
1268f128fcdSmpi.Fa startp .
1278f128fcdSmpi.Pp
1288f128fcdSmpi.Fa flags
1298f128fcdSmpipassed to
1308f128fcdSmpi.Fn uvm_map
1318f128fcdSmpiare typically created using the
1328f128fcdSmpi.Fn UVM_MAPFLAG
1338f128fcdSmpimacro, which uses the following values.
1348f128fcdSmpiThe
1358f128fcdSmpi.Fa prot
1368f128fcdSmpiand
1378f128fcdSmpi.Fa maxprot
1388f128fcdSmpican take a mix of the following values:
1398f128fcdSmpi.Bd -literal
1408f128fcdSmpi#define PROT_MASK   0x07    /* protection mask */
1418f128fcdSmpi#define PROT_NONE   0x00    /* protection none */
1428f128fcdSmpi#define PROT_READ   0x01    /* read */
1438f128fcdSmpi#define PROT_WRITE  0x02    /* write */
1448f128fcdSmpi#define PROT_EXEC   0x04    /* exec */
1458f128fcdSmpi.Ed
1468f128fcdSmpi.Pp
1478f128fcdSmpiThe values that
1488f128fcdSmpi.Fa inh
1498f128fcdSmpican take are:
1508f128fcdSmpi.Bd -literal
1518f128fcdSmpi#define MAP_INHERIT_MASK    0x30    /* inherit mask */
1528f128fcdSmpi#define MAP_INHERIT_SHARE   0x00    /* "share" */
1538f128fcdSmpi#define MAP_INHERIT_COPY    0x10    /* "copy" */
1548f128fcdSmpi#define MAP_INHERIT_NONE    0x20    /* "none" */
1558f128fcdSmpi#define MAP_INHERIT_ZERO    0x30    /* "zero" */
1568f128fcdSmpi.Ed
1578f128fcdSmpi.Pp
1588f128fcdSmpiThe values that
1598f128fcdSmpi.Fa advice
1608f128fcdSmpican take are:
1618f128fcdSmpi.Bd -literal
1628f128fcdSmpi#define MADV_NORMAL  0x0     /* 'normal' */
1638f128fcdSmpi#define MADV_RANDOM  0x1     /* 'random' */
1648f128fcdSmpi#define MADV_SEQUENTIAL 0x2  /* 'sequential' */
1658f128fcdSmpi#define MADV_MASK    0x7     /* mask */
1668f128fcdSmpi.Ed
1678f128fcdSmpi.Pp
1688f128fcdSmpiThe values that
1698f128fcdSmpi.Fa flags
1708f128fcdSmpican take are:
1718f128fcdSmpi.Bd -literal
1728f128fcdSmpi#define UVM_FLAG_FIXED   0x0010000 /* find space */
1738f128fcdSmpi#define UVM_FLAG_OVERLAY 0x0020000 /* establish overlay */
1748f128fcdSmpi#define UVM_FLAG_NOMERGE 0x0040000 /* don't merge map entries */
1758f128fcdSmpi#define UVM_FLAG_COPYONW 0x0080000 /* set copy_on_write flag */
1768f128fcdSmpi#define UVM_FLAG_TRYLOCK 0x0100000 /* fail if we can not lock map */
1778f128fcdSmpi#define UVM_FLAG_HOLE    0x0200000 /* no backend */
1788f128fcdSmpi#define UVM_FLAG_QUERY   0x0400000 /* do everything,
1798f128fcdSmpi                                      except actual execution */
1808f128fcdSmpi#define UVM_FLAG_NOFAULT 0x0800000 /* don't fault */
1818f128fcdSmpi#define UVM_FLAG_UNMAP   0x1000000 /* unmap to make space */
1828f128fcdSmpi#define UVM_FLAG_STACK   0x2000000 /* page may contain a stack */
1838f128fcdSmpi.Ed
1848f128fcdSmpi.Pp
1858f128fcdSmpiThe
1868f128fcdSmpi.Dv UVM_MAPFLAG
1878f128fcdSmpimacro arguments can be combined with an or operator.
1888f128fcdSmpiThere are also some additional macros to extract bits from the flags.
1898f128fcdSmpiThe
1908f128fcdSmpi.Dv UVM_PROTECTION ,
1918f128fcdSmpi.Dv UVM_INHERIT ,
1928f128fcdSmpi.Dv UVM_MAXPROTECTION
1938f128fcdSmpiand
1948f128fcdSmpi.Dv UVM_ADVICE
1958f128fcdSmpimacros return the protection, inheritance, maximum protection and advice,
1968f128fcdSmpirespectively.
1978f128fcdSmpi.Fn uvm_map
1988f128fcdSmpireturns a standard errno.
1998f128fcdSmpi.Pp
2008f128fcdSmpiThe
2018f128fcdSmpi.Fn uvm_map_pageable
2028f128fcdSmpifunction changes the pageability of the pages in the range from
2038f128fcdSmpi.Fa start
2048f128fcdSmpito
2058f128fcdSmpi.Fa end
2068f128fcdSmpiin map
2078f128fcdSmpi.Fa map
2088f128fcdSmpito
2098f128fcdSmpi.Fa new_pageable .
2108f128fcdSmpiThe
2118f128fcdSmpi.Fn uvm_map_pageable_all
2128f128fcdSmpifunction changes the pageability of all mapped regions.
2138f128fcdSmpiIf
2148f128fcdSmpi.Fa limit
2158f128fcdSmpiis non-zero and
2168f128fcdSmpi.Fn pmap_wired_count
2178f128fcdSmpiis implemented,
2188f128fcdSmpi.Dv ENOMEM
2198f128fcdSmpiis returned if the amount of wired pages exceed
2208f128fcdSmpi.Fa limit .
2218f128fcdSmpiThe map is locked on entry if
2228f128fcdSmpi.Fa lockflags
2238f128fcdSmpicontain
2248f128fcdSmpi.Dv UVM_LK_ENTER ,
2258f128fcdSmpiand locked on exit if
2268f128fcdSmpi.Fa lockflags
2278f128fcdSmpicontain
2288f128fcdSmpi.Dv UVM_LK_EXIT .
2298f128fcdSmpi.Fn uvm_map_pageable
2308f128fcdSmpiand
2318f128fcdSmpi.Fn uvm_map_pageable_all
2328f128fcdSmpireturn a standard errno.
2338f128fcdSmpi.Pp
2348f128fcdSmpiThe
2358f128fcdSmpi.Fn uvm_map_checkprot
2368f128fcdSmpifunction checks the protection of the range from
2378f128fcdSmpi.Fa start
2388f128fcdSmpito
2398f128fcdSmpi.Fa end
2408f128fcdSmpiin map
2418f128fcdSmpi.Fa map
2428f128fcdSmpiagainst
2438f128fcdSmpi.Fa protection .
2448f128fcdSmpiThis returns either
2458f128fcdSmpi.Dv TRUE
2468f128fcdSmpior
2478f128fcdSmpi.Dv FALSE .
2488f128fcdSmpi.Pp
2498f128fcdSmpiThe
2508f128fcdSmpi.Fn uvm_map_protect
2518f128fcdSmpifunction changes the protection
2528f128fcdSmpi.Fa start
2538f128fcdSmpito
2548f128fcdSmpi.Fa end
2558f128fcdSmpiin map
2568f128fcdSmpi.Fa map
2578f128fcdSmpito
2588f128fcdSmpi.Fa new_prot ,
2598f128fcdSmpialso setting the maximum protection to the region to
2608f128fcdSmpi.Fa new_prot
2618f128fcdSmpiif
2628f128fcdSmpi.Fa set_max
2638f128fcdSmpiis non-zero.
264123a6750SderaadtThe
265123a6750Sderaadt.Fa et
266123a6750Sderaadtparameter should be 0, unless a
267*1b715172Sjmc.Dv PROT_READ | PROT_WRITE
268*1b715172Sjmcmapping is being changed to extend the stack limit, then it may be
269*1b715172Sjmc.Dv UVM_ET_STACK .
2708f128fcdSmpiThis function returns a standard errno.
2718f128fcdSmpi.Pp
2728f128fcdSmpiThe
2738f128fcdSmpi.Fn uvmspace_alloc
2748f128fcdSmpifunction allocates and returns a new address space, with ranges from
2758f128fcdSmpi.Fa min
2768f128fcdSmpito
2778f128fcdSmpi.Fa max ,
2788f128fcdSmpisetting the pageability of the address space to
2798f128fcdSmpi.Fa pageable .
2808f128fcdSmpiIf
2818f128fcdSmpi.Fa remove_holes
2828f128fcdSmpiis non-zero, hardware
2838f128fcdSmpi.Sq holes
2848f128fcdSmpiin the virtual address space will be removed from the newly allocated
2858f128fcdSmpiaddress space.
2868f128fcdSmpi.Pp
2878f128fcdSmpiThe
2888f128fcdSmpi.Fn uvmspace_exec
2898f128fcdSmpifunction either reuses the address space of process
2908f128fcdSmpi.Fa p
2918f128fcdSmpiif there are no other references to it, or creates
2928f128fcdSmpia new one with
2938f128fcdSmpi.Fn uvmspace_alloc .
2948f128fcdSmpiThe range of valid addresses in the address space is reset to
2958f128fcdSmpi.Fa start
2968f128fcdSmpithrough
2978f128fcdSmpi.Fa end .
2988f128fcdSmpi.Pp
2998f128fcdSmpiThe
3008f128fcdSmpi.Fn uvmspace_fork
3018f128fcdSmpifunction creates and returns a new address space based upon the
3028f128fcdSmpiaddress space of process
3038f128fcdSmpi.Fa pr
3048f128fcdSmpiand is typically used when allocating an address space for a
3058f128fcdSmpichild process.
3068f128fcdSmpi.Pp
3078f128fcdSmpiThe
3088f128fcdSmpi.Fn uvmspace_free
3098f128fcdSmpifunction lowers the reference count on the address space
3108f128fcdSmpi.Fa vm ,
3118f128fcdSmpifreeing the data structures if there are no other references.
3128f128fcdSmpi.Pp
3138f128fcdSmpiThe
3148f128fcdSmpi.Fn uvmspace_share
3158f128fcdSmpifunction returns a reference to the address space of process
3168f128fcdSmpi.Fa pr ,
3178f128fcdSmpiincreasing its reference count.
3188f128fcdSmpi.Pp
3198f128fcdSmpiThe
3208f128fcdSmpi.Fn uvm_uarea_alloc
3218f128fcdSmpifunction allocates a thread's
3228f128fcdSmpi.Sq uarea ,
3238f128fcdSmpithe memory where its kernel stack and PCB are stored.
3248f128fcdSmpiThe
3258f128fcdSmpi.Fn uvm_uarea_free
3268f128fcdSmpifunction frees the uarea for
3278f128fcdSmpithread
3288f128fcdSmpi.Fa p ,
3298f128fcdSmpiwhich must no longer be running.
3308f128fcdSmpi.Sh SEE ALSO
3318f128fcdSmpi.Xr pmap 9
332