]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_map.h
xnu-1228.15.4.tar.gz
[apple/xnu.git] / osfmk / vm / vm_map.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 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>
108#include <kern/lock.h>
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
117/*
118 * Types defined:
119 *
120 * vm_map_t the high-level address map data structure.
121 * vm_map_entry_t an entry in an address map.
122 * vm_map_version_t a timestamp of a map, for use with vm_map_lookup
123 * vm_map_copy_t represents memory copied from an address map,
124 * used for inter-map copy operations
125 */
9bccf70c 126typedef struct vm_map_entry *vm_map_entry_t;
91447636 127#define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0)
9bccf70c 128
1c79356b
A
129
130/*
131 * Type: vm_map_object_t [internal use only]
132 *
133 * Description:
134 * The target of an address mapping, either a virtual
135 * memory object or a sub map (of the kernel map).
136 */
137typedef union vm_map_object {
91447636
A
138 vm_object_t vm_object; /* object object */
139 vm_map_t sub_map; /* belongs to another map */
1c79356b
A
140} vm_map_object_t;
141
91447636 142#define named_entry_lock_init(object) mutex_init(&(object)->Lock, 0)
1c79356b
A
143#define named_entry_lock(object) mutex_lock(&(object)->Lock)
144#define named_entry_unlock(object) mutex_unlock(&(object)->Lock)
145
146/*
147 * Type: vm_named_entry_t [internal use only]
148 *
149 * Description:
150 * Description of a mapping to a memory cache object.
151 *
152 * Implementation:
153 * While the handle to this object is used as a means to map
154 * and pass around the right to map regions backed by pagers
155 * of all sorts, the named_entry itself is only manipulated
156 * by the kernel. Named entries hold information on the
157 * right to map a region of a cached object. Namely,
158 * the target cache object, the beginning and ending of the
159 * region to be mapped, and the permissions, (read, write)
160 * with which it can be mapped.
161 *
162 */
163
164struct vm_named_entry {
165 decl_mutex_data(, Lock) /* Synchronization */
1c79356b 166 union {
91447636
A
167 vm_object_t object; /* object I point to */
168 memory_object_t pager; /* amo pager port */
169 vm_map_t map; /* map backing submap */
1c79356b 170 } backing;
91447636
A
171 vm_object_offset_t offset; /* offset into object */
172 vm_object_size_t size; /* size of region */
173 vm_prot_t protection; /* access permissions */
1c79356b 174 int ref_count; /* Number of references */
91447636
A
175 unsigned int /* Is backing.xxx : */
176 /* boolean_t */ internal:1, /* ... an internal object */
177 /* boolean_t */ is_sub_map:1, /* ... a submap? */
178 /* boolean_t */ is_pager:1; /* ... a pager port */
1c79356b
A
179};
180
1c79356b
A
181/*
182 * Type: vm_map_entry_t [internal use only]
183 *
184 * Description:
185 * A single mapping within an address map.
186 *
187 * Implementation:
188 * Address map entries consist of start and end addresses,
189 * a VM object (or sub map) and offset into that object,
190 * and user-exported inheritance and protection information.
191 * Control information for virtual copy operations is also
192 * stored in the address map entry.
193 */
194struct vm_map_links {
195 struct vm_map_entry *prev; /* previous entry */
196 struct vm_map_entry *next; /* next entry */
91447636
A
197 vm_map_offset_t start; /* start address */
198 vm_map_offset_t end; /* end address */
1c79356b
A
199};
200
201struct vm_map_entry {
202 struct vm_map_links links; /* links to other entries */
203#define vme_prev links.prev
204#define vme_next links.next
205#define vme_start links.start
206#define vme_end links.end
207 union vm_map_object object; /* object I point to */
208 vm_object_offset_t offset; /* offset into object */
209 unsigned int
210 /* boolean_t */ is_shared:1, /* region is shared */
211 /* boolean_t */ is_sub_map:1, /* Is "object" a submap? */
212 /* boolean_t */ in_transition:1, /* Entry being changed */
213 /* boolean_t */ needs_wakeup:1, /* Waiters on in_transition */
214 /* vm_behavior_t */ behavior:2, /* user paging behavior hint */
215 /* behavior is not defined for submap type */
216 /* boolean_t */ needs_copy:1, /* object need to be copied? */
217 /* Only in task maps: */
218 /* vm_prot_t */ protection:3, /* protection code */
219 /* vm_prot_t */ max_protection:3,/* maximum protection */
220 /* vm_inherit_t */ inheritance:2, /* inheritance */
91447636
A
221 /* boolean_t */ use_pmap:1, /* nested pmaps */
222 /* unsigned char */ alias:8, /* user alias */
2d21ac55
A
223 /* boolean_t */ no_cache:1, /* should new pages be cached? */
224 /* unsigned char */ pad:7; /* available bits */
1c79356b
A
225 unsigned short wired_count; /* can be paged if = 0 */
226 unsigned short user_wired_count; /* for vm_wire */
227};
228
229/*
230 * wired_counts are unsigned short. This value is used to safeguard
231 * against any mishaps due to runaway user programs.
232 */
233#define MAX_WIRE_COUNT 65535
234
235
236
237/*
238 * Type: struct vm_map_header
239 *
240 * Description:
241 * Header for a vm_map and a vm_map_copy.
242 */
243struct vm_map_header {
244 struct vm_map_links links; /* first, last, min, max */
245 int nentries; /* Number of entries */
246 boolean_t entries_pageable;
247 /* are map entries pageable? */
248};
249
250/*
251 * Type: vm_map_t [exported; contents invisible]
252 *
253 * Description:
254 * An address map -- a directory relating valid
255 * regions of a task's address space to the corresponding
256 * virtual memory objects.
257 *
258 * Implementation:
259 * Maps are doubly-linked lists of map entries, sorted
260 * by address. One hint is used to start
261 * searches again from the last successful search,
262 * insertion, or removal. Another hint is used to
263 * quickly find free space.
264 */
2d21ac55 265struct _vm_map {
1c79356b
A
266 lock_t lock; /* uni- and smp-lock */
267 struct vm_map_header hdr; /* Map entry header */
268#define min_offset hdr.links.start /* start of range */
269#define max_offset hdr.links.end /* end of range */
270 pmap_t pmap; /* Physical map */
91447636 271 vm_map_size_t size; /* virtual size */
2d21ac55
A
272 vm_map_size_t user_wire_limit;/* rlimit on user locked memory */
273 vm_map_size_t user_wire_size; /* current size of user locked memory in this map */
1c79356b
A
274 int ref_count; /* Reference count */
275#if TASK_SWAPPER
276 int res_count; /* Residence count (swap) */
277 int sw_state; /* Swap state */
278#endif /* TASK_SWAPPER */
2d21ac55 279 decl_mutex_data(, s_lock) /* Lock ref, res fields */
1c79356b
A
280 vm_map_entry_t hint; /* hint for quick lookups */
281 vm_map_entry_t first_free; /* First free space hint */
282 boolean_t wait_for_space; /* Should callers wait
283 for space? */
284 boolean_t wiring_required;/* All memory wired? */
285 boolean_t no_zero_fill; /* No zero fill absent pages */
9bccf70c 286 boolean_t mapped; /* has this map been mapped */
593a1d5f 287 boolean_t prot_copy_allow;/* is VM_PROT_COPY allowed on this map */
1c79356b 288 unsigned int timestamp; /* Version number */
2d21ac55 289 unsigned int color_rr; /* next color (not protected by a lock) */
1c79356b
A
290} ;
291
292#define vm_map_to_entry(map) ((struct vm_map_entry *) &(map)->hdr.links)
293#define vm_map_first_entry(map) ((map)->hdr.links.next)
294#define vm_map_last_entry(map) ((map)->hdr.links.prev)
295
296#if TASK_SWAPPER
297/*
298 * VM map swap states. There are no transition states.
299 */
300#define MAP_SW_IN 1 /* map is swapped in; residence count > 0 */
301#define MAP_SW_OUT 2 /* map is out (res_count == 0 */
302#endif /* TASK_SWAPPER */
303
304/*
305 * Type: vm_map_version_t [exported; contents invisible]
306 *
307 * Description:
308 * Map versions may be used to quickly validate a previous
309 * lookup operation.
310 *
311 * Usage note:
312 * Because they are bulky objects, map versions are usually
313 * passed by reference.
314 *
315 * Implementation:
316 * Just a timestamp for the main map.
317 */
318typedef struct vm_map_version {
319 unsigned int main_timestamp;
320} vm_map_version_t;
321
322/*
323 * Type: vm_map_copy_t [exported; contents invisible]
324 *
325 * Description:
326 * A map copy object represents a region of virtual memory
327 * that has been copied from an address map but is still
328 * in transit.
329 *
330 * A map copy object may only be used by a single thread
331 * at a time.
332 *
333 * Implementation:
334 * There are three formats for map copy objects.
335 * The first is very similar to the main
336 * address map in structure, and as a result, some
337 * of the internal maintenance functions/macros can
338 * be used with either address maps or map copy objects.
339 *
340 * The map copy object contains a header links
341 * entry onto which the other entries that represent
342 * the region are chained.
343 *
91447636
A
344 * The second format is a single vm object. This was used
345 * primarily in the pageout path - but is not currently used
346 * except for placeholder copy objects (see vm_map_copy_copy()).
347 *
348 * The third format is a kernel buffer copy object - for data
349 * small enough that physical copies were the most efficient
350 * method.
1c79356b 351 */
1c79356b
A
352
353struct vm_map_copy {
354 int type;
355#define VM_MAP_COPY_ENTRY_LIST 1
356#define VM_MAP_COPY_OBJECT 2
0b4e3aa0 357#define VM_MAP_COPY_KERNEL_BUFFER 3
1c79356b 358 vm_object_offset_t offset;
91447636 359 vm_map_size_t size;
1c79356b
A
360 union {
361 struct vm_map_header hdr; /* ENTRY_LIST */
91447636
A
362 vm_object_t object; /* OBJECT */
363 struct {
364 void *kdata; /* KERNEL_BUFFER */
1c79356b
A
365 vm_size_t kalloc_size; /* size of this copy_t */
366 } c_k;
367 } c_u;
368};
369
370
371#define cpy_hdr c_u.hdr
372
91447636 373#define cpy_object c_u.object
1c79356b 374
1c79356b
A
375#define cpy_kdata c_u.c_k.kdata
376#define cpy_kalloc_size c_u.c_k.kalloc_size
377
378
379/*
380 * Useful macros for entry list copy objects
381 */
382
383#define vm_map_copy_to_entry(copy) \
384 ((struct vm_map_entry *) &(copy)->cpy_hdr.links)
385#define vm_map_copy_first_entry(copy) \
386 ((copy)->cpy_hdr.links.next)
387#define vm_map_copy_last_entry(copy) \
388 ((copy)->cpy_hdr.links.prev)
389
1c79356b
A
390/*
391 * Macros: vm_map_lock, etc. [internal use only]
392 * Description:
393 * Perform locking on the data portion of a map.
394 * When multiple maps are to be locked, order by map address.
395 * (See vm_map.c::vm_remap())
396 */
397
398#define vm_map_lock_init(map) \
9bccf70c 399 ((map)->timestamp = 0 , \
91447636 400 lock_init(&(map)->lock, TRUE, 0, 0))
9bccf70c
A
401
402#define vm_map_lock(map) lock_write(&(map)->lock)
403#define vm_map_unlock(map) \
404 ((map)->timestamp++ , lock_write_done(&(map)->lock))
405#define vm_map_lock_read(map) lock_read(&(map)->lock)
406#define vm_map_unlock_read(map) lock_read_done(&(map)->lock)
1c79356b 407#define vm_map_lock_write_to_read(map) \
9bccf70c 408 ((map)->timestamp++ , lock_write_to_read(&(map)->lock))
2d21ac55
A
409/* lock_read_to_write() returns FALSE on failure. Macro evaluates to
410 * zero on success and non-zero value on failure.
411 */
412#define vm_map_lock_read_to_write(map) (lock_read_to_write(&(map)->lock) != TRUE)
1c79356b 413
1c79356b
A
414/*
415 * Exported procedures that operate on vm_map_t.
416 */
417
418/* Initialize the module */
2d21ac55 419extern void vm_map_init(void) __attribute__((section("__TEXT, initcode")));
1c79356b
A
420
421/* Allocate a range in the specified virtual address map and
422 * return the entry allocated for that range. */
423extern kern_return_t vm_map_find_space(
91447636
A
424 vm_map_t map,
425 vm_map_address_t *address, /* OUT */
426 vm_map_size_t size,
427 vm_map_offset_t mask,
0c530ab8 428 int flags,
91447636 429 vm_map_entry_t *o_entry); /* OUT */
1c79356b
A
430
431/* Lookup map entry containing or the specified address in the given map */
432extern boolean_t vm_map_lookup_entry(
91447636
A
433 vm_map_t map,
434 vm_map_address_t address,
435 vm_map_entry_t *entry); /* OUT */
1c79356b 436
1c79356b
A
437/* Find the VM object, offset, and protection for a given virtual address
438 * in the specified map, assuming a page fault of the type specified. */
439extern kern_return_t vm_map_lookup_locked(
91447636
A
440 vm_map_t *var_map, /* IN/OUT */
441 vm_map_address_t vaddr,
442 vm_prot_t fault_type,
2d21ac55 443 int object_lock_type,
91447636
A
444 vm_map_version_t *out_version, /* OUT */
445 vm_object_t *object, /* OUT */
446 vm_object_offset_t *offset, /* OUT */
447 vm_prot_t *out_prot, /* OUT */
448 boolean_t *wired, /* OUT */
2d21ac55 449 vm_object_fault_info_t fault_info, /* OUT */
91447636 450 vm_map_t *real_map); /* OUT */
1c79356b
A
451
452/* Verifies that the map has not changed since the given version. */
453extern boolean_t vm_map_verify(
91447636
A
454 vm_map_t map,
455 vm_map_version_t *version); /* REF */
1c79356b
A
456
457extern vm_map_entry_t vm_map_entry_insert(
458 vm_map_t map,
459 vm_map_entry_t insp_entry,
91447636
A
460 vm_map_offset_t start,
461 vm_map_offset_t end,
1c79356b
A
462 vm_object_t object,
463 vm_object_offset_t offset,
464 boolean_t needs_copy,
465 boolean_t is_shared,
466 boolean_t in_transition,
467 vm_prot_t cur_protection,
468 vm_prot_t max_protection,
469 vm_behavior_t behavior,
470 vm_inherit_t inheritance,
2d21ac55
A
471 unsigned wired_count,
472 boolean_t no_cache);
1c79356b 473
1c79356b
A
474
475/*
476 * Functions implemented as macros
477 */
91447636 478#define vm_map_min(map) ((map)->min_offset)
1c79356b
A
479 /* Lowest valid address in
480 * a map */
481
91447636 482#define vm_map_max(map) ((map)->max_offset)
1c79356b
A
483 /* Highest valid address */
484
485#define vm_map_pmap(map) ((map)->pmap)
486 /* Physical map associated
487 * with this address map */
488
489#define vm_map_verify_done(map, version) vm_map_unlock_read(map)
490 /* Operation that required
491 * a verified lookup is
492 * now complete */
493
494/*
495 * Macros/functions for map residence counts and swapin/out of vm maps
496 */
497#if TASK_SWAPPER
498
499#if MACH_ASSERT
500/* Gain a reference to an existing map */
501extern void vm_map_reference(
502 vm_map_t map);
503/* Lose a residence count */
504extern void vm_map_res_deallocate(
505 vm_map_t map);
506/* Gain a residence count on a map */
507extern void vm_map_res_reference(
508 vm_map_t map);
509/* Gain reference & residence counts to possibly swapped-out map */
510extern void vm_map_reference_swap(
511 vm_map_t map);
512
513#else /* MACH_ASSERT */
514
91447636 515#define vm_map_reference(map) \
1c79356b 516MACRO_BEGIN \
91447636 517 vm_map_t Map = (map); \
1c79356b
A
518 if (Map) { \
519 mutex_lock(&Map->s_lock); \
520 Map->res_count++; \
521 Map->ref_count++; \
522 mutex_unlock(&Map->s_lock); \
523 } \
524MACRO_END
525
526#define vm_map_res_reference(map) \
527MACRO_BEGIN \
91447636 528 vm_map_t Lmap = (map); \
1c79356b 529 if (Lmap->res_count == 0) { \
91447636 530 mutex_unlock(&Lmap->s_lock);\
1c79356b
A
531 vm_map_lock(Lmap); \
532 vm_map_swapin(Lmap); \
533 mutex_lock(&Lmap->s_lock); \
534 ++Lmap->res_count; \
535 vm_map_unlock(Lmap); \
536 } else \
537 ++Lmap->res_count; \
538MACRO_END
539
540#define vm_map_res_deallocate(map) \
541MACRO_BEGIN \
91447636
A
542 vm_map_t Map = (map); \
543 if (--Map->res_count == 0) { \
1c79356b
A
544 mutex_unlock(&Map->s_lock); \
545 vm_map_lock(Map); \
546 vm_map_swapout(Map); \
547 vm_map_unlock(Map); \
548 mutex_lock(&Map->s_lock); \
549 } \
550MACRO_END
551
552#define vm_map_reference_swap(map) \
553MACRO_BEGIN \
554 vm_map_t Map = (map); \
555 mutex_lock(&Map->s_lock); \
556 ++Map->ref_count; \
557 vm_map_res_reference(Map); \
558 mutex_unlock(&Map->s_lock); \
559MACRO_END
560#endif /* MACH_ASSERT */
561
562extern void vm_map_swapin(
563 vm_map_t map);
564
565extern void vm_map_swapout(
566 vm_map_t map);
567
568#else /* TASK_SWAPPER */
569
570#define vm_map_reference(map) \
571MACRO_BEGIN \
572 vm_map_t Map = (map); \
573 if (Map) { \
574 mutex_lock(&Map->s_lock); \
575 Map->ref_count++; \
576 mutex_unlock(&Map->s_lock); \
577 } \
578MACRO_END
579
580#define vm_map_reference_swap(map) vm_map_reference(map)
581#define vm_map_res_reference(map)
582#define vm_map_res_deallocate(map)
583
584#endif /* TASK_SWAPPER */
585
586/*
587 * Submap object. Must be used to create memory to be put
588 * in a submap by vm_map_submap.
589 */
590extern vm_object_t vm_submap_object;
591
592/*
593 * Wait and wakeup macros for in_transition map entries.
594 */
595#define vm_map_entry_wait(map, interruptible) \
9bccf70c
A
596 ((map)->timestamp++ , \
597 thread_sleep_lock_write((event_t)&(map)->hdr, \
598 &(map)->lock, interruptible))
1c79356b 599
1c79356b 600
91447636
A
601#define vm_map_entry_wakeup(map) \
602 thread_wakeup((event_t)(&(map)->hdr))
1c79356b
A
603
604
91447636 605#define vm_map_ref_fast(map) \
1c79356b
A
606 MACRO_BEGIN \
607 mutex_lock(&map->s_lock); \
608 map->ref_count++; \
609 vm_map_res_reference(map); \
610 mutex_unlock(&map->s_lock); \
611 MACRO_END
612
91447636 613#define vm_map_dealloc_fast(map) \
1c79356b 614 MACRO_BEGIN \
91447636 615 register int c; \
1c79356b
A
616 \
617 mutex_lock(&map->s_lock); \
91447636 618 c = --map->ref_count; \
1c79356b
A
619 if (c > 0) \
620 vm_map_res_deallocate(map); \
621 mutex_unlock(&map->s_lock); \
622 if (c == 0) \
623 vm_map_destroy(map); \
624 MACRO_END
625
626
627/* simplify map entries */
5353443c
A
628extern void vm_map_simplify_entry(
629 vm_map_t map,
630 vm_map_entry_t this_entry);
1c79356b 631extern void vm_map_simplify(
91447636
A
632 vm_map_t map,
633 vm_map_offset_t start);
1c79356b
A
634
635/* Move the information in a map copy object to a new map copy object */
636extern vm_map_copy_t vm_map_copy_copy(
91447636 637 vm_map_copy_t copy);
1c79356b 638
1c79356b
A
639/* Create a copy object from an object. */
640extern kern_return_t vm_map_copyin_object(
641 vm_object_t object,
642 vm_object_offset_t offset,
643 vm_object_size_t size,
644 vm_map_copy_t *copy_result); /* OUT */
645
1c79356b
A
646/* Enter a mapping */
647extern kern_return_t vm_map_enter(
648 vm_map_t map,
91447636
A
649 vm_map_offset_t *address,
650 vm_map_size_t size,
651 vm_map_offset_t mask,
1c79356b
A
652 int flags,
653 vm_object_t object,
654 vm_object_offset_t offset,
655 boolean_t needs_copy,
656 vm_prot_t cur_protection,
657 vm_prot_t max_protection,
658 vm_inherit_t inheritance);
659
91447636
A
660/* XXX should go away - replaced with regular enter of contig object */
661extern kern_return_t vm_map_enter_cpm(
662 vm_map_t map,
663 vm_map_address_t *addr,
664 vm_map_size_t size,
665 int flags);
666
667extern kern_return_t vm_map_remap(
668 vm_map_t target_map,
669 vm_map_offset_t *address,
670 vm_map_size_t size,
671 vm_map_offset_t mask,
672 boolean_t anywhere,
673 vm_map_t src_map,
674 vm_map_offset_t memory_address,
675 boolean_t copy,
676 vm_prot_t *cur_protection,
677 vm_prot_t *max_protection,
678 vm_inherit_t inheritance);
679
680
681/*
682 * Read and write from a kernel buffer to a specified map.
683 */
1c79356b 684extern kern_return_t vm_map_write_user(
91447636
A
685 vm_map_t map,
686 void *src_p,
687 vm_map_offset_t dst_addr,
688 vm_size_t size);
1c79356b
A
689
690extern kern_return_t vm_map_read_user(
91447636
A
691 vm_map_t map,
692 vm_map_offset_t src_addr,
693 void *dst_p,
694 vm_size_t size);
1c79356b
A
695
696/* Create a new task map using an existing task map as a template. */
697extern vm_map_t vm_map_fork(
91447636 698 vm_map_t old_map);
1c79356b 699
9bccf70c
A
700/* Change inheritance */
701extern kern_return_t vm_map_inherit(
91447636
A
702 vm_map_t map,
703 vm_map_offset_t start,
704 vm_map_offset_t end,
705 vm_inherit_t new_inheritance);
1c79356b 706
9bccf70c
A
707/* Add or remove machine-dependent attributes from map regions */
708extern kern_return_t vm_map_machine_attribute(
91447636
A
709 vm_map_t map,
710 vm_map_offset_t start,
711 vm_map_offset_t end,
9bccf70c
A
712 vm_machine_attribute_t attribute,
713 vm_machine_attribute_val_t* value); /* IN/OUT */
91447636
A
714
715extern kern_return_t vm_map_msync(
716 vm_map_t map,
717 vm_map_address_t address,
718 vm_map_size_t size,
719 vm_sync_t sync_flags);
720
9bccf70c
A
721/* Set paging behavior */
722extern kern_return_t vm_map_behavior_set(
91447636
A
723 vm_map_t map,
724 vm_map_offset_t start,
725 vm_map_offset_t end,
726 vm_behavior_t new_behavior);
727
728extern kern_return_t vm_map_purgable_control(
729 vm_map_t map,
730 vm_map_offset_t address,
731 vm_purgable_t control,
732 int *state);
733
734extern kern_return_t vm_map_region(
735 vm_map_t map,
736 vm_map_offset_t *address,
737 vm_map_size_t *size,
738 vm_region_flavor_t flavor,
739 vm_region_info_t info,
740 mach_msg_type_number_t *count,
741 mach_port_t *object_name);
742
743extern kern_return_t vm_map_region_recurse_64(
744 vm_map_t map,
745 vm_map_offset_t *address,
746 vm_map_size_t *size,
747 natural_t *nesting_depth,
748 vm_region_submap_info_64_t info,
749 mach_msg_type_number_t *count);
750
751extern kern_return_t vm_map_page_info(
752 vm_map_t map,
753 vm_map_offset_t offset,
754 int *disposition,
755 int *ref_count);
9bccf70c
A
756
757extern kern_return_t vm_map_submap(
91447636
A
758 vm_map_t map,
759 vm_map_offset_t start,
760 vm_map_offset_t end,
761 vm_map_t submap,
762 vm_map_offset_t offset,
763 boolean_t use_pmap);
764
765extern void vm_map_submap_pmap_clean(
766 vm_map_t map,
767 vm_map_offset_t start,
768 vm_map_offset_t end,
769 vm_map_t sub_map,
770 vm_map_offset_t offset);
771
772/* Convert from a map entry port to a map */
773extern vm_map_t convert_port_entry_to_map(
774 ipc_port_t port);
775
776/* Convert from a port to a vm_object */
777extern vm_object_t convert_port_entry_to_object(
778 ipc_port_t port);
9bccf70c
A
779
780
2d21ac55
A
781/* definitions related to overriding the NX behavior */
782
783#define VM_ABI_32 0x1
784#define VM_ABI_64 0x2
785
786extern int override_nx(vm_map_t map, uint32_t user_tag);
787
9bccf70c
A
788#endif /* MACH_KERNEL_PRIVATE */
789
91447636
A
790__BEGIN_DECLS
791
9bccf70c
A
792/* Create an empty map */
793extern vm_map_t vm_map_create(
91447636
A
794 pmap_t pmap,
795 vm_map_offset_t min_off,
796 vm_map_offset_t max_off,
797 boolean_t pageable);
9bccf70c
A
798
799/* Get rid of a map */
800extern void vm_map_destroy(
2d21ac55
A
801 vm_map_t map,
802 int flags);
803
9bccf70c
A
804/* Lose a reference */
805extern void vm_map_deallocate(
91447636
A
806 vm_map_t map);
807
808extern vm_map_t vm_map_switch(
809 vm_map_t map);
9bccf70c
A
810
811/* Change protection */
812extern kern_return_t vm_map_protect(
91447636
A
813 vm_map_t map,
814 vm_map_offset_t start,
815 vm_map_offset_t end,
816 vm_prot_t new_prot,
817 boolean_t set_max);
818
819/* Check protection */
820extern boolean_t vm_map_check_protection(
821 vm_map_t map,
822 vm_map_offset_t start,
823 vm_map_offset_t end,
824 vm_prot_t protection);
1c79356b
A
825
826/* wire down a region */
827extern kern_return_t vm_map_wire(
91447636
A
828 vm_map_t map,
829 vm_map_offset_t start,
830 vm_map_offset_t end,
831 vm_prot_t access_type,
832 boolean_t user_wire);
1c79356b
A
833
834/* unwire a region */
835extern kern_return_t vm_map_unwire(
91447636
A
836 vm_map_t map,
837 vm_map_offset_t start,
838 vm_map_offset_t end,
839 boolean_t user_wire);
1c79356b 840
2d21ac55
A
841/* Enter a mapping of a memory object */
842extern kern_return_t vm_map_enter_mem_object(
843 vm_map_t map,
844 vm_map_offset_t *address,
845 vm_map_size_t size,
846 vm_map_offset_t mask,
847 int flags,
848 ipc_port_t port,
849 vm_object_offset_t offset,
850 boolean_t needs_copy,
851 vm_prot_t cur_protection,
852 vm_prot_t max_protection,
853 vm_inherit_t inheritance);
854
1c79356b
A
855/* Deallocate a region */
856extern kern_return_t vm_map_remove(
91447636
A
857 vm_map_t map,
858 vm_map_offset_t start,
859 vm_map_offset_t end,
860 boolean_t flags);
861
862/* Discard a copy without using it */
863extern void vm_map_copy_discard(
864 vm_map_copy_t copy);
865
866/* Overwrite existing memory with a copy */
867extern kern_return_t vm_map_copy_overwrite(
868 vm_map_t dst_map,
869 vm_map_address_t dst_addr,
870 vm_map_copy_t copy,
871 int interruptible);
1c79356b
A
872
873/* Place a copy into a map */
874extern kern_return_t vm_map_copyout(
91447636
A
875 vm_map_t dst_map,
876 vm_map_address_t *dst_addr, /* OUT */
877 vm_map_copy_t copy);
1c79356b 878
2d21ac55
A
879extern kern_return_t vm_map_copyin(
880 vm_map_t src_map,
881 vm_map_address_t src_addr,
882 vm_map_size_t len,
883 boolean_t src_destroy,
884 vm_map_copy_t *copy_result); /* OUT */
885
1c79356b 886extern kern_return_t vm_map_copyin_common(
91447636
A
887 vm_map_t src_map,
888 vm_map_address_t src_addr,
889 vm_map_size_t len,
890 boolean_t src_destroy,
891 boolean_t src_volatile,
892 vm_map_copy_t *copy_result, /* OUT */
893 boolean_t use_maxprot);
55e303ae 894
0c530ab8
A
895extern void vm_map_disable_NX(
896 vm_map_t map);
897
898extern void vm_map_set_64bit(
899 vm_map_t map);
900
901extern void vm_map_set_32bit(
902 vm_map_t map);
903
2d21ac55
A
904extern boolean_t vm_map_is_64bit(
905 vm_map_t map);
906
0c530ab8
A
907extern boolean_t vm_map_has_4GB_pagezero(
908 vm_map_t map);
909
910extern void vm_map_set_4GB_pagezero(
911 vm_map_t map);
912
913extern void vm_map_clear_4GB_pagezero(
914 vm_map_t map);
915
916extern kern_return_t vm_map_raise_min_offset(
917 vm_map_t map,
918 vm_map_offset_t new_min_offset);
919
920extern vm_map_offset_t vm_compute_max_offset(
921 unsigned is64);
922
2d21ac55
A
923extern void vm_map_set_user_wire_limit(
924 vm_map_t map,
925 vm_size_t limit);
926
593a1d5f
A
927extern void vm_map_set_prot_copy_allow(
928 vm_map_t map,
929 boolean_t allow);
930
2d21ac55
A
931#ifdef MACH_KERNEL_PRIVATE
932
1c79356b
A
933/*
934 * Macros to invoke vm_map_copyin_common. vm_map_copyin is the
935 * usual form; it handles a copyin based on the current protection
936 * (current protection == VM_PROT_NONE) is a failure.
937 * vm_map_copyin_maxprot handles a copyin based on maximum possible
938 * access. The difference is that a region with no current access
939 * BUT possible maximum access is rejected by vm_map_copyin(), but
940 * returned by vm_map_copyin_maxprot.
941 */
942#define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \
943 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
944 FALSE, copy_result, FALSE)
945
946#define vm_map_copyin_maxprot(src_map, \
947 src_addr, len, src_destroy, copy_result) \
948 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
949 FALSE, copy_result, TRUE)
950
2d21ac55
A
951#endif /* MACH_KERNEL_PRIVATE */
952
91447636
A
953/*
954 * Macros for rounding and truncation of vm_map offsets and sizes
955 */
956#define vm_map_round_page(x) (((vm_map_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
957#define vm_map_trunc_page(x) ((vm_map_offset_t)(x) & ~((signed)PAGE_MASK))
958
1c79356b
A
959/*
960 * Flags for vm_map_remove() and vm_map_delete()
961 */
962#define VM_MAP_NO_FLAGS 0x0
963#define VM_MAP_REMOVE_KUNWIRE 0x1
964#define VM_MAP_REMOVE_INTERRUPTIBLE 0x2
965#define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4
91447636 966#define VM_MAP_REMOVE_SAVE_ENTRIES 0x8
2d21ac55 967#define VM_MAP_REMOVE_NO_PMAP_CLEANUP 0x10
91447636
A
968
969/* Support for UPLs from vm_maps */
970
971extern kern_return_t vm_map_get_upl(
972 vm_map_t target_map,
cc9f6e38 973 vm_map_offset_t map_offset,
91447636
A
974 vm_size_t *size,
975 upl_t *upl,
976 upl_page_info_array_t page_info,
977 mach_msg_type_number_t *page_infoCnt,
978 integer_t *flags,
979 integer_t force_data_sync);
980
981__END_DECLS
982
983#endif /* KERNEL_PRIVATE */
1c79356b 984
1c79356b 985#endif /* _VM_VM_MAP_H_ */