]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/vm_kern.h
xnu-6153.101.6.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
0a7de745
A
83extern kern_return_t kernel_memory_allocate(
84 vm_map_t map,
85 vm_offset_t *addrp,
86 vm_size_t size,
87 vm_offset_t mask,
88 int flags,
89 vm_tag_t tag);
1c79356b
A
90
91/* flags for kernel_memory_allocate */
0a7de745
A
92#define KMA_HERE 0x01
93#define KMA_NOPAGEWAIT 0x02
94#define KMA_KOBJECT 0x04
95#define KMA_LOMEM 0x08
96#define KMA_GUARD_FIRST 0x10
97#define KMA_GUARD_LAST 0x20
98#define KMA_PERMANENT 0x40
99#define KMA_NOENCRYPT 0x80
100#define KMA_KSTACK 0x100
101#define KMA_VAONLY 0x200
102#define KMA_COMPRESSOR 0x400 /* Pages belonging to the compressor are not on the paging queues, nor are they counted as wired. */
103#define KMA_ATOMIC 0x800
104#define KMA_ZERO 0x1000
105#define KMA_PAGEABLE 0x2000
39037602
A
106
107extern kern_return_t kmem_alloc(
0a7de745
A
108 vm_map_t map,
109 vm_offset_t *addrp,
110 vm_size_t size,
cb323159 111 vm_tag_t tag) __XNU_INTERNAL(kmem_alloc);
1c79356b
A
112
113extern kern_return_t kmem_alloc_contig(
0a7de745
A
114 vm_map_t map,
115 vm_offset_t *addrp,
116 vm_size_t size,
117 vm_offset_t mask,
118 ppnum_t max_pnum,
119 ppnum_t pnum_mask,
120 int flags,
121 vm_tag_t tag);
122
123extern kern_return_t kmem_alloc_flags(
124 vm_map_t map,
125 vm_offset_t *addrp,
126 vm_size_t size,
127 vm_tag_t tag,
128 int flags);
129
130extern kern_return_t kmem_alloc_pageable(
131 vm_map_t map,
132 vm_offset_t *addrp,
133 vm_size_t size,
cb323159 134 vm_tag_t tag) __XNU_INTERNAL(kmem_alloc_pageable);
0a7de745
A
135
136extern kern_return_t kmem_alloc_aligned(
137 vm_map_t map,
138 vm_offset_t *addrp,
139 vm_size_t size,
140 vm_tag_t tag);
141
142extern kern_return_t kmem_realloc(
143 vm_map_t map,
144 vm_offset_t oldaddr,
145 vm_size_t oldsize,
146 vm_offset_t *newaddrp,
147 vm_size_t newsize,
148 vm_tag_t tag);
149
150extern void kmem_free(
151 vm_map_t map,
152 vm_offset_t addr,
153 vm_size_t size);
154
155extern kern_return_t kmem_suballoc(
156 vm_map_t parent,
157 vm_offset_t *addr,
158 vm_size_t size,
159 boolean_t pageable,
160 int flags,
161 vm_map_kernel_flags_t vmk_flags,
162 vm_tag_t tag,
163 vm_map_t *new_map);
164
165extern kern_return_t kmem_alloc_kobject(
166 vm_map_t map,
167 vm_offset_t *addrp,
168 vm_size_t size,
cb323159 169 vm_tag_t tag) __XNU_INTERNAL(kmem_alloc_kobject);
2d21ac55 170
39236c6e 171extern kern_return_t kernel_memory_populate(
0a7de745
A
172 vm_map_t map,
173 vm_offset_t addr,
174 vm_size_t size,
175 int flags,
3e170ce0
A
176 vm_tag_t tag);
177
39236c6e 178extern void kernel_memory_depopulate(
0a7de745
A
179 vm_map_t map,
180 vm_offset_t addr,
181 vm_size_t size,
182 int flags);
183
184extern kern_return_t memory_object_iopl_request(
185 ipc_port_t port,
186 memory_object_offset_t offset,
187 upl_size_t *upl_size,
188 upl_t *upl_ptr,
189 upl_page_info_array_t user_page_list,
190 unsigned int *page_list_count,
191 upl_control_flags_t *flags,
192 vm_tag_t tag);
3e170ce0
A
193
194struct mach_memory_info;
0a7de745
A
195extern kern_return_t vm_page_diagnose(struct mach_memory_info * info,
196 unsigned int num_info, uint64_t zones_collectable_bytes);
5ba3f43e
A
197
198extern uint32_t vm_page_diagnose_estimate(void);
39037602
A
199
200#if DEBUG || DEVELOPMENT
5ba3f43e
A
201
202extern kern_return_t mach_memory_info_check(void);
203
204extern kern_return_t vm_kern_allocation_info(uintptr_t addr, vm_size_t * size, vm_tag_t * tag, vm_size_t * zone_size);
205
39037602 206#endif /* DEBUG || DEVELOPMENT */
3e170ce0 207
0a7de745 208extern vm_tag_t vm_tag_bt(void);
3e170ce0 209
0a7de745 210extern vm_tag_t vm_tag_alloc(vm_allocation_site_t * site);
3e170ce0 211
0a7de745 212extern void vm_tag_alloc_locked(vm_allocation_site_t * site, vm_allocation_site_t ** releasesiteP);
3e170ce0 213
0a7de745 214extern void vm_tag_update_size(vm_tag_t tag, int64_t size);
3e170ce0 215
5ba3f43e 216#if VM_MAX_TAG_ZONES
0a7de745 217extern void vm_allocation_zones_init(void);
5ba3f43e 218extern void vm_tag_will_update_zone(vm_tag_t tag, uint32_t zidx);
0a7de745 219extern void vm_tag_update_zone_size(vm_tag_t tag, uint32_t zidx, int64_t delta, int64_t dwaste);
39037602 220
5ba3f43e 221extern vm_allocation_zone_total_t ** vm_allocation_zone_totals;
39037602 222
5ba3f43e 223#endif /* VM_MAX_TAG_ZONES */
39037602 224
0a7de745 225extern vm_tag_t vm_tag_bt_debug(void);
39037602 226
5ba3f43e 227extern uint32_t vm_tag_get_kext(vm_tag_t tag, char * name, vm_size_t namelen);
39037602 228
0a7de745 229extern boolean_t vm_kernel_map_is_kernel(vm_map_t map);
3e170ce0 230
0a7de745 231extern ppnum_t kernel_pmap_present_mapping(uint64_t vaddr, uint64_t * pvincr, uintptr_t * pvphysaddr);
3e170ce0
A
232
233#else /* XNU_KERNEL_PRIVATE */
234
0a7de745
A
235extern kern_return_t kmem_alloc(
236 vm_map_t map,
237 vm_offset_t *addrp,
238 vm_size_t size);
3e170ce0 239
0a7de745
A
240extern kern_return_t kmem_alloc_pageable(
241 vm_map_t map,
242 vm_offset_t *addrp,
243 vm_size_t size);
3e170ce0 244
0a7de745
A
245extern kern_return_t kmem_alloc_kobject(
246 vm_map_t map,
247 vm_offset_t *addrp,
248 vm_size_t size);
3e170ce0 249
0a7de745
A
250extern void kmem_free(
251 vm_map_t map,
252 vm_offset_t addr,
253 vm_size_t size);
3e170ce0
A
254
255#endif /* !XNU_KERNEL_PRIVATE */
256
257
5ba3f43e
A
258#ifdef XNU_KERNEL_PRIVATE
259typedef struct vm_allocation_site kern_allocation_name;
260typedef kern_allocation_name * kern_allocation_name_t;
261#else /* XNU_KERNEL_PRIVATE */
262struct kern_allocation_name;
263typedef struct kern_allocation_name * kern_allocation_name_t;
264#endif /* !XNU_KERNEL_PRIVATE */
265
0a7de745
A
266extern kern_allocation_name_t kern_allocation_name_allocate(const char * name, uint32_t suballocs);
267extern void kern_allocation_name_release(kern_allocation_name_t allocation);
5ba3f43e
A
268extern const char * kern_allocation_get_name(kern_allocation_name_t allocation);
269#ifdef XNU_KERNEL_PRIVATE
0a7de745
A
270extern void kern_allocation_update_size(kern_allocation_name_t allocation, int64_t delta);
271extern void kern_allocation_update_subtotal(kern_allocation_name_t allocation, uint32_t subtag, int64_t delta);
272extern vm_tag_t kern_allocation_name_get_vm_tag(kern_allocation_name_t allocation);
5ba3f43e
A
273#endif /* XNU_KERNEL_PRIVATE */
274
0a7de745 275#ifdef MACH_KERNEL_PRIVATE
2d21ac55 276
0a7de745
A
277extern void kmem_init(
278 vm_offset_t start,
279 vm_offset_t end);
2d21ac55 280
0a7de745
A
281extern kern_return_t copyinmap(
282 vm_map_t map,
283 vm_map_offset_t fromaddr,
284 void *todata,
285 vm_size_t length);
1c79356b 286
0a7de745
A
287extern kern_return_t copyoutmap(
288 vm_map_t map,
289 void *fromdata,
290 vm_map_offset_t toaddr,
291 vm_size_t length);
1c79356b 292
0a7de745
A
293extern kern_return_t kmem_alloc_external(
294 vm_map_t map,
295 vm_offset_t *addrp,
296 vm_size_t size);
3e170ce0 297
0a7de745
A
298extern kern_return_t kmem_alloc_kobject_external(
299 vm_map_t map,
300 vm_offset_t *addrp,
301 vm_size_t size);
3e170ce0 302
0a7de745
A
303extern kern_return_t kmem_alloc_pageable_external(
304 vm_map_t map,
305 vm_offset_t *addrp,
306 vm_size_t size);
3e170ce0 307
0a7de745 308#endif /* MACH_KERNEL_PRIVATE */
91447636 309
5ba3f43e
A
310#ifdef XNU_KERNEL_PRIVATE
311
312extern kern_return_t mach_vm_allocate_kernel(
0a7de745
A
313 vm_map_t map,
314 mach_vm_offset_t *addr,
315 mach_vm_size_t size,
316 int flags,
5ba3f43e
A
317 vm_tag_t tag);
318
319extern kern_return_t vm_allocate_kernel(
0a7de745
A
320 vm_map_t map,
321 vm_offset_t *addr,
322 vm_size_t size,
5ba3f43e
A
323 int flags,
324 vm_tag_t tag);
325
326
327extern kern_return_t mach_vm_map_kernel(
0a7de745
A
328 vm_map_t target_map,
329 mach_vm_offset_t *address,
330 mach_vm_size_t initial_size,
331 mach_vm_offset_t mask,
332 int flags,
333 vm_map_kernel_flags_t vmk_flags,
334 vm_tag_t tag,
335 ipc_port_t port,
336 vm_object_offset_t offset,
337 boolean_t copy,
338 vm_prot_t cur_protection,
339 vm_prot_t max_protection,
340 vm_inherit_t inheritance);
5ba3f43e
A
341
342
343extern kern_return_t vm_map_kernel(
0a7de745
A
344 vm_map_t target_map,
345 vm_offset_t *address,
346 vm_size_t size,
347 vm_offset_t mask,
348 int flags,
349 vm_map_kernel_flags_t vmk_flags,
350 vm_tag_t tag,
351 ipc_port_t port,
352 vm_offset_t offset,
353 boolean_t copy,
354 vm_prot_t cur_protection,
355 vm_prot_t max_protection,
356 vm_inherit_t inheritance);
5ba3f43e
A
357
358extern kern_return_t mach_vm_remap_kernel(
0a7de745
A
359 vm_map_t target_map,
360 mach_vm_offset_t *address,
361 mach_vm_size_t size,
362 mach_vm_offset_t mask,
363 int flags,
5ba3f43e 364 vm_tag_t tag,
0a7de745
A
365 vm_map_t src_map,
366 mach_vm_offset_t memory_address,
367 boolean_t copy,
368 vm_prot_t *cur_protection,
369 vm_prot_t *max_protection,
370 vm_inherit_t inheritance);
5ba3f43e
A
371
372extern kern_return_t vm_remap_kernel(
0a7de745
A
373 vm_map_t target_map,
374 vm_offset_t *address,
375 vm_size_t size,
376 vm_offset_t mask,
377 int flags,
5ba3f43e 378 vm_tag_t tag,
0a7de745
A
379 vm_map_t src_map,
380 vm_offset_t memory_address,
381 boolean_t copy,
382 vm_prot_t *cur_protection,
383 vm_prot_t *max_protection,
384 vm_inherit_t inheritance);
5ba3f43e
A
385
386extern kern_return_t vm_map_64_kernel(
0a7de745
A
387 vm_map_t target_map,
388 vm_offset_t *address,
389 vm_size_t size,
390 vm_offset_t mask,
391 int flags,
392 vm_map_kernel_flags_t vmk_flags,
393 vm_tag_t tag,
394 ipc_port_t port,
395 vm_object_offset_t offset,
396 boolean_t copy,
397 vm_prot_t cur_protection,
398 vm_prot_t max_protection,
399 vm_inherit_t inheritance);
5ba3f43e
A
400
401extern kern_return_t mach_vm_wire_kernel(
0a7de745
A
402 host_priv_t host_priv,
403 vm_map_t map,
404 mach_vm_offset_t start,
405 mach_vm_size_t size,
406 vm_prot_t access,
407 vm_tag_t tag);
5ba3f43e
A
408
409extern kern_return_t vm_map_wire_kernel(
0a7de745
A
410 vm_map_t map,
411 vm_map_offset_t start,
412 vm_map_offset_t end,
413 vm_prot_t caller_prot,
414 vm_tag_t tag,
415 boolean_t user_wire);
5ba3f43e
A
416
417extern kern_return_t vm_map_wire_and_extract_kernel(
0a7de745
A
418 vm_map_t map,
419 vm_map_offset_t start,
420 vm_prot_t caller_prot,
421 vm_tag_t tag,
422 boolean_t user_wire,
423 ppnum_t *physpage_p);
5ba3f43e 424
0a7de745 425#endif /* XNU_KERNEL_PRIVATE */
5ba3f43e 426
0a7de745
A
427extern vm_map_t kernel_map;
428extern vm_map_t kernel_pageable_map;
1c79356b
A
429extern vm_map_t ipc_kernel_map;
430
0a7de745 431#endif /* KERNEL_PRIVATE */
91447636 432
3e170ce0
A
433#ifdef KERNEL
434
5ba3f43e 435__BEGIN_DECLS
cb323159
A
436#if MACH_KERNEL_PRIVATE
437extern vm_offset_t vm_kernel_addrhash(vm_offset_t addr)
438__XNU_INTERNAL(vm_kernel_addrhash);
439#else
5ba3f43e 440extern vm_offset_t vm_kernel_addrhash(vm_offset_t addr);
cb323159 441#endif
5ba3f43e
A
442__END_DECLS
443
444extern void vm_kernel_addrhide(
445 vm_offset_t addr,
446 vm_offset_t *hide_addr);
447
3e170ce0
A
448extern vm_offset_t vm_kernel_addrperm_ext;
449
0a7de745
A
450extern void vm_kernel_addrperm_external(
451 vm_offset_t addr,
452 vm_offset_t *perm_addr);
3e170ce0 453
0a7de745
A
454extern void vm_kernel_unslide_or_perm_external(
455 vm_offset_t addr,
456 vm_offset_t *up_addr);
5ba3f43e
A
457
458#if MACH_KERNEL_PRIVATE
459extern uint64_t vm_kernel_addrhash_salt;
460extern uint64_t vm_kernel_addrhash_salt_ext;
461
462extern void vm_kernel_addrhash_external(
0a7de745
A
463 vm_offset_t addr,
464 vm_offset_t *perm_addr);
5ba3f43e
A
465#endif /* MACH_KERNEL_PRIVATE */
466
467extern void vm_init_before_launchd(void);
468
3e170ce0 469#endif /* KERNEL */
d9a64523
A
470
471#ifdef __cplusplus
472}
473#endif
474
0a7de745 475#endif /* _VM_VM_KERN_H_ */