4 <strong>Function
</strong> - Map the specified memory object to a region of virtual memory.
7 <strong>kern_return_t vm_map
</strong>
8 <strong>(vm_task_t
</strong> <var>target_task
</var>,
9 <strong>vm_address_t
</strong> <var>address
</var>,
10 <strong>vm_size_t
</strong> <var>size
</var>,
11 <strong>vm_address_t
</strong> <var>mask
</var>,
12 <strong>boolean_t
</strong> <var>anywhere
</var>,
13 <strong>memory_object_t
</strong> <var>memory_object
</var>,
14 <strong>vm_offset_t
</strong> <var>offset
</var>,
15 <strong>boolean_t
</strong> <var>copy
</var>,
16 <strong>vm_prot_t
</strong> <var>cur_protection
</var>,
17 <strong>vm_prot_t
</strong> <var>max_protection
</var>,
18 <strong>vm_inherit_t
</strong> <var>inheritance
</var><strong>);
</strong>
23 <dt> <var>target_task
</var>
26 The port for the task in whose address space the
27 memory object is to be mapped.
29 <dt> <var>address
</var>
31 [pointer to in/out scalar]
32 The starting address for the mapped object.
33 The mapped object will start at the beginning of the page containing
34 <var>address
</var>. If there is not enough room following the address, the kernel
35 does not map the object. The kernel returns the starting address
36 actually used for the mapped object.
41 The number of bytes to allocate for the object. The kernel
42 rounds this number up to an integral number of virtual pages.
47 Alignment restrictions for starting address. Bits turned on in
48 the mask will not be turned on in the starting address.
50 <dt> <var>anywhere
</var>
53 Placement indicator. The valid values are:
56 <dt> <strong>TRUE
</strong>
58 The kernel allocates the region in the next unused space that
59 is sufficient within the address space. The kernel returns the
60 starting address actually used in
<var>address
</var>.
62 <dt> <strong>FALSE
</strong>
64 The kernel allocates the region starting at
<var>address
</var> unless that
65 space is already allocated.
68 <dt> <var>memory_object
</var>
70 [in memory-object send right]
72 memory object. If
<strong>MEMORY_OBJECT_NULL
</strong> is
73 specified, the kernel allocates zero-filled memory, as with
<strong>vm_allocate
</strong>.
75 <dt> <var>offset
</var>
78 An offset within the memory object, in bytes. The kernel
79 maps
<var>address
</var> to the specified offset.
84 Copy indicator. If true, the kernel copies the region of the
85 memory object to the specified task's address space. If false, the region
88 <dt> <var>cur_protection
</var>
91 The initial current protection for the region. Valid values are
92 obtained by or'ing together the following values:
95 <dt> <strong>VM_PROT_READ
</strong>
99 <dt> <strong>VM_PROT_WRITE
</strong>
103 <dt> <strong>VM_PROT_EXECUTE
</strong>
105 Allows execute access.
108 <dt> <var>max_protection
</var>
111 The maximum protection for the region. Values are the same
112 as for
<var>cur_protection
</var>.
114 <dt> <var>inheritance
</var>
117 The initial inheritance attribute for the region. Valid values
121 <dt> <strong>VM_INHERIT_SHARE
</strong>
123 Allows child tasks to share the region.
125 <dt> <strong>VM_INHERIT_COPY
</strong>
127 Gives child tasks a copy of the region.
129 <dt> <strong>VM_INHERIT_NONE
</strong>
131 Provides no access to the region for child tasks.
136 The
<strong>vm_map
</strong> function maps a portion of the specified
137 memory object into the
138 virtual address space belonging to
<var>target_task
</var>. The target task
140 task or another task, identified by its task kernel port.
142 The portion of the memory object mapped is determined by
<var>offset
</var>
143 and
<var>size
</var>. The
144 kernel maps
<var>address
</var> to the offset, so that an access to the memory
145 starts at the offset in the object.
147 The
<var>mask
</var> parameter specifies additional alignment restrictions on
148 the kernel's selection of the starting address. Uses for this mask include:
151 Forcing the memory address alignment for a mapping to be the same as the
152 alignment within the memory object.
154 Quickly finding the beginning of an allocated region by performing bit
155 arithmetic on an address known to be in the region.
157 Emulating a larger virtual page size.
160 The
<var>cur_protection
</var>,
<var>max_protection
</var>, and
<var>inheritance
</var>
162 protection and inheritance attributes for the mapped object.
163 As a rule, at least the
164 maximum protection should be specified so that a server can make
166 example, read-only) mapping in a client atomically. The current
168 inheritance parameters are provided for convenience so that the
170 have to call
<strong>vm_inherit
</strong> and
<strong>vm_protect
</strong> separately.
172 The same memory object can be mapped more than once and by more than one
173 task. If an object is mapped by multiple tasks, the kernel maintains
175 for all the mappings if they use the same page alignment for
<var>offset
</var>
177 the same host. In this case, the virtual memory to which the
179 shared by all the tasks. Changes made by one task in its address space are
180 visible to all the other tasks.
181 The call will not return until the
182 memory object is ready for
186 <strong>vm_map
</strong> allocates a region in a task's address space
187 and maps the specified
188 memory object to this region.
<strong>vm_allocate
</strong> allocates
189 a zero-filled temporary
190 region in a task's address space.
192 Before a memory object can be mapped, a port naming it must be acquired from
193 the memory manager serving it.
195 This interface is machine word length specific because of the virtual address
199 Do not attempt to map a memory object unless it has been provided by a
200 memory manager that implements the memory object interface.
201 If another type of port
202 is specified, a thread that accesses the mapped virtual memory may become
203 permanently hung or may receive a memory exception.
204 <h3>RETURN VALUES
</h3>
207 <dt> <strong>KERN_NO_SPACE
</strong>
209 There is not enough space in the task's address space to allocate the
210 new region for the memory object.
212 <dt> <strong>KERN_PROTECTION_FAILURE
</strong>
214 <var>max_protection
</var> or
<var>cur_protection
</var> exceeds
215 that permitted by
<var>memory_object
</var>.
217 <dt> <strong>KERN_INVALID_OBJECT
</strong>
219 The memory manager failed to map the memory object.
221 <h3>RELATED INFORMATION
</h3>
224 <a href=
"vm_allocate.html"><strong>vm_allocate
</strong></a>,
225 <a href=
"vm_remap.html"><strong>vm_remap
</strong></a>.