xref: /xnu-11215.81.4/osfmk/vm/vm_iokit.h (revision d4514f0bc1d3f944c22d92e68b646ac3fb40d452)
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 
51 
52 extern void iopl_valid_data(
53 	upl_t                   upl_ptr,
54 	vm_tag_t        tag);
55 
56 
57 #ifdef  MACH_KERNEL_PRIVATE
58 #include <vm/vm_page.h>
59 #else
60 typedef struct vm_page  *vm_page_t;
61 #endif
62 
63 
64 extern void               vm_page_set_offset(vm_page_t page, vm_object_offset_t offset);
65 extern vm_object_offset_t vm_page_get_offset(vm_page_t page);
66 extern ppnum_t            vm_page_get_phys_page(vm_page_t page);
67 extern vm_page_t          vm_page_get_next(vm_page_t page);
68 
69 
70 /*
71  * device_data_action and device_close are exported symbols
72  */
73 extern kern_return_t device_data_action(
74 	uintptr_t               device_handle,
75 	ipc_port_t              device_pager,
76 	vm_prot_t               protection,
77 	vm_object_offset_t      offset,
78 	vm_size_t               size);
79 
80 extern kern_return_t device_close(
81 	uintptr_t     device_handle);
82 
83 extern boolean_t vm_swap_files_pinned(void);
84 
85 extern kern_return_t device_pager_populate_object(
86 	memory_object_t         device,
87 	memory_object_offset_t  offset,
88 	ppnum_t                 page_num,
89 	vm_size_t               size);
90 extern memory_object_t device_pager_setup(
91 	memory_object_t,
92 	uintptr_t,
93 	vm_size_t,
94 	int);
95 
96 extern kern_return_t vm_map_range_physical_size(
97 	vm_map_t         map,
98 	vm_map_address_t start,
99 	mach_vm_size_t   size,
100 	mach_vm_size_t * phys_size);
101 
102 
103 #if defined(__arm64__)
104 extern void vm_panic_hibernate_write_image_failed(int err);
105 #endif /* __arm64__ */
106 
107 
108 extern kern_return_t mach_make_memory_entry_internal(
109 	vm_map_t                target_map,
110 	memory_object_size_ut  *size,
111 	memory_object_offset_ut offset,
112 	vm_prot_ut              permission,
113 	vm_named_entry_kernel_flags_t vmne_kflags,
114 	ipc_port_t              *object_handle,
115 	ipc_port_t              parent_handle);
116 
117 extern kern_return_t
118 memory_entry_check_for_adjustment(
119 	vm_map_t                        src_map,
120 	ipc_port_t                      port,
121 	vm_map_offset_t         *overmap_start,
122 	vm_map_offset_t         *overmap_end);
123 
124 extern kern_return_t memory_entry_purgeable_control_internal(
125 	ipc_port_t      entry_port,
126 	vm_purgable_t   control,
127 	int             *state);
128 
129 extern kern_return_t mach_memory_entry_get_page_counts(
130 	ipc_port_t      entry_port,
131 	unsigned int    *resident_page_count,
132 	unsigned int    *dirty_page_count);
133 
134 extern kern_return_t mach_memory_entry_phys_page_offset(
135 	ipc_port_t              entry_port,
136 	vm_object_offset_t      *offset_p);
137 
138 extern kern_return_t mach_memory_entry_map_size(
139 	ipc_port_t                 entry_port,
140 	vm_map_t                   map,
141 	memory_object_offset_ut    offset,
142 	memory_object_size_ut      size,
143 	mach_vm_size_t            *map_size);
144 
145 /* Enter a mapping of a memory object */
146 extern kern_return_t vm_map_enter_mem_object_prefault(
147 	vm_map_t                map,
148 	vm_map_offset_ut       *address,
149 	vm_map_size_ut          size,
150 	vm_map_offset_ut        mask,
151 	vm_map_kernel_flags_t   vmk_flags,
152 	ipc_port_t              port,
153 	vm_object_offset_ut     offset,
154 	vm_prot_ut              cur_protection,
155 	vm_prot_ut              max_protection,
156 	upl_page_list_ptr_t     page_list,
157 	unsigned int            page_list_count);
158 
159 
160 __END_DECLS
161 
162 #endif  /* _VM_VM_IOKIT_H_ */
163