| 1 | /* |
| 2 | * Copyright (c) 2000-2020 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 | * Mach Operating System |
| 33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University |
| 34 | * All Rights Reserved. |
| 35 | * |
| 36 | * Permission to use, copy, modify and distribute this software and its |
| 37 | * documentation is hereby granted, provided that both the copyright |
| 38 | * notice and this permission notice appear in all copies of the |
| 39 | * software, derivative works or modified versions, and any portions |
| 40 | * thereof, and that both notices appear in supporting documentation. |
| 41 | * |
| 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" |
| 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR |
| 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. |
| 45 | * |
| 46 | * Carnegie Mellon requests users of this software to return to |
| 47 | * |
| 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
| 49 | * School of Computer Science |
| 50 | * Carnegie Mellon University |
| 51 | * Pittsburgh PA 15213-3890 |
| 52 | * |
| 53 | * any improvements or extensions that they make and grant Carnegie Mellon |
| 54 | * the rights to redistribute these changes. |
| 55 | */ |
| 56 | /* |
| 57 | */ |
| 58 | /* |
| 59 | *	File:	mach/vm_statistics.h |
| 60 | *	Author:	Avadis Tevanian, Jr., Michael Wayne Young, David Golub |
| 61 | * |
| 62 | *	Virtual memory statistics structure. |
| 63 | * |
| 64 | */ |
| 65 | |
| 66 | #ifndef _MACH_VM_STATISTICS_H_ |
| 67 | #define _MACH_VM_STATISTICS_H_ |
| 68 | |
| 69 | |
| 70 | #include <Availability.h> |
| 71 | #include <os/base.h> |
| 72 | #include <stdbool.h> |
| 73 | #include <sys/cdefs.h> |
| 74 | |
| 75 | #include <mach/machine/vm_types.h> |
| 76 | #include <mach/machine/kern_return.h> |
| 77 | |
| 78 | __BEGIN_DECLS |
| 79 | |
| 80 | #pragma mark VM Statistics |
| 81 | |
| 82 | /* |
| 83 | * vm_statistics |
| 84 | * |
| 85 | * History: |
| 86 | *	rev0 - original structure. |
| 87 | *	rev1 - added purgable info (purgable_count and purges). |
| 88 | *	rev2 - added speculative_count. |
| 89 | * |
| 90 | * Note: you cannot add any new fields to this structure. Add them below in |
| 91 | * vm_statistics64. |
| 92 | */ |
| 93 | |
| 94 | struct vm_statistics { |
| 95 | 	natural_t free_count; /* # of pages free */ |
| 96 | 	natural_t active_count; /* # of pages active */ |
| 97 | 	natural_t inactive_count; /* # of pages inactive */ |
| 98 | 	natural_t wire_count; /* # of pages wired down */ |
| 99 | 	natural_t zero_fill_count; /* # of zero fill pages */ |
| 100 | 	natural_t reactivations; /* # of pages reactivated */ |
| 101 | 	natural_t pageins; /* # of pageins */ |
| 102 | 	natural_t pageouts; /* # of pageouts */ |
| 103 | 	natural_t faults; /* # of faults */ |
| 104 | 	natural_t cow_faults; /* # of copy-on-writes */ |
| 105 | 	natural_t lookups; /* object cache lookups */ |
| 106 | 	natural_t hits; /* object cache hits */ |
| 107 | |
| 108 | 	/* added for rev1 */ |
| 109 | 	natural_t purgeable_count; /* # of pages purgeable */ |
| 110 | 	natural_t purges; /* # of pages purged */ |
| 111 | |
| 112 | 	/* added for rev2 */ |
| 113 | 	/* |
| 114 | 	 * NB: speculative pages are already accounted for in "free_count", |
| 115 | 	 * so "speculative_count" is the number of "free" pages that are |
| 116 | 	 * used to hold data that was read speculatively from disk but |
| 117 | 	 * haven't actually been used by anyone so far. |
| 118 | 	 */ |
| 119 | 	natural_t speculative_count; /* # of pages speculative */ |
| 120 | }; |
| 121 | |
| 122 | /* Used by all architectures */ |
| 123 | typedef struct vm_statistics *vm_statistics_t; |
| 124 | typedef struct vm_statistics vm_statistics_data_t; |
| 125 | |
| 126 | /* |
| 127 | * vm_statistics64 |
| 128 | * |
| 129 | * History: |
| 130 | *	rev0 - original structure. |
| 131 | *	rev1 - added purgable info (purgable_count and purges). |
| 132 | *	rev2 - added speculative_count. |
| 133 | *	 ---- |
| 134 | *	rev3 - changed name to vm_statistics64. |
| 135 | *		changed some fields in structure to 64-bit on |
| 136 | *		arm, i386 and x86_64 architectures. |
| 137 | *	rev4 - require 64-bit alignment for efficient access |
| 138 | *		in the kernel. No change to reported data. |
| 139 | * |
| 140 | */ |
| 141 | |
| 142 | struct vm_statistics64 { |
| 143 | 	natural_t free_count; /* # of pages free */ |
| 144 | 	natural_t active_count; /* # of pages active */ |
| 145 | 	natural_t inactive_count; /* # of pages inactive */ |
| 146 | 	natural_t wire_count; /* # of pages wired down */ |
| 147 | 	uint64_t zero_fill_count; /* # of zero fill pages */ |
| 148 | 	uint64_t reactivations; /* # of pages reactivated */ |
| 149 | 	uint64_t pageins; /* # of pageins (lifetime) */ |
| 150 | 	uint64_t pageouts; /* # of pageouts */ |
| 151 | 	uint64_t faults; /* # of faults */ |
| 152 | 	uint64_t cow_faults; /* # of copy-on-writes */ |
| 153 | 	uint64_t lookups; /* object cache lookups */ |
| 154 | 	uint64_t hits; /* object cache hits */ |
| 155 | 	uint64_t purges; /* # of pages purged */ |
| 156 | 	natural_t purgeable_count; /* # of pages purgeable */ |
| 157 | 	/* |
| 158 | 	 * NB: speculative pages are already accounted for in "free_count", |
| 159 | 	 * so "speculative_count" is the number of "free" pages that are |
| 160 | 	 * used to hold data that was read speculatively from disk but |
| 161 | 	 * haven't actually been used by anyone so far. |
| 162 | 	 */ |
| 163 | 	natural_t speculative_count; /* # of pages speculative */ |
| 164 | |
| 165 | 	/* added for rev1 */ |
| 166 | 	uint64_t decompressions; /* # of pages decompressed (lifetime) */ |
| 167 | 	uint64_t compressions; /* # of pages compressed (lifetime) */ |
| 168 | 	uint64_t swapins; /* # of pages swapped in via compressor segments (lifetime) */ |
| 169 | 	uint64_t swapouts; /* # of pages swapped out via compressor segments (lifetime) */ |
| 170 | 	natural_t compressor_page_count; /* # of pages used by the compressed pager to hold all the compressed data */ |
| 171 | 	natural_t throttled_count; /* # of pages throttled */ |
| 172 | 	natural_t external_page_count; /* # of pages that are file-backed (non-swap) */ |
| 173 | 	natural_t internal_page_count; /* # of pages that are anonymous */ |
| 174 | 	uint64_t total_uncompressed_pages_in_compressor; /* # of pages (uncompressed) held within the compressor. */ |
| 175 | 	/* added for rev2 */ |
| 176 | 	uint64_t swapped_count; /* # of compressor-stored pages currently stored in swap */ |
| 177 | 	/* Added in rev3 */ |
| 178 | 	/* The total number of physical pages in the tag storage region */ |
| 179 | 	uint64_t total_tag_storage_pages; |
| 180 | 	/* |
| 181 | 	 * The number of tag storage pages which hold non-tag data and are pageable |
| 182 | 	 */ |
| 183 | 	uint64_t nontag_pageable_tag_storage_pages; |
| 184 | 	/* The number of tag storage pages which hold non-tag data and are wired */ |
| 185 | 	uint64_t nontag_wired_tag_storage_pages; |
| 186 | 	/* |
| 187 | 	 * The number of tag storage pages which are being used for neither tags nor |
| 188 | 	 * regular memory |
| 189 | 	 */ |
| 190 | 	uint64_t free_tag_storage_pages; |
| 191 | 	/* The number of tag storage pages which currently hold tags */ |
| 192 | 	uint64_t tag_storing_tag_storage_pages; |
| 193 | |
| 194 | 	/* The total number of virtual pages which are tagged */ |
| 195 | 	uint64_t total_tagged_pages; |
| 196 | 	/* The number of resident, physical pages which are tagged */ |
| 197 | 	uint64_t resident_tagged_pages; |
| 198 | 	/* |
| 199 | 	 * The outstanding number of virtual tagged pages whose contents reside in the |
| 200 | 	 * compressor |
| 201 | 	 */ |
| 202 | 	uint64_t compressed_tagged_pages; |
| 203 | |
| 204 | 	/* The number of tagged pages which have been compressed since boot */ |
| 205 | 	uint64_t tagged_compressions; |
| 206 | 	/* The number of tagged pages which have been decompressed since boot */ |
| 207 | 	uint64_t tagged_decompressions; |
| 208 | 	/* The current number of bytes consumed by compressed tag storage data */ |
| 209 | 	uint64_t compressed_tag_storage_bytes; |
| 210 | } __attribute__((aligned(8))); |
| 211 | |
| 212 | typedef struct vm_statistics64 *vm_statistics64_t; |
| 213 | typedef struct vm_statistics64 vm_statistics64_data_t; |
| 214 | |
| 215 | /* |
| 216 | * VM_STATISTICS_TRUNCATE_TO_32_BIT |
| 217 | * |
| 218 | * This is used by host_statistics() to truncate and peg the 64-bit in-kernel values from |
| 219 | * vm_statistics64 to the 32-bit values of the older structure above (vm_statistics). |
| 220 | */ |
| 221 | #define VM_STATISTICS_TRUNCATE_TO_32_BIT(value) ((uint32_t)(((value) > UINT32_MAX ) ? UINT32_MAX : (value))) |
| 222 | |
| 223 | /* |
| 224 | * vm_extmod_statistics |
| 225 | * |
| 226 | * Structure to record modifications to a task by an |
| 227 | * external agent. |
| 228 | * |
| 229 | * History: |
| 230 | *	rev0 - original structure. |
| 231 | */ |
| 232 | |
| 233 | struct vm_extmod_statistics { |
| 234 | 	int64_t task_for_pid_count; /* # of times task port was looked up */ |
| 235 | 	int64_t task_for_pid_caller_count; /* # of times this task called task_for_pid */ |
| 236 | 	int64_t thread_creation_count; /* # of threads created in task */ |
| 237 | 	int64_t thread_creation_caller_count; /* # of threads created by task */ |
| 238 | 	int64_t thread_set_state_count; /* # of register state sets in task */ |
| 239 | 	int64_t thread_set_state_caller_count; /* # of register state sets by task */ |
| 240 | } __attribute__((aligned(8))); |
| 241 | |
| 242 | typedef struct vm_extmod_statistics *vm_extmod_statistics_t; |
| 243 | typedef struct vm_extmod_statistics vm_extmod_statistics_data_t; |
| 244 | |
| 245 | typedef struct vm_purgeable_stat { |
| 246 | 	uint64_t count; |
| 247 | 	uint64_t size; |
| 248 | }vm_purgeable_stat_t; |
| 249 | |
| 250 | struct vm_purgeable_info { |
| 251 | 	vm_purgeable_stat_t fifo_data[8]; |
| 252 | 	vm_purgeable_stat_t obsolete_data; |
| 253 | 	vm_purgeable_stat_t lifo_data[8]; |
| 254 | }; |
| 255 | |
| 256 | typedef struct vm_purgeable_info *vm_purgeable_info_t; |
| 257 | |
| 258 | /* included for the vm_map_page_query call */ |
| 259 | |
| 260 | typedef int32_t vm_page_disposition_t; |
| 261 | |
| 262 | #define VM_PAGE_QUERY_PAGE_PRESENT 0x001 |
| 263 | #define VM_PAGE_QUERY_PAGE_FICTITIOUS 0x002 |
| 264 | #define VM_PAGE_QUERY_PAGE_REF 0x004 |
| 265 | #define VM_PAGE_QUERY_PAGE_DIRTY 0x008 |
| 266 | #define VM_PAGE_QUERY_PAGE_PAGED_OUT 0x010 |
| 267 | #define VM_PAGE_QUERY_PAGE_COPIED 0x020 |
| 268 | #define VM_PAGE_QUERY_PAGE_SPECULATIVE 0x040 |
| 269 | #define VM_PAGE_QUERY_PAGE_EXTERNAL 0x080 |
| 270 | #define VM_PAGE_QUERY_PAGE_CS_VALIDATED 0x100 |
| 271 | #define VM_PAGE_QUERY_PAGE_CS_TAINTED 0x200 |
| 272 | #define VM_PAGE_QUERY_PAGE_CS_NX 0x400 |
| 273 | #define VM_PAGE_QUERY_PAGE_REUSABLE 0x800 |
| 274 | |
| 275 | #pragma mark User Flags |
| 276 | |
| 277 | /* |
| 278 | * Options for vm_reallocate: |
| 279 | * |
| 280 | * VM_REALLOCATE_DEALLOCATE_SOURCE |
| 281 | * When the source is relocated, the VA it previously occupied will be unmapped. |
| 282 | * |
| 283 | * VM_REALLOCATE_ZERO_FILL_SOURCE |
| 284 | * When the source is relocated, the VA it previously occupied will be mapped |
| 285 | * by new entries with equivalent protections and inheritance, equivalent to a |
| 286 | * fresh zero-filled allocation from vm_allocate(). |
| 287 | */ |
| 288 | #define VM_REALLOCATE_DEALLOCATE_SOURCE 0x0 |
| 289 | #define VM_REALLOCATE_ZERO_FILL_SOURCE 0x1 |
| 290 | |
| 291 | /* |
| 292 | * VM allocation flags: |
| 293 | * |
| 294 | * VM_FLAGS_FIXED |
| 295 | * (really the absence of VM_FLAGS_ANYWHERE) |
| 296 | *	Allocate new VM region at the specified virtual address, if possible. |
| 297 | * |
| 298 | * VM_FLAGS_ANYWHERE |
| 299 | *	Allocate new VM region anywhere it would fit in the address space. |
| 300 | * |
| 301 | * VM_FLAGS_PURGABLE |
| 302 | *	Create a purgable VM object for that new VM region. |
| 303 | * |
| 304 | * VM_FLAGS_4GB_CHUNK |
| 305 | *	The new VM region will be chunked up into 4GB sized pieces. |
| 306 | * |
| 307 | * VM_FLAGS_NO_PMAP_CHECK |
| 308 | *	(for DEBUG kernel config only, ignored for other configs) |
| 309 | *	Do not check that there is no stale pmap mapping for the new VM region. |
| 310 | *	This is useful for kernel memory allocations at bootstrap when building |
| 311 | *	the initial kernel address space while some memory is already in use. |
| 312 | * |
| 313 | * VM_FLAGS_OVERWRITE |
| 314 | *	The new VM region can replace existing VM regions if necessary |
| 315 | *	(to be used in combination with VM_FLAGS_FIXED). |
| 316 | * |
| 317 | * VM_FLAGS_NO_CACHE |
| 318 | *	Pages brought in to this VM region are placed on the speculative |
| 319 | *	queue instead of the active queue. In other words, they are not |
| 320 | *	cached so that they will be stolen first if memory runs low. |
| 321 | * |
| 322 | * VM_FLAGS_GUARD_OBJECT_OPTOUT |
| 323 | *	Opt out this allocation from the guard object allocation policy. |
| 324 | *	And memory will be allocated in typical first-fit allocation order. |
| 325 | */ |
| 326 | |
| 327 | #define VM_FLAGS_FIXED 0x00000000 |
| 328 | #define VM_FLAGS_ANYWHERE 0x00000001 |
| 329 | #define VM_FLAGS_PURGABLE 0x00000002 |
| 330 | #define VM_FLAGS_4GB_CHUNK 0x00000004 |
| 331 | #define VM_FLAGS_RANDOM_ADDR 0x00000008 |
| 332 | #define VM_FLAGS_NO_CACHE 0x00000010 |
| 333 | #define VM_FLAGS_RESILIENT_CODESIGN 0x00000020 |
| 334 | #define VM_FLAGS_RESILIENT_MEDIA 0x00000040 |
| 335 | #define VM_FLAGS_PERMANENT 0x00000080 |
| 336 | #define VM_FLAGS_TPRO 0x00001000 |
| 337 | #define VM_FLAGS_MTE 0x00002000 |
| 338 | #define VM_FLAGS_OVERWRITE 0x00004000 /* delete any existing mappings first */ |
| 339 | /* |
| 340 | * VM_FLAGS_SUPERPAGE_MASK |
| 341 | *	3 bits that specify whether large pages should be used instead of |
| 342 | *	base pages (!=0), as well as the requested page size. |
| 343 | */ |
| 344 | #define VM_FLAGS_SUPERPAGE_MASK 0x00070000 /* bits 0x10000, 0x20000, 0x40000 */ |
| 345 | #define VM_FLAGS_RETURN_DATA_ADDR 0x00100000 /* Return address of target data, rather than base of page */ |
| 346 | #define VM_FLAGS_GUARD_OBJECT_OPTOUT 0x00400000 |
| 347 | #define VM_FLAGS_RETURN_4K_DATA_ADDR 0x00800000 /* Return 4K aligned address of target data */ |
| 348 | #define VM_FLAGS_ALIAS_MASK 0xFF000000 |
| 349 | #define VM_GET_FLAGS_ALIAS(flags, alias) \ |
| 350 | 	 (alias) = (((flags) >> 24) & 0xff) |
| 351 | #define VM_SET_FLAGS_ALIAS(flags, alias) \ |
| 352 | 	 (flags) = (((flags) & ~VM_FLAGS_ALIAS_MASK) | \ |
| 353 | 	 (((alias) & ~VM_FLAGS_ALIAS_MASK) << 24)) |
| 354 | |
| 355 | #define VM_FLAGS_HW (VM_FLAGS_TPRO | \ |
| 356 | 	 VM_FLAGS_MTE) |
| 357 | |
| 358 | /* These are the flags that we accept from user-space */ |
| 359 | #define VM_FLAGS_USER_ALLOCATE (VM_FLAGS_FIXED | \ |
| 360 | 	 VM_FLAGS_ANYWHERE | \ |
| 361 | 	 VM_FLAGS_PURGABLE | \ |
| 362 | 	 VM_FLAGS_4GB_CHUNK | \ |
| 363 | 	 VM_FLAGS_RANDOM_ADDR | \ |
| 364 | 	 VM_FLAGS_NO_CACHE | \ |
| 365 | 	 VM_FLAGS_PERMANENT | \ |
| 366 | 	 VM_FLAGS_OVERWRITE | \ |
| 367 | 	 VM_FLAGS_GUARD_OBJECT_OPTOUT | \ |
| 368 | 	 VM_FLAGS_SUPERPAGE_MASK | \ |
| 369 | 	 VM_FLAGS_HW | \ |
| 370 | 	 VM_FLAGS_ALIAS_MASK) |
| 371 | |
| 372 | #define VM_FLAGS_USER_MAP (VM_FLAGS_USER_ALLOCATE | \ |
| 373 | 	 VM_FLAGS_RETURN_4K_DATA_ADDR | \ |
| 374 | 	 VM_FLAGS_RETURN_DATA_ADDR) |
| 375 | |
| 376 | #define VM_FLAGS_USER_REMAP (VM_FLAGS_FIXED | \ |
| 377 | 	 VM_FLAGS_ANYWHERE | \ |
| 378 | 	 VM_FLAGS_RANDOM_ADDR | \ |
| 379 | 	 VM_FLAGS_OVERWRITE| \ |
| 380 | 	 VM_FLAGS_RETURN_DATA_ADDR | \ |
| 381 | 	 VM_FLAGS_RESILIENT_CODESIGN | \ |
| 382 | 	 VM_FLAGS_RESILIENT_MEDIA) |
| 383 | |
| 384 | #define VM_FLAGS_SUPERPAGE_SHIFT 16 |
| 385 | #define SUPERPAGE_NONE 0 /* no superpages, if all bits are 0 */ |
| 386 | #define SUPERPAGE_SIZE_ANY 1 |
| 387 | #define VM_FLAGS_SUPERPAGE_NONE (SUPERPAGE_NONE << VM_FLAGS_SUPERPAGE_SHIFT) |
| 388 | #define VM_FLAGS_SUPERPAGE_SIZE_ANY (SUPERPAGE_SIZE_ANY << VM_FLAGS_SUPERPAGE_SHIFT) |
| 389 | #define SUPERPAGE_SIZE_2MB 2 |
| 390 | #define VM_FLAGS_SUPERPAGE_SIZE_2MB (SUPERPAGE_SIZE_2MB<<VM_FLAGS_SUPERPAGE_SHIFT) |
| 391 | |
| 392 | /* |
| 393 | * EXC_GUARD definitions for virtual memory. |
| 394 | */ |
| 395 | #define GUARD_TYPE_VIRT_MEMORY 0x5 |
| 396 | |
| 397 | /* Reasons for exception for virtual memory */ |
| 398 | __enum_decl(virtual_memory_guard_exception_code_t, uint32_t, { |
| 399 | 	kGUARD_EXC_DEALLOC_GAP = 1, |
| 400 | 	kGUARD_EXC_RECLAIM_COPYIO_FAILURE = 2, |
| 401 | 	kGUARD_EXC_RECLAIM_INDEX_FAILURE = 4, |
| 402 | 	kGUARD_EXC_RECLAIM_DEALLOCATE_FAILURE = 8, |
| 403 | 	kGUARD_EXC_RECLAIM_ACCOUNTING_FAILURE = 9, |
| 404 | 	kGUARD_EXC_SEC_IOPL_ON_EXEC_PAGE = 10, |
| 405 | 	kGUARD_EXC_SEC_EXEC_ON_IOPL_PAGE = 11, |
| 406 | 	kGUARD_EXC_SEC_UPL_WRITE_ON_EXEC_REGION = 12, |
| 407 | 	kGUARD_EXC_LARGE_ALLOCATION_TELEMETRY = 13, |
| 408 | 	/* |
| 409 | 	 * rdar://151450801 (Remove spurious kGUARD_EXC_SEC_ACCESS_FAULT and kGUARD_EXC_SEC_ASYNC_ACCESS_FAULT once CrashReporter is aligned) |
| 410 | 	 */ |
| 411 | 	kGUARD_EXC_SEC_ACCESS_FAULT = 98, |
| 412 | 	kGUARD_EXC_SEC_ASYNC_ACCESS_FAULT = 99, |
| 413 | 	/* VM policy decisions */ |
| 414 | 	kGUARD_EXC_SEC_COPY_DENIED = 100, |
| 415 | 	kGUARD_EXC_SEC_SHARING_DENIED = 101, |
| 416 | |
| 417 | 	/* Fault-related exceptions. */ |
| 418 | 	kGUARD_EXC_MTE_SYNC_FAULT = 200, |
| 419 | 	kGUARD_EXC_MTE_ASYNC_USER_FAULT = 201, |
| 420 | 	kGUARD_EXC_MTE_ASYNC_KERN_FAULT = 202, |
| 421 | 	kGUARD_EXC_GUARD_OBJECT_ASYNC_USER_FAULT = 203, |
| 422 | 	kGUARD_EXC_GUARD_OBJECT_ASYNC_KERN_FAULT = 204, |
| 423 | }); |
| 424 | |
| 425 | #define kGUARD_EXC_MTE_SOFT_MODE 0x100000 |
| 426 | |
| 427 | |
| 428 | #pragma mark Ledger Tags |
| 429 | |
| 430 | /* current accounting postmark */ |
| 431 | #define __VM_LEDGER_ACCOUNTING_POSTMARK 2019032600 |
| 432 | |
| 433 | /* |
| 434 | * When making a new VM_LEDGER_TAG_* or VM_LEDGER_FLAG_*, update tests |
| 435 | * vm_parameter_validation_[user|kern] and their expected results; they |
| 436 | * deliberately call VM functions with invalid ledger values and you may |
| 437 | * be turning one of those invalid tags/flags valid. |
| 438 | */ |
| 439 | /* discrete values: */ |
| 440 | #define VM_LEDGER_TAG_NONE 0x00000000 |
| 441 | #define VM_LEDGER_TAG_DEFAULT 0x00000001 |
| 442 | #define VM_LEDGER_TAG_NETWORK 0x00000002 |
| 443 | #define VM_LEDGER_TAG_MEDIA 0x00000003 |
| 444 | #define VM_LEDGER_TAG_GRAPHICS 0x00000004 |
| 445 | #define VM_LEDGER_TAG_NEURAL 0x00000005 |
| 446 | #define VM_LEDGER_TAG_MAX 0x00000005 |
| 447 | #define VM_LEDGER_TAG_UNCHANGED ((int)-1) |
| 448 | |
| 449 | /* individual bits: */ |
| 450 | #define VM_LEDGER_FLAG_NO_FOOTPRINT (1 << 0) |
| 451 | #define VM_LEDGER_FLAG_NO_FOOTPRINT_FOR_DEBUG (1 << 1) |
| 452 | #define VM_LEDGER_FLAG_FROM_KERNEL (1 << 2) |
| 453 | |
| 454 | #define VM_LEDGER_FLAGS_USER (VM_LEDGER_FLAG_NO_FOOTPRINT | VM_LEDGER_FLAG_NO_FOOTPRINT_FOR_DEBUG) |
| 455 | #define VM_LEDGER_FLAGS_ALL (VM_LEDGER_FLAGS_USER | VM_LEDGER_FLAG_FROM_KERNEL) |
| 456 | |
| 457 | #pragma mark User Memory Tags |
| 458 | |
| 459 | /* |
| 460 | * These tags may be used to identify memory regions created with |
| 461 | * `mach_vm_map()` or `mach_vm_allocate()` via the top 8 bits of the `flags` |
| 462 | * parameter. Users should pass `VM_MAKE_TAG(tag) | flags` (see section |
| 463 | * "User Flags"). |
| 464 | */ |
| 465 | #define VM_MEMORY_MALLOC 1 |
| 466 | #define VM_MEMORY_MALLOC_SMALL 2 |
| 467 | #define VM_MEMORY_MALLOC_LARGE 3 |
| 468 | #define VM_MEMORY_MALLOC_HUGE 4 |
| 469 | #define VM_MEMORY_SBRK 5// uninteresting -- no one should call |
| 470 | #define VM_MEMORY_REALLOC 6 |
| 471 | #define VM_MEMORY_MALLOC_TINY 7 |
| 472 | #define VM_MEMORY_MALLOC_LARGE_REUSABLE 8 |
| 473 | #define VM_MEMORY_MALLOC_LARGE_REUSED 9 |
| 474 | |
| 475 | #define VM_MEMORY_ANALYSIS_TOOL 10 |
| 476 | |
| 477 | #define VM_MEMORY_MALLOC_NANO 11 |
| 478 | #define VM_MEMORY_MALLOC_MEDIUM 12 |
| 479 | #define VM_MEMORY_MALLOC_PROB_GUARD 13 |
| 480 | |
| 481 | #define VM_MEMORY_MACH_MSG 20 |
| 482 | #define VM_MEMORY_IOKIT 21 |
| 483 | #define VM_MEMORY_VM_RECLAIM 22 |
| 484 | |
| 485 | #define VM_MEMORY_STACK 30 |
| 486 | #define VM_MEMORY_GUARD 31 |
| 487 | #define VM_MEMORY_SHARED_PMAP 32 |
| 488 | /* memory containing a dylib */ |
| 489 | #define VM_MEMORY_DYLIB 33 |
| 490 | #define VM_MEMORY_OBJC_DISPATCHERS 34 |
| 491 | |
| 492 | /* Was a nested pmap (VM_MEMORY_SHARED_PMAP) which has now been unnested */ |
| 493 | #define VM_MEMORY_UNSHARED_PMAP 35 |
| 494 | |
| 495 | /* for libchannel memory, mostly used on visionOS for communication with realtime threads */ |
| 496 | #define VM_MEMORY_LIBCHANNEL 36 |
| 497 | |
| 498 | // Placeholders for now -- as we analyze the libraries and find how they |
| 499 | // use memory, we can make these labels more specific. |
| 500 | #define VM_MEMORY_APPKIT 40 |
| 501 | #define VM_MEMORY_FOUNDATION 41 |
| 502 | #define VM_MEMORY_COREGRAPHICS 42 |
| 503 | #define VM_MEMORY_CORESERVICES 43 |
| 504 | #define VM_MEMORY_CARBON VM_MEMORY_CORESERVICES |
| 505 | #define VM_MEMORY_JAVA 44 |
| 506 | #define VM_MEMORY_COREDATA 45 |
| 507 | #define VM_MEMORY_COREDATA_OBJECTIDS 46 |
| 508 | |
| 509 | #define VM_MEMORY_ATS 50 |
| 510 | #define VM_MEMORY_LAYERKIT 51 |
| 511 | #define VM_MEMORY_CGIMAGE 52 |
| 512 | #define VM_MEMORY_TCMALLOC 53 |
| 513 | |
| 514 | /* private raster data (i.e. layers, some images, QGL allocator) */ |
| 515 | #define VM_MEMORY_COREGRAPHICS_DATA 54 |
| 516 | |
| 517 | /* shared image and font caches */ |
| 518 | #define VM_MEMORY_COREGRAPHICS_SHARED 55 |
| 519 | |
| 520 | /* Memory used for virtual framebuffers, shadowing buffers, etc... */ |
| 521 | #define VM_MEMORY_COREGRAPHICS_FRAMEBUFFERS 56 |
| 522 | |
| 523 | /* Window backing stores, custom shadow data, and compressed backing stores */ |
| 524 | #define VM_MEMORY_COREGRAPHICS_BACKINGSTORES 57 |
| 525 | |
| 526 | /* x-alloc'd memory */ |
| 527 | #define VM_MEMORY_COREGRAPHICS_XALLOC 58 |
| 528 | |
| 529 | /* catch-all for other uses, such as the read-only shared data page */ |
| 530 | #define VM_MEMORY_COREGRAPHICS_MISC VM_MEMORY_COREGRAPHICS |
| 531 | |
| 532 | /* memory allocated by the dynamic loader for itself */ |
| 533 | #define VM_MEMORY_DYLD 60 |
| 534 | /* malloc'd memory created by dyld */ |
| 535 | #define VM_MEMORY_DYLD_MALLOC 61 |
| 536 | |
| 537 | /* Used for sqlite page cache */ |
| 538 | #define VM_MEMORY_SQLITE 62 |
| 539 | |
| 540 | /* JavaScriptCore heaps */ |
| 541 | #define VM_MEMORY_JAVASCRIPT_CORE 63 |
| 542 | #define VM_MEMORY_WEBASSEMBLY VM_MEMORY_JAVASCRIPT_CORE |
| 543 | /* memory allocated for the JIT */ |
| 544 | #define VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR 64 |
| 545 | #define VM_MEMORY_JAVASCRIPT_JIT_REGISTER_FILE 65 |
| 546 | |
| 547 | /* memory allocated for GLSL */ |
| 548 | #define VM_MEMORY_GLSL 66 |
| 549 | |
| 550 | /* memory allocated for OpenCL.framework */ |
| 551 | #define VM_MEMORY_OPENCL 67 |
| 552 | |
| 553 | /* memory allocated for QuartzCore.framework */ |
| 554 | #define VM_MEMORY_COREIMAGE 68 |
| 555 | |
| 556 | /* memory allocated for WebCore Purgeable Buffers */ |
| 557 | #define VM_MEMORY_WEBCORE_PURGEABLE_BUFFERS 69 |
| 558 | |
| 559 | /* ImageIO memory */ |
| 560 | #define VM_MEMORY_IMAGEIO 70 |
| 561 | |
| 562 | /* CoreProfile memory */ |
| 563 | #define VM_MEMORY_COREPROFILE 71 |
| 564 | |
| 565 | /* assetsd / MobileSlideShow memory */ |
| 566 | #define VM_MEMORY_ASSETSD 72 |
| 567 | |
| 568 | /* libsystem_kernel os_once_alloc */ |
| 569 | #define VM_MEMORY_OS_ALLOC_ONCE 73 |
| 570 | |
| 571 | /* libdispatch internal allocator */ |
| 572 | #define VM_MEMORY_LIBDISPATCH 74 |
| 573 | |
| 574 | /* Accelerate.framework image backing stores */ |
| 575 | #define VM_MEMORY_ACCELERATE 75 |
| 576 | |
| 577 | /* CoreUI image block data */ |
| 578 | #define VM_MEMORY_COREUI 76 |
| 579 | |
| 580 | /* CoreUI image file */ |
| 581 | #define VM_MEMORY_COREUIFILE 77 |
| 582 | |
| 583 | /* Genealogy buffers */ |
| 584 | #define VM_MEMORY_GENEALOGY 78 |
| 585 | |
| 586 | /* RawCamera VM allocated memory */ |
| 587 | #define VM_MEMORY_RAWCAMERA 79 |
| 588 | |
| 589 | /* corpse info for dead process */ |
| 590 | #define VM_MEMORY_CORPSEINFO 80 |
| 591 | |
| 592 | /* Apple System Logger (ASL) messages */ |
| 593 | #define VM_MEMORY_ASL 81 |
| 594 | |
| 595 | /* Swift runtime */ |
| 596 | #define VM_MEMORY_SWIFT_RUNTIME 82 |
| 597 | |
| 598 | /* Swift metadata */ |
| 599 | #define VM_MEMORY_SWIFT_METADATA 83 |
| 600 | |
| 601 | /* DHMM data */ |
| 602 | #define VM_MEMORY_DHMM 84 |
| 603 | |
| 604 | /* memory needed for DFR related actions */ |
| 605 | #define VM_MEMORY_DFR 85 |
| 606 | |
| 607 | /* memory allocated by SceneKit.framework */ |
| 608 | #define VM_MEMORY_SCENEKIT 86 |
| 609 | |
| 610 | /* memory allocated by skywalk networking */ |
| 611 | #define VM_MEMORY_SKYWALK 87 |
| 612 | |
| 613 | #define VM_MEMORY_IOSURFACE 88 |
| 614 | |
| 615 | #define VM_MEMORY_LIBNETWORK 89 |
| 616 | |
| 617 | #define VM_MEMORY_AUDIO 90 |
| 618 | |
| 619 | #define VM_MEMORY_VIDEOBITSTREAM 91 |
| 620 | |
| 621 | /* memory allocated by CoreMedia */ |
| 622 | #define VM_MEMORY_CM_XPC 92 |
| 623 | |
| 624 | #define VM_MEMORY_CM_RPC 93 |
| 625 | |
| 626 | #define VM_MEMORY_CM_MEMORYPOOL 94 |
| 627 | |
| 628 | #define VM_MEMORY_CM_READCACHE 95 |
| 629 | |
| 630 | #define VM_MEMORY_CM_CRABS 96 |
| 631 | |
| 632 | /* memory allocated for QuickLookThumbnailing */ |
| 633 | #define VM_MEMORY_QUICKLOOK_THUMBNAILS 97 |
| 634 | |
| 635 | /* memory allocated by Accounts framework */ |
| 636 | #define VM_MEMORY_ACCOUNTS 98 |
| 637 | |
| 638 | /* memory allocated by Sanitizer runtime libraries */ |
| 639 | #define VM_MEMORY_SANITIZER 99 |
| 640 | |
| 641 | /* Differentiate memory needed by GPU drivers and frameworks from generic IOKit allocations */ |
| 642 | #define VM_MEMORY_IOACCELERATOR 100 |
| 643 | |
| 644 | /* memory allocated by CoreMedia for global image registration of frames */ |
| 645 | #define VM_MEMORY_CM_REGWARP 101 |
| 646 | |
| 647 | /* memory allocated by EmbeddedAcousticRecognition for speech decoder */ |
| 648 | #define VM_MEMORY_EAR_DECODER 102 |
| 649 | |
| 650 | /* CoreUI cached image data */ |
| 651 | #define VM_MEMORY_COREUI_CACHED_IMAGE_DATA 103 |
| 652 | |
| 653 | /* ColorSync is using mmap for read-only copies of ICC profile data */ |
| 654 | #define VM_MEMORY_COLORSYNC 104 |
| 655 | |
| 656 | /* backtrace info for simulated crashes */ |
| 657 | #define VM_MEMORY_BTINFO 105 |
| 658 | |
| 659 | /* memory allocated by CoreMedia */ |
| 660 | #define VM_MEMORY_CM_HLS 106 |
| 661 | |
| 662 | /* memory allocated for CompositorServices */ |
| 663 | #define VM_MEMORY_COMPOSITOR_SERVICES 107 |
| 664 | |
| 665 | /* Reserve 230-239 for Rosetta */ |
| 666 | #define VM_MEMORY_ROSETTA 230 |
| 667 | #define VM_MEMORY_ROSETTA_THREAD_CONTEXT 231 |
| 668 | #define VM_MEMORY_ROSETTA_INDIRECT_BRANCH_MAP 232 |
| 669 | #define VM_MEMORY_ROSETTA_RETURN_STACK 233 |
| 670 | #define VM_MEMORY_ROSETTA_EXECUTABLE_HEAP 234 |
| 671 | #define VM_MEMORY_ROSETTA_USER_LDT 235 |
| 672 | #define VM_MEMORY_ROSETTA_ARENA 236 |
| 673 | #define VM_MEMORY_ROSETTA_10 239 |
| 674 | |
| 675 | /* Reserve 240-255 for application */ |
| 676 | #define VM_MEMORY_APPLICATION_SPECIFIC_1 240 |
| 677 | #define VM_MEMORY_APPLICATION_SPECIFIC_2 241 |
| 678 | #define VM_MEMORY_APPLICATION_SPECIFIC_3 242 |
| 679 | #define VM_MEMORY_APPLICATION_SPECIFIC_4 243 |
| 680 | #define VM_MEMORY_APPLICATION_SPECIFIC_5 244 |
| 681 | #define VM_MEMORY_APPLICATION_SPECIFIC_6 245 |
| 682 | #define VM_MEMORY_APPLICATION_SPECIFIC_7 246 |
| 683 | #define VM_MEMORY_APPLICATION_SPECIFIC_8 247 |
| 684 | #define VM_MEMORY_APPLICATION_SPECIFIC_9 248 |
| 685 | #define VM_MEMORY_APPLICATION_SPECIFIC_10 249 |
| 686 | #define VM_MEMORY_APPLICATION_SPECIFIC_11 250 |
| 687 | #define VM_MEMORY_APPLICATION_SPECIFIC_12 251 |
| 688 | #define VM_MEMORY_APPLICATION_SPECIFIC_13 252 |
| 689 | #define VM_MEMORY_APPLICATION_SPECIFIC_14 253 |
| 690 | #define VM_MEMORY_APPLICATION_SPECIFIC_15 254 |
| 691 | #define VM_MEMORY_APPLICATION_SPECIFIC_16 255 |
| 692 | |
| 693 | #define VM_MEMORY_COUNT 256 |
| 694 | |
| 695 | #define VM_MAKE_TAG(tag) ((tag) << 24) |
| 696 | |
| 697 | |
| 698 | __END_DECLS |
| 699 | |
| 700 | #endif /* _MACH_VM_STATISTICS_H_ */ |