]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_map.h
xnu-3248.60.10.tar.gz
[apple/xnu.git] / osfmk / vm / vm_map.h
CommitLineData
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
89extern void vm_map_reference(vm_map_t map);
90extern vm_map_t current_map(void);
91
2d21ac55
A
92/* Setup reserved areas in a new VM map */
93extern kern_return_t vm_map_exec(
94 vm_map_t new_map,
95 task_t task,
96 void *fsroot,
97 cpu_type_t cpu);
98
91447636
A
99__END_DECLS
100
101#ifdef MACH_KERNEL_PRIVATE
1c79356b 102
1c79356b
A
103#include <task_swapper.h>
104#include <mach_assert.h>
105
106#include <vm/vm_object.h>
107#include <vm/vm_page.h>
fe8ab488 108#include <kern/locks.h>
1c79356b
A
109#include <kern/zalloc.h>
110#include <kern/macro_help.h>
111
91447636 112#include <kern/thread.h>
1c79356b 113
91447636 114#define current_map_fast() (current_thread()->map)
1c79356b
A
115#define current_map() (current_map_fast())
116
6d2010ae
A
117#include <vm/vm_map_store.h>
118
119
1c79356b
A
120/*
121 * Types defined:
122 *
123 * vm_map_t the high-level address map data structure.
124 * vm_map_entry_t an entry in an address map.
125 * vm_map_version_t a timestamp of a map, for use with vm_map_lookup
126 * vm_map_copy_t represents memory copied from an address map,
127 * used for inter-map copy operations
128 */
9bccf70c 129typedef struct vm_map_entry *vm_map_entry_t;
91447636 130#define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0)
9bccf70c 131
1c79356b
A
132
133/*
134 * Type: vm_map_object_t [internal use only]
135 *
136 * Description:
137 * The target of an address mapping, either a virtual
138 * memory object or a sub map (of the kernel map).
139 */
140typedef union vm_map_object {
3e170ce0
A
141 vm_object_t vmo_object; /* object object */
142 vm_map_t vmo_submap; /* belongs to another map */
1c79356b
A
143} vm_map_object_t;
144
b0d623f7 145#define named_entry_lock_init(object) lck_mtx_init(&(object)->Lock, &vm_object_lck_grp, &vm_object_lck_attr)
316670eb 146#define named_entry_lock_destroy(object) lck_mtx_destroy(&(object)->Lock, &vm_object_lck_grp)
b0d623f7
A
147#define named_entry_lock(object) lck_mtx_lock(&(object)->Lock)
148#define named_entry_unlock(object) lck_mtx_unlock(&(object)->Lock)
1c79356b
A
149
150/*
151 * Type: vm_named_entry_t [internal use only]
152 *
153 * Description:
154 * Description of a mapping to a memory cache object.
155 *
156 * Implementation:
157 * While the handle to this object is used as a means to map
158 * and pass around the right to map regions backed by pagers
159 * of all sorts, the named_entry itself is only manipulated
160 * by the kernel. Named entries hold information on the
161 * right to map a region of a cached object. Namely,
162 * the target cache object, the beginning and ending of the
163 * region to be mapped, and the permissions, (read, write)
164 * with which it can be mapped.
165 *
166 */
167
168struct vm_named_entry {
b0d623f7 169 decl_lck_mtx_data(, Lock) /* Synchronization */
1c79356b 170 union {
91447636
A
171 vm_object_t object; /* object I point to */
172 memory_object_t pager; /* amo pager port */
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
A
184 /* boolean_t */ is_pager:1, /* ... a pager port */
185 /* boolean_t */ is_copy:1; /* ... a VM map copy */
1c79356b
A
186};
187
1c79356b
A
188/*
189 * Type: vm_map_entry_t [internal use only]
190 *
191 * Description:
192 * A single mapping within an address map.
193 *
194 * Implementation:
195 * Address map entries consist of start and end addresses,
196 * a VM object (or sub map) and offset into that object,
197 * and user-exported inheritance and protection information.
198 * Control information for virtual copy operations is also
199 * stored in the address map entry.
200 */
6d2010ae 201
1c79356b
A
202struct vm_map_links {
203 struct vm_map_entry *prev; /* previous entry */
204 struct vm_map_entry *next; /* next entry */
91447636
A
205 vm_map_offset_t start; /* start address */
206 vm_map_offset_t end; /* end address */
1c79356b
A
207};
208
3e170ce0
A
209/*
210 * IMPORTANT:
211 * The "alias" field can be updated while holding the VM map lock
212 * "shared". It's OK as along as it's the only field that can be
213 * updated without the VM map "exclusive" lock.
214 */
215#define VME_OBJECT(entry) ((entry)->vme_object.vmo_object)
216#define VME_OBJECT_SET(entry, object) \
217 MACRO_BEGIN \
218 (entry)->vme_object.vmo_object = (object); \
219 MACRO_END
220#define VME_SUBMAP(entry) ((entry)->vme_object.vmo_submap)
221#define VME_SUBMAP_SET(entry, submap) \
222 MACRO_BEGIN \
223 (entry)->vme_object.vmo_submap = (submap); \
224 MACRO_END
225#define VME_OFFSET(entry) ((entry)->vme_offset & ~PAGE_MASK)
226#define VME_OFFSET_SET(entry, offset) \
227 MACRO_BEGIN \
228 int __alias; \
229 __alias = VME_ALIAS((entry)); \
230 assert((offset & PAGE_MASK) == 0); \
231 (entry)->vme_offset = offset | __alias; \
232 MACRO_END
233#define VME_OBJECT_SHADOW(entry, length) \
234 MACRO_BEGIN \
235 vm_object_t __object; \
236 vm_object_offset_t __offset; \
237 __object = VME_OBJECT((entry)); \
238 __offset = VME_OFFSET((entry)); \
239 vm_object_shadow(&__object, &__offset, (length)); \
240 if (__object != VME_OBJECT((entry))) { \
241 VME_OBJECT_SET((entry), __object); \
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
1c79356b
A
257struct vm_map_entry {
258 struct vm_map_links links; /* links to other entries */
259#define vme_prev links.prev
260#define vme_next links.next
261#define vme_start links.start
262#define vme_end links.end
6d2010ae
A
263
264 struct vm_map_store store;
3e170ce0
A
265 union vm_map_object vme_object; /* object I point to */
266 vm_object_offset_t vme_offset; /* offset into object */
267
1c79356b 268 unsigned int
3e170ce0
A
269 /* boolean_t */ is_shared:1, /* region is shared */
270 /* boolean_t */ is_sub_map:1, /* Is "object" a submap? */
271 /* boolean_t */ in_transition:1, /* Entry being changed */
272 /* boolean_t */ needs_wakeup:1, /* Waiters on in_transition */
273 /* vm_behavior_t */ behavior:2, /* user paging behavior hint */
1c79356b 274 /* behavior is not defined for submap type */
3e170ce0
A
275 /* boolean_t */ needs_copy:1, /* object need to be copied? */
276
1c79356b 277 /* Only in task maps: */
3e170ce0
A
278 /* vm_prot_t */ protection:3, /* protection code */
279 /* vm_prot_t */ max_protection:3, /* maximum protection */
280 /* vm_inherit_t */ inheritance:2, /* inheritance */
281 /* boolean_t */ use_pmap:1, /*
282 * use_pmap is overloaded:
283 * if "is_sub_map":
284 * use a nested pmap?
285 * else (i.e. if object):
286 * use pmap accounting
287 * for footprint?
288 */
289 /* boolean_t */ no_cache:1, /* should new pages be cached? */
290 /* boolean_t */ permanent:1, /* mapping can not be removed */
291 /* boolean_t */ superpage_size:1, /* use superpages of a certain size */
292 /* boolean_t */ map_aligned:1, /* align to map's page size */
293 /* boolean_t */ zero_wired_pages:1, /* zero out the wired pages of
294 * this entry it is being deleted
295 * without unwiring them */
296 /* boolean_t */ used_for_jit:1,
297 /* boolean_t */ from_reserved_zone:1, /* Allocated from
298 * kernel reserved zone */
fe8ab488
A
299
300 /* iokit accounting: use the virtual size rather than resident size: */
3e170ce0
A
301 /* boolean_t */ iokit_acct:1,
302 /* boolean_t */ vme_resilient_codesign:1,
303 /* boolean_t */ vme_resilient_media:1,
304 __unused:6;
305;
fe8ab488 306
1c79356b
A
307 unsigned short wired_count; /* can be paged if = 0 */
308 unsigned short user_wired_count; /* for vm_wire */
316670eb
A
309#if DEBUG
310#define MAP_ENTRY_CREATION_DEBUG (1)
39236c6e 311#define MAP_ENTRY_INSERTION_DEBUG (1)
316670eb
A
312#endif
313#if MAP_ENTRY_CREATION_DEBUG
39236c6e
A
314 struct vm_map_header *vme_creation_maphdr;
315 uintptr_t vme_creation_bt[16];
316#endif
317#if MAP_ENTRY_INSERTION_DEBUG
318 uintptr_t vme_insertion_bt[16];
316670eb 319#endif
1c79356b
A
320};
321
b0d623f7
A
322/*
323 * Convenience macros for dealing with superpages
324 * SUPERPAGE_NBASEPAGES is architecture dependent and defined in pmap.h
325 */
326#define SUPERPAGE_SIZE (PAGE_SIZE*SUPERPAGE_NBASEPAGES)
327#define SUPERPAGE_MASK (-SUPERPAGE_SIZE)
328#define SUPERPAGE_ROUND_DOWN(a) (a & SUPERPAGE_MASK)
329#define SUPERPAGE_ROUND_UP(a) ((a + SUPERPAGE_SIZE-1) & SUPERPAGE_MASK)
330
1c79356b
A
331/*
332 * wired_counts are unsigned short. This value is used to safeguard
333 * against any mishaps due to runaway user programs.
334 */
335#define MAX_WIRE_COUNT 65535
336
337
338
339/*
340 * Type: struct vm_map_header
341 *
342 * Description:
343 * Header for a vm_map and a vm_map_copy.
344 */
6d2010ae
A
345
346
1c79356b
A
347struct vm_map_header {
348 struct vm_map_links links; /* first, last, min, max */
349 int nentries; /* Number of entries */
350 boolean_t entries_pageable;
351 /* are map entries pageable? */
6d2010ae
A
352 vm_map_offset_t highest_entry_end_addr; /* The ending address of the highest allocated vm_entry_t */
353#ifdef VM_MAP_STORE_USE_RB
354 struct rb_head rb_head_store;
355#endif
39236c6e 356 int page_shift; /* page shift */
1c79356b
A
357};
358
39236c6e
A
359#define VM_MAP_HDR_PAGE_SHIFT(hdr) ((hdr)->page_shift)
360#define VM_MAP_HDR_PAGE_SIZE(hdr) (1 << VM_MAP_HDR_PAGE_SHIFT((hdr)))
361#define VM_MAP_HDR_PAGE_MASK(hdr) (VM_MAP_HDR_PAGE_SIZE((hdr)) - 1)
362
1c79356b
A
363/*
364 * Type: vm_map_t [exported; contents invisible]
365 *
366 * Description:
367 * An address map -- a directory relating valid
368 * regions of a task's address space to the corresponding
369 * virtual memory objects.
370 *
371 * Implementation:
372 * Maps are doubly-linked lists of map entries, sorted
373 * by address. One hint is used to start
374 * searches again from the last successful search,
375 * insertion, or removal. Another hint is used to
376 * quickly find free space.
377 */
2d21ac55 378struct _vm_map {
fe8ab488 379 lck_rw_t lock; /* map lock */
1c79356b
A
380 struct vm_map_header hdr; /* Map entry header */
381#define min_offset hdr.links.start /* start of range */
382#define max_offset hdr.links.end /* end of range */
6d2010ae 383#define highest_entry_end hdr.highest_entry_end_addr
1c79356b 384 pmap_t pmap; /* Physical map */
91447636 385 vm_map_size_t size; /* virtual size */
2d21ac55
A
386 vm_map_size_t user_wire_limit;/* rlimit on user locked memory */
387 vm_map_size_t user_wire_size; /* current size of user locked memory in this map */
1c79356b
A
388 int ref_count; /* Reference count */
389#if TASK_SWAPPER
390 int res_count; /* Residence count (swap) */
391 int sw_state; /* Swap state */
392#endif /* TASK_SWAPPER */
b0d623f7
A
393 decl_lck_mtx_data(, s_lock) /* Lock ref, res fields */
394 lck_mtx_ext_t s_lock_ext;
1c79356b 395 vm_map_entry_t hint; /* hint for quick lookups */
3e170ce0
A
396 struct vm_map_links* hole_hint; /* hint for quick hole lookups */
397 union{
398 vm_map_entry_t _first_free; /* First free space hint */
399 struct vm_map_links* _holes; /* links all holes between entries */
400 }f_s; /* Union for free space data structures being used */
401
402#define first_free f_s._first_free
403#define holes_list f_s._holes
404
6d2010ae
A
405 unsigned int
406 /* boolean_t */ wait_for_space:1, /* Should callers wait for space? */
407 /* boolean_t */ wiring_required:1, /* All memory wired? */
408 /* boolean_t */ no_zero_fill:1, /*No zero fill absent pages */
316670eb 409 /* boolean_t */ mapped_in_other_pmaps:1, /*has this submap been mapped in maps that use a different pmap */
6d2010ae
A
410 /* boolean_t */ switch_protect:1, /* Protect map from write faults while switched */
411 /* boolean_t */ disable_vmentry_reuse:1, /* All vm entries should keep using newer and higher addresses in the map */
412 /* boolean_t */ map_disallow_data_exec:1, /* Disallow execution from data pages on exec-permissive architectures */
3e170ce0
A
413 /* boolean_t */ holelistenabled:1,
414 /* reserved */ pad:24;
1c79356b 415 unsigned int timestamp; /* Version number */
2d21ac55 416 unsigned int color_rr; /* next color (not protected by a lock) */
6d2010ae 417#if CONFIG_FREEZE
316670eb 418 void *default_freezer_handle;
6d2010ae
A
419#endif
420 boolean_t jit_entry_exists;
1c79356b
A
421} ;
422
423#define vm_map_to_entry(map) ((struct vm_map_entry *) &(map)->hdr.links)
424#define vm_map_first_entry(map) ((map)->hdr.links.next)
425#define vm_map_last_entry(map) ((map)->hdr.links.prev)
426
427#if TASK_SWAPPER
428/*
429 * VM map swap states. There are no transition states.
430 */
431#define MAP_SW_IN 1 /* map is swapped in; residence count > 0 */
432#define MAP_SW_OUT 2 /* map is out (res_count == 0 */
433#endif /* TASK_SWAPPER */
434
435/*
436 * Type: vm_map_version_t [exported; contents invisible]
437 *
438 * Description:
439 * Map versions may be used to quickly validate a previous
440 * lookup operation.
441 *
442 * Usage note:
443 * Because they are bulky objects, map versions are usually
444 * passed by reference.
445 *
446 * Implementation:
447 * Just a timestamp for the main map.
448 */
449typedef struct vm_map_version {
450 unsigned int main_timestamp;
451} vm_map_version_t;
452
453/*
454 * Type: vm_map_copy_t [exported; contents invisible]
455 *
456 * Description:
457 * A map copy object represents a region of virtual memory
458 * that has been copied from an address map but is still
459 * in transit.
460 *
461 * A map copy object may only be used by a single thread
462 * at a time.
463 *
464 * Implementation:
465 * There are three formats for map copy objects.
466 * The first is very similar to the main
467 * address map in structure, and as a result, some
468 * of the internal maintenance functions/macros can
469 * be used with either address maps or map copy objects.
470 *
471 * The map copy object contains a header links
472 * entry onto which the other entries that represent
473 * the region are chained.
474 *
91447636
A
475 * The second format is a single vm object. This was used
476 * primarily in the pageout path - but is not currently used
477 * except for placeholder copy objects (see vm_map_copy_copy()).
478 *
479 * The third format is a kernel buffer copy object - for data
480 * small enough that physical copies were the most efficient
3e170ce0
A
481 * method. This method uses a zero-sized array unioned with
482 * other format-specific data in the 'c_u' member. This unsized
483 * array overlaps the other elements and allows us to use this
484 * extra structure space for physical memory copies. On 64-bit
485 * systems this saves ~64 bytes per vm_map_copy.
1c79356b 486 */
1c79356b
A
487
488struct vm_map_copy {
489 int type;
490#define VM_MAP_COPY_ENTRY_LIST 1
491#define VM_MAP_COPY_OBJECT 2
0b4e3aa0 492#define VM_MAP_COPY_KERNEL_BUFFER 3
1c79356b 493 vm_object_offset_t offset;
91447636 494 vm_map_size_t size;
1c79356b 495 union {
3e170ce0
A
496 struct vm_map_header hdr; /* ENTRY_LIST */
497 vm_object_t object; /* OBJECT */
498 uint8_t kdata[0]; /* KERNEL_BUFFER */
1c79356b
A
499 } c_u;
500};
501
502
503#define cpy_hdr c_u.hdr
504
91447636 505#define cpy_object c_u.object
3e170ce0
A
506#define cpy_kdata c_u.kdata
507#define cpy_kdata_hdr_sz (offsetof(struct vm_map_copy, c_u.kdata))
1c79356b 508
39236c6e
A
509#define VM_MAP_COPY_PAGE_SHIFT(copy) ((copy)->cpy_hdr.page_shift)
510#define VM_MAP_COPY_PAGE_SIZE(copy) (1 << VM_MAP_COPY_PAGE_SHIFT((copy)))
511#define VM_MAP_COPY_PAGE_MASK(copy) (VM_MAP_COPY_PAGE_SIZE((copy)) - 1)
1c79356b
A
512
513/*
514 * Useful macros for entry list copy objects
515 */
516
517#define vm_map_copy_to_entry(copy) \
518 ((struct vm_map_entry *) &(copy)->cpy_hdr.links)
519#define vm_map_copy_first_entry(copy) \
520 ((copy)->cpy_hdr.links.next)
521#define vm_map_copy_last_entry(copy) \
522 ((copy)->cpy_hdr.links.prev)
523
1c79356b
A
524/*
525 * Macros: vm_map_lock, etc. [internal use only]
526 * Description:
527 * Perform locking on the data portion of a map.
528 * When multiple maps are to be locked, order by map address.
529 * (See vm_map.c::vm_remap())
530 */
531
532#define vm_map_lock_init(map) \
9bccf70c 533 ((map)->timestamp = 0 , \
fe8ab488 534 lck_rw_init(&(map)->lock, &vm_map_lck_grp, &vm_map_lck_rw_attr))
9bccf70c 535
fe8ab488 536#define vm_map_lock(map) lck_rw_lock_exclusive(&(map)->lock)
9bccf70c 537#define vm_map_unlock(map) \
fe8ab488
A
538 ((map)->timestamp++ , lck_rw_done(&(map)->lock))
539#define vm_map_lock_read(map) lck_rw_lock_shared(&(map)->lock)
540#define vm_map_unlock_read(map) lck_rw_done(&(map)->lock)
1c79356b 541#define vm_map_lock_write_to_read(map) \
fe8ab488 542 ((map)->timestamp++ , lck_rw_lock_exclusive_to_shared(&(map)->lock))
2d21ac55
A
543/* lock_read_to_write() returns FALSE on failure. Macro evaluates to
544 * zero on success and non-zero value on failure.
545 */
fe8ab488 546#define vm_map_lock_read_to_write(map) (lck_rw_lock_shared_to_exclusive(&(map)->lock) != TRUE)
1c79356b 547
3e170ce0
A
548#if MACH_ASSERT || DEBUG
549#define vm_map_lock_assert_held(map) \
550 lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_HELD)
551#define vm_map_lock_assert_shared(map) \
552 lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_SHARED)
553#define vm_map_lock_assert_exclusive(map) \
554 lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_EXCLUSIVE)
555#define vm_map_lock_assert_notheld(map) \
556 lck_rw_assert(&(map)->lock, LCK_RW_ASSERT_NOTHELD)
557#else /* MACH_ASSERT || DEBUG */
558#define vm_map_lock_assert_held(map)
559#define vm_map_lock_assert_shared(map)
560#define vm_map_lock_assert_exclusive(map)
561#define vm_map_lock_assert_notheld(map)
562#endif /* MACH_ASSERT || DEBUG */
563
1c79356b
A
564/*
565 * Exported procedures that operate on vm_map_t.
566 */
567
568/* Initialize the module */
39236c6e 569extern void vm_map_init(void);
1c79356b 570
39236c6e 571extern void vm_kernel_reserved_entry_init(void);
7ddcb079 572
1c79356b
A
573/* Allocate a range in the specified virtual address map and
574 * return the entry allocated for that range. */
575extern kern_return_t vm_map_find_space(
91447636
A
576 vm_map_t map,
577 vm_map_address_t *address, /* OUT */
578 vm_map_size_t size,
579 vm_map_offset_t mask,
0c530ab8 580 int flags,
91447636 581 vm_map_entry_t *o_entry); /* OUT */
1c79356b 582
e2d2fc5c
A
583extern void vm_map_clip_start(
584 vm_map_t map,
585 vm_map_entry_t entry,
586 vm_map_offset_t endaddr);
587extern void vm_map_clip_end(
588 vm_map_t map,
589 vm_map_entry_t entry,
590 vm_map_offset_t endaddr);
e2d2fc5c
A
591extern boolean_t vm_map_entry_should_cow_for_true_share(
592 vm_map_entry_t entry);
e2d2fc5c 593
1c79356b
A
594/* Lookup map entry containing or the specified address in the given map */
595extern boolean_t vm_map_lookup_entry(
91447636
A
596 vm_map_t map,
597 vm_map_address_t address,
598 vm_map_entry_t *entry); /* OUT */
1c79356b 599
39236c6e
A
600extern void vm_map_copy_remap(
601 vm_map_t map,
602 vm_map_entry_t where,
603 vm_map_copy_t copy,
604 vm_map_offset_t adjustment,
605 vm_prot_t cur_prot,
606 vm_prot_t max_prot,
607 vm_inherit_t inheritance);
608
1c79356b
A
609/* Find the VM object, offset, and protection for a given virtual address
610 * in the specified map, assuming a page fault of the type specified. */
611extern kern_return_t vm_map_lookup_locked(
91447636
A
612 vm_map_t *var_map, /* IN/OUT */
613 vm_map_address_t vaddr,
614 vm_prot_t fault_type,
2d21ac55 615 int object_lock_type,
91447636
A
616 vm_map_version_t *out_version, /* OUT */
617 vm_object_t *object, /* OUT */
618 vm_object_offset_t *offset, /* OUT */
619 vm_prot_t *out_prot, /* OUT */
620 boolean_t *wired, /* OUT */
2d21ac55 621 vm_object_fault_info_t fault_info, /* OUT */
91447636 622 vm_map_t *real_map); /* OUT */
1c79356b
A
623
624/* Verifies that the map has not changed since the given version. */
625extern boolean_t vm_map_verify(
91447636
A
626 vm_map_t map,
627 vm_map_version_t *version); /* REF */
1c79356b
A
628
629extern vm_map_entry_t vm_map_entry_insert(
630 vm_map_t map,
631 vm_map_entry_t insp_entry,
91447636
A
632 vm_map_offset_t start,
633 vm_map_offset_t end,
1c79356b
A
634 vm_object_t object,
635 vm_object_offset_t offset,
636 boolean_t needs_copy,
637 boolean_t is_shared,
638 boolean_t in_transition,
639 vm_prot_t cur_protection,
640 vm_prot_t max_protection,
641 vm_behavior_t behavior,
642 vm_inherit_t inheritance,
2d21ac55 643 unsigned wired_count,
b0d623f7
A
644 boolean_t no_cache,
645 boolean_t permanent,
39236c6e 646 unsigned int superpage_size,
fe8ab488
A
647 boolean_t clear_map_aligned,
648 boolean_t is_submap);
1c79356b 649
1c79356b
A
650
651/*
652 * Functions implemented as macros
653 */
91447636 654#define vm_map_min(map) ((map)->min_offset)
1c79356b
A
655 /* Lowest valid address in
656 * a map */
657
91447636 658#define vm_map_max(map) ((map)->max_offset)
1c79356b
A
659 /* Highest valid address */
660
661#define vm_map_pmap(map) ((map)->pmap)
662 /* Physical map associated
663 * with this address map */
664
665#define vm_map_verify_done(map, version) vm_map_unlock_read(map)
666 /* Operation that required
667 * a verified lookup is
668 * now complete */
669
670/*
671 * Macros/functions for map residence counts and swapin/out of vm maps
672 */
673#if TASK_SWAPPER
674
675#if MACH_ASSERT
676/* Gain a reference to an existing map */
677extern void vm_map_reference(
678 vm_map_t map);
679/* Lose a residence count */
680extern void vm_map_res_deallocate(
681 vm_map_t map);
682/* Gain a residence count on a map */
683extern void vm_map_res_reference(
684 vm_map_t map);
685/* Gain reference & residence counts to possibly swapped-out map */
686extern void vm_map_reference_swap(
687 vm_map_t map);
688
689#else /* MACH_ASSERT */
690
91447636 691#define vm_map_reference(map) \
1c79356b 692MACRO_BEGIN \
91447636 693 vm_map_t Map = (map); \
1c79356b 694 if (Map) { \
b0d623f7 695 lck_mtx_lock(&Map->s_lock); \
1c79356b
A
696 Map->res_count++; \
697 Map->ref_count++; \
b0d623f7 698 lck_mtx_unlock(&Map->s_lock); \
1c79356b
A
699 } \
700MACRO_END
701
702#define vm_map_res_reference(map) \
703MACRO_BEGIN \
91447636 704 vm_map_t Lmap = (map); \
1c79356b 705 if (Lmap->res_count == 0) { \
b0d623f7 706 lck_mtx_unlock(&Lmap->s_lock);\
1c79356b
A
707 vm_map_lock(Lmap); \
708 vm_map_swapin(Lmap); \
b0d623f7 709 lck_mtx_lock(&Lmap->s_lock); \
1c79356b
A
710 ++Lmap->res_count; \
711 vm_map_unlock(Lmap); \
712 } else \
713 ++Lmap->res_count; \
714MACRO_END
715
716#define vm_map_res_deallocate(map) \
717MACRO_BEGIN \
91447636
A
718 vm_map_t Map = (map); \
719 if (--Map->res_count == 0) { \
b0d623f7 720 lck_mtx_unlock(&Map->s_lock); \
1c79356b
A
721 vm_map_lock(Map); \
722 vm_map_swapout(Map); \
723 vm_map_unlock(Map); \
b0d623f7 724 lck_mtx_lock(&Map->s_lock); \
1c79356b
A
725 } \
726MACRO_END
727
728#define vm_map_reference_swap(map) \
729MACRO_BEGIN \
730 vm_map_t Map = (map); \
b0d623f7 731 lck_mtx_lock(&Map->s_lock); \
1c79356b
A
732 ++Map->ref_count; \
733 vm_map_res_reference(Map); \
b0d623f7 734 lck_mtx_unlock(&Map->s_lock); \
1c79356b
A
735MACRO_END
736#endif /* MACH_ASSERT */
737
738extern void vm_map_swapin(
739 vm_map_t map);
740
741extern void vm_map_swapout(
742 vm_map_t map);
743
744#else /* TASK_SWAPPER */
745
746#define vm_map_reference(map) \
747MACRO_BEGIN \
748 vm_map_t Map = (map); \
749 if (Map) { \
b0d623f7 750 lck_mtx_lock(&Map->s_lock); \
1c79356b 751 Map->ref_count++; \
b0d623f7 752 lck_mtx_unlock(&Map->s_lock); \
1c79356b
A
753 } \
754MACRO_END
755
756#define vm_map_reference_swap(map) vm_map_reference(map)
757#define vm_map_res_reference(map)
758#define vm_map_res_deallocate(map)
759
760#endif /* TASK_SWAPPER */
761
762/*
763 * Submap object. Must be used to create memory to be put
764 * in a submap by vm_map_submap.
765 */
766extern vm_object_t vm_submap_object;
767
768/*
769 * Wait and wakeup macros for in_transition map entries.
770 */
771#define vm_map_entry_wait(map, interruptible) \
9bccf70c 772 ((map)->timestamp++ , \
fe8ab488
A
773 lck_rw_sleep(&(map)->lock, LCK_SLEEP_EXCLUSIVE|LCK_SLEEP_PROMOTED_PRI, \
774 (event_t)&(map)->hdr, interruptible))
1c79356b 775
1c79356b 776
91447636
A
777#define vm_map_entry_wakeup(map) \
778 thread_wakeup((event_t)(&(map)->hdr))
1c79356b
A
779
780
91447636 781#define vm_map_ref_fast(map) \
1c79356b 782 MACRO_BEGIN \
b0d623f7 783 lck_mtx_lock(&map->s_lock); \
1c79356b
A
784 map->ref_count++; \
785 vm_map_res_reference(map); \
b0d623f7 786 lck_mtx_unlock(&map->s_lock); \
1c79356b
A
787 MACRO_END
788
91447636 789#define vm_map_dealloc_fast(map) \
1c79356b 790 MACRO_BEGIN \
91447636 791 register int c; \
1c79356b 792 \
b0d623f7 793 lck_mtx_lock(&map->s_lock); \
91447636 794 c = --map->ref_count; \
1c79356b
A
795 if (c > 0) \
796 vm_map_res_deallocate(map); \
b0d623f7 797 lck_mtx_unlock(&map->s_lock); \
1c79356b
A
798 if (c == 0) \
799 vm_map_destroy(map); \
800 MACRO_END
801
802
803/* simplify map entries */
5353443c
A
804extern void vm_map_simplify_entry(
805 vm_map_t map,
806 vm_map_entry_t this_entry);
1c79356b 807extern void vm_map_simplify(
91447636
A
808 vm_map_t map,
809 vm_map_offset_t start);
1c79356b
A
810
811/* Move the information in a map copy object to a new map copy object */
812extern vm_map_copy_t vm_map_copy_copy(
91447636 813 vm_map_copy_t copy);
1c79356b 814
1c79356b
A
815/* Create a copy object from an object. */
816extern kern_return_t vm_map_copyin_object(
817 vm_object_t object,
818 vm_object_offset_t offset,
819 vm_object_size_t size,
820 vm_map_copy_t *copy_result); /* OUT */
821
316670eb
A
822extern kern_return_t vm_map_random_address_for_size(
823 vm_map_t map,
824 vm_map_offset_t *address,
825 vm_map_size_t size);
826
1c79356b
A
827/* Enter a mapping */
828extern kern_return_t vm_map_enter(
829 vm_map_t map,
91447636
A
830 vm_map_offset_t *address,
831 vm_map_size_t size,
832 vm_map_offset_t mask,
1c79356b
A
833 int flags,
834 vm_object_t object,
835 vm_object_offset_t offset,
836 boolean_t needs_copy,
837 vm_prot_t cur_protection,
838 vm_prot_t max_protection,
839 vm_inherit_t inheritance);
840
3e170ce0 841
91447636
A
842/* XXX should go away - replaced with regular enter of contig object */
843extern kern_return_t vm_map_enter_cpm(
844 vm_map_t map,
845 vm_map_address_t *addr,
846 vm_map_size_t size,
847 int flags);
848
849extern kern_return_t vm_map_remap(
850 vm_map_t target_map,
851 vm_map_offset_t *address,
852 vm_map_size_t size,
853 vm_map_offset_t mask,
060df5ea 854 int flags,
91447636
A
855 vm_map_t src_map,
856 vm_map_offset_t memory_address,
857 boolean_t copy,
858 vm_prot_t *cur_protection,
859 vm_prot_t *max_protection,
860 vm_inherit_t inheritance);
861
862
863/*
864 * Read and write from a kernel buffer to a specified map.
865 */
1c79356b 866extern kern_return_t vm_map_write_user(
91447636
A
867 vm_map_t map,
868 void *src_p,
869 vm_map_offset_t dst_addr,
870 vm_size_t size);
1c79356b
A
871
872extern kern_return_t vm_map_read_user(
91447636
A
873 vm_map_t map,
874 vm_map_offset_t src_addr,
875 void *dst_p,
876 vm_size_t size);
1c79356b
A
877
878/* Create a new task map using an existing task map as a template. */
879extern vm_map_t vm_map_fork(
316670eb 880 ledger_t ledger,
91447636 881 vm_map_t old_map);
1c79356b 882
9bccf70c
A
883/* Change inheritance */
884extern kern_return_t vm_map_inherit(
91447636
A
885 vm_map_t map,
886 vm_map_offset_t start,
887 vm_map_offset_t end,
888 vm_inherit_t new_inheritance);
1c79356b 889
9bccf70c
A
890/* Add or remove machine-dependent attributes from map regions */
891extern kern_return_t vm_map_machine_attribute(
91447636
A
892 vm_map_t map,
893 vm_map_offset_t start,
894 vm_map_offset_t end,
9bccf70c
A
895 vm_machine_attribute_t attribute,
896 vm_machine_attribute_val_t* value); /* IN/OUT */
91447636
A
897
898extern kern_return_t vm_map_msync(
899 vm_map_t map,
900 vm_map_address_t address,
901 vm_map_size_t size,
902 vm_sync_t sync_flags);
903
9bccf70c
A
904/* Set paging behavior */
905extern kern_return_t vm_map_behavior_set(
91447636
A
906 vm_map_t map,
907 vm_map_offset_t start,
908 vm_map_offset_t end,
909 vm_behavior_t new_behavior);
910
911extern kern_return_t vm_map_purgable_control(
912 vm_map_t map,
913 vm_map_offset_t address,
914 vm_purgable_t control,
915 int *state);
916
917extern kern_return_t vm_map_region(
918 vm_map_t map,
919 vm_map_offset_t *address,
920 vm_map_size_t *size,
921 vm_region_flavor_t flavor,
922 vm_region_info_t info,
923 mach_msg_type_number_t *count,
924 mach_port_t *object_name);
925
926extern kern_return_t vm_map_region_recurse_64(
927 vm_map_t map,
928 vm_map_offset_t *address,
929 vm_map_size_t *size,
930 natural_t *nesting_depth,
931 vm_region_submap_info_64_t info,
932 mach_msg_type_number_t *count);
933
b0d623f7 934extern kern_return_t vm_map_page_query_internal(
91447636
A
935 vm_map_t map,
936 vm_map_offset_t offset,
937 int *disposition,
938 int *ref_count);
9bccf70c 939
39236c6e
A
940extern kern_return_t vm_map_query_volatile(
941 vm_map_t map,
942 mach_vm_size_t *volatile_virtual_size_p,
943 mach_vm_size_t *volatile_resident_size_p,
3e170ce0
A
944 mach_vm_size_t *volatile_compressed_size_p,
945 mach_vm_size_t *volatile_pmap_size_p,
946 mach_vm_size_t *volatile_compressed_pmap_size_p);
b0d623f7 947
9bccf70c 948extern kern_return_t vm_map_submap(
91447636
A
949 vm_map_t map,
950 vm_map_offset_t start,
951 vm_map_offset_t end,
952 vm_map_t submap,
953 vm_map_offset_t offset,
954 boolean_t use_pmap);
955
956extern void vm_map_submap_pmap_clean(
957 vm_map_t map,
958 vm_map_offset_t start,
959 vm_map_offset_t end,
960 vm_map_t sub_map,
961 vm_map_offset_t offset);
962
963/* Convert from a map entry port to a map */
964extern vm_map_t convert_port_entry_to_map(
965 ipc_port_t port);
966
967/* Convert from a port to a vm_object */
968extern vm_object_t convert_port_entry_to_object(
969 ipc_port_t port);
9bccf70c
A
970
971
6d2010ae
A
972extern kern_return_t vm_map_set_cache_attr(
973 vm_map_t map,
974 vm_map_offset_t va);
975
976
2d21ac55
A
977/* definitions related to overriding the NX behavior */
978
979#define VM_ABI_32 0x1
980#define VM_ABI_64 0x2
981
982extern int override_nx(vm_map_t map, uint32_t user_tag);
983
fe8ab488
A
984extern int vm_map_purge(vm_map_t map);
985
3e170ce0
A
986
987/* kext exported versions */
988
989extern kern_return_t vm_map_wire_external(
990 register vm_map_t map,
991 register vm_map_offset_t start,
992 register vm_map_offset_t end,
993 register vm_prot_t caller_prot,
994 boolean_t user_wire);
995
996extern kern_return_t vm_map_wire_and_extract_external(
997 vm_map_t map,
998 vm_map_offset_t start,
999 vm_prot_t caller_prot,
1000 boolean_t user_wire,
1001 ppnum_t *physpage_p);
1002
9bccf70c
A
1003#endif /* MACH_KERNEL_PRIVATE */
1004
91447636
A
1005__BEGIN_DECLS
1006
9bccf70c
A
1007/* Create an empty map */
1008extern vm_map_t vm_map_create(
91447636
A
1009 pmap_t pmap,
1010 vm_map_offset_t min_off,
1011 vm_map_offset_t max_off,
1012 boolean_t pageable);
9bccf70c 1013
3e170ce0
A
1014extern void vm_map_disable_hole_optimization(vm_map_t map);
1015
9bccf70c
A
1016/* Get rid of a map */
1017extern void vm_map_destroy(
2d21ac55
A
1018 vm_map_t map,
1019 int flags);
1020
9bccf70c
A
1021/* Lose a reference */
1022extern void vm_map_deallocate(
91447636
A
1023 vm_map_t map);
1024
1025extern vm_map_t vm_map_switch(
1026 vm_map_t map);
9bccf70c
A
1027
1028/* Change protection */
1029extern kern_return_t vm_map_protect(
91447636
A
1030 vm_map_t map,
1031 vm_map_offset_t start,
1032 vm_map_offset_t end,
1033 vm_prot_t new_prot,
1034 boolean_t set_max);
1035
1036/* Check protection */
1037extern boolean_t vm_map_check_protection(
1038 vm_map_t map,
1039 vm_map_offset_t start,
1040 vm_map_offset_t end,
1041 vm_prot_t protection);
1c79356b
A
1042
1043/* wire down a region */
1044extern kern_return_t vm_map_wire(
91447636
A
1045 vm_map_t map,
1046 vm_map_offset_t start,
1047 vm_map_offset_t end,
1048 vm_prot_t access_type,
1049 boolean_t user_wire);
1c79356b 1050
fe8ab488
A
1051extern kern_return_t vm_map_wire_and_extract(
1052 vm_map_t map,
1053 vm_map_offset_t start,
1054 vm_prot_t access_type,
1055 boolean_t user_wire,
1056 ppnum_t *physpage_p);
1057
1c79356b
A
1058/* unwire a region */
1059extern kern_return_t vm_map_unwire(
91447636
A
1060 vm_map_t map,
1061 vm_map_offset_t start,
1062 vm_map_offset_t end,
1063 boolean_t user_wire);
1c79356b 1064
2d21ac55
A
1065/* Enter a mapping of a memory object */
1066extern kern_return_t vm_map_enter_mem_object(
1067 vm_map_t map,
1068 vm_map_offset_t *address,
1069 vm_map_size_t size,
1070 vm_map_offset_t mask,
1071 int flags,
1072 ipc_port_t port,
1073 vm_object_offset_t offset,
1074 boolean_t needs_copy,
1075 vm_prot_t cur_protection,
1076 vm_prot_t max_protection,
1077 vm_inherit_t inheritance);
1078
fe8ab488
A
1079/* Enter a mapping of a memory object */
1080extern kern_return_t vm_map_enter_mem_object_prefault(
1081 vm_map_t map,
1082 vm_map_offset_t *address,
1083 vm_map_size_t size,
1084 vm_map_offset_t mask,
1085 int flags,
1086 ipc_port_t port,
1087 vm_object_offset_t offset,
1088 vm_prot_t cur_protection,
1089 vm_prot_t max_protection,
1090 upl_page_list_ptr_t page_list,
1091 unsigned int page_list_count);
1092
b0d623f7
A
1093/* Enter a mapping of a memory object */
1094extern kern_return_t vm_map_enter_mem_object_control(
1095 vm_map_t map,
1096 vm_map_offset_t *address,
1097 vm_map_size_t size,
1098 vm_map_offset_t mask,
1099 int flags,
1100 memory_object_control_t control,
1101 vm_object_offset_t offset,
1102 boolean_t needs_copy,
1103 vm_prot_t cur_protection,
1104 vm_prot_t max_protection,
1105 vm_inherit_t inheritance);
1106
1c79356b
A
1107/* Deallocate a region */
1108extern kern_return_t vm_map_remove(
91447636
A
1109 vm_map_t map,
1110 vm_map_offset_t start,
1111 vm_map_offset_t end,
1112 boolean_t flags);
1113
1114/* Discard a copy without using it */
1115extern void vm_map_copy_discard(
1116 vm_map_copy_t copy);
1117
1118/* Overwrite existing memory with a copy */
1119extern kern_return_t vm_map_copy_overwrite(
1120 vm_map_t dst_map,
1121 vm_map_address_t dst_addr,
1122 vm_map_copy_t copy,
b0d623f7 1123 boolean_t interruptible);
1c79356b 1124
2dced7af
A
1125/* returns TRUE if size of vm_map_copy == size parameter FALSE otherwise */
1126extern boolean_t vm_map_copy_validate_size(
1127 vm_map_t dst_map,
1128 vm_map_copy_t copy,
1129 vm_map_size_t size);
1130
1c79356b
A
1131/* Place a copy into a map */
1132extern kern_return_t vm_map_copyout(
91447636
A
1133 vm_map_t dst_map,
1134 vm_map_address_t *dst_addr, /* OUT */
1135 vm_map_copy_t copy);
1c79356b 1136
39236c6e
A
1137extern kern_return_t vm_map_copyout_internal(
1138 vm_map_t dst_map,
1139 vm_map_address_t *dst_addr, /* OUT */
1140 vm_map_copy_t copy,
1141 boolean_t consume_on_success,
1142 vm_prot_t cur_protection,
1143 vm_prot_t max_protection,
1144 vm_inherit_t inheritance);
1145
2d21ac55
A
1146extern kern_return_t vm_map_copyin(
1147 vm_map_t src_map,
1148 vm_map_address_t src_addr,
1149 vm_map_size_t len,
1150 boolean_t src_destroy,
1151 vm_map_copy_t *copy_result); /* OUT */
1152
1c79356b 1153extern kern_return_t vm_map_copyin_common(
91447636
A
1154 vm_map_t src_map,
1155 vm_map_address_t src_addr,
1156 vm_map_size_t len,
1157 boolean_t src_destroy,
1158 boolean_t src_volatile,
1159 vm_map_copy_t *copy_result, /* OUT */
1160 boolean_t use_maxprot);
55e303ae 1161
4bd07ac2
A
1162#define VM_MAP_COPYIN_SRC_DESTROY 0x00000001
1163#define VM_MAP_COPYIN_USE_MAXPROT 0x00000002
1164#define VM_MAP_COPYIN_ENTRY_LIST 0x00000004
1165#define VM_MAP_COPYIN_ALL_FLAGS 0x00000007
1166extern kern_return_t vm_map_copyin_internal(
1167 vm_map_t src_map,
1168 vm_map_address_t src_addr,
1169 vm_map_size_t len,
1170 int flags,
1171 vm_map_copy_t *copy_result); /* OUT */
1172
39236c6e
A
1173extern kern_return_t vm_map_copy_extract(
1174 vm_map_t src_map,
1175 vm_map_address_t src_addr,
1176 vm_map_size_t len,
1177 vm_map_copy_t *copy_result, /* OUT */
1178 vm_prot_t *cur_prot, /* OUT */
1179 vm_prot_t *max_prot);
1180
1181
0c530ab8
A
1182extern void vm_map_disable_NX(
1183 vm_map_t map);
1184
6d2010ae
A
1185extern void vm_map_disallow_data_exec(
1186 vm_map_t map);
1187
0c530ab8
A
1188extern void vm_map_set_64bit(
1189 vm_map_t map);
1190
1191extern void vm_map_set_32bit(
1192 vm_map_t map);
1193
316670eb
A
1194extern boolean_t vm_map_has_hard_pagezero(
1195 vm_map_t map,
1196 vm_map_offset_t pagezero_size);
1197
2d21ac55
A
1198extern boolean_t vm_map_is_64bit(
1199 vm_map_t map);
1200
0c530ab8 1201
316670eb
A
1202extern kern_return_t vm_map_raise_max_offset(
1203 vm_map_t map,
1204 vm_map_offset_t new_max_offset);
1205
0c530ab8
A
1206extern kern_return_t vm_map_raise_min_offset(
1207 vm_map_t map,
1208 vm_map_offset_t new_min_offset);
1209
1210extern vm_map_offset_t vm_compute_max_offset(
3e170ce0 1211 boolean_t is64);
0c530ab8 1212
39236c6e
A
1213extern uint64_t vm_map_get_max_aslr_slide_pages(
1214 vm_map_t map);
1215
2d21ac55
A
1216extern void vm_map_set_user_wire_limit(
1217 vm_map_t map,
1218 vm_size_t limit);
1219
b0d623f7
A
1220extern void vm_map_switch_protect(
1221 vm_map_t map,
1222 boolean_t val);
1223
39236c6e
A
1224extern void vm_map_iokit_mapped_region(
1225 vm_map_t map,
1226 vm_size_t bytes);
1227
1228extern void vm_map_iokit_unmapped_region(
1229 vm_map_t map,
1230 vm_size_t bytes);
1231
1232
6d2010ae
A
1233extern boolean_t first_free_is_valid(vm_map_t);
1234
39236c6e
A
1235extern int vm_map_page_shift(
1236 vm_map_t map);
1237
3e170ce0 1238extern vm_map_offset_t vm_map_page_mask(
39236c6e
A
1239 vm_map_t map);
1240
1241extern int vm_map_page_size(
1242 vm_map_t map);
1243
1244extern vm_map_offset_t vm_map_round_page_mask(
1245 vm_map_offset_t offset,
1246 vm_map_offset_t mask);
1247
1248extern vm_map_offset_t vm_map_trunc_page_mask(
1249 vm_map_offset_t offset,
1250 vm_map_offset_t mask);
1251
3e170ce0
A
1252extern boolean_t vm_map_page_aligned(
1253 vm_map_offset_t offset,
1254 vm_map_offset_t mask);
1255
b0d623f7
A
1256#ifdef XNU_KERNEL_PRIVATE
1257extern kern_return_t vm_map_page_info(
1258 vm_map_t map,
1259 vm_map_offset_t offset,
1260 vm_page_info_flavor_t flavor,
1261 vm_page_info_t info,
1262 mach_msg_type_number_t *count);
1263#endif /* XNU_KERNEL_PRIVATE */
1264
593a1d5f 1265
2d21ac55
A
1266#ifdef MACH_KERNEL_PRIVATE
1267
1c79356b
A
1268/*
1269 * Macros to invoke vm_map_copyin_common. vm_map_copyin is the
1270 * usual form; it handles a copyin based on the current protection
1271 * (current protection == VM_PROT_NONE) is a failure.
1272 * vm_map_copyin_maxprot handles a copyin based on maximum possible
1273 * access. The difference is that a region with no current access
1274 * BUT possible maximum access is rejected by vm_map_copyin(), but
1275 * returned by vm_map_copyin_maxprot.
1276 */
1277#define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \
1278 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
1279 FALSE, copy_result, FALSE)
1280
1281#define vm_map_copyin_maxprot(src_map, \
1282 src_addr, len, src_destroy, copy_result) \
1283 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
1284 FALSE, copy_result, TRUE)
1285
39236c6e
A
1286
1287/*
1288 * Internal macros for rounding and truncation of vm_map offsets and sizes
1289 */
1290#define VM_MAP_ROUND_PAGE(x,pgmask) (((vm_map_offset_t)(x) + (pgmask)) & ~((signed)(pgmask)))
1291#define VM_MAP_TRUNC_PAGE(x,pgmask) ((vm_map_offset_t)(x) & ~((signed)(pgmask)))
2d21ac55 1292
91447636
A
1293/*
1294 * Macros for rounding and truncation of vm_map offsets and sizes
1295 */
39236c6e
A
1296#define VM_MAP_PAGE_SHIFT(map) ((map) ? (map)->hdr.page_shift : PAGE_SHIFT)
1297#define VM_MAP_PAGE_SIZE(map) (1 << VM_MAP_PAGE_SHIFT((map)))
1298#define VM_MAP_PAGE_MASK(map) (VM_MAP_PAGE_SIZE((map)) - 1)
1299#define VM_MAP_PAGE_ALIGNED(x,pgmask) (((x) & (pgmask)) == 0)
1300
1301#endif /* MACH_KERNEL_PRIVATE */
1302
1303#ifdef XNU_KERNEL_PRIVATE
1304extern kern_return_t vm_map_set_page_shift(vm_map_t map, int pageshift);
1305#endif /* XNU_KERNEL_PRIVATE */
1306
1307#define vm_map_round_page(x,pgmask) (((vm_map_offset_t)(x) + (pgmask)) & ~((signed)(pgmask)))
1308#define vm_map_trunc_page(x,pgmask) ((vm_map_offset_t)(x) & ~((signed)(pgmask)))
91447636 1309
1c79356b
A
1310/*
1311 * Flags for vm_map_remove() and vm_map_delete()
1312 */
1313#define VM_MAP_NO_FLAGS 0x0
1314#define VM_MAP_REMOVE_KUNWIRE 0x1
1315#define VM_MAP_REMOVE_INTERRUPTIBLE 0x2
1316#define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4
91447636 1317#define VM_MAP_REMOVE_SAVE_ENTRIES 0x8
2d21ac55 1318#define VM_MAP_REMOVE_NO_PMAP_CLEANUP 0x10
fe8ab488 1319#define VM_MAP_REMOVE_NO_MAP_ALIGN 0x20
3e170ce0 1320#define VM_MAP_REMOVE_NO_UNNESTING 0x40
91447636
A
1321
1322/* Support for UPLs from vm_maps */
1323
1324extern kern_return_t vm_map_get_upl(
1325 vm_map_t target_map,
cc9f6e38 1326 vm_map_offset_t map_offset,
b0d623f7 1327 upl_size_t *size,
91447636
A
1328 upl_t *upl,
1329 upl_page_info_array_t page_info,
3e170ce0
A
1330 unsigned int *page_infoCnt,
1331 upl_control_flags_t *flags,
1332 int force_data_sync);
1333
1334extern void
1335vm_map_sizes(vm_map_t map,
1336 vm_map_size_t * psize,
1337 vm_map_size_t * pfree,
1338 vm_map_size_t * plargest_free);
91447636 1339
b7266188
A
1340#if CONFIG_DYNAMIC_CODE_SIGNING
1341extern kern_return_t vm_map_sign(vm_map_t map,
1342 vm_map_offset_t start,
1343 vm_map_offset_t end);
1344#endif
1345
fe8ab488
A
1346extern kern_return_t vm_map_partial_reap(
1347 vm_map_t map,
1348 unsigned int *reclaimed_resident,
1349 unsigned int *reclaimed_compressed);
1350
6d2010ae 1351#if CONFIG_FREEZE
316670eb
A
1352void vm_map_freeze_thaw_init(void);
1353void vm_map_freeze_thaw(void);
1354void vm_map_demand_fault(void);
1355
6d2010ae
A
1356extern kern_return_t vm_map_freeze_walk(
1357 vm_map_t map,
1358 unsigned int *purgeable_count,
1359 unsigned int *wired_count,
1360 unsigned int *clean_count,
1361 unsigned int *dirty_count,
316670eb 1362 unsigned int dirty_budget,
6d2010ae
A
1363 boolean_t *has_shared);
1364
1365extern kern_return_t vm_map_freeze(
1366 vm_map_t map,
1367 unsigned int *purgeable_count,
1368 unsigned int *wired_count,
1369 unsigned int *clean_count,
1370 unsigned int *dirty_count,
316670eb 1371 unsigned int dirty_budget,
6d2010ae
A
1372 boolean_t *has_shared);
1373
316670eb 1374extern kern_return_t vm_map_thaw(
6d2010ae
A
1375 vm_map_t map);
1376#endif
1377
91447636
A
1378__END_DECLS
1379
1380#endif /* KERNEL_PRIVATE */
1c79356b 1381
1c79356b 1382#endif /* _VM_VM_MAP_H_ */