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 | __BEGIN_DECLS |
42 | |
43 | typedef vm_offset_t pointer_t __kernel_ptr_semantics; |
44 | typedef vm_offset_t vm_address_t __kernel_ptr_semantics; |
45 | |
46 | /* |
47 | * We use addr64_t for 64-bit addresses that are used on both |
48 | * 32 and 64-bit machines. On PPC, they are passed and returned as |
49 | * two adjacent 32-bit GPRs. We use addr64_t in places where |
50 | * common code must be useable both on 32 and 64-bit machines. |
51 | */ |
52 | typedef uint64_t addr64_t; /* Basic effective address */ |
53 | |
54 | /* |
55 | * We use reg64_t for addresses that are 32 bits on a 32-bit |
56 | * machine, and 64 bits on a 64-bit machine, but are always |
57 | * passed and returned in a single GPR on PPC. This type |
58 | * cannot be used in generic 32-bit c, since on a 64-bit |
59 | * machine the upper half of the register will be ignored |
60 | * by the c compiler in 32-bit mode. In c, we can only use the |
61 | * type in prototypes of functions that are written in and called |
62 | * from assembly language. This type is basically a comment. |
63 | */ |
64 | typedef uint32_t reg64_t; |
65 | |
66 | /* |
67 | * To minimize the use of 64-bit fields, we keep some physical |
68 | * addresses (that are page aligned) as 32-bit page numbers. |
69 | * This limits the physical address space to 16TB of RAM. |
70 | */ |
71 | typedef uint32_t ppnum_t __kernel_ptr_semantics; /* Physical page number */ |
72 | #define PPNUM_MAX UINT32_MAX |
73 | |
74 | #ifdef KERNEL_PRIVATE |
75 | |
76 | __options_decl(vm_map_create_options_t, uint32_t, { |
77 | VM_MAP_CREATE_DEFAULT = 0x00000000, |
78 | VM_MAP_CREATE_PAGEABLE = 0x00000001, |
79 | = 0x00000002, |
80 | VM_MAP_CREATE_DISABLE_HOLELIST = 0x00000004, |
81 | VM_MAP_CREATE_NEVER_FAULTS = 0x00000008, |
82 | }); |
83 | |
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 | |
91 | typedef struct pmap *pmap_t; |
92 | typedef struct _vm_map *vm_map_t, *vm_map_read_t, *vm_map_inspect_t; |
93 | typedef struct vm_object *vm_object_t; |
94 | typedef struct vm_object_fault_info *vm_object_fault_info_t; |
95 | typedef struct upl *upl_t; |
96 | typedef struct vm_map_copy *vm_map_copy_t; |
97 | typedef struct vm_named_entry *vm_named_entry_t; |
98 | |
99 | #define PMAP_NULL ((pmap_t) NULL) |
100 | #define VM_OBJECT_NULL ((vm_object_t) NULL) |
101 | #define VM_MAP_COPY_NULL ((vm_map_copy_t) NULL) |
102 | |
103 | #else /* KERNEL_PRIVATE */ |
104 | |
105 | typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; |
106 | typedef mach_port_t upl_t; |
107 | typedef mach_port_t vm_named_entry_t; |
108 | |
109 | #endif /* KERNEL_PRIVATE */ |
110 | |
111 | #ifdef KERNEL |
112 | #define VM_MAP_NULL ((vm_map_t) NULL) |
113 | #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) NULL) |
114 | #define VM_MAP_READ_NULL ((vm_map_read_t) NULL) |
115 | #define UPL_NULL ((upl_t) NULL) |
116 | #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) NULL) |
117 | #else |
118 | #define VM_MAP_NULL ((vm_map_t) 0) |
119 | #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) |
120 | #define VM_MAP_READ_NULL ((vm_map_read_t) 0) |
121 | #define UPL_NULL ((upl_t) 0) |
122 | #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) |
123 | #endif |
124 | |
125 | /* |
126 | * Evolving definitions, likely to change. |
127 | */ |
128 | |
129 | typedef uint64_t vm_object_offset_t; |
130 | typedef uint64_t vm_object_size_t; |
131 | |
132 | /*! |
133 | * @typedef mach_vm_range_t |
134 | * |
135 | * @brief |
136 | * Pair of a min/max address used to denote a memory region. |
137 | * |
138 | * @discussion |
139 | * @c min_address must be smaller or equal to @c max_address. |
140 | */ |
141 | typedef struct mach_vm_range { |
142 | mach_vm_offset_t min_address; |
143 | mach_vm_offset_t max_address; |
144 | } *mach_vm_range_t; |
145 | |
146 | /*! |
147 | * @enum mach_vm_range_flavor_t |
148 | * |
149 | * @brief |
150 | * A flavor for the mach_vm_range_create() call. |
151 | * |
152 | * @const MACH_VM_RANGE_FLAVOR_V1 |
153 | * The recipe is an array of @c mach_vm_range_recipe_v1_t. |
154 | */ |
155 | __enum_decl(mach_vm_range_flavor_t, uint32_t, { |
156 | MACH_VM_RANGE_FLAVOR_INVALID, |
157 | MACH_VM_RANGE_FLAVOR_V1, |
158 | }); |
159 | |
160 | |
161 | /*! |
162 | * @enum mach_vm_range_flags_t |
163 | * |
164 | * @brief |
165 | * Flags used to alter the behavior of a Mach VM Range. |
166 | */ |
167 | __options_decl(mach_vm_range_flags_t, uint64_t, { |
168 | MACH_VM_RANGE_NONE = 0x000000000000, |
169 | }); |
170 | |
171 | |
172 | /*! |
173 | * @enum mach_vm_range_tag_t |
174 | * |
175 | * @brief |
176 | * A tag to denote the semantics of a given Mach VM Range. |
177 | * |
178 | * @const MACH_VM_RANGE_DEFAULT |
179 | * The tag associated with the general VA space usable |
180 | * before the shared cache. |
181 | * Such a range can't be made by userspace. |
182 | * |
183 | * @const MACH_VM_RANGE_DATA |
184 | * The tag associated with the anonymous randomly slid |
185 | * range of data heap optionally made when a process is created. |
186 | * Such a range can't be made by userspace. |
187 | * |
188 | * @const MACH_VM_RANGE_FIXED |
189 | * The tag associated with ranges that are made available |
190 | * for @c VM_FLAGS_FIXED allocations, but that the VM will never |
191 | * autonomously serve from a @c VM_FLAGS_ANYWHERE kind of request. |
192 | * This really create a delegated piece of VA that can be carved out |
193 | * in the way userspace sees fit. |
194 | */ |
195 | __enum_decl(mach_vm_range_tag_t, uint16_t, { |
196 | MACH_VM_RANGE_DEFAULT, |
197 | MACH_VM_RANGE_DATA, |
198 | MACH_VM_RANGE_FIXED, |
199 | }); |
200 | |
201 | #pragma pack(1) |
202 | |
203 | typedef struct { |
204 | mach_vm_range_flags_t flags: 48; |
205 | mach_vm_range_tag_t range_tag : 8; |
206 | uint8_t vm_tag : 8; |
207 | struct mach_vm_range range; |
208 | } mach_vm_range_recipe_v1_t; |
209 | |
210 | #pragma pack() |
211 | |
212 | #define MACH_VM_RANGE_FLAVOR_DEFAULT MACH_VM_RANGE_FLAVOR_V1 |
213 | typedef mach_vm_range_recipe_v1_t mach_vm_range_recipe_t; |
214 | |
215 | typedef uint8_t *mach_vm_range_recipes_raw_t; |
216 | |
217 | #ifdef PRIVATE |
218 | |
219 | typedef struct { |
220 | uint64_t rtfabstime; // mach_continuous_time at start of fault |
221 | uint64_t rtfduration; // fault service duration |
222 | uint64_t rtfaddr; // fault address |
223 | uint64_t rtfpc; // userspace program counter of thread incurring the fault |
224 | uint64_t rtftid; // thread ID |
225 | uint64_t rtfupid; // process identifier |
226 | uint64_t rtftype; // fault type |
227 | } vm_rtfault_record_t; |
228 | |
229 | #endif /* PRIVATE */ |
230 | #ifdef XNU_KERNEL_PRIVATE |
231 | |
232 | #define VM_TAG_ACTIVE_UPDATE 1 |
233 | |
234 | typedef uint16_t vm_tag_t; |
235 | |
236 | #define VM_TAG_NAME_LEN_MAX 0x7F |
237 | #define VM_TAG_NAME_LEN_SHIFT 0 |
238 | #define VM_TAG_UNLOAD 0x0100 |
239 | #define VM_TAG_KMOD 0x0200 |
240 | |
241 | #if !KASAN && (DEBUG || DEVELOPMENT) |
242 | /* |
243 | * To track the utilization of memory at every kalloc callsite, zone tagging |
244 | * allocates an array of stats (of size VM_TAG_SIZECLASSES), one for each |
245 | * size class exposed by kalloc. |
246 | * |
247 | * If VM_TAG_SIZECLASSES is modified ensure that z_tags_sizeclass |
248 | * has sufficient bits to represent all values (max value exclusive). |
249 | */ |
250 | #define VM_TAG_SIZECLASSES 36 |
251 | // must be multiple of 64 |
252 | #define VM_MAX_TAG_VALUE 1536 |
253 | #else |
254 | #define VM_TAG_SIZECLASSES 0 |
255 | #define VM_MAX_TAG_VALUE 256 |
256 | #endif |
257 | |
258 | #define ARRAY_COUNT(a) (sizeof((a)) / sizeof((a)[0])) |
259 | |
260 | struct vm_allocation_total { |
261 | vm_tag_t tag; |
262 | uint64_t total; |
263 | }; |
264 | |
265 | struct vm_allocation_zone_total { |
266 | vm_size_t vazt_total; |
267 | vm_size_t vazt_peak; |
268 | }; |
269 | typedef struct vm_allocation_zone_total vm_allocation_zone_total_t; |
270 | |
271 | struct vm_allocation_site { |
272 | uint64_t total; |
273 | #if DEBUG || DEVELOPMENT |
274 | uint64_t peak; |
275 | #endif /* DEBUG || DEVELOPMENT */ |
276 | uint64_t mapped; |
277 | int16_t refcount; |
278 | vm_tag_t tag; |
279 | uint16_t flags; |
280 | uint16_t subtotalscount; |
281 | struct vm_allocation_total subtotals[0]; |
282 | /* char name[0]; -- this is placed after subtotals, see KA_NAME() */ |
283 | }; |
284 | typedef struct vm_allocation_site vm_allocation_site_t; |
285 | |
286 | extern int (uint64_t, boolean_t, unsigned long, void *, unsigned long *); |
287 | extern unsigned int vmrtfaultinfo_bufsz(void); |
288 | |
289 | #endif /* XNU_KERNEL_PRIVATE */ |
290 | |
291 | __END_DECLS |
292 | |
293 | #endif /* _MACH_VM_TYPES_H_ */ |
294 | |