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 typedef vm_offset_t pointer_t __kernel_ptr_semantics; 42 typedef vm_offset_t vm_address_t __kernel_ptr_semantics; 43 44 /* 45 * We use addr64_t for 64-bit addresses that are used on both 46 * 32 and 64-bit machines. On PPC, they are passed and returned as 47 * two adjacent 32-bit GPRs. We use addr64_t in places where 48 * common code must be useable both on 32 and 64-bit machines. 49 */ 50 typedef uint64_t addr64_t; /* Basic effective address */ 51 52 /* 53 * We use reg64_t for addresses that are 32 bits on a 32-bit 54 * machine, and 64 bits on a 64-bit machine, but are always 55 * passed and returned in a single GPR on PPC. This type 56 * cannot be used in generic 32-bit c, since on a 64-bit 57 * machine the upper half of the register will be ignored 58 * by the c compiler in 32-bit mode. In c, we can only use the 59 * type in prototypes of functions that are written in and called 60 * from assembly language. This type is basically a comment. 61 */ 62 typedef uint32_t reg64_t; 63 64 /* 65 * To minimize the use of 64-bit fields, we keep some physical 66 * addresses (that are page aligned) as 32-bit page numbers. 67 * This limits the physical address space to 16TB of RAM. 68 */ 69 typedef uint32_t ppnum_t; /* Physical page number */ 70 #define PPNUM_MAX UINT32_MAX 71 72 73 #ifdef KERNEL_PRIVATE 74 75 __options_decl(vm_map_create_options_t, uint32_t, { 76 VM_MAP_CREATE_DEFAULT = 0x00000000, 77 VM_MAP_CREATE_PAGEABLE = 0x00000001, 78 VM_MAP_CREATE_CORPSE_FOOTPRINT = 0x00000002, 79 VM_MAP_CREATE_DISABLE_HOLELIST = 0x00000004, 80 VM_MAP_CREATE_NEVER_FAULTS = 0x00000008, 81 }); 82 83 #ifndef MACH_KERNEL_PRIVATE 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 __BEGIN_DECLS 91 92 struct pmap; 93 struct _vm_map; 94 struct vm_object; 95 96 __END_DECLS 97 98 #endif /* MACH_KERNEL_PRIVATE */ 99 100 typedef struct pmap *pmap_t; 101 typedef struct _vm_map *vm_map_t, *vm_map_read_t, *vm_map_inspect_t; 102 typedef struct vm_object *vm_object_t; 103 typedef struct vm_object_fault_info *vm_object_fault_info_t; 104 105 #define PMAP_NULL ((pmap_t) NULL) 106 #define VM_OBJECT_NULL ((vm_object_t) NULL) 107 108 #else /* KERNEL_PRIVATE */ 109 110 typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 111 112 #endif /* KERNEL_PRIVATE */ 113 114 #ifdef KERNEL 115 #define VM_MAP_NULL ((vm_map_t) NULL) 116 #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) NULL) 117 #define VM_MAP_READ_NULL ((vm_map_read_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 #endif 123 124 /* 125 * Evolving definitions, likely to change. 126 */ 127 128 typedef uint64_t vm_object_offset_t; 129 typedef uint64_t vm_object_size_t; 130 131 132 #ifdef XNU_KERNEL_PRIVATE 133 134 #define VM_TAG_ACTIVE_UPDATE 1 135 136 typedef uint16_t vm_tag_t; 137 138 #define VM_TAG_NAME_LEN_MAX 0x7F 139 #define VM_TAG_NAME_LEN_SHIFT 0 140 #define VM_TAG_UNLOAD 0x0100 141 #define VM_TAG_KMOD 0x0200 142 143 #if !KASAN && (DEBUG || DEVELOPMENT) 144 /* 145 * To track the utilization of memory at every kalloc callsite, zone tagging 146 * allocates an array of stats (of size VM_TAG_SIZECLASSES), one for each 147 * size class exposed by kalloc. 148 * 149 * If VM_TAG_SIZECLASSES is modified ensure that z_tags_sizeclass 150 * has sufficient bits to represent all values (max value exclusive). 151 */ 152 #define VM_TAG_SIZECLASSES 36 153 #else 154 #define VM_TAG_SIZECLASSES 0 155 #endif 156 157 #if VM_TAG_SIZECLASSES 158 // must be multiple of 64 159 #define VM_MAX_TAG_VALUE 1536 160 #else 161 #define VM_MAX_TAG_VALUE 256 162 #endif 163 164 165 #define ARRAY_COUNT(a) (sizeof((a)) / sizeof((a)[0])) 166 167 struct vm_allocation_total { 168 vm_tag_t tag; 169 uint64_t total; 170 }; 171 172 struct vm_allocation_zone_total { 173 vm_size_t vazt_total; 174 vm_size_t vazt_peak; 175 }; 176 typedef struct vm_allocation_zone_total vm_allocation_zone_total_t; 177 178 struct vm_allocation_site { 179 uint64_t total; 180 #if DEBUG || DEVELOPMENT 181 uint64_t peak; 182 #endif /* DEBUG || DEVELOPMENT */ 183 uint64_t mapped; 184 int16_t refcount; 185 vm_tag_t tag; 186 uint16_t flags; 187 uint16_t subtotalscount; 188 struct vm_allocation_total subtotals[0]; 189 /* char name[0]; -- this is placed after subtotals, see KA_NAME() */ 190 }; 191 typedef struct vm_allocation_site vm_allocation_site_t; 192 193 extern int vmrtf_extract(uint64_t, boolean_t, unsigned long, void *, unsigned long *); 194 extern unsigned int vmrtfaultinfo_bufsz(void); 195 196 #endif /* XNU_KERNEL_PRIVATE */ 197 198 #ifdef KERNEL_PRIVATE 199 200 #ifndef MACH_KERNEL_PRIVATE 201 202 __BEGIN_DECLS 203 204 struct upl; 205 struct vm_map_copy; 206 struct vm_named_entry; 207 208 __END_DECLS 209 210 #endif /* MACH_KERNEL_PRIVATE */ 211 212 typedef struct upl *upl_t; 213 typedef struct vm_map_copy *vm_map_copy_t; 214 typedef struct vm_named_entry *vm_named_entry_t; 215 216 #define VM_MAP_COPY_NULL ((vm_map_copy_t) NULL) 217 218 #else /* KERNEL_PRIVATE */ 219 220 typedef mach_port_t upl_t; 221 typedef mach_port_t vm_named_entry_t; 222 223 #endif /* KERNEL_PRIVATE */ 224 225 #ifdef KERNEL 226 #define UPL_NULL ((upl_t) NULL) 227 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) NULL) 228 #else 229 #define UPL_NULL ((upl_t) 0) 230 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 231 #endif 232 233 #ifdef PRIVATE 234 typedef struct { 235 uint64_t rtfabstime; // mach_continuous_time at start of fault 236 uint64_t rtfduration; // fault service duration 237 uint64_t rtfaddr; // fault address 238 uint64_t rtfpc; // userspace program counter of thread incurring the fault 239 uint64_t rtftid; // thread ID 240 uint64_t rtfupid; // process identifier 241 uint64_t rtftype; // fault type 242 } vm_rtfault_record_t; 243 #endif 244 #endif /* _MACH_VM_TYPES_H_ */ 245