Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | <h2>vm_reallocate</h2> <hr> <p> <strong>Function</strong> - Reallocate a region of virtual memory. <h3>SYNOPSIS</h3> <pre> <strong>kern_return_t vm_reallocate</strong> <strong>(vm_task_t</strong> <var>target_task</var>, <strong>vm_address_t</strong> <var>src</var>, <strong>vm_size_t</strong> <var>src_size</var>, <strong>vm_address_t</strong> <var>*dst</var>, <strong>vm_size_t</strong> <var>dst_size</var>, <strong>vm_offset_t</strong> <var>align_mask</var>, <strong>int</strong> <var>options</var>, <strong>int</strong> <var>flags</var><strong>);</strong> </pre> <h3>PARAMETERS</h3> <dl> <p> <dt> <var>target_task</var> <dd> [in task send right] The port for the task whose address space the region is to be reallocated in. <p> <dt> <var>src</var> <dd> [in scalar] The starting address for the source region. <p> <dt> <var>src_size</var> <dd> [in scalar] The size of the source region in bytes. <p> <dt> <var>dst</var> <dd> [pointer to in/out scalar] The starting address for the destination region, or a minimum address hint, depending on <var>flags</var>. <p> <dt> <var>dst_size</var> <dd> [in scalar] The size of the destination region in bytes; must be at least <var>src_size</var>. <p> <dt> <var>align_mask</var> <dd> [in scalar] Alignment bitmask for destination address. Must be of the form (2^n - 1). The result of <var>align_mask</var> | <strong>page_mask</strong> will be used for alignment. <p> <dt> <var>options</var> <dd> [in scalar] Reallocation options. <dl> <p> <dt><strong>VM_REALLOCATE_DEALLOCATE_SOURCE</strong> <dd> The kernel deallocates the source. <p> </dl> <dl> <p> <dt><strong>VM_REALLOCATE_ZERO_FILL_SOURCE</strong> <dd> The kernel zero-fills the source. <p> </dl> <dt> <var>flags</var> <dd> [in scalar] Flags that determine how the destination address is interpreted. The user tag is passed in the high order byte. <dl> <p> <dt><strong>VM_FLAGS_ANYWHERE</strong> <dd> The kernel will find an address, starting from <var>*dst</var>, to place the reallocated region. <p> </dl> <dl> <p> <dt><strong>VM_FLAGS_FIXED</strong> <dd> The kernel will attempt to place the reallocated region directly at <var>*dst</var>, and will fail if the address range is already mapped. <p> </dl> <dl> <p> <dt><strong>VM_FLAGS_OVERWRITE</strong> <dd> The kernel will overwrite any existing allocations when <strong>VM_FLAGS_FIXED</strong> is specified. All <var>dst_size</var> bytes of the destination must already be mapped without holes. On failure, the contents of the destination are undefined, and should not be relied upon. <p> </dl> <h3>DESCRIPTION</h3> <p> The <strong>vm_reallocate</strong> function causes the <var>src_size</var> bytes starting at address <var>src</var> to be reallocated as <var>dst_size</var> bytes, and writes the new address to <var>*dst</var>. <p> If <strong>KERN_SUCCESS</strong> is returned, the data will only be accessible through <var>*dst</var>. This restriction allows reallocation without making any copies of the source data. Using <strong>vm_reallocate</strong> is therefore more efficient than creating a new allocation and using <strong>memcpy</strong> or <strong>vm_copy</strong> to "reallocate" memory. <p> The expanded region will be zero-filled. <strong>vm_reallocate</strong> affects only <var>target_task</var>. Other tasks that have access to the deallocated memory can continue to reference it. <h3>NOTES</h3> <p> <strong>vm_deallocate</strong> can be used to deallocate memory passed as out-of-line data in a message. <p> <h3>RETURN VALUES</h3> <dl> <p> <dt> <strong>KERN_INVALID_ARGUMENT</strong> <dd> Unsupported Mach VM flags are specified in <var>flags</var>. </dl> <p> <dt> <strong>KERN_INVALID_ARGUMENT</strong> <dd> An unsupported reallocation option is specified in <var>options</var>. </dl> <p> <dt> <strong>KERN_INVALID_ARGUMENT</strong> <dd> <var>dst_size</var> or <var>src_size</var> is not a multiple of <strong>PAGE_SIZE</strong>. </dl> <p> <dt> <strong>KERN_INVALID_ARGUMENT</strong> <dd> <var>dst_size</var> is smaller than <var>src_size</var>. </dl> <p> <dt> <strong>KERN_INVALID_ADDRESS</strong> <dd> <var>src</var> is not page-aligned. </dl> <p> <dt> <strong>KERN_INVALID_ADDRESS</strong> <dd> <strong>VM_FLAGS_FIXED</strong> is specified, and <var>*dst</var> is not page/<var>align_mask</var>-aligned. </dl> <p> <dt> <strong>KERN_INVALID_ADDRESS</strong> <dd> Any portion of [<var>src</var>, <var>src</var> + <var>src_size</var>) is not mapped, is permanent, or is a sub-map. </dl> <p> <dt> <strong>KERN_INVALID_ADDRESS</strong> <dd> <strong>VM_FLAGS_FIXED</strong> | <strong>VM_FLAGS_OVERWRITE</strong> specified, and [<var>dst</var>, <var>dst</var> + <var>dst_size</var>) overlaps [<var>src</var>, <var>src</var> + <var>src_size</var>). </dl> <p> <dt> <strong>KERN_NO_SPACE</strong> <dd> <strong>VM_FLAGS_ANYWHERE</strong> is specified, and no contiguous range of <var>dst_size</var> bytes could be found at or after <var>*dst</var>. </dl> <p> <dt> <strong>KERN_NO_SPACE</strong> <dd> <strong>VM_FLAGS_FIXED</strong> is specified without <strong>VM_FLAGS_OVERWRITE</strong> and any portion of [<var>*dst</var>, <var>*dst</var> + <var>dst_size</var>) is already mapped. </dl> <p> <dt> <strong>KERN_NOT_SUPPORTED</strong> <dd> The process is running with non-native page size (e.g., Rosetta). </dl> <p> <dt> <strong>KERN_NOT_SUPPORTED</strong> <dd> Otherwise, <strong>vm_reallocate</strong> cannot perform the reallocation. </dl> <p> <h3>RELATED INFORMATION</h3> <p> Functions: <a href="mach_msg.html"><strong>mach_msg</strong></a>, <a href="vm_allocate.html"><strong>vm_allocate</strong></a>, <a href="vm_deallocate.html"><strong>vm_deallocate</strong></a>, <a href="host_page_size.html"><strong>host_page_size</strong></a>. |