xref: /xnu-8796.121.2/osfmk/mach/vm_types.h (revision c54f35ca767986246321eb901baf8f5ff7923f6a)
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 __kernel_ptr_semantics; /* 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 // must be multiple of 64
168 #define VM_MAX_TAG_VALUE        1536
169 #else
170 #define VM_TAG_SIZECLASSES      0
171 #define VM_MAX_TAG_VALUE        256
172 #endif
173 
174 #define ARRAY_COUNT(a)  (sizeof((a)) / sizeof((a)[0]))
175 
176 struct vm_allocation_total {
177 	vm_tag_t tag;
178 	uint64_t total;
179 };
180 
181 struct vm_allocation_zone_total {
182 	vm_size_t vazt_total;
183 	vm_size_t vazt_peak;
184 };
185 typedef struct vm_allocation_zone_total vm_allocation_zone_total_t;
186 
187 struct vm_allocation_site {
188 	uint64_t  total;
189 #if DEBUG || DEVELOPMENT
190 	uint64_t  peak;
191 #endif /* DEBUG || DEVELOPMENT */
192 	uint64_t  mapped;
193 	int16_t   refcount;
194 	vm_tag_t  tag;
195 	uint16_t  flags;
196 	uint16_t  subtotalscount;
197 	struct vm_allocation_total subtotals[0];
198 	/* char      name[0]; -- this is placed after subtotals, see KA_NAME() */
199 };
200 typedef struct vm_allocation_site vm_allocation_site_t;
201 
202 extern int vmrtf_extract(uint64_t, boolean_t, unsigned long, void *, unsigned long *);
203 extern unsigned int vmrtfaultinfo_bufsz(void);
204 
205 #endif /* XNU_KERNEL_PRIVATE */
206 
207 #ifdef  KERNEL_PRIVATE
208 
209 #ifndef MACH_KERNEL_PRIVATE
210 
211 __BEGIN_DECLS
212 
213 struct upl;
214 struct vm_map_copy;
215 struct vm_named_entry;
216 
217 __END_DECLS
218 
219 #endif  /* MACH_KERNEL_PRIVATE */
220 
221 typedef struct upl              *upl_t;
222 typedef struct vm_map_copy      *vm_map_copy_t;
223 typedef struct vm_named_entry   *vm_named_entry_t;
224 
225 #define VM_MAP_COPY_NULL        ((vm_map_copy_t) NULL)
226 
227 #else   /* KERNEL_PRIVATE */
228 
229 typedef mach_port_t             upl_t;
230 typedef mach_port_t             vm_named_entry_t;
231 
232 #endif  /* KERNEL_PRIVATE */
233 
234 #ifdef KERNEL
235 #define UPL_NULL                ((upl_t) NULL)
236 #define VM_NAMED_ENTRY_NULL     ((vm_named_entry_t) NULL)
237 #else
238 #define UPL_NULL                ((upl_t) 0)
239 #define VM_NAMED_ENTRY_NULL     ((vm_named_entry_t) 0)
240 #endif
241 
242 #ifdef PRIVATE
243 typedef struct {
244 	uint64_t rtfabstime; // mach_continuous_time at start of fault
245 	uint64_t rtfduration; // fault service duration
246 	uint64_t rtfaddr; // fault address
247 	uint64_t rtfpc; // userspace program counter of thread incurring the fault
248 	uint64_t rtftid; // thread ID
249 	uint64_t rtfupid; // process identifier
250 	uint64_t rtftype; // fault type
251 } vm_rtfault_record_t;
252 #endif
253 #endif  /* _MACH_VM_TYPES_H_ */
254