xref: /xnu-11215.61.5/osfmk/mach/vm_types.h (revision 4f1223e81cd707a65cc109d0b8ad6653699da3c4)
1*4f1223e8SApple OSS Distributions /*
2*4f1223e8SApple OSS Distributions  * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
3*4f1223e8SApple OSS Distributions  *
4*4f1223e8SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*4f1223e8SApple OSS Distributions  *
6*4f1223e8SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*4f1223e8SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*4f1223e8SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*4f1223e8SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*4f1223e8SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*4f1223e8SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*4f1223e8SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*4f1223e8SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*4f1223e8SApple OSS Distributions  *
15*4f1223e8SApple OSS Distributions  * Please obtain a copy of the License at
16*4f1223e8SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*4f1223e8SApple OSS Distributions  *
18*4f1223e8SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*4f1223e8SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*4f1223e8SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*4f1223e8SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*4f1223e8SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*4f1223e8SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*4f1223e8SApple OSS Distributions  * limitations under the License.
25*4f1223e8SApple OSS Distributions  *
26*4f1223e8SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*4f1223e8SApple OSS Distributions  */
28*4f1223e8SApple OSS Distributions /*
29*4f1223e8SApple OSS Distributions  * @OSF_COPYRIGHT@
30*4f1223e8SApple OSS Distributions  *
31*4f1223e8SApple OSS Distributions  */
32*4f1223e8SApple OSS Distributions #ifndef _MACH_VM_TYPES_H_
33*4f1223e8SApple OSS Distributions #define _MACH_VM_TYPES_H_
34*4f1223e8SApple OSS Distributions 
35*4f1223e8SApple OSS Distributions #include <mach/port.h>
36*4f1223e8SApple OSS Distributions #include <mach/machine/vm_types.h>
37*4f1223e8SApple OSS Distributions 
38*4f1223e8SApple OSS Distributions #include <stdint.h>
39*4f1223e8SApple OSS Distributions #include <sys/cdefs.h>
40*4f1223e8SApple OSS Distributions 
41*4f1223e8SApple OSS Distributions __BEGIN_DECLS
42*4f1223e8SApple OSS Distributions 
43*4f1223e8SApple OSS Distributions typedef vm_offset_t             pointer_t __kernel_ptr_semantics;
44*4f1223e8SApple OSS Distributions typedef vm_offset_t             vm_address_t __kernel_ptr_semantics;
45*4f1223e8SApple OSS Distributions 
46*4f1223e8SApple OSS Distributions /*
47*4f1223e8SApple OSS Distributions  * We use addr64_t for 64-bit addresses that are used on both
48*4f1223e8SApple OSS Distributions  * 32 and 64-bit machines.  On PPC, they are passed and returned as
49*4f1223e8SApple OSS Distributions  * two adjacent 32-bit GPRs.  We use addr64_t in places where
50*4f1223e8SApple OSS Distributions  * common code must be useable both on 32 and 64-bit machines.
51*4f1223e8SApple OSS Distributions  */
52*4f1223e8SApple OSS Distributions typedef uint64_t addr64_t;              /* Basic effective address */
53*4f1223e8SApple OSS Distributions 
54*4f1223e8SApple OSS Distributions /*
55*4f1223e8SApple OSS Distributions  * We use reg64_t for addresses that are 32 bits on a 32-bit
56*4f1223e8SApple OSS Distributions  * machine, and 64 bits on a 64-bit machine, but are always
57*4f1223e8SApple OSS Distributions  * passed and returned in a single GPR on PPC.  This type
58*4f1223e8SApple OSS Distributions  * cannot be used in generic 32-bit c, since on a 64-bit
59*4f1223e8SApple OSS Distributions  * machine the upper half of the register will be ignored
60*4f1223e8SApple OSS Distributions  * by the c compiler in 32-bit mode.  In c, we can only use the
61*4f1223e8SApple OSS Distributions  * type in prototypes of functions that are written in and called
62*4f1223e8SApple OSS Distributions  * from assembly language.  This type is basically a comment.
63*4f1223e8SApple OSS Distributions  */
64*4f1223e8SApple OSS Distributions typedef uint32_t        reg64_t;
65*4f1223e8SApple OSS Distributions 
66*4f1223e8SApple OSS Distributions /*
67*4f1223e8SApple OSS Distributions  * To minimize the use of 64-bit fields, we keep some physical
68*4f1223e8SApple OSS Distributions  * addresses (that are page aligned) as 32-bit page numbers.
69*4f1223e8SApple OSS Distributions  * This limits the physical address space to 16TB of RAM.
70*4f1223e8SApple OSS Distributions  */
71*4f1223e8SApple OSS Distributions typedef uint32_t ppnum_t __kernel_ptr_semantics; /* Physical page number */
72*4f1223e8SApple OSS Distributions #define PPNUM_MAX UINT32_MAX
73*4f1223e8SApple OSS Distributions 
74*4f1223e8SApple OSS Distributions #ifdef  KERNEL_PRIVATE
75*4f1223e8SApple OSS Distributions 
76*4f1223e8SApple OSS Distributions __options_decl(vm_map_create_options_t, uint32_t, {
77*4f1223e8SApple OSS Distributions 	VM_MAP_CREATE_DEFAULT          = 0x00000000,
78*4f1223e8SApple OSS Distributions 	VM_MAP_CREATE_PAGEABLE         = 0x00000001,
79*4f1223e8SApple OSS Distributions 	VM_MAP_CREATE_CORPSE_FOOTPRINT = 0x00000002,
80*4f1223e8SApple OSS Distributions 	VM_MAP_CREATE_DISABLE_HOLELIST = 0x00000004,
81*4f1223e8SApple OSS Distributions 	VM_MAP_CREATE_NEVER_FAULTS     = 0x00000008,
82*4f1223e8SApple OSS Distributions });
83*4f1223e8SApple OSS Distributions 
84*4f1223e8SApple OSS Distributions /*
85*4f1223e8SApple OSS Distributions  * Use specifically typed null structures for these in
86*4f1223e8SApple OSS Distributions  * other parts of the kernel to enable compiler warnings
87*4f1223e8SApple OSS Distributions  * about type mismatches, etc...  Otherwise, these would
88*4f1223e8SApple OSS Distributions  * be void*.
89*4f1223e8SApple OSS Distributions  */
90*4f1223e8SApple OSS Distributions 
91*4f1223e8SApple OSS Distributions typedef struct pmap             *pmap_t;
92*4f1223e8SApple OSS Distributions typedef struct _vm_map          *vm_map_t, *vm_map_read_t, *vm_map_inspect_t;
93*4f1223e8SApple OSS Distributions typedef struct vm_object        *vm_object_t;
94*4f1223e8SApple OSS Distributions typedef struct vm_object_fault_info     *vm_object_fault_info_t;
95*4f1223e8SApple OSS Distributions typedef struct upl              *upl_t;
96*4f1223e8SApple OSS Distributions typedef struct vm_map_copy      *vm_map_copy_t;
97*4f1223e8SApple OSS Distributions typedef struct vm_named_entry   *vm_named_entry_t;
98*4f1223e8SApple OSS Distributions typedef struct vm_page          *vm_page_t;
99*4f1223e8SApple OSS Distributions 
100*4f1223e8SApple OSS Distributions #define PMAP_NULL               ((pmap_t) NULL)
101*4f1223e8SApple OSS Distributions #define VM_OBJECT_NULL          ((vm_object_t) NULL)
102*4f1223e8SApple OSS Distributions #define VM_MAP_COPY_NULL        ((vm_map_copy_t) NULL)
103*4f1223e8SApple OSS Distributions 
104*4f1223e8SApple OSS Distributions #else   /* KERNEL_PRIVATE */
105*4f1223e8SApple OSS Distributions 
106*4f1223e8SApple OSS Distributions typedef mach_port_t             vm_map_t, vm_map_read_t, vm_map_inspect_t;
107*4f1223e8SApple OSS Distributions typedef mach_port_t             upl_t;
108*4f1223e8SApple OSS Distributions typedef mach_port_t             vm_named_entry_t;
109*4f1223e8SApple OSS Distributions 
110*4f1223e8SApple OSS Distributions #endif  /* KERNEL_PRIVATE */
111*4f1223e8SApple OSS Distributions 
112*4f1223e8SApple OSS Distributions #ifdef KERNEL
113*4f1223e8SApple OSS Distributions #define VM_MAP_NULL             ((vm_map_t) NULL)
114*4f1223e8SApple OSS Distributions #define VM_MAP_INSPECT_NULL     ((vm_map_inspect_t) NULL)
115*4f1223e8SApple OSS Distributions #define VM_MAP_READ_NULL        ((vm_map_read_t) NULL)
116*4f1223e8SApple OSS Distributions #define UPL_NULL                ((upl_t) NULL)
117*4f1223e8SApple OSS Distributions #define VM_NAMED_ENTRY_NULL     ((vm_named_entry_t) NULL)
118*4f1223e8SApple OSS Distributions #else
119*4f1223e8SApple OSS Distributions #define VM_MAP_NULL             ((vm_map_t) 0)
120*4f1223e8SApple OSS Distributions #define VM_MAP_INSPECT_NULL     ((vm_map_inspect_t) 0)
121*4f1223e8SApple OSS Distributions #define VM_MAP_READ_NULL        ((vm_map_read_t) 0)
122*4f1223e8SApple OSS Distributions #define UPL_NULL                ((upl_t) 0)
123*4f1223e8SApple OSS Distributions #define VM_NAMED_ENTRY_NULL     ((vm_named_entry_t) 0)
124*4f1223e8SApple OSS Distributions #endif
125*4f1223e8SApple OSS Distributions 
126*4f1223e8SApple OSS Distributions /*
127*4f1223e8SApple OSS Distributions  * Evolving definitions, likely to change.
128*4f1223e8SApple OSS Distributions  */
129*4f1223e8SApple OSS Distributions 
130*4f1223e8SApple OSS Distributions typedef uint64_t                vm_object_offset_t;
131*4f1223e8SApple OSS Distributions typedef uint64_t                vm_object_size_t;
132*4f1223e8SApple OSS Distributions 
133*4f1223e8SApple OSS Distributions /*!
134*4f1223e8SApple OSS Distributions  * @typedef mach_vm_range_t
135*4f1223e8SApple OSS Distributions  *
136*4f1223e8SApple OSS Distributions  * @brief
137*4f1223e8SApple OSS Distributions  * Pair of a min/max address used to denote a memory region.
138*4f1223e8SApple OSS Distributions  *
139*4f1223e8SApple OSS Distributions  * @discussion
140*4f1223e8SApple OSS Distributions  * @c min_address must be smaller or equal to @c max_address.
141*4f1223e8SApple OSS Distributions  */
142*4f1223e8SApple OSS Distributions typedef struct mach_vm_range {
143*4f1223e8SApple OSS Distributions 	mach_vm_offset_t        min_address;
144*4f1223e8SApple OSS Distributions 	mach_vm_offset_t        max_address;
145*4f1223e8SApple OSS Distributions } *mach_vm_range_t;
146*4f1223e8SApple OSS Distributions 
147*4f1223e8SApple OSS Distributions /*!
148*4f1223e8SApple OSS Distributions  * @enum mach_vm_range_flavor_t
149*4f1223e8SApple OSS Distributions  *
150*4f1223e8SApple OSS Distributions  * @brief
151*4f1223e8SApple OSS Distributions  * A flavor for the mach_vm_range_create() call.
152*4f1223e8SApple OSS Distributions  *
153*4f1223e8SApple OSS Distributions  * @const MACH_VM_RANGE_FLAVOR_V1
154*4f1223e8SApple OSS Distributions  * The recipe is an array of @c mach_vm_range_recipe_v1_t.
155*4f1223e8SApple OSS Distributions  */
156*4f1223e8SApple OSS Distributions __enum_decl(mach_vm_range_flavor_t, uint32_t, {
157*4f1223e8SApple OSS Distributions 	MACH_VM_RANGE_FLAVOR_INVALID,
158*4f1223e8SApple OSS Distributions 	MACH_VM_RANGE_FLAVOR_V1,
159*4f1223e8SApple OSS Distributions });
160*4f1223e8SApple OSS Distributions 
161*4f1223e8SApple OSS Distributions 
162*4f1223e8SApple OSS Distributions /*!
163*4f1223e8SApple OSS Distributions  * @enum mach_vm_range_flags_t
164*4f1223e8SApple OSS Distributions  *
165*4f1223e8SApple OSS Distributions  * @brief
166*4f1223e8SApple OSS Distributions  * Flags used to alter the behavior of a Mach VM Range.
167*4f1223e8SApple OSS Distributions  */
168*4f1223e8SApple OSS Distributions __options_decl(mach_vm_range_flags_t, uint64_t, {
169*4f1223e8SApple OSS Distributions 	MACH_VM_RANGE_NONE      = 0x000000000000,
170*4f1223e8SApple OSS Distributions });
171*4f1223e8SApple OSS Distributions 
172*4f1223e8SApple OSS Distributions 
173*4f1223e8SApple OSS Distributions /*!
174*4f1223e8SApple OSS Distributions  * @enum mach_vm_range_tag_t
175*4f1223e8SApple OSS Distributions  *
176*4f1223e8SApple OSS Distributions  * @brief
177*4f1223e8SApple OSS Distributions  * A tag to denote the semantics of a given Mach VM Range.
178*4f1223e8SApple OSS Distributions  *
179*4f1223e8SApple OSS Distributions  * @const MACH_VM_RANGE_DEFAULT
180*4f1223e8SApple OSS Distributions  * The tag associated with the general VA space usable
181*4f1223e8SApple OSS Distributions  * before the shared cache.
182*4f1223e8SApple OSS Distributions  * Such a range can't be made by userspace.
183*4f1223e8SApple OSS Distributions  *
184*4f1223e8SApple OSS Distributions  * @const MACH_VM_RANGE_DATA
185*4f1223e8SApple OSS Distributions  * The tag associated with the anonymous randomly slid
186*4f1223e8SApple OSS Distributions  * range of data heap optionally made when a process is created.
187*4f1223e8SApple OSS Distributions  * Such a range can't be made by userspace.
188*4f1223e8SApple OSS Distributions  *
189*4f1223e8SApple OSS Distributions  * @const MACH_VM_RANGE_FIXED
190*4f1223e8SApple OSS Distributions  * The tag associated with ranges that are made available
191*4f1223e8SApple OSS Distributions  * for @c VM_FLAGS_FIXED allocations, but that the VM will never
192*4f1223e8SApple OSS Distributions  * autonomously serve from a @c VM_FLAGS_ANYWHERE kind of request.
193*4f1223e8SApple OSS Distributions  * This really create a delegated piece of VA that can be carved out
194*4f1223e8SApple OSS Distributions  * in the way userspace sees fit.
195*4f1223e8SApple OSS Distributions  */
196*4f1223e8SApple OSS Distributions __enum_decl(mach_vm_range_tag_t, uint16_t, {
197*4f1223e8SApple OSS Distributions 	MACH_VM_RANGE_DEFAULT,
198*4f1223e8SApple OSS Distributions 	MACH_VM_RANGE_DATA,
199*4f1223e8SApple OSS Distributions 	MACH_VM_RANGE_FIXED,
200*4f1223e8SApple OSS Distributions });
201*4f1223e8SApple OSS Distributions 
202*4f1223e8SApple OSS Distributions #pragma pack(1)
203*4f1223e8SApple OSS Distributions 
204*4f1223e8SApple OSS Distributions typedef struct {
205*4f1223e8SApple OSS Distributions 	mach_vm_range_flags_t   flags: 48;
206*4f1223e8SApple OSS Distributions 	mach_vm_range_tag_t     range_tag  : 8;
207*4f1223e8SApple OSS Distributions 	uint8_t                 vm_tag : 8;
208*4f1223e8SApple OSS Distributions 	struct mach_vm_range    range;
209*4f1223e8SApple OSS Distributions } mach_vm_range_recipe_v1_t;
210*4f1223e8SApple OSS Distributions 
211*4f1223e8SApple OSS Distributions #pragma pack()
212*4f1223e8SApple OSS Distributions 
213*4f1223e8SApple OSS Distributions #define MACH_VM_RANGE_FLAVOR_DEFAULT MACH_VM_RANGE_FLAVOR_V1
214*4f1223e8SApple OSS Distributions typedef mach_vm_range_recipe_v1_t    mach_vm_range_recipe_t;
215*4f1223e8SApple OSS Distributions 
216*4f1223e8SApple OSS Distributions typedef uint8_t                *mach_vm_range_recipes_raw_t;
217*4f1223e8SApple OSS Distributions 
218*4f1223e8SApple OSS Distributions #ifdef PRIVATE
219*4f1223e8SApple OSS Distributions 
220*4f1223e8SApple OSS Distributions typedef struct {
221*4f1223e8SApple OSS Distributions 	uint64_t rtfabstime; // mach_continuous_time at start of fault
222*4f1223e8SApple OSS Distributions 	uint64_t rtfduration; // fault service duration
223*4f1223e8SApple OSS Distributions 	uint64_t rtfaddr; // fault address
224*4f1223e8SApple OSS Distributions 	uint64_t rtfpc; // userspace program counter of thread incurring the fault
225*4f1223e8SApple OSS Distributions 	uint64_t rtftid; // thread ID
226*4f1223e8SApple OSS Distributions 	uint64_t rtfupid; // process identifier
227*4f1223e8SApple OSS Distributions 	uint64_t rtftype; // fault type
228*4f1223e8SApple OSS Distributions } vm_rtfault_record_t;
229*4f1223e8SApple OSS Distributions 
230*4f1223e8SApple OSS Distributions #endif /* PRIVATE */
231*4f1223e8SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
232*4f1223e8SApple OSS Distributions 
233*4f1223e8SApple OSS Distributions #define VM_TAG_ACTIVE_UPDATE    1
234*4f1223e8SApple OSS Distributions 
235*4f1223e8SApple OSS Distributions typedef uint16_t                vm_tag_t;
236*4f1223e8SApple OSS Distributions 
237*4f1223e8SApple OSS Distributions #define VM_TAG_NAME_LEN_MAX     0x7F
238*4f1223e8SApple OSS Distributions #define VM_TAG_NAME_LEN_SHIFT   0
239*4f1223e8SApple OSS Distributions #define VM_TAG_UNLOAD           0x0100
240*4f1223e8SApple OSS Distributions #define VM_TAG_KMOD             0x0200
241*4f1223e8SApple OSS Distributions 
242*4f1223e8SApple OSS Distributions #if !KASAN && (DEBUG || DEVELOPMENT)
243*4f1223e8SApple OSS Distributions /*
244*4f1223e8SApple OSS Distributions  * To track the utilization of memory at every kalloc callsite, zone tagging
245*4f1223e8SApple OSS Distributions  * allocates an array of stats (of size VM_TAG_SIZECLASSES), one for each
246*4f1223e8SApple OSS Distributions  * size class exposed by kalloc.
247*4f1223e8SApple OSS Distributions  *
248*4f1223e8SApple OSS Distributions  * If VM_TAG_SIZECLASSES is modified ensure that z_tags_sizeclass
249*4f1223e8SApple OSS Distributions  * has sufficient bits to represent all values (max value exclusive).
250*4f1223e8SApple OSS Distributions  */
251*4f1223e8SApple OSS Distributions #define VM_TAG_SIZECLASSES      36
252*4f1223e8SApple OSS Distributions // must be multiple of 64
253*4f1223e8SApple OSS Distributions #define VM_MAX_TAG_VALUE        1536
254*4f1223e8SApple OSS Distributions #else
255*4f1223e8SApple OSS Distributions #define VM_TAG_SIZECLASSES      0
256*4f1223e8SApple OSS Distributions #define VM_MAX_TAG_VALUE        256
257*4f1223e8SApple OSS Distributions #endif
258*4f1223e8SApple OSS Distributions 
259*4f1223e8SApple OSS Distributions #define ARRAY_COUNT(a)  (sizeof((a)) / sizeof((a)[0]))
260*4f1223e8SApple OSS Distributions 
261*4f1223e8SApple OSS Distributions struct vm_allocation_total {
262*4f1223e8SApple OSS Distributions 	vm_tag_t tag;
263*4f1223e8SApple OSS Distributions 	uint64_t total;
264*4f1223e8SApple OSS Distributions };
265*4f1223e8SApple OSS Distributions 
266*4f1223e8SApple OSS Distributions struct vm_allocation_zone_total {
267*4f1223e8SApple OSS Distributions 	vm_size_t vazt_total;
268*4f1223e8SApple OSS Distributions 	vm_size_t vazt_peak;
269*4f1223e8SApple OSS Distributions };
270*4f1223e8SApple OSS Distributions typedef struct vm_allocation_zone_total vm_allocation_zone_total_t;
271*4f1223e8SApple OSS Distributions 
272*4f1223e8SApple OSS Distributions struct vm_allocation_site {
273*4f1223e8SApple OSS Distributions 	uint64_t  total;
274*4f1223e8SApple OSS Distributions #if DEBUG || DEVELOPMENT
275*4f1223e8SApple OSS Distributions 	uint64_t  peak;
276*4f1223e8SApple OSS Distributions #endif /* DEBUG || DEVELOPMENT */
277*4f1223e8SApple OSS Distributions 	uint64_t  mapped;
278*4f1223e8SApple OSS Distributions 	int16_t   refcount;
279*4f1223e8SApple OSS Distributions 	vm_tag_t  tag;
280*4f1223e8SApple OSS Distributions 	uint16_t  flags;
281*4f1223e8SApple OSS Distributions 	uint16_t  subtotalscount;
282*4f1223e8SApple OSS Distributions 	struct vm_allocation_total subtotals[0];
283*4f1223e8SApple OSS Distributions 	/* char      name[0]; -- this is placed after subtotals, see KA_NAME() */
284*4f1223e8SApple OSS Distributions };
285*4f1223e8SApple OSS Distributions typedef struct vm_allocation_site vm_allocation_site_t;
286*4f1223e8SApple OSS Distributions 
287*4f1223e8SApple OSS Distributions extern int vmrtf_extract(uint64_t, boolean_t, unsigned long, void *, unsigned long *);
288*4f1223e8SApple OSS Distributions extern unsigned int vmrtfaultinfo_bufsz(void);
289*4f1223e8SApple OSS Distributions 
290*4f1223e8SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
291*4f1223e8SApple OSS Distributions 
292*4f1223e8SApple OSS Distributions __END_DECLS
293*4f1223e8SApple OSS Distributions 
294*4f1223e8SApple OSS Distributions #endif  /* _MACH_VM_TYPES_H_ */
295