]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_map.h
xnu-792.6.22.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_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 vm_map_entry_t *o_entry); /* OUT */
408
409 /* Lookup map entry containing or the specified address in the given map */
410 extern boolean_t vm_map_lookup_entry(
411 vm_map_t map,
412 vm_map_address_t address,
413 vm_map_entry_t *entry); /* OUT */
414
415 /* Find the VM object, offset, and protection for a given virtual address
416 * in the specified map, assuming a page fault of the type specified. */
417 extern kern_return_t vm_map_lookup_locked(
418 vm_map_t *var_map, /* IN/OUT */
419 vm_map_address_t vaddr,
420 vm_prot_t fault_type,
421 vm_map_version_t *out_version, /* OUT */
422 vm_object_t *object, /* OUT */
423 vm_object_offset_t *offset, /* OUT */
424 vm_prot_t *out_prot, /* OUT */
425 boolean_t *wired, /* OUT */
426 int *behavior, /* OUT */
427 vm_map_offset_t *lo_offset, /* OUT */
428 vm_map_offset_t *hi_offset, /* OUT */
429 vm_map_t *real_map); /* OUT */
430
431 /* Verifies that the map has not changed since the given version. */
432 extern boolean_t vm_map_verify(
433 vm_map_t map,
434 vm_map_version_t *version); /* REF */
435
436 extern vm_map_entry_t vm_map_entry_insert(
437 vm_map_t map,
438 vm_map_entry_t insp_entry,
439 vm_map_offset_t start,
440 vm_map_offset_t end,
441 vm_object_t object,
442 vm_object_offset_t offset,
443 boolean_t needs_copy,
444 boolean_t is_shared,
445 boolean_t in_transition,
446 vm_prot_t cur_protection,
447 vm_prot_t max_protection,
448 vm_behavior_t behavior,
449 vm_inherit_t inheritance,
450 unsigned wired_count);
451
452
453 /*
454 * Functions implemented as macros
455 */
456 #define vm_map_min(map) ((map)->min_offset)
457 /* Lowest valid address in
458 * a map */
459
460 #define vm_map_max(map) ((map)->max_offset)
461 /* Highest valid address */
462
463 #define vm_map_pmap(map) ((map)->pmap)
464 /* Physical map associated
465 * with this address map */
466
467 #define vm_map_verify_done(map, version) vm_map_unlock_read(map)
468 /* Operation that required
469 * a verified lookup is
470 * now complete */
471
472 /*
473 * Macros/functions for map residence counts and swapin/out of vm maps
474 */
475 #if TASK_SWAPPER
476
477 #if MACH_ASSERT
478 /* Gain a reference to an existing map */
479 extern void vm_map_reference(
480 vm_map_t map);
481 /* Lose a residence count */
482 extern void vm_map_res_deallocate(
483 vm_map_t map);
484 /* Gain a residence count on a map */
485 extern void vm_map_res_reference(
486 vm_map_t map);
487 /* Gain reference & residence counts to possibly swapped-out map */
488 extern void vm_map_reference_swap(
489 vm_map_t map);
490
491 #else /* MACH_ASSERT */
492
493 #define vm_map_reference(map) \
494 MACRO_BEGIN \
495 vm_map_t Map = (map); \
496 if (Map) { \
497 mutex_lock(&Map->s_lock); \
498 Map->res_count++; \
499 Map->ref_count++; \
500 mutex_unlock(&Map->s_lock); \
501 } \
502 MACRO_END
503
504 #define vm_map_res_reference(map) \
505 MACRO_BEGIN \
506 vm_map_t Lmap = (map); \
507 if (Lmap->res_count == 0) { \
508 mutex_unlock(&Lmap->s_lock);\
509 vm_map_lock(Lmap); \
510 vm_map_swapin(Lmap); \
511 mutex_lock(&Lmap->s_lock); \
512 ++Lmap->res_count; \
513 vm_map_unlock(Lmap); \
514 } else \
515 ++Lmap->res_count; \
516 MACRO_END
517
518 #define vm_map_res_deallocate(map) \
519 MACRO_BEGIN \
520 vm_map_t Map = (map); \
521 if (--Map->res_count == 0) { \
522 mutex_unlock(&Map->s_lock); \
523 vm_map_lock(Map); \
524 vm_map_swapout(Map); \
525 vm_map_unlock(Map); \
526 mutex_lock(&Map->s_lock); \
527 } \
528 MACRO_END
529
530 #define vm_map_reference_swap(map) \
531 MACRO_BEGIN \
532 vm_map_t Map = (map); \
533 mutex_lock(&Map->s_lock); \
534 ++Map->ref_count; \
535 vm_map_res_reference(Map); \
536 mutex_unlock(&Map->s_lock); \
537 MACRO_END
538 #endif /* MACH_ASSERT */
539
540 extern void vm_map_swapin(
541 vm_map_t map);
542
543 extern void vm_map_swapout(
544 vm_map_t map);
545
546 #else /* TASK_SWAPPER */
547
548 #define vm_map_reference(map) \
549 MACRO_BEGIN \
550 vm_map_t Map = (map); \
551 if (Map) { \
552 mutex_lock(&Map->s_lock); \
553 Map->ref_count++; \
554 mutex_unlock(&Map->s_lock); \
555 } \
556 MACRO_END
557
558 #define vm_map_reference_swap(map) vm_map_reference(map)
559 #define vm_map_res_reference(map)
560 #define vm_map_res_deallocate(map)
561
562 #endif /* TASK_SWAPPER */
563
564 /*
565 * Submap object. Must be used to create memory to be put
566 * in a submap by vm_map_submap.
567 */
568 extern vm_object_t vm_submap_object;
569
570 /*
571 * Wait and wakeup macros for in_transition map entries.
572 */
573 #define vm_map_entry_wait(map, interruptible) \
574 ((map)->timestamp++ , \
575 thread_sleep_lock_write((event_t)&(map)->hdr, \
576 &(map)->lock, interruptible))
577
578
579 #define vm_map_entry_wakeup(map) \
580 thread_wakeup((event_t)(&(map)->hdr))
581
582
583 #define vm_map_ref_fast(map) \
584 MACRO_BEGIN \
585 mutex_lock(&map->s_lock); \
586 map->ref_count++; \
587 vm_map_res_reference(map); \
588 mutex_unlock(&map->s_lock); \
589 MACRO_END
590
591 #define vm_map_dealloc_fast(map) \
592 MACRO_BEGIN \
593 register int c; \
594 \
595 mutex_lock(&map->s_lock); \
596 c = --map->ref_count; \
597 if (c > 0) \
598 vm_map_res_deallocate(map); \
599 mutex_unlock(&map->s_lock); \
600 if (c == 0) \
601 vm_map_destroy(map); \
602 MACRO_END
603
604
605 /* simplify map entries */
606 extern void vm_map_simplify_entry(
607 vm_map_t map,
608 vm_map_entry_t this_entry);
609 extern void vm_map_simplify(
610 vm_map_t map,
611 vm_map_offset_t start);
612
613 /* Move the information in a map copy object to a new map copy object */
614 extern vm_map_copy_t vm_map_copy_copy(
615 vm_map_copy_t copy);
616
617 /* Create a copy object from an object. */
618 extern kern_return_t vm_map_copyin_object(
619 vm_object_t object,
620 vm_object_offset_t offset,
621 vm_object_size_t size,
622 vm_map_copy_t *copy_result); /* OUT */
623
624 /* Enter a mapping */
625 extern kern_return_t vm_map_enter(
626 vm_map_t map,
627 vm_map_offset_t *address,
628 vm_map_size_t size,
629 vm_map_offset_t mask,
630 int flags,
631 vm_object_t object,
632 vm_object_offset_t offset,
633 boolean_t needs_copy,
634 vm_prot_t cur_protection,
635 vm_prot_t max_protection,
636 vm_inherit_t inheritance);
637
638 /* XXX should go away - replaced with regular enter of contig object */
639 extern kern_return_t vm_map_enter_cpm(
640 vm_map_t map,
641 vm_map_address_t *addr,
642 vm_map_size_t size,
643 int flags);
644
645 extern kern_return_t vm_map_remap(
646 vm_map_t target_map,
647 vm_map_offset_t *address,
648 vm_map_size_t size,
649 vm_map_offset_t mask,
650 boolean_t anywhere,
651 vm_map_t src_map,
652 vm_map_offset_t memory_address,
653 boolean_t copy,
654 vm_prot_t *cur_protection,
655 vm_prot_t *max_protection,
656 vm_inherit_t inheritance);
657
658
659 /*
660 * Read and write from a kernel buffer to a specified map.
661 */
662 extern kern_return_t vm_map_write_user(
663 vm_map_t map,
664 void *src_p,
665 vm_map_offset_t dst_addr,
666 vm_size_t size);
667
668 extern kern_return_t vm_map_read_user(
669 vm_map_t map,
670 vm_map_offset_t src_addr,
671 void *dst_p,
672 vm_size_t size);
673
674 /* Create a new task map using an existing task map as a template. */
675 extern vm_map_t vm_map_fork(
676 vm_map_t old_map);
677
678 /* Change inheritance */
679 extern kern_return_t vm_map_inherit(
680 vm_map_t map,
681 vm_map_offset_t start,
682 vm_map_offset_t end,
683 vm_inherit_t new_inheritance);
684
685 /* Add or remove machine-dependent attributes from map regions */
686 extern kern_return_t vm_map_machine_attribute(
687 vm_map_t map,
688 vm_map_offset_t start,
689 vm_map_offset_t end,
690 vm_machine_attribute_t attribute,
691 vm_machine_attribute_val_t* value); /* IN/OUT */
692
693 extern kern_return_t vm_map_msync(
694 vm_map_t map,
695 vm_map_address_t address,
696 vm_map_size_t size,
697 vm_sync_t sync_flags);
698
699 /* Set paging behavior */
700 extern kern_return_t vm_map_behavior_set(
701 vm_map_t map,
702 vm_map_offset_t start,
703 vm_map_offset_t end,
704 vm_behavior_t new_behavior);
705
706 extern kern_return_t vm_map_purgable_control(
707 vm_map_t map,
708 vm_map_offset_t address,
709 vm_purgable_t control,
710 int *state);
711
712 extern kern_return_t vm_map_region(
713 vm_map_t map,
714 vm_map_offset_t *address,
715 vm_map_size_t *size,
716 vm_region_flavor_t flavor,
717 vm_region_info_t info,
718 mach_msg_type_number_t *count,
719 mach_port_t *object_name);
720
721 extern kern_return_t vm_map_region_recurse_64(
722 vm_map_t map,
723 vm_map_offset_t *address,
724 vm_map_size_t *size,
725 natural_t *nesting_depth,
726 vm_region_submap_info_64_t info,
727 mach_msg_type_number_t *count);
728
729 extern kern_return_t vm_map_page_info(
730 vm_map_t map,
731 vm_map_offset_t offset,
732 int *disposition,
733 int *ref_count);
734
735 extern kern_return_t vm_map_submap(
736 vm_map_t map,
737 vm_map_offset_t start,
738 vm_map_offset_t end,
739 vm_map_t submap,
740 vm_map_offset_t offset,
741 boolean_t use_pmap);
742
743 extern void vm_map_submap_pmap_clean(
744 vm_map_t map,
745 vm_map_offset_t start,
746 vm_map_offset_t end,
747 vm_map_t sub_map,
748 vm_map_offset_t offset);
749
750 /* Convert from a map entry port to a map */
751 extern vm_map_t convert_port_entry_to_map(
752 ipc_port_t port);
753
754 /* Convert from a port to a vm_object */
755 extern vm_object_t convert_port_entry_to_object(
756 ipc_port_t port);
757
758
759 #endif /* MACH_KERNEL_PRIVATE */
760
761 __BEGIN_DECLS
762
763 /* Create an empty map */
764 extern vm_map_t vm_map_create(
765 pmap_t pmap,
766 vm_map_offset_t min_off,
767 vm_map_offset_t max_off,
768 boolean_t pageable);
769
770 /* Get rid of a map */
771 extern void vm_map_destroy(
772 vm_map_t map);
773 /* Lose a reference */
774 extern void vm_map_deallocate(
775 vm_map_t map);
776
777 extern vm_map_t vm_map_switch(
778 vm_map_t map);
779
780 /* Change protection */
781 extern kern_return_t vm_map_protect(
782 vm_map_t map,
783 vm_map_offset_t start,
784 vm_map_offset_t end,
785 vm_prot_t new_prot,
786 boolean_t set_max);
787
788 /* Check protection */
789 extern boolean_t vm_map_check_protection(
790 vm_map_t map,
791 vm_map_offset_t start,
792 vm_map_offset_t end,
793 vm_prot_t protection);
794
795 /* wire down a region */
796 extern kern_return_t vm_map_wire(
797 vm_map_t map,
798 vm_map_offset_t start,
799 vm_map_offset_t end,
800 vm_prot_t access_type,
801 boolean_t user_wire);
802
803 /* unwire a region */
804 extern kern_return_t vm_map_unwire(
805 vm_map_t map,
806 vm_map_offset_t start,
807 vm_map_offset_t end,
808 boolean_t user_wire);
809
810 /* Deallocate a region */
811 extern kern_return_t vm_map_remove(
812 vm_map_t map,
813 vm_map_offset_t start,
814 vm_map_offset_t end,
815 boolean_t flags);
816
817 /* Discard a copy without using it */
818 extern void vm_map_copy_discard(
819 vm_map_copy_t copy);
820
821 /* Overwrite existing memory with a copy */
822 extern kern_return_t vm_map_copy_overwrite(
823 vm_map_t dst_map,
824 vm_map_address_t dst_addr,
825 vm_map_copy_t copy,
826 int interruptible);
827
828 /* Place a copy into a map */
829 extern kern_return_t vm_map_copyout(
830 vm_map_t dst_map,
831 vm_map_address_t *dst_addr, /* OUT */
832 vm_map_copy_t copy);
833
834 extern kern_return_t vm_map_copyin_common(
835 vm_map_t src_map,
836 vm_map_address_t src_addr,
837 vm_map_size_t len,
838 boolean_t src_destroy,
839 boolean_t src_volatile,
840 vm_map_copy_t *copy_result, /* OUT */
841 boolean_t use_maxprot);
842
843 /*
844 * Macros to invoke vm_map_copyin_common. vm_map_copyin is the
845 * usual form; it handles a copyin based on the current protection
846 * (current protection == VM_PROT_NONE) is a failure.
847 * vm_map_copyin_maxprot handles a copyin based on maximum possible
848 * access. The difference is that a region with no current access
849 * BUT possible maximum access is rejected by vm_map_copyin(), but
850 * returned by vm_map_copyin_maxprot.
851 */
852 #define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \
853 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
854 FALSE, copy_result, FALSE)
855
856 #define vm_map_copyin_maxprot(src_map, \
857 src_addr, len, src_destroy, copy_result) \
858 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
859 FALSE, copy_result, TRUE)
860
861 /*
862 * Macros for rounding and truncation of vm_map offsets and sizes
863 */
864 #define vm_map_round_page(x) (((vm_map_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
865 #define vm_map_trunc_page(x) ((vm_map_offset_t)(x) & ~((signed)PAGE_MASK))
866
867 /*
868 * Flags for vm_map_remove() and vm_map_delete()
869 */
870 #define VM_MAP_NO_FLAGS 0x0
871 #define VM_MAP_REMOVE_KUNWIRE 0x1
872 #define VM_MAP_REMOVE_INTERRUPTIBLE 0x2
873 #define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4
874 #define VM_MAP_REMOVE_SAVE_ENTRIES 0x8
875
876 /* Support for shared regions */
877 extern kern_return_t vm_region_clone(
878 ipc_port_t src_region,
879 ipc_port_t dst_region);
880
881 extern kern_return_t vm_map_region_replace(
882 vm_map_t target_map,
883 ipc_port_t old_region,
884 ipc_port_t new_region,
885 vm_map_offset_t start,
886 vm_map_offset_t end);
887
888 /* Support for UPLs from vm_maps */
889
890 extern kern_return_t vm_map_get_upl(
891 vm_map_t target_map,
892 vm_map_offset_t map_offset,
893 vm_size_t *size,
894 upl_t *upl,
895 upl_page_info_array_t page_info,
896 mach_msg_type_number_t *page_infoCnt,
897 integer_t *flags,
898 integer_t force_data_sync);
899
900 __END_DECLS
901
902 #endif /* KERNEL_PRIVATE */
903
904 #endif /* _VM_VM_MAP_H_ */