]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_map.h
02bf60eea1ce82fcf741f79dc6081f81f314e5e0
[apple/xnu.git] / osfmk / vm / vm_map.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52
53 /*
54 * File: vm/vm_map.h
55 * Author: Avadis Tevanian, Jr., Michael Wayne Young
56 * Date: 1985
57 *
58 * Virtual memory map module definitions.
59 *
60 * Contributors:
61 * avie, dlb, mwyoung
62 */
63
64 #ifndef _VM_VM_MAP_H_
65 #define _VM_VM_MAP_H_
66
67 #include <mach/mach_types.h>
68 #include <mach/kern_return.h>
69 #include <mach/boolean.h>
70 #include <mach/vm_types.h>
71 #include <mach/vm_prot.h>
72 #include <mach/vm_inherit.h>
73 #include <mach/vm_behavior.h>
74 #include <mach/vm_param.h>
75 #include <vm/pmap.h>
76
77 #ifdef KERNEL_PRIVATE
78
79 #include <sys/cdefs.h>
80
81 __BEGIN_DECLS
82
83 extern void vm_map_reference(vm_map_t map);
84 extern vm_map_t current_map(void);
85
86 __END_DECLS
87
88 #ifdef MACH_KERNEL_PRIVATE
89
90 #include <task_swapper.h>
91 #include <mach_assert.h>
92
93 #include <vm/vm_object.h>
94 #include <vm/vm_page.h>
95 #include <kern/lock.h>
96 #include <kern/zalloc.h>
97 #include <kern/macro_help.h>
98
99 #include <kern/thread.h>
100
101 #define current_map_fast() (current_thread()->map)
102 #define current_map() (current_map_fast())
103
104 /*
105 * Types defined:
106 *
107 * vm_map_t the high-level address map data structure.
108 * vm_map_entry_t an entry in an address map.
109 * vm_map_version_t a timestamp of a map, for use with vm_map_lookup
110 * vm_map_copy_t represents memory copied from an address map,
111 * used for inter-map copy operations
112 */
113 typedef struct vm_map_entry *vm_map_entry_t;
114 #define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0)
115
116
117 /*
118 * Type: vm_map_object_t [internal use only]
119 *
120 * Description:
121 * The target of an address mapping, either a virtual
122 * memory object or a sub map (of the kernel map).
123 */
124 typedef union vm_map_object {
125 vm_object_t vm_object; /* object object */
126 vm_map_t sub_map; /* belongs to another map */
127 } vm_map_object_t;
128
129 #define named_entry_lock_init(object) mutex_init(&(object)->Lock, 0)
130 #define named_entry_lock(object) mutex_lock(&(object)->Lock)
131 #define named_entry_unlock(object) mutex_unlock(&(object)->Lock)
132
133 /*
134 * Type: vm_named_entry_t [internal use only]
135 *
136 * Description:
137 * Description of a mapping to a memory cache object.
138 *
139 * Implementation:
140 * While the handle to this object is used as a means to map
141 * and pass around the right to map regions backed by pagers
142 * of all sorts, the named_entry itself is only manipulated
143 * by the kernel. Named entries hold information on the
144 * right to map a region of a cached object. Namely,
145 * the target cache object, the beginning and ending of the
146 * region to be mapped, and the permissions, (read, write)
147 * with which it can be mapped.
148 *
149 */
150
151 struct vm_named_entry {
152 decl_mutex_data(, Lock) /* Synchronization */
153 union {
154 vm_object_t object; /* object I point to */
155 memory_object_t pager; /* amo pager port */
156 vm_map_t map; /* map backing submap */
157 } backing;
158 vm_object_offset_t offset; /* offset into object */
159 vm_object_size_t size; /* size of region */
160 vm_prot_t protection; /* access permissions */
161 int ref_count; /* Number of references */
162 unsigned int /* Is backing.xxx : */
163 /* boolean_t */ internal:1, /* ... an internal object */
164 /* boolean_t */ is_sub_map:1, /* ... a submap? */
165 /* boolean_t */ is_pager:1; /* ... a pager port */
166 };
167
168 /*
169 * Type: vm_map_entry_t [internal use only]
170 *
171 * Description:
172 * A single mapping within an address map.
173 *
174 * Implementation:
175 * Address map entries consist of start and end addresses,
176 * a VM object (or sub map) and offset into that object,
177 * and user-exported inheritance and protection information.
178 * Control information for virtual copy operations is also
179 * stored in the address map entry.
180 */
181 struct vm_map_links {
182 struct vm_map_entry *prev; /* previous entry */
183 struct vm_map_entry *next; /* next entry */
184 vm_map_offset_t start; /* start address */
185 vm_map_offset_t end; /* end address */
186 };
187
188 struct vm_map_entry {
189 struct vm_map_links links; /* links to other entries */
190 #define vme_prev links.prev
191 #define vme_next links.next
192 #define vme_start links.start
193 #define vme_end links.end
194 union vm_map_object object; /* object I point to */
195 vm_object_offset_t offset; /* offset into object */
196 unsigned int
197 /* boolean_t */ is_shared:1, /* region is shared */
198 /* boolean_t */ is_sub_map:1, /* Is "object" a submap? */
199 /* boolean_t */ in_transition:1, /* Entry being changed */
200 /* boolean_t */ needs_wakeup:1, /* Waiters on in_transition */
201 /* vm_behavior_t */ behavior:2, /* user paging behavior hint */
202 /* behavior is not defined for submap type */
203 /* boolean_t */ needs_copy:1, /* object need to be copied? */
204 /* Only in task maps: */
205 /* vm_prot_t */ protection:3, /* protection code */
206 /* vm_prot_t */ max_protection:3,/* maximum protection */
207 /* vm_inherit_t */ inheritance:2, /* inheritance */
208 /* boolean_t */ use_pmap:1, /* nested pmaps */
209 /* unsigned char */ alias:8, /* user alias */
210 /* unsigned char */ pad:8; /* available bits */
211 unsigned short wired_count; /* can be paged if = 0 */
212 unsigned short user_wired_count; /* for vm_wire */
213 };
214
215 /*
216 * wired_counts are unsigned short. This value is used to safeguard
217 * against any mishaps due to runaway user programs.
218 */
219 #define MAX_WIRE_COUNT 65535
220
221
222
223 /*
224 * Type: struct vm_map_header
225 *
226 * Description:
227 * Header for a vm_map and a vm_map_copy.
228 */
229 struct vm_map_header {
230 struct vm_map_links links; /* first, last, min, max */
231 int nentries; /* Number of entries */
232 boolean_t entries_pageable;
233 /* are map entries pageable? */
234 };
235
236 /*
237 * Type: vm_map_t [exported; contents invisible]
238 *
239 * Description:
240 * An address map -- a directory relating valid
241 * regions of a task's address space to the corresponding
242 * virtual memory objects.
243 *
244 * Implementation:
245 * Maps are doubly-linked lists of map entries, sorted
246 * by address. One hint is used to start
247 * searches again from the last successful search,
248 * insertion, or removal. Another hint is used to
249 * quickly find free space.
250 */
251 struct vm_map {
252 lock_t lock; /* uni- and smp-lock */
253 struct vm_map_header hdr; /* Map entry header */
254 #define min_offset hdr.links.start /* start of range */
255 #define max_offset hdr.links.end /* end of range */
256 pmap_t pmap; /* Physical map */
257 vm_map_size_t size; /* virtual size */
258 int ref_count; /* Reference count */
259 #if TASK_SWAPPER
260 int res_count; /* Residence count (swap) */
261 int sw_state; /* Swap state */
262 #endif /* TASK_SWAPPER */
263 decl_mutex_data(, s_lock) /* Lock ref, res, hint fields */
264 vm_map_entry_t hint; /* hint for quick lookups */
265 vm_map_entry_t first_free; /* First free space hint */
266 boolean_t wait_for_space; /* Should callers wait
267 for space? */
268 boolean_t wiring_required;/* All memory wired? */
269 boolean_t no_zero_fill; /* No zero fill absent pages */
270 boolean_t mapped; /* has this map been mapped */
271 unsigned int timestamp; /* Version number */
272 } ;
273
274 #define vm_map_to_entry(map) ((struct vm_map_entry *) &(map)->hdr.links)
275 #define vm_map_first_entry(map) ((map)->hdr.links.next)
276 #define vm_map_last_entry(map) ((map)->hdr.links.prev)
277
278 #if TASK_SWAPPER
279 /*
280 * VM map swap states. There are no transition states.
281 */
282 #define MAP_SW_IN 1 /* map is swapped in; residence count > 0 */
283 #define MAP_SW_OUT 2 /* map is out (res_count == 0 */
284 #endif /* TASK_SWAPPER */
285
286 /*
287 * Type: vm_map_version_t [exported; contents invisible]
288 *
289 * Description:
290 * Map versions may be used to quickly validate a previous
291 * lookup operation.
292 *
293 * Usage note:
294 * Because they are bulky objects, map versions are usually
295 * passed by reference.
296 *
297 * Implementation:
298 * Just a timestamp for the main map.
299 */
300 typedef struct vm_map_version {
301 unsigned int main_timestamp;
302 } vm_map_version_t;
303
304 /*
305 * Type: vm_map_copy_t [exported; contents invisible]
306 *
307 * Description:
308 * A map copy object represents a region of virtual memory
309 * that has been copied from an address map but is still
310 * in transit.
311 *
312 * A map copy object may only be used by a single thread
313 * at a time.
314 *
315 * Implementation:
316 * There are three formats for map copy objects.
317 * The first is very similar to the main
318 * address map in structure, and as a result, some
319 * of the internal maintenance functions/macros can
320 * be used with either address maps or map copy objects.
321 *
322 * The map copy object contains a header links
323 * entry onto which the other entries that represent
324 * the region are chained.
325 *
326 * The second format is a single vm object. This was used
327 * primarily in the pageout path - but is not currently used
328 * except for placeholder copy objects (see vm_map_copy_copy()).
329 *
330 * The third format is a kernel buffer copy object - for data
331 * small enough that physical copies were the most efficient
332 * method.
333 */
334
335 struct vm_map_copy {
336 int type;
337 #define VM_MAP_COPY_ENTRY_LIST 1
338 #define VM_MAP_COPY_OBJECT 2
339 #define VM_MAP_COPY_KERNEL_BUFFER 3
340 vm_object_offset_t offset;
341 vm_map_size_t size;
342 union {
343 struct vm_map_header hdr; /* ENTRY_LIST */
344 vm_object_t object; /* OBJECT */
345 struct {
346 void *kdata; /* KERNEL_BUFFER */
347 vm_size_t kalloc_size; /* size of this copy_t */
348 } c_k;
349 } c_u;
350 };
351
352
353 #define cpy_hdr c_u.hdr
354
355 #define cpy_object c_u.object
356
357 #define cpy_kdata c_u.c_k.kdata
358 #define cpy_kalloc_size c_u.c_k.kalloc_size
359
360
361 /*
362 * Useful macros for entry list copy objects
363 */
364
365 #define vm_map_copy_to_entry(copy) \
366 ((struct vm_map_entry *) &(copy)->cpy_hdr.links)
367 #define vm_map_copy_first_entry(copy) \
368 ((copy)->cpy_hdr.links.next)
369 #define vm_map_copy_last_entry(copy) \
370 ((copy)->cpy_hdr.links.prev)
371
372 /*
373 * Macros: vm_map_lock, etc. [internal use only]
374 * Description:
375 * Perform locking on the data portion of a map.
376 * When multiple maps are to be locked, order by map address.
377 * (See vm_map.c::vm_remap())
378 */
379
380 #define vm_map_lock_init(map) \
381 ((map)->timestamp = 0 , \
382 lock_init(&(map)->lock, TRUE, 0, 0))
383
384 #define vm_map_lock(map) lock_write(&(map)->lock)
385 #define vm_map_unlock(map) \
386 ((map)->timestamp++ , lock_write_done(&(map)->lock))
387 #define vm_map_lock_read(map) lock_read(&(map)->lock)
388 #define vm_map_unlock_read(map) lock_read_done(&(map)->lock)
389 #define vm_map_lock_write_to_read(map) \
390 ((map)->timestamp++ , lock_write_to_read(&(map)->lock))
391 #define vm_map_lock_read_to_write(map) lock_read_to_write(&(map)->lock)
392
393 /*
394 * Exported procedures that operate on vm_map_t.
395 */
396
397 /* Initialize the module */
398 extern void vm_map_init(void);
399
400 /* Allocate a range in the specified virtual address map and
401 * return the entry allocated for that range. */
402 extern kern_return_t vm_map_find_space(
403 vm_map_t map,
404 vm_map_address_t *address, /* OUT */
405 vm_map_size_t size,
406 vm_map_offset_t mask,
407 int flags,
408 vm_map_entry_t *o_entry); /* OUT */
409
410 /* Lookup map entry containing or the specified address in the given map */
411 extern boolean_t vm_map_lookup_entry(
412 vm_map_t map,
413 vm_map_address_t address,
414 vm_map_entry_t *entry); /* OUT */
415
416 /* Find the VM object, offset, and protection for a given virtual address
417 * in the specified map, assuming a page fault of the type specified. */
418 extern kern_return_t vm_map_lookup_locked(
419 vm_map_t *var_map, /* IN/OUT */
420 vm_map_address_t vaddr,
421 vm_prot_t fault_type,
422 vm_map_version_t *out_version, /* OUT */
423 vm_object_t *object, /* OUT */
424 vm_object_offset_t *offset, /* OUT */
425 vm_prot_t *out_prot, /* OUT */
426 boolean_t *wired, /* OUT */
427 int *behavior, /* OUT */
428 vm_map_offset_t *lo_offset, /* OUT */
429 vm_map_offset_t *hi_offset, /* OUT */
430 vm_map_t *real_map); /* OUT */
431
432 /* Verifies that the map has not changed since the given version. */
433 extern boolean_t vm_map_verify(
434 vm_map_t map,
435 vm_map_version_t *version); /* REF */
436
437 extern vm_map_entry_t vm_map_entry_insert(
438 vm_map_t map,
439 vm_map_entry_t insp_entry,
440 vm_map_offset_t start,
441 vm_map_offset_t end,
442 vm_object_t object,
443 vm_object_offset_t offset,
444 boolean_t needs_copy,
445 boolean_t is_shared,
446 boolean_t in_transition,
447 vm_prot_t cur_protection,
448 vm_prot_t max_protection,
449 vm_behavior_t behavior,
450 vm_inherit_t inheritance,
451 unsigned wired_count);
452
453
454 /*
455 * Functions implemented as macros
456 */
457 #define vm_map_min(map) ((map)->min_offset)
458 /* Lowest valid address in
459 * a map */
460
461 #define vm_map_max(map) ((map)->max_offset)
462 /* Highest valid address */
463
464 #define vm_map_pmap(map) ((map)->pmap)
465 /* Physical map associated
466 * with this address map */
467
468 #define vm_map_verify_done(map, version) vm_map_unlock_read(map)
469 /* Operation that required
470 * a verified lookup is
471 * now complete */
472
473 /*
474 * Macros/functions for map residence counts and swapin/out of vm maps
475 */
476 #if TASK_SWAPPER
477
478 #if MACH_ASSERT
479 /* Gain a reference to an existing map */
480 extern void vm_map_reference(
481 vm_map_t map);
482 /* Lose a residence count */
483 extern void vm_map_res_deallocate(
484 vm_map_t map);
485 /* Gain a residence count on a map */
486 extern void vm_map_res_reference(
487 vm_map_t map);
488 /* Gain reference & residence counts to possibly swapped-out map */
489 extern void vm_map_reference_swap(
490 vm_map_t map);
491
492 #else /* MACH_ASSERT */
493
494 #define vm_map_reference(map) \
495 MACRO_BEGIN \
496 vm_map_t Map = (map); \
497 if (Map) { \
498 mutex_lock(&Map->s_lock); \
499 Map->res_count++; \
500 Map->ref_count++; \
501 mutex_unlock(&Map->s_lock); \
502 } \
503 MACRO_END
504
505 #define vm_map_res_reference(map) \
506 MACRO_BEGIN \
507 vm_map_t Lmap = (map); \
508 if (Lmap->res_count == 0) { \
509 mutex_unlock(&Lmap->s_lock);\
510 vm_map_lock(Lmap); \
511 vm_map_swapin(Lmap); \
512 mutex_lock(&Lmap->s_lock); \
513 ++Lmap->res_count; \
514 vm_map_unlock(Lmap); \
515 } else \
516 ++Lmap->res_count; \
517 MACRO_END
518
519 #define vm_map_res_deallocate(map) \
520 MACRO_BEGIN \
521 vm_map_t Map = (map); \
522 if (--Map->res_count == 0) { \
523 mutex_unlock(&Map->s_lock); \
524 vm_map_lock(Map); \
525 vm_map_swapout(Map); \
526 vm_map_unlock(Map); \
527 mutex_lock(&Map->s_lock); \
528 } \
529 MACRO_END
530
531 #define vm_map_reference_swap(map) \
532 MACRO_BEGIN \
533 vm_map_t Map = (map); \
534 mutex_lock(&Map->s_lock); \
535 ++Map->ref_count; \
536 vm_map_res_reference(Map); \
537 mutex_unlock(&Map->s_lock); \
538 MACRO_END
539 #endif /* MACH_ASSERT */
540
541 extern void vm_map_swapin(
542 vm_map_t map);
543
544 extern void vm_map_swapout(
545 vm_map_t map);
546
547 #else /* TASK_SWAPPER */
548
549 #define vm_map_reference(map) \
550 MACRO_BEGIN \
551 vm_map_t Map = (map); \
552 if (Map) { \
553 mutex_lock(&Map->s_lock); \
554 Map->ref_count++; \
555 mutex_unlock(&Map->s_lock); \
556 } \
557 MACRO_END
558
559 #define vm_map_reference_swap(map) vm_map_reference(map)
560 #define vm_map_res_reference(map)
561 #define vm_map_res_deallocate(map)
562
563 #endif /* TASK_SWAPPER */
564
565 /*
566 * Submap object. Must be used to create memory to be put
567 * in a submap by vm_map_submap.
568 */
569 extern vm_object_t vm_submap_object;
570
571 /*
572 * Wait and wakeup macros for in_transition map entries.
573 */
574 #define vm_map_entry_wait(map, interruptible) \
575 ((map)->timestamp++ , \
576 thread_sleep_lock_write((event_t)&(map)->hdr, \
577 &(map)->lock, interruptible))
578
579
580 #define vm_map_entry_wakeup(map) \
581 thread_wakeup((event_t)(&(map)->hdr))
582
583
584 #define vm_map_ref_fast(map) \
585 MACRO_BEGIN \
586 mutex_lock(&map->s_lock); \
587 map->ref_count++; \
588 vm_map_res_reference(map); \
589 mutex_unlock(&map->s_lock); \
590 MACRO_END
591
592 #define vm_map_dealloc_fast(map) \
593 MACRO_BEGIN \
594 register int c; \
595 \
596 mutex_lock(&map->s_lock); \
597 c = --map->ref_count; \
598 if (c > 0) \
599 vm_map_res_deallocate(map); \
600 mutex_unlock(&map->s_lock); \
601 if (c == 0) \
602 vm_map_destroy(map); \
603 MACRO_END
604
605
606 /* simplify map entries */
607 extern void vm_map_simplify_entry(
608 vm_map_t map,
609 vm_map_entry_t this_entry);
610 extern void vm_map_simplify(
611 vm_map_t map,
612 vm_map_offset_t start);
613
614 /* Move the information in a map copy object to a new map copy object */
615 extern vm_map_copy_t vm_map_copy_copy(
616 vm_map_copy_t copy);
617
618 /* Create a copy object from an object. */
619 extern kern_return_t vm_map_copyin_object(
620 vm_object_t object,
621 vm_object_offset_t offset,
622 vm_object_size_t size,
623 vm_map_copy_t *copy_result); /* OUT */
624
625 /* Enter a mapping */
626 extern kern_return_t vm_map_enter(
627 vm_map_t map,
628 vm_map_offset_t *address,
629 vm_map_size_t size,
630 vm_map_offset_t mask,
631 int flags,
632 vm_object_t object,
633 vm_object_offset_t offset,
634 boolean_t needs_copy,
635 vm_prot_t cur_protection,
636 vm_prot_t max_protection,
637 vm_inherit_t inheritance);
638
639 /* XXX should go away - replaced with regular enter of contig object */
640 extern kern_return_t vm_map_enter_cpm(
641 vm_map_t map,
642 vm_map_address_t *addr,
643 vm_map_size_t size,
644 int flags);
645
646 extern kern_return_t vm_map_remap(
647 vm_map_t target_map,
648 vm_map_offset_t *address,
649 vm_map_size_t size,
650 vm_map_offset_t mask,
651 boolean_t anywhere,
652 vm_map_t src_map,
653 vm_map_offset_t memory_address,
654 boolean_t copy,
655 vm_prot_t *cur_protection,
656 vm_prot_t *max_protection,
657 vm_inherit_t inheritance);
658
659
660 /*
661 * Read and write from a kernel buffer to a specified map.
662 */
663 extern kern_return_t vm_map_write_user(
664 vm_map_t map,
665 void *src_p,
666 vm_map_offset_t dst_addr,
667 vm_size_t size);
668
669 extern kern_return_t vm_map_read_user(
670 vm_map_t map,
671 vm_map_offset_t src_addr,
672 void *dst_p,
673 vm_size_t size);
674
675 /* Create a new task map using an existing task map as a template. */
676 extern vm_map_t vm_map_fork(
677 vm_map_t old_map);
678
679 /* Change inheritance */
680 extern kern_return_t vm_map_inherit(
681 vm_map_t map,
682 vm_map_offset_t start,
683 vm_map_offset_t end,
684 vm_inherit_t new_inheritance);
685
686 /* Add or remove machine-dependent attributes from map regions */
687 extern kern_return_t vm_map_machine_attribute(
688 vm_map_t map,
689 vm_map_offset_t start,
690 vm_map_offset_t end,
691 vm_machine_attribute_t attribute,
692 vm_machine_attribute_val_t* value); /* IN/OUT */
693
694 extern kern_return_t vm_map_msync(
695 vm_map_t map,
696 vm_map_address_t address,
697 vm_map_size_t size,
698 vm_sync_t sync_flags);
699
700 /* Set paging behavior */
701 extern kern_return_t vm_map_behavior_set(
702 vm_map_t map,
703 vm_map_offset_t start,
704 vm_map_offset_t end,
705 vm_behavior_t new_behavior);
706
707 extern kern_return_t vm_map_purgable_control(
708 vm_map_t map,
709 vm_map_offset_t address,
710 vm_purgable_t control,
711 int *state);
712
713 extern kern_return_t vm_map_region(
714 vm_map_t map,
715 vm_map_offset_t *address,
716 vm_map_size_t *size,
717 vm_region_flavor_t flavor,
718 vm_region_info_t info,
719 mach_msg_type_number_t *count,
720 mach_port_t *object_name);
721
722 extern kern_return_t vm_map_region_recurse_64(
723 vm_map_t map,
724 vm_map_offset_t *address,
725 vm_map_size_t *size,
726 natural_t *nesting_depth,
727 vm_region_submap_info_64_t info,
728 mach_msg_type_number_t *count);
729
730 extern kern_return_t vm_map_page_info(
731 vm_map_t map,
732 vm_map_offset_t offset,
733 int *disposition,
734 int *ref_count);
735
736 extern kern_return_t vm_map_submap(
737 vm_map_t map,
738 vm_map_offset_t start,
739 vm_map_offset_t end,
740 vm_map_t submap,
741 vm_map_offset_t offset,
742 boolean_t use_pmap);
743
744 extern void vm_map_submap_pmap_clean(
745 vm_map_t map,
746 vm_map_offset_t start,
747 vm_map_offset_t end,
748 vm_map_t sub_map,
749 vm_map_offset_t offset);
750
751 /* Convert from a map entry port to a map */
752 extern vm_map_t convert_port_entry_to_map(
753 ipc_port_t port);
754
755 /* Convert from a port to a vm_object */
756 extern vm_object_t convert_port_entry_to_object(
757 ipc_port_t port);
758
759
760 #endif /* MACH_KERNEL_PRIVATE */
761
762 __BEGIN_DECLS
763
764 /* Create an empty map */
765 extern vm_map_t vm_map_create(
766 pmap_t pmap,
767 vm_map_offset_t min_off,
768 vm_map_offset_t max_off,
769 boolean_t pageable);
770
771 /* Get rid of a map */
772 extern void vm_map_destroy(
773 vm_map_t map);
774 /* Lose a reference */
775 extern void vm_map_deallocate(
776 vm_map_t map);
777
778 extern vm_map_t vm_map_switch(
779 vm_map_t map);
780
781 /* Change protection */
782 extern kern_return_t vm_map_protect(
783 vm_map_t map,
784 vm_map_offset_t start,
785 vm_map_offset_t end,
786 vm_prot_t new_prot,
787 boolean_t set_max);
788
789 /* Check protection */
790 extern boolean_t vm_map_check_protection(
791 vm_map_t map,
792 vm_map_offset_t start,
793 vm_map_offset_t end,
794 vm_prot_t protection);
795
796 /* wire down a region */
797 extern kern_return_t vm_map_wire(
798 vm_map_t map,
799 vm_map_offset_t start,
800 vm_map_offset_t end,
801 vm_prot_t access_type,
802 boolean_t user_wire);
803
804 /* unwire a region */
805 extern kern_return_t vm_map_unwire(
806 vm_map_t map,
807 vm_map_offset_t start,
808 vm_map_offset_t end,
809 boolean_t user_wire);
810
811 /* Deallocate a region */
812 extern kern_return_t vm_map_remove(
813 vm_map_t map,
814 vm_map_offset_t start,
815 vm_map_offset_t end,
816 boolean_t flags);
817
818 /* Discard a copy without using it */
819 extern void vm_map_copy_discard(
820 vm_map_copy_t copy);
821
822 /* Overwrite existing memory with a copy */
823 extern kern_return_t vm_map_copy_overwrite(
824 vm_map_t dst_map,
825 vm_map_address_t dst_addr,
826 vm_map_copy_t copy,
827 int interruptible);
828
829 /* Place a copy into a map */
830 extern kern_return_t vm_map_copyout(
831 vm_map_t dst_map,
832 vm_map_address_t *dst_addr, /* OUT */
833 vm_map_copy_t copy);
834
835 extern kern_return_t vm_map_copyin_common(
836 vm_map_t src_map,
837 vm_map_address_t src_addr,
838 vm_map_size_t len,
839 boolean_t src_destroy,
840 boolean_t src_volatile,
841 vm_map_copy_t *copy_result, /* OUT */
842 boolean_t use_maxprot);
843
844 extern void vm_map_disable_NX(
845 vm_map_t map);
846
847 extern void vm_map_set_64bit(
848 vm_map_t map);
849
850 extern void vm_map_set_32bit(
851 vm_map_t map);
852
853 extern boolean_t vm_map_has_4GB_pagezero(
854 vm_map_t map);
855
856 extern void vm_map_set_4GB_pagezero(
857 vm_map_t map);
858
859 extern void vm_map_clear_4GB_pagezero(
860 vm_map_t map);
861
862 extern kern_return_t vm_map_raise_min_offset(
863 vm_map_t map,
864 vm_map_offset_t new_min_offset);
865
866 extern vm_map_offset_t vm_compute_max_offset(
867 unsigned is64);
868
869 /*
870 * Macros to invoke vm_map_copyin_common. vm_map_copyin is the
871 * usual form; it handles a copyin based on the current protection
872 * (current protection == VM_PROT_NONE) is a failure.
873 * vm_map_copyin_maxprot handles a copyin based on maximum possible
874 * access. The difference is that a region with no current access
875 * BUT possible maximum access is rejected by vm_map_copyin(), but
876 * returned by vm_map_copyin_maxprot.
877 */
878 #define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \
879 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
880 FALSE, copy_result, FALSE)
881
882 #define vm_map_copyin_maxprot(src_map, \
883 src_addr, len, src_destroy, copy_result) \
884 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
885 FALSE, copy_result, TRUE)
886
887 /*
888 * Macros for rounding and truncation of vm_map offsets and sizes
889 */
890 #define vm_map_round_page(x) (((vm_map_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
891 #define vm_map_trunc_page(x) ((vm_map_offset_t)(x) & ~((signed)PAGE_MASK))
892
893 /*
894 * Flags for vm_map_remove() and vm_map_delete()
895 */
896 #define VM_MAP_NO_FLAGS 0x0
897 #define VM_MAP_REMOVE_KUNWIRE 0x1
898 #define VM_MAP_REMOVE_INTERRUPTIBLE 0x2
899 #define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4
900 #define VM_MAP_REMOVE_SAVE_ENTRIES 0x8
901
902 /* Support for shared regions */
903 extern kern_return_t vm_region_clone(
904 ipc_port_t src_region,
905 ipc_port_t dst_region);
906
907 extern kern_return_t vm_map_region_replace(
908 vm_map_t target_map,
909 ipc_port_t old_region,
910 ipc_port_t new_region,
911 vm_map_offset_t start,
912 vm_map_offset_t end);
913
914 /* Support for UPLs from vm_maps */
915
916 extern kern_return_t vm_map_get_upl(
917 vm_map_t target_map,
918 vm_map_offset_t map_offset,
919 vm_size_t *size,
920 upl_t *upl,
921 upl_page_info_array_t page_info,
922 mach_msg_type_number_t *page_infoCnt,
923 integer_t *flags,
924 integer_t force_data_sync);
925
926 __END_DECLS
927
928 #endif /* KERNEL_PRIVATE */
929
930 #endif /* _VM_VM_MAP_H_ */