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