2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
55 * Author: Avadis Tevanian, Jr., Michael Wayne Young
58 * Virtual memory map module definitions.
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>
76 typedef struct vm_map_entry
*vm_map_entry_t
;
78 extern void kernel_vm_map_reference(vm_map_t map
);
80 #ifndef MACH_KERNEL_PRIVATE
82 struct vm_map_entry
{};
84 extern void vm_map_reference(vm_map_t map
);
85 extern vm_map_t
current_map(void);
87 #else /* MACH_KERNEL_PRIVATE */
90 #include <task_swapper.h>
91 #include <mach_assert.h>
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>
99 #define shared_region_mapping_lock_init(object) \
100 mutex_init(&(object)->Lock, ETAP_VM_OBJ)
101 #define shared_region_mapping_lock(object) mutex_lock(&(object)->Lock)
102 #define shared_region_mapping_unlock(object) mutex_unlock(&(object)->Lock)
103 #include <kern/thread_act.h>
105 #define current_map_fast() (current_act_fast()->map)
106 #define current_map() (current_map_fast())
111 * vm_map_t the high-level address map data structure.
112 * vm_map_entry_t an entry in an address map.
113 * vm_map_version_t a timestamp of a map, for use with vm_map_lookup
114 * vm_map_copy_t represents memory copied from an address map,
115 * used for inter-map copy operations
119 * Type: vm_map_object_t [internal use only]
122 * The target of an address mapping, either a virtual
123 * memory object or a sub map (of the kernel map).
125 typedef union vm_map_object
{
126 struct vm_object
*vm_object
; /* object object */
127 struct vm_map
*sub_map
; /* belongs to another map */
130 #define named_entry_lock_init(object) mutex_init(&(object)->Lock, ETAP_VM_OBJ)
131 #define named_entry_lock(object) mutex_lock(&(object)->Lock)
132 #define named_entry_unlock(object) mutex_unlock(&(object)->Lock)
135 * Type: vm_named_entry_t [internal use only]
138 * Description of a mapping to a memory cache object.
141 * While the handle to this object is used as a means to map
142 * and pass around the right to map regions backed by pagers
143 * of all sorts, the named_entry itself is only manipulated
144 * by the kernel. Named entries hold information on the
145 * right to map a region of a cached object. Namely,
146 * the target cache object, the beginning and ending of the
147 * region to be mapped, and the permissions, (read, write)
148 * with which it can be mapped.
152 struct vm_named_entry
{
153 decl_mutex_data(, Lock
) /* Synchronization */
154 vm_object_t object
; /* object I point to */
155 vm_object_offset_t offset
; /* offset into object */
157 ipc_port_t pager
; /* amo pager port */
158 vm_map_t map
; /* map backing submap */
160 unsigned int size
; /* size of region */
161 unsigned int protection
; /* access permissions */
162 int ref_count
; /* Number of references */
164 /* boolean_t */ internal
:1, /* is an internal object */
165 /* boolean_t */ is_sub_map
:1; /* is object is a submap? */
168 typedef struct vm_named_entry
*vm_named_entry_t
;
172 * Type: vm_map_entry_t [internal use only]
175 * A single mapping within an address map.
178 * Address map entries consist of start and end addresses,
179 * a VM object (or sub map) and offset into that object,
180 * and user-exported inheritance and protection information.
181 * Control information for virtual copy operations is also
182 * stored in the address map entry.
184 struct vm_map_links
{
185 struct vm_map_entry
*prev
; /* previous entry */
186 struct vm_map_entry
*next
; /* next entry */
187 vm_offset_t start
; /* start address */
188 vm_offset_t end
; /* end address */
191 struct vm_map_entry
{
192 struct vm_map_links links
; /* links to other entries */
193 #define vme_prev links.prev
194 #define vme_next links.next
195 #define vme_start links.start
196 #define vme_end links.end
197 union vm_map_object object
; /* object I point to */
198 vm_object_offset_t offset
; /* offset into object */
200 /* boolean_t */ is_shared
:1, /* region is shared */
201 /* boolean_t */ is_sub_map
:1, /* Is "object" a submap? */
202 /* boolean_t */ in_transition
:1, /* Entry being changed */
203 /* boolean_t */ needs_wakeup
:1, /* Waiters on in_transition */
204 /* vm_behavior_t */ behavior
:2, /* user paging behavior hint */
205 /* behavior is not defined for submap type */
206 /* boolean_t */ needs_copy
:1, /* object need to be copied? */
207 /* Only in task maps: */
208 /* vm_prot_t */ protection
:3, /* protection code */
209 /* vm_prot_t */ max_protection
:3,/* maximum protection */
210 /* vm_inherit_t */ inheritance
:2, /* inheritance */
211 /* nested pmap */ use_pmap
:1, /* nested pmaps */
212 /* user alias */ alias
:8;
213 unsigned short wired_count
; /* can be paged if = 0 */
214 unsigned short user_wired_count
; /* for vm_wire */
218 * wired_counts are unsigned short. This value is used to safeguard
219 * against any mishaps due to runaway user programs.
221 #define MAX_WIRE_COUNT 65535
226 * Type: struct vm_map_header
229 * Header for a vm_map and a vm_map_copy.
231 struct vm_map_header
{
232 struct vm_map_links links
; /* first, last, min, max */
233 int nentries
; /* Number of entries */
234 boolean_t entries_pageable
;
235 /* are map entries pageable? */
239 * Type: vm_map_t [exported; contents invisible]
242 * An address map -- a directory relating valid
243 * regions of a task's address space to the corresponding
244 * virtual memory objects.
247 * Maps are doubly-linked lists of map entries, sorted
248 * by address. One hint is used to start
249 * searches again from the last successful search,
250 * insertion, or removal. Another hint is used to
251 * quickly find free space.
254 lock_t lock
; /* uni- and smp-lock */
255 struct vm_map_header hdr
; /* Map entry header */
256 #define min_offset hdr.links.start /* start of range */
257 #define max_offset hdr.links.end /* end of range */
258 pmap_t pmap
; /* Physical map */
259 vm_size_t size
; /* virtual size */
260 int ref_count
; /* Reference count */
262 int res_count
; /* Residence count (swap) */
263 int sw_state
; /* Swap state */
264 #endif /* TASK_SWAPPER */
265 decl_mutex_data(, s_lock
) /* Lock ref, res, hint fields */
266 vm_map_entry_t hint
; /* hint for quick lookups */
267 vm_map_entry_t first_free
; /* First free space hint */
268 boolean_t wait_for_space
; /* Should callers wait
270 boolean_t wiring_required
;/* All memory wired? */
271 boolean_t no_zero_fill
; /* No zero fill absent pages */
272 unsigned int timestamp
; /* Version number */
275 #define vm_map_to_entry(map) ((struct vm_map_entry *) &(map)->hdr.links)
276 #define vm_map_first_entry(map) ((map)->hdr.links.next)
277 #define vm_map_last_entry(map) ((map)->hdr.links.prev)
281 * VM map swap states. There are no transition states.
283 #define MAP_SW_IN 1 /* map is swapped in; residence count > 0 */
284 #define MAP_SW_OUT 2 /* map is out (res_count == 0 */
285 #endif /* TASK_SWAPPER */
288 * Type: vm_map_version_t [exported; contents invisible]
291 * Map versions may be used to quickly validate a previous
295 * Because they are bulky objects, map versions are usually
296 * passed by reference.
299 * Just a timestamp for the main map.
301 typedef struct vm_map_version
{
302 unsigned int main_timestamp
;
306 * Type: vm_map_copy_t [exported; contents invisible]
309 * A map copy object represents a region of virtual memory
310 * that has been copied from an address map but is still
313 * A map copy object may only be used by a single thread
317 * There are three formats for map copy objects.
318 * The first is very similar to the main
319 * address map in structure, and as a result, some
320 * of the internal maintenance functions/macros can
321 * be used with either address maps or map copy objects.
323 * The map copy object contains a header links
324 * entry onto which the other entries that represent
325 * the region are chained.
327 * The second format is a single vm object. This is used
328 * primarily in the pageout path. The third format is a
329 * list of vm pages. An optional continuation provides
330 * a hook to be called to obtain more of the memory,
331 * or perform other operations. The continuation takes 3
332 * arguments, a saved arg buffer, a pointer to a new vm_map_copy
333 * (returned) and an abort flag (abort if TRUE).
336 #define VM_MAP_COPY_PAGE_LIST_MAX 20
337 #define VM_MAP_COPY_PAGE_LIST_MAX_SIZE (VM_MAP_COPY_PAGE_LIST_MAX * PAGE_SIZE)
341 * Options for vm_map_copyin_page_list.
344 #define VM_MAP_COPYIN_OPT_VM_PROT 0x7
345 #define VM_MAP_COPYIN_OPT_SRC_DESTROY 0x8
346 #define VM_MAP_COPYIN_OPT_STEAL_PAGES 0x10
347 #define VM_MAP_COPYIN_OPT_PMAP_ENTER 0x20
348 #define VM_MAP_COPYIN_OPT_NO_ZERO_FILL 0x40
351 * Continuation structures for vm_map_copyin_page_list.
355 vm_offset_t src_addr
;
357 vm_offset_t destroy_addr
;
358 vm_size_t destroy_len
;
360 } vm_map_copyin_args_data_t
, *vm_map_copyin_args_t
;
362 #define VM_MAP_COPYIN_ARGS_NULL ((vm_map_copyin_args_t) 0)
365 /* vm_map_copy_cont_t is a type definition/prototype
366 * for the cont function pointer in vm_map_copy structure.
368 typedef kern_return_t (*vm_map_copy_cont_t
)(
369 vm_map_copyin_args_t
,
372 #define VM_MAP_COPY_CONT_NULL ((vm_map_copy_cont_t) 0)
376 #define VM_MAP_COPY_ENTRY_LIST 1
377 #define VM_MAP_COPY_OBJECT 2
378 #define VM_MAP_COPY_PAGE_LIST 3
379 #define VM_MAP_COPY_KERNEL_BUFFER 4
380 vm_object_offset_t offset
;
383 struct vm_map_header hdr
; /* ENTRY_LIST */
384 struct { /* OBJECT */
386 vm_size_t index
; /* record progress as pages
387 * are moved from object to
388 * page list; must be zero
389 * when first invoking
390 * vm_map_object_to_page_list
393 struct { /* PAGE_LIST */
395 boolean_t page_loose
;
396 vm_map_copy_cont_t cont
;
397 vm_map_copyin_args_t cont_args
;
398 vm_page_t page_list
[VM_MAP_COPY_PAGE_LIST_MAX
];
400 struct { /* KERNEL_BUFFER */
402 vm_size_t kalloc_size
; /* size of this copy_t */
408 #define cpy_hdr c_u.hdr
410 #define cpy_object c_u.c_o.object
411 #define cpy_index c_u.c_o.index
413 #define cpy_page_list c_u.c_p.page_list
414 #define cpy_npages c_u.c_p.npages
415 #define cpy_page_loose c_u.c_p.page_loose
416 #define cpy_cont c_u.c_p.cont
417 #define cpy_cont_args c_u.c_p.cont_args
419 #define cpy_kdata c_u.c_k.kdata
420 #define cpy_kalloc_size c_u.c_k.kalloc_size
424 * Useful macros for entry list copy objects
427 #define vm_map_copy_to_entry(copy) \
428 ((struct vm_map_entry *) &(copy)->cpy_hdr.links)
429 #define vm_map_copy_first_entry(copy) \
430 ((copy)->cpy_hdr.links.next)
431 #define vm_map_copy_last_entry(copy) \
432 ((copy)->cpy_hdr.links.prev)
435 * Continuation macros for page list copy objects
438 #define vm_map_copy_invoke_cont(old_copy, new_copy, result) \
440 assert(vm_map_copy_cont_is_valid(old_copy)); \
441 vm_map_copy_page_discard(old_copy); \
442 *result = (*((old_copy)->cpy_cont))((old_copy)->cpy_cont_args, \
444 (old_copy)->cpy_cont = VM_MAP_COPY_CONT_NULL; \
447 #define vm_map_copy_invoke_extend_cont(old_copy, new_copy, result) \
449 assert(vm_map_copy_cont_is_valid(old_copy)); \
450 *result = (*((old_copy)->cpy_cont))((old_copy)->cpy_cont_args, \
452 (old_copy)->cpy_cont = VM_MAP_COPY_CONT_NULL; \
455 #define vm_map_copy_abort_cont(old_copy) \
457 assert(vm_map_copy_cont_is_valid(old_copy)); \
458 vm_map_copy_page_discard(old_copy); \
459 (*((old_copy)->cpy_cont))((old_copy)->cpy_cont_args, \
460 (vm_map_copy_t *) 0); \
461 (old_copy)->cpy_cont = VM_MAP_COPY_CONT_NULL; \
462 (old_copy)->cpy_cont_args = VM_MAP_COPYIN_ARGS_NULL; \
465 #define vm_map_copy_has_cont(copy) \
466 (((copy)->cpy_cont) != VM_MAP_COPY_CONT_NULL)
469 * Macro to determine number of pages in a page-list copy chain.
472 #define vm_map_copy_page_count(copy) \
473 (round_page(((vm_offset_t)(copy)->offset - trunc_page((vm_offset_t)(copy)->offset)) + (copy)->size) / PAGE_SIZE)
476 * Macros: vm_map_lock, etc. [internal use only]
478 * Perform locking on the data portion of a map.
479 * When multiple maps are to be locked, order by map address.
480 * (See vm_map.c::vm_remap())
483 #define vm_map_lock_init(map) \
485 lock_init(&(map)->lock, TRUE, ETAP_VM_MAP, ETAP_VM_MAP_I); \
486 (map)->timestamp = 0; \
488 #define vm_map_lock(map) \
490 lock_write(&(map)->lock); \
491 (map)->timestamp++; \
494 #define vm_map_unlock(map) lock_write_done(&(map)->lock)
495 #define vm_map_lock_read(map) lock_read(&(map)->lock)
496 #define vm_map_unlock_read(map) lock_read_done(&(map)->lock)
497 #define vm_map_lock_write_to_read(map) \
498 lock_write_to_read(&(map)->lock)
499 #define vm_map_lock_read_to_write(map) \
500 (lock_read_to_write(&(map)->lock) || (((map)->timestamp++), 0))
502 extern zone_t vm_map_copy_zone
; /* zone for vm_map_copy structures */
505 * Exported procedures that operate on vm_map_t.
508 /* Initialize the module */
509 extern void vm_map_init(void);
511 /* Allocate a range in the specified virtual address map and
512 * return the entry allocated for that range. */
513 extern kern_return_t
vm_map_find_space(
515 vm_offset_t
*address
, /* OUT */
518 vm_map_entry_t
*o_entry
); /* OUT */
520 /* Lookup map entry containing or the specified address in the given map */
521 extern boolean_t
vm_map_lookup_entry(
524 vm_map_entry_t
*entry
); /* OUT */
526 /* A version of vm_map_copy_discard that can be called
527 * as a continuation from a vm_map_copy page list. */
528 extern kern_return_t
vm_map_copy_discard_cont(
529 vm_map_copyin_args_t cont_args
,
530 vm_map_copy_t
*copy_result
);/* OUT */
532 /* Find the VM object, offset, and protection for a given virtual address
533 * in the specified map, assuming a page fault of the type specified. */
534 extern kern_return_t
vm_map_lookup_locked(
535 vm_map_t
*var_map
, /* IN/OUT */
537 vm_prot_t fault_type
,
538 vm_map_version_t
*out_version
, /* OUT */
539 vm_object_t
*object
, /* OUT */
540 vm_object_offset_t
*offset
, /* OUT */
541 vm_prot_t
*out_prot
, /* OUT */
542 boolean_t
*wired
, /* OUT */
543 int *behavior
, /* OUT */
544 vm_object_offset_t
*lo_offset
, /* OUT */
545 vm_object_offset_t
*hi_offset
, /* OUT */
546 vm_map_t
*pmap_map
); /* OUT */
548 /* Verifies that the map has not changed since the given version. */
549 extern boolean_t
vm_map_verify(
551 vm_map_version_t
*version
); /* REF */
553 /* Split a vm_map_entry into 2 entries */
554 extern void _vm_map_clip_start(
555 struct vm_map_header
*map_header
,
556 vm_map_entry_t entry
,
559 extern vm_map_entry_t
vm_map_entry_insert(
561 vm_map_entry_t insp_entry
,
565 vm_object_offset_t offset
,
566 boolean_t needs_copy
,
568 boolean_t in_transition
,
569 vm_prot_t cur_protection
,
570 vm_prot_t max_protection
,
571 vm_behavior_t behavior
,
572 vm_inherit_t inheritance
,
573 unsigned wired_count
);
575 extern kern_return_t
vm_remap_extract(
580 struct vm_map_header
*map_header
,
581 vm_prot_t
*cur_protection
,
582 vm_prot_t
*max_protection
,
583 vm_inherit_t inheritance
,
586 extern kern_return_t
vm_remap_range_allocate(
588 vm_offset_t
*address
,
592 vm_map_entry_t
*map_entry
);
594 extern kern_return_t
vm_remap_extract(
599 struct vm_map_header
*map_header
,
600 vm_prot_t
*cur_protection
,
601 vm_prot_t
*max_protection
,
602 vm_inherit_t inheritance
,
605 extern kern_return_t
vm_remap_range_allocate(
607 vm_offset_t
*address
,
611 vm_map_entry_t
*map_entry
);
614 * Functions implemented as macros
616 #define vm_map_min(map) ((map)->min_offset)
617 /* Lowest valid address in
620 #define vm_map_max(map) ((map)->max_offset)
621 /* Highest valid address */
623 #define vm_map_pmap(map) ((map)->pmap)
624 /* Physical map associated
625 * with this address map */
627 #define vm_map_verify_done(map, version) vm_map_unlock_read(map)
628 /* Operation that required
629 * a verified lookup is
633 * Macros/functions for map residence counts and swapin/out of vm maps
638 /* Gain a reference to an existing map */
639 extern void vm_map_reference(
641 /* Lose a residence count */
642 extern void vm_map_res_deallocate(
644 /* Gain a residence count on a map */
645 extern void vm_map_res_reference(
647 /* Gain reference & residence counts to possibly swapped-out map */
648 extern void vm_map_reference_swap(
651 #else /* MACH_ASSERT */
653 #define vm_map_reference(map) \
655 vm_map_t Map = (map); \
657 mutex_lock(&Map->s_lock); \
660 mutex_unlock(&Map->s_lock); \
664 #define vm_map_res_reference(map) \
666 vm_map_t Lmap = (map); \
667 if (Lmap->res_count == 0) { \
668 mutex_unlock(&Lmap->s_lock); \
670 vm_map_swapin(Lmap); \
671 mutex_lock(&Lmap->s_lock); \
673 vm_map_unlock(Lmap); \
678 #define vm_map_res_deallocate(map) \
680 vm_map_t Map = (map); \
681 if (--Map->res_count == 0) { \
682 mutex_unlock(&Map->s_lock); \
684 vm_map_swapout(Map); \
685 vm_map_unlock(Map); \
686 mutex_lock(&Map->s_lock); \
690 #define vm_map_reference_swap(map) \
692 vm_map_t Map = (map); \
693 mutex_lock(&Map->s_lock); \
695 vm_map_res_reference(Map); \
696 mutex_unlock(&Map->s_lock); \
698 #endif /* MACH_ASSERT */
700 extern void vm_map_swapin(
703 extern void vm_map_swapout(
706 #else /* TASK_SWAPPER */
708 #define vm_map_reference(map) \
710 vm_map_t Map = (map); \
712 mutex_lock(&Map->s_lock); \
714 mutex_unlock(&Map->s_lock); \
718 #define vm_map_reference_swap(map) vm_map_reference(map)
719 #define vm_map_res_reference(map)
720 #define vm_map_res_deallocate(map)
722 #endif /* TASK_SWAPPER */
725 * Submap object. Must be used to create memory to be put
726 * in a submap by vm_map_submap.
728 extern vm_object_t vm_submap_object
;
731 * Wait and wakeup macros for in_transition map entries.
733 #define vm_map_entry_wait(map, interruptible) \
735 assert_wait((event_t)&(map)->hdr, interruptible); \
736 vm_map_unlock(map); \
737 thread_block((void (*)(void))0); \
740 #define vm_map_entry_wakeup(map) thread_wakeup((event_t)(&(map)->hdr))
744 #define vm_map_ref_fast(map) \
746 mutex_lock(&map->s_lock); \
748 vm_map_res_reference(map); \
749 mutex_unlock(&map->s_lock); \
752 #define vm_map_dealloc_fast(map) \
756 mutex_lock(&map->s_lock); \
757 c = --map->ref_count; \
759 vm_map_res_deallocate(map); \
760 mutex_unlock(&map->s_lock); \
762 vm_map_destroy(map); \
766 /* simplify map entries */
767 extern void vm_map_simplify(
771 /* Steal all the pages from a vm_map_copy page_list */
772 extern void vm_map_copy_steal_pages(
775 /* Discard a copy without using it */
776 extern void vm_map_copy_discard(
779 /* Move the information in a map copy object to a new map copy object */
780 extern vm_map_copy_t
vm_map_copy_copy(
783 /* Overwrite existing memory with a copy */
784 extern kern_return_t
vm_map_copy_overwrite(
786 vm_offset_t dst_addr
,
790 /* Version of vm_map_copyout() for page list vm map copies. */
791 extern kern_return_t
vm_map_copyout_page_list(
793 vm_offset_t
*dst_addr
, /* OUT */
796 /* Get rid of the pages in a page_list copy. */
797 extern void vm_map_copy_page_discard(
800 /* Create a copy object from an object. */
801 extern kern_return_t
vm_map_copyin_object(
803 vm_object_offset_t offset
,
804 vm_object_size_t size
,
805 vm_map_copy_t
*copy_result
); /* OUT */
808 /* Make a copy of a region */
809 /* Make a copy of a region using a page list copy */
810 extern kern_return_t
vm_map_copyin_page_list(
812 vm_offset_t src_addr
,
815 vm_map_copy_t
*copy_result
, /* OUT */
818 extern vm_map_t
vm_map_switch(
821 extern int vm_map_copy_cont_is_valid(
826 #endif /* !MACH_KERNEL_PRIVATE */
828 /* Get rid of a map */
829 extern void vm_map_destroy(
831 /* Lose a reference */
832 extern void vm_map_deallocate(
835 /* Create an empty map */
836 extern vm_map_t
vm_map_create(
843 /* Enter a mapping */
844 extern kern_return_t
vm_map_enter(
846 vm_offset_t
*address
,
851 vm_object_offset_t offset
,
852 boolean_t needs_copy
,
853 vm_prot_t cur_protection
,
854 vm_prot_t max_protection
,
855 vm_inherit_t inheritance
);
857 extern kern_return_t
vm_map_write_user(
859 vm_offset_t src_addr
,
860 vm_offset_t dst_addr
,
863 extern kern_return_t
vm_map_read_user(
865 vm_offset_t src_addr
,
866 vm_offset_t dst_addr
,
869 /* Create a new task map using an existing task map as a template. */
870 extern vm_map_t
vm_map_fork(
873 /* Change protection */
874 extern kern_return_t
vm_map_protect(
881 /* Change inheritance */
882 extern kern_return_t
vm_map_inherit(
886 vm_inherit_t new_inheritance
);
888 /* wire down a region */
889 extern kern_return_t
vm_map_wire(
893 vm_prot_t access_type
,
894 boolean_t user_wire
);
896 /* unwire a region */
897 extern kern_return_t
vm_map_unwire(
901 boolean_t user_wire
);
903 /* Deallocate a region */
904 extern kern_return_t
vm_map_remove(
910 /* Place a copy into a map */
911 extern kern_return_t
vm_map_copyout(
913 vm_offset_t
*dst_addr
, /* OUT */
917 /* Add or remove machine-dependent attributes from map regions */
918 extern kern_return_t
vm_map_machine_attribute(
922 vm_machine_attribute_t attribute
,
923 vm_machine_attribute_val_t
* value
); /* IN/OUT */
924 /* Set paging behavior */
925 extern kern_return_t
vm_map_behavior_set(
929 vm_behavior_t new_behavior
);
931 extern kern_return_t
vm_map_copyin_common(
933 vm_offset_t src_addr
,
935 boolean_t src_destroy
,
936 boolean_t src_volatile
,
937 vm_map_copy_t
*copy_result
, /* OUT */
938 boolean_t use_maxprot
);
940 extern kern_return_t
vm_map_submap(
949 * Macros to invoke vm_map_copyin_common. vm_map_copyin is the
950 * usual form; it handles a copyin based on the current protection
951 * (current protection == VM_PROT_NONE) is a failure.
952 * vm_map_copyin_maxprot handles a copyin based on maximum possible
953 * access. The difference is that a region with no current access
954 * BUT possible maximum access is rejected by vm_map_copyin(), but
955 * returned by vm_map_copyin_maxprot.
957 #define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \
958 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
959 FALSE, copy_result, FALSE)
961 #define vm_map_copyin_maxprot(src_map, \
962 src_addr, len, src_destroy, copy_result) \
963 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
964 FALSE, copy_result, TRUE)
966 #define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0)
969 * Flags for vm_map_remove() and vm_map_delete()
971 #define VM_MAP_NO_FLAGS 0x0
972 #define VM_MAP_REMOVE_KUNWIRE 0x1
973 #define VM_MAP_REMOVE_INTERRUPTIBLE 0x2
974 #define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4
977 #ifdef MACH_KERNEL_PRIVATE
979 /* address space shared region descriptor */
981 struct shared_region_mapping
{
982 decl_mutex_data(, Lock
) /* Synchronization */
984 ipc_port_t text_region
;
986 ipc_port_t data_region
;
988 vm_offset_t region_mappings
;
989 vm_offset_t client_base
;
990 vm_offset_t alternate_base
;
991 vm_offset_t alternate_next
;
994 struct shared_region_object_chain
*object_chain
;
995 struct shared_region_mapping
*self
;
996 struct shared_region_mapping
*next
;
999 typedef struct shared_region_mapping
*shared_region_mapping_t
;
1001 struct shared_region_object_chain
{
1002 shared_region_mapping_t object_chain_region
;
1004 struct shared_region_object_chain
*next
;
1007 typedef struct shared_region_object_chain
*shared_region_object_chain_t
;
1009 #endif /* MACH_KERNEL_PRIVATE */
1012 #endif /* _VM_VM_MAP_H_ */