2 * Copyright (c) 2004-2007 Apple 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@
29 #ifdef XNU_KERNEL_PRIVATE
31 #ifndef _VM_VM_PROTOS_H_
32 #define _VM_VM_PROTOS_H_
34 #include <mach/mach_types.h>
35 #include <kern/kern_types.h>
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.
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
55 extern kern_return_t
device_data_action(
56 uintptr_t device_handle
,
57 ipc_port_t device_pager
,
59 vm_object_offset_t offset
,
62 extern kern_return_t
device_close(
63 uintptr_t device_handle
);
65 extern boolean_t
vm_swap_files_pinned(void);
70 #ifndef _IPC_IPC_PORT_H_
71 extern mach_port_name_t
ipc_port_copyout_send(
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(
80 #endif /* _IPC_IPC_PORT_H_ */
82 extern ipc_space_t
get_task_ipcspace(
85 #if CONFIG_MEMORYSTATUS
86 extern int max_task_footprint_mb
; /* Per-task limit on physical memory consumption in megabytes */
87 #endif /* CONFIG_MEMORYSTATUS */
89 /* Some loose-ends VM stuff */
91 extern vm_map_t kalloc_map
;
92 extern vm_size_t msg_ool_size_small
;
93 extern vm_map_t zone_map
;
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
);
100 extern int get_vmmap_entries(vm_map_t
);
102 extern int get_map_nentries(vm_map_t
);
104 extern vm_map_offset_t
vm_map_page_mask(vm_map_t
);
106 extern kern_return_t
vm_map_purgable_control(
108 vm_map_offset_t address
,
109 vm_purgable_t control
,
113 extern boolean_t
coredumpok(vm_map_t map
, vm_offset_t va
);
117 * VM routines that used to be published to
118 * user space, and are now restricted to the kernel.
120 * They should eventually go away entirely -
121 * to be replaced with standard vm_map() and
122 * vm_deallocate() calls.
125 extern kern_return_t vm_upl_map
127 vm_map_t target_task
,
129 vm_address_t
*address
132 extern kern_return_t vm_upl_unmap
134 vm_map_t target_task
,
138 extern kern_return_t vm_region_object_create
140 vm_map_t target_task
,
142 ipc_port_t
*object_handle
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
);
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(
156 vm_map_offset_t start
,
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 */
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
);
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)) */
182 #define FOURK_PAGE_SIZE 0x1000
183 #define FOURK_PAGE_MASK 0xFFF
184 #define FOURK_PAGE_SHIFT 12
186 extern unsigned int page_shift_user32
;
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
,
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__ */
209 extern void *upl_get_internal_page_list(
212 extern void vnode_setswapmount(struct vnode
*);
213 extern int64_t vnode_getswappin_avail(struct vnode
*);
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(
229 extern uint32_t vnode_pager_isinuse(
231 extern boolean_t
vnode_pager_isSSD(
233 extern void vnode_pager_throttle(
235 extern uint32_t vnode_pager_return_throttle_io_limit(
238 extern kern_return_t
vnode_pager_get_name(
241 vm_size_t pathname_len
,
243 vm_size_t filename_len
,
244 boolean_t
*truncated_path_p
);
246 extern kern_return_t
vnode_pager_get_mtime(
248 struct timespec
*mtime
,
249 struct timespec
*cs_mtime
);
250 extern kern_return_t
vnode_pager_get_cs_blobs(
255 void vnode_pager_issue_reprioritize_io(
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
268 #endif /* CHECK_CS_VALIDATION_BITMAP */
270 extern void vnode_pager_bootstrap(void);
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(
279 memory_object_control_t
,
280 memory_object_cluster_size_t
);
281 extern kern_return_t
vnode_pager_get_object_size(
283 memory_object_offset_t
*);
286 extern kern_return_t
vnode_pager_get_object_devvp(
291 extern kern_return_t
vnode_pager_get_isinuse(
294 extern kern_return_t
vnode_pager_get_isSSD(
297 extern kern_return_t
vnode_pager_get_throttle_io_limit(
300 extern kern_return_t
vnode_pager_get_object_name(
301 memory_object_t mem_obj
,
303 vm_size_t pathname_len
,
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
);
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
,
317 #endif /*CHECK_CS_VALIDATION_BITMAP*/
319 extern kern_return_t
ubc_cs_check_validation_bitmap (
321 memory_object_offset_t offset
,
324 extern kern_return_t
vnode_pager_data_request(
326 memory_object_offset_t
,
327 memory_object_cluster_size_t
,
329 memory_object_fault_info_t
);
330 extern kern_return_t
vnode_pager_data_return(
332 memory_object_offset_t
,
333 memory_object_cluster_size_t
,
334 memory_object_offset_t
*,
339 extern kern_return_t
vnode_pager_data_initialize(
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
,
353 extern kern_return_t
vnode_pager_last_unmap(
354 memory_object_t mem_obj
);
355 extern void vnode_pager_deallocate(
357 extern kern_return_t
vnode_pager_terminate(
359 extern void vnode_pager_vrele(
361 extern struct vnode
*vnode_pager_lookup_vnode(
367 extern void ubc_unmap(
371 extern struct vm_object
*find_vnode_object(struct vm_map_entry
*entry
);
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
,
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
*,
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
,
399 extern kern_return_t
device_pager_synchronize(memory_object_t
,
400 memory_object_offset_t
,
401 memory_object_size_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
,
410 extern memory_object_t
device_pager_setup(
415 extern void device_pager_bootstrap(void);
416 extern boolean_t
is_device_pager_ops(const struct memory_object_pager_ops
*pager_ops
);
418 extern kern_return_t
pager_map_to_phys_contiguous(
419 memory_object_control_t object
,
420 memory_object_offset_t offset
,
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
);
429 struct macx_triggers_args
;
430 extern int mach_macx_triggers(
431 struct macx_triggers_args
*args
);
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
);
439 extern void log_stack_execution_failure(addr64_t vaddr
, vm_prot_t prot
);
440 extern void log_unnest_badness(
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
);
448 extern int cs_allow_invalid(struct proc
*p
);
449 extern int cs_invalid_page(addr64_t vaddr
, boolean_t
*cs_killed
);
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
,
460 extern kern_return_t
memory_entry_purgeable_control_internal(
461 ipc_port_t entry_port
,
462 vm_purgable_t control
,
465 extern kern_return_t
mach_memory_entry_purgable_control(
466 ipc_port_t entry_port
,
467 vm_purgable_t control
,
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
);
475 extern kern_return_t
mach_memory_entry_page_op(
476 ipc_port_t entry_port
,
477 vm_object_offset_t offset
,
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
,
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
);
495 extern void vm_paging_map_init(void);
497 extern int macx_backing_store_compaction(int flags
);
498 extern unsigned int mach_vm_ctl_page_free_wanted(void);
500 extern int no_paging_space_action(void);
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*);
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. */
511 extern void vm_compressor_pager_init(void);
512 extern kern_return_t
compressor_memory_object_create(
513 memory_object_size_t
,
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);
521 extern int proc_get_memstat_priority(struct proc
*, boolean_t
);
522 #endif /* CONFIG_JETSAM */
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
);
532 struct trim_list
*tl_next
;
535 u_int32_t
vnode_trim_list(struct vnode
*vp
, struct trim_list
*tl
, boolean_t route_only
);
537 #define MAX_SWAPFILENAME_LEN 1024
538 #define SWAPFILENAME_INDEX_LEN 2 /* Doesn't include the terminating NULL character */
540 extern char swapfilename
[MAX_SWAPFILENAME_LEN
+ 1];
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
;
553 extern struct vm_counters vm_counters
;
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
;
564 int grab_for_iokit_success
;
566 extern struct vm_page_secluded_data vm_page_secluded
;
568 extern int num_tasks_can_use_secluded_mem
;
571 extern int secluded_for_apps
;
572 extern int secluded_for_iokit
;
573 extern int secluded_for_filecache
;
575 extern int secluded_for_fbdp
;
578 extern void memory_object_mark_eligible_for_secluded(
579 memory_object_control_t control
,
580 boolean_t eligible_for_secluded
);
582 #endif /* CONFIG_SECLUDED_MEMORY */
584 #define MAX_PAGE_RANGE_QUERY (1ULL * 1024 * 1024 * 1024) /* 1 GB */
590 #endif /* _VM_VM_PROTOS_H_ */
592 #endif /* XNU_KERNEL_PRIVATE */