xref: /xnu-11215.41.3/osfmk/mach/vm_region.h (revision 33de042d024d46de5ff4e89f2471de6608e37fa4)
1 /*
2  * Copyright (c) 2000-2016 Apple Computer, 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  *	File:	mach/vm_region.h
33  *
34  *	Define the attributes of a task's memory region
35  *
36  */
37 
38 #ifndef _MACH_VM_REGION_H_
39 #define _MACH_VM_REGION_H_
40 
41 #include <mach/boolean.h>
42 #include <mach/vm_prot.h>
43 #include <mach/vm_inherit.h>
44 #include <mach/vm_behavior.h>
45 #include <mach/vm_types.h>
46 #include <mach/message.h>
47 #include <mach/machine/vm_param.h>
48 #include <mach/machine/vm_types.h>
49 #include <mach/memory_object_types.h>
50 
51 #include <sys/cdefs.h>
52 
53 #pragma pack(push, 4)
54 
55 // LP64todo: all the current tools are 32bit, obviously never worked for 64b
56 // so probably should be a real 32b ID vs. ptr.
57 // Current users just check for equality
58 typedef uint32_t vm32_object_id_t;
59 
60 /*
61  *	Types defined:
62  *
63  *	vm_region_info_t	memory region attributes
64  */
65 
66 #define VM_REGION_INFO_MAX      (1024)
67 typedef int     *vm_region_info_t;
68 typedef int     *vm_region_info_64_t;
69 typedef int     *vm_region_recurse_info_t;
70 typedef int     *vm_region_recurse_info_64_t;
71 typedef int      vm_region_flavor_t;
72 typedef int      vm_region_info_data_t[VM_REGION_INFO_MAX];
73 
74 #ifdef PRIVATE
75 /* task region info flags configured via sysctl */
76 #ifdef MACH_KERNEL_PRIVATE
77 /* update the bit field size in task.h if flags are added */
78 #endif /* MACH_KERNEL_PRIVATE */
79 /* return SM_SHARED for SM_PRIVATE_ALIASED/SM_SHARED_ALIASED (perf) */
80 #define VM_REGION_INFO_FLAGS_NO_ALIASED 0x1
81 #endif /* PRIVATE */
82 
83 #define VM_REGION_BASIC_INFO_64         9
84 struct vm_region_basic_info_64 {
85 	vm_prot_t               protection;
86 	vm_prot_t               max_protection;
87 	vm_inherit_t            inheritance;
88 	boolean_t               shared;
89 	boolean_t               reserved;
90 	memory_object_offset_t  offset;
91 	vm_behavior_t           behavior;
92 	unsigned short          user_wired_count;
93 };
94 typedef struct vm_region_basic_info_64          *vm_region_basic_info_64_t;
95 typedef struct vm_region_basic_info_64           vm_region_basic_info_data_64_t;
96 
97 #define VM_REGION_BASIC_INFO_COUNT_64   ((mach_msg_type_number_t) \
98 	(sizeof(vm_region_basic_info_data_64_t)/sizeof(int)))
99 
100 /*
101  * Passing VM_REGION_BASIC_INFO to vm_region_64
102  * automatically converts it to a VM_REGION_BASIC_INFO_64.
103  * Please use that explicitly instead.
104  */
105 #define VM_REGION_BASIC_INFO            10
106 
107 /*
108  * This is the legacy basic info structure.  It is
109  * deprecated because it passes only a 32-bit memory object
110  * offset back - too small for many larger objects (e.g. files).
111  */
112 struct vm_region_basic_info {
113 	vm_prot_t               protection;
114 	vm_prot_t               max_protection;
115 	vm_inherit_t            inheritance;
116 	boolean_t               shared;
117 	boolean_t               reserved;
118 	uint32_t                offset; /* too small for a real offset */
119 	vm_behavior_t           behavior;
120 	unsigned short          user_wired_count;
121 };
122 
123 typedef struct vm_region_basic_info             *vm_region_basic_info_t;
124 typedef struct vm_region_basic_info              vm_region_basic_info_data_t;
125 
126 #define VM_REGION_BASIC_INFO_COUNT ((mach_msg_type_number_t) \
127 	(sizeof(vm_region_basic_info_data_t)/sizeof(int)))
128 
129 #define SM_COW             1
130 #define SM_PRIVATE         2
131 #define SM_EMPTY           3
132 #define SM_SHARED          4
133 #define SM_TRUESHARED      5
134 #define SM_PRIVATE_ALIASED 6
135 #define SM_SHARED_ALIASED  7
136 #define SM_LARGE_PAGE      8
137 
138 /*
139  * For submap info,  the SM flags above are overlayed when a submap
140  * is encountered.  The field denotes whether or not machine level mapping
141  * information is being shared.  PTE's etc.  When such sharing is taking
142  * place the value returned is SM_TRUESHARED otherwise SM_PRIVATE is passed
143  * back.
144  */
145 
146 #ifdef MACH_KERNEL_PRIVATE
147 #define VM_REGION_EXTENDED_INFO__legacy 11
148 struct vm_region_extended_info__legacy {
149 	vm_prot_t               protection;
150 	unsigned int            user_tag;
151 	unsigned int            pages_resident;
152 	unsigned int            pages_shared_now_private;
153 	unsigned int            pages_swapped_out;
154 	unsigned int            pages_dirtied;
155 	unsigned int            ref_count;
156 	unsigned short          shadow_depth;
157 	unsigned char           external_pager;
158 	unsigned char           share_mode;
159 	/*
160 	 * XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
161 	 *  DO NOT EXTEND THIS DATA STRUCTURE.
162 	 *  IT IS NOW ABANDONED AND REPLACED WITH vm_region_extended_info BELOW.
163 	 * XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
164 	 */
165 };
166 #define VM_REGION_EXTENDED_INFO_COUNT__legacy               \
167 	((mach_msg_type_number_t)                           \
168 	 (sizeof (struct vm_region_extended_info__legacy) / \
169 	  sizeof (natural_t)))
170 #endif /* MACH_KERNEL_PRIVATE */
171 
172 
173 
174 #define VM_REGION_EXTENDED_INFO 13
175 struct vm_region_extended_info {
176 	vm_prot_t               protection;
177 	unsigned int            user_tag;
178 	unsigned int            pages_resident;
179 	unsigned int            pages_shared_now_private;
180 	unsigned int            pages_swapped_out;
181 	unsigned int            pages_dirtied;
182 	unsigned int            ref_count;
183 	unsigned short          shadow_depth;
184 	unsigned char           external_pager;
185 	unsigned char           share_mode;
186 	unsigned int            pages_reusable;
187 };
188 typedef struct vm_region_extended_info          *vm_region_extended_info_t;
189 typedef struct vm_region_extended_info           vm_region_extended_info_data_t;
190 #define VM_REGION_EXTENDED_INFO_COUNT                   \
191 	((mach_msg_type_number_t)                       \
192 	 (sizeof (vm_region_extended_info_data_t) / sizeof (natural_t)))
193 
194 
195 
196 
197 #define VM_REGION_TOP_INFO      12
198 
199 struct vm_region_top_info {
200 	unsigned int            obj_id;
201 	unsigned int            ref_count;
202 	unsigned int            private_pages_resident;
203 	unsigned int            shared_pages_resident;
204 	unsigned char           share_mode;
205 };
206 
207 typedef struct vm_region_top_info               *vm_region_top_info_t;
208 typedef struct vm_region_top_info                vm_region_top_info_data_t;
209 
210 #define VM_REGION_TOP_INFO_COUNT                                        \
211 	((mach_msg_type_number_t)                                       \
212 	 (sizeof(vm_region_top_info_data_t) / sizeof(natural_t)))
213 
214 
215 
216 /*
217  * vm_region_submap_info will return information on a submap or object.
218  * The user supplies a nesting level on the call.  When a walk of the
219  * user's map is done and a submap is encountered, the nesting count is
220  * checked. If the nesting count is greater than 1 the submap is entered and
221  * the offset relative to the address in the base map is examined.  If the
222  * nesting count is zero, the information on the submap is returned.
223  * The caller may thus learn about a submap and its contents by judicious
224  * choice of the base map address and nesting count.  The nesting count
225  * allows penetration of recursively mapped submaps.  If a submap is
226  * encountered as a mapped entry of another submap, the caller may bump
227  * the nesting count and call vm_region_recurse again on the target address
228  * range.  The "is_submap" field tells the caller whether or not a submap
229  * has been encountered.
230  *
231  * Object only fields are filled in through a walking of the object shadow
232  * chain (where one is present), and a walking of the resident page queue.
233  *
234  */
235 
236 struct vm_region_submap_info {
237 	vm_prot_t               protection;     /* present access protection */
238 	vm_prot_t               max_protection; /* max avail through vm_prot */
239 	vm_inherit_t            inheritance;/* behavior of map/obj on fork */
240 	uint32_t                offset;         /* offset into object/map */
241 	unsigned int            user_tag;       /* user tag on map entry */
242 	unsigned int            pages_resident; /* only valid for objects */
243 	unsigned int            pages_shared_now_private; /* only for objects */
244 	unsigned int            pages_swapped_out; /* only for objects */
245 	unsigned int            pages_dirtied;   /* only for objects */
246 	unsigned int            ref_count;       /* obj/map mappers, etc */
247 	unsigned short          shadow_depth;   /* only for obj */
248 	unsigned char           external_pager;  /* only for obj */
249 	unsigned char           share_mode;     /* see enumeration */
250 	boolean_t               is_submap;      /* submap vs obj */
251 	vm_behavior_t           behavior;       /* access behavior hint */
252 	vm32_object_id_t        object_id;      /* obj/map name, not a handle */
253 	unsigned short          user_wired_count;
254 };
255 
256 typedef struct vm_region_submap_info            *vm_region_submap_info_t;
257 typedef struct vm_region_submap_info             vm_region_submap_info_data_t;
258 
259 #define VM_REGION_SUBMAP_INFO_COUNT                                     \
260 	((mach_msg_type_number_t)                                       \
261 	 (sizeof(vm_region_submap_info_data_t) / sizeof(natural_t)))
262 
263 struct vm_region_submap_info_64 {
264 	vm_prot_t               protection;     /* present access protection */
265 	vm_prot_t               max_protection; /* max avail through vm_prot */
266 	vm_inherit_t            inheritance;/* behavior of map/obj on fork */
267 	memory_object_offset_t  offset;         /* offset into object/map */
268 	unsigned int            user_tag;       /* user tag on map entry */
269 	unsigned int            pages_resident; /* only valid for objects */
270 	unsigned int            pages_shared_now_private; /* only for objects */
271 	unsigned int            pages_swapped_out; /* only for objects */
272 	unsigned int            pages_dirtied;   /* only for objects */
273 	unsigned int            ref_count;       /* obj/map mappers, etc */
274 	unsigned short          shadow_depth;   /* only for obj */
275 	unsigned char           external_pager;  /* only for obj */
276 	unsigned char           share_mode;     /* see enumeration */
277 	boolean_t               is_submap;      /* submap vs obj */
278 	vm_behavior_t           behavior;       /* access behavior hint */
279 	vm32_object_id_t        object_id;      /* obj/map name, not a handle */
280 	unsigned short          user_wired_count;
281 	unsigned int            pages_reusable;
282 	vm_object_id_t          object_id_full;
283 };
284 
285 typedef struct vm_region_submap_info_64         *vm_region_submap_info_64_t;
286 typedef struct vm_region_submap_info_64          vm_region_submap_info_data_64_t;
287 
288 #define VM_REGION_SUBMAP_INFO_V2_SIZE   \
289 	(sizeof (vm_region_submap_info_data_64_t))
290 #define VM_REGION_SUBMAP_INFO_V1_SIZE   \
291 	(VM_REGION_SUBMAP_INFO_V2_SIZE - \
292 	 sizeof (vm_object_id_t) /* object_id_full */ )
293 #define VM_REGION_SUBMAP_INFO_V0_SIZE   \
294 	(VM_REGION_SUBMAP_INFO_V1_SIZE - \
295 	 sizeof (unsigned int) /* pages_reusable */ )
296 
297 #define VM_REGION_SUBMAP_INFO_V2_COUNT_64 \
298 	((mach_msg_type_number_t) \
299 	 (VM_REGION_SUBMAP_INFO_V2_SIZE / sizeof (natural_t)))
300 #define VM_REGION_SUBMAP_INFO_V1_COUNT_64 \
301 	((mach_msg_type_number_t) \
302 	 (VM_REGION_SUBMAP_INFO_V1_SIZE / sizeof (natural_t)))
303 #define VM_REGION_SUBMAP_INFO_V0_COUNT_64 \
304 	((mach_msg_type_number_t) \
305 	 (VM_REGION_SUBMAP_INFO_V0_SIZE / sizeof (natural_t)))
306 
307 /* set this to the latest version */
308 #define VM_REGION_SUBMAP_INFO_COUNT_64          VM_REGION_SUBMAP_INFO_V2_COUNT_64
309 
310 struct vm_region_submap_short_info_64 {
311 	vm_prot_t               protection;     /* present access protection */
312 	vm_prot_t               max_protection; /* max avail through vm_prot */
313 	vm_inherit_t            inheritance;/* behavior of map/obj on fork */
314 	memory_object_offset_t  offset;         /* offset into object/map */
315 	unsigned int            user_tag;       /* user tag on map entry */
316 	unsigned int            ref_count;       /* obj/map mappers, etc */
317 	unsigned short          shadow_depth;   /* only for obj */
318 	unsigned char           external_pager;  /* only for obj */
319 	unsigned char           share_mode;     /* see enumeration */
320 	boolean_t               is_submap;      /* submap vs obj */
321 	vm_behavior_t           behavior;       /* access behavior hint */
322 	vm32_object_id_t        object_id;      /* obj/map name, not a handle */
323 	unsigned short          user_wired_count;
324 };
325 
326 typedef struct vm_region_submap_short_info_64   *vm_region_submap_short_info_64_t;
327 typedef struct vm_region_submap_short_info_64    vm_region_submap_short_info_data_64_t;
328 
329 #define VM_REGION_SUBMAP_SHORT_INFO_COUNT_64                            \
330 	((mach_msg_type_number_t)                                       \
331 	 (sizeof (vm_region_submap_short_info_data_64_t) / sizeof (natural_t)))
332 
333 struct mach_vm_read_entry {
334 	mach_vm_address_t address;
335 	mach_vm_size_t size;
336 };
337 
338 struct vm_read_entry {
339 	vm_address_t    address;
340 	vm_size_t       size;
341 };
342 
343 #ifdef VM32_SUPPORT
344 struct vm32_read_entry {
345 	vm32_address_t  address;
346 	vm32_size_t     size;
347 };
348 #endif
349 
350 
351 #define VM_MAP_ENTRY_MAX  (256)
352 
353 typedef struct mach_vm_read_entry       mach_vm_read_entry_t[VM_MAP_ENTRY_MAX];
354 typedef struct vm_read_entry            vm_read_entry_t[VM_MAP_ENTRY_MAX];
355 #ifdef VM32_SUPPORT
356 typedef struct vm32_read_entry          vm32_read_entry_t[VM_MAP_ENTRY_MAX];
357 #endif
358 
359 #pragma pack(pop)
360 
361 
362 #define VM_PAGE_INFO_MAX
363 typedef int *vm_page_info_t;
364 typedef int vm_page_info_data_t[VM_PAGE_INFO_MAX];
365 typedef int vm_page_info_flavor_t;
366 
367 #define VM_PAGE_INFO_BASIC              1
368 struct vm_page_info_basic {
369 	int                     disposition;
370 	int                     ref_count;
371 	vm_object_id_t          object_id;
372 	memory_object_offset_t  offset;
373 	int                     depth;
374 	int                     __pad; /* pad to 64-bit boundary */
375 };
376 typedef struct vm_page_info_basic               *vm_page_info_basic_t;
377 typedef struct vm_page_info_basic               vm_page_info_basic_data_t;
378 
379 #define VM_PAGE_INFO_BASIC_COUNT        ((mach_msg_type_number_t) \
380 	(sizeof(vm_page_info_basic_data_t)/sizeof(int)))
381 
382 
383 #endif  /*_MACH_VM_REGION_H_*/
384