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