xref: /xnu-8796.141.3/osfmk/man/vm_map.html (revision 1b191cb58250d0705d8a51287127505aa4bc0789)
1*1b191cb5SApple OSS Distributions<h2>vm_map</h2>
2*1b191cb5SApple OSS Distributions<hr>
3*1b191cb5SApple OSS Distributions<p>
4*1b191cb5SApple OSS Distributions<strong>Function</strong> - Map the specified memory object to a region of virtual memory.
5*1b191cb5SApple OSS Distributions<h3>SYNOPSIS</h3>
6*1b191cb5SApple OSS Distributions<pre>
7*1b191cb5SApple OSS Distributions<strong>kern_return_t   vm_map</strong>
8*1b191cb5SApple OSS Distributions                <strong>(vm_task_t</strong>                          <var>target_task</var>,
9*1b191cb5SApple OSS Distributions                 <strong>vm_address_t</strong>                           <var>address</var>,
10*1b191cb5SApple OSS Distributions                 <strong>vm_size_t</strong>                                 <var>size</var>,
11*1b191cb5SApple OSS Distributions                 <strong>vm_address_t</strong>                              <var>mask</var>,
12*1b191cb5SApple OSS Distributions                 <strong>boolean_t</strong>                             <var>anywhere</var>,
13*1b191cb5SApple OSS Distributions                 <strong>memory_object_t</strong>                  <var>memory_object</var>,
14*1b191cb5SApple OSS Distributions                 <strong>vm_offset_t</strong>                             <var>offset</var>,
15*1b191cb5SApple OSS Distributions                 <strong>boolean_t</strong>                                 <var>copy</var>,
16*1b191cb5SApple OSS Distributions                 <strong>vm_prot_t</strong>                       <var>cur_protection</var>,
17*1b191cb5SApple OSS Distributions                 <strong>vm_prot_t</strong>                       <var>max_protection</var>,
18*1b191cb5SApple OSS Distributions                 <strong>vm_inherit_t</strong>                       <var>inheritance</var><strong>);</strong>
19*1b191cb5SApple OSS Distributions</pre>
20*1b191cb5SApple OSS Distributions<h3>PARAMETERS</h3>
21*1b191cb5SApple OSS Distributions<dl>
22*1b191cb5SApple OSS Distributions<p>
23*1b191cb5SApple OSS Distributions<dt> <var>target_task</var>
24*1b191cb5SApple OSS Distributions<dd>
25*1b191cb5SApple OSS Distributions[in task send right]
26*1b191cb5SApple OSS DistributionsThe port for the task in whose address space the
27*1b191cb5SApple OSS Distributionsmemory object is to be mapped.
28*1b191cb5SApple OSS Distributions<p>
29*1b191cb5SApple OSS Distributions<dt> <var>address</var>
30*1b191cb5SApple OSS Distributions<dd>
31*1b191cb5SApple OSS Distributions[pointer to in/out scalar]
32*1b191cb5SApple OSS DistributionsThe starting address for the mapped object.
33*1b191cb5SApple OSS DistributionsThe mapped object will start at the beginning of the page containing
34*1b191cb5SApple OSS Distributions<var>address</var>.  If there is not enough room following the address, the kernel
35*1b191cb5SApple OSS Distributionsdoes not map the object.  The kernel returns the starting address
36*1b191cb5SApple OSS Distributionsactually used for the mapped object.
37*1b191cb5SApple OSS Distributions<p>
38*1b191cb5SApple OSS Distributions<dt> <var>size</var>
39*1b191cb5SApple OSS Distributions<dd>
40*1b191cb5SApple OSS Distributions[in scalar]
41*1b191cb5SApple OSS DistributionsThe number of bytes to allocate for the object.  The kernel
42*1b191cb5SApple OSS Distributionsrounds this number up to an integral number of virtual pages.
43*1b191cb5SApple OSS Distributions<p>
44*1b191cb5SApple OSS Distributions<dt> <var>mask</var>
45*1b191cb5SApple OSS Distributions<dd>
46*1b191cb5SApple OSS Distributions[in scalar]
47*1b191cb5SApple OSS DistributionsAlignment restrictions for starting address.  Bits turned on in
48*1b191cb5SApple OSS Distributionsthe mask will not be turned on in the starting address.
49*1b191cb5SApple OSS Distributions<p>
50*1b191cb5SApple OSS Distributions<dt> <var>anywhere</var>
51*1b191cb5SApple OSS Distributions<dd>
52*1b191cb5SApple OSS Distributions[in scalar]
53*1b191cb5SApple OSS DistributionsPlacement indicator.  The valid values are:
54*1b191cb5SApple OSS Distributions<dl>
55*1b191cb5SApple OSS Distributions<p>
56*1b191cb5SApple OSS Distributions<dt> <strong>TRUE</strong>
57*1b191cb5SApple OSS Distributions<dd>
58*1b191cb5SApple OSS DistributionsThe kernel allocates the region in the next unused space that
59*1b191cb5SApple OSS Distributionsis sufficient within the address space.  The kernel returns the
60*1b191cb5SApple OSS Distributionsstarting address actually used in <var>address</var>.
61*1b191cb5SApple OSS Distributions<p>
62*1b191cb5SApple OSS Distributions<dt> <strong>FALSE</strong>
63*1b191cb5SApple OSS Distributions<dd>
64*1b191cb5SApple OSS DistributionsThe kernel allocates the region starting at <var>address</var> unless that
65*1b191cb5SApple OSS Distributionsspace is already allocated.
66*1b191cb5SApple OSS Distributions</dl>
67*1b191cb5SApple OSS Distributions<p>
68*1b191cb5SApple OSS Distributions<dt> <var>memory_object</var>
69*1b191cb5SApple OSS Distributions<dd>
70*1b191cb5SApple OSS Distributions[in memory-object send right]
71*1b191cb5SApple OSS DistributionsThe port naming the
72*1b191cb5SApple OSS Distributionsmemory object.  If <strong>MEMORY_OBJECT_NULL</strong> is
73*1b191cb5SApple OSS Distributionsspecified, the kernel allocates zero-filled memory, as with <strong>vm_allocate</strong>.
74*1b191cb5SApple OSS Distributions<p>
75*1b191cb5SApple OSS Distributions<dt> <var>offset</var>
76*1b191cb5SApple OSS Distributions<dd>
77*1b191cb5SApple OSS Distributions[in scalar]
78*1b191cb5SApple OSS DistributionsAn offset within the memory object, in bytes.  The kernel
79*1b191cb5SApple OSS Distributionsmaps <var>address</var> to the specified offset.
80*1b191cb5SApple OSS Distributions<p>
81*1b191cb5SApple OSS Distributions<dt> <var>copy</var>
82*1b191cb5SApple OSS Distributions<dd>
83*1b191cb5SApple OSS Distributions[in scalar]
84*1b191cb5SApple OSS DistributionsCopy indicator.  If true, the kernel copies the region of the
85*1b191cb5SApple OSS Distributionsmemory object to the specified task's address space.  If false, the region
86*1b191cb5SApple OSS Distributionsis directly mapped.
87*1b191cb5SApple OSS Distributions<p>
88*1b191cb5SApple OSS Distributions<dt> <var>cur_protection</var>
89*1b191cb5SApple OSS Distributions<dd>
90*1b191cb5SApple OSS Distributions[in scalar]
91*1b191cb5SApple OSS DistributionsThe initial current protection for the region.  Valid values are
92*1b191cb5SApple OSS Distributionsobtained by or'ing together the following values:
93*1b191cb5SApple OSS Distributions<dl>
94*1b191cb5SApple OSS Distributions<p>
95*1b191cb5SApple OSS Distributions<dt> <strong>VM_PROT_READ</strong>
96*1b191cb5SApple OSS Distributions<dd>
97*1b191cb5SApple OSS DistributionsAllows read access.
98*1b191cb5SApple OSS Distributions<p>
99*1b191cb5SApple OSS Distributions<dt> <strong>VM_PROT_WRITE</strong>
100*1b191cb5SApple OSS Distributions<dd>
101*1b191cb5SApple OSS DistributionsAllows write access.
102*1b191cb5SApple OSS Distributions<p>
103*1b191cb5SApple OSS Distributions<dt> <strong>VM_PROT_EXECUTE</strong>
104*1b191cb5SApple OSS Distributions<dd>
105*1b191cb5SApple OSS DistributionsAllows execute access.
106*1b191cb5SApple OSS Distributions</dl>
107*1b191cb5SApple OSS Distributions<p>
108*1b191cb5SApple OSS Distributions<dt> <var>max_protection</var>
109*1b191cb5SApple OSS Distributions<dd>
110*1b191cb5SApple OSS Distributions[in scalar]
111*1b191cb5SApple OSS DistributionsThe maximum protection for the region.  Values are the same
112*1b191cb5SApple OSS Distributionsas for <var>cur_protection</var>.
113*1b191cb5SApple OSS Distributions<p>
114*1b191cb5SApple OSS Distributions<dt> <var>inheritance</var>
115*1b191cb5SApple OSS Distributions<dd>
116*1b191cb5SApple OSS Distributions[in scalar]
117*1b191cb5SApple OSS DistributionsThe initial inheritance attribute for the region.  Valid values
118*1b191cb5SApple OSS Distributionsare:
119*1b191cb5SApple OSS Distributions<dl>
120*1b191cb5SApple OSS Distributions<p>
121*1b191cb5SApple OSS Distributions<dt> <strong>VM_INHERIT_SHARE</strong>
122*1b191cb5SApple OSS Distributions<dd>
123*1b191cb5SApple OSS DistributionsAllows child tasks to share the region.
124*1b191cb5SApple OSS Distributions<p>
125*1b191cb5SApple OSS Distributions<dt> <strong>VM_INHERIT_COPY</strong>
126*1b191cb5SApple OSS Distributions<dd>
127*1b191cb5SApple OSS DistributionsGives child tasks a copy of the region.
128*1b191cb5SApple OSS Distributions<p>
129*1b191cb5SApple OSS Distributions<dt> <strong>VM_INHERIT_NONE</strong>
130*1b191cb5SApple OSS Distributions<dd>
131*1b191cb5SApple OSS DistributionsProvides no access to the region for child tasks.
132*1b191cb5SApple OSS Distributions</dl>
133*1b191cb5SApple OSS Distributions</dl>
134*1b191cb5SApple OSS Distributions<h3>DESCRIPTION</h3>
135*1b191cb5SApple OSS Distributions<p>
136*1b191cb5SApple OSS DistributionsThe <strong>vm_map</strong> function maps a portion of the specified
137*1b191cb5SApple OSS Distributionsmemory object into the
138*1b191cb5SApple OSS Distributionsvirtual address space belonging to <var>target_task</var>.  The target task
139*1b191cb5SApple OSS Distributionscan be the calling
140*1b191cb5SApple OSS Distributionstask or another task, identified by its task kernel port.
141*1b191cb5SApple OSS Distributions<p>
142*1b191cb5SApple OSS DistributionsThe portion of the memory object mapped is determined by <var>offset</var>
143*1b191cb5SApple OSS Distributionsand <var>size</var>.  The
144*1b191cb5SApple OSS Distributionskernel maps <var>address</var> to the offset, so that an access to the memory
145*1b191cb5SApple OSS Distributionsstarts at the offset in the object.
146*1b191cb5SApple OSS Distributions<p>
147*1b191cb5SApple OSS DistributionsThe <var>mask</var> parameter specifies additional alignment restrictions on
148*1b191cb5SApple OSS Distributionsthe kernel's selection of the starting address.  Uses for this mask include:
149*1b191cb5SApple OSS Distributions<ul>
150*1b191cb5SApple OSS Distributions<li>
151*1b191cb5SApple OSS DistributionsForcing the memory address alignment for a mapping to be the same as the
152*1b191cb5SApple OSS Distributionsalignment within the memory object.
153*1b191cb5SApple OSS Distributions<li>
154*1b191cb5SApple OSS DistributionsQuickly finding the beginning of an allocated region by performing bit
155*1b191cb5SApple OSS Distributionsarithmetic on an address known to be in the region.
156*1b191cb5SApple OSS Distributions<li>
157*1b191cb5SApple OSS DistributionsEmulating a larger virtual page size.
158*1b191cb5SApple OSS Distributions</ul>
159*1b191cb5SApple OSS Distributions<p>
160*1b191cb5SApple OSS DistributionsThe <var>cur_protection</var>, <var>max_protection</var>, and <var>inheritance</var>
161*1b191cb5SApple OSS Distributionsparameters set the
162*1b191cb5SApple OSS Distributionsprotection and inheritance attributes for the mapped object.
163*1b191cb5SApple OSS DistributionsAs a rule, at least the
164*1b191cb5SApple OSS Distributionsmaximum protection should be specified so that a server can make
165*1b191cb5SApple OSS Distributionsa restricted (for
166*1b191cb5SApple OSS Distributionsexample, read-only) mapping in a client atomically.  The current
167*1b191cb5SApple OSS Distributionsprotection and
168*1b191cb5SApple OSS Distributionsinheritance parameters are provided for convenience so that the
169*1b191cb5SApple OSS Distributionscaller does not
170*1b191cb5SApple OSS Distributionshave to call <strong>vm_inherit</strong> and <strong>vm_protect</strong> separately.
171*1b191cb5SApple OSS Distributions<p>
172*1b191cb5SApple OSS DistributionsThe same memory object can be mapped more than once and by more than one
173*1b191cb5SApple OSS Distributionstask.  If an object is mapped by multiple tasks, the kernel maintains
174*1b191cb5SApple OSS Distributionsconsistency
175*1b191cb5SApple OSS Distributionsfor all the mappings if they use the same page alignment for <var>offset</var>
176*1b191cb5SApple OSS Distributionsand are on
177*1b191cb5SApple OSS Distributionsthe same host.  In this case, the virtual memory to which the
178*1b191cb5SApple OSS Distributionsobject is mapped is
179*1b191cb5SApple OSS Distributionsshared by all the tasks.  Changes made by one task in its address space are
180*1b191cb5SApple OSS Distributionsvisible to all the other tasks.
181*1b191cb5SApple OSS DistributionsThe call will not return until the
182*1b191cb5SApple OSS Distributionsmemory object is ready for
183*1b191cb5SApple OSS Distributionsuse.
184*1b191cb5SApple OSS Distributions<h3>NOTES</h3>
185*1b191cb5SApple OSS Distributions<p>
186*1b191cb5SApple OSS Distributions<strong>vm_map</strong> allocates a region in a task's address space
187*1b191cb5SApple OSS Distributionsand maps the specified
188*1b191cb5SApple OSS Distributionsmemory object to this region.  <strong>vm_allocate</strong> allocates
189*1b191cb5SApple OSS Distributionsa zero-filled temporary
190*1b191cb5SApple OSS Distributionsregion in a task's address space.
191*1b191cb5SApple OSS Distributions<p>
192*1b191cb5SApple OSS DistributionsBefore a memory object can be mapped, a port naming it must be acquired from
193*1b191cb5SApple OSS Distributionsthe memory manager serving it.
194*1b191cb5SApple OSS Distributions<p>
195*1b191cb5SApple OSS DistributionsThis interface is machine word length specific because of the virtual address
196*1b191cb5SApple OSS Distributionsparameter.
197*1b191cb5SApple OSS Distributions<h3>CAUTIONS</h3>
198*1b191cb5SApple OSS Distributions<p>
199*1b191cb5SApple OSS DistributionsDo not attempt to map a memory object unless it has been provided by a
200*1b191cb5SApple OSS Distributionsmemory manager that implements the memory object interface.
201*1b191cb5SApple OSS DistributionsIf another type of port
202*1b191cb5SApple OSS Distributionsis specified, a thread that accesses the mapped virtual memory may become
203*1b191cb5SApple OSS Distributionspermanently hung or may receive a memory exception.
204*1b191cb5SApple OSS Distributions<h3>RETURN VALUES</h3>
205*1b191cb5SApple OSS Distributions<dl>
206*1b191cb5SApple OSS Distributions<p>
207*1b191cb5SApple OSS Distributions<dt> <strong>KERN_NO_SPACE</strong>
208*1b191cb5SApple OSS Distributions<dd>
209*1b191cb5SApple OSS DistributionsThere is not enough space in the task's address space to allocate the
210*1b191cb5SApple OSS Distributionsnew region for the memory object.
211*1b191cb5SApple OSS Distributions<p>
212*1b191cb5SApple OSS Distributions<dt> <strong>KERN_PROTECTION_FAILURE</strong>
213*1b191cb5SApple OSS Distributions<dd>
214*1b191cb5SApple OSS Distributions<var>max_protection</var> or <var>cur_protection</var> exceeds
215*1b191cb5SApple OSS Distributionsthat permitted by <var>memory_object</var>.
216*1b191cb5SApple OSS Distributions<p>
217*1b191cb5SApple OSS Distributions<dt> <strong>KERN_INVALID_OBJECT</strong>
218*1b191cb5SApple OSS Distributions<dd>
219*1b191cb5SApple OSS DistributionsThe memory manager failed to map the memory object.
220*1b191cb5SApple OSS Distributions</dl>
221*1b191cb5SApple OSS Distributions<h3>RELATED INFORMATION</h3>
222*1b191cb5SApple OSS Distributions<p>
223*1b191cb5SApple OSS DistributionsFunctions:
224*1b191cb5SApple OSS Distributions<a href="vm_allocate.html"><strong>vm_allocate</strong></a>,
225*1b191cb5SApple OSS Distributions<a href="vm_remap.html"><strong>vm_remap</strong></a>.
226