Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | /* * Copyright (c) 2021 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ */ /* * Mach Operating System * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ #ifndef _VM_VM_MAP_INTERNAL_H_ #define _VM_VM_MAP_INTERNAL_H_ #include <vm/vm_map.h> #include <vm/vm_kern.h> __BEGIN_DECLS #pragma GCC visibility push(hidden) /* * This file contains interfaces that are private to the VM */ #define KiB(x) (1024 * (x)) #define MeB(x) (1024 * 1024 * (x)) #if __LP64__ #define KMEM_SMALLMAP_THRESHOLD (MeB(1)) #else #define KMEM_SMALLMAP_THRESHOLD (KiB(256)) #endif #if CONFIG_MAP_RANGES /* * This has been tuned for iOS only */ #define VM_MAP_USER_RANGE_MAX (GiB(12)) #endif struct kmem_page_meta; /* Initialize the module */ extern void vm_map_init(void); extern kern_return_t vm_map_locate_space( vm_map_t map, vm_map_size_t size, vm_map_offset_t mask, vm_map_kernel_flags_t vmk_flags, vm_map_offset_t *start_inout, vm_map_entry_t *entry_out); /* Allocate a range in the specified virtual address map and * return the entry allocated for that range. */ extern kern_return_t vm_map_find_space( vm_map_t map, vm_map_address_t hint_addr, vm_map_size_t size, vm_map_offset_t mask, vm_map_kernel_flags_t vmk_flags, vm_map_entry_t *o_entry); /* OUT */ extern void vm_map_clip_start( vm_map_t map, vm_map_entry_t entry, vm_map_offset_t endaddr); extern void vm_map_clip_end( vm_map_t map, vm_map_entry_t entry, vm_map_offset_t endaddr); extern boolean_t vm_map_entry_should_cow_for_true_share( vm_map_entry_t entry); /*! * @typedef vmr_flags_t * * @brief * Flags for vm_map_remove() and vm_map_delete() * * @const VM_MAP_REMOVE_NO_FLAGS * When no special flags is to be passed. * * @const VM_MAP_REMOVE_KUNWIRE * Unwire memory as a side effect. * * @const VM_MAP_REMOVE_INTERRUPTIBLE * Whether the call is interruptible if it needs to wait for a vm map * entry to quiesce (interruption leads to KERN_ABORTED). * * @const VM_MAP_REMOVE_NOKUNWIRE_LAST * Do not unwire the last page of this entry during remove. * (Used by kmem_realloc()). * * @const VM_MAP_REMOVE_IMMUTABLE * Allow permanent entries to be removed. * * @const VM_MAP_REMOVE_GAPS_FAIL * Return KERN_INVALID_VALUE when a gap is being removed instead of panicking. * * @const VM_MAP_REMOVE_NO_YIELD. * Try to avoid yielding during this call. * * @const VM_MAP_REMOVE_GUESS_SIZE * The caller doesn't know the precise size of the entry, * but the address must match an atomic entry. * * @const VM_MAP_REMOVE_IMMUTABLE_CODE * Allow executables entries to be removed (for VM_PROT_COPY), * which is used by debuggers. */ __options_decl(vmr_flags_t, uint32_t, { VM_MAP_REMOVE_NO_FLAGS = 0x000, VM_MAP_REMOVE_KUNWIRE = 0x001, VM_MAP_REMOVE_INTERRUPTIBLE = 0x002, VM_MAP_REMOVE_NOKUNWIRE_LAST = 0x004, VM_MAP_REMOVE_NO_MAP_ALIGN = 0x008, VM_MAP_REMOVE_IMMUTABLE = 0x010, VM_MAP_REMOVE_GAPS_FAIL = 0x020, VM_MAP_REMOVE_NO_YIELD = 0x040, VM_MAP_REMOVE_GUESS_SIZE = 0x080, VM_MAP_REMOVE_IMMUTABLE_CODE = 0x100, }); /* Deallocate a region */ extern kmem_return_t vm_map_remove_guard( vm_map_t map, vm_map_offset_t start, vm_map_offset_t end, vmr_flags_t flags, kmem_guard_t guard) __result_use_check; extern kmem_return_t vm_map_remove_and_unlock( vm_map_t map, vm_map_offset_t start, vm_map_offset_t end, vmr_flags_t flags, kmem_guard_t guard) __result_use_check; /* Deallocate a region */ static inline void vm_map_remove( vm_map_t map, vm_map_offset_t start, vm_map_offset_t end) { vmr_flags_t flags = VM_MAP_REMOVE_NO_FLAGS; kmem_guard_t guard = KMEM_GUARD_NONE; (void)vm_map_remove_guard(map, start, end, flags, guard); } extern bool kmem_is_ptr_range(vm_map_range_id_t range_id); extern mach_vm_range_t kmem_validate_range_for_overwrite( vm_map_offset_t addr, vm_map_size_t size); extern uint32_t kmem_addr_get_slot_idx( vm_map_offset_t start, vm_map_offset_t end, vm_map_range_id_t range_id, struct kmem_page_meta **meta, uint32_t *size_idx, mach_vm_range_t slot); extern void kmem_validate_slot( vm_map_offset_t addr, struct kmem_page_meta *meta, uint32_t size_idx, uint32_t slot_idx); /* * Function used to allocate VA from kmem pointer ranges */ extern kern_return_t kmem_locate_space( vm_map_size_t size, vm_map_range_id_t range_id, bool direction, vm_map_offset_t *start_inout, vm_map_entry_t *entry_out); /* * Function used to free VA to kmem pointer ranges */ extern void kmem_free_space( vm_map_offset_t start, vm_map_offset_t end, vm_map_range_id_t range_id, mach_vm_range_t slot); #pragma GCC visibility pop __END_DECLS #endif /* _VM_VM_MAP_INTERNAL_H_ */ |