]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_map.h
xnu-1228.tar.gz
[apple/xnu.git] / osfmk / vm / vm_map.h
1 /*
2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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>
80 #include <mach/vm_param.h>
81 #include <vm/pmap.h>
82
83 #ifdef KERNEL_PRIVATE
84
85 #include <sys/cdefs.h>
86
87 __BEGIN_DECLS
88
89 extern void vm_map_reference(vm_map_t map);
90 extern vm_map_t current_map(void);
91
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,
96 void *fsroot,
97 cpu_type_t cpu);
98
99 __END_DECLS
100
101 #ifdef MACH_KERNEL_PRIVATE
102
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
112 #include <kern/thread.h>
113
114 #define current_map_fast() (current_thread()->map)
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 */
126 typedef struct vm_map_entry *vm_map_entry_t;
127 #define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0)
128
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 */
137 typedef union vm_map_object {
138 vm_object_t vm_object; /* object object */
139 vm_map_t sub_map; /* belongs to another map */
140 } vm_map_object_t;
141
142 #define named_entry_lock_init(object) mutex_init(&(object)->Lock, 0)
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
164 struct vm_named_entry {
165 decl_mutex_data(, Lock) /* Synchronization */
166 union {
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 */
170 } backing;
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 */
174 int ref_count; /* Number of references */
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 */
179 };
180
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 */
194 struct vm_map_links {
195 struct vm_map_entry *prev; /* previous entry */
196 struct vm_map_entry *next; /* next entry */
197 vm_map_offset_t start; /* start address */
198 vm_map_offset_t end; /* end address */
199 };
200
201 struct 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 */
221 /* boolean_t */ use_pmap:1, /* nested pmaps */
222 /* unsigned char */ alias:8, /* user alias */
223 /* boolean_t */ no_cache:1, /* should new pages be cached? */
224 /* unsigned char */ pad:7; /* available bits */
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 */
243 struct 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 */
265 struct _vm_map {
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 */
271 vm_map_size_t size; /* virtual size */
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 */
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 */
279 decl_mutex_data(, s_lock) /* Lock ref, res fields */
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 */
286 boolean_t mapped; /* has this map been mapped */
287 unsigned int timestamp; /* Version number */
288 unsigned int color_rr; /* next color (not protected by a lock) */
289 } ;
290
291 #define vm_map_to_entry(map) ((struct vm_map_entry *) &(map)->hdr.links)
292 #define vm_map_first_entry(map) ((map)->hdr.links.next)
293 #define vm_map_last_entry(map) ((map)->hdr.links.prev)
294
295 #if TASK_SWAPPER
296 /*
297 * VM map swap states. There are no transition states.
298 */
299 #define MAP_SW_IN 1 /* map is swapped in; residence count > 0 */
300 #define MAP_SW_OUT 2 /* map is out (res_count == 0 */
301 #endif /* TASK_SWAPPER */
302
303 /*
304 * Type: vm_map_version_t [exported; contents invisible]
305 *
306 * Description:
307 * Map versions may be used to quickly validate a previous
308 * lookup operation.
309 *
310 * Usage note:
311 * Because they are bulky objects, map versions are usually
312 * passed by reference.
313 *
314 * Implementation:
315 * Just a timestamp for the main map.
316 */
317 typedef struct vm_map_version {
318 unsigned int main_timestamp;
319 } vm_map_version_t;
320
321 /*
322 * Type: vm_map_copy_t [exported; contents invisible]
323 *
324 * Description:
325 * A map copy object represents a region of virtual memory
326 * that has been copied from an address map but is still
327 * in transit.
328 *
329 * A map copy object may only be used by a single thread
330 * at a time.
331 *
332 * Implementation:
333 * There are three formats for map copy objects.
334 * The first is very similar to the main
335 * address map in structure, and as a result, some
336 * of the internal maintenance functions/macros can
337 * be used with either address maps or map copy objects.
338 *
339 * The map copy object contains a header links
340 * entry onto which the other entries that represent
341 * the region are chained.
342 *
343 * The second format is a single vm object. This was used
344 * primarily in the pageout path - but is not currently used
345 * except for placeholder copy objects (see vm_map_copy_copy()).
346 *
347 * The third format is a kernel buffer copy object - for data
348 * small enough that physical copies were the most efficient
349 * method.
350 */
351
352 struct vm_map_copy {
353 int type;
354 #define VM_MAP_COPY_ENTRY_LIST 1
355 #define VM_MAP_COPY_OBJECT 2
356 #define VM_MAP_COPY_KERNEL_BUFFER 3
357 vm_object_offset_t offset;
358 vm_map_size_t size;
359 union {
360 struct vm_map_header hdr; /* ENTRY_LIST */
361 vm_object_t object; /* OBJECT */
362 struct {
363 void *kdata; /* KERNEL_BUFFER */
364 vm_size_t kalloc_size; /* size of this copy_t */
365 } c_k;
366 } c_u;
367 };
368
369
370 #define cpy_hdr c_u.hdr
371
372 #define cpy_object c_u.object
373
374 #define cpy_kdata c_u.c_k.kdata
375 #define cpy_kalloc_size c_u.c_k.kalloc_size
376
377
378 /*
379 * Useful macros for entry list copy objects
380 */
381
382 #define vm_map_copy_to_entry(copy) \
383 ((struct vm_map_entry *) &(copy)->cpy_hdr.links)
384 #define vm_map_copy_first_entry(copy) \
385 ((copy)->cpy_hdr.links.next)
386 #define vm_map_copy_last_entry(copy) \
387 ((copy)->cpy_hdr.links.prev)
388
389 /*
390 * Macros: vm_map_lock, etc. [internal use only]
391 * Description:
392 * Perform locking on the data portion of a map.
393 * When multiple maps are to be locked, order by map address.
394 * (See vm_map.c::vm_remap())
395 */
396
397 #define vm_map_lock_init(map) \
398 ((map)->timestamp = 0 , \
399 lock_init(&(map)->lock, TRUE, 0, 0))
400
401 #define vm_map_lock(map) lock_write(&(map)->lock)
402 #define vm_map_unlock(map) \
403 ((map)->timestamp++ , lock_write_done(&(map)->lock))
404 #define vm_map_lock_read(map) lock_read(&(map)->lock)
405 #define vm_map_unlock_read(map) lock_read_done(&(map)->lock)
406 #define vm_map_lock_write_to_read(map) \
407 ((map)->timestamp++ , lock_write_to_read(&(map)->lock))
408 /* lock_read_to_write() returns FALSE on failure. Macro evaluates to
409 * zero on success and non-zero value on failure.
410 */
411 #define vm_map_lock_read_to_write(map) (lock_read_to_write(&(map)->lock) != TRUE)
412
413 /*
414 * Exported procedures that operate on vm_map_t.
415 */
416
417 /* Initialize the module */
418 extern void vm_map_init(void) __attribute__((section("__TEXT, initcode")));
419
420 /* Allocate a range in the specified virtual address map and
421 * return the entry allocated for that range. */
422 extern kern_return_t vm_map_find_space(
423 vm_map_t map,
424 vm_map_address_t *address, /* OUT */
425 vm_map_size_t size,
426 vm_map_offset_t mask,
427 int flags,
428 vm_map_entry_t *o_entry); /* OUT */
429
430 /* Lookup map entry containing or the specified address in the given map */
431 extern boolean_t vm_map_lookup_entry(
432 vm_map_t map,
433 vm_map_address_t address,
434 vm_map_entry_t *entry); /* OUT */
435
436 /* Find the VM object, offset, and protection for a given virtual address
437 * in the specified map, assuming a page fault of the type specified. */
438 extern kern_return_t vm_map_lookup_locked(
439 vm_map_t *var_map, /* IN/OUT */
440 vm_map_address_t vaddr,
441 vm_prot_t fault_type,
442 int object_lock_type,
443 vm_map_version_t *out_version, /* OUT */
444 vm_object_t *object, /* OUT */
445 vm_object_offset_t *offset, /* OUT */
446 vm_prot_t *out_prot, /* OUT */
447 boolean_t *wired, /* OUT */
448 vm_object_fault_info_t fault_info, /* OUT */
449 vm_map_t *real_map); /* OUT */
450
451 /* Verifies that the map has not changed since the given version. */
452 extern boolean_t vm_map_verify(
453 vm_map_t map,
454 vm_map_version_t *version); /* REF */
455
456 extern vm_map_entry_t vm_map_entry_insert(
457 vm_map_t map,
458 vm_map_entry_t insp_entry,
459 vm_map_offset_t start,
460 vm_map_offset_t end,
461 vm_object_t object,
462 vm_object_offset_t offset,
463 boolean_t needs_copy,
464 boolean_t is_shared,
465 boolean_t in_transition,
466 vm_prot_t cur_protection,
467 vm_prot_t max_protection,
468 vm_behavior_t behavior,
469 vm_inherit_t inheritance,
470 unsigned wired_count,
471 boolean_t no_cache);
472
473
474 /*
475 * Functions implemented as macros
476 */
477 #define vm_map_min(map) ((map)->min_offset)
478 /* Lowest valid address in
479 * a map */
480
481 #define vm_map_max(map) ((map)->max_offset)
482 /* Highest valid address */
483
484 #define vm_map_pmap(map) ((map)->pmap)
485 /* Physical map associated
486 * with this address map */
487
488 #define vm_map_verify_done(map, version) vm_map_unlock_read(map)
489 /* Operation that required
490 * a verified lookup is
491 * now complete */
492
493 /*
494 * Macros/functions for map residence counts and swapin/out of vm maps
495 */
496 #if TASK_SWAPPER
497
498 #if MACH_ASSERT
499 /* Gain a reference to an existing map */
500 extern void vm_map_reference(
501 vm_map_t map);
502 /* Lose a residence count */
503 extern void vm_map_res_deallocate(
504 vm_map_t map);
505 /* Gain a residence count on a map */
506 extern void vm_map_res_reference(
507 vm_map_t map);
508 /* Gain reference & residence counts to possibly swapped-out map */
509 extern void vm_map_reference_swap(
510 vm_map_t map);
511
512 #else /* MACH_ASSERT */
513
514 #define vm_map_reference(map) \
515 MACRO_BEGIN \
516 vm_map_t Map = (map); \
517 if (Map) { \
518 mutex_lock(&Map->s_lock); \
519 Map->res_count++; \
520 Map->ref_count++; \
521 mutex_unlock(&Map->s_lock); \
522 } \
523 MACRO_END
524
525 #define vm_map_res_reference(map) \
526 MACRO_BEGIN \
527 vm_map_t Lmap = (map); \
528 if (Lmap->res_count == 0) { \
529 mutex_unlock(&Lmap->s_lock);\
530 vm_map_lock(Lmap); \
531 vm_map_swapin(Lmap); \
532 mutex_lock(&Lmap->s_lock); \
533 ++Lmap->res_count; \
534 vm_map_unlock(Lmap); \
535 } else \
536 ++Lmap->res_count; \
537 MACRO_END
538
539 #define vm_map_res_deallocate(map) \
540 MACRO_BEGIN \
541 vm_map_t Map = (map); \
542 if (--Map->res_count == 0) { \
543 mutex_unlock(&Map->s_lock); \
544 vm_map_lock(Map); \
545 vm_map_swapout(Map); \
546 vm_map_unlock(Map); \
547 mutex_lock(&Map->s_lock); \
548 } \
549 MACRO_END
550
551 #define vm_map_reference_swap(map) \
552 MACRO_BEGIN \
553 vm_map_t Map = (map); \
554 mutex_lock(&Map->s_lock); \
555 ++Map->ref_count; \
556 vm_map_res_reference(Map); \
557 mutex_unlock(&Map->s_lock); \
558 MACRO_END
559 #endif /* MACH_ASSERT */
560
561 extern void vm_map_swapin(
562 vm_map_t map);
563
564 extern void vm_map_swapout(
565 vm_map_t map);
566
567 #else /* TASK_SWAPPER */
568
569 #define vm_map_reference(map) \
570 MACRO_BEGIN \
571 vm_map_t Map = (map); \
572 if (Map) { \
573 mutex_lock(&Map->s_lock); \
574 Map->ref_count++; \
575 mutex_unlock(&Map->s_lock); \
576 } \
577 MACRO_END
578
579 #define vm_map_reference_swap(map) vm_map_reference(map)
580 #define vm_map_res_reference(map)
581 #define vm_map_res_deallocate(map)
582
583 #endif /* TASK_SWAPPER */
584
585 /*
586 * Submap object. Must be used to create memory to be put
587 * in a submap by vm_map_submap.
588 */
589 extern vm_object_t vm_submap_object;
590
591 /*
592 * Wait and wakeup macros for in_transition map entries.
593 */
594 #define vm_map_entry_wait(map, interruptible) \
595 ((map)->timestamp++ , \
596 thread_sleep_lock_write((event_t)&(map)->hdr, \
597 &(map)->lock, interruptible))
598
599
600 #define vm_map_entry_wakeup(map) \
601 thread_wakeup((event_t)(&(map)->hdr))
602
603
604 #define vm_map_ref_fast(map) \
605 MACRO_BEGIN \
606 mutex_lock(&map->s_lock); \
607 map->ref_count++; \
608 vm_map_res_reference(map); \
609 mutex_unlock(&map->s_lock); \
610 MACRO_END
611
612 #define vm_map_dealloc_fast(map) \
613 MACRO_BEGIN \
614 register int c; \
615 \
616 mutex_lock(&map->s_lock); \
617 c = --map->ref_count; \
618 if (c > 0) \
619 vm_map_res_deallocate(map); \
620 mutex_unlock(&map->s_lock); \
621 if (c == 0) \
622 vm_map_destroy(map); \
623 MACRO_END
624
625
626 /* simplify map entries */
627 extern void vm_map_simplify_entry(
628 vm_map_t map,
629 vm_map_entry_t this_entry);
630 extern void vm_map_simplify(
631 vm_map_t map,
632 vm_map_offset_t start);
633
634 /* Move the information in a map copy object to a new map copy object */
635 extern vm_map_copy_t vm_map_copy_copy(
636 vm_map_copy_t copy);
637
638 /* Create a copy object from an object. */
639 extern kern_return_t vm_map_copyin_object(
640 vm_object_t object,
641 vm_object_offset_t offset,
642 vm_object_size_t size,
643 vm_map_copy_t *copy_result); /* OUT */
644
645 /* Enter a mapping */
646 extern kern_return_t vm_map_enter(
647 vm_map_t map,
648 vm_map_offset_t *address,
649 vm_map_size_t size,
650 vm_map_offset_t mask,
651 int flags,
652 vm_object_t object,
653 vm_object_offset_t offset,
654 boolean_t needs_copy,
655 vm_prot_t cur_protection,
656 vm_prot_t max_protection,
657 vm_inherit_t inheritance);
658
659 /* XXX should go away - replaced with regular enter of contig object */
660 extern kern_return_t vm_map_enter_cpm(
661 vm_map_t map,
662 vm_map_address_t *addr,
663 vm_map_size_t size,
664 int flags);
665
666 extern kern_return_t vm_map_remap(
667 vm_map_t target_map,
668 vm_map_offset_t *address,
669 vm_map_size_t size,
670 vm_map_offset_t mask,
671 boolean_t anywhere,
672 vm_map_t src_map,
673 vm_map_offset_t memory_address,
674 boolean_t copy,
675 vm_prot_t *cur_protection,
676 vm_prot_t *max_protection,
677 vm_inherit_t inheritance);
678
679
680 /*
681 * Read and write from a kernel buffer to a specified map.
682 */
683 extern kern_return_t vm_map_write_user(
684 vm_map_t map,
685 void *src_p,
686 vm_map_offset_t dst_addr,
687 vm_size_t size);
688
689 extern kern_return_t vm_map_read_user(
690 vm_map_t map,
691 vm_map_offset_t src_addr,
692 void *dst_p,
693 vm_size_t size);
694
695 /* Create a new task map using an existing task map as a template. */
696 extern vm_map_t vm_map_fork(
697 vm_map_t old_map);
698
699 /* Change inheritance */
700 extern kern_return_t vm_map_inherit(
701 vm_map_t map,
702 vm_map_offset_t start,
703 vm_map_offset_t end,
704 vm_inherit_t new_inheritance);
705
706 /* Add or remove machine-dependent attributes from map regions */
707 extern kern_return_t vm_map_machine_attribute(
708 vm_map_t map,
709 vm_map_offset_t start,
710 vm_map_offset_t end,
711 vm_machine_attribute_t attribute,
712 vm_machine_attribute_val_t* value); /* IN/OUT */
713
714 extern kern_return_t vm_map_msync(
715 vm_map_t map,
716 vm_map_address_t address,
717 vm_map_size_t size,
718 vm_sync_t sync_flags);
719
720 /* Set paging behavior */
721 extern kern_return_t vm_map_behavior_set(
722 vm_map_t map,
723 vm_map_offset_t start,
724 vm_map_offset_t end,
725 vm_behavior_t new_behavior);
726
727 extern kern_return_t vm_map_purgable_control(
728 vm_map_t map,
729 vm_map_offset_t address,
730 vm_purgable_t control,
731 int *state);
732
733 extern kern_return_t vm_map_region(
734 vm_map_t map,
735 vm_map_offset_t *address,
736 vm_map_size_t *size,
737 vm_region_flavor_t flavor,
738 vm_region_info_t info,
739 mach_msg_type_number_t *count,
740 mach_port_t *object_name);
741
742 extern kern_return_t vm_map_region_recurse_64(
743 vm_map_t map,
744 vm_map_offset_t *address,
745 vm_map_size_t *size,
746 natural_t *nesting_depth,
747 vm_region_submap_info_64_t info,
748 mach_msg_type_number_t *count);
749
750 extern kern_return_t vm_map_page_info(
751 vm_map_t map,
752 vm_map_offset_t offset,
753 int *disposition,
754 int *ref_count);
755
756 extern kern_return_t vm_map_submap(
757 vm_map_t map,
758 vm_map_offset_t start,
759 vm_map_offset_t end,
760 vm_map_t submap,
761 vm_map_offset_t offset,
762 boolean_t use_pmap);
763
764 extern void vm_map_submap_pmap_clean(
765 vm_map_t map,
766 vm_map_offset_t start,
767 vm_map_offset_t end,
768 vm_map_t sub_map,
769 vm_map_offset_t offset);
770
771 /* Convert from a map entry port to a map */
772 extern vm_map_t convert_port_entry_to_map(
773 ipc_port_t port);
774
775 /* Convert from a port to a vm_object */
776 extern vm_object_t convert_port_entry_to_object(
777 ipc_port_t port);
778
779
780 /* definitions related to overriding the NX behavior */
781
782 #define VM_ABI_32 0x1
783 #define VM_ABI_64 0x2
784
785 extern int override_nx(vm_map_t map, uint32_t user_tag);
786
787 #endif /* MACH_KERNEL_PRIVATE */
788
789 __BEGIN_DECLS
790
791 /* Create an empty map */
792 extern vm_map_t vm_map_create(
793 pmap_t pmap,
794 vm_map_offset_t min_off,
795 vm_map_offset_t max_off,
796 boolean_t pageable);
797
798 /* Get rid of a map */
799 extern void vm_map_destroy(
800 vm_map_t map,
801 int flags);
802
803 /* Lose a reference */
804 extern void vm_map_deallocate(
805 vm_map_t map);
806
807 extern vm_map_t vm_map_switch(
808 vm_map_t map);
809
810 /* Change protection */
811 extern kern_return_t vm_map_protect(
812 vm_map_t map,
813 vm_map_offset_t start,
814 vm_map_offset_t end,
815 vm_prot_t new_prot,
816 boolean_t set_max);
817
818 /* Check protection */
819 extern boolean_t vm_map_check_protection(
820 vm_map_t map,
821 vm_map_offset_t start,
822 vm_map_offset_t end,
823 vm_prot_t protection);
824
825 /* wire down a region */
826 extern kern_return_t vm_map_wire(
827 vm_map_t map,
828 vm_map_offset_t start,
829 vm_map_offset_t end,
830 vm_prot_t access_type,
831 boolean_t user_wire);
832
833 /* unwire a region */
834 extern kern_return_t vm_map_unwire(
835 vm_map_t map,
836 vm_map_offset_t start,
837 vm_map_offset_t end,
838 boolean_t user_wire);
839
840 /* Enter a mapping of a memory object */
841 extern kern_return_t vm_map_enter_mem_object(
842 vm_map_t map,
843 vm_map_offset_t *address,
844 vm_map_size_t size,
845 vm_map_offset_t mask,
846 int flags,
847 ipc_port_t port,
848 vm_object_offset_t offset,
849 boolean_t needs_copy,
850 vm_prot_t cur_protection,
851 vm_prot_t max_protection,
852 vm_inherit_t inheritance);
853
854 /* Deallocate a region */
855 extern kern_return_t vm_map_remove(
856 vm_map_t map,
857 vm_map_offset_t start,
858 vm_map_offset_t end,
859 boolean_t flags);
860
861 /* Discard a copy without using it */
862 extern void vm_map_copy_discard(
863 vm_map_copy_t copy);
864
865 /* Overwrite existing memory with a copy */
866 extern kern_return_t vm_map_copy_overwrite(
867 vm_map_t dst_map,
868 vm_map_address_t dst_addr,
869 vm_map_copy_t copy,
870 int interruptible);
871
872 /* Place a copy into a map */
873 extern kern_return_t vm_map_copyout(
874 vm_map_t dst_map,
875 vm_map_address_t *dst_addr, /* OUT */
876 vm_map_copy_t copy);
877
878 extern kern_return_t vm_map_copyin(
879 vm_map_t src_map,
880 vm_map_address_t src_addr,
881 vm_map_size_t len,
882 boolean_t src_destroy,
883 vm_map_copy_t *copy_result); /* OUT */
884
885 extern kern_return_t vm_map_copyin_common(
886 vm_map_t src_map,
887 vm_map_address_t src_addr,
888 vm_map_size_t len,
889 boolean_t src_destroy,
890 boolean_t src_volatile,
891 vm_map_copy_t *copy_result, /* OUT */
892 boolean_t use_maxprot);
893
894 extern void vm_map_disable_NX(
895 vm_map_t map);
896
897 extern void vm_map_set_64bit(
898 vm_map_t map);
899
900 extern void vm_map_set_32bit(
901 vm_map_t map);
902
903 extern boolean_t vm_map_is_64bit(
904 vm_map_t map);
905
906 extern boolean_t vm_map_has_4GB_pagezero(
907 vm_map_t map);
908
909 extern void vm_map_set_4GB_pagezero(
910 vm_map_t map);
911
912 extern void vm_map_clear_4GB_pagezero(
913 vm_map_t map);
914
915 extern kern_return_t vm_map_raise_min_offset(
916 vm_map_t map,
917 vm_map_offset_t new_min_offset);
918
919 extern vm_map_offset_t vm_compute_max_offset(
920 unsigned is64);
921
922 extern void vm_map_set_user_wire_limit(
923 vm_map_t map,
924 vm_size_t limit);
925
926 #ifdef MACH_KERNEL_PRIVATE
927
928 /*
929 * Macros to invoke vm_map_copyin_common. vm_map_copyin is the
930 * usual form; it handles a copyin based on the current protection
931 * (current protection == VM_PROT_NONE) is a failure.
932 * vm_map_copyin_maxprot handles a copyin based on maximum possible
933 * access. The difference is that a region with no current access
934 * BUT possible maximum access is rejected by vm_map_copyin(), but
935 * returned by vm_map_copyin_maxprot.
936 */
937 #define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \
938 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
939 FALSE, copy_result, FALSE)
940
941 #define vm_map_copyin_maxprot(src_map, \
942 src_addr, len, src_destroy, copy_result) \
943 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
944 FALSE, copy_result, TRUE)
945
946 #endif /* MACH_KERNEL_PRIVATE */
947
948 /*
949 * Macros for rounding and truncation of vm_map offsets and sizes
950 */
951 #define vm_map_round_page(x) (((vm_map_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
952 #define vm_map_trunc_page(x) ((vm_map_offset_t)(x) & ~((signed)PAGE_MASK))
953
954 /*
955 * Flags for vm_map_remove() and vm_map_delete()
956 */
957 #define VM_MAP_NO_FLAGS 0x0
958 #define VM_MAP_REMOVE_KUNWIRE 0x1
959 #define VM_MAP_REMOVE_INTERRUPTIBLE 0x2
960 #define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4
961 #define VM_MAP_REMOVE_SAVE_ENTRIES 0x8
962 #define VM_MAP_REMOVE_NO_PMAP_CLEANUP 0x10
963
964 /* Support for UPLs from vm_maps */
965
966 extern kern_return_t vm_map_get_upl(
967 vm_map_t target_map,
968 vm_map_offset_t map_offset,
969 vm_size_t *size,
970 upl_t *upl,
971 upl_page_info_array_t page_info,
972 mach_msg_type_number_t *page_infoCnt,
973 integer_t *flags,
974 integer_t force_data_sync);
975
976 __END_DECLS
977
978 #endif /* KERNEL_PRIVATE */
979
980 #endif /* _VM_VM_MAP_H_ */