xref: /xnu-8796.141.3/osfmk/mach/vm_statistics.h (revision 1b191cb58250d0705d8a51287127505aa4bc0789)
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  [email protected]
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 #include <sys/cdefs.h>
70 
71 __BEGIN_DECLS
72 
73 #include <mach/machine/vm_types.h>
74 #include <mach/machine/kern_return.h>
75 
76 /*
77  * vm_statistics
78  *
79  * History:
80  *	rev0 -  original structure.
81  *	rev1 -  added purgable info (purgable_count and purges).
82  *	rev2 -  added speculative_count.
83  *
84  * Note: you cannot add any new fields to this structure. Add them below in
85  *       vm_statistics64.
86  */
87 
88 struct vm_statistics {
89 	natural_t       free_count;             /* # of pages free */
90 	natural_t       active_count;           /* # of pages active */
91 	natural_t       inactive_count;         /* # of pages inactive */
92 	natural_t       wire_count;             /* # of pages wired down */
93 	natural_t       zero_fill_count;        /* # of zero fill pages */
94 	natural_t       reactivations;          /* # of pages reactivated */
95 	natural_t       pageins;                /* # of pageins */
96 	natural_t       pageouts;               /* # of pageouts */
97 	natural_t       faults;                 /* # of faults */
98 	natural_t       cow_faults;             /* # of copy-on-writes */
99 	natural_t       lookups;                /* object cache lookups */
100 	natural_t       hits;                   /* object cache hits */
101 
102 	/* added for rev1 */
103 	natural_t       purgeable_count;        /* # of pages purgeable */
104 	natural_t       purges;                 /* # of pages purged */
105 
106 	/* added for rev2 */
107 	/*
108 	 * NB: speculative pages are already accounted for in "free_count",
109 	 * so "speculative_count" is the number of "free" pages that are
110 	 * used to hold data that was read speculatively from disk but
111 	 * haven't actually been used by anyone so far.
112 	 */
113 	natural_t       speculative_count;      /* # of pages speculative */
114 };
115 
116 /* Used by all architectures */
117 typedef struct vm_statistics    *vm_statistics_t;
118 typedef struct vm_statistics    vm_statistics_data_t;
119 
120 /*
121  * vm_statistics64
122  *
123  * History:
124  *	rev0 -  original structure.
125  *	rev1 -  added purgable info (purgable_count and purges).
126  *	rev2 -  added speculative_count.
127  *	   ----
128  *	rev3 -  changed name to vm_statistics64.
129  *		changed some fields in structure to 64-bit on
130  *		arm, i386 and x86_64 architectures.
131  *	rev4 -  require 64-bit alignment for efficient access
132  *		in the kernel. No change to reported data.
133  *
134  */
135 
136 struct vm_statistics64 {
137 	natural_t       free_count;             /* # of pages free */
138 	natural_t       active_count;           /* # of pages active */
139 	natural_t       inactive_count;         /* # of pages inactive */
140 	natural_t       wire_count;             /* # of pages wired down */
141 	uint64_t        zero_fill_count;        /* # of zero fill pages */
142 	uint64_t        reactivations;          /* # of pages reactivated */
143 	uint64_t        pageins;                /* # of pageins */
144 	uint64_t        pageouts;               /* # of pageouts */
145 	uint64_t        faults;                 /* # of faults */
146 	uint64_t        cow_faults;             /* # of copy-on-writes */
147 	uint64_t        lookups;                /* object cache lookups */
148 	uint64_t        hits;                   /* object cache hits */
149 	uint64_t        purges;                 /* # of pages purged */
150 	natural_t       purgeable_count;        /* # of pages purgeable */
151 	/*
152 	 * NB: speculative pages are already accounted for in "free_count",
153 	 * so "speculative_count" is the number of "free" pages that are
154 	 * used to hold data that was read speculatively from disk but
155 	 * haven't actually been used by anyone so far.
156 	 */
157 	natural_t       speculative_count;      /* # of pages speculative */
158 
159 	/* added for rev1 */
160 	uint64_t        decompressions;         /* # of pages decompressed */
161 	uint64_t        compressions;           /* # of pages compressed */
162 	uint64_t        swapins;                /* # of pages swapped in (via compression segments) */
163 	uint64_t        swapouts;               /* # of pages swapped out (via compression segments) */
164 	natural_t       compressor_page_count;  /* # of pages used by the compressed pager to hold all the compressed data */
165 	natural_t       throttled_count;        /* # of pages throttled */
166 	natural_t       external_page_count;    /* # of pages that are file-backed (non-swap) */
167 	natural_t       internal_page_count;    /* # of pages that are anonymous */
168 	uint64_t        total_uncompressed_pages_in_compressor; /* # of pages (uncompressed) held within the compressor. */
169 } __attribute__((aligned(8)));
170 
171 typedef struct vm_statistics64  *vm_statistics64_t;
172 typedef struct vm_statistics64  vm_statistics64_data_t;
173 
174 kern_return_t vm_stats(void *info, unsigned int *count);
175 
176 /*
177  * VM_STATISTICS_TRUNCATE_TO_32_BIT
178  *
179  * This is used by host_statistics() to truncate and peg the 64-bit in-kernel values from
180  * vm_statistics64 to the 32-bit values of the older structure above (vm_statistics).
181  */
182 #define VM_STATISTICS_TRUNCATE_TO_32_BIT(value) ((uint32_t)(((value) > UINT32_MAX ) ? UINT32_MAX : (value)))
183 
184 /*
185  * vm_extmod_statistics
186  *
187  * Structure to record modifications to a task by an
188  * external agent.
189  *
190  * History:
191  *	rev0 -  original structure.
192  */
193 
194 struct vm_extmod_statistics {
195 	int64_t task_for_pid_count;                     /* # of times task port was looked up */
196 	int64_t task_for_pid_caller_count;      /* # of times this task called task_for_pid */
197 	int64_t thread_creation_count;          /* # of threads created in task */
198 	int64_t thread_creation_caller_count;   /* # of threads created by task */
199 	int64_t thread_set_state_count;         /* # of register state sets in task */
200 	int64_t thread_set_state_caller_count;  /* # of register state sets by task */
201 } __attribute__((aligned(8)));
202 
203 typedef struct vm_extmod_statistics *vm_extmod_statistics_t;
204 typedef struct vm_extmod_statistics vm_extmod_statistics_data_t;
205 
206 typedef struct vm_purgeable_stat {
207 	uint64_t        count;
208 	uint64_t        size;
209 }vm_purgeable_stat_t;
210 
211 struct vm_purgeable_info {
212 	vm_purgeable_stat_t fifo_data[8];
213 	vm_purgeable_stat_t obsolete_data;
214 	vm_purgeable_stat_t lifo_data[8];
215 };
216 
217 typedef struct vm_purgeable_info        *vm_purgeable_info_t;
218 
219 /* included for the vm_map_page_query call */
220 
221 #define VM_PAGE_QUERY_PAGE_PRESENT      0x1
222 #define VM_PAGE_QUERY_PAGE_FICTITIOUS   0x2
223 #define VM_PAGE_QUERY_PAGE_REF          0x4
224 #define VM_PAGE_QUERY_PAGE_DIRTY        0x8
225 #define VM_PAGE_QUERY_PAGE_PAGED_OUT    0x10
226 #define VM_PAGE_QUERY_PAGE_COPIED       0x20
227 #define VM_PAGE_QUERY_PAGE_SPECULATIVE  0x40
228 #define VM_PAGE_QUERY_PAGE_EXTERNAL     0x80
229 #define VM_PAGE_QUERY_PAGE_CS_VALIDATED 0x100
230 #define VM_PAGE_QUERY_PAGE_CS_TAINTED   0x200
231 #define VM_PAGE_QUERY_PAGE_CS_NX        0x400
232 #define VM_PAGE_QUERY_PAGE_REUSABLE     0x800
233 
234 /*
235  * VM allocation flags:
236  *
237  * VM_FLAGS_FIXED
238  *      (really the absence of VM_FLAGS_ANYWHERE)
239  *	Allocate new VM region at the specified virtual address, if possible.
240  *
241  * VM_FLAGS_ANYWHERE
242  *	Allocate new VM region anywhere it would fit in the address space.
243  *
244  * VM_FLAGS_PURGABLE
245  *	Create a purgable VM object for that new VM region.
246  *
247  * VM_FLAGS_4GB_CHUNK
248  *	The new VM region will be chunked up into 4GB sized pieces.
249  *
250  * VM_FLAGS_NO_PMAP_CHECK
251  *	(for DEBUG kernel config only, ignored for other configs)
252  *	Do not check that there is no stale pmap mapping for the new VM region.
253  *	This is useful for kernel memory allocations at bootstrap when building
254  *	the initial kernel address space while some memory is already in use.
255  *
256  * VM_FLAGS_OVERWRITE
257  *	The new VM region can replace existing VM regions if necessary
258  *	(to be used in combination with VM_FLAGS_FIXED).
259  *
260  * VM_FLAGS_NO_CACHE
261  *	Pages brought in to this VM region are placed on the speculative
262  *	queue instead of the active queue.  In other words, they are not
263  *	cached so that they will be stolen first if memory runs low.
264  */
265 
266 #define VM_FLAGS_FIXED                  0x00000000
267 #define VM_FLAGS_ANYWHERE               0x00000001
268 #define VM_FLAGS_PURGABLE               0x00000002
269 #define VM_FLAGS_4GB_CHUNK              0x00000004
270 #define VM_FLAGS_RANDOM_ADDR            0x00000008
271 #define VM_FLAGS_NO_CACHE               0x00000010
272 #define VM_FLAGS_RESILIENT_CODESIGN     0x00000020
273 #define VM_FLAGS_RESILIENT_MEDIA        0x00000040
274 #define VM_FLAGS_PERMANENT              0x00000080
275 #define VM_FLAGS_TPRO                   0x00001000
276 #define VM_FLAGS_OVERWRITE              0x00004000  /* delete any existing mappings first */
277 /*
278  * VM_FLAGS_SUPERPAGE_MASK
279  *	3 bits that specify whether large pages should be used instead of
280  *	base pages (!=0), as well as the requested page size.
281  */
282 #define VM_FLAGS_SUPERPAGE_MASK         0x00070000 /* bits 0x10000, 0x20000, 0x40000 */
283 #define VM_FLAGS_RETURN_DATA_ADDR       0x00100000 /* Return address of target data, rather than base of page */
284 #define VM_FLAGS_RETURN_4K_DATA_ADDR    0x00800000 /* Return 4K aligned address of target data */
285 #define VM_FLAGS_ALIAS_MASK             0xFF000000
286 #define VM_GET_FLAGS_ALIAS(flags, alias)                        \
287 	        (alias) = (((flags) >> 24) & 0xff)
288 #if !XNU_KERNEL_PRIVATE
289 #define VM_SET_FLAGS_ALIAS(flags, alias)                        \
290 	        (flags) = (((flags) & ~VM_FLAGS_ALIAS_MASK) |   \
291 	        (((alias) & ~VM_FLAGS_ALIAS_MASK) << 24))
292 #endif /* !XNU_KERNEL_PRIVATE */
293 
294 #if XNU_KERNEL_PRIVATE
295 /*
296  * When making a new VM_FLAG_*:
297  * - add it to this mask
298  * - add a vmf_* field to vm_map_kernel_flags_t in the right spot
299  * - add a check in vm_map_kernel_flags_uflags()
300  */
301 #define VM_FLAGS_ANY_MASK       (VM_FLAGS_FIXED |               \
302 	                         VM_FLAGS_ANYWHERE |            \
303 	                         VM_FLAGS_PURGABLE |            \
304 	                         VM_FLAGS_4GB_CHUNK |           \
305 	                         VM_FLAGS_RANDOM_ADDR |         \
306 	                         VM_FLAGS_NO_CACHE |            \
307 	                         VM_FLAGS_RESILIENT_CODESIGN |  \
308 	                         VM_FLAGS_RESILIENT_MEDIA |     \
309 	                         VM_FLAGS_PERMANENT |           \
310 	                         VM_FLAGS_TPRO |                \
311 	                         VM_FLAGS_OVERWRITE |           \
312 	                         VM_FLAGS_SUPERPAGE_MASK |      \
313 	                         VM_FLAGS_RETURN_DATA_ADDR |    \
314 	                         VM_FLAGS_RETURN_4K_DATA_ADDR | \
315 	                         VM_FLAGS_ALIAS_MASK)
316 #endif /* XNU_KERNEL_PRIVATE */
317 
318 /* These are the flags that we accept from user-space */
319 #define VM_FLAGS_USER_ALLOCATE  (VM_FLAGS_FIXED |               \
320 	                         VM_FLAGS_ANYWHERE |            \
321 	                         VM_FLAGS_PURGABLE |            \
322 	                         VM_FLAGS_4GB_CHUNK |           \
323 	                         VM_FLAGS_RANDOM_ADDR |         \
324 	                         VM_FLAGS_NO_CACHE |            \
325 	                         VM_FLAGS_PERMANENT |           \
326 	                         VM_FLAGS_OVERWRITE |           \
327 	                         VM_FLAGS_SUPERPAGE_MASK |      \
328 	                         VM_FLAGS_TPRO |                \
329 	                         VM_FLAGS_ALIAS_MASK)
330 
331 #define VM_FLAGS_USER_MAP       (VM_FLAGS_USER_ALLOCATE |       \
332 	                         VM_FLAGS_RETURN_4K_DATA_ADDR | \
333 	                         VM_FLAGS_RETURN_DATA_ADDR)
334 
335 #define VM_FLAGS_USER_REMAP     (VM_FLAGS_FIXED |               \
336 	                         VM_FLAGS_ANYWHERE |            \
337 	                         VM_FLAGS_RANDOM_ADDR |         \
338 	                         VM_FLAGS_OVERWRITE|            \
339 	                         VM_FLAGS_RETURN_DATA_ADDR |    \
340 	                         VM_FLAGS_RESILIENT_CODESIGN |  \
341 	                         VM_FLAGS_RESILIENT_MEDIA)
342 
343 #define VM_FLAGS_SUPERPAGE_SHIFT 16
344 #define SUPERPAGE_NONE                  0       /* no superpages, if all bits are 0 */
345 #define SUPERPAGE_SIZE_ANY              1
346 #define VM_FLAGS_SUPERPAGE_NONE     (SUPERPAGE_NONE     << VM_FLAGS_SUPERPAGE_SHIFT)
347 #define VM_FLAGS_SUPERPAGE_SIZE_ANY (SUPERPAGE_SIZE_ANY << VM_FLAGS_SUPERPAGE_SHIFT)
348 #if defined(__x86_64__) || !defined(KERNEL)
349 #define SUPERPAGE_SIZE_2MB              2
350 #define VM_FLAGS_SUPERPAGE_SIZE_2MB (SUPERPAGE_SIZE_2MB<<VM_FLAGS_SUPERPAGE_SHIFT)
351 #endif
352 
353 /*
354  * EXC_GUARD definitions for virtual memory.
355  */
356 #define GUARD_TYPE_VIRT_MEMORY  0x5
357 
358 /* Reasons for exception for virtual memory */
359 enum virtual_memory_guard_exception_codes {
360 	kGUARD_EXC_DEALLOC_GAP  = 1u << 0,
361 	kGUARD_EXC_RECLAIM_COPYIO_FAILURE = 1u << 1,
362 	kGUARD_EXC_RECLAIM_INDEX_FAILURE = 1u << 2,
363 	kGUARD_EXC_RECLAIM_DEALLOCATE_FAILURE = 1u << 3,
364 };
365 
366 #ifdef XNU_KERNEL_PRIVATE
367 
368 /*!
369  * @enum vm_map_range_id_t
370  *
371  * @brief
372  * Enumerate a particular vm_map range.
373  *
374  * @discussion
375  * The kernel_map VA has been split into the following ranges. Userspace
376  * VA for any given process can also optionally be split by the following user
377  * ranges.
378  *
379  * @const KMEM_RANGE_ID_NONE
380  * This range is only used for early initialization.
381  *
382  * @const KMEM_RANGE_ID_PTR_*
383  * Range containing general purpose allocations from kalloc, etc that
384  * contain pointers.
385  *
386  * @const KMEM_RANGE_ID_SPRAYQTN
387  * The spray quarantine range contains allocations that have the following
388  * properties:
389  * - An attacker could control the size, lifetime and number of allocations
390  *   of this type (or from this callsite).
391  * - The pointer to the allocation is zeroed to ensure that it isn't left
392  *   dangling limiting the use of UaFs.
393  * - OOBs on the allocation is carefully considered and sufficiently
394  *   addressed.
395  *
396  * @const KMEM_RANGE_ID_DATA
397  * Range containing allocations that are bags of bytes and contain no
398  * pointers.
399  *
400  * @const UMEM_RANGE_ID_DEFAULT
401  * Range containing default allocation calls
402  *
403  * @const UMEM_RANGE_ID_HEAP
404  * Range containing heap allocation calls
405  */
406 __enum_decl(vm_map_range_id_t, uint32_t, {
407 	KMEM_RANGE_ID_NONE,
408 	KMEM_RANGE_ID_PTR_0,
409 	KMEM_RANGE_ID_PTR_1,
410 	KMEM_RANGE_ID_PTR_2,
411 	KMEM_RANGE_ID_SPRAYQTN,
412 	KMEM_RANGE_ID_DATA,
413 
414 	KMEM_RANGE_ID_FIRST   = KMEM_RANGE_ID_PTR_0,
415 	KMEM_RANGE_ID_NUM_PTR = KMEM_RANGE_ID_PTR_2,
416 	KMEM_RANGE_ID_MAX     = KMEM_RANGE_ID_DATA,
417 
418 	UMEM_RANGE_ID_DEFAULT = 0,
419 	UMEM_RANGE_ID_HEAP,
420 	UMEM_RANGE_ID_MAX = UMEM_RANGE_ID_HEAP,
421 
422 #define KMEM_RANGE_COUNT        (KMEM_RANGE_ID_MAX + 1)
423 #define UMEM_RANGE_COUNT        (UMEM_RANGE_ID_MAX + 1)
424 });
425 
426 typedef vm_map_range_id_t       kmem_range_id_t;
427 
428 #define kmem_log2down(mask)     (31 - __builtin_clz(mask))
429 #define KMEM_RANGE_MAX          (UMEM_RANGE_ID_MAX < KMEM_RANGE_ID_MAX \
430 	                        ? KMEM_RANGE_ID_MAX : UMEM_RANGE_ID_MAX)
431 #define KMEM_RANGE_BITS         kmem_log2down(2 * KMEM_RANGE_MAX - 1)
432 
433 typedef union {
434 	struct {
435 		unsigned long long
436 		/*
437 		 * VM_FLAG_* flags
438 		 */
439 		    vmf_fixed:1,
440 		    vmf_purgeable:1,
441 		    vmf_4gb_chunk:1,
442 		    vmf_random_addr:1,
443 		    vmf_no_cache:1,
444 		    vmf_resilient_codesign:1,
445 		    vmf_resilient_media:1,
446 		    vmf_permanent:1,
447 
448 		    __unused_bit_8:1,
449 		    __unused_bit_9:1,
450 		    __unused_bit_10:1,
451 		    __unused_bit_11:1,
452 		    vmf_tpro:1,
453 		    __unused_bit_13:1,
454 		    vmf_overwrite:1,
455 		    __unused_bit_15:1,
456 
457 		    vmf_superpage_size:3,
458 		    __unused_bit_19:1,
459 		    vmf_return_data_addr:1,
460 		    __unused_bit_21:1,
461 		    __unused_bit_22:1,
462 		    vmf_return_4k_data_addr:1,
463 
464 		/*
465 		 * VM tag (user or kernel)
466 		 *
467 		 * User tags are limited to 8 bits,
468 		 * kernel tags can use up to 12 bits
469 		 * with -zt or similar features.
470 		 */
471 		    vm_tag : 12, /* same as VME_ALIAS_BITS */
472 
473 		/*
474 		 * General kernel flags
475 		 */
476 		    vmkf_already:1,             /* OK if same mapping already exists */
477 		    vmkf_beyond_max:1,          /* map beyond the map's max offset */
478 		    vmkf_no_pmap_check:1,       /* do not check that pmap is empty */
479 		    vmkf_map_jit:1,             /* mark entry as JIT region */
480 		    vmkf_iokit_acct:1,          /* IOKit accounting */
481 		    vmkf_keep_map_locked:1,     /* keep map locked when returning from vm_map_enter() */
482 		    vmkf_fourk:1,               /* use fourk pager */
483 		    vmkf_overwrite_immutable:1, /* can overwrite immutable mappings */
484 		    vmkf_remap_prot_copy:1,     /* vm_remap for VM_PROT_COPY */
485 		    vmkf_cs_enforcement_override:1,     /* override CS_ENFORCEMENT */
486 		    vmkf_cs_enforcement:1,      /* new value for CS_ENFORCEMENT */
487 		    vmkf_nested_pmap:1,         /* use a nested pmap */
488 		    vmkf_no_copy_on_read:1,     /* do not use copy_on_read */
489 		    vmkf_copy_single_object:1,  /* vm_map_copy only 1 VM object */
490 		    vmkf_copy_pageable:1,       /* vm_map_copy with pageable entries */
491 		    vmkf_copy_same_map:1,       /* vm_map_copy to remap in original map */
492 		    vmkf_translated_allow_execute:1,    /* allow execute in translated processes */
493 
494 		/*
495 		 * Submap creation, altering vm_map_enter() only
496 		 */
497 		    vmkf_submap:1,              /* mapping a VM submap */
498 		    vmkf_submap_atomic:1,       /* keep entry atomic (no splitting/coalescing) */
499 		    vmkf_submap_adjust:1,       /* the submap needs to be adjusted */
500 
501 		/*
502 		 * Flags altering the behavior of vm_map_locate_space()
503 		 */
504 		    vmkf_32bit_map_va:1,        /* allocate in low 32-bits range */
505 		    vmkf_guard_before:1,        /* guard page before the mapping */
506 		    vmkf_last_free:1,           /* find space from the end */
507 		    vmkf_range_id:KMEM_RANGE_BITS,      /* kmem range to allocate in */
508 
509 		    __vmkf_unused:2;
510 	};
511 
512 	/*
513 	 * do not access these directly,
514 	 * use vm_map_kernel_flags_check_vmflags*()
515 	 */
516 	uint32_t __vm_flags : 24;
517 } vm_map_kernel_flags_t;
518 
519 /*
520  * using this means that vmf_* flags can't be used
521  * until vm_map_kernel_flags_set_vmflags() is set,
522  * or some manual careful init is done.
523  *
524  * Prefer VM_MAP_KERNEL_FLAGS_(FIXED,ANYWHERE) instead.
525  */
526 #define VM_MAP_KERNEL_FLAGS_NONE \
527 	(vm_map_kernel_flags_t){ }
528 
529 #define VM_MAP_KERNEL_FLAGS_FIXED(...) \
530 	(vm_map_kernel_flags_t){ .vmf_fixed = true, __VA_ARGS__ }
531 
532 #define VM_MAP_KERNEL_FLAGS_ANYWHERE(...) \
533 	(vm_map_kernel_flags_t){ .vmf_fixed = false, __VA_ARGS__ }
534 
535 #define VM_MAP_KERNEL_FLAGS_FIXED_PERMANENT(...) \
536 	VM_MAP_KERNEL_FLAGS_FIXED(.vmf_permanent = true, __VA_ARGS__)
537 
538 #define VM_MAP_KERNEL_FLAGS_DATA_ANYWHERE(...) \
539 	VM_MAP_KERNEL_FLAGS_ANYWHERE(.vmkf_range_id = KMEM_RANGE_ID_DATA, __VA_ARGS__)
540 
541 typedef struct {
542 	unsigned int
543 	    vmnekf_ledger_tag:3,
544 	    vmnekf_ledger_no_footprint:1,
545 	    __vmnekf_unused:28;
546 } vm_named_entry_kernel_flags_t;
547 #define VM_NAMED_ENTRY_KERNEL_FLAGS_NONE (vm_named_entry_kernel_flags_t) {    \
548 	.vmnekf_ledger_tag = 0,                                                \
549 	.vmnekf_ledger_no_footprint = 0,                                       \
550 	.__vmnekf_unused = 0                                                   \
551 }
552 
553 #endif /* XNU_KERNEL_PRIVATE */
554 
555 /* current accounting postmark */
556 #define __VM_LEDGER_ACCOUNTING_POSTMARK 2019032600
557 
558 /* discrete values: */
559 #define VM_LEDGER_TAG_NONE      0x00000000
560 #define VM_LEDGER_TAG_DEFAULT   0x00000001
561 #define VM_LEDGER_TAG_NETWORK   0x00000002
562 #define VM_LEDGER_TAG_MEDIA     0x00000003
563 #define VM_LEDGER_TAG_GRAPHICS  0x00000004
564 #define VM_LEDGER_TAG_NEURAL    0x00000005
565 #define VM_LEDGER_TAG_MAX       0x00000005
566 #define VM_LEDGER_TAG_UNCHANGED ((int)-1)
567 
568 /* individual bits: */
569 #define VM_LEDGER_FLAG_NO_FOOTPRINT               (1 << 0)
570 #define VM_LEDGER_FLAG_NO_FOOTPRINT_FOR_DEBUG    (1 << 1)
571 #define VM_LEDGER_FLAGS (VM_LEDGER_FLAG_NO_FOOTPRINT | VM_LEDGER_FLAG_NO_FOOTPRINT_FOR_DEBUG)
572 
573 
574 #define VM_MEMORY_MALLOC 1
575 #define VM_MEMORY_MALLOC_SMALL 2
576 #define VM_MEMORY_MALLOC_LARGE 3
577 #define VM_MEMORY_MALLOC_HUGE 4
578 #define VM_MEMORY_SBRK 5// uninteresting -- no one should call
579 #define VM_MEMORY_REALLOC 6
580 #define VM_MEMORY_MALLOC_TINY 7
581 #define VM_MEMORY_MALLOC_LARGE_REUSABLE 8
582 #define VM_MEMORY_MALLOC_LARGE_REUSED 9
583 
584 #define VM_MEMORY_ANALYSIS_TOOL 10
585 
586 #define VM_MEMORY_MALLOC_NANO 11
587 #define VM_MEMORY_MALLOC_MEDIUM 12
588 #define VM_MEMORY_MALLOC_PGUARD 13  // Will be removed
589 #define VM_MEMORY_MALLOC_PROB_GUARD 13
590 
591 #define VM_MEMORY_MACH_MSG 20
592 #define VM_MEMORY_IOKIT 21
593 #define VM_MEMORY_STACK  30
594 #define VM_MEMORY_GUARD  31
595 #define VM_MEMORY_SHARED_PMAP 32
596 /* memory containing a dylib */
597 #define VM_MEMORY_DYLIB 33
598 #define VM_MEMORY_OBJC_DISPATCHERS 34
599 
600 /* Was a nested pmap (VM_MEMORY_SHARED_PMAP) which has now been unnested */
601 #define VM_MEMORY_UNSHARED_PMAP 35
602 
603 
604 // Placeholders for now -- as we analyze the libraries and find how they
605 // use memory, we can make these labels more specific.
606 #define VM_MEMORY_APPKIT 40
607 #define VM_MEMORY_FOUNDATION 41
608 #define VM_MEMORY_COREGRAPHICS 42
609 #define VM_MEMORY_CORESERVICES 43
610 #define VM_MEMORY_CARBON VM_MEMORY_CORESERVICES
611 #define VM_MEMORY_JAVA 44
612 #define VM_MEMORY_COREDATA 45
613 #define VM_MEMORY_COREDATA_OBJECTIDS 46
614 #define VM_MEMORY_ATS 50
615 #define VM_MEMORY_LAYERKIT 51
616 #define VM_MEMORY_CGIMAGE 52
617 #define VM_MEMORY_TCMALLOC 53
618 
619 /* private raster data (i.e. layers, some images, QGL allocator) */
620 #define VM_MEMORY_COREGRAPHICS_DATA     54
621 
622 /* shared image and font caches */
623 #define VM_MEMORY_COREGRAPHICS_SHARED   55
624 
625 /* Memory used for virtual framebuffers, shadowing buffers, etc... */
626 #define VM_MEMORY_COREGRAPHICS_FRAMEBUFFERS     56
627 
628 /* Window backing stores, custom shadow data, and compressed backing stores */
629 #define VM_MEMORY_COREGRAPHICS_BACKINGSTORES    57
630 
631 /* x-alloc'd memory */
632 #define VM_MEMORY_COREGRAPHICS_XALLOC 58
633 
634 /* catch-all for other uses, such as the read-only shared data page */
635 #define VM_MEMORY_COREGRAPHICS_MISC VM_MEMORY_COREGRAPHICS
636 
637 /* memory allocated by the dynamic loader for itself */
638 #define VM_MEMORY_DYLD 60
639 /* malloc'd memory created by dyld */
640 #define VM_MEMORY_DYLD_MALLOC 61
641 
642 /* Used for sqlite page cache */
643 #define VM_MEMORY_SQLITE 62
644 
645 /* JavaScriptCore heaps */
646 #define VM_MEMORY_JAVASCRIPT_CORE 63
647 #define VM_MEMORY_WEBASSEMBLY VM_MEMORY_JAVASCRIPT_CORE
648 /* memory allocated for the JIT */
649 #define VM_MEMORY_JAVASCRIPT_JIT_EXECUTABLE_ALLOCATOR 64
650 #define VM_MEMORY_JAVASCRIPT_JIT_REGISTER_FILE 65
651 
652 /* memory allocated for GLSL */
653 #define VM_MEMORY_GLSL  66
654 
655 /* memory allocated for OpenCL.framework */
656 #define VM_MEMORY_OPENCL    67
657 
658 /* memory allocated for QuartzCore.framework */
659 #define VM_MEMORY_COREIMAGE 68
660 
661 /* memory allocated for WebCore Purgeable Buffers */
662 #define VM_MEMORY_WEBCORE_PURGEABLE_BUFFERS 69
663 
664 /* ImageIO memory */
665 #define VM_MEMORY_IMAGEIO       70
666 
667 /* CoreProfile memory */
668 #define VM_MEMORY_COREPROFILE   71
669 
670 /* assetsd / MobileSlideShow memory */
671 #define VM_MEMORY_ASSETSD       72
672 
673 /* libsystem_kernel os_once_alloc */
674 #define VM_MEMORY_OS_ALLOC_ONCE 73
675 
676 /* libdispatch internal allocator */
677 #define VM_MEMORY_LIBDISPATCH 74
678 
679 /* Accelerate.framework image backing stores */
680 #define VM_MEMORY_ACCELERATE 75
681 
682 /* CoreUI image block data */
683 #define VM_MEMORY_COREUI 76
684 
685 /* CoreUI image file */
686 #define VM_MEMORY_COREUIFILE 77
687 
688 /* Genealogy buffers */
689 #define VM_MEMORY_GENEALOGY 78
690 
691 /* RawCamera VM allocated memory */
692 #define VM_MEMORY_RAWCAMERA 79
693 
694 /* corpse info for dead process */
695 #define VM_MEMORY_CORPSEINFO 80
696 
697 /* Apple System Logger (ASL) messages */
698 #define VM_MEMORY_ASL 81
699 
700 /* Swift runtime */
701 #define VM_MEMORY_SWIFT_RUNTIME 82
702 
703 /* Swift metadata */
704 #define VM_MEMORY_SWIFT_METADATA 83
705 
706 /* DHMM data */
707 #define VM_MEMORY_DHMM 84
708 
709 
710 /* memory allocated by SceneKit.framework */
711 #define VM_MEMORY_SCENEKIT 86
712 
713 /* memory allocated by skywalk networking */
714 #define VM_MEMORY_SKYWALK 87
715 
716 #define VM_MEMORY_IOSURFACE 88
717 
718 #define VM_MEMORY_LIBNETWORK 89
719 
720 #define VM_MEMORY_AUDIO 90
721 
722 #define VM_MEMORY_VIDEOBITSTREAM 91
723 
724 /* memory allocated by CoreMedia */
725 #define VM_MEMORY_CM_XPC 92
726 
727 #define VM_MEMORY_CM_RPC 93
728 
729 #define VM_MEMORY_CM_MEMORYPOOL 94
730 
731 #define VM_MEMORY_CM_READCACHE 95
732 
733 #define VM_MEMORY_CM_CRABS 96
734 
735 /* memory allocated for QuickLookThumbnailing */
736 #define VM_MEMORY_QUICKLOOK_THUMBNAILS 97
737 
738 /* memory allocated by Accounts framework */
739 #define VM_MEMORY_ACCOUNTS 98
740 
741 /* memory allocated by Sanitizer runtime libraries */
742 #define VM_MEMORY_SANITIZER 99
743 
744 /* Differentiate memory needed by GPU drivers and frameworks from generic IOKit allocations */
745 #define VM_MEMORY_IOACCELERATOR 100
746 
747 /* memory allocated by CoreMedia for global image registration of frames */
748 #define VM_MEMORY_CM_REGWARP 101
749 
750 /* memory allocated by EmbeddedAcousticRecognition for speech decoder */
751 #define VM_MEMORY_EAR_DECODER 102
752 
753 /* CoreUI cached image data */
754 #define VM_MEMORY_COREUI_CACHED_IMAGE_DATA 103
755 
756 /* ColorSync is using mmap for read-only copies of ICC profile data */
757 #define VM_MEMORY_COLORSYNC 104
758 
759 /* backtrace info for simulated crashes */
760 #define VM_MEMORY_BTINFO 105
761 
762 /* Reserve 230-239 for Rosetta */
763 #define VM_MEMORY_ROSETTA 230
764 #define VM_MEMORY_ROSETTA_THREAD_CONTEXT 231
765 #define VM_MEMORY_ROSETTA_INDIRECT_BRANCH_MAP 232
766 #define VM_MEMORY_ROSETTA_RETURN_STACK 233
767 #define VM_MEMORY_ROSETTA_EXECUTABLE_HEAP 234
768 #define VM_MEMORY_ROSETTA_USER_LDT 235
769 #define VM_MEMORY_ROSETTA_ARENA 236
770 #define VM_MEMORY_ROSETTA_10 239
771 
772 /* Reserve 240-255 for application */
773 #define VM_MEMORY_APPLICATION_SPECIFIC_1 240
774 #define VM_MEMORY_APPLICATION_SPECIFIC_16 255
775 
776 #define VM_MEMORY_COUNT 256
777 
778 #if !XNU_KERNEL_PRIVATE
779 #define VM_MAKE_TAG(tag) ((tag) << 24)
780 #endif /* XNU_KERNEL_PRIVATE */
781 
782 
783 #if KERNEL_PRIVATE
784 
785 /* kernel map tags */
786 /* please add new definition strings to zprint */
787 
788 #define VM_KERN_MEMORY_NONE             0
789 
790 #define VM_KERN_MEMORY_OSFMK            1
791 #define VM_KERN_MEMORY_BSD              2
792 #define VM_KERN_MEMORY_IOKIT            3
793 #define VM_KERN_MEMORY_LIBKERN          4
794 #define VM_KERN_MEMORY_OSKEXT           5
795 #define VM_KERN_MEMORY_KEXT             6
796 #define VM_KERN_MEMORY_IPC              7
797 #define VM_KERN_MEMORY_STACK            8
798 #define VM_KERN_MEMORY_CPU              9
799 #define VM_KERN_MEMORY_PMAP             10
800 #define VM_KERN_MEMORY_PTE              11
801 #define VM_KERN_MEMORY_ZONE             12
802 #define VM_KERN_MEMORY_KALLOC           13
803 #define VM_KERN_MEMORY_COMPRESSOR       14
804 #define VM_KERN_MEMORY_COMPRESSED_DATA  15
805 #define VM_KERN_MEMORY_PHANTOM_CACHE    16
806 #define VM_KERN_MEMORY_WAITQ            17
807 #define VM_KERN_MEMORY_DIAG             18
808 #define VM_KERN_MEMORY_LOG              19
809 #define VM_KERN_MEMORY_FILE             20
810 #define VM_KERN_MEMORY_MBUF             21
811 #define VM_KERN_MEMORY_UBC              22
812 #define VM_KERN_MEMORY_SECURITY         23
813 #define VM_KERN_MEMORY_MLOCK            24
814 #define VM_KERN_MEMORY_REASON           25
815 #define VM_KERN_MEMORY_SKYWALK          26
816 #define VM_KERN_MEMORY_LTABLE           27
817 #define VM_KERN_MEMORY_HV               28
818 #define VM_KERN_MEMORY_KALLOC_DATA      29
819 #define VM_KERN_MEMORY_RETIRED          30
820 #define VM_KERN_MEMORY_KALLOC_TYPE      31
821 #define VM_KERN_MEMORY_TRIAGE           32
822 #define VM_KERN_MEMORY_RECOUNT          33
823 /* add new tags here and adjust first-dynamic value */
824 #define VM_KERN_MEMORY_FIRST_DYNAMIC    34
825 
826 /* out of tags: */
827 #define VM_KERN_MEMORY_ANY              255
828 #define VM_KERN_MEMORY_COUNT            256
829 
830 /* end kernel map tags */
831 
832 // mach_memory_info.flags
833 #define VM_KERN_SITE_TYPE               0x000000FF
834 #define VM_KERN_SITE_TAG                0x00000000
835 #define VM_KERN_SITE_KMOD               0x00000001
836 #define VM_KERN_SITE_KERNEL             0x00000002
837 #define VM_KERN_SITE_COUNTER            0x00000003
838 #define VM_KERN_SITE_WIRED              0x00000100      /* add to wired count */
839 #define VM_KERN_SITE_HIDE               0x00000200      /* no zprint */
840 #define VM_KERN_SITE_NAMED              0x00000400
841 #define VM_KERN_SITE_ZONE               0x00000800
842 #define VM_KERN_SITE_ZONE_VIEW          0x00001000
843 #define VM_KERN_SITE_KALLOC             0x00002000      /* zone field is size class */
844 
845 #define VM_KERN_COUNT_MANAGED           0
846 #define VM_KERN_COUNT_RESERVED          1
847 #define VM_KERN_COUNT_WIRED             2
848 #define VM_KERN_COUNT_WIRED_MANAGED     3
849 #define VM_KERN_COUNT_STOLEN            4
850 #define VM_KERN_COUNT_LOPAGE            5
851 #define VM_KERN_COUNT_MAP_KERNEL        6
852 #define VM_KERN_COUNT_MAP_ZONE          7
853 #define VM_KERN_COUNT_MAP_KALLOC        8
854 
855 #define VM_KERN_COUNT_WIRED_BOOT    9
856 
857 #define VM_KERN_COUNT_BOOT_STOLEN       10
858 
859 /* The number of bytes from the kernel cache that are wired in memory */
860 #define VM_KERN_COUNT_WIRED_STATIC_KERNELCACHE 11
861 
862 #define VM_KERN_COUNT_MAP_KALLOC_LARGE  VM_KERN_COUNT_MAP_KALLOC
863 #define VM_KERN_COUNT_MAP_KALLOC_LARGE_DATA     12
864 #define VM_KERN_COUNT_MAP_KERNEL_DATA   13
865 
866 #define VM_KERN_COUNTER_COUNT           14
867 
868 #endif /* KERNEL_PRIVATE */
869 
870 __END_DECLS
871 
872 #endif  /* _MACH_VM_STATISTICS_H_ */
873