]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/vm_types.h
xnu-6153.121.1.tar.gz
[apple/xnu.git] / osfmk / mach / vm_types.h
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
40 typedef vm_offset_t pointer_t;
41 typedef vm_offset_t vm_address_t;
42
43 /*
44 * We use addr64_t for 64-bit addresses that are used on both
45 * 32 and 64-bit machines. On PPC, they are passed and returned as
46 * two adjacent 32-bit GPRs. We use addr64_t in places where
47 * common code must be useable both on 32 and 64-bit machines.
48 */
49 typedef uint64_t addr64_t; /* Basic effective address */
50
51 /*
52 * We use reg64_t for addresses that are 32 bits on a 32-bit
53 * machine, and 64 bits on a 64-bit machine, but are always
54 * passed and returned in a single GPR on PPC. This type
55 * cannot be used in generic 32-bit c, since on a 64-bit
56 * machine the upper half of the register will be ignored
57 * by the c compiler in 32-bit mode. In c, we can only use the
58 * type in prototypes of functions that are written in and called
59 * from assembly language. This type is basically a comment.
60 */
61 typedef uint32_t reg64_t;
62
63 /*
64 * To minimize the use of 64-bit fields, we keep some physical
65 * addresses (that are page aligned) as 32-bit page numbers.
66 * This limits the physical address space to 16TB of RAM.
67 */
68 typedef uint32_t ppnum_t; /* Physical page number */
69 #define PPNUM_MAX UINT32_MAX
70
71
72 #ifdef KERNEL_PRIVATE
73
74 #include <sys/cdefs.h>
75
76 #ifndef MACH_KERNEL_PRIVATE
77 /*
78 * Use specifically typed null structures for these in
79 * other parts of the kernel to enable compiler warnings
80 * about type mismatches, etc... Otherwise, these would
81 * be void*.
82 */
83 __BEGIN_DECLS
84
85 struct pmap;
86 struct _vm_map;
87 struct vm_object;
88
89 __END_DECLS
90
91 #endif /* MACH_KERNEL_PRIVATE */
92
93 typedef struct pmap *pmap_t;
94 typedef struct _vm_map *vm_map_t;
95 typedef struct vm_object *vm_object_t;
96 typedef struct vm_object_fault_info *vm_object_fault_info_t;
97
98 #define PMAP_NULL ((pmap_t) NULL)
99 #define VM_OBJECT_NULL ((vm_object_t) NULL)
100
101 #else /* KERNEL_PRIVATE */
102
103 typedef mach_port_t vm_map_t;
104
105 #endif /* KERNEL_PRIVATE */
106
107 #ifdef KERNEL
108 #define VM_MAP_NULL ((vm_map_t) NULL)
109 #else
110 #define VM_MAP_NULL ((vm_map_t) 0)
111 #endif
112
113 /*
114 * Evolving definitions, likely to change.
115 */
116
117 typedef uint64_t vm_object_offset_t;
118 typedef uint64_t vm_object_size_t;
119
120
121 #ifdef XNU_KERNEL_PRIVATE
122
123 #define VM_TAG_ACTIVE_UPDATE 1
124
125 typedef uint16_t vm_tag_t;
126
127 #define VM_TAG_NAME_LEN_MAX 0x7F
128 #define VM_TAG_NAME_LEN_SHIFT 0
129 #define VM_TAG_BT 0x0080
130 #define VM_TAG_UNLOAD 0x0100
131 #define VM_TAG_KMOD 0x0200
132
133 #if DEBUG || DEVELOPMENT
134 #define VM_MAX_TAG_ZONES 28
135 #else
136 #define VM_MAX_TAG_ZONES 0
137 #endif
138
139 #if VM_MAX_TAG_ZONES
140 // must be multiple of 64
141 #define VM_MAX_TAG_VALUE 1536
142 #else
143 #define VM_MAX_TAG_VALUE 256
144 #endif
145
146
147 #define ARRAY_COUNT(a) (sizeof((a)) / sizeof((a)[0]))
148
149 struct vm_allocation_total {
150 vm_tag_t tag;
151 uint64_t total;
152 };
153
154 struct vm_allocation_zone_total {
155 uint64_t total;
156 uint64_t peak;
157 uint32_t waste;
158 uint32_t wastediv;
159 };
160 typedef struct vm_allocation_zone_total vm_allocation_zone_total_t;
161
162 struct vm_allocation_site {
163 uint64_t total;
164 #if DEBUG || DEVELOPMENT
165 uint64_t peak;
166 #endif /* DEBUG || DEVELOPMENT */
167 uint64_t mapped;
168 int16_t refcount;
169 vm_tag_t tag;
170 uint16_t flags;
171 uint16_t subtotalscount;
172 struct vm_allocation_total subtotals[0];
173 /* char name[0]; -- this is placed after subtotals, see KA_NAME() */
174 };
175 typedef struct vm_allocation_site vm_allocation_site_t;
176
177 #define VM_ALLOC_SITE_STATIC(iflags, itag) \
178 static vm_allocation_site_t site __attribute__((section("__DATA, __data"))) \
179 = { .refcount = 2, .tag = (itag), .flags = (iflags) };
180
181 extern int vmrtf_extract(uint64_t, boolean_t, int, void *, int *);
182 extern unsigned int vmrtfaultinfo_bufsz(void);
183
184 #endif /* XNU_KERNEL_PRIVATE */
185
186 #ifdef KERNEL_PRIVATE
187
188 #ifndef MACH_KERNEL_PRIVATE
189
190 __BEGIN_DECLS
191
192 struct upl;
193 struct vm_map_copy;
194 struct vm_named_entry;
195
196 __END_DECLS
197
198 #endif /* MACH_KERNEL_PRIVATE */
199
200 typedef struct upl *upl_t;
201 typedef struct vm_map_copy *vm_map_copy_t;
202 typedef struct vm_named_entry *vm_named_entry_t;
203
204 #define VM_MAP_COPY_NULL ((vm_map_copy_t) NULL)
205
206 #else /* KERNEL_PRIVATE */
207
208 typedef mach_port_t upl_t;
209 typedef mach_port_t vm_named_entry_t;
210
211 #endif /* KERNEL_PRIVATE */
212
213 #ifdef KERNEL
214 #define UPL_NULL ((upl_t) NULL)
215 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) NULL)
216 #else
217 #define UPL_NULL ((upl_t) 0)
218 #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0)
219 #endif
220
221 #ifdef PRIVATE
222 typedef struct {
223 uint64_t rtfabstime; // mach_continuous_time at start of fault
224 uint64_t rtfduration; // fault service duration
225 uint64_t rtfaddr; // fault address
226 uint64_t rtfpc; // userspace program counter of thread incurring the fault
227 uint64_t rtftid; // thread ID
228 uint64_t rtfupid; // process identifier
229 uint64_t rtftype; // fault type
230 } vm_rtfault_record_t;
231 #endif
232 #endif /* _MACH_VM_TYPES_H_ */