]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2000-2009 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | ||
59 | /* | |
60 | * File: vm/vm_map.h | |
61 | * Author: Avadis Tevanian, Jr., Michael Wayne Young | |
62 | * Date: 1985 | |
63 | * | |
64 | * Virtual memory map module definitions. | |
65 | * | |
66 | * Contributors: | |
67 | * avie, dlb, mwyoung | |
68 | */ | |
69 | ||
70 | #ifndef _VM_VM_MAP_H_ | |
71 | #define _VM_VM_MAP_H_ | |
72 | ||
73 | #include <mach/mach_types.h> | |
74 | #include <mach/kern_return.h> | |
75 | #include <mach/boolean.h> | |
76 | #include <mach/vm_types.h> | |
77 | #include <mach/vm_prot.h> | |
78 | #include <mach/vm_inherit.h> | |
79 | #include <mach/vm_behavior.h> | |
91447636 | 80 | #include <mach/vm_param.h> |
1c79356b A |
81 | #include <vm/pmap.h> |
82 | ||
91447636 | 83 | #ifdef KERNEL_PRIVATE |
1c79356b | 84 | |
91447636 | 85 | #include <sys/cdefs.h> |
1c79356b | 86 | |
91447636 | 87 | __BEGIN_DECLS |
1c79356b A |
88 | |
89 | extern void vm_map_reference(vm_map_t map); | |
90 | extern vm_map_t current_map(void); | |
91 | ||
2d21ac55 A |
92 | /* Setup reserved areas in a new VM map */ |
93 | extern kern_return_t vm_map_exec( | |
94 | vm_map_t new_map, | |
95 | task_t task, | |
39037602 | 96 | boolean_t is64bit, |
2d21ac55 A |
97 | void *fsroot, |
98 | cpu_type_t cpu); | |
99 | ||
91447636 A |
100 | __END_DECLS |
101 | ||
102 | #ifdef MACH_KERNEL_PRIVATE | |
1c79356b | 103 | |
1c79356b A |
104 | #include <task_swapper.h> |
105 | #include <mach_assert.h> | |
106 | ||
107 | #include <vm/vm_object.h> | |
108 | #include <vm/vm_page.h> | |
fe8ab488 | 109 | #include <kern/locks.h> |
1c79356b A |
110 | #include <kern/zalloc.h> |
111 | #include <kern/macro_help.h> | |
112 | ||
91447636 | 113 | #include <kern/thread.h> |
1c79356b | 114 | |
91447636 | 115 | #define current_map_fast() (current_thread()->map) |
1c79356b A |
116 | #define current_map() (current_map_fast()) |
117 | ||
6d2010ae A |
118 | #include <vm/vm_map_store.h> |
119 | ||
120 | ||
1c79356b A |
121 | /* |
122 | * Types defined: | |
123 | * | |
124 | * vm_map_t the high-level address map data structure. | |
125 | * vm_map_entry_t an entry in an address map. | |
126 | * vm_map_version_t a timestamp of a map, for use with vm_map_lookup | |
127 | * vm_map_copy_t represents memory copied from an address map, | |
128 | * used for inter-map copy operations | |
129 | */ | |
9bccf70c | 130 | typedef struct vm_map_entry *vm_map_entry_t; |
91447636 | 131 | #define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0) |
9bccf70c | 132 | |
1c79356b A |
133 | |
134 | /* | |
135 | * Type: vm_map_object_t [internal use only] | |
136 | * | |
137 | * Description: | |
138 | * The target of an address mapping, either a virtual | |
139 | * memory object or a sub map (of the kernel map). | |
140 | */ | |
141 | typedef union vm_map_object { | |
3e170ce0 A |
142 | vm_object_t vmo_object; /* object object */ |
143 | vm_map_t vmo_submap; /* belongs to another map */ | |
1c79356b A |
144 | } vm_map_object_t; |
145 | ||
b0d623f7 | 146 | #define named_entry_lock_init(object) lck_mtx_init(&(object)->Lock, &vm_object_lck_grp, &vm_object_lck_attr) |
316670eb | 147 | #define named_entry_lock_destroy(object) lck_mtx_destroy(&(object)->Lock, &vm_object_lck_grp) |
b0d623f7 A |
148 | #define named_entry_lock(object) lck_mtx_lock(&(object)->Lock) |
149 | #define named_entry_unlock(object) lck_mtx_unlock(&(object)->Lock) | |
1c79356b A |
150 | |
151 | /* | |
152 | * Type: vm_named_entry_t [internal use only] | |
153 | * | |
154 | * Description: | |
155 | * Description of a mapping to a memory cache object. | |
156 | * | |
157 | * Implementation: | |
158 | * While the handle to this object is used as a means to map | |
159 | * and pass around the right to map regions backed by pagers | |
160 | * of all sorts, the named_entry itself is only manipulated | |
161 | * by the kernel. Named entries hold information on the | |
162 | * right to map a region of a cached object. Namely, | |
163 | * the target cache object, the beginning and ending of the | |
164 | * region to be mapped, and the permissions, (read, write) | |
165 | * with which it can be mapped. | |
166 | * | |
167 | */ | |
168 | ||
169 | struct vm_named_entry { | |
b0d623f7 | 170 | decl_lck_mtx_data(, Lock) /* Synchronization */ |
1c79356b | 171 | union { |
91447636 | 172 | vm_object_t object; /* object I point to */ |
91447636 | 173 | vm_map_t map; /* map backing submap */ |
39236c6e | 174 | vm_map_copy_t copy; /* a VM map copy */ |
1c79356b | 175 | } backing; |
91447636 A |
176 | vm_object_offset_t offset; /* offset into object */ |
177 | vm_object_size_t size; /* size of region */ | |
39236c6e | 178 | vm_object_offset_t data_offset; /* offset to first byte of data */ |
91447636 | 179 | vm_prot_t protection; /* access permissions */ |
1c79356b | 180 | int ref_count; /* Number of references */ |
91447636 A |
181 | unsigned int /* Is backing.xxx : */ |
182 | /* boolean_t */ internal:1, /* ... an internal object */ | |
183 | /* boolean_t */ is_sub_map:1, /* ... a submap? */ | |
39236c6e | 184 | /* boolean_t */ is_copy:1; /* ... a VM map copy */ |
1c79356b A |
185 | }; |
186 | ||
1c79356b A |
187 | /* |
188 | * Type: vm_map_entry_t [internal use only] | |
189 | * | |
190 | * Description: | |
191 | * A single mapping within an address map. | |
192 | * | |
193 | * Implementation: | |
194 | * Address map entries consist of start and end addresses, | |
195 | * a VM object (or sub map) and offset into that object, | |
196 | * and user-exported inheritance and protection information. | |
197 | * Control information for virtual copy operations is also | |
198 | * stored in the address map entry. | |
199 | */ | |
6d2010ae | 200 | |
1c79356b A |
201 | struct vm_map_links { |
202 | struct vm_map_entry *prev; /* previous entry */ | |
203 | struct vm_map_entry *next; /* next entry */ | |
91447636 A |
204 | vm_map_offset_t start; /* start address */ |
205 | vm_map_offset_t end; /* end address */ | |
1c79356b A |
206 | }; |
207 | ||
3e170ce0 A |
208 | /* |
209 | * IMPORTANT: | |
210 | * The "alias" field can be updated while holding the VM map lock | |
211 | * "shared". It's OK as along as it's the only field that can be | |
212 | * updated without the VM map "exclusive" lock. | |
213 | */ | |
214 | #define VME_OBJECT(entry) ((entry)->vme_object.vmo_object) | |
215 | #define VME_OBJECT_SET(entry, object) \ | |
216 | MACRO_BEGIN \ | |
217 | (entry)->vme_object.vmo_object = (object); \ | |
218 | MACRO_END | |
219 | #define VME_SUBMAP(entry) ((entry)->vme_object.vmo_submap) | |
220 | #define VME_SUBMAP_SET(entry, submap) \ | |
221 | MACRO_BEGIN \ | |
222 | (entry)->vme_object.vmo_submap = (submap); \ | |
223 | MACRO_END | |
224 | #define VME_OFFSET(entry) ((entry)->vme_offset & ~PAGE_MASK) | |
225 | #define VME_OFFSET_SET(entry, offset) \ | |
226 | MACRO_BEGIN \ | |
227 | int __alias; \ | |
228 | __alias = VME_ALIAS((entry)); \ | |
229 | assert((offset & PAGE_MASK) == 0); \ | |
230 | (entry)->vme_offset = offset | __alias; \ | |
231 | MACRO_END | |
232 | #define VME_OBJECT_SHADOW(entry, length) \ | |
233 | MACRO_BEGIN \ | |
234 | vm_object_t __object; \ | |
235 | vm_object_offset_t __offset; \ | |
236 | __object = VME_OBJECT((entry)); \ | |
237 | __offset = VME_OFFSET((entry)); \ | |
238 | vm_object_shadow(&__object, &__offset, (length)); \ | |
239 | if (__object != VME_OBJECT((entry))) { \ | |
240 | VME_OBJECT_SET((entry), __object); \ | |
a39ff7e2 | 241 | (entry)->use_pmap = TRUE; \ |
3e170ce0 A |
242 | } \ |
243 | if (__offset != VME_OFFSET((entry))) { \ | |
244 | VME_OFFSET_SET((entry), __offset); \ | |
245 | } \ | |
246 | MACRO_END | |
247 | ||
248 | #define VME_ALIAS_MASK (PAGE_MASK) | |
249 | #define VME_ALIAS(entry) ((unsigned int)((entry)->vme_offset & VME_ALIAS_MASK)) | |
250 | #define VME_ALIAS_SET(entry, alias) \ | |
251 | MACRO_BEGIN \ | |
252 | vm_map_offset_t __offset; \ | |
253 | __offset = VME_OFFSET((entry)); \ | |
254 | (entry)->vme_offset = __offset | ((alias) & VME_ALIAS_MASK); \ | |
255 | MACRO_END | |
256 | ||
a39ff7e2 A |
257 | /* |
258 | * FOOTPRINT ACCOUNTING: | |
259 | * The "memory footprint" is better described in the pmap layer. | |
260 | * | |
261 | * At the VM level, these 2 vm_map_entry_t fields are relevant: | |
262 | * iokit_mapped: | |
263 | * For an "iokit_mapped" entry, we add the size of the entry to the | |
264 | * footprint when the entry is entered into the map and we subtract that | |
265 | * size when the entry is removed. No other accounting should take place. | |
266 | * "use_pmap" should be FALSE but is not taken into account. | |
267 | * use_pmap: (only when is_sub_map is FALSE) | |
268 | * This indicates if we should ask the pmap layer to account for pages | |
269 | * in this mapping. If FALSE, we expect that another form of accounting | |
270 | * is being used (e.g. "iokit_mapped" or the explicit accounting of | |
271 | * non-volatile purgable memory). | |
272 | * | |
273 | * So the logic is mostly: | |
274 | * if entry->is_sub_map == TRUE | |
275 | * anything in a submap does not count for the footprint | |
276 | * else if entry->iokit_mapped == TRUE | |
277 | * footprint includes the entire virtual size of this entry | |
278 | * else if entry->use_pmap == FALSE | |
279 | * tell pmap NOT to account for pages being pmap_enter()'d from this | |
280 | * mapping (i.e. use "alternate accounting") | |
281 | * else | |
282 | * pmap will account for pages being pmap_enter()'d from this mapping | |
283 | * as it sees fit (only if anonymous, etc...) | |
284 | */ | |
285 | ||
1c79356b A |
286 | struct vm_map_entry { |
287 | struct vm_map_links links; /* links to other entries */ | |
288 | #define vme_prev links.prev | |
289 | #define vme_next links.next | |
290 | #define vme_start links.start | |
291 | #define vme_end links.end | |
6d2010ae A |
292 | |
293 | struct vm_map_store store; | |
3e170ce0 A |
294 | union vm_map_object vme_object; /* object I point to */ |
295 | vm_object_offset_t vme_offset; /* offset into object */ | |
296 | ||
1c79356b | 297 | unsigned int |
3e170ce0 A |
298 | /* boolean_t */ is_shared:1, /* region is shared */ |
299 | /* boolean_t */ is_sub_map:1, /* Is "object" a submap? */ | |
300 | /* boolean_t */ in_transition:1, /* Entry being changed */ | |
301 | /* boolean_t */ needs_wakeup:1, /* Waiters on in_transition */ | |
302 | /* vm_behavior_t */ behavior:2, /* user paging behavior hint */ | |
1c79356b | 303 | /* behavior is not defined for submap type */ |
3e170ce0 A |
304 | /* boolean_t */ needs_copy:1, /* object need to be copied? */ |
305 | ||
1c79356b | 306 | /* Only in task maps: */ |
3e170ce0 A |
307 | /* vm_prot_t */ protection:3, /* protection code */ |
308 | /* vm_prot_t */ max_protection:3, /* maximum protection */ | |
309 | /* vm_inherit_t */ inheritance:2, /* inheritance */ | |
310 | /* boolean_t */ use_pmap:1, /* | |
311 | * use_pmap is overloaded: | |
312 | * if "is_sub_map": | |
313 | * use a nested pmap? | |
314 | * else (i.e. if object): | |
315 | * use pmap accounting | |
316 | * for footprint? | |
317 | */ | |
318 | /* boolean_t */ no_cache:1, /* should new pages be cached? */ | |
319 | /* boolean_t */ permanent:1, /* mapping can not be removed */ | |
320 | /* boolean_t */ superpage_size:1, /* use superpages of a certain size */ | |
321 | /* boolean_t */ map_aligned:1, /* align to map's page size */ | |
322 | /* boolean_t */ zero_wired_pages:1, /* zero out the wired pages of | |
323 | * this entry it is being deleted | |
324 | * without unwiring them */ | |
325 | /* boolean_t */ used_for_jit:1, | |
326 | /* boolean_t */ from_reserved_zone:1, /* Allocated from | |
327 | * kernel reserved zone */ | |
fe8ab488 A |
328 | |
329 | /* iokit accounting: use the virtual size rather than resident size: */ | |
3e170ce0 A |
330 | /* boolean_t */ iokit_acct:1, |
331 | /* boolean_t */ vme_resilient_codesign:1, | |
332 | /* boolean_t */ vme_resilient_media:1, | |
39037602 A |
333 | /* boolean_t */ vme_atomic:1, /* entry cannot be split/coalesced */ |
334 | __unused:5; | |
3e170ce0 | 335 | ; |
fe8ab488 | 336 | |
1c79356b A |
337 | unsigned short wired_count; /* can be paged if = 0 */ |
338 | unsigned short user_wired_count; /* for vm_wire */ | |
316670eb A |
339 | #if DEBUG |
340 | #define MAP_ENTRY_CREATION_DEBUG (1) | |
39236c6e | 341 | #define MAP_ENTRY_INSERTION_DEBUG (1) |
316670eb A |
342 | #endif |
343 | #if MAP_ENTRY_CREATION_DEBUG | |
39236c6e A |
344 | struct vm_map_header *vme_creation_maphdr; |
345 | uintptr_t vme_creation_bt[16]; | |
346 | #endif | |
347 | #if MAP_ENTRY_INSERTION_DEBUG | |
348 | uintptr_t vme_insertion_bt[16]; | |
316670eb | 349 | #endif |
1c79356b A |
350 | }; |
351 | ||
b0d623f7 A |
352 | /* |
353 | * Convenience macros for dealing with superpages | |
354 | * SUPERPAGE_NBASEPAGES is architecture dependent and defined in pmap.h | |
355 | */ | |
356 | #define SUPERPAGE_SIZE (PAGE_SIZE*SUPERPAGE_NBASEPAGES) | |
357 | #define SUPERPAGE_MASK (-SUPERPAGE_SIZE) | |
358 | #define SUPERPAGE_ROUND_DOWN(a) (a & SUPERPAGE_MASK) | |
359 | #define SUPERPAGE_ROUND_UP(a) ((a + SUPERPAGE_SIZE-1) & SUPERPAGE_MASK) | |
360 | ||
1c79356b A |
361 | /* |
362 | * wired_counts are unsigned short. This value is used to safeguard | |
363 | * against any mishaps due to runaway user programs. | |
364 | */ | |
365 | #define MAX_WIRE_COUNT 65535 | |
366 | ||
367 | ||
368 | ||
369 | /* | |
370 | * Type: struct vm_map_header | |
371 | * | |
372 | * Description: | |
373 | * Header for a vm_map and a vm_map_copy. | |
374 | */ | |
6d2010ae A |
375 | |
376 | ||
1c79356b A |
377 | struct vm_map_header { |
378 | struct vm_map_links links; /* first, last, min, max */ | |
379 | int nentries; /* Number of entries */ | |
380 | boolean_t entries_pageable; | |
381 | /* are map entries pageable? */ | |
6d2010ae A |
382 | #ifdef VM_MAP_STORE_USE_RB |
383 | struct rb_head rb_head_store; | |
384 | #endif | |
39236c6e | 385 | int page_shift; /* page shift */ |
1c79356b A |
386 | }; |
387 | ||
39236c6e A |
388 | #define VM_MAP_HDR_PAGE_SHIFT(hdr) ((hdr)->page_shift) |
389 | #define VM_MAP_HDR_PAGE_SIZE(hdr) (1 << VM_MAP_HDR_PAGE_SHIFT((hdr))) | |
390 | #define VM_MAP_HDR_PAGE_MASK(hdr) (VM_MAP_HDR_PAGE_SIZE((hdr)) - 1) | |
391 | ||
1c79356b A |
392 | /* |
393 | * Type: vm_map_t [exported; contents invisible] | |
394 | * | |
395 | * Description: | |
396 | * An address map -- a directory relating valid | |
397 | * regions of a task's address space to the corresponding | |
398 | * virtual memory objects. | |
399 | * | |
400 | * Implementation: | |
401 | * Maps are doubly-linked lists of map entries, sorted | |
402 | * by address. One hint is used to start | |
403 | * searches again from the last successful search, | |
404 | * insertion, or removal. Another hint is used to | |
405 | * quickly find free space. | |
406 | */ | |
2d21ac55 | 407 | struct _vm_map { |
fe8ab488 | 408 | lck_rw_t lock; /* map lock */ |
1c79356b A |
409 | struct vm_map_header hdr; /* Map entry header */ |
410 | #define min_offset hdr.links.start /* start of range */ | |
411 | #define max_offset hdr.links.end /* end of range */ | |
412 | pmap_t pmap; /* Physical map */ | |
91447636 | 413 | vm_map_size_t size; /* virtual size */ |
2d21ac55 A |
414 | vm_map_size_t user_wire_limit;/* rlimit on user locked memory */ |
415 | vm_map_size_t user_wire_size; /* current size of user locked memory in this map */ | |
5ba3f43e A |
416 | #if __x86_64__ |
417 | vm_map_offset_t vmmap_high_start; | |
418 | #endif /* __x86_64__ */ | |
39037602 A |
419 | |
420 | union { | |
421 | /* | |
422 | * If map->disable_vmentry_reuse == TRUE: | |
423 | * the end address of the highest allocated vm_map_entry_t. | |
424 | */ | |
425 | vm_map_offset_t vmu1_highest_entry_end; | |
426 | /* | |
427 | * For a nested VM map: | |
428 | * the lowest address in this nested VM map that we would | |
429 | * expect to be unnested under normal operation (i.e. for | |
430 | * regular copy-on-write on DATA section). | |
431 | */ | |
432 | vm_map_offset_t vmu1_lowest_unnestable_start; | |
433 | } vmu1; | |
434 | #define highest_entry_end vmu1.vmu1_highest_entry_end | |
435 | #define lowest_unnestable_start vmu1.vmu1_lowest_unnestable_start | |
436 | ||
1c79356b A |
437 | int ref_count; /* Reference count */ |
438 | #if TASK_SWAPPER | |
439 | int res_count; /* Residence count (swap) */ | |
440 | int sw_state; /* Swap state */ | |
441 | #endif /* TASK_SWAPPER */ | |
b0d623f7 A |
442 | decl_lck_mtx_data(, s_lock) /* Lock ref, res fields */ |
443 | lck_mtx_ext_t s_lock_ext; | |
1c79356b | 444 | vm_map_entry_t hint; /* hint for quick lookups */ |
3e170ce0 A |
445 | struct vm_map_links* hole_hint; /* hint for quick hole lookups */ |
446 | union{ | |
447 | vm_map_entry_t _first_free; /* First free space hint */ | |
448 | struct vm_map_links* _holes; /* links all holes between entries */ | |
449 | }f_s; /* Union for free space data structures being used */ | |
450 | ||
451 | #define first_free f_s._first_free | |
452 | #define holes_list f_s._holes | |
453 | ||
6d2010ae A |
454 | unsigned int |
455 | /* boolean_t */ wait_for_space:1, /* Should callers wait for space? */ | |
456 | /* boolean_t */ wiring_required:1, /* All memory wired? */ | |
457 | /* boolean_t */ no_zero_fill:1, /*No zero fill absent pages */ | |
316670eb | 458 | /* boolean_t */ mapped_in_other_pmaps:1, /*has this submap been mapped in maps that use a different pmap */ |
6d2010ae A |
459 | /* boolean_t */ switch_protect:1, /* Protect map from write faults while switched */ |
460 | /* boolean_t */ disable_vmentry_reuse:1, /* All vm entries should keep using newer and higher addresses in the map */ | |
461 | /* boolean_t */ map_disallow_data_exec:1, /* Disallow execution from data pages on exec-permissive architectures */ | |
3e170ce0 | 462 | /* boolean_t */ holelistenabled:1, |
39037602 | 463 | /* boolean_t */ is_nested_map:1, |
a39ff7e2 A |
464 | /* boolean_t */ map_disallow_new_exec:1, /* Disallow new executable code */ |
465 | /* reserved */ pad:22; | |
1c79356b | 466 | unsigned int timestamp; /* Version number */ |
2d21ac55 | 467 | unsigned int color_rr; /* next color (not protected by a lock) */ |
39037602 | 468 | |
6d2010ae | 469 | boolean_t jit_entry_exists; |
1c79356b A |
470 | } ; |
471 | ||
472 | #define vm_map_to_entry(map) ((struct vm_map_entry *) &(map)->hdr.links) | |
473 | #define vm_map_first_entry(map) ((map)->hdr.links.next) | |
474 | #define vm_map_last_entry(map) ((map)->hdr.links.prev) | |
475 | ||
476 | #if TASK_SWAPPER | |
477 | /* | |
478 | * VM map swap states. There are no transition states. | |
479 | */ | |
480 | #define MAP_SW_IN 1 /* map is swapped in; residence count > 0 */ | |
481 | #define MAP_SW_OUT 2 /* map is out (res_count == 0 */ | |
482 | #endif /* TASK_SWAPPER */ | |
483 | ||
484 | /* | |
485 | * Type: vm_map_version_t [exported; contents invisible] | |
486 | * | |
487 | * Description: | |
488 | * Map versions may be used to quickly validate a previous | |
489 | * lookup operation. | |
490 | * | |
491 | * Usage note: | |
492 | * Because they are bulky objects, map versions are usually | |
493 | * passed by reference. | |
494 | * | |
495 | * Implementation: | |
496 | * Just a timestamp for the main map. | |
497 | */ | |
498 | typedef struct vm_map_version { | |
499 | unsigned int main_timestamp; | |
500 | } vm_map_version_t; | |
501 | ||
502 | /* | |
503 | * Type: vm_map_copy_t [exported; contents invisible] | |
504 | * | |
505 | * Description: | |
506 | * A map copy object represents a region of virtual memory | |
507 | * that has been copied from an address map but is still | |
508 | * in transit. | |
509 | * | |
510 | * A map copy object may only be used by a single thread | |
511 | * at a time. | |
512 | * | |
513 | * Implementation: | |
514 | * There are three formats for map copy objects. | |
515 | * The first is very similar to the main | |
516 | * address map in structure, and as a result, some | |
517 | * of the internal maintenance functions/macros can | |
518 | * be used with either address maps or map copy objects. | |
519 | * | |
520 | * The map copy object contains a header links | |
521 | * entry onto which the other entries that represent | |
522 | * the region are chained. | |
523 | * | |
91447636 A |
524 | * The second format is a single vm object. This was used |
525 | * primarily in the pageout path - but is not currently used | |
526 | * except for placeholder copy objects (see vm_map_copy_copy()). | |
527 | * | |
528 | * The third format is a kernel buffer copy object - for data | |
529 | * small enough that physical copies were the most efficient | |
3e170ce0 A |
530 | * method. This method uses a zero-sized array unioned with |
531 | * other format-specific data in the 'c_u' member. This unsized | |
532 | * array overlaps the other elements and allows us to use this | |
533 | * extra structure space for physical memory copies. On 64-bit | |
534 | * systems this saves ~64 bytes per vm_map_copy. | |
1c79356b | 535 | */ |
1c79356b A |
536 | |
537 | struct vm_map_copy { | |
538 | int type; | |
539 | #define VM_MAP_COPY_ENTRY_LIST 1 | |
540 | #define VM_MAP_COPY_OBJECT 2 | |
0b4e3aa0 | 541 | #define VM_MAP_COPY_KERNEL_BUFFER 3 |
1c79356b | 542 | vm_object_offset_t offset; |
91447636 | 543 | vm_map_size_t size; |
1c79356b | 544 | union { |
3e170ce0 A |
545 | struct vm_map_header hdr; /* ENTRY_LIST */ |
546 | vm_object_t object; /* OBJECT */ | |
547 | uint8_t kdata[0]; /* KERNEL_BUFFER */ | |
1c79356b A |
548 | } c_u; |
549 | }; | |
550 | ||
551 | ||
552 | #define cpy_hdr c_u.hdr | |
553 | ||
91447636 | 554 | #define cpy_object c_u.object |
3e170ce0 A |
555 | #define cpy_kdata c_u.kdata |
556 | #define cpy_kdata_hdr_sz (offsetof(struct vm_map_copy, c_u.kdata)) | |
1c79356b | 557 | |
39236c6e A |
558 | #define VM_MAP_COPY_PAGE_SHIFT(copy) ((copy)->cpy_hdr.page_shift) |
559 | #define VM_MAP_COPY_PAGE_SIZE(copy) (1 << VM_MAP_COPY_PAGE_SHIFT((copy))) | |
560 | #define VM_MAP_COPY_PAGE_MASK(copy) (VM_MAP_COPY_PAGE_SIZE((copy)) - 1) | |
1c79356b A |
561 | |
562 | /* | |
563 | * Useful macros for entry list copy objects | |
564 | */ | |
565 | ||
566 | #define vm_map_copy_to_entry(copy) \ | |
567 | ((struct vm_map_entry *) &(copy)->cpy_hdr.links) | |
568 | #define vm_map_copy_first_entry(copy) \ | |
569 | ((copy)->cpy_hdr.links.next) | |
570 | #define vm_map_copy_last_entry(copy) \ | |
571 | ((copy)->cpy_hdr.links.prev) | |
572 | ||
1c79356b A |
573 | /* |
574 | * Macros: vm_map_lock, etc. [internal use only] | |
575 | * Description: | |
576 | * Perform locking on the data portion of a map. | |
577 | * When multiple maps are to be locked, order by map address. | |
578 | * (See vm_map.c::vm_remap()) | |
579 | */ | |
580 | ||
581 | #define vm_map_lock_init(map) \ | |
9bccf70c | 582 | ((map)->timestamp = 0 , \ |
fe8ab488 | 583 | lck_rw_init(&(map)->lock, &vm_map_lck_grp, &vm_map_lck_rw_attr)) |
9bccf70c | 584 | |
fe8ab488 | 585 | #define vm_map_lock(map) lck_rw_lock_exclusive(&(map)->lock) |
9bccf70c | 586 | #define vm_map_unlock(map) \ |
fe8ab488 A |
587 | ((map)->timestamp++ , lck_rw_done(&(map)->lock)) |
588 | #define vm_map_lock_read(map) lck_rw_lock_shared(&(map)->lock) | |
589 | #define vm_map_unlock_read(map) lck_rw_done(&(map)->lock) | |
1c79356b | 590 | #define vm_map_lock_write_to_read(map) \ |
fe8ab488 | 591 | ((map)->timestamp++ , lck_rw_lock_exclusive_to_shared(&(map)->lock)) |
2d21ac55 A |
592 | /* lock_read_to_write() returns FALSE on failure. Macro evaluates to |
593 | * zero on success and non-zero value on failure. | |
594 | */ | |
fe8ab488 | 595 | #define vm_map_lock_read_to_write(map) (lck_rw_lock_shared_to_exclusive(&(map)->lock) != TRUE) |
1c79356b | 596 | |
5ba3f43e A |
597 | #define vm_map_try_lock(map) lck_rw_try_lock_exclusive(&(map)->lock) |
598 | #define vm_map_try_lock_read(map) lck_rw_try_lock_shared(&(map)->lock) | |
599 | ||
3e170ce0 A |
600 | #if MACH_ASSERT || DEBUG |
601 | #define vm_map_lock_assert_held(map) \ | |
602 | lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_HELD) | |
603 | #define vm_map_lock_assert_shared(map) \ | |
604 | lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_SHARED) | |
605 | #define vm_map_lock_assert_exclusive(map) \ | |
606 | lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_EXCLUSIVE) | |
607 | #define vm_map_lock_assert_notheld(map) \ | |
608 | lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_NOTHELD) | |
609 | #else /* MACH_ASSERT || DEBUG */ | |
610 | #define vm_map_lock_assert_held(map) | |
611 | #define vm_map_lock_assert_shared(map) | |
612 | #define vm_map_lock_assert_exclusive(map) | |
613 | #define vm_map_lock_assert_notheld(map) | |
614 | #endif /* MACH_ASSERT || DEBUG */ | |
615 | ||
1c79356b A |
616 | /* |
617 | * Exported procedures that operate on vm_map_t. | |
618 | */ | |
619 | ||
620 | /* Initialize the module */ | |
39236c6e | 621 | extern void vm_map_init(void); |
1c79356b | 622 | |
39236c6e | 623 | extern void vm_kernel_reserved_entry_init(void); |
7ddcb079 | 624 | |
1c79356b A |
625 | /* Allocate a range in the specified virtual address map and |
626 | * return the entry allocated for that range. */ | |
627 | extern kern_return_t vm_map_find_space( | |
91447636 A |
628 | vm_map_t map, |
629 | vm_map_address_t *address, /* OUT */ | |
630 | vm_map_size_t size, | |
631 | vm_map_offset_t mask, | |
0c530ab8 | 632 | int flags, |
5ba3f43e A |
633 | vm_map_kernel_flags_t vmk_flags, |
634 | vm_tag_t tag, | |
91447636 | 635 | vm_map_entry_t *o_entry); /* OUT */ |
1c79356b | 636 | |
e2d2fc5c A |
637 | extern void vm_map_clip_start( |
638 | vm_map_t map, | |
639 | vm_map_entry_t entry, | |
640 | vm_map_offset_t endaddr); | |
641 | extern void vm_map_clip_end( | |
642 | vm_map_t map, | |
643 | vm_map_entry_t entry, | |
644 | vm_map_offset_t endaddr); | |
e2d2fc5c A |
645 | extern boolean_t vm_map_entry_should_cow_for_true_share( |
646 | vm_map_entry_t entry); | |
e2d2fc5c | 647 | |
1c79356b A |
648 | /* Lookup map entry containing or the specified address in the given map */ |
649 | extern boolean_t vm_map_lookup_entry( | |
91447636 A |
650 | vm_map_t map, |
651 | vm_map_address_t address, | |
652 | vm_map_entry_t *entry); /* OUT */ | |
1c79356b | 653 | |
39236c6e A |
654 | extern void vm_map_copy_remap( |
655 | vm_map_t map, | |
656 | vm_map_entry_t where, | |
657 | vm_map_copy_t copy, | |
658 | vm_map_offset_t adjustment, | |
659 | vm_prot_t cur_prot, | |
660 | vm_prot_t max_prot, | |
661 | vm_inherit_t inheritance); | |
662 | ||
1c79356b A |
663 | /* Find the VM object, offset, and protection for a given virtual address |
664 | * in the specified map, assuming a page fault of the type specified. */ | |
665 | extern kern_return_t vm_map_lookup_locked( | |
91447636 A |
666 | vm_map_t *var_map, /* IN/OUT */ |
667 | vm_map_address_t vaddr, | |
668 | vm_prot_t fault_type, | |
2d21ac55 | 669 | int object_lock_type, |
91447636 A |
670 | vm_map_version_t *out_version, /* OUT */ |
671 | vm_object_t *object, /* OUT */ | |
672 | vm_object_offset_t *offset, /* OUT */ | |
673 | vm_prot_t *out_prot, /* OUT */ | |
674 | boolean_t *wired, /* OUT */ | |
2d21ac55 | 675 | vm_object_fault_info_t fault_info, /* OUT */ |
91447636 | 676 | vm_map_t *real_map); /* OUT */ |
1c79356b A |
677 | |
678 | /* Verifies that the map has not changed since the given version. */ | |
679 | extern boolean_t vm_map_verify( | |
91447636 A |
680 | vm_map_t map, |
681 | vm_map_version_t *version); /* REF */ | |
1c79356b A |
682 | |
683 | extern vm_map_entry_t vm_map_entry_insert( | |
684 | vm_map_t map, | |
685 | vm_map_entry_t insp_entry, | |
91447636 A |
686 | vm_map_offset_t start, |
687 | vm_map_offset_t end, | |
1c79356b A |
688 | vm_object_t object, |
689 | vm_object_offset_t offset, | |
690 | boolean_t needs_copy, | |
691 | boolean_t is_shared, | |
692 | boolean_t in_transition, | |
693 | vm_prot_t cur_protection, | |
694 | vm_prot_t max_protection, | |
695 | vm_behavior_t behavior, | |
696 | vm_inherit_t inheritance, | |
2d21ac55 | 697 | unsigned wired_count, |
b0d623f7 A |
698 | boolean_t no_cache, |
699 | boolean_t permanent, | |
39236c6e | 700 | unsigned int superpage_size, |
fe8ab488 | 701 | boolean_t clear_map_aligned, |
5ba3f43e A |
702 | boolean_t is_submap, |
703 | boolean_t used_for_jit, | |
704 | int alias); | |
1c79356b | 705 | |
1c79356b A |
706 | |
707 | /* | |
708 | * Functions implemented as macros | |
709 | */ | |
91447636 | 710 | #define vm_map_min(map) ((map)->min_offset) |
1c79356b A |
711 | /* Lowest valid address in |
712 | * a map */ | |
713 | ||
91447636 | 714 | #define vm_map_max(map) ((map)->max_offset) |
1c79356b A |
715 | /* Highest valid address */ |
716 | ||
717 | #define vm_map_pmap(map) ((map)->pmap) | |
718 | /* Physical map associated | |
719 | * with this address map */ | |
720 | ||
1c79356b A |
721 | /* |
722 | * Macros/functions for map residence counts and swapin/out of vm maps | |
723 | */ | |
724 | #if TASK_SWAPPER | |
725 | ||
726 | #if MACH_ASSERT | |
727 | /* Gain a reference to an existing map */ | |
728 | extern void vm_map_reference( | |
729 | vm_map_t map); | |
730 | /* Lose a residence count */ | |
731 | extern void vm_map_res_deallocate( | |
732 | vm_map_t map); | |
733 | /* Gain a residence count on a map */ | |
734 | extern void vm_map_res_reference( | |
735 | vm_map_t map); | |
736 | /* Gain reference & residence counts to possibly swapped-out map */ | |
737 | extern void vm_map_reference_swap( | |
738 | vm_map_t map); | |
739 | ||
740 | #else /* MACH_ASSERT */ | |
741 | ||
91447636 | 742 | #define vm_map_reference(map) \ |
1c79356b | 743 | MACRO_BEGIN \ |
91447636 | 744 | vm_map_t Map = (map); \ |
1c79356b | 745 | if (Map) { \ |
b0d623f7 | 746 | lck_mtx_lock(&Map->s_lock); \ |
1c79356b A |
747 | Map->res_count++; \ |
748 | Map->ref_count++; \ | |
b0d623f7 | 749 | lck_mtx_unlock(&Map->s_lock); \ |
1c79356b A |
750 | } \ |
751 | MACRO_END | |
752 | ||
753 | #define vm_map_res_reference(map) \ | |
754 | MACRO_BEGIN \ | |
91447636 | 755 | vm_map_t Lmap = (map); \ |
1c79356b | 756 | if (Lmap->res_count == 0) { \ |
b0d623f7 | 757 | lck_mtx_unlock(&Lmap->s_lock);\ |
1c79356b A |
758 | vm_map_lock(Lmap); \ |
759 | vm_map_swapin(Lmap); \ | |
b0d623f7 | 760 | lck_mtx_lock(&Lmap->s_lock); \ |
1c79356b A |
761 | ++Lmap->res_count; \ |
762 | vm_map_unlock(Lmap); \ | |
763 | } else \ | |
764 | ++Lmap->res_count; \ | |
765 | MACRO_END | |
766 | ||
767 | #define vm_map_res_deallocate(map) \ | |
768 | MACRO_BEGIN \ | |
91447636 A |
769 | vm_map_t Map = (map); \ |
770 | if (--Map->res_count == 0) { \ | |
b0d623f7 | 771 | lck_mtx_unlock(&Map->s_lock); \ |
1c79356b A |
772 | vm_map_lock(Map); \ |
773 | vm_map_swapout(Map); \ | |
774 | vm_map_unlock(Map); \ | |
b0d623f7 | 775 | lck_mtx_lock(&Map->s_lock); \ |
1c79356b A |
776 | } \ |
777 | MACRO_END | |
778 | ||
779 | #define vm_map_reference_swap(map) \ | |
780 | MACRO_BEGIN \ | |
781 | vm_map_t Map = (map); \ | |
b0d623f7 | 782 | lck_mtx_lock(&Map->s_lock); \ |
1c79356b A |
783 | ++Map->ref_count; \ |
784 | vm_map_res_reference(Map); \ | |
b0d623f7 | 785 | lck_mtx_unlock(&Map->s_lock); \ |
1c79356b A |
786 | MACRO_END |
787 | #endif /* MACH_ASSERT */ | |
788 | ||
789 | extern void vm_map_swapin( | |
790 | vm_map_t map); | |
791 | ||
792 | extern void vm_map_swapout( | |
793 | vm_map_t map); | |
794 | ||
795 | #else /* TASK_SWAPPER */ | |
796 | ||
797 | #define vm_map_reference(map) \ | |
798 | MACRO_BEGIN \ | |
799 | vm_map_t Map = (map); \ | |
800 | if (Map) { \ | |
b0d623f7 | 801 | lck_mtx_lock(&Map->s_lock); \ |
1c79356b | 802 | Map->ref_count++; \ |
b0d623f7 | 803 | lck_mtx_unlock(&Map->s_lock); \ |
1c79356b A |
804 | } \ |
805 | MACRO_END | |
806 | ||
807 | #define vm_map_reference_swap(map) vm_map_reference(map) | |
808 | #define vm_map_res_reference(map) | |
809 | #define vm_map_res_deallocate(map) | |
810 | ||
811 | #endif /* TASK_SWAPPER */ | |
812 | ||
813 | /* | |
814 | * Submap object. Must be used to create memory to be put | |
815 | * in a submap by vm_map_submap. | |
816 | */ | |
817 | extern vm_object_t vm_submap_object; | |
818 | ||
819 | /* | |
820 | * Wait and wakeup macros for in_transition map entries. | |
821 | */ | |
822 | #define vm_map_entry_wait(map, interruptible) \ | |
9bccf70c | 823 | ((map)->timestamp++ , \ |
fe8ab488 A |
824 | lck_rw_sleep(&(map)->lock, LCK_SLEEP_EXCLUSIVE|LCK_SLEEP_PROMOTED_PRI, \ |
825 | (event_t)&(map)->hdr, interruptible)) | |
1c79356b | 826 | |
1c79356b | 827 | |
91447636 A |
828 | #define vm_map_entry_wakeup(map) \ |
829 | thread_wakeup((event_t)(&(map)->hdr)) | |
1c79356b A |
830 | |
831 | ||
91447636 | 832 | #define vm_map_ref_fast(map) \ |
1c79356b | 833 | MACRO_BEGIN \ |
b0d623f7 | 834 | lck_mtx_lock(&map->s_lock); \ |
1c79356b A |
835 | map->ref_count++; \ |
836 | vm_map_res_reference(map); \ | |
b0d623f7 | 837 | lck_mtx_unlock(&map->s_lock); \ |
1c79356b A |
838 | MACRO_END |
839 | ||
91447636 | 840 | #define vm_map_dealloc_fast(map) \ |
1c79356b | 841 | MACRO_BEGIN \ |
39037602 | 842 | int c; \ |
1c79356b | 843 | \ |
b0d623f7 | 844 | lck_mtx_lock(&map->s_lock); \ |
91447636 | 845 | c = --map->ref_count; \ |
1c79356b A |
846 | if (c > 0) \ |
847 | vm_map_res_deallocate(map); \ | |
b0d623f7 | 848 | lck_mtx_unlock(&map->s_lock); \ |
1c79356b A |
849 | if (c == 0) \ |
850 | vm_map_destroy(map); \ | |
851 | MACRO_END | |
852 | ||
853 | ||
854 | /* simplify map entries */ | |
5353443c A |
855 | extern void vm_map_simplify_entry( |
856 | vm_map_t map, | |
857 | vm_map_entry_t this_entry); | |
1c79356b | 858 | extern void vm_map_simplify( |
91447636 A |
859 | vm_map_t map, |
860 | vm_map_offset_t start); | |
1c79356b A |
861 | |
862 | /* Move the information in a map copy object to a new map copy object */ | |
863 | extern vm_map_copy_t vm_map_copy_copy( | |
91447636 | 864 | vm_map_copy_t copy); |
1c79356b | 865 | |
1c79356b A |
866 | /* Create a copy object from an object. */ |
867 | extern kern_return_t vm_map_copyin_object( | |
868 | vm_object_t object, | |
869 | vm_object_offset_t offset, | |
870 | vm_object_size_t size, | |
871 | vm_map_copy_t *copy_result); /* OUT */ | |
872 | ||
316670eb A |
873 | extern kern_return_t vm_map_random_address_for_size( |
874 | vm_map_t map, | |
875 | vm_map_offset_t *address, | |
876 | vm_map_size_t size); | |
877 | ||
1c79356b A |
878 | /* Enter a mapping */ |
879 | extern kern_return_t vm_map_enter( | |
880 | vm_map_t map, | |
91447636 A |
881 | vm_map_offset_t *address, |
882 | vm_map_size_t size, | |
883 | vm_map_offset_t mask, | |
1c79356b | 884 | int flags, |
5ba3f43e A |
885 | vm_map_kernel_flags_t vmk_flags, |
886 | vm_tag_t tag, | |
1c79356b A |
887 | vm_object_t object, |
888 | vm_object_offset_t offset, | |
889 | boolean_t needs_copy, | |
890 | vm_prot_t cur_protection, | |
891 | vm_prot_t max_protection, | |
892 | vm_inherit_t inheritance); | |
893 | ||
5ba3f43e A |
894 | #if __arm64__ |
895 | extern kern_return_t vm_map_enter_fourk( | |
896 | vm_map_t map, | |
897 | vm_map_offset_t *address, | |
898 | vm_map_size_t size, | |
899 | vm_map_offset_t mask, | |
900 | int flags, | |
901 | vm_map_kernel_flags_t vmk_flags, | |
902 | vm_tag_t tag, | |
903 | vm_object_t object, | |
904 | vm_object_offset_t offset, | |
905 | boolean_t needs_copy, | |
906 | vm_prot_t cur_protection, | |
907 | vm_prot_t max_protection, | |
908 | vm_inherit_t inheritance); | |
909 | #endif /* __arm64__ */ | |
3e170ce0 | 910 | |
91447636 A |
911 | /* XXX should go away - replaced with regular enter of contig object */ |
912 | extern kern_return_t vm_map_enter_cpm( | |
913 | vm_map_t map, | |
914 | vm_map_address_t *addr, | |
915 | vm_map_size_t size, | |
916 | int flags); | |
917 | ||
918 | extern kern_return_t vm_map_remap( | |
919 | vm_map_t target_map, | |
920 | vm_map_offset_t *address, | |
921 | vm_map_size_t size, | |
922 | vm_map_offset_t mask, | |
060df5ea | 923 | int flags, |
5ba3f43e A |
924 | vm_map_kernel_flags_t vmk_flags, |
925 | vm_tag_t tag, | |
91447636 A |
926 | vm_map_t src_map, |
927 | vm_map_offset_t memory_address, | |
928 | boolean_t copy, | |
929 | vm_prot_t *cur_protection, | |
930 | vm_prot_t *max_protection, | |
931 | vm_inherit_t inheritance); | |
932 | ||
933 | ||
934 | /* | |
935 | * Read and write from a kernel buffer to a specified map. | |
936 | */ | |
1c79356b | 937 | extern kern_return_t vm_map_write_user( |
91447636 A |
938 | vm_map_t map, |
939 | void *src_p, | |
940 | vm_map_offset_t dst_addr, | |
941 | vm_size_t size); | |
1c79356b A |
942 | |
943 | extern kern_return_t vm_map_read_user( | |
91447636 A |
944 | vm_map_t map, |
945 | vm_map_offset_t src_addr, | |
946 | void *dst_p, | |
947 | vm_size_t size); | |
1c79356b A |
948 | |
949 | /* Create a new task map using an existing task map as a template. */ | |
950 | extern vm_map_t vm_map_fork( | |
316670eb | 951 | ledger_t ledger, |
39037602 A |
952 | vm_map_t old_map, |
953 | int options); | |
954 | #define VM_MAP_FORK_SHARE_IF_INHERIT_NONE 0x00000001 | |
955 | #define VM_MAP_FORK_PRESERVE_PURGEABLE 0x00000002 | |
1c79356b | 956 | |
9bccf70c A |
957 | /* Change inheritance */ |
958 | extern kern_return_t vm_map_inherit( | |
91447636 A |
959 | vm_map_t map, |
960 | vm_map_offset_t start, | |
961 | vm_map_offset_t end, | |
962 | vm_inherit_t new_inheritance); | |
1c79356b | 963 | |
9bccf70c A |
964 | /* Add or remove machine-dependent attributes from map regions */ |
965 | extern kern_return_t vm_map_machine_attribute( | |
91447636 A |
966 | vm_map_t map, |
967 | vm_map_offset_t start, | |
968 | vm_map_offset_t end, | |
9bccf70c A |
969 | vm_machine_attribute_t attribute, |
970 | vm_machine_attribute_val_t* value); /* IN/OUT */ | |
91447636 A |
971 | |
972 | extern kern_return_t vm_map_msync( | |
973 | vm_map_t map, | |
974 | vm_map_address_t address, | |
975 | vm_map_size_t size, | |
976 | vm_sync_t sync_flags); | |
977 | ||
9bccf70c A |
978 | /* Set paging behavior */ |
979 | extern kern_return_t vm_map_behavior_set( | |
91447636 A |
980 | vm_map_t map, |
981 | vm_map_offset_t start, | |
982 | vm_map_offset_t end, | |
983 | vm_behavior_t new_behavior); | |
984 | ||
91447636 A |
985 | extern kern_return_t vm_map_region( |
986 | vm_map_t map, | |
987 | vm_map_offset_t *address, | |
988 | vm_map_size_t *size, | |
989 | vm_region_flavor_t flavor, | |
990 | vm_region_info_t info, | |
991 | mach_msg_type_number_t *count, | |
992 | mach_port_t *object_name); | |
993 | ||
994 | extern kern_return_t vm_map_region_recurse_64( | |
995 | vm_map_t map, | |
996 | vm_map_offset_t *address, | |
997 | vm_map_size_t *size, | |
998 | natural_t *nesting_depth, | |
999 | vm_region_submap_info_64_t info, | |
1000 | mach_msg_type_number_t *count); | |
1001 | ||
b0d623f7 | 1002 | extern kern_return_t vm_map_page_query_internal( |
91447636 A |
1003 | vm_map_t map, |
1004 | vm_map_offset_t offset, | |
1005 | int *disposition, | |
1006 | int *ref_count); | |
9bccf70c | 1007 | |
39236c6e A |
1008 | extern kern_return_t vm_map_query_volatile( |
1009 | vm_map_t map, | |
1010 | mach_vm_size_t *volatile_virtual_size_p, | |
1011 | mach_vm_size_t *volatile_resident_size_p, | |
3e170ce0 A |
1012 | mach_vm_size_t *volatile_compressed_size_p, |
1013 | mach_vm_size_t *volatile_pmap_size_p, | |
1014 | mach_vm_size_t *volatile_compressed_pmap_size_p); | |
b0d623f7 | 1015 | |
9bccf70c | 1016 | extern kern_return_t vm_map_submap( |
91447636 A |
1017 | vm_map_t map, |
1018 | vm_map_offset_t start, | |
1019 | vm_map_offset_t end, | |
1020 | vm_map_t submap, | |
1021 | vm_map_offset_t offset, | |
1022 | boolean_t use_pmap); | |
1023 | ||
1024 | extern void vm_map_submap_pmap_clean( | |
1025 | vm_map_t map, | |
1026 | vm_map_offset_t start, | |
1027 | vm_map_offset_t end, | |
1028 | vm_map_t sub_map, | |
1029 | vm_map_offset_t offset); | |
1030 | ||
1031 | /* Convert from a map entry port to a map */ | |
1032 | extern vm_map_t convert_port_entry_to_map( | |
1033 | ipc_port_t port); | |
1034 | ||
1035 | /* Convert from a port to a vm_object */ | |
1036 | extern vm_object_t convert_port_entry_to_object( | |
1037 | ipc_port_t port); | |
9bccf70c A |
1038 | |
1039 | ||
6d2010ae A |
1040 | extern kern_return_t vm_map_set_cache_attr( |
1041 | vm_map_t map, | |
1042 | vm_map_offset_t va); | |
1043 | ||
1044 | ||
2d21ac55 A |
1045 | /* definitions related to overriding the NX behavior */ |
1046 | ||
1047 | #define VM_ABI_32 0x1 | |
1048 | #define VM_ABI_64 0x2 | |
1049 | ||
1050 | extern int override_nx(vm_map_t map, uint32_t user_tag); | |
1051 | ||
a39ff7e2 A |
1052 | extern void vm_map_region_top_walk( |
1053 | vm_map_entry_t entry, | |
1054 | vm_region_top_info_t top); | |
1055 | extern void vm_map_region_walk( | |
1056 | vm_map_t map, | |
1057 | vm_map_offset_t va, | |
1058 | vm_map_entry_t entry, | |
1059 | vm_object_offset_t offset, | |
1060 | vm_object_size_t range, | |
1061 | vm_region_extended_info_t extended, | |
1062 | boolean_t look_for_pages, | |
1063 | mach_msg_type_number_t count); | |
1064 | ||
9bccf70c A |
1065 | #endif /* MACH_KERNEL_PRIVATE */ |
1066 | ||
91447636 A |
1067 | __BEGIN_DECLS |
1068 | ||
9bccf70c A |
1069 | /* Create an empty map */ |
1070 | extern vm_map_t vm_map_create( | |
91447636 A |
1071 | pmap_t pmap, |
1072 | vm_map_offset_t min_off, | |
1073 | vm_map_offset_t max_off, | |
1074 | boolean_t pageable); | |
9bccf70c | 1075 | |
3e170ce0 A |
1076 | extern void vm_map_disable_hole_optimization(vm_map_t map); |
1077 | ||
9bccf70c A |
1078 | /* Get rid of a map */ |
1079 | extern void vm_map_destroy( | |
2d21ac55 A |
1080 | vm_map_t map, |
1081 | int flags); | |
1082 | ||
9bccf70c A |
1083 | /* Lose a reference */ |
1084 | extern void vm_map_deallocate( | |
91447636 A |
1085 | vm_map_t map); |
1086 | ||
1087 | extern vm_map_t vm_map_switch( | |
1088 | vm_map_t map); | |
9bccf70c A |
1089 | |
1090 | /* Change protection */ | |
1091 | extern kern_return_t vm_map_protect( | |
91447636 A |
1092 | vm_map_t map, |
1093 | vm_map_offset_t start, | |
1094 | vm_map_offset_t end, | |
1095 | vm_prot_t new_prot, | |
1096 | boolean_t set_max); | |
1097 | ||
1098 | /* Check protection */ | |
1099 | extern boolean_t vm_map_check_protection( | |
1100 | vm_map_t map, | |
1101 | vm_map_offset_t start, | |
1102 | vm_map_offset_t end, | |
1103 | vm_prot_t protection); | |
1c79356b A |
1104 | |
1105 | /* wire down a region */ | |
5ba3f43e A |
1106 | |
1107 | #ifdef XNU_KERNEL_PRIVATE | |
1108 | ||
1109 | extern kern_return_t vm_map_wire_kernel( | |
1110 | vm_map_t map, | |
1111 | vm_map_offset_t start, | |
1112 | vm_map_offset_t end, | |
1113 | vm_prot_t access_type, | |
1114 | vm_tag_t tag, | |
1115 | boolean_t user_wire); | |
1116 | ||
1117 | extern kern_return_t vm_map_wire_and_extract_kernel( | |
1118 | vm_map_t map, | |
1119 | vm_map_offset_t start, | |
1120 | vm_prot_t access_type, | |
1121 | vm_tag_t tag, | |
1122 | boolean_t user_wire, | |
1123 | ppnum_t *physpage_p); | |
1124 | ||
1125 | /* kext exported versions */ | |
1126 | ||
1127 | extern kern_return_t vm_map_wire_external( | |
1128 | vm_map_t map, | |
1129 | vm_map_offset_t start, | |
1130 | vm_map_offset_t end, | |
1131 | vm_prot_t access_type, | |
1132 | boolean_t user_wire); | |
1133 | ||
1134 | extern kern_return_t vm_map_wire_and_extract_external( | |
1135 | vm_map_t map, | |
1136 | vm_map_offset_t start, | |
1137 | vm_prot_t access_type, | |
1138 | boolean_t user_wire, | |
1139 | ppnum_t *physpage_p); | |
1140 | ||
1141 | #else /* XNU_KERNEL_PRIVATE */ | |
1142 | ||
1c79356b | 1143 | extern kern_return_t vm_map_wire( |
91447636 A |
1144 | vm_map_t map, |
1145 | vm_map_offset_t start, | |
1146 | vm_map_offset_t end, | |
1147 | vm_prot_t access_type, | |
1148 | boolean_t user_wire); | |
1c79356b | 1149 | |
fe8ab488 A |
1150 | extern kern_return_t vm_map_wire_and_extract( |
1151 | vm_map_t map, | |
1152 | vm_map_offset_t start, | |
1153 | vm_prot_t access_type, | |
1154 | boolean_t user_wire, | |
1155 | ppnum_t *physpage_p); | |
1156 | ||
5ba3f43e A |
1157 | #endif /* !XNU_KERNEL_PRIVATE */ |
1158 | ||
1c79356b A |
1159 | /* unwire a region */ |
1160 | extern kern_return_t vm_map_unwire( | |
91447636 A |
1161 | vm_map_t map, |
1162 | vm_map_offset_t start, | |
1163 | vm_map_offset_t end, | |
1164 | boolean_t user_wire); | |
1c79356b | 1165 | |
5ba3f43e A |
1166 | #ifdef XNU_KERNEL_PRIVATE |
1167 | ||
2d21ac55 A |
1168 | /* Enter a mapping of a memory object */ |
1169 | extern kern_return_t vm_map_enter_mem_object( | |
1170 | vm_map_t map, | |
1171 | vm_map_offset_t *address, | |
1172 | vm_map_size_t size, | |
1173 | vm_map_offset_t mask, | |
1174 | int flags, | |
5ba3f43e A |
1175 | vm_map_kernel_flags_t vmk_flags, |
1176 | vm_tag_t tag, | |
2d21ac55 A |
1177 | ipc_port_t port, |
1178 | vm_object_offset_t offset, | |
1179 | boolean_t needs_copy, | |
1180 | vm_prot_t cur_protection, | |
1181 | vm_prot_t max_protection, | |
1182 | vm_inherit_t inheritance); | |
1183 | ||
fe8ab488 A |
1184 | /* Enter a mapping of a memory object */ |
1185 | extern kern_return_t vm_map_enter_mem_object_prefault( | |
1186 | vm_map_t map, | |
1187 | vm_map_offset_t *address, | |
1188 | vm_map_size_t size, | |
1189 | vm_map_offset_t mask, | |
1190 | int flags, | |
5ba3f43e A |
1191 | vm_map_kernel_flags_t vmk_flags, |
1192 | vm_tag_t tag, | |
fe8ab488 A |
1193 | ipc_port_t port, |
1194 | vm_object_offset_t offset, | |
1195 | vm_prot_t cur_protection, | |
1196 | vm_prot_t max_protection, | |
1197 | upl_page_list_ptr_t page_list, | |
1198 | unsigned int page_list_count); | |
1199 | ||
b0d623f7 A |
1200 | /* Enter a mapping of a memory object */ |
1201 | extern kern_return_t vm_map_enter_mem_object_control( | |
1202 | vm_map_t map, | |
1203 | vm_map_offset_t *address, | |
1204 | vm_map_size_t size, | |
1205 | vm_map_offset_t mask, | |
1206 | int flags, | |
5ba3f43e A |
1207 | vm_map_kernel_flags_t vmk_flags, |
1208 | vm_tag_t tag, | |
b0d623f7 A |
1209 | memory_object_control_t control, |
1210 | vm_object_offset_t offset, | |
1211 | boolean_t needs_copy, | |
1212 | vm_prot_t cur_protection, | |
1213 | vm_prot_t max_protection, | |
1214 | vm_inherit_t inheritance); | |
1215 | ||
5ba3f43e A |
1216 | #endif /* !XNU_KERNEL_PRIVATE */ |
1217 | ||
1c79356b A |
1218 | /* Deallocate a region */ |
1219 | extern kern_return_t vm_map_remove( | |
91447636 A |
1220 | vm_map_t map, |
1221 | vm_map_offset_t start, | |
1222 | vm_map_offset_t end, | |
1223 | boolean_t flags); | |
1224 | ||
39037602 A |
1225 | /* Deallocate a region when the map is already locked */ |
1226 | extern kern_return_t vm_map_remove_locked( | |
1227 | vm_map_t map, | |
1228 | vm_map_offset_t start, | |
1229 | vm_map_offset_t end, | |
1230 | boolean_t flags); | |
1231 | ||
91447636 A |
1232 | /* Discard a copy without using it */ |
1233 | extern void vm_map_copy_discard( | |
1234 | vm_map_copy_t copy); | |
1235 | ||
1236 | /* Overwrite existing memory with a copy */ | |
1237 | extern kern_return_t vm_map_copy_overwrite( | |
1238 | vm_map_t dst_map, | |
1239 | vm_map_address_t dst_addr, | |
1240 | vm_map_copy_t copy, | |
b0d623f7 | 1241 | boolean_t interruptible); |
1c79356b | 1242 | |
2dced7af A |
1243 | /* returns TRUE if size of vm_map_copy == size parameter FALSE otherwise */ |
1244 | extern boolean_t vm_map_copy_validate_size( | |
1245 | vm_map_t dst_map, | |
1246 | vm_map_copy_t copy, | |
39037602 | 1247 | vm_map_size_t *size); |
2dced7af | 1248 | |
1c79356b A |
1249 | /* Place a copy into a map */ |
1250 | extern kern_return_t vm_map_copyout( | |
91447636 A |
1251 | vm_map_t dst_map, |
1252 | vm_map_address_t *dst_addr, /* OUT */ | |
1253 | vm_map_copy_t copy); | |
1c79356b | 1254 | |
39037602 A |
1255 | extern kern_return_t vm_map_copyout_size( |
1256 | vm_map_t dst_map, | |
1257 | vm_map_address_t *dst_addr, /* OUT */ | |
1258 | vm_map_copy_t copy, | |
1259 | vm_map_size_t copy_size); | |
1260 | ||
39236c6e A |
1261 | extern kern_return_t vm_map_copyout_internal( |
1262 | vm_map_t dst_map, | |
1263 | vm_map_address_t *dst_addr, /* OUT */ | |
1264 | vm_map_copy_t copy, | |
39037602 | 1265 | vm_map_size_t copy_size, |
39236c6e A |
1266 | boolean_t consume_on_success, |
1267 | vm_prot_t cur_protection, | |
1268 | vm_prot_t max_protection, | |
1269 | vm_inherit_t inheritance); | |
1270 | ||
2d21ac55 A |
1271 | extern kern_return_t vm_map_copyin( |
1272 | vm_map_t src_map, | |
1273 | vm_map_address_t src_addr, | |
1274 | vm_map_size_t len, | |
1275 | boolean_t src_destroy, | |
1276 | vm_map_copy_t *copy_result); /* OUT */ | |
1277 | ||
1c79356b | 1278 | extern kern_return_t vm_map_copyin_common( |
91447636 A |
1279 | vm_map_t src_map, |
1280 | vm_map_address_t src_addr, | |
1281 | vm_map_size_t len, | |
1282 | boolean_t src_destroy, | |
1283 | boolean_t src_volatile, | |
1284 | vm_map_copy_t *copy_result, /* OUT */ | |
1285 | boolean_t use_maxprot); | |
55e303ae | 1286 | |
4bd07ac2 A |
1287 | #define VM_MAP_COPYIN_SRC_DESTROY 0x00000001 |
1288 | #define VM_MAP_COPYIN_USE_MAXPROT 0x00000002 | |
1289 | #define VM_MAP_COPYIN_ENTRY_LIST 0x00000004 | |
39037602 A |
1290 | #define VM_MAP_COPYIN_PRESERVE_PURGEABLE 0x00000008 |
1291 | #define VM_MAP_COPYIN_ALL_FLAGS 0x0000000F | |
4bd07ac2 A |
1292 | extern kern_return_t vm_map_copyin_internal( |
1293 | vm_map_t src_map, | |
1294 | vm_map_address_t src_addr, | |
1295 | vm_map_size_t len, | |
1296 | int flags, | |
1297 | vm_map_copy_t *copy_result); /* OUT */ | |
1298 | ||
39236c6e A |
1299 | extern kern_return_t vm_map_copy_extract( |
1300 | vm_map_t src_map, | |
1301 | vm_map_address_t src_addr, | |
1302 | vm_map_size_t len, | |
1303 | vm_map_copy_t *copy_result, /* OUT */ | |
1304 | vm_prot_t *cur_prot, /* OUT */ | |
1305 | vm_prot_t *max_prot); | |
1306 | ||
1307 | ||
0c530ab8 A |
1308 | extern void vm_map_disable_NX( |
1309 | vm_map_t map); | |
1310 | ||
6d2010ae A |
1311 | extern void vm_map_disallow_data_exec( |
1312 | vm_map_t map); | |
1313 | ||
0c530ab8 A |
1314 | extern void vm_map_set_64bit( |
1315 | vm_map_t map); | |
1316 | ||
1317 | extern void vm_map_set_32bit( | |
1318 | vm_map_t map); | |
1319 | ||
813fb2f6 A |
1320 | extern void vm_map_set_jumbo( |
1321 | vm_map_t map); | |
1322 | ||
316670eb A |
1323 | extern boolean_t vm_map_has_hard_pagezero( |
1324 | vm_map_t map, | |
1325 | vm_map_offset_t pagezero_size); | |
39037602 | 1326 | extern void vm_commit_pagezero_status(vm_map_t tmap); |
316670eb | 1327 | |
5ba3f43e A |
1328 | #ifdef __arm__ |
1329 | static inline boolean_t vm_map_is_64bit(__unused vm_map_t map) { return 0; } | |
1330 | #else | |
2d21ac55 A |
1331 | extern boolean_t vm_map_is_64bit( |
1332 | vm_map_t map); | |
5ba3f43e | 1333 | #endif |
2d21ac55 | 1334 | |
0c530ab8 | 1335 | |
316670eb A |
1336 | extern kern_return_t vm_map_raise_max_offset( |
1337 | vm_map_t map, | |
1338 | vm_map_offset_t new_max_offset); | |
1339 | ||
0c530ab8 A |
1340 | extern kern_return_t vm_map_raise_min_offset( |
1341 | vm_map_t map, | |
1342 | vm_map_offset_t new_min_offset); | |
5ba3f43e A |
1343 | #if __x86_64__ |
1344 | extern void vm_map_set_high_start( | |
1345 | vm_map_t map, | |
1346 | vm_map_offset_t high_start); | |
1347 | #endif /* __x86_64__ */ | |
0c530ab8 A |
1348 | |
1349 | extern vm_map_offset_t vm_compute_max_offset( | |
3e170ce0 | 1350 | boolean_t is64); |
0c530ab8 | 1351 | |
5ba3f43e A |
1352 | extern void vm_map_get_max_aslr_slide_section( |
1353 | vm_map_t map, | |
1354 | int64_t *max_sections, | |
1355 | int64_t *section_size); | |
1356 | ||
39236c6e A |
1357 | extern uint64_t vm_map_get_max_aslr_slide_pages( |
1358 | vm_map_t map); | |
5ba3f43e A |
1359 | |
1360 | extern uint64_t vm_map_get_max_loader_aslr_slide_pages( | |
1361 | vm_map_t map); | |
1362 | ||
2d21ac55 A |
1363 | extern void vm_map_set_user_wire_limit( |
1364 | vm_map_t map, | |
1365 | vm_size_t limit); | |
1366 | ||
b0d623f7 | 1367 | extern void vm_map_switch_protect( |
5ba3f43e | 1368 | vm_map_t map, |
b0d623f7 A |
1369 | boolean_t val); |
1370 | ||
39236c6e A |
1371 | extern void vm_map_iokit_mapped_region( |
1372 | vm_map_t map, | |
1373 | vm_size_t bytes); | |
1374 | ||
1375 | extern void vm_map_iokit_unmapped_region( | |
1376 | vm_map_t map, | |
1377 | vm_size_t bytes); | |
1378 | ||
1379 | ||
6d2010ae A |
1380 | extern boolean_t first_free_is_valid(vm_map_t); |
1381 | ||
39236c6e A |
1382 | extern int vm_map_page_shift( |
1383 | vm_map_t map); | |
1384 | ||
3e170ce0 | 1385 | extern vm_map_offset_t vm_map_page_mask( |
39236c6e A |
1386 | vm_map_t map); |
1387 | ||
1388 | extern int vm_map_page_size( | |
1389 | vm_map_t map); | |
1390 | ||
1391 | extern vm_map_offset_t vm_map_round_page_mask( | |
1392 | vm_map_offset_t offset, | |
1393 | vm_map_offset_t mask); | |
1394 | ||
1395 | extern vm_map_offset_t vm_map_trunc_page_mask( | |
1396 | vm_map_offset_t offset, | |
1397 | vm_map_offset_t mask); | |
1398 | ||
3e170ce0 A |
1399 | extern boolean_t vm_map_page_aligned( |
1400 | vm_map_offset_t offset, | |
1401 | vm_map_offset_t mask); | |
1402 | ||
b0d623f7 A |
1403 | #ifdef XNU_KERNEL_PRIVATE |
1404 | extern kern_return_t vm_map_page_info( | |
1405 | vm_map_t map, | |
1406 | vm_map_offset_t offset, | |
1407 | vm_page_info_flavor_t flavor, | |
1408 | vm_page_info_t info, | |
1409 | mach_msg_type_number_t *count); | |
5ba3f43e A |
1410 | extern kern_return_t vm_map_page_range_info_internal( |
1411 | vm_map_t map, | |
1412 | vm_map_offset_t start_offset, | |
1413 | vm_map_offset_t end_offset, | |
1414 | vm_page_info_flavor_t flavor, | |
1415 | vm_page_info_t info, | |
1416 | mach_msg_type_number_t *count); | |
b0d623f7 A |
1417 | #endif /* XNU_KERNEL_PRIVATE */ |
1418 | ||
593a1d5f | 1419 | |
2d21ac55 A |
1420 | #ifdef MACH_KERNEL_PRIVATE |
1421 | ||
1c79356b A |
1422 | /* |
1423 | * Macros to invoke vm_map_copyin_common. vm_map_copyin is the | |
1424 | * usual form; it handles a copyin based on the current protection | |
1425 | * (current protection == VM_PROT_NONE) is a failure. | |
1426 | * vm_map_copyin_maxprot handles a copyin based on maximum possible | |
1427 | * access. The difference is that a region with no current access | |
1428 | * BUT possible maximum access is rejected by vm_map_copyin(), but | |
1429 | * returned by vm_map_copyin_maxprot. | |
1430 | */ | |
1431 | #define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \ | |
1432 | vm_map_copyin_common(src_map, src_addr, len, src_destroy, \ | |
1433 | FALSE, copy_result, FALSE) | |
1434 | ||
1435 | #define vm_map_copyin_maxprot(src_map, \ | |
1436 | src_addr, len, src_destroy, copy_result) \ | |
1437 | vm_map_copyin_common(src_map, src_addr, len, src_destroy, \ | |
1438 | FALSE, copy_result, TRUE) | |
1439 | ||
39236c6e A |
1440 | |
1441 | /* | |
1442 | * Internal macros for rounding and truncation of vm_map offsets and sizes | |
1443 | */ | |
1444 | #define VM_MAP_ROUND_PAGE(x,pgmask) (((vm_map_offset_t)(x) + (pgmask)) & ~((signed)(pgmask))) | |
1445 | #define VM_MAP_TRUNC_PAGE(x,pgmask) ((vm_map_offset_t)(x) & ~((signed)(pgmask))) | |
2d21ac55 | 1446 | |
91447636 A |
1447 | /* |
1448 | * Macros for rounding and truncation of vm_map offsets and sizes | |
1449 | */ | |
39236c6e A |
1450 | #define VM_MAP_PAGE_SHIFT(map) ((map) ? (map)->hdr.page_shift : PAGE_SHIFT) |
1451 | #define VM_MAP_PAGE_SIZE(map) (1 << VM_MAP_PAGE_SHIFT((map))) | |
1452 | #define VM_MAP_PAGE_MASK(map) (VM_MAP_PAGE_SIZE((map)) - 1) | |
1453 | #define VM_MAP_PAGE_ALIGNED(x,pgmask) (((x) & (pgmask)) == 0) | |
1454 | ||
5ba3f43e A |
1455 | static inline void vm_prot_to_wimg(unsigned int prot, unsigned int *wimg) |
1456 | { | |
1457 | switch (prot) { | |
1458 | case MAP_MEM_NOOP: break; | |
1459 | case MAP_MEM_IO: *wimg = VM_WIMG_IO; break; | |
1460 | case MAP_MEM_COPYBACK: *wimg = VM_WIMG_USE_DEFAULT; break; | |
1461 | case MAP_MEM_INNERWBACK: *wimg = VM_WIMG_INNERWBACK; break; | |
1462 | case MAP_MEM_POSTED: *wimg = VM_WIMG_POSTED; break; | |
1463 | case MAP_MEM_WTHRU: *wimg = VM_WIMG_WTHRU; break; | |
1464 | case MAP_MEM_WCOMB: *wimg = VM_WIMG_WCOMB; break; | |
1465 | default: | |
1466 | panic("Unrecognized mapping type %u\n", prot); | |
1467 | } | |
1468 | } | |
1469 | ||
39236c6e A |
1470 | #endif /* MACH_KERNEL_PRIVATE */ |
1471 | ||
1472 | #ifdef XNU_KERNEL_PRIVATE | |
1473 | extern kern_return_t vm_map_set_page_shift(vm_map_t map, int pageshift); | |
1474 | #endif /* XNU_KERNEL_PRIVATE */ | |
1475 | ||
1476 | #define vm_map_round_page(x,pgmask) (((vm_map_offset_t)(x) + (pgmask)) & ~((signed)(pgmask))) | |
1477 | #define vm_map_trunc_page(x,pgmask) ((vm_map_offset_t)(x) & ~((signed)(pgmask))) | |
91447636 | 1478 | |
1c79356b A |
1479 | /* |
1480 | * Flags for vm_map_remove() and vm_map_delete() | |
1481 | */ | |
1482 | #define VM_MAP_NO_FLAGS 0x0 | |
1483 | #define VM_MAP_REMOVE_KUNWIRE 0x1 | |
1484 | #define VM_MAP_REMOVE_INTERRUPTIBLE 0x2 | |
1485 | #define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4 | |
91447636 | 1486 | #define VM_MAP_REMOVE_SAVE_ENTRIES 0x8 |
2d21ac55 | 1487 | #define VM_MAP_REMOVE_NO_PMAP_CLEANUP 0x10 |
fe8ab488 | 1488 | #define VM_MAP_REMOVE_NO_MAP_ALIGN 0x20 |
3e170ce0 | 1489 | #define VM_MAP_REMOVE_NO_UNNESTING 0x40 |
5ba3f43e | 1490 | #define VM_MAP_REMOVE_IMMUTABLE 0x80 |
91447636 A |
1491 | |
1492 | /* Support for UPLs from vm_maps */ | |
1493 | ||
5ba3f43e A |
1494 | #ifdef XNU_KERNEL_PRIVATE |
1495 | ||
91447636 A |
1496 | extern kern_return_t vm_map_get_upl( |
1497 | vm_map_t target_map, | |
cc9f6e38 | 1498 | vm_map_offset_t map_offset, |
b0d623f7 | 1499 | upl_size_t *size, |
91447636 A |
1500 | upl_t *upl, |
1501 | upl_page_info_array_t page_info, | |
3e170ce0 A |
1502 | unsigned int *page_infoCnt, |
1503 | upl_control_flags_t *flags, | |
5ba3f43e | 1504 | vm_tag_t tag, |
3e170ce0 A |
1505 | int force_data_sync); |
1506 | ||
5ba3f43e A |
1507 | #endif /* XNU_KERNEL_PRIVATE */ |
1508 | ||
3e170ce0 A |
1509 | extern void |
1510 | vm_map_sizes(vm_map_t map, | |
1511 | vm_map_size_t * psize, | |
1512 | vm_map_size_t * pfree, | |
1513 | vm_map_size_t * plargest_free); | |
91447636 | 1514 | |
b7266188 A |
1515 | #if CONFIG_DYNAMIC_CODE_SIGNING |
1516 | extern kern_return_t vm_map_sign(vm_map_t map, | |
1517 | vm_map_offset_t start, | |
1518 | vm_map_offset_t end); | |
1519 | #endif | |
1520 | ||
fe8ab488 A |
1521 | extern kern_return_t vm_map_partial_reap( |
1522 | vm_map_t map, | |
1523 | unsigned int *reclaimed_resident, | |
1524 | unsigned int *reclaimed_compressed); | |
1525 | ||
316670eb | 1526 | |
39037602 A |
1527 | #if DEVELOPMENT || DEBUG |
1528 | ||
1529 | extern int vm_map_disconnect_page_mappings( | |
1530 | vm_map_t map, | |
1531 | boolean_t); | |
1532 | #endif | |
1533 | ||
1534 | ||
1535 | #if CONFIG_FREEZE | |
6d2010ae A |
1536 | |
1537 | extern kern_return_t vm_map_freeze( | |
1538 | vm_map_t map, | |
1539 | unsigned int *purgeable_count, | |
1540 | unsigned int *wired_count, | |
1541 | unsigned int *clean_count, | |
1542 | unsigned int *dirty_count, | |
316670eb | 1543 | unsigned int dirty_budget, |
6d2010ae | 1544 | boolean_t *has_shared); |
6d2010ae A |
1545 | #endif |
1546 | ||
91447636 A |
1547 | __END_DECLS |
1548 | ||
a39ff7e2 A |
1549 | /* |
1550 | * In some cases, we don't have a real VM object but still want to return a | |
1551 | * unique ID (to avoid a memory region looking like shared memory), so build | |
1552 | * a fake pointer based on the map's ledger and the index of the ledger being | |
1553 | * reported. | |
1554 | */ | |
1555 | #define INFO_MAKE_FAKE_OBJECT_ID(map,ledger_id) ((uint32_t)(uintptr_t)VM_KERNEL_ADDRPERM((int*)((map)->pmap->ledger)+(ledger_id))) | |
1556 | ||
91447636 | 1557 | #endif /* KERNEL_PRIVATE */ |
1c79356b | 1558 | |
1c79356b | 1559 | #endif /* _VM_VM_MAP_H_ */ |