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