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 #ifndef MACH_KERNEL_PRIVATE 76 /* 77 * Use specifically typed null structures for these in 78 * other parts of the kernel to enable compiler warnings 79 * about type mismatches, etc... Otherwise, these would 80 * be void*. 81 */ 82 __BEGIN_DECLS 83 84 struct pmap; 85 struct _vm_map; 86 struct vm_object; 87 88 __END_DECLS 89 90 #endif /* MACH_KERNEL_PRIVATE */ 91 92 typedef struct pmap *pmap_t; 93 typedef struct _vm_map *vm_map_t, *vm_map_read_t, *vm_map_inspect_t; 94 typedef struct vm_object *vm_object_t; 95 typedef struct vm_object_fault_info *vm_object_fault_info_t; 96 97 #define PMAP_NULL ((pmap_t) NULL) 98 #define VM_OBJECT_NULL ((vm_object_t) NULL) 99 100 #else /* KERNEL_PRIVATE */ 101 102 typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 103 104 #endif /* KERNEL_PRIVATE */ 105 106 #ifdef KERNEL 107 #define VM_MAP_NULL ((vm_map_t) NULL) 108 #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) NULL) 109 #define VM_MAP_READ_NULL ((vm_map_read_t) NULL) 110 #else 111 #define VM_MAP_NULL ((vm_map_t) 0) 112 #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) 113 #define VM_MAP_READ_NULL ((vm_map_read_t) 0) 114 #endif 115 116 /* 117 * Evolving definitions, likely to change. 118 */ 119 120 typedef uint64_t vm_object_offset_t; 121 typedef uint64_t vm_object_size_t; 122 123 124 #ifdef XNU_KERNEL_PRIVATE 125 126 #define VM_TAG_ACTIVE_UPDATE 1 127 128 typedef uint16_t vm_tag_t; 129 130 #define VM_TAG_NAME_LEN_MAX 0x7F 131 #define VM_TAG_NAME_LEN_SHIFT 0 132 #define VM_TAG_BT 0x0080 133 #define VM_TAG_UNLOAD 0x0100 134 #define VM_TAG_KMOD 0x0200 135 136 #if !KASAN && (DEBUG || DEVELOPMENT) 137 /* 138 * To track the utilization of memory at every kalloc callsite, zone tagging 139 * allocates an array of stats (of size VM_TAG_SIZECLASSES), one for each 140 * size class exposed by kalloc. 141 * 142 * If VM_TAG_SIZECLASSES is modified ensure that z_tags_sizeclass 143 * has sufficient bits to represent all values (max value exclusive). 144 */ 145 #define VM_TAG_SIZECLASSES 32 146 #else 147 #define VM_TAG_SIZECLASSES 0 148 #endif 149 150 #if VM_TAG_SIZECLASSES 151 // must be multiple of 64 152 #define VM_MAX_TAG_VALUE 1536 153 #else 154 #define VM_MAX_TAG_VALUE 256 155 #endif 156 157 158 #define ARRAY_COUNT(a) (sizeof((a)) / sizeof((a)[0])) 159 160 struct vm_allocation_total { 161 vm_tag_t tag; 162 uint64_t total; 163 }; 164 165 struct vm_allocation_zone_total { 166 vm_size_t vazt_total; 167 vm_size_t vazt_peak; 168 }; 169 typedef struct vm_allocation_zone_total vm_allocation_zone_total_t; 170 171 struct vm_allocation_site { 172 uint64_t total; 173 #if DEBUG || DEVELOPMENT 174 uint64_t peak; 175 #endif /* DEBUG || DEVELOPMENT */ 176 uint64_t mapped; 177 int16_t refcount; 178 vm_tag_t tag; 179 uint16_t flags; 180 uint16_t subtotalscount; 181 struct vm_allocation_total subtotals[0]; 182 /* char name[0]; -- this is placed after subtotals, see KA_NAME() */ 183 }; 184 typedef struct vm_allocation_site vm_allocation_site_t; 185 186 #define VM_ALLOC_SITE_STATIC(iflags, itag) \ 187 static vm_allocation_site_t site __attribute__((section("__DATA, __data"))) \ 188 = { .refcount = 2, .tag = (itag), .flags = (iflags) }; 189 190 extern int vmrtf_extract(uint64_t, boolean_t, unsigned long, void *, unsigned long *); 191 extern unsigned int vmrtfaultinfo_bufsz(void); 192 193 #endif /* XNU_KERNEL_PRIVATE */ 194 195 #ifdef KERNEL_PRIVATE 196 197 #ifndef MACH_KERNEL_PRIVATE 198 199 __BEGIN_DECLS 200 201 struct upl; 202 struct vm_map_copy; 203 struct vm_named_entry; 204 205 __END_DECLS 206 207 #endif /* MACH_KERNEL_PRIVATE */ 208 209 typedef struct upl *upl_t; 210 typedef struct vm_map_copy *vm_map_copy_t; 211 typedef struct vm_named_entry *vm_named_entry_t; 212 213 #define VM_MAP_COPY_NULL ((vm_map_copy_t) NULL) 214 215 #else /* KERNEL_PRIVATE */ 216 217 typedef mach_port_t upl_t; 218 typedef mach_port_t vm_named_entry_t; 219 220 #endif /* KERNEL_PRIVATE */ 221 222 #ifdef KERNEL 223 #define UPL_NULL ((upl_t) NULL) 224 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) NULL) 225 #else 226 #define UPL_NULL ((upl_t) 0) 227 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 228 #endif 229 230 #ifdef PRIVATE 231 typedef struct { 232 uint64_t rtfabstime; // mach_continuous_time at start of fault 233 uint64_t rtfduration; // fault service duration 234 uint64_t rtfaddr; // fault address 235 uint64_t rtfpc; // userspace program counter of thread incurring the fault 236 uint64_t rtftid; // thread ID 237 uint64_t rtfupid; // process identifier 238 uint64_t rtftype; // fault type 239 } vm_rtfault_record_t; 240 #endif 241 #endif /* _MACH_VM_TYPES_H_ */ 242