]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_kern.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / vm / vm_kern.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
0a7de745 31/*
1c79356b
A
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
0a7de745 35 *
1c79356b
A
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.
0a7de745 41 *
1c79356b
A
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.
0a7de745 45 *
1c79356b 46 * Carnegie Mellon requests users of this software to return to
0a7de745 47 *
1c79356b
A
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
0a7de745 52 *
1c79356b
A
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56/*
57 */
58/*
59 * File: vm/vm_kern.h
60 * Author: Avadis Tevanian, Jr., Michael Wayne Young
61 * Date: 1985
62 *
63 * Kernel memory management definitions.
64 */
65
0a7de745 66#ifndef _VM_VM_KERN_H_
1c79356b
A
67#define _VM_VM_KERN_H_
68
d9a64523
A
69#ifdef __cplusplus
70extern "C" {
71#endif
72
91447636 73#include <mach/mach_types.h>
1c79356b
A
74#include <mach/boolean.h>
75#include <mach/kern_return.h>
1c79356b 76
0a7de745 77#ifdef KERNEL_PRIVATE
1c79356b 78
3e170ce0
A
79#ifdef XNU_KERNEL_PRIVATE
80
39037602
A
81#include <kern/locks.h>
82
c3c9b80d
A
83struct vm_page;
84
85__options_decl(kma_flags_t, uint32_t, {
86 KMA_NONE = 0x00000000,
87 KMA_HERE = 0x00000001,
88 KMA_NOPAGEWAIT = 0x00000002,
89 KMA_KOBJECT = 0x00000004,
90 KMA_LOMEM = 0x00000008,
91 KMA_GUARD_FIRST = 0x00000010,
92 KMA_GUARD_LAST = 0x00000020,
93 KMA_PERMANENT = 0x00000040,
94 KMA_NOENCRYPT = 0x00000080,
95 KMA_KSTACK = 0x00000100,
96 KMA_VAONLY = 0x00000200,
97 /*
98 * Pages belonging to the compressor are not on the paging queues,
99 * nor are they counted as wired.
100 */
101 KMA_COMPRESSOR = 0x00000400,
102 KMA_ATOMIC = 0x00000800,
103 KMA_ZERO = 0x00001000,
104 KMA_PAGEABLE = 0x00002000,
105 KMA_KHEAP = 0x00004000, /* Pages belonging to zones backing one of kalloc_heap. */
106});
107
0a7de745
A
108extern kern_return_t kernel_memory_allocate(
109 vm_map_t map,
110 vm_offset_t *addrp,
111 vm_size_t size,
112 vm_offset_t mask,
c3c9b80d 113 kma_flags_t flags,
0a7de745 114 vm_tag_t tag);
1c79356b 115
39037602 116extern kern_return_t kmem_alloc(
f427ee49
A
117 vm_map_t map,
118 vm_offset_t *addrp,
119 vm_size_t size,
120 vm_tag_t tag) __XNU_INTERNAL(kmem_alloc);
1c79356b
A
121
122extern kern_return_t kmem_alloc_contig(
0a7de745
A
123 vm_map_t map,
124 vm_offset_t *addrp,
125 vm_size_t size,
126 vm_offset_t mask,
127 ppnum_t max_pnum,
128 ppnum_t pnum_mask,
c3c9b80d 129 kma_flags_t flags,
0a7de745
A
130 vm_tag_t tag);
131
132extern kern_return_t kmem_alloc_flags(
133 vm_map_t map,
134 vm_offset_t *addrp,
135 vm_size_t size,
136 vm_tag_t tag,
c3c9b80d 137 kma_flags_t flags);
0a7de745
A
138
139extern kern_return_t kmem_alloc_pageable(
140 vm_map_t map,
141 vm_offset_t *addrp,
142 vm_size_t size,
cb323159 143 vm_tag_t tag) __XNU_INTERNAL(kmem_alloc_pageable);
0a7de745
A
144
145extern kern_return_t kmem_alloc_aligned(
146 vm_map_t map,
147 vm_offset_t *addrp,
148 vm_size_t size,
149 vm_tag_t tag);
150
151extern kern_return_t kmem_realloc(
152 vm_map_t map,
153 vm_offset_t oldaddr,
154 vm_size_t oldsize,
155 vm_offset_t *newaddrp,
156 vm_size_t newsize,
157 vm_tag_t tag);
158
159extern void kmem_free(
160 vm_map_t map,
161 vm_offset_t addr,
162 vm_size_t size);
163
164extern kern_return_t kmem_suballoc(
165 vm_map_t parent,
166 vm_offset_t *addr,
167 vm_size_t size,
168 boolean_t pageable,
169 int flags,
170 vm_map_kernel_flags_t vmk_flags,
f427ee49 171 vm_tag_t tag,
0a7de745
A
172 vm_map_t *new_map);
173
174extern kern_return_t kmem_alloc_kobject(
175 vm_map_t map,
176 vm_offset_t *addrp,
177 vm_size_t size,
cb323159 178 vm_tag_t tag) __XNU_INTERNAL(kmem_alloc_kobject);
2d21ac55 179
c3c9b80d
A
180extern void kernel_memory_populate_with_pages(
181 vm_map_t map,
182 vm_offset_t addr,
183 vm_size_t size,
184 struct vm_page *page_list,
185 kma_flags_t flags,
186 vm_tag_t tag);
187
39236c6e 188extern kern_return_t kernel_memory_populate(
0a7de745
A
189 vm_map_t map,
190 vm_offset_t addr,
191 vm_size_t size,
c3c9b80d 192 kma_flags_t flags,
3e170ce0
A
193 vm_tag_t tag);
194
39236c6e 195extern void kernel_memory_depopulate(
0a7de745
A
196 vm_map_t map,
197 vm_offset_t addr,
198 vm_size_t size,
c3c9b80d 199 kma_flags_t flags,
f427ee49 200 vm_tag_t tag);
0a7de745
A
201
202extern kern_return_t memory_object_iopl_request(
203 ipc_port_t port,
204 memory_object_offset_t offset,
205 upl_size_t *upl_size,
206 upl_t *upl_ptr,
207 upl_page_info_array_t user_page_list,
208 unsigned int *page_list_count,
209 upl_control_flags_t *flags,
210 vm_tag_t tag);
3e170ce0
A
211
212struct mach_memory_info;
f427ee49
A
213extern kern_return_t vm_page_diagnose(
214 struct mach_memory_info *info,
215 unsigned int num_info,
216 uint64_t zones_collectable_bytes);
5ba3f43e
A
217
218extern uint32_t vm_page_diagnose_estimate(void);
39037602
A
219
220#if DEBUG || DEVELOPMENT
5ba3f43e
A
221
222extern kern_return_t mach_memory_info_check(void);
223
224extern kern_return_t vm_kern_allocation_info(uintptr_t addr, vm_size_t * size, vm_tag_t * tag, vm_size_t * zone_size);
225
39037602 226#endif /* DEBUG || DEVELOPMENT */
3e170ce0 227
f427ee49
A
228#if HIBERNATION
229extern void hibernate_rebuild_vm_structs(void);
230#endif /* HIBERNATION */
231
0a7de745 232extern vm_tag_t vm_tag_bt(void);
3e170ce0 233
0a7de745 234extern vm_tag_t vm_tag_alloc(vm_allocation_site_t * site);
3e170ce0 235
0a7de745 236extern void vm_tag_alloc_locked(vm_allocation_site_t * site, vm_allocation_site_t ** releasesiteP);
3e170ce0 237
0a7de745 238extern void vm_tag_update_size(vm_tag_t tag, int64_t size);
3e170ce0 239
5ba3f43e 240#if VM_MAX_TAG_ZONES
f427ee49 241
0a7de745 242extern void vm_allocation_zones_init(void);
c3c9b80d
A
243extern vm_tag_t vm_tag_will_update_zone(vm_tag_t tag, uint32_t zidx, uint32_t zflags);
244extern void vm_tag_update_zone_size(vm_tag_t tag, uint32_t zidx, long delta);
39037602 245
5ba3f43e 246#endif /* VM_MAX_TAG_ZONES */
39037602 247
0a7de745 248extern vm_tag_t vm_tag_bt_debug(void);
39037602 249
5ba3f43e 250extern uint32_t vm_tag_get_kext(vm_tag_t tag, char * name, vm_size_t namelen);
39037602 251
0a7de745 252extern boolean_t vm_kernel_map_is_kernel(vm_map_t map);
3e170ce0 253
0a7de745 254extern ppnum_t kernel_pmap_present_mapping(uint64_t vaddr, uint64_t * pvincr, uintptr_t * pvphysaddr);
3e170ce0
A
255
256#else /* XNU_KERNEL_PRIVATE */
257
0a7de745
A
258extern kern_return_t kmem_alloc(
259 vm_map_t map,
260 vm_offset_t *addrp,
261 vm_size_t size);
3e170ce0 262
0a7de745
A
263extern kern_return_t kmem_alloc_pageable(
264 vm_map_t map,
265 vm_offset_t *addrp,
266 vm_size_t size);
3e170ce0 267
0a7de745
A
268extern kern_return_t kmem_alloc_kobject(
269 vm_map_t map,
270 vm_offset_t *addrp,
271 vm_size_t size);
3e170ce0 272
0a7de745
A
273extern void kmem_free(
274 vm_map_t map,
275 vm_offset_t addr,
276 vm_size_t size);
3e170ce0
A
277
278#endif /* !XNU_KERNEL_PRIVATE */
279
280
5ba3f43e
A
281#ifdef XNU_KERNEL_PRIVATE
282typedef struct vm_allocation_site kern_allocation_name;
283typedef kern_allocation_name * kern_allocation_name_t;
284#else /* XNU_KERNEL_PRIVATE */
285struct kern_allocation_name;
286typedef struct kern_allocation_name * kern_allocation_name_t;
287#endif /* !XNU_KERNEL_PRIVATE */
288
f427ee49 289extern kern_allocation_name_t kern_allocation_name_allocate(const char * name, uint16_t suballocs);
0a7de745 290extern void kern_allocation_name_release(kern_allocation_name_t allocation);
5ba3f43e
A
291extern const char * kern_allocation_get_name(kern_allocation_name_t allocation);
292#ifdef XNU_KERNEL_PRIVATE
0a7de745
A
293extern void kern_allocation_update_size(kern_allocation_name_t allocation, int64_t delta);
294extern void kern_allocation_update_subtotal(kern_allocation_name_t allocation, uint32_t subtag, int64_t delta);
295extern vm_tag_t kern_allocation_name_get_vm_tag(kern_allocation_name_t allocation);
5ba3f43e
A
296#endif /* XNU_KERNEL_PRIVATE */
297
0a7de745 298#ifdef MACH_KERNEL_PRIVATE
2d21ac55 299
0a7de745
A
300extern void kmem_init(
301 vm_offset_t start,
302 vm_offset_t end);
2d21ac55 303
0a7de745
A
304extern kern_return_t copyinmap(
305 vm_map_t map,
306 vm_map_offset_t fromaddr,
307 void *todata,
308 vm_size_t length);
1c79356b 309
0a7de745
A
310extern kern_return_t copyoutmap(
311 vm_map_t map,
312 void *fromdata,
313 vm_map_offset_t toaddr,
314 vm_size_t length);
1c79356b 315
c3c9b80d
A
316extern kern_return_t copyoutmap_atomic32(
317 vm_map_t map,
318 uint32_t value,
319 vm_map_offset_t toaddr);
320
321extern kern_return_t copyoutmap_atomic64(
322 vm_map_t map,
323 uint64_t value,
324 vm_map_offset_t toaddr);
325
0a7de745
A
326extern kern_return_t kmem_alloc_external(
327 vm_map_t map,
328 vm_offset_t *addrp,
329 vm_size_t size);
3e170ce0 330
0a7de745
A
331extern kern_return_t kmem_alloc_kobject_external(
332 vm_map_t map,
333 vm_offset_t *addrp,
334 vm_size_t size);
3e170ce0 335
0a7de745
A
336extern kern_return_t kmem_alloc_pageable_external(
337 vm_map_t map,
338 vm_offset_t *addrp,
339 vm_size_t size);
3e170ce0 340
0a7de745 341#endif /* MACH_KERNEL_PRIVATE */
91447636 342
5ba3f43e
A
343#ifdef XNU_KERNEL_PRIVATE
344
345extern kern_return_t mach_vm_allocate_kernel(
0a7de745
A
346 vm_map_t map,
347 mach_vm_offset_t *addr,
f427ee49 348 mach_vm_size_t size,
0a7de745 349 int flags,
f427ee49 350 vm_tag_t tag);
5ba3f43e
A
351
352extern kern_return_t vm_allocate_kernel(
f427ee49
A
353 vm_map_t map,
354 vm_offset_t *addr,
355 vm_size_t size,
356 int flags,
357 vm_tag_t tag);
5ba3f43e
A
358
359
360extern kern_return_t mach_vm_map_kernel(
0a7de745
A
361 vm_map_t target_map,
362 mach_vm_offset_t *address,
f427ee49 363 mach_vm_size_t initial_size,
0a7de745
A
364 mach_vm_offset_t mask,
365 int flags,
366 vm_map_kernel_flags_t vmk_flags,
367 vm_tag_t tag,
368 ipc_port_t port,
369 vm_object_offset_t offset,
370 boolean_t copy,
371 vm_prot_t cur_protection,
372 vm_prot_t max_protection,
373 vm_inherit_t inheritance);
5ba3f43e
A
374
375
376extern kern_return_t vm_map_kernel(
0a7de745
A
377 vm_map_t target_map,
378 vm_offset_t *address,
379 vm_size_t size,
380 vm_offset_t mask,
381 int flags,
382 vm_map_kernel_flags_t vmk_flags,
383 vm_tag_t tag,
384 ipc_port_t port,
385 vm_offset_t offset,
386 boolean_t copy,
387 vm_prot_t cur_protection,
388 vm_prot_t max_protection,
389 vm_inherit_t inheritance);
5ba3f43e
A
390
391extern kern_return_t mach_vm_remap_kernel(
0a7de745
A
392 vm_map_t target_map,
393 mach_vm_offset_t *address,
f427ee49 394 mach_vm_size_t size,
0a7de745
A
395 mach_vm_offset_t mask,
396 int flags,
f427ee49 397 vm_tag_t tag,
0a7de745
A
398 vm_map_t src_map,
399 mach_vm_offset_t memory_address,
400 boolean_t copy,
401 vm_prot_t *cur_protection,
402 vm_prot_t *max_protection,
403 vm_inherit_t inheritance);
5ba3f43e
A
404
405extern kern_return_t vm_remap_kernel(
0a7de745
A
406 vm_map_t target_map,
407 vm_offset_t *address,
408 vm_size_t size,
409 vm_offset_t mask,
410 int flags,
f427ee49 411 vm_tag_t tag,
0a7de745
A
412 vm_map_t src_map,
413 vm_offset_t memory_address,
414 boolean_t copy,
415 vm_prot_t *cur_protection,
416 vm_prot_t *max_protection,
417 vm_inherit_t inheritance);
5ba3f43e
A
418
419extern kern_return_t vm_map_64_kernel(
0a7de745
A
420 vm_map_t target_map,
421 vm_offset_t *address,
422 vm_size_t size,
423 vm_offset_t mask,
424 int flags,
425 vm_map_kernel_flags_t vmk_flags,
426 vm_tag_t tag,
427 ipc_port_t port,
428 vm_object_offset_t offset,
429 boolean_t copy,
430 vm_prot_t cur_protection,
431 vm_prot_t max_protection,
432 vm_inherit_t inheritance);
5ba3f43e
A
433
434extern kern_return_t mach_vm_wire_kernel(
0a7de745
A
435 host_priv_t host_priv,
436 vm_map_t map,
437 mach_vm_offset_t start,
f427ee49 438 mach_vm_size_t size,
0a7de745
A
439 vm_prot_t access,
440 vm_tag_t tag);
5ba3f43e
A
441
442extern kern_return_t vm_map_wire_kernel(
0a7de745
A
443 vm_map_t map,
444 vm_map_offset_t start,
445 vm_map_offset_t end,
446 vm_prot_t caller_prot,
447 vm_tag_t tag,
448 boolean_t user_wire);
5ba3f43e
A
449
450extern kern_return_t vm_map_wire_and_extract_kernel(
0a7de745
A
451 vm_map_t map,
452 vm_map_offset_t start,
453 vm_prot_t caller_prot,
454 vm_tag_t tag,
455 boolean_t user_wire,
456 ppnum_t *physpage_p);
5ba3f43e 457
0a7de745 458#endif /* XNU_KERNEL_PRIVATE */
5ba3f43e 459
0a7de745
A
460extern vm_map_t kernel_map;
461extern vm_map_t kernel_pageable_map;
1c79356b 462extern vm_map_t ipc_kernel_map;
f427ee49 463extern vm_map_t g_kext_map;
1c79356b 464
0a7de745 465#endif /* KERNEL_PRIVATE */
91447636 466
3e170ce0
A
467#ifdef KERNEL
468
5ba3f43e 469__BEGIN_DECLS
cb323159
A
470#if MACH_KERNEL_PRIVATE
471extern vm_offset_t vm_kernel_addrhash(vm_offset_t addr)
472__XNU_INTERNAL(vm_kernel_addrhash);
473#else
5ba3f43e 474extern vm_offset_t vm_kernel_addrhash(vm_offset_t addr);
cb323159 475#endif
5ba3f43e
A
476__END_DECLS
477
478extern void vm_kernel_addrhide(
479 vm_offset_t addr,
480 vm_offset_t *hide_addr);
481
3e170ce0
A
482extern vm_offset_t vm_kernel_addrperm_ext;
483
0a7de745
A
484extern void vm_kernel_addrperm_external(
485 vm_offset_t addr,
486 vm_offset_t *perm_addr);
3e170ce0 487
0a7de745
A
488extern void vm_kernel_unslide_or_perm_external(
489 vm_offset_t addr,
490 vm_offset_t *up_addr);
5ba3f43e
A
491
492#if MACH_KERNEL_PRIVATE
493extern uint64_t vm_kernel_addrhash_salt;
494extern uint64_t vm_kernel_addrhash_salt_ext;
495
496extern void vm_kernel_addrhash_external(
0a7de745
A
497 vm_offset_t addr,
498 vm_offset_t *perm_addr);
5ba3f43e
A
499#endif /* MACH_KERNEL_PRIVATE */
500
501extern void vm_init_before_launchd(void);
502
3e170ce0 503#endif /* KERNEL */
d9a64523
A
504
505#ifdef __cplusplus
506}
507#endif
508
0a7de745 509#endif /* _VM_VM_KERN_H_ */