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 }); 83 84 /* 85 * Use specifically typed null structures for these in 86 * other parts of the kernel to enable compiler warnings 87 * about type mismatches, etc... Otherwise, these would 88 * be void*. 89 */ 90 91 typedef struct pmap *pmap_t; 92 typedef struct _vm_map *vm_map_t, *vm_map_read_t, *vm_map_inspect_t; 93 typedef struct vm_object *vm_object_t; 94 typedef struct vm_object_fault_info *vm_object_fault_info_t; 95 typedef struct upl *upl_t; 96 typedef struct vm_map_copy *vm_map_copy_t; 97 typedef struct vm_named_entry *vm_named_entry_t; 98 typedef struct vm_page *vm_page_t; 99 100 #define PMAP_NULL ((pmap_t) NULL) 101 #define VM_OBJECT_NULL ((vm_object_t) NULL) 102 #define VM_MAP_COPY_NULL ((vm_map_copy_t) NULL) 103 104 #else /* KERNEL_PRIVATE */ 105 106 typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 107 typedef mach_port_t upl_t; 108 typedef mach_port_t vm_named_entry_t; 109 110 #endif /* KERNEL_PRIVATE */ 111 112 #ifdef KERNEL 113 #define VM_MAP_NULL ((vm_map_t) NULL) 114 #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) NULL) 115 #define VM_MAP_READ_NULL ((vm_map_read_t) NULL) 116 #define UPL_NULL ((upl_t) NULL) 117 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) NULL) 118 #else 119 #define VM_MAP_NULL ((vm_map_t) 0) 120 #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) 121 #define VM_MAP_READ_NULL ((vm_map_read_t) 0) 122 #define UPL_NULL ((upl_t) 0) 123 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 124 #endif 125 126 /* 127 * Evolving definitions, likely to change. 128 */ 129 130 typedef uint64_t vm_object_offset_t; 131 typedef uint64_t vm_object_size_t; 132 133 /*! 134 * @typedef mach_vm_range_t 135 * 136 * @brief 137 * Pair of a min/max address used to denote a memory region. 138 * 139 * @discussion 140 * @c min_address must be smaller or equal to @c max_address. 141 */ 142 typedef struct mach_vm_range { 143 mach_vm_offset_t min_address; 144 mach_vm_offset_t max_address; 145 } *mach_vm_range_t; 146 147 /*! 148 * @enum mach_vm_range_flavor_t 149 * 150 * @brief 151 * A flavor for the mach_vm_range_create() call. 152 * 153 * @const MACH_VM_RANGE_FLAVOR_V1 154 * The recipe is an array of @c mach_vm_range_recipe_v1_t. 155 */ 156 __enum_decl(mach_vm_range_flavor_t, uint32_t, { 157 MACH_VM_RANGE_FLAVOR_INVALID, 158 MACH_VM_RANGE_FLAVOR_V1, 159 }); 160 161 162 /*! 163 * @enum mach_vm_range_flags_t 164 * 165 * @brief 166 * Flags used to alter the behavior of a Mach VM Range. 167 */ 168 __options_decl(mach_vm_range_flags_t, uint64_t, { 169 MACH_VM_RANGE_NONE = 0x000000000000, 170 }); 171 172 173 /*! 174 * @enum mach_vm_range_tag_t 175 * 176 * @brief 177 * A tag to denote the semantics of a given Mach VM Range. 178 * 179 * @const MACH_VM_RANGE_DEFAULT 180 * The tag associated with the general VA space usable 181 * before the shared cache. 182 * Such a range can't be made by userspace. 183 * 184 * @const MACH_VM_RANGE_DATA 185 * The tag associated with the anonymous randomly slid 186 * range of data heap optionally made when a process is created. 187 * Such a range can't be made by userspace. 188 * 189 * @const MACH_VM_RANGE_FIXED 190 * The tag associated with ranges that are made available 191 * for @c VM_FLAGS_FIXED allocations, but that the VM will never 192 * autonomously serve from a @c VM_FLAGS_ANYWHERE kind of request. 193 * This really create a delegated piece of VA that can be carved out 194 * in the way userspace sees fit. 195 */ 196 __enum_decl(mach_vm_range_tag_t, uint16_t, { 197 MACH_VM_RANGE_DEFAULT, 198 MACH_VM_RANGE_DATA, 199 MACH_VM_RANGE_FIXED, 200 }); 201 202 #pragma pack(1) 203 204 typedef struct { 205 mach_vm_range_flags_t flags: 48; 206 mach_vm_range_tag_t range_tag : 8; 207 uint8_t vm_tag : 8; 208 struct mach_vm_range range; 209 } mach_vm_range_recipe_v1_t; 210 211 #pragma pack() 212 213 #define MACH_VM_RANGE_FLAVOR_DEFAULT MACH_VM_RANGE_FLAVOR_V1 214 typedef mach_vm_range_recipe_v1_t mach_vm_range_recipe_t; 215 216 typedef uint8_t *mach_vm_range_recipes_raw_t; 217 218 #ifdef PRIVATE 219 220 typedef struct { 221 uint64_t rtfabstime; // mach_continuous_time at start of fault 222 uint64_t rtfduration; // fault service duration 223 uint64_t rtfaddr; // fault address 224 uint64_t rtfpc; // userspace program counter of thread incurring the fault 225 uint64_t rtftid; // thread ID 226 uint64_t rtfupid; // process identifier 227 uint64_t rtftype; // fault type 228 } vm_rtfault_record_t; 229 230 #endif /* PRIVATE */ 231 #ifdef XNU_KERNEL_PRIVATE 232 233 #define VM_TAG_ACTIVE_UPDATE 1 234 235 typedef uint16_t vm_tag_t; 236 237 #define VM_TAG_NAME_LEN_MAX 0x7F 238 #define VM_TAG_NAME_LEN_SHIFT 0 239 #define VM_TAG_UNLOAD 0x0100 240 #define VM_TAG_KMOD 0x0200 241 242 #if !KASAN && (DEBUG || DEVELOPMENT) 243 /* 244 * To track the utilization of memory at every kalloc callsite, zone tagging 245 * allocates an array of stats (of size VM_TAG_SIZECLASSES), one for each 246 * size class exposed by kalloc. 247 * 248 * If VM_TAG_SIZECLASSES is modified ensure that z_tags_sizeclass 249 * has sufficient bits to represent all values (max value exclusive). 250 */ 251 #define VM_TAG_SIZECLASSES 36 252 // must be multiple of 64 253 #define VM_MAX_TAG_VALUE 1536 254 #else 255 #define VM_TAG_SIZECLASSES 0 256 #define VM_MAX_TAG_VALUE 256 257 #endif 258 259 #define ARRAY_COUNT(a) (sizeof((a)) / sizeof((a)[0])) 260 261 struct vm_allocation_total { 262 vm_tag_t tag; 263 uint64_t total; 264 }; 265 266 struct vm_allocation_zone_total { 267 vm_size_t vazt_total; 268 vm_size_t vazt_peak; 269 }; 270 typedef struct vm_allocation_zone_total vm_allocation_zone_total_t; 271 272 struct vm_allocation_site { 273 uint64_t total; 274 #if DEBUG || DEVELOPMENT 275 uint64_t peak; 276 #endif /* DEBUG || DEVELOPMENT */ 277 uint64_t mapped; 278 int16_t refcount; 279 vm_tag_t tag; 280 uint16_t flags; 281 uint16_t subtotalscount; 282 struct vm_allocation_total subtotals[0]; 283 /* char name[0]; -- this is placed after subtotals, see KA_NAME() */ 284 }; 285 typedef struct vm_allocation_site vm_allocation_site_t; 286 287 extern int vmrtf_extract(uint64_t, boolean_t, unsigned long, void *, unsigned long *); 288 extern unsigned int vmrtfaultinfo_bufsz(void); 289 290 #endif /* XNU_KERNEL_PRIVATE */ 291 292 __END_DECLS 293 294 #endif /* _MACH_VM_TYPES_H_ */ 295