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