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