1 /* 2 * Copyright (c) 2000-2018 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 * @OSF_COPYRIGHT@ 30 * 31 */ 32 #ifndef _MACH_VM_TYPES_H_ 33 #define _MACH_VM_TYPES_H_ 34 35 #include <mach/port.h> 36 #include <mach/machine/vm_types.h> 37 38 #include <stdint.h> 39 #include <sys/cdefs.h> 40 41 __BEGIN_DECLS 42 43 typedef vm_offset_t pointer_t __kernel_ptr_semantics; 44 typedef vm_offset_t vm_address_t __kernel_ptr_semantics; 45 46 /* 47 * We use addr64_t for 64-bit addresses that are used on both 48 * 32 and 64-bit machines. On PPC, they are passed and returned as 49 * two adjacent 32-bit GPRs. We use addr64_t in places where 50 * common code must be useable both on 32 and 64-bit machines. 51 */ 52 typedef uint64_t addr64_t; /* Basic effective address */ 53 54 /* 55 * We use reg64_t for addresses that are 32 bits on a 32-bit 56 * machine, and 64 bits on a 64-bit machine, but are always 57 * passed and returned in a single GPR on PPC. This type 58 * cannot be used in generic 32-bit c, since on a 64-bit 59 * machine the upper half of the register will be ignored 60 * by the c compiler in 32-bit mode. In c, we can only use the 61 * type in prototypes of functions that are written in and called 62 * from assembly language. This type is basically a comment. 63 */ 64 typedef uint32_t reg64_t; 65 66 /* 67 * To minimize the use of 64-bit fields, we keep some physical 68 * addresses (that are page aligned) as 32-bit page numbers. 69 * This limits the physical address space to 16TB of RAM. 70 */ 71 typedef uint32_t ppnum_t __kernel_ptr_semantics; /* Physical page number */ 72 #define PPNUM_MAX UINT32_MAX 73 74 #ifdef KERNEL_PRIVATE 75 76 __options_decl(vm_map_create_options_t, uint32_t, { 77 VM_MAP_CREATE_DEFAULT = 0x00000000, 78 VM_MAP_CREATE_PAGEABLE = 0x00000001, 79 VM_MAP_CREATE_CORPSE_FOOTPRINT = 0x00000002, 80 VM_MAP_CREATE_DISABLE_HOLELIST = 0x00000004, 81 VM_MAP_CREATE_NEVER_FAULTS = 0x00000008, 82 /* Denote that we're creating this map as part of a fork() */ 83 VM_MAP_CREATE_VIA_FORK = 0x00000010, 84 }); 85 86 /* 87 * Use specifically typed null structures for these in 88 * other parts of the kernel to enable compiler warnings 89 * about type mismatches, etc... Otherwise, these would 90 * be void*. 91 */ 92 93 typedef struct pmap *pmap_t; 94 typedef struct _vm_map *vm_map_t, *vm_map_read_t, *vm_map_inspect_t; 95 typedef struct vm_object *vm_object_t; 96 typedef struct vm_object_fault_info *vm_object_fault_info_t; 97 typedef struct upl *upl_t; 98 typedef struct vm_map_copy *vm_map_copy_t; 99 typedef struct vm_named_entry *vm_named_entry_t; 100 typedef struct vm_page *vm_page_t; 101 /* 102 * A generation ID for vm_maps, which increments monotonically. 103 * These IDs are not globally unique among VM maps, however. Instead, 104 * IDs represent 'independent' VM map lineages: maps interrelated via 105 * fork() identify with the same ID. 106 */ 107 typedef const void *vm_map_serial_t; 108 109 #define PMAP_NULL ((pmap_t) NULL) 110 #define VM_OBJECT_NULL ((vm_object_t) NULL) 111 #define VM_MAP_COPY_NULL ((vm_map_copy_t) NULL) 112 113 #define VM_MAP_SERIAL_NONE ((vm_map_serial_t)-1) 114 /* Denotes 'special'/one-off kernel-managed objects that don't belong to a parent map */ 115 #define VM_MAP_SERIAL_SPECIAL ((vm_map_serial_t)-2) 116 117 #else /* KERNEL_PRIVATE */ 118 119 typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 120 typedef mach_port_t upl_t; 121 typedef mach_port_t vm_named_entry_t; 122 123 #endif /* KERNEL_PRIVATE */ 124 125 typedef mach_vm_offset_t *mach_vm_offset_list_t; 126 127 #ifdef KERNEL 128 #define VM_MAP_NULL ((vm_map_t) NULL) 129 #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) NULL) 130 #define VM_MAP_READ_NULL ((vm_map_read_t) NULL) 131 #define UPL_NULL ((upl_t) NULL) 132 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) NULL) 133 #else 134 #define VM_MAP_NULL ((vm_map_t) 0) 135 #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) 136 #define VM_MAP_READ_NULL ((vm_map_read_t) 0) 137 #define UPL_NULL ((upl_t) 0) 138 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 139 #endif 140 141 /* 142 * Evolving definitions, likely to change. 143 */ 144 145 typedef uint64_t vm_object_offset_t; 146 typedef uint64_t vm_object_size_t; 147 148 /*! 149 * @typedef mach_vm_range_t 150 * 151 * @brief 152 * Pair of a min/max address used to denote a memory region. 153 * 154 * @discussion 155 * @c min_address must be smaller or equal to @c max_address. 156 */ 157 typedef struct mach_vm_range { 158 mach_vm_offset_t min_address; 159 mach_vm_offset_t max_address; 160 } *mach_vm_range_t; 161 162 /*! 163 * @enum mach_vm_range_flavor_t 164 * 165 * @brief 166 * A flavor for the mach_vm_range_create() call. 167 * 168 * @const MACH_VM_RANGE_FLAVOR_V1 169 * The recipe is an array of @c mach_vm_range_recipe_v1_t. 170 */ 171 __enum_decl(mach_vm_range_flavor_t, uint32_t, { 172 MACH_VM_RANGE_FLAVOR_INVALID, 173 MACH_VM_RANGE_FLAVOR_V1, 174 }); 175 176 177 /*! 178 * @enum mach_vm_range_flags_t 179 * 180 * @brief 181 * Flags used to alter the behavior of a Mach VM Range. 182 */ 183 __options_decl(mach_vm_range_flags_t, uint64_t, { 184 MACH_VM_RANGE_NONE = 0x000000000000, 185 }); 186 187 188 /*! 189 * @enum mach_vm_range_tag_t 190 * 191 * @brief 192 * A tag to denote the semantics of a given Mach VM Range. 193 * 194 * @const MACH_VM_RANGE_DEFAULT 195 * The tag associated with the general VA space usable 196 * before the shared cache. 197 * Such a range can't be made by userspace. 198 * 199 * @const MACH_VM_RANGE_DATA 200 * The tag associated with the anonymous randomly slid 201 * range of data heap optionally made when a process is created. 202 * Such a range can't be made by userspace. 203 * 204 * @const MACH_VM_RANGE_FIXED 205 * The tag associated with ranges that are made available 206 * for @c VM_FLAGS_FIXED allocations, but that the VM will never 207 * autonomously serve from a @c VM_FLAGS_ANYWHERE kind of request. 208 * This really create a delegated piece of VA that can be carved out 209 * in the way userspace sees fit. 210 */ 211 __enum_decl(mach_vm_range_tag_t, uint16_t, { 212 MACH_VM_RANGE_DEFAULT, 213 MACH_VM_RANGE_DATA, 214 MACH_VM_RANGE_FIXED, 215 }); 216 217 #pragma pack(1) 218 219 typedef struct { 220 mach_vm_range_flags_t flags: 48; 221 mach_vm_range_tag_t range_tag : 8; 222 uint8_t vm_tag : 8; 223 struct mach_vm_range range; 224 } mach_vm_range_recipe_v1_t; 225 226 #pragma pack() 227 228 #define MACH_VM_RANGE_FLAVOR_DEFAULT MACH_VM_RANGE_FLAVOR_V1 229 typedef mach_vm_range_recipe_v1_t mach_vm_range_recipe_t; 230 231 typedef uint8_t *mach_vm_range_recipes_raw_t; 232 233 #ifdef PRIVATE 234 235 typedef struct { 236 uint64_t rtfabstime; // mach_continuous_time at start of fault 237 uint64_t rtfduration; // fault service duration 238 uint64_t rtfaddr; // fault address 239 uint64_t rtfpc; // userspace program counter of thread incurring the fault 240 uint64_t rtftid; // thread ID 241 uint64_t rtfupid; // process identifier 242 uint64_t rtftype; // fault type 243 } vm_rtfault_record_t; 244 245 #endif /* PRIVATE */ 246 #ifdef XNU_KERNEL_PRIVATE 247 248 #define VM_TAG_ACTIVE_UPDATE 1 249 250 typedef uint16_t vm_tag_t; 251 252 #define VM_TAG_NAME_LEN_MAX 0x7F 253 #define VM_TAG_NAME_LEN_SHIFT 0 254 #define VM_TAG_UNLOAD 0x0100 255 #define VM_TAG_KMOD 0x0200 256 257 #if !KASAN && (DEBUG || DEVELOPMENT) 258 /* 259 * To track the utilization of memory at every kalloc callsite, zone tagging 260 * allocates an array of stats (of size VM_TAG_SIZECLASSES), one for each 261 * size class exposed by kalloc. 262 * 263 * If VM_TAG_SIZECLASSES is modified ensure that z_tags_sizeclass 264 * has sufficient bits to represent all values (max value exclusive). 265 */ 266 #define VM_TAG_SIZECLASSES 36 267 // must be multiple of 64 268 #define VM_MAX_TAG_VALUE 1536 269 #else 270 #define VM_TAG_SIZECLASSES 0 271 #define VM_MAX_TAG_VALUE 256 272 #endif 273 274 #define ARRAY_COUNT(a) (sizeof((a)) / sizeof((a)[0])) 275 276 struct vm_allocation_total { 277 vm_tag_t tag; 278 uint64_t total; 279 }; 280 281 struct vm_allocation_zone_total { 282 vm_size_t vazt_total; 283 vm_size_t vazt_peak; 284 }; 285 typedef struct vm_allocation_zone_total vm_allocation_zone_total_t; 286 287 struct vm_allocation_site { 288 uint64_t total; 289 #if DEBUG || DEVELOPMENT 290 uint64_t peak; 291 #endif /* DEBUG || DEVELOPMENT */ 292 uint64_t mapped; 293 int16_t refcount; 294 vm_tag_t tag; 295 uint16_t flags; 296 uint16_t subtotalscount; 297 struct vm_allocation_total subtotals[0]; 298 /* char name[0]; -- this is placed after subtotals, see KA_NAME() */ 299 }; 300 typedef struct vm_allocation_site vm_allocation_site_t; 301 302 extern int vmrtf_extract(uint64_t, boolean_t, unsigned long, void *, unsigned long *); 303 extern unsigned int vmrtfaultinfo_bufsz(void); 304 305 #endif /* XNU_KERNEL_PRIVATE */ 306 307 __END_DECLS 308 309 #endif /* _MACH_VM_TYPES_H_ */ 310