1*2c2f96dcSApple OSS Distributions /* 2*2c2f96dcSApple OSS Distributions * Copyright (c) 2000-2018 Apple Inc. All rights reserved. 3*2c2f96dcSApple OSS Distributions * 4*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*2c2f96dcSApple OSS Distributions * 6*2c2f96dcSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*2c2f96dcSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*2c2f96dcSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*2c2f96dcSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*2c2f96dcSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*2c2f96dcSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*2c2f96dcSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*2c2f96dcSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*2c2f96dcSApple OSS Distributions * 15*2c2f96dcSApple OSS Distributions * Please obtain a copy of the License at 16*2c2f96dcSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*2c2f96dcSApple OSS Distributions * 18*2c2f96dcSApple OSS Distributions * The Original Code and all software distributed under the License are 19*2c2f96dcSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*2c2f96dcSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*2c2f96dcSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*2c2f96dcSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*2c2f96dcSApple OSS Distributions * Please see the License for the specific language governing rights and 24*2c2f96dcSApple OSS Distributions * limitations under the License. 25*2c2f96dcSApple OSS Distributions * 26*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*2c2f96dcSApple OSS Distributions */ 28*2c2f96dcSApple OSS Distributions /* 29*2c2f96dcSApple OSS Distributions * @OSF_COPYRIGHT@ 30*2c2f96dcSApple OSS Distributions * 31*2c2f96dcSApple OSS Distributions */ 32*2c2f96dcSApple OSS Distributions #ifndef _MACH_VM_TYPES_H_ 33*2c2f96dcSApple OSS Distributions #define _MACH_VM_TYPES_H_ 34*2c2f96dcSApple OSS Distributions 35*2c2f96dcSApple OSS Distributions #include <mach/port.h> 36*2c2f96dcSApple OSS Distributions #include <mach/machine/vm_types.h> 37*2c2f96dcSApple OSS Distributions 38*2c2f96dcSApple OSS Distributions #include <stdint.h> 39*2c2f96dcSApple OSS Distributions #include <sys/cdefs.h> 40*2c2f96dcSApple OSS Distributions 41*2c2f96dcSApple OSS Distributions __BEGIN_DECLS 42*2c2f96dcSApple OSS Distributions 43*2c2f96dcSApple OSS Distributions typedef vm_offset_t pointer_t __kernel_ptr_semantics; 44*2c2f96dcSApple OSS Distributions typedef vm_offset_t vm_address_t __kernel_ptr_semantics; 45*2c2f96dcSApple OSS Distributions 46*2c2f96dcSApple OSS Distributions /* 47*2c2f96dcSApple OSS Distributions * We use addr64_t for 64-bit addresses that are used on both 48*2c2f96dcSApple OSS Distributions * 32 and 64-bit machines. On PPC, they are passed and returned as 49*2c2f96dcSApple OSS Distributions * two adjacent 32-bit GPRs. We use addr64_t in places where 50*2c2f96dcSApple OSS Distributions * common code must be useable both on 32 and 64-bit machines. 51*2c2f96dcSApple OSS Distributions */ 52*2c2f96dcSApple OSS Distributions typedef uint64_t addr64_t; /* Basic effective address */ 53*2c2f96dcSApple OSS Distributions 54*2c2f96dcSApple OSS Distributions /* 55*2c2f96dcSApple OSS Distributions * We use reg64_t for addresses that are 32 bits on a 32-bit 56*2c2f96dcSApple OSS Distributions * machine, and 64 bits on a 64-bit machine, but are always 57*2c2f96dcSApple OSS Distributions * passed and returned in a single GPR on PPC. This type 58*2c2f96dcSApple OSS Distributions * cannot be used in generic 32-bit c, since on a 64-bit 59*2c2f96dcSApple OSS Distributions * machine the upper half of the register will be ignored 60*2c2f96dcSApple OSS Distributions * by the c compiler in 32-bit mode. In c, we can only use the 61*2c2f96dcSApple OSS Distributions * type in prototypes of functions that are written in and called 62*2c2f96dcSApple OSS Distributions * from assembly language. This type is basically a comment. 63*2c2f96dcSApple OSS Distributions */ 64*2c2f96dcSApple OSS Distributions typedef uint32_t reg64_t; 65*2c2f96dcSApple OSS Distributions 66*2c2f96dcSApple OSS Distributions /* 67*2c2f96dcSApple OSS Distributions * To minimize the use of 64-bit fields, we keep some physical 68*2c2f96dcSApple OSS Distributions * addresses (that are page aligned) as 32-bit page numbers. 69*2c2f96dcSApple OSS Distributions * This limits the physical address space to 16TB of RAM. 70*2c2f96dcSApple OSS Distributions */ 71*2c2f96dcSApple OSS Distributions typedef uint32_t ppnum_t __kernel_ptr_semantics; /* Physical page number */ 72*2c2f96dcSApple OSS Distributions #define PPNUM_MAX UINT32_MAX 73*2c2f96dcSApple OSS Distributions 74*2c2f96dcSApple OSS Distributions #ifdef KERNEL_PRIVATE 75*2c2f96dcSApple OSS Distributions 76*2c2f96dcSApple OSS Distributions __options_decl(vm_map_create_options_t, uint32_t, { 77*2c2f96dcSApple OSS Distributions VM_MAP_CREATE_DEFAULT = 0x00000000, 78*2c2f96dcSApple OSS Distributions VM_MAP_CREATE_PAGEABLE = 0x00000001, 79*2c2f96dcSApple OSS Distributions VM_MAP_CREATE_CORPSE_FOOTPRINT = 0x00000002, 80*2c2f96dcSApple OSS Distributions VM_MAP_CREATE_DISABLE_HOLELIST = 0x00000004, 81*2c2f96dcSApple OSS Distributions VM_MAP_CREATE_NEVER_FAULTS = 0x00000008, 82*2c2f96dcSApple OSS Distributions }); 83*2c2f96dcSApple OSS Distributions 84*2c2f96dcSApple OSS Distributions /* 85*2c2f96dcSApple OSS Distributions * Use specifically typed null structures for these in 86*2c2f96dcSApple OSS Distributions * other parts of the kernel to enable compiler warnings 87*2c2f96dcSApple OSS Distributions * about type mismatches, etc... Otherwise, these would 88*2c2f96dcSApple OSS Distributions * be void*. 89*2c2f96dcSApple OSS Distributions */ 90*2c2f96dcSApple OSS Distributions 91*2c2f96dcSApple OSS Distributions typedef struct pmap *pmap_t; 92*2c2f96dcSApple OSS Distributions typedef struct _vm_map *vm_map_t, *vm_map_read_t, *vm_map_inspect_t; 93*2c2f96dcSApple OSS Distributions typedef struct vm_object *vm_object_t; 94*2c2f96dcSApple OSS Distributions typedef struct vm_object_fault_info *vm_object_fault_info_t; 95*2c2f96dcSApple OSS Distributions typedef struct upl *upl_t; 96*2c2f96dcSApple OSS Distributions typedef struct vm_map_copy *vm_map_copy_t; 97*2c2f96dcSApple OSS Distributions typedef struct vm_named_entry *vm_named_entry_t; 98*2c2f96dcSApple OSS Distributions 99*2c2f96dcSApple OSS Distributions #define PMAP_NULL ((pmap_t) NULL) 100*2c2f96dcSApple OSS Distributions #define VM_OBJECT_NULL ((vm_object_t) NULL) 101*2c2f96dcSApple OSS Distributions #define VM_MAP_COPY_NULL ((vm_map_copy_t) NULL) 102*2c2f96dcSApple OSS Distributions 103*2c2f96dcSApple OSS Distributions #else /* KERNEL_PRIVATE */ 104*2c2f96dcSApple OSS Distributions 105*2c2f96dcSApple OSS Distributions typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 106*2c2f96dcSApple OSS Distributions typedef mach_port_t upl_t; 107*2c2f96dcSApple OSS Distributions typedef mach_port_t vm_named_entry_t; 108*2c2f96dcSApple OSS Distributions 109*2c2f96dcSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 110*2c2f96dcSApple OSS Distributions 111*2c2f96dcSApple OSS Distributions #ifdef KERNEL 112*2c2f96dcSApple OSS Distributions #define VM_MAP_NULL ((vm_map_t) NULL) 113*2c2f96dcSApple OSS Distributions #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) NULL) 114*2c2f96dcSApple OSS Distributions #define VM_MAP_READ_NULL ((vm_map_read_t) NULL) 115*2c2f96dcSApple OSS Distributions #define UPL_NULL ((upl_t) NULL) 116*2c2f96dcSApple OSS Distributions #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) NULL) 117*2c2f96dcSApple OSS Distributions #else 118*2c2f96dcSApple OSS Distributions #define VM_MAP_NULL ((vm_map_t) 0) 119*2c2f96dcSApple OSS Distributions #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) 120*2c2f96dcSApple OSS Distributions #define VM_MAP_READ_NULL ((vm_map_read_t) 0) 121*2c2f96dcSApple OSS Distributions #define UPL_NULL ((upl_t) 0) 122*2c2f96dcSApple OSS Distributions #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 123*2c2f96dcSApple OSS Distributions #endif 124*2c2f96dcSApple OSS Distributions 125*2c2f96dcSApple OSS Distributions /* 126*2c2f96dcSApple OSS Distributions * Evolving definitions, likely to change. 127*2c2f96dcSApple OSS Distributions */ 128*2c2f96dcSApple OSS Distributions 129*2c2f96dcSApple OSS Distributions typedef uint64_t vm_object_offset_t; 130*2c2f96dcSApple OSS Distributions typedef uint64_t vm_object_size_t; 131*2c2f96dcSApple OSS Distributions 132*2c2f96dcSApple OSS Distributions /*! 133*2c2f96dcSApple OSS Distributions * @typedef mach_vm_range_t 134*2c2f96dcSApple OSS Distributions * 135*2c2f96dcSApple OSS Distributions * @brief 136*2c2f96dcSApple OSS Distributions * Pair of a min/max address used to denote a memory region. 137*2c2f96dcSApple OSS Distributions * 138*2c2f96dcSApple OSS Distributions * @discussion 139*2c2f96dcSApple OSS Distributions * @c min_address must be smaller or equal to @c max_address. 140*2c2f96dcSApple OSS Distributions */ 141*2c2f96dcSApple OSS Distributions typedef struct mach_vm_range { 142*2c2f96dcSApple OSS Distributions mach_vm_offset_t min_address; 143*2c2f96dcSApple OSS Distributions mach_vm_offset_t max_address; 144*2c2f96dcSApple OSS Distributions } *mach_vm_range_t; 145*2c2f96dcSApple OSS Distributions 146*2c2f96dcSApple OSS Distributions /*! 147*2c2f96dcSApple OSS Distributions * @enum mach_vm_range_flavor_t 148*2c2f96dcSApple OSS Distributions * 149*2c2f96dcSApple OSS Distributions * @brief 150*2c2f96dcSApple OSS Distributions * A flavor for the mach_vm_range_create() call. 151*2c2f96dcSApple OSS Distributions * 152*2c2f96dcSApple OSS Distributions * @const MACH_VM_RANGE_FLAVOR_V1 153*2c2f96dcSApple OSS Distributions * The recipe is an array of @c mach_vm_range_recipe_v1_t. 154*2c2f96dcSApple OSS Distributions */ 155*2c2f96dcSApple OSS Distributions __enum_decl(mach_vm_range_flavor_t, uint32_t, { 156*2c2f96dcSApple OSS Distributions MACH_VM_RANGE_FLAVOR_INVALID, 157*2c2f96dcSApple OSS Distributions MACH_VM_RANGE_FLAVOR_V1, 158*2c2f96dcSApple OSS Distributions }); 159*2c2f96dcSApple OSS Distributions 160*2c2f96dcSApple OSS Distributions 161*2c2f96dcSApple OSS Distributions /*! 162*2c2f96dcSApple OSS Distributions * @enum mach_vm_range_flags_t 163*2c2f96dcSApple OSS Distributions * 164*2c2f96dcSApple OSS Distributions * @brief 165*2c2f96dcSApple OSS Distributions * Flags used to alter the behavior of a Mach VM Range. 166*2c2f96dcSApple OSS Distributions */ 167*2c2f96dcSApple OSS Distributions __options_decl(mach_vm_range_flags_t, uint64_t, { 168*2c2f96dcSApple OSS Distributions MACH_VM_RANGE_NONE = 0x000000000000, 169*2c2f96dcSApple OSS Distributions }); 170*2c2f96dcSApple OSS Distributions 171*2c2f96dcSApple OSS Distributions 172*2c2f96dcSApple OSS Distributions /*! 173*2c2f96dcSApple OSS Distributions * @enum mach_vm_range_tag_t 174*2c2f96dcSApple OSS Distributions * 175*2c2f96dcSApple OSS Distributions * @brief 176*2c2f96dcSApple OSS Distributions * A tag to denote the semantics of a given Mach VM Range. 177*2c2f96dcSApple OSS Distributions * 178*2c2f96dcSApple OSS Distributions * @const MACH_VM_RANGE_DEFAULT 179*2c2f96dcSApple OSS Distributions * The tag associated with the general VA space usable 180*2c2f96dcSApple OSS Distributions * before the shared cache. 181*2c2f96dcSApple OSS Distributions * Such a range can't be made by userspace. 182*2c2f96dcSApple OSS Distributions * 183*2c2f96dcSApple OSS Distributions * @const MACH_VM_RANGE_DATA 184*2c2f96dcSApple OSS Distributions * The tag associated with the anonymous randomly slid 185*2c2f96dcSApple OSS Distributions * range of data heap optionally made when a process is created. 186*2c2f96dcSApple OSS Distributions * Such a range can't be made by userspace. 187*2c2f96dcSApple OSS Distributions * 188*2c2f96dcSApple OSS Distributions * @const MACH_VM_RANGE_FIXED 189*2c2f96dcSApple OSS Distributions * The tag associated with ranges that are made available 190*2c2f96dcSApple OSS Distributions * for @c VM_FLAGS_FIXED allocations, but that the VM will never 191*2c2f96dcSApple OSS Distributions * autonomously serve from a @c VM_FLAGS_ANYWHERE kind of request. 192*2c2f96dcSApple OSS Distributions * This really create a delegated piece of VA that can be carved out 193*2c2f96dcSApple OSS Distributions * in the way userspace sees fit. 194*2c2f96dcSApple OSS Distributions */ 195*2c2f96dcSApple OSS Distributions __enum_decl(mach_vm_range_tag_t, uint16_t, { 196*2c2f96dcSApple OSS Distributions MACH_VM_RANGE_DEFAULT, 197*2c2f96dcSApple OSS Distributions MACH_VM_RANGE_DATA, 198*2c2f96dcSApple OSS Distributions MACH_VM_RANGE_FIXED, 199*2c2f96dcSApple OSS Distributions }); 200*2c2f96dcSApple OSS Distributions 201*2c2f96dcSApple OSS Distributions #pragma pack(1) 202*2c2f96dcSApple OSS Distributions 203*2c2f96dcSApple OSS Distributions typedef struct { 204*2c2f96dcSApple OSS Distributions mach_vm_range_flags_t flags: 48; 205*2c2f96dcSApple OSS Distributions mach_vm_range_tag_t range_tag : 8; 206*2c2f96dcSApple OSS Distributions uint8_t vm_tag : 8; 207*2c2f96dcSApple OSS Distributions struct mach_vm_range range; 208*2c2f96dcSApple OSS Distributions } mach_vm_range_recipe_v1_t; 209*2c2f96dcSApple OSS Distributions 210*2c2f96dcSApple OSS Distributions #pragma pack() 211*2c2f96dcSApple OSS Distributions 212*2c2f96dcSApple OSS Distributions #define MACH_VM_RANGE_FLAVOR_DEFAULT MACH_VM_RANGE_FLAVOR_V1 213*2c2f96dcSApple OSS Distributions typedef mach_vm_range_recipe_v1_t mach_vm_range_recipe_t; 214*2c2f96dcSApple OSS Distributions 215*2c2f96dcSApple OSS Distributions typedef uint8_t *mach_vm_range_recipes_raw_t; 216*2c2f96dcSApple OSS Distributions 217*2c2f96dcSApple OSS Distributions #ifdef PRIVATE 218*2c2f96dcSApple OSS Distributions 219*2c2f96dcSApple OSS Distributions typedef struct { 220*2c2f96dcSApple OSS Distributions uint64_t rtfabstime; // mach_continuous_time at start of fault 221*2c2f96dcSApple OSS Distributions uint64_t rtfduration; // fault service duration 222*2c2f96dcSApple OSS Distributions uint64_t rtfaddr; // fault address 223*2c2f96dcSApple OSS Distributions uint64_t rtfpc; // userspace program counter of thread incurring the fault 224*2c2f96dcSApple OSS Distributions uint64_t rtftid; // thread ID 225*2c2f96dcSApple OSS Distributions uint64_t rtfupid; // process identifier 226*2c2f96dcSApple OSS Distributions uint64_t rtftype; // fault type 227*2c2f96dcSApple OSS Distributions } vm_rtfault_record_t; 228*2c2f96dcSApple OSS Distributions 229*2c2f96dcSApple OSS Distributions #endif /* PRIVATE */ 230*2c2f96dcSApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 231*2c2f96dcSApple OSS Distributions 232*2c2f96dcSApple OSS Distributions #define VM_TAG_ACTIVE_UPDATE 1 233*2c2f96dcSApple OSS Distributions 234*2c2f96dcSApple OSS Distributions typedef uint16_t vm_tag_t; 235*2c2f96dcSApple OSS Distributions 236*2c2f96dcSApple OSS Distributions #define VM_TAG_NAME_LEN_MAX 0x7F 237*2c2f96dcSApple OSS Distributions #define VM_TAG_NAME_LEN_SHIFT 0 238*2c2f96dcSApple OSS Distributions #define VM_TAG_UNLOAD 0x0100 239*2c2f96dcSApple OSS Distributions #define VM_TAG_KMOD 0x0200 240*2c2f96dcSApple OSS Distributions 241*2c2f96dcSApple OSS Distributions #if !KASAN && (DEBUG || DEVELOPMENT) 242*2c2f96dcSApple OSS Distributions /* 243*2c2f96dcSApple OSS Distributions * To track the utilization of memory at every kalloc callsite, zone tagging 244*2c2f96dcSApple OSS Distributions * allocates an array of stats (of size VM_TAG_SIZECLASSES), one for each 245*2c2f96dcSApple OSS Distributions * size class exposed by kalloc. 246*2c2f96dcSApple OSS Distributions * 247*2c2f96dcSApple OSS Distributions * If VM_TAG_SIZECLASSES is modified ensure that z_tags_sizeclass 248*2c2f96dcSApple OSS Distributions * has sufficient bits to represent all values (max value exclusive). 249*2c2f96dcSApple OSS Distributions */ 250*2c2f96dcSApple OSS Distributions #define VM_TAG_SIZECLASSES 36 251*2c2f96dcSApple OSS Distributions // must be multiple of 64 252*2c2f96dcSApple OSS Distributions #define VM_MAX_TAG_VALUE 1536 253*2c2f96dcSApple OSS Distributions #else 254*2c2f96dcSApple OSS Distributions #define VM_TAG_SIZECLASSES 0 255*2c2f96dcSApple OSS Distributions #define VM_MAX_TAG_VALUE 256 256*2c2f96dcSApple OSS Distributions #endif 257*2c2f96dcSApple OSS Distributions 258*2c2f96dcSApple OSS Distributions #define ARRAY_COUNT(a) (sizeof((a)) / sizeof((a)[0])) 259*2c2f96dcSApple OSS Distributions 260*2c2f96dcSApple OSS Distributions struct vm_allocation_total { 261*2c2f96dcSApple OSS Distributions vm_tag_t tag; 262*2c2f96dcSApple OSS Distributions uint64_t total; 263*2c2f96dcSApple OSS Distributions }; 264*2c2f96dcSApple OSS Distributions 265*2c2f96dcSApple OSS Distributions struct vm_allocation_zone_total { 266*2c2f96dcSApple OSS Distributions vm_size_t vazt_total; 267*2c2f96dcSApple OSS Distributions vm_size_t vazt_peak; 268*2c2f96dcSApple OSS Distributions }; 269*2c2f96dcSApple OSS Distributions typedef struct vm_allocation_zone_total vm_allocation_zone_total_t; 270*2c2f96dcSApple OSS Distributions 271*2c2f96dcSApple OSS Distributions struct vm_allocation_site { 272*2c2f96dcSApple OSS Distributions uint64_t total; 273*2c2f96dcSApple OSS Distributions #if DEBUG || DEVELOPMENT 274*2c2f96dcSApple OSS Distributions uint64_t peak; 275*2c2f96dcSApple OSS Distributions #endif /* DEBUG || DEVELOPMENT */ 276*2c2f96dcSApple OSS Distributions uint64_t mapped; 277*2c2f96dcSApple OSS Distributions int16_t refcount; 278*2c2f96dcSApple OSS Distributions vm_tag_t tag; 279*2c2f96dcSApple OSS Distributions uint16_t flags; 280*2c2f96dcSApple OSS Distributions uint16_t subtotalscount; 281*2c2f96dcSApple OSS Distributions struct vm_allocation_total subtotals[0]; 282*2c2f96dcSApple OSS Distributions /* char name[0]; -- this is placed after subtotals, see KA_NAME() */ 283*2c2f96dcSApple OSS Distributions }; 284*2c2f96dcSApple OSS Distributions typedef struct vm_allocation_site vm_allocation_site_t; 285*2c2f96dcSApple OSS Distributions 286*2c2f96dcSApple OSS Distributions extern int vmrtf_extract(uint64_t, boolean_t, unsigned long, void *, unsigned long *); 287*2c2f96dcSApple OSS Distributions extern unsigned int vmrtfaultinfo_bufsz(void); 288*2c2f96dcSApple OSS Distributions 289*2c2f96dcSApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 290*2c2f96dcSApple OSS Distributions 291*2c2f96dcSApple OSS Distributions __END_DECLS 292*2c2f96dcSApple OSS Distributions 293*2c2f96dcSApple OSS Distributions #endif /* _MACH_VM_TYPES_H_ */ 294