xref: /xnu-12377.61.12/osfmk/vm/vm_iokit.h (revision 4d495c6e23c53686cf65f45067f79024cf5dcee8)
1 /*
2  * Copyright (c) 2023 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 #ifndef _VM_VM_IOKIT_H_
30 #define _VM_VM_IOKIT_H_
31 
32 #include <sys/cdefs.h>
33 #include <mach/mach_types.h>
34 #include <kern/kern_types.h>
35 #include <vm/vm_options.h>
36 
37 __BEGIN_DECLS
38 
39 extern kern_return_t memory_object_iopl_request(
40 	ipc_port_t              port,
41 	memory_object_offset_t  offset,
42 	upl_size_t              *upl_size,
43 	upl_t                   *upl_ptr,
44 	upl_page_info_array_t   user_page_list,
45 	unsigned int            *page_list_count,
46 	upl_control_flags_t     *flags,
47 	vm_tag_t                tag);
48 
49 extern uint32_t         vm_tag_get_kext(vm_tag_t tag, char * name, vm_size_t namelen);
50 #if DEBUG || DEVELOPMENT
51 extern uint64_t         vm_task_evict_shared_cache(task_t task);
52 extern uint64_t         vm_task_pageins(task_t task);
53 #endif /* DEBUG || DEVELOPMENT */
54 
55 
56 extern void iopl_valid_data(
57 	upl_t                   upl_ptr,
58 	vm_tag_t        tag);
59 
60 
61 #ifdef  MACH_KERNEL_PRIVATE
62 #include <vm/vm_page.h>
63 #else
64 typedef struct vm_page  *vm_page_t;
65 #endif
66 
67 
68 extern void               vm_page_set_offset(vm_page_t page, vm_object_offset_t offset);
69 extern vm_object_offset_t vm_page_get_offset(vm_page_t page);
70 extern ppnum_t            vm_page_get_phys_page(vm_page_t page);
71 extern vm_page_t          vm_page_get_next(vm_page_t page);
72 
73 
74 /*
75  * device_data_action and device_close are exported symbols
76  */
77 extern kern_return_t device_data_action(
78 	uintptr_t               device_handle,
79 	ipc_port_t              device_pager,
80 	vm_prot_t               protection,
81 	vm_object_offset_t      offset,
82 	vm_size_t               size);
83 
84 extern kern_return_t device_close(
85 	uintptr_t     device_handle);
86 
87 extern boolean_t vm_swap_files_pinned(void);
88 
89 extern kern_return_t device_pager_populate_object(
90 	memory_object_t         device,
91 	memory_object_offset_t  offset,
92 	ppnum_t                 page_num,
93 	vm_size_t               size);
94 extern memory_object_t device_pager_setup(
95 	memory_object_t,
96 	uintptr_t,
97 	vm_size_t,
98 	int);
99 
100 extern kern_return_t vm_map_range_physical_size(
101 	vm_map_t         map,
102 	vm_map_address_t start,
103 	mach_vm_size_t   size,
104 	mach_vm_size_t * phys_size);
105 
106 
107 #if defined(__arm64__)
108 extern void vm_panic_hibernate_write_image_failed(
109 	int err,
110 	uint64_t file_size_min,
111 	uint64_t file_size_max,
112 	uint64_t file_size);
113 #endif /* __arm64__ */
114 
115 
116 extern kern_return_t mach_make_memory_entry_internal(
117 	vm_map_t                target_map,
118 	memory_object_size_ut  *size,
119 	memory_object_offset_ut offset,
120 	vm_prot_ut              permission,
121 	vm_named_entry_kernel_flags_t vmne_kflags,
122 	ipc_port_t              *object_handle,
123 	ipc_port_t              parent_handle);
124 
125 extern kern_return_t
126 memory_entry_check_for_adjustment(
127 	vm_map_t                        src_map,
128 	ipc_port_t                      port,
129 	vm_map_offset_t         *overmap_start,
130 	vm_map_offset_t         *overmap_end);
131 
132 extern kern_return_t memory_entry_purgeable_control_internal(
133 	ipc_port_t      entry_port,
134 	vm_purgable_t   control,
135 	int             *state);
136 
137 extern kern_return_t mach_memory_entry_get_page_counts(
138 	ipc_port_t      entry_port,
139 	uint64_t        *resident_page_count,
140 	uint64_t        *dirty_page_count,
141 	uint64_t        *swapped_page_count);
142 
143 extern kern_return_t mach_memory_entry_phys_page_offset(
144 	ipc_port_t              entry_port,
145 	vm_object_offset_t      *offset_p);
146 
147 extern kern_return_t mach_memory_entry_map_size(
148 	ipc_port_t                 entry_port,
149 	vm_map_t                   map,
150 	memory_object_offset_ut    offset,
151 	memory_object_size_ut      size,
152 	mach_vm_size_t            *map_size);
153 
154 /* Enter a mapping of a memory object */
155 extern kern_return_t vm_map_enter_mem_object_prefault(
156 	vm_map_t                map,
157 	vm_map_offset_ut       *address,
158 	vm_map_size_ut          size,
159 	vm_map_offset_ut        mask,
160 	vm_map_kernel_flags_t   vmk_flags,
161 	ipc_port_t              port,
162 	vm_object_offset_ut     offset,
163 	vm_prot_ut              cur_protection,
164 	vm_prot_ut              max_protection,
165 	upl_page_list_ptr_t     page_list,
166 	unsigned int            page_list_count);
167 
168 extern void vm_report_disallowed_sharing_data_buffers(void);
169 
170 extern bool vm_map_should_allow_entering_alias(
171 	vm_map_t originating_map,
172 	vm_map_t destination_map,
173 	ipc_port_t ne_port);
174 
175 __END_DECLS
176 
177 #endif  /* _VM_VM_IOKIT_H_ */
178