]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_kern.h
xnu-4570.61.1.tar.gz
[apple/xnu.git] / osfmk / vm / vm_kern.h
1 /*
2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
69 #include <mach/mach_types.h>
70 #include <mach/boolean.h>
71 #include <mach/kern_return.h>
72
73 #ifdef KERNEL_PRIVATE
74
75 #ifdef XNU_KERNEL_PRIVATE
76
77 #include <kern/locks.h>
78
79 extern kern_return_t kernel_memory_allocate(
80 vm_map_t map,
81 vm_offset_t *addrp,
82 vm_size_t size,
83 vm_offset_t mask,
84 int flags,
85 vm_tag_t tag);
86
87 /* flags for kernel_memory_allocate */
88 #define KMA_HERE 0x01
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
101
102 extern kern_return_t kmem_alloc(
103 vm_map_t map,
104 vm_offset_t *addrp,
105 vm_size_t size,
106 vm_tag_t tag);
107
108 extern kern_return_t kmem_alloc_contig(
109 vm_map_t map,
110 vm_offset_t *addrp,
111 vm_size_t size,
112 vm_offset_t mask,
113 ppnum_t max_pnum,
114 ppnum_t pnum_mask,
115 int flags,
116 vm_tag_t tag);
117
118 extern kern_return_t kmem_alloc_flags(
119 vm_map_t map,
120 vm_offset_t *addrp,
121 vm_size_t size,
122 vm_tag_t tag,
123 int flags);
124
125 extern kern_return_t kmem_alloc_pageable(
126 vm_map_t map,
127 vm_offset_t *addrp,
128 vm_size_t size,
129 vm_tag_t tag);
130
131 extern kern_return_t kmem_alloc_aligned(
132 vm_map_t map,
133 vm_offset_t *addrp,
134 vm_size_t size,
135 vm_tag_t tag);
136
137 extern kern_return_t kmem_realloc(
138 vm_map_t map,
139 vm_offset_t oldaddr,
140 vm_size_t oldsize,
141 vm_offset_t *newaddrp,
142 vm_size_t newsize,
143 vm_tag_t tag);
144
145 extern void kmem_free(
146 vm_map_t map,
147 vm_offset_t addr,
148 vm_size_t size);
149
150 extern kern_return_t kmem_suballoc(
151 vm_map_t parent,
152 vm_offset_t *addr,
153 vm_size_t size,
154 boolean_t pageable,
155 int flags,
156 vm_map_kernel_flags_t vmk_flags,
157 vm_tag_t tag,
158 vm_map_t *new_map);
159
160 extern kern_return_t kmem_alloc_kobject(
161 vm_map_t map,
162 vm_offset_t *addrp,
163 vm_size_t size,
164 vm_tag_t tag);
165
166 extern kern_return_t kernel_memory_populate(
167 vm_map_t map,
168 vm_offset_t addr,
169 vm_size_t size,
170 int flags,
171 vm_tag_t tag);
172
173 extern void kernel_memory_depopulate(
174 vm_map_t map,
175 vm_offset_t addr,
176 vm_size_t size,
177 int flags);
178
179 extern kern_return_t memory_object_iopl_request(
180 ipc_port_t port,
181 memory_object_offset_t offset,
182 upl_size_t *upl_size,
183 upl_t *upl_ptr,
184 upl_page_info_array_t user_page_list,
185 unsigned int *page_list_count,
186 upl_control_flags_t *flags,
187 vm_tag_t tag);
188
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);
192
193 extern uint32_t vm_page_diagnose_estimate(void);
194
195 #if DEBUG || DEVELOPMENT
196
197 extern kern_return_t mach_memory_info_check(void);
198
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);
200
201 #endif /* DEBUG || DEVELOPMENT */
202
203 extern vm_tag_t vm_tag_bt(void);
204
205 extern vm_tag_t vm_tag_alloc(vm_allocation_site_t * site);
206
207 extern void vm_tag_alloc_locked(vm_allocation_site_t * site, vm_allocation_site_t ** releasesiteP);
208
209 extern void vm_tag_update_size(vm_tag_t tag, int64_t size);
210
211 #if VM_MAX_TAG_ZONES
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);
215
216 extern vm_allocation_zone_total_t ** vm_allocation_zone_totals;
217
218 #endif /* VM_MAX_TAG_ZONES */
219
220 extern vm_tag_t vm_tag_bt_debug(void);
221
222 extern uint32_t vm_tag_get_kext(vm_tag_t tag, char * name, vm_size_t namelen);
223
224 extern boolean_t vm_kernel_map_is_kernel(vm_map_t map);
225
226 extern ppnum_t kernel_pmap_present_mapping(uint64_t vaddr, uint64_t * pvincr, uintptr_t * pvphysaddr);
227
228 #else /* XNU_KERNEL_PRIVATE */
229
230 extern kern_return_t kmem_alloc(
231 vm_map_t map,
232 vm_offset_t *addrp,
233 vm_size_t size);
234
235 extern kern_return_t kmem_alloc_pageable(
236 vm_map_t map,
237 vm_offset_t *addrp,
238 vm_size_t size);
239
240 extern kern_return_t kmem_alloc_kobject(
241 vm_map_t map,
242 vm_offset_t *addrp,
243 vm_size_t size);
244
245 extern void kmem_free(
246 vm_map_t map,
247 vm_offset_t addr,
248 vm_size_t size);
249
250 #endif /* !XNU_KERNEL_PRIVATE */
251
252
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 */
260
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 */
269
270 #ifdef MACH_KERNEL_PRIVATE
271
272 extern void kmem_init(
273 vm_offset_t start,
274 vm_offset_t end);
275
276
277 extern kern_return_t copyinmap(
278 vm_map_t map,
279 vm_map_offset_t fromaddr,
280 void *todata,
281 vm_size_t length);
282
283 extern kern_return_t copyoutmap(
284 vm_map_t map,
285 void *fromdata,
286 vm_map_offset_t toaddr,
287 vm_size_t length);
288
289 extern kern_return_t kmem_alloc_external(
290 vm_map_t map,
291 vm_offset_t *addrp,
292 vm_size_t size);
293
294 extern kern_return_t kmem_alloc_kobject_external(
295 vm_map_t map,
296 vm_offset_t *addrp,
297 vm_size_t size);
298
299 extern kern_return_t kmem_alloc_pageable_external(
300 vm_map_t map,
301 vm_offset_t *addrp,
302 vm_size_t size);
303
304 #endif /* MACH_KERNEL_PRIVATE */
305
306 #ifdef XNU_KERNEL_PRIVATE
307
308 extern kern_return_t mach_vm_allocate_kernel(
309 vm_map_t map,
310 mach_vm_offset_t *addr,
311 mach_vm_size_t size,
312 int flags,
313 vm_tag_t tag);
314
315 extern kern_return_t vm_allocate_kernel(
316 vm_map_t map,
317 vm_offset_t *addr,
318 vm_size_t size,
319 int flags,
320 vm_tag_t tag);
321
322
323 extern kern_return_t mach_vm_map_kernel(
324 vm_map_t target_map,
325 mach_vm_offset_t *address,
326 mach_vm_size_t initial_size,
327 mach_vm_offset_t mask,
328 int flags,
329 vm_tag_t tag,
330 ipc_port_t port,
331 vm_object_offset_t offset,
332 boolean_t copy,
333 vm_prot_t cur_protection,
334 vm_prot_t max_protection,
335 vm_inherit_t inheritance);
336
337
338 extern kern_return_t vm_map_kernel(
339 vm_map_t target_map,
340 vm_offset_t *address,
341 vm_size_t size,
342 vm_offset_t mask,
343 int flags,
344 vm_tag_t tag,
345 ipc_port_t port,
346 vm_offset_t offset,
347 boolean_t copy,
348 vm_prot_t cur_protection,
349 vm_prot_t max_protection,
350 vm_inherit_t inheritance);
351
352 extern kern_return_t mach_vm_remap_kernel(
353 vm_map_t target_map,
354 mach_vm_offset_t *address,
355 mach_vm_size_t size,
356 mach_vm_offset_t mask,
357 int flags,
358 vm_tag_t tag,
359 vm_map_t src_map,
360 mach_vm_offset_t memory_address,
361 boolean_t copy,
362 vm_prot_t *cur_protection,
363 vm_prot_t *max_protection,
364 vm_inherit_t inheritance);
365
366 extern kern_return_t vm_remap_kernel(
367 vm_map_t target_map,
368 vm_offset_t *address,
369 vm_size_t size,
370 vm_offset_t mask,
371 int flags,
372 vm_tag_t tag,
373 vm_map_t src_map,
374 vm_offset_t memory_address,
375 boolean_t copy,
376 vm_prot_t *cur_protection,
377 vm_prot_t *max_protection,
378 vm_inherit_t inheritance);
379
380 extern kern_return_t vm_map_64_kernel(
381 vm_map_t target_map,
382 vm_offset_t *address,
383 vm_size_t size,
384 vm_offset_t mask,
385 int flags,
386 vm_tag_t tag,
387 ipc_port_t port,
388 vm_object_offset_t offset,
389 boolean_t copy,
390 vm_prot_t cur_protection,
391 vm_prot_t max_protection,
392 vm_inherit_t inheritance);
393
394 extern kern_return_t mach_vm_wire_kernel(
395 host_priv_t host_priv,
396 vm_map_t map,
397 mach_vm_offset_t start,
398 mach_vm_size_t size,
399 vm_prot_t access,
400 vm_tag_t tag);
401
402 extern kern_return_t vm_map_wire_kernel(
403 vm_map_t map,
404 vm_map_offset_t start,
405 vm_map_offset_t end,
406 vm_prot_t caller_prot,
407 vm_tag_t tag,
408 boolean_t user_wire);
409
410 extern kern_return_t vm_map_wire_and_extract_kernel(
411 vm_map_t map,
412 vm_map_offset_t start,
413 vm_prot_t caller_prot,
414 vm_tag_t tag,
415 boolean_t user_wire,
416 ppnum_t *physpage_p);
417
418 #endif /* XNU_KERNEL_PRIVATE */
419
420 extern vm_map_t kernel_map;
421 extern vm_map_t kernel_pageable_map;
422 extern vm_map_t ipc_kernel_map;
423
424 #endif /* KERNEL_PRIVATE */
425
426 #ifdef KERNEL
427
428 __BEGIN_DECLS
429 extern vm_offset_t vm_kernel_addrhash(vm_offset_t addr);
430 __END_DECLS
431
432 extern void vm_kernel_addrhide(
433 vm_offset_t addr,
434 vm_offset_t *hide_addr);
435
436 extern vm_offset_t vm_kernel_addrperm_ext;
437
438 extern void vm_kernel_addrperm_external(
439 vm_offset_t addr,
440 vm_offset_t *perm_addr);
441
442 extern void vm_kernel_unslide_or_perm_external(
443 vm_offset_t addr,
444 vm_offset_t *up_addr);
445
446 #if MACH_KERNEL_PRIVATE
447 extern uint64_t vm_kernel_addrhash_salt;
448 extern uint64_t vm_kernel_addrhash_salt_ext;
449
450 extern void vm_kernel_addrhash_external(
451 vm_offset_t addr,
452 vm_offset_t *perm_addr);
453 #endif /* MACH_KERNEL_PRIVATE */
454
455 extern void vm_init_before_launchd(void);
456
457 #endif /* KERNEL */
458 #endif /* _VM_VM_KERN_H_ */