2 * Copyright (c) 2000-2006 Apple Computer, 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.
60 * Author: Avadis Tevanian, Jr., Michael Wayne Young
63 * Kernel memory management definitions.
66 #ifndef _VM_VM_KERN_H_
67 #define _VM_VM_KERN_H_
69 #include <mach/mach_types.h>
70 #include <mach/boolean.h>
71 #include <mach/kern_return.h>
75 #ifdef XNU_KERNEL_PRIVATE
77 #include <kern/locks.h>
79 extern kern_return_t
kernel_memory_allocate(
87 /* flags for kernel_memory_allocate */
89 #define KMA_NOPAGEWAIT 0x02
90 #define KMA_KOBJECT 0x04
91 #define KMA_LOMEM 0x08
92 #define KMA_GUARD_FIRST 0x10
93 #define KMA_GUARD_LAST 0x20
94 #define KMA_PERMANENT 0x40
95 #define KMA_NOENCRYPT 0x80
96 #define KMA_KSTACK 0x100
97 #define KMA_VAONLY 0x200
98 #define KMA_COMPRESSOR 0x400 /* Pages belonging to the compressor are not on the paging queues, nor are they counted as wired. */
99 #define KMA_ATOMIC 0x800
100 #define KMA_ZERO 0x1000
102 extern kern_return_t
kmem_alloc(
108 extern kern_return_t
kmem_alloc_contig(
118 extern kern_return_t
kmem_alloc_flags(
125 extern kern_return_t
kmem_alloc_pageable(
131 extern kern_return_t
kmem_alloc_aligned(
137 extern kern_return_t
kmem_realloc(
141 vm_offset_t
*newaddrp
,
145 extern void kmem_free(
150 extern kern_return_t
kmem_suballoc(
156 vm_map_kernel_flags_t vmk_flags
,
160 extern kern_return_t
kmem_alloc_kobject(
166 extern kern_return_t
kernel_memory_populate(
173 extern void kernel_memory_depopulate(
179 extern kern_return_t
memory_object_iopl_request(
181 memory_object_offset_t offset
,
182 upl_size_t
*upl_size
,
184 upl_page_info_array_t user_page_list
,
185 unsigned int *page_list_count
,
186 upl_control_flags_t
*flags
,
189 struct mach_memory_info
;
190 extern kern_return_t
vm_page_diagnose(struct mach_memory_info
* info
,
191 unsigned int num_info
, uint64_t zones_collectable_bytes
);
193 extern uint32_t vm_page_diagnose_estimate(void);
195 #if DEBUG || DEVELOPMENT
197 extern kern_return_t
mach_memory_info_check(void);
199 extern kern_return_t
vm_kern_allocation_info(uintptr_t addr
, vm_size_t
* size
, vm_tag_t
* tag
, vm_size_t
* zone_size
);
201 #endif /* DEBUG || DEVELOPMENT */
203 extern vm_tag_t
vm_tag_bt(void);
205 extern vm_tag_t
vm_tag_alloc(vm_allocation_site_t
* site
);
207 extern void vm_tag_alloc_locked(vm_allocation_site_t
* site
, vm_allocation_site_t
** releasesiteP
);
209 extern void vm_tag_update_size(vm_tag_t tag
, int64_t size
);
212 extern void vm_allocation_zones_init(void);
213 extern void vm_tag_will_update_zone(vm_tag_t tag
, uint32_t zidx
);
214 extern void vm_tag_update_zone_size(vm_tag_t tag
, uint32_t zidx
, int64_t delta
, int64_t dwaste
);
216 extern vm_allocation_zone_total_t
** vm_allocation_zone_totals
;
218 #endif /* VM_MAX_TAG_ZONES */
220 extern vm_tag_t
vm_tag_bt_debug(void);
222 extern uint32_t vm_tag_get_kext(vm_tag_t tag
, char * name
, vm_size_t namelen
);
224 extern boolean_t
vm_kernel_map_is_kernel(vm_map_t map
);
226 extern ppnum_t
kernel_pmap_present_mapping(uint64_t vaddr
, uint64_t * pvincr
, uintptr_t * pvphysaddr
);
228 #else /* XNU_KERNEL_PRIVATE */
230 extern kern_return_t
kmem_alloc(
235 extern kern_return_t
kmem_alloc_pageable(
240 extern kern_return_t
kmem_alloc_kobject(
245 extern void kmem_free(
250 #endif /* !XNU_KERNEL_PRIVATE */
253 #ifdef XNU_KERNEL_PRIVATE
254 typedef struct vm_allocation_site kern_allocation_name
;
255 typedef kern_allocation_name
* kern_allocation_name_t
;
256 #else /* XNU_KERNEL_PRIVATE */
257 struct kern_allocation_name
;
258 typedef struct kern_allocation_name
* kern_allocation_name_t
;
259 #endif /* !XNU_KERNEL_PRIVATE */
261 extern kern_allocation_name_t
kern_allocation_name_allocate(const char * name
, uint32_t suballocs
);
262 extern void kern_allocation_name_release(kern_allocation_name_t allocation
);
263 extern const char * kern_allocation_get_name(kern_allocation_name_t allocation
);
264 #ifdef XNU_KERNEL_PRIVATE
265 extern void kern_allocation_update_size(kern_allocation_name_t allocation
, int64_t delta
);
266 extern void kern_allocation_update_subtotal(kern_allocation_name_t allocation
, uint32_t subtag
, int64_t delta
);
267 extern vm_tag_t
kern_allocation_name_get_vm_tag(kern_allocation_name_t allocation
);
268 #endif /* XNU_KERNEL_PRIVATE */
270 #ifdef MACH_KERNEL_PRIVATE
272 extern void kmem_init(
277 extern kern_return_t
copyinmap(
279 vm_map_offset_t fromaddr
,
283 extern kern_return_t
copyoutmap(
286 vm_map_offset_t toaddr
,
289 extern kern_return_t
kmem_alloc_external(
294 extern kern_return_t
kmem_alloc_kobject_external(
299 extern kern_return_t
kmem_alloc_pageable_external(
304 #endif /* MACH_KERNEL_PRIVATE */
306 #ifdef XNU_KERNEL_PRIVATE
308 extern kern_return_t
mach_vm_allocate_kernel(
310 mach_vm_offset_t
*addr
,
315 extern kern_return_t
vm_allocate_kernel(
323 extern kern_return_t
mach_vm_map_kernel(
325 mach_vm_offset_t
*address
,
326 mach_vm_size_t initial_size
,
327 mach_vm_offset_t mask
,
331 vm_object_offset_t offset
,
333 vm_prot_t cur_protection
,
334 vm_prot_t max_protection
,
335 vm_inherit_t inheritance
);
338 extern kern_return_t
vm_map_kernel(
340 vm_offset_t
*address
,
348 vm_prot_t cur_protection
,
349 vm_prot_t max_protection
,
350 vm_inherit_t inheritance
);
352 extern kern_return_t
mach_vm_remap_kernel(
354 mach_vm_offset_t
*address
,
356 mach_vm_offset_t mask
,
360 mach_vm_offset_t memory_address
,
362 vm_prot_t
*cur_protection
,
363 vm_prot_t
*max_protection
,
364 vm_inherit_t inheritance
);
366 extern kern_return_t
vm_remap_kernel(
368 vm_offset_t
*address
,
374 vm_offset_t memory_address
,
376 vm_prot_t
*cur_protection
,
377 vm_prot_t
*max_protection
,
378 vm_inherit_t inheritance
);
380 extern kern_return_t
vm_map_64_kernel(
382 vm_offset_t
*address
,
388 vm_object_offset_t offset
,
390 vm_prot_t cur_protection
,
391 vm_prot_t max_protection
,
392 vm_inherit_t inheritance
);
394 extern kern_return_t
mach_vm_wire_kernel(
395 host_priv_t host_priv
,
397 mach_vm_offset_t start
,
402 extern kern_return_t
vm_map_wire_kernel(
404 vm_map_offset_t start
,
406 vm_prot_t caller_prot
,
408 boolean_t user_wire
);
410 extern kern_return_t
vm_map_wire_and_extract_kernel(
412 vm_map_offset_t start
,
413 vm_prot_t caller_prot
,
416 ppnum_t
*physpage_p
);
418 #endif /* XNU_KERNEL_PRIVATE */
420 extern vm_map_t kernel_map
;
421 extern vm_map_t kernel_pageable_map
;
422 extern vm_map_t ipc_kernel_map
;
424 #endif /* KERNEL_PRIVATE */
429 extern vm_offset_t
vm_kernel_addrhash(vm_offset_t addr
);
432 extern void vm_kernel_addrhide(
434 vm_offset_t
*hide_addr
);
436 extern vm_offset_t vm_kernel_addrperm_ext
;
438 extern void vm_kernel_addrperm_external(
440 vm_offset_t
*perm_addr
);
442 extern void vm_kernel_unslide_or_perm_external(
444 vm_offset_t
*up_addr
);
446 #if MACH_KERNEL_PRIVATE
447 extern uint64_t vm_kernel_addrhash_salt
;
448 extern uint64_t vm_kernel_addrhash_salt_ext
;
450 extern void vm_kernel_addrhash_external(
452 vm_offset_t
*perm_addr
);
453 #endif /* MACH_KERNEL_PRIVATE */
455 extern void vm_init_before_launchd(void);
458 #endif /* _VM_VM_KERN_H_ */