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