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 /* v0 fields */ 265 vm_prot_t protection; /* present access protection */ 266 vm_prot_t max_protection; /* max avail through vm_prot */ 267 vm_inherit_t inheritance;/* behavior of map/obj on fork */ 268 memory_object_offset_t offset; /* offset into object/map */ 269 unsigned int user_tag; /* user tag on map entry */ 270 unsigned int pages_resident; /* only valid for objects */ 271 unsigned int pages_shared_now_private; /* only for objects */ 272 unsigned int pages_swapped_out; /* only for objects */ 273 unsigned int pages_dirtied; /* only for objects */ 274 unsigned int ref_count; /* obj/map mappers, etc */ 275 unsigned short shadow_depth; /* only for obj */ 276 unsigned char external_pager; /* only for obj */ 277 unsigned char share_mode; /* see enumeration */ 278 boolean_t is_submap; /* submap vs obj */ 279 vm_behavior_t behavior; /* access behavior hint */ 280 vm32_object_id_t object_id; /* obj/map name, not a handle */ 281 unsigned short user_wired_count; 282 unsigned short flags; 283 /* v1 fields */ 284 unsigned int pages_reusable; 285 /* v2 fields */ 286 vm_object_id_t object_id_full; 287 }; 288 289 typedef struct vm_region_submap_info_64 *vm_region_submap_info_64_t; 290 typedef struct vm_region_submap_info_64 vm_region_submap_info_data_64_t; 291 292 /* 293 * Note that this size is hard-coded at the MIG boundary in mach_types.defs 294 * so if we ever increase this you'll need to also bump the definition of 295 * vm_region_recurse_info_t. 296 */ 297 #define VM_REGION_SUBMAP_INFO_V2_SIZE \ 298 (sizeof (vm_region_submap_info_data_64_t)) 299 300 /* v1 size is v2 size minus v2's new fields */ 301 #define VM_REGION_SUBMAP_INFO_V1_SIZE \ 302 (VM_REGION_SUBMAP_INFO_V2_SIZE - \ 303 sizeof (vm_object_id_t) /* object_id_full */ ) 304 305 /* v0 size is v1 size minus v1's new fields */ 306 #define VM_REGION_SUBMAP_INFO_V0_SIZE \ 307 (VM_REGION_SUBMAP_INFO_V1_SIZE - \ 308 sizeof (unsigned int) /* pages_reusable */ ) 309 310 #define VM_REGION_SUBMAP_INFO_V2_COUNT_64 \ 311 ((mach_msg_type_number_t) \ 312 (VM_REGION_SUBMAP_INFO_V2_SIZE / sizeof (natural_t))) 313 #define VM_REGION_SUBMAP_INFO_V1_COUNT_64 \ 314 ((mach_msg_type_number_t) \ 315 (VM_REGION_SUBMAP_INFO_V1_SIZE / sizeof (natural_t))) 316 #define VM_REGION_SUBMAP_INFO_V0_COUNT_64 \ 317 ((mach_msg_type_number_t) \ 318 (VM_REGION_SUBMAP_INFO_V0_SIZE / sizeof (natural_t))) 319 320 /* set this to the latest version */ 321 #define VM_REGION_SUBMAP_INFO_COUNT_64 VM_REGION_SUBMAP_INFO_V2_COUNT_64 322 323 #define VM_REGION_FLAG_JIT_ENABLED 0x1 324 #define VM_REGION_FLAG_TPRO_ENABLED 0x2 325 326 327 struct vm_region_submap_short_info_64 { 328 vm_prot_t protection; /* present access protection */ 329 vm_prot_t max_protection; /* max avail through vm_prot */ 330 vm_inherit_t inheritance;/* behavior of map/obj on fork */ 331 memory_object_offset_t offset; /* offset into object/map */ 332 unsigned int user_tag; /* user tag on map entry */ 333 unsigned int ref_count; /* obj/map mappers, etc */ 334 unsigned short shadow_depth; /* only for obj */ 335 unsigned char external_pager; /* only for obj */ 336 unsigned char share_mode; /* see enumeration */ 337 boolean_t is_submap; /* submap vs obj */ 338 vm_behavior_t behavior; /* access behavior hint */ 339 vm32_object_id_t object_id; /* obj/map name, not a handle */ 340 unsigned short user_wired_count; 341 unsigned short flags; 342 }; 343 344 typedef struct vm_region_submap_short_info_64 *vm_region_submap_short_info_64_t; 345 typedef struct vm_region_submap_short_info_64 vm_region_submap_short_info_data_64_t; 346 347 #define VM_REGION_SUBMAP_SHORT_INFO_COUNT_64 \ 348 ((mach_msg_type_number_t) \ 349 (sizeof (vm_region_submap_short_info_data_64_t) / sizeof (natural_t))) 350 351 struct mach_vm_read_entry { 352 mach_vm_address_t address; 353 mach_vm_size_t size; 354 }; 355 356 struct vm_read_entry { 357 vm_address_t address; 358 vm_size_t size; 359 }; 360 361 #ifdef VM32_SUPPORT 362 struct vm32_read_entry { 363 vm32_address_t address; 364 vm32_size_t size; 365 }; 366 #endif 367 368 369 #define VM_MAP_ENTRY_MAX (256) 370 371 typedef struct mach_vm_read_entry mach_vm_read_entry_t[VM_MAP_ENTRY_MAX]; 372 typedef struct vm_read_entry vm_read_entry_t[VM_MAP_ENTRY_MAX]; 373 #ifdef VM32_SUPPORT 374 typedef struct vm32_read_entry vm32_read_entry_t[VM_MAP_ENTRY_MAX]; 375 #endif 376 377 #pragma pack(pop) 378 379 380 #define VM_PAGE_INFO_MAX 381 typedef int *vm_page_info_t; 382 typedef int vm_page_info_data_t[VM_PAGE_INFO_MAX]; 383 typedef int vm_page_info_flavor_t; 384 385 #define VM_PAGE_INFO_BASIC 1 386 struct vm_page_info_basic { 387 int disposition; 388 int ref_count; 389 vm_object_id_t object_id; 390 memory_object_offset_t offset; 391 int depth; 392 int __pad; /* pad to 64-bit boundary */ 393 }; 394 typedef struct vm_page_info_basic *vm_page_info_basic_t; 395 typedef struct vm_page_info_basic vm_page_info_basic_data_t; 396 397 #define VM_PAGE_INFO_BASIC_COUNT ((mach_msg_type_number_t) \ 398 (sizeof(vm_page_info_basic_data_t)/sizeof(int))) 399 400 401 #endif /*_MACH_VM_REGION_H_*/ 402