2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
61 * Author: Avadis Tevanian, Jr., Michael Wayne Young
64 * Virtual memory map module definitions.
73 #include <mach/mach_types.h>
74 #include <mach/kern_return.h>
75 #include <mach/boolean.h>
76 #include <mach/vm_types.h>
77 #include <mach/vm_prot.h>
78 #include <mach/vm_inherit.h>
79 #include <mach/vm_behavior.h>
80 #include <mach/vm_param.h>
85 #include <sys/cdefs.h>
89 extern void vm_map_reference(vm_map_t map
);
90 extern vm_map_t
current_map(void);
92 /* Setup reserved areas in a new VM map */
93 extern kern_return_t
vm_map_exec(
101 #ifdef MACH_KERNEL_PRIVATE
103 #include <task_swapper.h>
104 #include <mach_assert.h>
106 #include <vm/vm_object.h>
107 #include <vm/vm_page.h>
108 #include <kern/lock.h>
109 #include <kern/zalloc.h>
110 #include <kern/macro_help.h>
112 #include <kern/thread.h>
114 #define current_map_fast() (current_thread()->map)
115 #define current_map() (current_map_fast())
120 * vm_map_t the high-level address map data structure.
121 * vm_map_entry_t an entry in an address map.
122 * vm_map_version_t a timestamp of a map, for use with vm_map_lookup
123 * vm_map_copy_t represents memory copied from an address map,
124 * used for inter-map copy operations
126 typedef struct vm_map_entry
*vm_map_entry_t
;
127 #define VM_MAP_ENTRY_NULL ((vm_map_entry_t) 0)
131 * Type: vm_map_object_t [internal use only]
134 * The target of an address mapping, either a virtual
135 * memory object or a sub map (of the kernel map).
137 typedef union vm_map_object
{
138 vm_object_t vm_object
; /* object object */
139 vm_map_t sub_map
; /* belongs to another map */
142 #define named_entry_lock_init(object) lck_mtx_init(&(object)->Lock, &vm_object_lck_grp, &vm_object_lck_attr)
143 #define named_entry_lock(object) lck_mtx_lock(&(object)->Lock)
144 #define named_entry_unlock(object) lck_mtx_unlock(&(object)->Lock)
147 * Type: vm_named_entry_t [internal use only]
150 * Description of a mapping to a memory cache object.
153 * While the handle to this object is used as a means to map
154 * and pass around the right to map regions backed by pagers
155 * of all sorts, the named_entry itself is only manipulated
156 * by the kernel. Named entries hold information on the
157 * right to map a region of a cached object. Namely,
158 * the target cache object, the beginning and ending of the
159 * region to be mapped, and the permissions, (read, write)
160 * with which it can be mapped.
164 struct vm_named_entry
{
165 decl_lck_mtx_data(, Lock
) /* Synchronization */
167 vm_object_t object
; /* object I point to */
168 memory_object_t pager
; /* amo pager port */
169 vm_map_t map
; /* map backing submap */
171 vm_object_offset_t offset
; /* offset into object */
172 vm_object_size_t size
; /* size of region */
173 vm_prot_t protection
; /* access permissions */
174 int ref_count
; /* Number of references */
175 unsigned int /* Is backing.xxx : */
176 /* boolean_t */ internal
:1, /* ... an internal object */
177 /* boolean_t */ is_sub_map
:1, /* ... a submap? */
178 /* boolean_t */ is_pager
:1; /* ... a pager port */
182 * Type: vm_map_entry_t [internal use only]
185 * A single mapping within an address map.
188 * Address map entries consist of start and end addresses,
189 * a VM object (or sub map) and offset into that object,
190 * and user-exported inheritance and protection information.
191 * Control information for virtual copy operations is also
192 * stored in the address map entry.
194 struct vm_map_links
{
195 struct vm_map_entry
*prev
; /* previous entry */
196 struct vm_map_entry
*next
; /* next entry */
197 vm_map_offset_t start
; /* start address */
198 vm_map_offset_t end
; /* end address */
201 struct vm_map_entry
{
202 struct vm_map_links links
; /* links to other entries */
203 #define vme_prev links.prev
204 #define vme_next links.next
205 #define vme_start links.start
206 #define vme_end links.end
207 union vm_map_object object
; /* object I point to */
208 vm_object_offset_t offset
; /* offset into object */
210 /* boolean_t */ is_shared
:1, /* region is shared */
211 /* boolean_t */ is_sub_map
:1, /* Is "object" a submap? */
212 /* boolean_t */ in_transition
:1, /* Entry being changed */
213 /* boolean_t */ needs_wakeup
:1, /* Waiters on in_transition */
214 /* vm_behavior_t */ behavior
:2, /* user paging behavior hint */
215 /* behavior is not defined for submap type */
216 /* boolean_t */ needs_copy
:1, /* object need to be copied? */
217 /* Only in task maps: */
218 /* vm_prot_t */ protection
:3, /* protection code */
219 /* vm_prot_t */ max_protection
:3,/* maximum protection */
220 /* vm_inherit_t */ inheritance
:2, /* inheritance */
221 /* boolean_t */ use_pmap
:1, /* nested pmaps */
224 * The "alias" field can be updated while holding the VM map lock
225 * "shared". It's OK as along as it's the only field that can be
226 * updated without the VM map "exclusive" lock.
228 /* unsigned char */ alias
:8, /* user alias */
229 /* boolean_t */ no_cache
:1, /* should new pages be cached? */
230 /* boolean_t */ permanent
:1, /* mapping can not be removed */
231 /* boolean_t */ superpage_size
:3,/* use superpages of a certain size */
232 /* boolean_t */ zero_wired_pages
:1, /* zero out the wired pages of this entry it is being deleted without unwiring them */
233 /* unsigned char */ pad
:2; /* available bits */
234 unsigned short wired_count
; /* can be paged if = 0 */
235 unsigned short user_wired_count
; /* for vm_wire */
239 * Convenience macros for dealing with superpages
240 * SUPERPAGE_NBASEPAGES is architecture dependent and defined in pmap.h
242 #define SUPERPAGE_SIZE (PAGE_SIZE*SUPERPAGE_NBASEPAGES)
243 #define SUPERPAGE_MASK (-SUPERPAGE_SIZE)
244 #define SUPERPAGE_ROUND_DOWN(a) (a & SUPERPAGE_MASK)
245 #define SUPERPAGE_ROUND_UP(a) ((a + SUPERPAGE_SIZE-1) & SUPERPAGE_MASK)
248 * wired_counts are unsigned short. This value is used to safeguard
249 * against any mishaps due to runaway user programs.
251 #define MAX_WIRE_COUNT 65535
256 * Type: struct vm_map_header
259 * Header for a vm_map and a vm_map_copy.
261 struct vm_map_header
{
262 struct vm_map_links links
; /* first, last, min, max */
263 int nentries
; /* Number of entries */
264 boolean_t entries_pageable
;
265 /* are map entries pageable? */
269 * Type: vm_map_t [exported; contents invisible]
272 * An address map -- a directory relating valid
273 * regions of a task's address space to the corresponding
274 * virtual memory objects.
277 * Maps are doubly-linked lists of map entries, sorted
278 * by address. One hint is used to start
279 * searches again from the last successful search,
280 * insertion, or removal. Another hint is used to
281 * quickly find free space.
284 lock_t lock
; /* uni- and smp-lock */
285 struct vm_map_header hdr
; /* Map entry header */
286 #define min_offset hdr.links.start /* start of range */
287 #define max_offset hdr.links.end /* end of range */
288 pmap_t pmap
; /* Physical map */
289 vm_map_size_t size
; /* virtual size */
290 vm_map_size_t user_wire_limit
;/* rlimit on user locked memory */
291 vm_map_size_t user_wire_size
; /* current size of user locked memory in this map */
292 int ref_count
; /* Reference count */
294 int res_count
; /* Residence count (swap) */
295 int sw_state
; /* Swap state */
296 #endif /* TASK_SWAPPER */
297 decl_lck_mtx_data(, s_lock
) /* Lock ref, res fields */
298 lck_mtx_ext_t s_lock_ext
;
299 vm_map_entry_t hint
; /* hint for quick lookups */
300 vm_map_entry_t first_free
; /* First free space hint */
301 boolean_t wait_for_space
; /* Should callers wait
303 boolean_t wiring_required
;/* All memory wired? */
304 boolean_t no_zero_fill
; /* No zero fill absent pages */
305 boolean_t mapped
; /* has this map been mapped */
306 boolean_t switch_protect
; /* Protect map from write faults while switched */
307 unsigned int timestamp
; /* Version number */
308 unsigned int color_rr
; /* next color (not protected by a lock) */
311 #define vm_map_to_entry(map) ((struct vm_map_entry *) &(map)->hdr.links)
312 #define vm_map_first_entry(map) ((map)->hdr.links.next)
313 #define vm_map_last_entry(map) ((map)->hdr.links.prev)
317 * VM map swap states. There are no transition states.
319 #define MAP_SW_IN 1 /* map is swapped in; residence count > 0 */
320 #define MAP_SW_OUT 2 /* map is out (res_count == 0 */
321 #endif /* TASK_SWAPPER */
324 * Type: vm_map_version_t [exported; contents invisible]
327 * Map versions may be used to quickly validate a previous
331 * Because they are bulky objects, map versions are usually
332 * passed by reference.
335 * Just a timestamp for the main map.
337 typedef struct vm_map_version
{
338 unsigned int main_timestamp
;
342 * Type: vm_map_copy_t [exported; contents invisible]
345 * A map copy object represents a region of virtual memory
346 * that has been copied from an address map but is still
349 * A map copy object may only be used by a single thread
353 * There are three formats for map copy objects.
354 * The first is very similar to the main
355 * address map in structure, and as a result, some
356 * of the internal maintenance functions/macros can
357 * be used with either address maps or map copy objects.
359 * The map copy object contains a header links
360 * entry onto which the other entries that represent
361 * the region are chained.
363 * The second format is a single vm object. This was used
364 * primarily in the pageout path - but is not currently used
365 * except for placeholder copy objects (see vm_map_copy_copy()).
367 * The third format is a kernel buffer copy object - for data
368 * small enough that physical copies were the most efficient
374 #define VM_MAP_COPY_ENTRY_LIST 1
375 #define VM_MAP_COPY_OBJECT 2
376 #define VM_MAP_COPY_KERNEL_BUFFER 3
377 vm_object_offset_t offset
;
380 struct vm_map_header hdr
; /* ENTRY_LIST */
381 vm_object_t object
; /* OBJECT */
383 void *kdata
; /* KERNEL_BUFFER */
384 vm_size_t kalloc_size
; /* size of this copy_t */
390 #define cpy_hdr c_u.hdr
392 #define cpy_object c_u.object
394 #define cpy_kdata c_u.c_k.kdata
395 #define cpy_kalloc_size c_u.c_k.kalloc_size
399 * Useful macros for entry list copy objects
402 #define vm_map_copy_to_entry(copy) \
403 ((struct vm_map_entry *) &(copy)->cpy_hdr.links)
404 #define vm_map_copy_first_entry(copy) \
405 ((copy)->cpy_hdr.links.next)
406 #define vm_map_copy_last_entry(copy) \
407 ((copy)->cpy_hdr.links.prev)
410 * Macros: vm_map_lock, etc. [internal use only]
412 * Perform locking on the data portion of a map.
413 * When multiple maps are to be locked, order by map address.
414 * (See vm_map.c::vm_remap())
417 #define vm_map_lock_init(map) \
418 ((map)->timestamp = 0 , \
419 lock_init(&(map)->lock, TRUE, 0, 0))
421 #define vm_map_lock(map) lock_write(&(map)->lock)
422 #define vm_map_unlock(map) \
423 ((map)->timestamp++ , lock_write_done(&(map)->lock))
424 #define vm_map_lock_read(map) lock_read(&(map)->lock)
425 #define vm_map_unlock_read(map) lock_read_done(&(map)->lock)
426 #define vm_map_lock_write_to_read(map) \
427 ((map)->timestamp++ , lock_write_to_read(&(map)->lock))
428 /* lock_read_to_write() returns FALSE on failure. Macro evaluates to
429 * zero on success and non-zero value on failure.
431 #define vm_map_lock_read_to_write(map) (lock_read_to_write(&(map)->lock) != TRUE)
434 * Exported procedures that operate on vm_map_t.
437 /* Initialize the module */
438 extern void vm_map_init(void) __attribute__((section("__TEXT, initcode")));
440 /* Allocate a range in the specified virtual address map and
441 * return the entry allocated for that range. */
442 extern kern_return_t
vm_map_find_space(
444 vm_map_address_t
*address
, /* OUT */
446 vm_map_offset_t mask
,
448 vm_map_entry_t
*o_entry
); /* OUT */
450 /* Lookup map entry containing or the specified address in the given map */
451 extern boolean_t
vm_map_lookup_entry(
453 vm_map_address_t address
,
454 vm_map_entry_t
*entry
); /* OUT */
456 /* Find the VM object, offset, and protection for a given virtual address
457 * in the specified map, assuming a page fault of the type specified. */
458 extern kern_return_t
vm_map_lookup_locked(
459 vm_map_t
*var_map
, /* IN/OUT */
460 vm_map_address_t vaddr
,
461 vm_prot_t fault_type
,
462 int object_lock_type
,
463 vm_map_version_t
*out_version
, /* OUT */
464 vm_object_t
*object
, /* OUT */
465 vm_object_offset_t
*offset
, /* OUT */
466 vm_prot_t
*out_prot
, /* OUT */
467 boolean_t
*wired
, /* OUT */
468 vm_object_fault_info_t fault_info
, /* OUT */
469 vm_map_t
*real_map
); /* OUT */
471 /* Verifies that the map has not changed since the given version. */
472 extern boolean_t
vm_map_verify(
474 vm_map_version_t
*version
); /* REF */
476 extern vm_map_entry_t
vm_map_entry_insert(
478 vm_map_entry_t insp_entry
,
479 vm_map_offset_t start
,
482 vm_object_offset_t offset
,
483 boolean_t needs_copy
,
485 boolean_t in_transition
,
486 vm_prot_t cur_protection
,
487 vm_prot_t max_protection
,
488 vm_behavior_t behavior
,
489 vm_inherit_t inheritance
,
490 unsigned wired_count
,
493 unsigned int superpage_size
);
497 * Functions implemented as macros
499 #define vm_map_min(map) ((map)->min_offset)
500 /* Lowest valid address in
503 #define vm_map_max(map) ((map)->max_offset)
504 /* Highest valid address */
506 #define vm_map_pmap(map) ((map)->pmap)
507 /* Physical map associated
508 * with this address map */
510 #define vm_map_verify_done(map, version) vm_map_unlock_read(map)
511 /* Operation that required
512 * a verified lookup is
516 * Macros/functions for map residence counts and swapin/out of vm maps
521 /* Gain a reference to an existing map */
522 extern void vm_map_reference(
524 /* Lose a residence count */
525 extern void vm_map_res_deallocate(
527 /* Gain a residence count on a map */
528 extern void vm_map_res_reference(
530 /* Gain reference & residence counts to possibly swapped-out map */
531 extern void vm_map_reference_swap(
534 #else /* MACH_ASSERT */
536 #define vm_map_reference(map) \
538 vm_map_t Map = (map); \
540 lck_mtx_lock(&Map->s_lock); \
543 lck_mtx_unlock(&Map->s_lock); \
547 #define vm_map_res_reference(map) \
549 vm_map_t Lmap = (map); \
550 if (Lmap->res_count == 0) { \
551 lck_mtx_unlock(&Lmap->s_lock);\
553 vm_map_swapin(Lmap); \
554 lck_mtx_lock(&Lmap->s_lock); \
556 vm_map_unlock(Lmap); \
561 #define vm_map_res_deallocate(map) \
563 vm_map_t Map = (map); \
564 if (--Map->res_count == 0) { \
565 lck_mtx_unlock(&Map->s_lock); \
567 vm_map_swapout(Map); \
568 vm_map_unlock(Map); \
569 lck_mtx_lock(&Map->s_lock); \
573 #define vm_map_reference_swap(map) \
575 vm_map_t Map = (map); \
576 lck_mtx_lock(&Map->s_lock); \
578 vm_map_res_reference(Map); \
579 lck_mtx_unlock(&Map->s_lock); \
581 #endif /* MACH_ASSERT */
583 extern void vm_map_swapin(
586 extern void vm_map_swapout(
589 #else /* TASK_SWAPPER */
591 #define vm_map_reference(map) \
593 vm_map_t Map = (map); \
595 lck_mtx_lock(&Map->s_lock); \
597 lck_mtx_unlock(&Map->s_lock); \
601 #define vm_map_reference_swap(map) vm_map_reference(map)
602 #define vm_map_res_reference(map)
603 #define vm_map_res_deallocate(map)
605 #endif /* TASK_SWAPPER */
608 * Submap object. Must be used to create memory to be put
609 * in a submap by vm_map_submap.
611 extern vm_object_t vm_submap_object
;
614 * Wait and wakeup macros for in_transition map entries.
616 #define vm_map_entry_wait(map, interruptible) \
617 ((map)->timestamp++ , \
618 thread_sleep_lock_write((event_t)&(map)->hdr, \
619 &(map)->lock, interruptible))
622 #define vm_map_entry_wakeup(map) \
623 thread_wakeup((event_t)(&(map)->hdr))
626 #define vm_map_ref_fast(map) \
628 lck_mtx_lock(&map->s_lock); \
630 vm_map_res_reference(map); \
631 lck_mtx_unlock(&map->s_lock); \
634 #define vm_map_dealloc_fast(map) \
638 lck_mtx_lock(&map->s_lock); \
639 c = --map->ref_count; \
641 vm_map_res_deallocate(map); \
642 lck_mtx_unlock(&map->s_lock); \
644 vm_map_destroy(map); \
648 /* simplify map entries */
649 extern void vm_map_simplify_entry(
651 vm_map_entry_t this_entry
);
652 extern void vm_map_simplify(
654 vm_map_offset_t start
);
656 /* Move the information in a map copy object to a new map copy object */
657 extern vm_map_copy_t
vm_map_copy_copy(
660 /* Create a copy object from an object. */
661 extern kern_return_t
vm_map_copyin_object(
663 vm_object_offset_t offset
,
664 vm_object_size_t size
,
665 vm_map_copy_t
*copy_result
); /* OUT */
667 /* Enter a mapping */
668 extern kern_return_t
vm_map_enter(
670 vm_map_offset_t
*address
,
672 vm_map_offset_t mask
,
675 vm_object_offset_t offset
,
676 boolean_t needs_copy
,
677 vm_prot_t cur_protection
,
678 vm_prot_t max_protection
,
679 vm_inherit_t inheritance
);
681 /* XXX should go away - replaced with regular enter of contig object */
682 extern kern_return_t
vm_map_enter_cpm(
684 vm_map_address_t
*addr
,
688 extern kern_return_t
vm_map_remap(
690 vm_map_offset_t
*address
,
692 vm_map_offset_t mask
,
695 vm_map_offset_t memory_address
,
697 vm_prot_t
*cur_protection
,
698 vm_prot_t
*max_protection
,
699 vm_inherit_t inheritance
);
703 * Read and write from a kernel buffer to a specified map.
705 extern kern_return_t
vm_map_write_user(
708 vm_map_offset_t dst_addr
,
711 extern kern_return_t
vm_map_read_user(
713 vm_map_offset_t src_addr
,
717 /* Create a new task map using an existing task map as a template. */
718 extern vm_map_t
vm_map_fork(
721 /* Change inheritance */
722 extern kern_return_t
vm_map_inherit(
724 vm_map_offset_t start
,
726 vm_inherit_t new_inheritance
);
728 /* Add or remove machine-dependent attributes from map regions */
729 extern kern_return_t
vm_map_machine_attribute(
731 vm_map_offset_t start
,
733 vm_machine_attribute_t attribute
,
734 vm_machine_attribute_val_t
* value
); /* IN/OUT */
736 extern kern_return_t
vm_map_msync(
738 vm_map_address_t address
,
740 vm_sync_t sync_flags
);
742 /* Set paging behavior */
743 extern kern_return_t
vm_map_behavior_set(
745 vm_map_offset_t start
,
747 vm_behavior_t new_behavior
);
749 extern kern_return_t
vm_map_purgable_control(
751 vm_map_offset_t address
,
752 vm_purgable_t control
,
755 extern kern_return_t
vm_map_region(
757 vm_map_offset_t
*address
,
759 vm_region_flavor_t flavor
,
760 vm_region_info_t info
,
761 mach_msg_type_number_t
*count
,
762 mach_port_t
*object_name
);
764 extern kern_return_t
vm_map_region_recurse_64(
766 vm_map_offset_t
*address
,
768 natural_t
*nesting_depth
,
769 vm_region_submap_info_64_t info
,
770 mach_msg_type_number_t
*count
);
772 extern kern_return_t
vm_map_page_query_internal(
774 vm_map_offset_t offset
,
779 extern kern_return_t
vm_map_submap(
781 vm_map_offset_t start
,
784 vm_map_offset_t offset
,
787 extern void vm_map_submap_pmap_clean(
789 vm_map_offset_t start
,
792 vm_map_offset_t offset
);
794 /* Convert from a map entry port to a map */
795 extern vm_map_t
convert_port_entry_to_map(
798 /* Convert from a port to a vm_object */
799 extern vm_object_t
convert_port_entry_to_object(
803 /* definitions related to overriding the NX behavior */
805 #define VM_ABI_32 0x1
806 #define VM_ABI_64 0x2
808 extern int override_nx(vm_map_t map
, uint32_t user_tag
);
810 #endif /* MACH_KERNEL_PRIVATE */
814 /* Create an empty map */
815 extern vm_map_t
vm_map_create(
817 vm_map_offset_t min_off
,
818 vm_map_offset_t max_off
,
821 /* Get rid of a map */
822 extern void vm_map_destroy(
826 /* Lose a reference */
827 extern void vm_map_deallocate(
830 extern vm_map_t
vm_map_switch(
833 /* Change protection */
834 extern kern_return_t
vm_map_protect(
836 vm_map_offset_t start
,
841 /* Check protection */
842 extern boolean_t
vm_map_check_protection(
844 vm_map_offset_t start
,
846 vm_prot_t protection
);
848 /* wire down a region */
849 extern kern_return_t
vm_map_wire(
851 vm_map_offset_t start
,
853 vm_prot_t access_type
,
854 boolean_t user_wire
);
856 /* unwire a region */
857 extern kern_return_t
vm_map_unwire(
859 vm_map_offset_t start
,
861 boolean_t user_wire
);
863 /* Enter a mapping of a memory object */
864 extern kern_return_t
vm_map_enter_mem_object(
866 vm_map_offset_t
*address
,
868 vm_map_offset_t mask
,
871 vm_object_offset_t offset
,
872 boolean_t needs_copy
,
873 vm_prot_t cur_protection
,
874 vm_prot_t max_protection
,
875 vm_inherit_t inheritance
);
877 /* Enter a mapping of a memory object */
878 extern kern_return_t
vm_map_enter_mem_object_control(
880 vm_map_offset_t
*address
,
882 vm_map_offset_t mask
,
884 memory_object_control_t control
,
885 vm_object_offset_t offset
,
886 boolean_t needs_copy
,
887 vm_prot_t cur_protection
,
888 vm_prot_t max_protection
,
889 vm_inherit_t inheritance
);
891 /* Deallocate a region */
892 extern kern_return_t
vm_map_remove(
894 vm_map_offset_t start
,
898 /* Discard a copy without using it */
899 extern void vm_map_copy_discard(
902 /* Overwrite existing memory with a copy */
903 extern kern_return_t
vm_map_copy_overwrite(
905 vm_map_address_t dst_addr
,
907 boolean_t interruptible
);
909 /* Place a copy into a map */
910 extern kern_return_t
vm_map_copyout(
912 vm_map_address_t
*dst_addr
, /* OUT */
915 extern kern_return_t
vm_map_copyin(
917 vm_map_address_t src_addr
,
919 boolean_t src_destroy
,
920 vm_map_copy_t
*copy_result
); /* OUT */
922 extern kern_return_t
vm_map_copyin_common(
924 vm_map_address_t src_addr
,
926 boolean_t src_destroy
,
927 boolean_t src_volatile
,
928 vm_map_copy_t
*copy_result
, /* OUT */
929 boolean_t use_maxprot
);
931 extern void vm_map_disable_NX(
934 extern void vm_map_set_64bit(
937 extern void vm_map_set_32bit(
940 extern boolean_t
vm_map_is_64bit(
943 extern boolean_t
vm_map_has_4GB_pagezero(
946 extern void vm_map_set_4GB_pagezero(
949 extern void vm_map_clear_4GB_pagezero(
952 extern kern_return_t
vm_map_raise_min_offset(
954 vm_map_offset_t new_min_offset
);
956 extern vm_map_offset_t
vm_compute_max_offset(
959 extern void vm_map_set_user_wire_limit(
963 extern void vm_map_switch_protect(
967 #ifdef XNU_KERNEL_PRIVATE
968 extern kern_return_t
vm_map_page_info(
970 vm_map_offset_t offset
,
971 vm_page_info_flavor_t flavor
,
973 mach_msg_type_number_t
*count
);
974 #endif /* XNU_KERNEL_PRIVATE */
977 #ifdef MACH_KERNEL_PRIVATE
980 * Macros to invoke vm_map_copyin_common. vm_map_copyin is the
981 * usual form; it handles a copyin based on the current protection
982 * (current protection == VM_PROT_NONE) is a failure.
983 * vm_map_copyin_maxprot handles a copyin based on maximum possible
984 * access. The difference is that a region with no current access
985 * BUT possible maximum access is rejected by vm_map_copyin(), but
986 * returned by vm_map_copyin_maxprot.
988 #define vm_map_copyin(src_map, src_addr, len, src_destroy, copy_result) \
989 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
990 FALSE, copy_result, FALSE)
992 #define vm_map_copyin_maxprot(src_map, \
993 src_addr, len, src_destroy, copy_result) \
994 vm_map_copyin_common(src_map, src_addr, len, src_destroy, \
995 FALSE, copy_result, TRUE)
997 #endif /* MACH_KERNEL_PRIVATE */
1000 * Macros for rounding and truncation of vm_map offsets and sizes
1002 #define vm_map_round_page(x) (((vm_map_offset_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
1003 #define vm_map_trunc_page(x) ((vm_map_offset_t)(x) & ~((signed)PAGE_MASK))
1006 * Flags for vm_map_remove() and vm_map_delete()
1008 #define VM_MAP_NO_FLAGS 0x0
1009 #define VM_MAP_REMOVE_KUNWIRE 0x1
1010 #define VM_MAP_REMOVE_INTERRUPTIBLE 0x2
1011 #define VM_MAP_REMOVE_WAIT_FOR_KWIRE 0x4
1012 #define VM_MAP_REMOVE_SAVE_ENTRIES 0x8
1013 #define VM_MAP_REMOVE_NO_PMAP_CLEANUP 0x10
1015 /* Support for UPLs from vm_maps */
1017 extern kern_return_t
vm_map_get_upl(
1018 vm_map_t target_map
,
1019 vm_map_offset_t map_offset
,
1022 upl_page_info_array_t page_info
,
1023 unsigned int *page_infoCnt
,
1025 int force_data_sync
);
1027 #if CONFIG_DYNAMIC_CODE_SIGNING
1028 extern kern_return_t
vm_map_sign(vm_map_t map
,
1029 vm_map_offset_t start
,
1030 vm_map_offset_t end
);
1035 #endif /* KERNEL_PRIVATE */
1037 #endif /* _VM_VM_MAP_H_ */