+ integer_t resident_count; /* # of pages mapped (total)*/
+ integer_t resident_max; /* # of pages mapped (peak) */
+ integer_t wired_count; /* # of pages wired */
+
+ integer_t device;
+ integer_t device_peak;
+ integer_t internal;
+ integer_t internal_peak;
+ integer_t external;
+ integer_t external_peak;
+ integer_t reusable;
+ integer_t reusable_peak;
+ uint64_t compressed __attribute__((aligned(8)));
+ uint64_t compressed_peak __attribute__((aligned(8)));
+ uint64_t compressed_lifetime __attribute__((aligned(8)));
+};
+
+typedef struct pmap_statistics *pmap_statistics_t;
+
+#define PMAP_STATS_PEAK(field) \
+ MACRO_BEGIN \
+ if (field > field##_peak) { \
+ field##_peak = field; \
+ } \
+ MACRO_END
+
+#endif /* MACH_KERNEL_PRIVATE */
+
+/*
+ * VM allocation flags:
+ *
+ * VM_FLAGS_FIXED
+ * (really the absence of VM_FLAGS_ANYWHERE)
+ * Allocate new VM region at the specified virtual address, if possible.
+ *
+ * VM_FLAGS_ANYWHERE
+ * Allocate new VM region anywhere it would fit in the address space.
+ *
+ * VM_FLAGS_PURGABLE
+ * Create a purgable VM object for that new VM region.
+ *
+ * VM_FLAGS_4GB_CHUNK
+ * The new VM region will be chunked up into 4GB sized pieces.
+ *
+ * VM_FLAGS_NO_PMAP_CHECK
+ * (for DEBUG kernel config only, ignored for other configs)
+ * Do not check that there is no stale pmap mapping for the new VM region.
+ * This is useful for kernel memory allocations at bootstrap when building
+ * the initial kernel address space while some memory is already in use.
+ *
+ * VM_FLAGS_OVERWRITE
+ * The new VM region can replace existing VM regions if necessary
+ * (to be used in combination with VM_FLAGS_FIXED).
+ *
+ * VM_FLAGS_NO_CACHE
+ * Pages brought in to this VM region are placed on the speculative
+ * queue instead of the active queue. In other words, they are not
+ * cached so that they will be stolen first if memory runs low.
+ */
+
+#define VM_FLAGS_FIXED 0x0000
+#define VM_FLAGS_ANYWHERE 0x0001
+#define VM_FLAGS_PURGABLE 0x0002
+#define VM_FLAGS_4GB_CHUNK 0x0004
+#define VM_FLAGS_RANDOM_ADDR 0x0008
+#define VM_FLAGS_NO_CACHE 0x0010
+#define VM_FLAGS_RESILIENT_CODESIGN 0x0020
+#define VM_FLAGS_RESILIENT_MEDIA 0x0040
+#define VM_FLAGS_OVERWRITE 0x4000 /* delete any existing mappings first */
+/*
+ * VM_FLAGS_SUPERPAGE_MASK
+ * 3 bits that specify whether large pages should be used instead of
+ * base pages (!=0), as well as the requested page size.
+ */
+#define VM_FLAGS_SUPERPAGE_MASK 0x70000 /* bits 0x10000, 0x20000, 0x40000 */
+#define VM_FLAGS_RETURN_DATA_ADDR 0x100000 /* Return address of target data, rather than base of page */
+#define VM_FLAGS_RETURN_4K_DATA_ADDR 0x800000 /* Return 4K aligned address of target data */
+#define VM_FLAGS_ALIAS_MASK 0xFF000000
+#define VM_GET_FLAGS_ALIAS(flags, alias) \
+ (alias) = ((flags) & VM_FLAGS_ALIAS_MASK) >> 24
+#if !XNU_KERNEL_PRIVATE
+#define VM_SET_FLAGS_ALIAS(flags, alias) \
+ (flags) = (((flags) & ~VM_FLAGS_ALIAS_MASK) | \
+ (((alias) & ~VM_FLAGS_ALIAS_MASK) << 24))
+#endif /* !XNU_KERNEL_PRIVATE */
+
+/* These are the flags that we accept from user-space */
+#define VM_FLAGS_USER_ALLOCATE (VM_FLAGS_FIXED | \
+ VM_FLAGS_ANYWHERE | \
+ VM_FLAGS_PURGABLE | \
+ VM_FLAGS_4GB_CHUNK | \
+ VM_FLAGS_RANDOM_ADDR | \
+ VM_FLAGS_NO_CACHE | \
+ VM_FLAGS_OVERWRITE | \
+ VM_FLAGS_SUPERPAGE_MASK | \
+ VM_FLAGS_ALIAS_MASK)
+#define VM_FLAGS_USER_MAP (VM_FLAGS_USER_ALLOCATE | \
+ VM_FLAGS_RETURN_4K_DATA_ADDR | \
+ VM_FLAGS_RETURN_DATA_ADDR)
+#define VM_FLAGS_USER_REMAP (VM_FLAGS_FIXED | \
+ VM_FLAGS_ANYWHERE | \
+ VM_FLAGS_RANDOM_ADDR | \
+ VM_FLAGS_OVERWRITE| \
+ VM_FLAGS_RETURN_DATA_ADDR | \
+ VM_FLAGS_RESILIENT_CODESIGN | \
+ VM_FLAGS_RESILIENT_MEDIA)
+
+#define VM_FLAGS_SUPERPAGE_SHIFT 16
+#define SUPERPAGE_NONE 0 /* no superpages, if all bits are 0 */
+#define SUPERPAGE_SIZE_ANY 1
+#define VM_FLAGS_SUPERPAGE_NONE (SUPERPAGE_NONE << VM_FLAGS_SUPERPAGE_SHIFT)
+#define VM_FLAGS_SUPERPAGE_SIZE_ANY (SUPERPAGE_SIZE_ANY << VM_FLAGS_SUPERPAGE_SHIFT)
+#if defined(__x86_64__) || !defined(KERNEL)
+#define SUPERPAGE_SIZE_2MB 2
+#define VM_FLAGS_SUPERPAGE_SIZE_2MB (SUPERPAGE_SIZE_2MB<<VM_FLAGS_SUPERPAGE_SHIFT)
+#endif
+
+/*
+ * EXC_GUARD definitions for virtual memory.
+ */
+#define GUARD_TYPE_VIRT_MEMORY 0x5
+
+/* Reasons for exception for virtual memory */
+enum virtual_memory_guard_exception_codes {
+ kGUARD_EXC_DEALLOC_GAP = 1u << 0