1/*
2 * Copyright (c) 2000-2006 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(4)
54
55/*
56 *	Types defined:
57 *
58 *	vm_region_info_t	memory region attributes
59 */
60
61#define VM_REGION_INFO_MAX      (1024)
62typedef int	*vm_region_info_t;
63typedef int	*vm_region_info_64_t;
64typedef int	*vm_region_recurse_info_t;
65typedef int	*vm_region_recurse_info_64_t;
66typedef int	 vm_region_flavor_t;
67typedef int	 vm_region_info_data_t[VM_REGION_INFO_MAX];
68
69#define VM_REGION_BASIC_INFO_64		9
70struct vm_region_basic_info_64 {
71	vm_prot_t		protection;
72	vm_prot_t		max_protection;
73	vm_inherit_t		inheritance;
74	boolean_t		shared;
75	boolean_t		reserved;
76	memory_object_offset_t	offset;
77	vm_behavior_t		behavior;
78	unsigned short		user_wired_count;
79};
80typedef struct vm_region_basic_info_64		*vm_region_basic_info_64_t;
81typedef struct vm_region_basic_info_64		 vm_region_basic_info_data_64_t;
82
83#define VM_REGION_BASIC_INFO_COUNT_64	((mach_msg_type_number_t) \
84	(sizeof(vm_region_basic_info_data_64_t)/sizeof(int)))
85
86/*
87 * Passing VM_REGION_BASIC_INFO to vm_region_64
88 * automatically converts it to a VM_REGION_BASIC_INFO_64.
89 * Please use that explicitly instead.
90 */
91#define VM_REGION_BASIC_INFO		10
92
93/*
94 * This is the legacy basic info structure.  It is
95 * deprecated because it passes only a 32-bit memory object
96 * offset back - too small for many larger objects (e.g. files).
97 */
98struct vm_region_basic_info {
99	vm_prot_t		protection;
100	vm_prot_t		max_protection;
101	vm_inherit_t		inheritance;
102	boolean_t		shared;
103	boolean_t		reserved;
104	uint32_t		offset; /* too small for a real offset */
105	vm_behavior_t		behavior;
106	unsigned short		user_wired_count;
107};
108
109typedef struct vm_region_basic_info		*vm_region_basic_info_t;
110typedef struct vm_region_basic_info		 vm_region_basic_info_data_t;
111
112#define VM_REGION_BASIC_INFO_COUNT ((mach_msg_type_number_t) \
113	(sizeof(vm_region_basic_info_data_t)/sizeof(int)))
114
115#define VM_REGION_EXTENDED_INFO	11
116
117#define SM_COW             1
118#define SM_PRIVATE         2
119#define SM_EMPTY           3
120#define SM_SHARED          4
121#define SM_TRUESHARED      5
122#define SM_PRIVATE_ALIASED 6
123#define SM_SHARED_ALIASED  7
124
125/*
126 * For submap info,  the SM flags above are overlayed when a submap
127 * is encountered.  The field denotes whether or not machine level mapping
128 * information is being shared.  PTE's etc.  When such sharing is taking
129 * place the value returned is SM_TRUESHARED otherwise SM_PRIVATE is passed
130 * back.
131 */
132
133struct vm_region_extended_info {
134	vm_prot_t		protection;
135        unsigned int            user_tag;
136        unsigned int            pages_resident;
137        unsigned int            pages_shared_now_private;
138        unsigned int            pages_swapped_out;
139        unsigned int            pages_dirtied;
140        unsigned int            ref_count;
141        unsigned short          shadow_depth;
142        unsigned char           external_pager;
143        unsigned char           share_mode;
144};
145
146typedef struct vm_region_extended_info		*vm_region_extended_info_t;
147typedef struct vm_region_extended_info		 vm_region_extended_info_data_t;
148
149#define VM_REGION_EXTENDED_INFO_COUNT	((mach_msg_type_number_t) \
150	(sizeof(vm_region_extended_info_data_t)/sizeof(int)))
151
152
153#define VM_REGION_TOP_INFO	12
154
155struct vm_region_top_info {
156        unsigned int            obj_id;
157        unsigned int            ref_count;
158        unsigned int            private_pages_resident;
159        unsigned int            shared_pages_resident;
160        unsigned char           share_mode;
161};
162
163typedef struct vm_region_top_info		*vm_region_top_info_t;
164typedef struct vm_region_top_info		 vm_region_top_info_data_t;
165
166#define VM_REGION_TOP_INFO_COUNT ((mach_msg_type_number_t) \
167	(sizeof(vm_region_top_info_data_t)/sizeof(int)))
168
169
170
171/*
172 * vm_region_submap_info will return information on a submap or object.
173 * The user supplies a nesting level on the call.  When a walk of the
174 * user's map is done and a submap is encountered, the nesting count is
175 * checked. If the nesting count is greater than 1 the submap is entered and
176 * the offset relative to the address in the base map is examined.  If the
177 * nesting count is zero, the information on the submap is returned.
178 * The caller may thus learn about a submap and its contents by judicious
179 * choice of the base map address and nesting count.  The nesting count
180 * allows penetration of recursively mapped submaps.  If a submap is
181 * encountered as a mapped entry of another submap, the caller may bump
182 * the nesting count and call vm_region_recurse again on the target address
183 * range.  The "is_submap" field tells the caller whether or not a submap
184 * has been encountered.
185 *
186 * Object only fields are filled in through a walking of the object shadow
187 * chain (where one is present), and a walking of the resident page queue.
188 *
189 */
190
191struct vm_region_submap_info {
192	vm_prot_t		protection;     /* present access protection */
193	vm_prot_t		max_protection; /* max avail through vm_prot */
194	vm_inherit_t		inheritance;/* behavior of map/obj on fork */
195	uint32_t		offset;		/* offset into object/map */
196        unsigned int            user_tag;	/* user tag on map entry */
197        unsigned int            pages_resident;	/* only valid for objects */
198        unsigned int            pages_shared_now_private; /* only for objects */
199        unsigned int            pages_swapped_out; /* only for objects */
200        unsigned int            pages_dirtied;   /* only for objects */
201        unsigned int            ref_count;	 /* obj/map mappers, etc */
202        unsigned short          shadow_depth; 	/* only for obj */
203        unsigned char           external_pager;  /* only for obj */
204        unsigned char           share_mode;	/* see enumeration */
205	boolean_t		is_submap;	/* submap vs obj */
206	vm_behavior_t		behavior;	/* access behavior hint */
207	vm_offset_t		object_id;	/* obj/map name, not a handle */
208	unsigned short		user_wired_count;
209};
210
211typedef struct vm_region_submap_info		*vm_region_submap_info_t;
212typedef struct vm_region_submap_info		 vm_region_submap_info_data_t;
213
214#define VM_REGION_SUBMAP_INFO_COUNT ((mach_msg_type_number_t) \
215	(sizeof(vm_region_submap_info_data_t)/sizeof(int)))
216
217struct vm_region_submap_info_64 {
218	vm_prot_t		protection;     /* present access protection */
219	vm_prot_t		max_protection; /* max avail through vm_prot */
220	vm_inherit_t		inheritance;/* behavior of map/obj on fork */
221	memory_object_offset_t	offset;		/* offset into object/map */
222        unsigned int            user_tag;	/* user tag on map entry */
223        unsigned int            pages_resident;	/* only valid for objects */
224        unsigned int            pages_shared_now_private; /* only for objects */
225        unsigned int            pages_swapped_out; /* only for objects */
226        unsigned int            pages_dirtied;   /* only for objects */
227        unsigned int            ref_count;	 /* obj/map mappers, etc */
228        unsigned short          shadow_depth; 	/* only for obj */
229        unsigned char           external_pager;  /* only for obj */
230        unsigned char           share_mode;	/* see enumeration */
231	boolean_t		is_submap;	/* submap vs obj */
232	vm_behavior_t		behavior;	/* access behavior hint */
233	vm_offset_t		object_id;	/* obj/map name, not a handle */
234	unsigned short		user_wired_count;
235};
236
237typedef struct vm_region_submap_info_64		*vm_region_submap_info_64_t;
238typedef struct vm_region_submap_info_64		 vm_region_submap_info_data_64_t;
239
240#define VM_REGION_SUBMAP_INFO_COUNT_64		((mach_msg_type_number_t) \
241	(sizeof(vm_region_submap_info_data_64_t)/sizeof(int)))
242
243struct vm_region_submap_short_info_64 {
244	vm_prot_t		protection;     /* present access protection */
245	vm_prot_t		max_protection; /* max avail through vm_prot */
246	vm_inherit_t		inheritance;/* behavior of map/obj on fork */
247	memory_object_offset_t	offset;		/* offset into object/map */
248        unsigned int            user_tag;	/* user tag on map entry */
249        unsigned int            ref_count;	 /* obj/map mappers, etc */
250        unsigned short          shadow_depth; 	/* only for obj */
251        unsigned char           external_pager;  /* only for obj */
252        unsigned char           share_mode;	/* see enumeration */
253	boolean_t		is_submap;	/* submap vs obj */
254	vm_behavior_t		behavior;	/* access behavior hint */
255	vm_offset_t		object_id;	/* obj/map name, not a handle */
256	unsigned short		user_wired_count;
257};
258
259typedef struct vm_region_submap_short_info_64	*vm_region_submap_short_info_64_t;
260typedef struct vm_region_submap_short_info_64	 vm_region_submap_short_info_data_64_t;
261
262#define VM_REGION_SUBMAP_SHORT_INFO_COUNT_64	((mach_msg_type_number_t) \
263	(sizeof(vm_region_submap_short_info_data_64_t)/sizeof(int)))
264
265
266struct mach_vm_read_entry {
267	mach_vm_address_t address;
268	mach_vm_size_t size;
269};
270
271struct vm_read_entry {
272	vm_address_t	address;
273	vm_size_t	size;
274};
275
276#define VM_MAP_ENTRY_MAX  (256)
277
278typedef struct mach_vm_read_entry	mach_vm_read_entry_t[VM_MAP_ENTRY_MAX];
279typedef struct vm_read_entry		vm_read_entry_t[VM_MAP_ENTRY_MAX];
280
281#pragma pack()
282
283#endif	/*_MACH_VM_REGION_H_*/
284