]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/vm_protos.h
de4756f67bfd3752004c291e41387de2e7eb8097
[apple/xnu.git] / osfmk / vm / vm_protos.h
1 /*
2 * Copyright (c) 2004-2007 Apple 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 #ifdef XNU_KERNEL_PRIVATE
30
31 #ifndef _VM_VM_PROTOS_H_
32 #define _VM_VM_PROTOS_H_
33
34 #include <mach/mach_types.h>
35 #include <kern/kern_types.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /*
42 * This file contains various type definitions and routine prototypes
43 * that are needed to avoid compilation warnings for VM code (in osfmk,
44 * default_pager and bsd).
45 * Most of these should eventually go into more appropriate header files.
46 *
47 * Include it after all other header files since it doesn't include any
48 * type definitions and it works around some conflicts with other header
49 * files.
50 */
51
52 /*
53 * iokit
54 */
55 extern kern_return_t device_data_action(
56 uintptr_t device_handle,
57 ipc_port_t device_pager,
58 vm_prot_t protection,
59 vm_object_offset_t offset,
60 vm_size_t size);
61
62 extern kern_return_t device_close(
63 uintptr_t device_handle);
64
65 extern boolean_t vm_swap_files_pinned(void);
66
67 /*
68 * osfmk
69 */
70 #ifndef _IPC_IPC_PORT_H_
71 extern mach_port_name_t ipc_port_copyout_send(
72 ipc_port_t sright,
73 ipc_space_t space);
74 extern task_t port_name_to_task(
75 mach_port_name_t name);
76 extern task_t port_name_to_task_inspect(
77 mach_port_name_t name);
78 extern void ipc_port_release_send(
79 ipc_port_t port);
80 #endif /* _IPC_IPC_PORT_H_ */
81
82 extern ipc_space_t get_task_ipcspace(
83 task_t t);
84
85 #if CONFIG_MEMORYSTATUS
86 extern int max_task_footprint_mb; /* Per-task limit on physical memory consumption in megabytes */
87 #endif /* CONFIG_MEMORYSTATUS */
88
89 /* Some loose-ends VM stuff */
90
91 extern vm_map_t kalloc_map;
92 extern vm_size_t msg_ool_size_small;
93 extern vm_map_t zone_map;
94
95 extern void consider_machine_adjust(void);
96 extern vm_map_offset_t get_map_min(vm_map_t);
97 extern vm_map_offset_t get_map_max(vm_map_t);
98 extern vm_map_size_t get_vmmap_size(vm_map_t);
99 #if CONFIG_COREDUMP
100 extern int get_vmmap_entries(vm_map_t);
101 #endif
102 extern int get_map_nentries(vm_map_t);
103
104 extern vm_map_offset_t vm_map_page_mask(vm_map_t);
105
106 extern kern_return_t vm_map_purgable_control(
107 vm_map_t map,
108 vm_map_offset_t address,
109 vm_purgable_t control,
110 int *state);
111
112 #if CONFIG_COREDUMP
113 extern boolean_t coredumpok(vm_map_t map, vm_offset_t va);
114 #endif
115
116 /*
117 * VM routines that used to be published to
118 * user space, and are now restricted to the kernel.
119 *
120 * They should eventually go away entirely -
121 * to be replaced with standard vm_map() and
122 * vm_deallocate() calls.
123 */
124
125 extern kern_return_t vm_upl_map
126 (
127 vm_map_t target_task,
128 upl_t upl,
129 vm_address_t *address
130 );
131
132 extern kern_return_t vm_upl_unmap
133 (
134 vm_map_t target_task,
135 upl_t upl
136 );
137
138 extern kern_return_t vm_region_object_create
139 (
140 vm_map_t target_task,
141 vm_size_t size,
142 ipc_port_t *object_handle
143 );
144
145 extern mach_vm_offset_t mach_get_vm_start(vm_map_t);
146 extern mach_vm_offset_t mach_get_vm_end(vm_map_t);
147
148 #if CONFIG_CODE_DECRYPTION
149 #define VM_MAP_DEBUG_APPLE_PROTECT MACH_ASSERT
150 #if VM_MAP_DEBUG_APPLE_PROTECT
151 extern int vm_map_debug_apple_protect;
152 #endif /* VM_MAP_DEBUG_APPLE_PROTECT */
153 struct pager_crypt_info;
154 extern kern_return_t vm_map_apple_protected(
155 vm_map_t map,
156 vm_map_offset_t start,
157 vm_map_offset_t end,
158 vm_object_offset_t crypto_backing_offset,
159 struct pager_crypt_info *crypt_info);
160 extern void apple_protect_pager_bootstrap(void);
161 extern memory_object_t apple_protect_pager_setup(
162 vm_object_t backing_object,
163 vm_object_offset_t backing_offset,
164 vm_object_offset_t crypto_backing_offset,
165 struct pager_crypt_info *crypt_info,
166 vm_object_offset_t crypto_start,
167 vm_object_offset_t crypto_end);
168 #endif /* CONFIG_CODE_DECRYPTION */
169
170 struct vnode;
171 extern void swapfile_pager_bootstrap(void);
172 extern memory_object_t swapfile_pager_setup(struct vnode *vp);
173 extern memory_object_control_t swapfile_pager_control(memory_object_t mem_obj);
174
175 #if __arm64__ || ((__ARM_ARCH_7K__ >= 2) && defined(PLATFORM_WatchOS))
176 #define SIXTEENK_PAGE_SIZE 0x4000
177 #define SIXTEENK_PAGE_MASK 0x3FFF
178 #define SIXTEENK_PAGE_SHIFT 14
179 #endif /* __arm64__ || ((__ARM_ARCH_7K__ >= 2) && defined(PLATFORM_WatchOS)) */
180
181 #if __arm64__
182 #define FOURK_PAGE_SIZE 0x1000
183 #define FOURK_PAGE_MASK 0xFFF
184 #define FOURK_PAGE_SHIFT 12
185
186 extern unsigned int page_shift_user32;
187
188 #define VM_MAP_DEBUG_FOURK MACH_ASSERT
189 #if VM_MAP_DEBUG_FOURK
190 extern int vm_map_debug_fourk;
191 #endif /* VM_MAP_DEBUG_FOURK */
192 extern void fourk_pager_bootstrap(void);
193 extern memory_object_t fourk_pager_create(void);
194 extern vm_object_t fourk_pager_to_vm_object(memory_object_t mem_obj);
195 extern kern_return_t fourk_pager_populate(
196 memory_object_t mem_obj,
197 boolean_t overwrite,
198 int index,
199 vm_object_t new_backing_object,
200 vm_object_offset_t new_backing_offset,
201 vm_object_t *old_backing_object,
202 vm_object_offset_t *old_backing_offset);
203 #endif /* __arm64__ */
204
205 /*
206 * bsd
207 */
208 struct vnode;
209 extern void *upl_get_internal_page_list(
210 upl_t upl);
211
212 extern void vnode_setswapmount(struct vnode *);
213 extern int64_t vnode_getswappin_avail(struct vnode *);
214
215 typedef int pager_return_t;
216 extern pager_return_t vnode_pagein(
217 struct vnode *, upl_t,
218 upl_offset_t, vm_object_offset_t,
219 upl_size_t, int, int *);
220 extern pager_return_t vnode_pageout(
221 struct vnode *, upl_t,
222 upl_offset_t, vm_object_offset_t,
223 upl_size_t, int, int *);
224 extern uint32_t vnode_trim (struct vnode *, int64_t offset, unsigned long len);
225 extern memory_object_t vnode_pager_setup(
226 struct vnode *, memory_object_t);
227 extern vm_object_offset_t vnode_pager_get_filesize(
228 struct vnode *);
229 extern uint32_t vnode_pager_isinuse(
230 struct vnode *);
231 extern boolean_t vnode_pager_isSSD(
232 struct vnode *);
233 extern void vnode_pager_throttle(
234 void);
235 extern uint32_t vnode_pager_return_throttle_io_limit(
236 struct vnode *,
237 uint32_t *);
238 extern kern_return_t vnode_pager_get_name(
239 struct vnode *vp,
240 char *pathname,
241 vm_size_t pathname_len,
242 char *filename,
243 vm_size_t filename_len,
244 boolean_t *truncated_path_p);
245 struct timespec;
246 extern kern_return_t vnode_pager_get_mtime(
247 struct vnode *vp,
248 struct timespec *mtime,
249 struct timespec *cs_mtime);
250 extern kern_return_t vnode_pager_get_cs_blobs(
251 struct vnode *vp,
252 void **blobs);
253
254 #if CONFIG_IOSCHED
255 void vnode_pager_issue_reprioritize_io(
256 struct vnode *devvp,
257 uint64_t blkno,
258 uint32_t len,
259 int priority);
260 #endif
261
262 #if CHECK_CS_VALIDATION_BITMAP
263 /* used by the vnode_pager_cs_validation_bitmap routine*/
264 #define CS_BITMAP_SET 1
265 #define CS_BITMAP_CLEAR 2
266 #define CS_BITMAP_CHECK 3
267
268 #endif /* CHECK_CS_VALIDATION_BITMAP */
269
270 extern void vnode_pager_bootstrap(void);
271 extern kern_return_t
272 vnode_pager_data_unlock(
273 memory_object_t mem_obj,
274 memory_object_offset_t offset,
275 memory_object_size_t size,
276 vm_prot_t desired_access);
277 extern kern_return_t vnode_pager_init(
278 memory_object_t,
279 memory_object_control_t,
280 memory_object_cluster_size_t);
281 extern kern_return_t vnode_pager_get_object_size(
282 memory_object_t,
283 memory_object_offset_t *);
284
285 #if CONFIG_IOSCHED
286 extern kern_return_t vnode_pager_get_object_devvp(
287 memory_object_t,
288 uintptr_t *);
289 #endif
290
291 extern kern_return_t vnode_pager_get_isinuse(
292 memory_object_t,
293 uint32_t *);
294 extern kern_return_t vnode_pager_get_isSSD(
295 memory_object_t,
296 boolean_t *);
297 extern kern_return_t vnode_pager_get_throttle_io_limit(
298 memory_object_t,
299 uint32_t *);
300 extern kern_return_t vnode_pager_get_object_name(
301 memory_object_t mem_obj,
302 char *pathname,
303 vm_size_t pathname_len,
304 char *filename,
305 vm_size_t filename_len,
306 boolean_t *truncated_path_p);
307 extern kern_return_t vnode_pager_get_object_mtime(
308 memory_object_t mem_obj,
309 struct timespec *mtime,
310 struct timespec *cs_mtime);
311
312 #if CHECK_CS_VALIDATION_BITMAP
313 extern kern_return_t vnode_pager_cs_check_validation_bitmap(
314 memory_object_t mem_obj,
315 memory_object_offset_t offset,
316 int optype);
317 #endif /*CHECK_CS_VALIDATION_BITMAP*/
318
319 extern kern_return_t ubc_cs_check_validation_bitmap (
320 struct vnode *vp,
321 memory_object_offset_t offset,
322 int optype);
323
324 extern kern_return_t vnode_pager_data_request(
325 memory_object_t,
326 memory_object_offset_t,
327 memory_object_cluster_size_t,
328 vm_prot_t,
329 memory_object_fault_info_t);
330 extern kern_return_t vnode_pager_data_return(
331 memory_object_t,
332 memory_object_offset_t,
333 memory_object_cluster_size_t,
334 memory_object_offset_t *,
335 int *,
336 boolean_t,
337 boolean_t,
338 int);
339 extern kern_return_t vnode_pager_data_initialize(
340 memory_object_t,
341 memory_object_offset_t,
342 memory_object_cluster_size_t);
343 extern void vnode_pager_reference(
344 memory_object_t mem_obj);
345 extern kern_return_t vnode_pager_synchronize(
346 memory_object_t mem_obj,
347 memory_object_offset_t offset,
348 memory_object_size_t length,
349 vm_sync_t sync_flags);
350 extern kern_return_t vnode_pager_map(
351 memory_object_t mem_obj,
352 vm_prot_t prot);
353 extern kern_return_t vnode_pager_last_unmap(
354 memory_object_t mem_obj);
355 extern void vnode_pager_deallocate(
356 memory_object_t);
357 extern kern_return_t vnode_pager_terminate(
358 memory_object_t);
359 extern void vnode_pager_vrele(
360 struct vnode *vp);
361 extern struct vnode *vnode_pager_lookup_vnode(
362 memory_object_t);
363
364 extern int ubc_map(
365 struct vnode *vp,
366 int flags);
367 extern void ubc_unmap(
368 struct vnode *vp);
369
370 struct vm_map_entry;
371 extern struct vm_object *find_vnode_object(struct vm_map_entry *entry);
372
373 extern void device_pager_reference(memory_object_t);
374 extern void device_pager_deallocate(memory_object_t);
375 extern kern_return_t device_pager_init(memory_object_t,
376 memory_object_control_t,
377 memory_object_cluster_size_t);
378 extern kern_return_t device_pager_terminate(memory_object_t);
379 extern kern_return_t device_pager_data_request(memory_object_t,
380 memory_object_offset_t,
381 memory_object_cluster_size_t,
382 vm_prot_t,
383 memory_object_fault_info_t);
384 extern kern_return_t device_pager_data_return(memory_object_t,
385 memory_object_offset_t,
386 memory_object_cluster_size_t,
387 memory_object_offset_t *,
388 int *,
389 boolean_t,
390 boolean_t,
391 int);
392 extern kern_return_t device_pager_data_initialize(memory_object_t,
393 memory_object_offset_t,
394 memory_object_cluster_size_t);
395 extern kern_return_t device_pager_data_unlock(memory_object_t,
396 memory_object_offset_t,
397 memory_object_size_t,
398 vm_prot_t);
399 extern kern_return_t device_pager_synchronize(memory_object_t,
400 memory_object_offset_t,
401 memory_object_size_t,
402 vm_sync_t);
403 extern kern_return_t device_pager_map(memory_object_t, vm_prot_t);
404 extern kern_return_t device_pager_last_unmap(memory_object_t);
405 extern kern_return_t device_pager_populate_object(
406 memory_object_t device,
407 memory_object_offset_t offset,
408 ppnum_t page_num,
409 vm_size_t size);
410 extern memory_object_t device_pager_setup(
411 memory_object_t,
412 uintptr_t,
413 vm_size_t,
414 int);
415 extern void device_pager_bootstrap(void);
416 extern boolean_t is_device_pager_ops(const struct memory_object_pager_ops *pager_ops);
417
418 extern kern_return_t pager_map_to_phys_contiguous(
419 memory_object_control_t object,
420 memory_object_offset_t offset,
421 addr64_t base_vaddr,
422 vm_size_t size);
423
424 extern kern_return_t memory_object_create_named(
425 memory_object_t pager,
426 memory_object_offset_t size,
427 memory_object_control_t *control);
428
429 struct macx_triggers_args;
430 extern int mach_macx_triggers(
431 struct macx_triggers_args *args);
432
433 extern int macx_swapinfo(
434 memory_object_size_t *total_p,
435 memory_object_size_t *avail_p,
436 vm_size_t *pagesize_p,
437 boolean_t *encrypted_p);
438
439 extern void log_stack_execution_failure(addr64_t vaddr, vm_prot_t prot);
440 extern void log_unnest_badness(
441 vm_map_t map,
442 vm_map_offset_t start_unnest,
443 vm_map_offset_t end_unnest,
444 boolean_t is_nested_map,
445 vm_map_offset_t lowest_unnestable_addr);
446
447 struct proc;
448 extern int cs_allow_invalid(struct proc *p);
449 extern int cs_invalid_page(addr64_t vaddr, boolean_t *cs_killed);
450
451 #define CS_VALIDATE_TAINTED 0x00000001
452 #define CS_VALIDATE_NX 0x00000002
453 extern boolean_t cs_validate_range(struct vnode *vp,
454 memory_object_t pager,
455 memory_object_offset_t offset,
456 const void *data,
457 vm_size_t size,
458 unsigned *result);
459
460 extern kern_return_t memory_entry_purgeable_control_internal(
461 ipc_port_t entry_port,
462 vm_purgable_t control,
463 int *state);
464
465 extern kern_return_t mach_memory_entry_purgable_control(
466 ipc_port_t entry_port,
467 vm_purgable_t control,
468 int *state);
469
470 extern kern_return_t mach_memory_entry_get_page_counts(
471 ipc_port_t entry_port,
472 unsigned int *resident_page_count,
473 unsigned int *dirty_page_count);
474
475 extern kern_return_t mach_memory_entry_page_op(
476 ipc_port_t entry_port,
477 vm_object_offset_t offset,
478 int ops,
479 ppnum_t *phys_entry,
480 int *flags);
481
482 extern kern_return_t mach_memory_entry_range_op(
483 ipc_port_t entry_port,
484 vm_object_offset_t offset_beg,
485 vm_object_offset_t offset_end,
486 int ops,
487 int *range);
488
489 extern void mach_memory_entry_port_release(ipc_port_t port);
490 extern void mach_destroy_memory_entry(ipc_port_t port);
491 extern kern_return_t mach_memory_entry_allocate(
492 struct vm_named_entry **user_entry_p,
493 ipc_port_t *user_handle_p);
494
495 extern void vm_paging_map_init(void);
496
497 extern int macx_backing_store_compaction(int flags);
498 extern unsigned int mach_vm_ctl_page_free_wanted(void);
499
500 extern int no_paging_space_action(void);
501
502 #define VM_TOGGLE_CLEAR 0
503 #define VM_TOGGLE_SET 1
504 #define VM_TOGGLE_GETVALUE 999
505 int vm_toggle_entry_reuse(int, int*);
506
507 #define SWAP_WRITE 0x00000000 /* Write buffer (pseudo flag). */
508 #define SWAP_READ 0x00000001 /* Read buffer. */
509 #define SWAP_ASYNC 0x00000002 /* Start I/O, do not wait. */
510
511 extern void vm_compressor_pager_init(void);
512 extern kern_return_t compressor_memory_object_create(
513 memory_object_size_t,
514 memory_object_t *);
515
516 extern boolean_t vm_compressor_low_on_space(void);
517 extern boolean_t vm_compressor_out_of_space(void);
518 extern int vm_swap_low_on_space(void);
519 void do_fastwake_warmup_all(void);
520 #if CONFIG_JETSAM
521 extern int proc_get_memstat_priority(struct proc*, boolean_t);
522 #endif /* CONFIG_JETSAM */
523
524 /* the object purger. purges the next eligible object from memory. */
525 /* returns TRUE if an object was purged, otherwise FALSE. */
526 boolean_t vm_purgeable_object_purge_one_unlocked(int force_purge_below_group);
527 void vm_purgeable_disown(task_t task);
528
529 struct trim_list {
530 uint64_t tl_offset;
531 uint64_t tl_length;
532 struct trim_list *tl_next;
533 };
534
535 u_int32_t vnode_trim_list(struct vnode *vp, struct trim_list *tl, boolean_t route_only);
536
537 #define MAX_SWAPFILENAME_LEN 1024
538 #define SWAPFILENAME_INDEX_LEN 2 /* Doesn't include the terminating NULL character */
539
540 extern char swapfilename[MAX_SWAPFILENAME_LEN + 1];
541
542 struct vm_counters {
543 unsigned int do_collapse_compressor;
544 unsigned int do_collapse_compressor_pages;
545 unsigned int do_collapse_terminate;
546 unsigned int do_collapse_terminate_failure;
547 unsigned int should_cow_but_wired;
548 unsigned int create_upl_extra_cow;
549 unsigned int create_upl_extra_cow_pages;
550 unsigned int create_upl_lookup_failure_write;
551 unsigned int create_upl_lookup_failure_copy;
552 };
553 extern struct vm_counters vm_counters;
554
555 #if CONFIG_SECLUDED_MEMORY
556 struct vm_page_secluded_data {
557 int eligible_for_secluded;
558 int grab_success_free;
559 int grab_success_other;
560 int grab_failure_locked;
561 int grab_failure_state;
562 int grab_failure_dirty;
563 int grab_for_iokit;
564 int grab_for_iokit_success;
565 };
566 extern struct vm_page_secluded_data vm_page_secluded;
567
568 extern int num_tasks_can_use_secluded_mem;
569
570 /* boot-args */
571 extern int secluded_for_apps;
572 extern int secluded_for_iokit;
573 extern int secluded_for_filecache;
574 #if 11
575 extern int secluded_for_fbdp;
576 #endif
577
578 extern void memory_object_mark_eligible_for_secluded(
579 memory_object_control_t control,
580 boolean_t eligible_for_secluded);
581
582 #endif /* CONFIG_SECLUDED_MEMORY */
583
584 #define MAX_PAGE_RANGE_QUERY (1ULL * 1024 * 1024 * 1024) /* 1 GB */
585
586 #ifdef __cplusplus
587 }
588 #endif
589
590 #endif /* _VM_VM_PROTOS_H_ */
591
592 #endif /* XNU_KERNEL_PRIVATE */