| 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 | |
| 54 | #pragma pack(push, 4) |
| 55 | |
| 56 | // LP64todo: all the current tools are 32bit, obviously never worked for 64b |
| 57 | // so probably should be a real 32b ID vs. ptr. |
| 58 | // Current users just check for equality |
| 59 | typedef uint32_t vm32_object_id_t; |
| 60 | |
| 61 | /* |
| 62 | *	Types defined: |
| 63 | * |
| 64 | *	vm_region_info_t	memory region attributes |
| 65 | */ |
| 66 | |
| 67 | #define VM_REGION_INFO_MAX (1024) |
| 68 | typedef int *vm_region_info_t; |
| 69 | typedef int *vm_region_info_64_t; |
| 70 | typedef int *vm_region_recurse_info_t; |
| 71 | typedef int *vm_region_recurse_info_64_t; |
| 72 | typedef int vm_region_flavor_t; |
| 73 | typedef int vm_region_info_data_t[VM_REGION_INFO_MAX]; |
| 74 | |
| 75 | |
| 76 | #define VM_REGION_BASIC_INFO_64 9 |
| 77 | struct vm_region_basic_info_64 { |
| 78 | 	vm_prot_t protection; |
| 79 | 	vm_prot_t max_protection; |
| 80 | 	vm_inherit_t inheritance; |
| 81 | 	boolean_t shared; |
| 82 | 	boolean_t reserved; |
| 83 | 	memory_object_offset_t offset; |
| 84 | 	vm_behavior_t behavior; |
| 85 | 	unsigned short user_wired_count; |
| 86 | }; |
| 87 | typedef struct vm_region_basic_info_64 *vm_region_basic_info_64_t; |
| 88 | typedef struct vm_region_basic_info_64 vm_region_basic_info_data_64_t; |
| 89 | |
| 90 | #define VM_REGION_BASIC_INFO_COUNT_64 ((mach_msg_type_number_t) \ |
| 91 | 	(sizeof(vm_region_basic_info_data_64_t)/sizeof(int))) |
| 92 | |
| 93 | /* |
| 94 | * Passing VM_REGION_BASIC_INFO to vm_region_64 |
| 95 | * automatically converts it to a VM_REGION_BASIC_INFO_64. |
| 96 | * Please use that explicitly instead. |
| 97 | */ |
| 98 | #define VM_REGION_BASIC_INFO 10 |
| 99 | |
| 100 | /* |
| 101 | * This is the legacy basic info structure. It is |
| 102 | * deprecated because it passes only a 32-bit memory object |
| 103 | * offset back - too small for many larger objects (e.g. files). |
| 104 | */ |
| 105 | struct vm_region_basic_info { |
| 106 | 	vm_prot_t protection; |
| 107 | 	vm_prot_t max_protection; |
| 108 | 	vm_inherit_t inheritance; |
| 109 | 	boolean_t shared; |
| 110 | 	boolean_t reserved; |
| 111 | 	uint32_t offset; /* too small for a real offset */ |
| 112 | 	vm_behavior_t behavior; |
| 113 | 	unsigned short user_wired_count; |
| 114 | }; |
| 115 | |
| 116 | typedef struct vm_region_basic_info *vm_region_basic_info_t; |
| 117 | typedef struct vm_region_basic_info vm_region_basic_info_data_t; |
| 118 | |
| 119 | #define VM_REGION_BASIC_INFO_COUNT ((mach_msg_type_number_t) \ |
| 120 | 	(sizeof(vm_region_basic_info_data_t)/sizeof(int))) |
| 121 | |
| 122 | /* |
| 123 | * Clients should move away from using these codes for anything other than debugging |
| 124 | * or best-effort accounting. |
| 125 | * Each value is only loosely defined, and even within those definitions it is not |
| 126 | * always possible for the VM to return the correct value. This behavior is also |
| 127 | * subject to change as VM internals evolve. |
| 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 | |
| 147 | |
| 148 | |
| 149 | #define VM_REGION_EXTENDED_INFO 13 |
| 150 | struct vm_region_extended_info { |
| 151 | 	vm_prot_t protection; |
| 152 | 	unsigned int user_tag; |
| 153 | 	unsigned int pages_resident; |
| 154 | 	unsigned int pages_shared_now_private; |
| 155 | 	unsigned int pages_swapped_out; |
| 156 | 	unsigned int pages_dirtied; |
| 157 | 	unsigned int ref_count; |
| 158 | 	unsigned short shadow_depth; |
| 159 | 	unsigned char external_pager; |
| 160 | 	unsigned char share_mode; |
| 161 | 	unsigned int pages_reusable; |
| 162 | }; |
| 163 | typedef struct vm_region_extended_info *vm_region_extended_info_t; |
| 164 | typedef struct vm_region_extended_info vm_region_extended_info_data_t; |
| 165 | #define VM_REGION_EXTENDED_INFO_COUNT \ |
| 166 | 	((mach_msg_type_number_t) \ |
| 167 | 	 (sizeof (vm_region_extended_info_data_t) / sizeof (natural_t))) |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | #define VM_REGION_TOP_INFO 12 |
| 173 | |
| 174 | struct vm_region_top_info { |
| 175 | 	unsigned int obj_id; |
| 176 | 	unsigned int ref_count; |
| 177 | 	unsigned int private_pages_resident; |
| 178 | 	unsigned int shared_pages_resident; |
| 179 | 	unsigned char share_mode; |
| 180 | }; |
| 181 | |
| 182 | typedef struct vm_region_top_info *vm_region_top_info_t; |
| 183 | typedef struct vm_region_top_info vm_region_top_info_data_t; |
| 184 | |
| 185 | #define VM_REGION_TOP_INFO_COUNT \ |
| 186 | 	((mach_msg_type_number_t) \ |
| 187 | 	 (sizeof(vm_region_top_info_data_t) / sizeof(natural_t))) |
| 188 | |
| 189 | |
| 190 | |
| 191 | /* |
| 192 | * vm_region_submap_info will return information on a submap or object. |
| 193 | * The user supplies a nesting level on the call. When a walk of the |
| 194 | * user's map is done and a submap is encountered, the nesting count is |
| 195 | * checked. If the nesting count is greater than 1 the submap is entered and |
| 196 | * the offset relative to the address in the base map is examined. If the |
| 197 | * nesting count is zero, the information on the submap is returned. |
| 198 | * The caller may thus learn about a submap and its contents by judicious |
| 199 | * choice of the base map address and nesting count. The nesting count |
| 200 | * allows penetration of recursively mapped submaps. If a submap is |
| 201 | * encountered as a mapped entry of another submap, the caller may bump |
| 202 | * the nesting count and call vm_region_recurse again on the target address |
| 203 | * range. The "is_submap" field tells the caller whether or not a submap |
| 204 | * has been encountered. |
| 205 | * |
| 206 | * Object only fields are filled in through a walking of the object shadow |
| 207 | * chain (where one is present), and a walking of the resident page queue. |
| 208 | * |
| 209 | */ |
| 210 | |
| 211 | struct vm_region_submap_info { |
| 212 | 	vm_prot_t protection; /* present access protection */ |
| 213 | 	vm_prot_t max_protection; /* max avail through vm_prot */ |
| 214 | 	vm_inherit_t inheritance;/* behavior of map/obj on fork */ |
| 215 | 	uint32_t offset; /* offset into object/map */ |
| 216 | 	unsigned int user_tag; /* user tag on map entry */ |
| 217 | 	unsigned int pages_resident; /* only valid for objects */ |
| 218 | 	unsigned int pages_shared_now_private; /* only for objects */ |
| 219 | 	unsigned int pages_swapped_out; /* only for objects */ |
| 220 | 	unsigned int pages_dirtied; /* only for objects */ |
| 221 | 	unsigned int ref_count; /* obj/map mappers, etc */ |
| 222 | 	unsigned short shadow_depth; /* only for obj */ |
| 223 | 	unsigned char external_pager; /* only for obj */ |
| 224 | 	unsigned char share_mode; /* see enumeration */ |
| 225 | 	boolean_t is_submap; /* submap vs obj */ |
| 226 | 	vm_behavior_t behavior; /* access behavior hint */ |
| 227 | 	vm32_object_id_t object_id; /* obj/map name, not a handle */ |
| 228 | 	unsigned short user_wired_count; |
| 229 | }; |
| 230 | |
| 231 | typedef struct vm_region_submap_info *vm_region_submap_info_t; |
| 232 | typedef struct vm_region_submap_info vm_region_submap_info_data_t; |
| 233 | |
| 234 | #define VM_REGION_SUBMAP_INFO_COUNT \ |
| 235 | 	((mach_msg_type_number_t) \ |
| 236 | 	 (sizeof(vm_region_submap_info_data_t) / sizeof(natural_t))) |
| 237 | |
| 238 | struct vm_region_submap_info_64 { |
| 239 | 	/* v0 fields */ |
| 240 | 	vm_prot_t protection; /* present access protection */ |
| 241 | 	vm_prot_t max_protection; /* max avail through vm_prot */ |
| 242 | 	vm_inherit_t inheritance;/* behavior of map/obj on fork */ |
| 243 | 	memory_object_offset_t offset; /* offset into object/map */ |
| 244 | 	unsigned int user_tag; /* user tag on map entry */ |
| 245 | 	unsigned int pages_resident; /* only valid for objects */ |
| 246 | 	unsigned int pages_shared_now_private; /* only for objects */ |
| 247 | 	unsigned int pages_swapped_out; /* only for objects */ |
| 248 | 	unsigned int pages_dirtied; /* only for objects */ |
| 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 | 	vm32_object_id_t object_id; /* obj/map name, not a handle */ |
| 256 | 	unsigned short user_wired_count; |
| 257 | 	unsigned short flags; |
| 258 | 	/* v1 fields */ |
| 259 | 	unsigned int pages_reusable; |
| 260 | 	/* v2 fields */ |
| 261 | 	vm_object_id_t object_id_full; |
| 262 | }; |
| 263 | |
| 264 | typedef struct vm_region_submap_info_64 *vm_region_submap_info_64_t; |
| 265 | typedef struct vm_region_submap_info_64 vm_region_submap_info_data_64_t; |
| 266 | |
| 267 | /* |
| 268 | * Note that this size is hard-coded at the MIG boundary in mach_types.defs |
| 269 | * so if we ever increase this you'll need to also bump the definition of |
| 270 | * vm_region_recurse_info_t. |
| 271 | */ |
| 272 | #define VM_REGION_SUBMAP_INFO_V2_SIZE \ |
| 273 | 	(sizeof (vm_region_submap_info_data_64_t)) |
| 274 | |
| 275 | /* v1 size is v2 size minus v2's new fields */ |
| 276 | #define VM_REGION_SUBMAP_INFO_V1_SIZE \ |
| 277 | 	(VM_REGION_SUBMAP_INFO_V2_SIZE - \ |
| 278 | 	 sizeof (vm_object_id_t) /* object_id_full */ ) |
| 279 | |
| 280 | /* v0 size is v1 size minus v1's new fields */ |
| 281 | #define VM_REGION_SUBMAP_INFO_V0_SIZE \ |
| 282 | 	(VM_REGION_SUBMAP_INFO_V1_SIZE - \ |
| 283 | 	 sizeof (unsigned int) /* pages_reusable */ ) |
| 284 | |
| 285 | #define VM_REGION_SUBMAP_INFO_V2_COUNT_64 \ |
| 286 | 	((mach_msg_type_number_t) \ |
| 287 | 	 (VM_REGION_SUBMAP_INFO_V2_SIZE / sizeof (natural_t))) |
| 288 | #define VM_REGION_SUBMAP_INFO_V1_COUNT_64 \ |
| 289 | 	((mach_msg_type_number_t) \ |
| 290 | 	 (VM_REGION_SUBMAP_INFO_V1_SIZE / sizeof (natural_t))) |
| 291 | #define VM_REGION_SUBMAP_INFO_V0_COUNT_64 \ |
| 292 | 	((mach_msg_type_number_t) \ |
| 293 | 	 (VM_REGION_SUBMAP_INFO_V0_SIZE / sizeof (natural_t))) |
| 294 | |
| 295 | /* set this to the latest version */ |
| 296 | #define VM_REGION_SUBMAP_INFO_COUNT_64 VM_REGION_SUBMAP_INFO_V2_COUNT_64 |
| 297 | |
| 298 | #define VM_REGION_FLAG_JIT_ENABLED 0x1 |
| 299 | #define VM_REGION_FLAG_TPRO_ENABLED 0x2 |
| 300 | |
| 301 | |
| 302 | struct vm_region_submap_short_info_64 { |
| 303 | 	vm_prot_t protection; /* present access protection */ |
| 304 | 	vm_prot_t max_protection; /* max avail through vm_prot */ |
| 305 | 	vm_inherit_t inheritance;/* behavior of map/obj on fork */ |
| 306 | 	memory_object_offset_t offset; /* offset into object/map */ |
| 307 | 	unsigned int user_tag; /* user tag on map entry */ |
| 308 | 	unsigned int ref_count; /* obj/map mappers, etc */ |
| 309 | 	unsigned short shadow_depth; /* only for obj */ |
| 310 | 	unsigned char external_pager; /* only for obj */ |
| 311 | 	unsigned char share_mode; /* see enumeration */ |
| 312 | 	boolean_t is_submap; /* submap vs obj */ |
| 313 | 	vm_behavior_t behavior; /* access behavior hint */ |
| 314 | 	vm32_object_id_t object_id; /* obj/map name, not a handle */ |
| 315 | 	unsigned short user_wired_count; |
| 316 | 	unsigned short flags; |
| 317 | }; |
| 318 | |
| 319 | typedef struct vm_region_submap_short_info_64 *vm_region_submap_short_info_64_t; |
| 320 | typedef struct vm_region_submap_short_info_64 vm_region_submap_short_info_data_64_t; |
| 321 | |
| 322 | #define VM_REGION_SUBMAP_SHORT_INFO_COUNT_64 \ |
| 323 | 	((mach_msg_type_number_t) \ |
| 324 | 	 (sizeof (vm_region_submap_short_info_data_64_t) / sizeof (natural_t))) |
| 325 | |
| 326 | struct mach_vm_read_entry { |
| 327 | 	mach_vm_address_t address; |
| 328 | 	mach_vm_size_t size; |
| 329 | }; |
| 330 | |
| 331 | struct vm_read_entry { |
| 332 | 	vm_address_t address; |
| 333 | 	vm_size_t size; |
| 334 | }; |
| 335 | |
| 336 | #ifdef VM32_SUPPORT |
| 337 | struct vm32_read_entry { |
| 338 | 	vm32_address_t address; |
| 339 | 	vm32_size_t size; |
| 340 | }; |
| 341 | #endif |
| 342 | |
| 343 | |
| 344 | #define VM_MAP_ENTRY_MAX (256) |
| 345 | |
| 346 | typedef struct mach_vm_read_entry mach_vm_read_entry_t[VM_MAP_ENTRY_MAX]; |
| 347 | typedef struct vm_read_entry vm_read_entry_t[VM_MAP_ENTRY_MAX]; |
| 348 | #ifdef VM32_SUPPORT |
| 349 | typedef struct vm32_read_entry vm32_read_entry_t[VM_MAP_ENTRY_MAX]; |
| 350 | #endif |
| 351 | |
| 352 | #pragma pack(pop) |
| 353 | |
| 354 | |
| 355 | #define VM_PAGE_INFO_MAX |
| 356 | typedef int *vm_page_info_t; |
| 357 | typedef int vm_page_info_data_t[VM_PAGE_INFO_MAX]; |
| 358 | typedef int vm_page_info_flavor_t; |
| 359 | |
| 360 | #define VM_PAGE_INFO_BASIC 1 |
| 361 | struct vm_page_info_basic { |
| 362 | 	int disposition; |
| 363 | 	int ref_count; |
| 364 | 	vm_object_id_t object_id; |
| 365 | 	memory_object_offset_t offset; |
| 366 | 	int depth; |
| 367 | 	int __pad; /* pad to 64-bit boundary */ |
| 368 | }; |
| 369 | typedef struct vm_page_info_basic *vm_page_info_basic_t; |
| 370 | typedef struct vm_page_info_basic vm_page_info_basic_data_t; |
| 371 | |
| 372 | #define VM_PAGE_INFO_BASIC_COUNT ((mach_msg_type_number_t) \ |
| 373 | 	(sizeof(vm_page_info_basic_data_t)/sizeof(int))) |
| 374 | |
| 375 | |
| 376 | #endif /*_MACH_VM_REGION_H_*/ |