]> git.saurik.com Git - apple/xnu.git/blame - osfmk/man/vm_map.html
xnu-344.tar.gz
[apple/xnu.git] / osfmk / man / vm_map.html
CommitLineData
9bccf70c 1<h2>vm_map</h2>\r<hr>\r<p>\r<strong>Function</strong> - Map the specified memory object to a region of virtual memory.\r<h3>SYNOPSIS</h3>\r<pre>\r<strong>kern_return_t vm_map</strong>\r <strong>(vm_task_t</strong> <var>target_task</var>,\r <strong>vm_address_t</strong> <var>address</var>,\r <strong>vm_size_t</strong> <var>size</var>,\r <strong>vm_address_t</strong> <var>mask</var>,\r <strong>boolean_t</strong> <var>anywhere</var>,\r <strong>memory_object_t</strong> <var>memory_object</var>,\r <strong>vm_offset_t</strong> <var>offset</var>,\r <strong>boolean_t</strong> <var>copy</var>,\r <strong>vm_prot_t</strong> <var>cur_protection</var>,\r <strong>vm_prot_t</strong> <var>max_protection</var>,\r <strong>vm_inherit_t</strong> <var>inheritance</var><strong>);</strong>\r</pre>\r<h3>PARAMETERS</h3>\r<dl>\r<p>\r<dt> <var>target_task</var> \r<dd>\r[in task send right]\rThe port for the task in whose address space the \rmemory object is to be mapped.\r<p>\r<dt> <var>address</var> \r<dd>\r[pointer to in/out scalar]\rThe starting address for the mapped object. \rThe mapped object will start at the beginning of the page containing \r<var>address</var>. If there is not enough room following the address, the kernel \rdoes not map the object. The kernel returns the starting address\ractually used for the mapped object.\r<p>\r<dt> <var>size</var> \r<dd>\r[in scalar]\rThe number of bytes to allocate for the object. The kernel \rrounds this number up to an integral number of virtual pages.\r<p>\r<dt> <var>mask</var> \r<dd>\r[in scalar]\rAlignment restrictions for starting address. Bits turned on in \rthe mask will not be turned on in the starting address.\r<p>\r<dt> <var>anywhere</var> \r<dd>\r[in scalar]\rPlacement indicator. The valid values are:\r<dl>\r<p>\r<dt> <strong>TRUE</strong>\r<dd>\rThe kernel allocates the region in the next unused space that \ris sufficient within the address space. The kernel returns the \rstarting address actually used in <var>address</var>.\r<p>\r<dt> <strong>FALSE</strong>\r<dd>\rThe kernel allocates the region starting at <var>address</var> unless that \rspace is already allocated.\r</dl>\r<p>\r<dt> <var>memory_object</var> \r<dd>\r[in memory-object send right]\rThe port naming the \rmemory object. If <strong>MEMORY_OBJECT_NULL</strong> is\rspecified, the kernel allocates zero-filled memory, as with <strong>vm_allocate</strong>.\r<p>\r<dt> <var>offset</var> \r<dd>\r[in scalar]\rAn offset within the memory object, in bytes. The kernel \rmaps <var>address</var> to the specified offset.\r<p>\r<dt> <var>copy</var> \r<dd>\r[in scalar]\rCopy indicator. If true, the kernel copies the region of the \rmemory object to the specified task's address space. If false, the region \ris directly mapped.\r<p>\r<dt> <var>cur_protection</var> \r<dd>\r[in scalar]\rThe initial current protection for the region. Valid values are \robtained by or'ing together the following values:\r<dl>\r<p>\r<dt> <strong>VM_PROT_READ</strong>\r<dd>\rAllows read access.\r<p>\r<dt> <strong>VM_PROT_WRITE</strong>\r<dd>\rAllows write access.\r<p>\r<dt> <strong>VM_PROT_EXECUTE</strong>\r<dd>\rAllows execute access.\r</dl>\r<p>\r<dt> <var>max_protection</var> \r<dd>\r[in scalar]\rThe maximum protection for the region. Values are the same \ras for <var>cur_protection</var>.\r<p>\r<dt> <var>inheritance</var> \r<dd>\r[in scalar]\rThe initial inheritance attribute for the region. Valid values \rare:\r<dl>\r<p>\r<dt> <strong>VM_INHERIT_SHARE</strong>\r<dd>\rAllows child tasks to share the region.\r<p>\r<dt> <strong>VM_INHERIT_COPY</strong>\r<dd>\rGives child tasks a copy of the region.\r<p>\r<dt> <strong>VM_INHERIT_NONE</strong>\r<dd>\rProvides no access to the region for child tasks.\r</dl>\r</dl>\r<h3>DESCRIPTION</h3>\r<p>\rThe <strong>vm_map</strong> function maps a portion of the specified\rmemory object into the \rvirtual address space belonging to <var>target_task</var>. The target task\rcan be the calling \rtask or another task, identified by its task kernel port.\r<p>\rThe portion of the memory object mapped is determined by <var>offset</var> \rand <var>size</var>. The \rkernel maps <var>address</var> to the offset, so that an access to the memory\rstarts at the offset in the object.\r<p>\rThe <var>mask</var> parameter specifies additional alignment restrictions on \rthe kernel's selection of the starting address. Uses for this mask include:\r<ul>\r<li>\rForcing the memory address alignment for a mapping to be the same as the \ralignment within the memory object.\r<li>\rQuickly finding the beginning of an allocated region by performing bit\rarithmetic on an address known to be in the region.\r<li>\rEmulating a larger virtual page size.\r</ul>\r<p>\rThe <var>cur_protection</var>, <var>max_protection</var>, and <var>inheritance</var>\rparameters set the\rprotection and inheritance attributes for the mapped object.\rAs a rule, at least the\rmaximum protection should be specified so that a server can make\ra restricted (for \rexample, read-only) mapping in a client atomically. The current\rprotection and \rinheritance parameters are provided for convenience so that the\rcaller does not \rhave to call <strong>vm_inherit</strong> and <strong>vm_protect</strong> separately.\r<p>\rThe same memory object can be mapped more than once and by more than one \rtask. If an object is mapped by multiple tasks, the kernel maintains\rconsistency \rfor all the mappings if they use the same page alignment for <var>offset</var> \rand are on \rthe same host. In this case, the virtual memory to which the\robject is mapped is \rshared by all the tasks. Changes made by one task in its address space are\rvisible to all the other tasks.\rThe call will not return until the\rmemory object is ready for \ruse.\r<h3>NOTES</h3>\r<p>\r<strong>vm_map</strong> allocates a region in a task's address space\rand maps the specified \rmemory object to this region. <strong>vm_allocate</strong> allocates\ra zero-filled temporary\rregion in a task's address space.\r<p>\rBefore a memory object can be mapped, a port naming it must be acquired from \rthe memory manager serving it.\r<p>\rThis interface is machine word length specific because of the virtual address\rparameter.\r<h3>CAUTIONS</h3>\r<p>\rDo not attempt to map a memory object unless it has been provided by a\rmemory manager that implements the memory object interface. \rIf another type of port \ris specified, a thread that accesses the mapped virtual memory may become\rpermanently hung or may receive a memory exception.\r<h3>RETURN VALUES</h3>\r<dl>\r<p>\r<dt> <strong>KERN_NO_SPACE</strong>\r<dd>\rThere is not enough space in the task's address space to allocate the \rnew region for the memory object.\r<p>\r<dt> <strong>KERN_PROTECTION_FAILURE</strong>\r<dd>\r<var>max_protection</var> or <var>cur_protection</var> exceeds \rthat permitted by <var>memory_object</var>.\r<p>\r<dt> <strong>KERN_INVALID_OBJECT</strong>\r<dd>\rThe memory manager failed to map the memory object.\r</dl>\r<h3>RELATED INFORMATION</h3>\r<p>\rFunctions:\r<a href="vm_allocate.html"><strong>vm_allocate</strong></a>,\r<a href="vm_remap.html"><strong>vm_remap</strong></a>.\r