1//===-- llvm/BinaryFormat/MachO.h - The MachO file format -------*- C++/-*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines manifest constants for the MachO object file format. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_BINARYFORMAT_MACHO_H 15#define LLVM_BINARYFORMAT_MACHO_H 16 17#include "llvm/Support/Compiler.h" 18#include "llvm/Support/DataTypes.h" 19#include "llvm/Support/Host.h" 20 21namespace llvm { 22namespace MachO { 23// Enums from <mach-o/loader.h> 24enum : uint32_t { 25 // Constants for the "magic" field in llvm::MachO::mach_header and 26 // llvm::MachO::mach_header_64 27 MH_MAGIC = 0xFEEDFACEu, 28 MH_CIGAM = 0xCEFAEDFEu, 29 MH_MAGIC_64 = 0xFEEDFACFu, 30 MH_CIGAM_64 = 0xCFFAEDFEu, 31 FAT_MAGIC = 0xCAFEBABEu, 32 FAT_CIGAM = 0xBEBAFECAu, 33 FAT_MAGIC_64 = 0xCAFEBABFu, 34 FAT_CIGAM_64 = 0xBFBAFECAu 35}; 36 37enum HeaderFileType { 38 // Constants for the "filetype" field in llvm::MachO::mach_header and 39 // llvm::MachO::mach_header_64 40 MH_OBJECT = 0x1u, 41 MH_EXECUTE = 0x2u, 42 MH_FVMLIB = 0x3u, 43 MH_CORE = 0x4u, 44 MH_PRELOAD = 0x5u, 45 MH_DYLIB = 0x6u, 46 MH_DYLINKER = 0x7u, 47 MH_BUNDLE = 0x8u, 48 MH_DYLIB_STUB = 0x9u, 49 MH_DSYM = 0xAu, 50 MH_KEXT_BUNDLE = 0xBu 51}; 52 53enum { 54 // Constant bits for the "flags" field in llvm::MachO::mach_header and 55 // llvm::MachO::mach_header_64 56 MH_NOUNDEFS = 0x00000001u, 57 MH_INCRLINK = 0x00000002u, 58 MH_DYLDLINK = 0x00000004u, 59 MH_BINDATLOAD = 0x00000008u, 60 MH_PREBOUND = 0x00000010u, 61 MH_SPLIT_SEGS = 0x00000020u, 62 MH_LAZY_INIT = 0x00000040u, 63 MH_TWOLEVEL = 0x00000080u, 64 MH_FORCE_FLAT = 0x00000100u, 65 MH_NOMULTIDEFS = 0x00000200u, 66 MH_NOFIXPREBINDING = 0x00000400u, 67 MH_PREBINDABLE = 0x00000800u, 68 MH_ALLMODSBOUND = 0x00001000u, 69 MH_SUBSECTIONS_VIA_SYMBOLS = 0x00002000u, 70 MH_CANONICAL = 0x00004000u, 71 MH_WEAK_DEFINES = 0x00008000u, 72 MH_BINDS_TO_WEAK = 0x00010000u, 73 MH_ALLOW_STACK_EXECUTION = 0x00020000u, 74 MH_ROOT_SAFE = 0x00040000u, 75 MH_SETUID_SAFE = 0x00080000u, 76 MH_NO_REEXPORTED_DYLIBS = 0x00100000u, 77 MH_PIE = 0x00200000u, 78 MH_DEAD_STRIPPABLE_DYLIB = 0x00400000u, 79 MH_HAS_TLV_DESCRIPTORS = 0x00800000u, 80 MH_NO_HEAP_EXECUTION = 0x01000000u, 81 MH_APP_EXTENSION_SAFE = 0x02000000u 82}; 83 84enum : uint32_t { 85 // Flags for the "cmd" field in llvm::MachO::load_command 86 LC_REQ_DYLD = 0x80000000u 87}; 88 89#define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) LCName = LCValue, 90 91enum LoadCommandType : uint32_t { 92#include "llvm/BinaryFormat/MachO.def" 93}; 94 95#undef HANDLE_LOAD_COMMAND 96 97enum : uint32_t { 98 // Constant bits for the "flags" field in llvm::MachO::segment_command 99 SG_HIGHVM = 0x1u, 100 SG_FVMLIB = 0x2u, 101 SG_NORELOC = 0x4u, 102 SG_PROTECTED_VERSION_1 = 0x8u, 103 104 // Constant masks for the "flags" field in llvm::MachO::section and 105 // llvm::MachO::section_64 106 SECTION_TYPE = 0x000000ffu, // SECTION_TYPE 107 SECTION_ATTRIBUTES = 0xffffff00u, // SECTION_ATTRIBUTES 108 SECTION_ATTRIBUTES_USR = 0xff000000u, // SECTION_ATTRIBUTES_USR 109 SECTION_ATTRIBUTES_SYS = 0x00ffff00u // SECTION_ATTRIBUTES_SYS 110}; 111 112/// These are the section type and attributes fields. A MachO section can 113/// have only one Type, but can have any of the attributes specified. 114enum SectionType : uint32_t { 115 // Constant masks for the "flags[7:0]" field in llvm::MachO::section and 116 // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE) 117 118 /// S_REGULAR - Regular section. 119 S_REGULAR = 0x00u, 120 /// S_ZEROFILL - Zero fill on demand section. 121 S_ZEROFILL = 0x01u, 122 /// S_CSTRING_LITERALS - Section with literal C strings. 123 S_CSTRING_LITERALS = 0x02u, 124 /// S_4BYTE_LITERALS - Section with 4 byte literals. 125 S_4BYTE_LITERALS = 0x03u, 126 /// S_8BYTE_LITERALS - Section with 8 byte literals. 127 S_8BYTE_LITERALS = 0x04u, 128 /// S_LITERAL_POINTERS - Section with pointers to literals. 129 S_LITERAL_POINTERS = 0x05u, 130 /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers. 131 S_NON_LAZY_SYMBOL_POINTERS = 0x06u, 132 /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers. 133 S_LAZY_SYMBOL_POINTERS = 0x07u, 134 /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in 135 /// the Reserved2 field. 136 S_SYMBOL_STUBS = 0x08u, 137 /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for 138 /// initialization. 139 S_MOD_INIT_FUNC_POINTERS = 0x09u, 140 /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for 141 /// termination. 142 S_MOD_TERM_FUNC_POINTERS = 0x0au, 143 /// S_COALESCED - Section contains symbols that are to be coalesced. 144 S_COALESCED = 0x0bu, 145 /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4 146 /// gigabytes). 147 S_GB_ZEROFILL = 0x0cu, 148 /// S_INTERPOSING - Section with only pairs of function pointers for 149 /// interposing. 150 S_INTERPOSING = 0x0du, 151 /// S_16BYTE_LITERALS - Section with only 16 byte literals. 152 S_16BYTE_LITERALS = 0x0eu, 153 /// S_DTRACE_DOF - Section contains DTrace Object Format. 154 S_DTRACE_DOF = 0x0fu, 155 /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to 156 /// lazy loaded dylibs. 157 S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10u, 158 /// S_THREAD_LOCAL_REGULAR - Thread local data section. 159 S_THREAD_LOCAL_REGULAR = 0x11u, 160 /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section. 161 S_THREAD_LOCAL_ZEROFILL = 0x12u, 162 /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable 163 /// structure data. 164 S_THREAD_LOCAL_VARIABLES = 0x13u, 165 /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread 166 /// local structures. 167 S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14u, 168 /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local 169 /// variable initialization pointers to functions. 170 S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15u, 171 172 LAST_KNOWN_SECTION_TYPE = S_THREAD_LOCAL_INIT_FUNCTION_POINTERS 173}; 174 175enum : uint32_t { 176 // Constant masks for the "flags[31:24]" field in llvm::MachO::section and 177 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR) 178 179 /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine 180 /// instructions. 181 S_ATTR_PURE_INSTRUCTIONS = 0x80000000u, 182 /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be 183 /// in a ranlib table of contents. 184 S_ATTR_NO_TOC = 0x40000000u, 185 /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section 186 /// in files with the MY_DYLDLINK flag. 187 S_ATTR_STRIP_STATIC_SYMS = 0x20000000u, 188 /// S_ATTR_NO_DEAD_STRIP - No dead stripping. 189 S_ATTR_NO_DEAD_STRIP = 0x10000000u, 190 /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks. 191 S_ATTR_LIVE_SUPPORT = 0x08000000u, 192 /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by 193 /// dyld. 194 S_ATTR_SELF_MODIFYING_CODE = 0x04000000u, 195 /// S_ATTR_DEBUG - A debug section. 196 S_ATTR_DEBUG = 0x02000000u, 197 198 // Constant masks for the "flags[23:8]" field in llvm::MachO::section and 199 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS) 200 201 /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions. 202 S_ATTR_SOME_INSTRUCTIONS = 0x00000400u, 203 /// S_ATTR_EXT_RELOC - Section has external relocation entries. 204 S_ATTR_EXT_RELOC = 0x00000200u, 205 /// S_ATTR_LOC_RELOC - Section has local relocation entries. 206 S_ATTR_LOC_RELOC = 0x00000100u, 207 208 // Constant masks for the value of an indirect symbol in an indirect 209 // symbol table 210 INDIRECT_SYMBOL_LOCAL = 0x80000000u, 211 INDIRECT_SYMBOL_ABS = 0x40000000u 212}; 213 214enum DataRegionType { 215 // Constants for the "kind" field in a data_in_code_entry structure 216 DICE_KIND_DATA = 1u, 217 DICE_KIND_JUMP_TABLE8 = 2u, 218 DICE_KIND_JUMP_TABLE16 = 3u, 219 DICE_KIND_JUMP_TABLE32 = 4u, 220 DICE_KIND_ABS_JUMP_TABLE32 = 5u 221}; 222 223enum RebaseType { 224 REBASE_TYPE_POINTER = 1u, 225 REBASE_TYPE_TEXT_ABSOLUTE32 = 2u, 226 REBASE_TYPE_TEXT_PCREL32 = 3u 227}; 228 229enum { REBASE_OPCODE_MASK = 0xF0u, REBASE_IMMEDIATE_MASK = 0x0Fu }; 230 231enum RebaseOpcode { 232 REBASE_OPCODE_DONE = 0x00u, 233 REBASE_OPCODE_SET_TYPE_IMM = 0x10u, 234 REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x20u, 235 REBASE_OPCODE_ADD_ADDR_ULEB = 0x30u, 236 REBASE_OPCODE_ADD_ADDR_IMM_SCALED = 0x40u, 237 REBASE_OPCODE_DO_REBASE_IMM_TIMES = 0x50u, 238 REBASE_OPCODE_DO_REBASE_ULEB_TIMES = 0x60u, 239 REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB = 0x70u, 240 REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u 241}; 242 243enum BindType { 244 BIND_TYPE_POINTER = 1u, 245 BIND_TYPE_TEXT_ABSOLUTE32 = 2u, 246 BIND_TYPE_TEXT_PCREL32 = 3u 247}; 248 249enum BindSpecialDylib { 250 BIND_SPECIAL_DYLIB_SELF = 0, 251 BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE = -1, 252 BIND_SPECIAL_DYLIB_FLAT_LOOKUP = -2 253}; 254 255enum { 256 BIND_SYMBOL_FLAGS_WEAK_IMPORT = 0x1u, 257 BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION = 0x8u, 258 259 BIND_OPCODE_MASK = 0xF0u, 260 BIND_IMMEDIATE_MASK = 0x0Fu 261}; 262 263enum BindOpcode { 264 BIND_OPCODE_DONE = 0x00u, 265 BIND_OPCODE_SET_DYLIB_ORDINAL_IMM = 0x10u, 266 BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB = 0x20u, 267 BIND_OPCODE_SET_DYLIB_SPECIAL_IMM = 0x30u, 268 BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM = 0x40u, 269 BIND_OPCODE_SET_TYPE_IMM = 0x50u, 270 BIND_OPCODE_SET_ADDEND_SLEB = 0x60u, 271 BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x70u, 272 BIND_OPCODE_ADD_ADDR_ULEB = 0x80u, 273 BIND_OPCODE_DO_BIND = 0x90u, 274 BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB = 0xA0u, 275 BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED = 0xB0u, 276 BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u 277}; 278 279enum { 280 EXPORT_SYMBOL_FLAGS_KIND_MASK = 0x03u, 281 EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION = 0x04u, 282 EXPORT_SYMBOL_FLAGS_REEXPORT = 0x08u, 283 EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER = 0x10u 284}; 285 286enum ExportSymbolKind { 287 EXPORT_SYMBOL_FLAGS_KIND_REGULAR = 0x00u, 288 EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL = 0x01u, 289 EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE = 0x02u 290}; 291 292enum { 293 // Constant masks for the "n_type" field in llvm::MachO::nlist and 294 // llvm::MachO::nlist_64 295 N_STAB = 0xe0, 296 N_PEXT = 0x10, 297 N_TYPE = 0x0e, 298 N_EXT = 0x01 299}; 300 301enum NListType : uint8_t { 302 // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and 303 // llvm::MachO::nlist_64 304 N_UNDF = 0x0u, 305 N_ABS = 0x2u, 306 N_SECT = 0xeu, 307 N_PBUD = 0xcu, 308 N_INDR = 0xau 309}; 310 311enum SectionOrdinal { 312 // Constants for the "n_sect" field in llvm::MachO::nlist and 313 // llvm::MachO::nlist_64 314 NO_SECT = 0u, 315 MAX_SECT = 0xffu 316}; 317 318enum { 319 // Constant masks for the "n_desc" field in llvm::MachO::nlist and 320 // llvm::MachO::nlist_64 321 // The low 3 bits are the for the REFERENCE_TYPE. 322 REFERENCE_TYPE = 0x7, 323 REFERENCE_FLAG_UNDEFINED_NON_LAZY = 0, 324 REFERENCE_FLAG_UNDEFINED_LAZY = 1, 325 REFERENCE_FLAG_DEFINED = 2, 326 REFERENCE_FLAG_PRIVATE_DEFINED = 3, 327 REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY = 4, 328 REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY = 5, 329 // Flag bits (some overlap with the library ordinal bits). 330 N_ARM_THUMB_DEF = 0x0008u, 331 REFERENCED_DYNAMICALLY = 0x0010u, 332 N_NO_DEAD_STRIP = 0x0020u, 333 N_WEAK_REF = 0x0040u, 334 N_WEAK_DEF = 0x0080u, 335 N_SYMBOL_RESOLVER = 0x0100u, 336 N_ALT_ENTRY = 0x0200u, 337 // For undefined symbols coming from libraries, see GET_LIBRARY_ORDINAL() 338 // as these are in the top 8 bits. 339 SELF_LIBRARY_ORDINAL = 0x0, 340 MAX_LIBRARY_ORDINAL = 0xfd, 341 DYNAMIC_LOOKUP_ORDINAL = 0xfe, 342 EXECUTABLE_ORDINAL = 0xff 343}; 344 345enum StabType { 346 // Constant values for the "n_type" field in llvm::MachO::nlist and 347 // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0" 348 N_GSYM = 0x20u, 349 N_FNAME = 0x22u, 350 N_FUN = 0x24u, 351 N_STSYM = 0x26u, 352 N_LCSYM = 0x28u, 353 N_BNSYM = 0x2Eu, 354 N_PC = 0x30u, 355 N_AST = 0x32u, 356 N_OPT = 0x3Cu, 357 N_RSYM = 0x40u, 358 N_SLINE = 0x44u, 359 N_ENSYM = 0x4Eu, 360 N_SSYM = 0x60u, 361 N_SO = 0x64u, 362 N_OSO = 0x66u, 363 N_LSYM = 0x80u, 364 N_BINCL = 0x82u, 365 N_SOL = 0x84u, 366 N_PARAMS = 0x86u, 367 N_VERSION = 0x88u, 368 N_OLEVEL = 0x8Au, 369 N_PSYM = 0xA0u, 370 N_EINCL = 0xA2u, 371 N_ENTRY = 0xA4u, 372 N_LBRAC = 0xC0u, 373 N_EXCL = 0xC2u, 374 N_RBRAC = 0xE0u, 375 N_BCOMM = 0xE2u, 376 N_ECOMM = 0xE4u, 377 N_ECOML = 0xE8u, 378 N_LENG = 0xFEu 379}; 380 381enum : uint32_t { 382 // Constant values for the r_symbolnum field in an 383 // llvm::MachO::relocation_info structure when r_extern is 0. 384 R_ABS = 0, 385 386 // Constant bits for the r_address field in an 387 // llvm::MachO::relocation_info structure. 388 R_SCATTERED = 0x80000000 389}; 390 391enum RelocationInfoType { 392 // Constant values for the r_type field in an 393 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info 394 // structure. 395 GENERIC_RELOC_VANILLA = 0, 396 GENERIC_RELOC_PAIR = 1, 397 GENERIC_RELOC_SECTDIFF = 2, 398 GENERIC_RELOC_PB_LA_PTR = 3, 399 GENERIC_RELOC_LOCAL_SECTDIFF = 4, 400 GENERIC_RELOC_TLV = 5, 401 402 // Constant values for the r_type field in a PowerPC architecture 403 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info 404 // structure. 405 PPC_RELOC_VANILLA = GENERIC_RELOC_VANILLA, 406 PPC_RELOC_PAIR = GENERIC_RELOC_PAIR, 407 PPC_RELOC_BR14 = 2, 408 PPC_RELOC_BR24 = 3, 409 PPC_RELOC_HI16 = 4, 410 PPC_RELOC_LO16 = 5, 411 PPC_RELOC_HA16 = 6, 412 PPC_RELOC_LO14 = 7, 413 PPC_RELOC_SECTDIFF = 8, 414 PPC_RELOC_PB_LA_PTR = 9, 415 PPC_RELOC_HI16_SECTDIFF = 10, 416 PPC_RELOC_LO16_SECTDIFF = 11, 417 PPC_RELOC_HA16_SECTDIFF = 12, 418 PPC_RELOC_JBSR = 13, 419 PPC_RELOC_LO14_SECTDIFF = 14, 420 PPC_RELOC_LOCAL_SECTDIFF = 15, 421 422 // Constant values for the r_type field in an ARM architecture 423 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info 424 // structure. 425 ARM_RELOC_VANILLA = GENERIC_RELOC_VANILLA, 426 ARM_RELOC_PAIR = GENERIC_RELOC_PAIR, 427 ARM_RELOC_SECTDIFF = GENERIC_RELOC_SECTDIFF, 428 ARM_RELOC_LOCAL_SECTDIFF = 3, 429 ARM_RELOC_PB_LA_PTR = 4, 430 ARM_RELOC_BR24 = 5, 431 ARM_THUMB_RELOC_BR22 = 6, 432 ARM_THUMB_32BIT_BRANCH = 7, // obsolete 433 ARM_RELOC_HALF = 8, 434 ARM_RELOC_HALF_SECTDIFF = 9, 435 436 // Constant values for the r_type field in an ARM64 architecture 437 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info 438 // structure. 439 440 // For pointers. 441 ARM64_RELOC_UNSIGNED = 0, 442 // Must be followed by an ARM64_RELOC_UNSIGNED 443 ARM64_RELOC_SUBTRACTOR = 1, 444 // A B/BL instruction with 26-bit displacement. 445 ARM64_RELOC_BRANCH26 = 2, 446 // PC-rel distance to page of target. 447 ARM64_RELOC_PAGE21 = 3, 448 // Offset within page, scaled by r_length. 449 ARM64_RELOC_PAGEOFF12 = 4, 450 // PC-rel distance to page of GOT slot. 451 ARM64_RELOC_GOT_LOAD_PAGE21 = 5, 452 // Offset within page of GOT slot, scaled by r_length. 453 ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6, 454 // For pointers to GOT slots. 455 ARM64_RELOC_POINTER_TO_GOT = 7, 456 // PC-rel distance to page of TLVP slot. 457 ARM64_RELOC_TLVP_LOAD_PAGE21 = 8, 458 // Offset within page of TLVP slot, scaled by r_length. 459 ARM64_RELOC_TLVP_LOAD_PAGEOFF12 = 9, 460 // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12. 461 ARM64_RELOC_ADDEND = 10, 462 463 // Constant values for the r_type field in an x86_64 architecture 464 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info 465 // structure 466 X86_64_RELOC_UNSIGNED = 0, 467 X86_64_RELOC_SIGNED = 1, 468 X86_64_RELOC_BRANCH = 2, 469 X86_64_RELOC_GOT_LOAD = 3, 470 X86_64_RELOC_GOT = 4, 471 X86_64_RELOC_SUBTRACTOR = 5, 472 X86_64_RELOC_SIGNED_1 = 6, 473 X86_64_RELOC_SIGNED_2 = 7, 474 X86_64_RELOC_SIGNED_4 = 8, 475 X86_64_RELOC_TLV = 9 476}; 477 478// Values for segment_command.initprot. 479// From <mach/vm_prot.h> 480enum { VM_PROT_READ = 0x1, VM_PROT_WRITE = 0x2, VM_PROT_EXECUTE = 0x4 }; 481 482// Values for platform field in build_version_command. 483enum { 484 PLATFORM_MACOS = 1, 485 PLATFORM_IOS = 2, 486 PLATFORM_TVOS = 3, 487 PLATFORM_WATCHOS = 4, 488 PLATFORM_BRIDGEOS = 5 489}; 490 491// Values for tools enum in build_tool_version. 492enum { TOOL_CLANG = 1, TOOL_SWIFT = 2, TOOL_LD = 3 }; 493 494// Structs from <mach-o/loader.h> 495 496struct mach_header { 497 uint32_t magic; 498 uint32_t cputype; 499 uint32_t cpusubtype; 500 uint32_t filetype; 501 uint32_t ncmds; 502 uint32_t sizeofcmds; 503 uint32_t flags; 504}; 505 506struct mach_header_64 { 507 uint32_t magic; 508 uint32_t cputype; 509 uint32_t cpusubtype; 510 uint32_t filetype; 511 uint32_t ncmds; 512 uint32_t sizeofcmds; 513 uint32_t flags; 514 uint32_t reserved; 515}; 516 517struct load_command { 518 uint32_t cmd; 519 uint32_t cmdsize; 520}; 521 522struct segment_command { 523 uint32_t cmd; 524 uint32_t cmdsize; 525 char segname[16]; 526 uint32_t vmaddr; 527 uint32_t vmsize; 528 uint32_t fileoff; 529 uint32_t filesize; 530 uint32_t maxprot; 531 uint32_t initprot; 532 uint32_t nsects; 533 uint32_t flags; 534}; 535 536struct segment_command_64 { 537 uint32_t cmd; 538 uint32_t cmdsize; 539 char segname[16]; 540 uint64_t vmaddr; 541 uint64_t vmsize; 542 uint64_t fileoff; 543 uint64_t filesize; 544 uint32_t maxprot; 545 uint32_t initprot; 546 uint32_t nsects; 547 uint32_t flags; 548}; 549 550struct section { 551 char sectname[16]; 552 char segname[16]; 553 uint32_t addr; 554 uint32_t size; 555 uint32_t offset; 556 uint32_t align; 557 uint32_t reloff; 558 uint32_t nreloc; 559 uint32_t flags; 560 uint32_t reserved1; 561 uint32_t reserved2; 562}; 563 564struct section_64 { 565 char sectname[16]; 566 char segname[16]; 567 uint64_t addr; 568 uint64_t size; 569 uint32_t offset; 570 uint32_t align; 571 uint32_t reloff; 572 uint32_t nreloc; 573 uint32_t flags; 574 uint32_t reserved1; 575 uint32_t reserved2; 576 uint32_t reserved3; 577}; 578 579struct fvmlib { 580 uint32_t name; 581 uint32_t minor_version; 582 uint32_t header_addr; 583}; 584 585// The fvmlib_command is obsolete and no longer supported. 586struct fvmlib_command { 587 uint32_t cmd; 588 uint32_t cmdsize; 589 struct fvmlib fvmlib; 590}; 591 592struct dylib { 593 uint32_t name; 594 uint32_t timestamp; 595 uint32_t current_version; 596 uint32_t compatibility_version; 597}; 598 599struct dylib_command { 600 uint32_t cmd; 601 uint32_t cmdsize; 602 struct dylib dylib; 603}; 604 605struct sub_framework_command { 606 uint32_t cmd; 607 uint32_t cmdsize; 608 uint32_t umbrella; 609}; 610 611struct sub_client_command { 612 uint32_t cmd; 613 uint32_t cmdsize; 614 uint32_t client; 615}; 616 617struct sub_umbrella_command { 618 uint32_t cmd; 619 uint32_t cmdsize; 620 uint32_t sub_umbrella; 621}; 622 623struct sub_library_command { 624 uint32_t cmd; 625 uint32_t cmdsize; 626 uint32_t sub_library; 627}; 628 629// The prebound_dylib_command is obsolete and no longer supported. 630struct prebound_dylib_command { 631 uint32_t cmd; 632 uint32_t cmdsize; 633 uint32_t name; 634 uint32_t nmodules; 635 uint32_t linked_modules; 636}; 637 638struct dylinker_command { 639 uint32_t cmd; 640 uint32_t cmdsize; 641 uint32_t name; 642}; 643 644struct thread_command { 645 uint32_t cmd; 646 uint32_t cmdsize; 647}; 648 649struct routines_command { 650 uint32_t cmd; 651 uint32_t cmdsize; 652 uint32_t init_address; 653 uint32_t init_module; 654 uint32_t reserved1; 655 uint32_t reserved2; 656 uint32_t reserved3; 657 uint32_t reserved4; 658 uint32_t reserved5; 659 uint32_t reserved6; 660}; 661 662struct routines_command_64 { 663 uint32_t cmd; 664 uint32_t cmdsize; 665 uint64_t init_address; 666 uint64_t init_module; 667 uint64_t reserved1; 668 uint64_t reserved2; 669 uint64_t reserved3; 670 uint64_t reserved4; 671 uint64_t reserved5; 672 uint64_t reserved6; 673}; 674 675struct symtab_command { 676 uint32_t cmd; 677 uint32_t cmdsize; 678 uint32_t symoff; 679 uint32_t nsyms; 680 uint32_t stroff; 681 uint32_t strsize; 682}; 683 684struct dysymtab_command { 685 uint32_t cmd; 686 uint32_t cmdsize; 687 uint32_t ilocalsym; 688 uint32_t nlocalsym; 689 uint32_t iextdefsym; 690 uint32_t nextdefsym; 691 uint32_t iundefsym; 692 uint32_t nundefsym; 693 uint32_t tocoff; 694 uint32_t ntoc; 695 uint32_t modtaboff; 696 uint32_t nmodtab; 697 uint32_t extrefsymoff; 698 uint32_t nextrefsyms; 699 uint32_t indirectsymoff; 700 uint32_t nindirectsyms; 701 uint32_t extreloff; 702 uint32_t nextrel; 703 uint32_t locreloff; 704 uint32_t nlocrel; 705}; 706 707struct dylib_table_of_contents { 708 uint32_t symbol_index; 709 uint32_t module_index; 710}; 711 712struct dylib_module { 713 uint32_t module_name; 714 uint32_t iextdefsym; 715 uint32_t nextdefsym; 716 uint32_t irefsym; 717 uint32_t nrefsym; 718 uint32_t ilocalsym; 719 uint32_t nlocalsym; 720 uint32_t iextrel; 721 uint32_t nextrel; 722 uint32_t iinit_iterm; 723 uint32_t ninit_nterm; 724 uint32_t objc_module_info_addr; 725 uint32_t objc_module_info_size; 726}; 727 728struct dylib_module_64 { 729 uint32_t module_name; 730 uint32_t iextdefsym; 731 uint32_t nextdefsym; 732 uint32_t irefsym; 733 uint32_t nrefsym; 734 uint32_t ilocalsym; 735 uint32_t nlocalsym; 736 uint32_t iextrel; 737 uint32_t nextrel; 738 uint32_t iinit_iterm; 739 uint32_t ninit_nterm; 740 uint32_t objc_module_info_size; 741 uint64_t objc_module_info_addr; 742}; 743 744struct dylib_reference { 745 uint32_t isym : 24, flags : 8; 746}; 747 748// The twolevel_hints_command is obsolete and no longer supported. 749struct twolevel_hints_command { 750 uint32_t cmd; 751 uint32_t cmdsize; 752 uint32_t offset; 753 uint32_t nhints; 754}; 755 756// The twolevel_hints_command is obsolete and no longer supported. 757struct twolevel_hint { 758 uint32_t isub_image : 8, itoc : 24; 759}; 760 761// The prebind_cksum_command is obsolete and no longer supported. 762struct prebind_cksum_command { 763 uint32_t cmd; 764 uint32_t cmdsize; 765 uint32_t cksum; 766}; 767 768struct uuid_command { 769 uint32_t cmd; 770 uint32_t cmdsize; 771 uint8_t uuid[16]; 772}; 773 774struct rpath_command { 775 uint32_t cmd; 776 uint32_t cmdsize; 777 uint32_t path; 778}; 779 780struct linkedit_data_command { 781 uint32_t cmd; 782 uint32_t cmdsize; 783 uint32_t dataoff; 784 uint32_t datasize; 785}; 786 787struct data_in_code_entry { 788 uint32_t offset; 789 uint16_t length; 790 uint16_t kind; 791}; 792 793struct source_version_command { 794 uint32_t cmd; 795 uint32_t cmdsize; 796 uint64_t version; 797}; 798 799struct encryption_info_command { 800 uint32_t cmd; 801 uint32_t cmdsize; 802 uint32_t cryptoff; 803 uint32_t cryptsize; 804 uint32_t cryptid; 805}; 806 807struct encryption_info_command_64 { 808 uint32_t cmd; 809 uint32_t cmdsize; 810 uint32_t cryptoff; 811 uint32_t cryptsize; 812 uint32_t cryptid; 813 uint32_t pad; 814}; 815 816struct version_min_command { 817 uint32_t cmd; // LC_VERSION_MIN_MACOSX or 818 // LC_VERSION_MIN_IPHONEOS 819 uint32_t cmdsize; // sizeof(struct version_min_command) 820 uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz 821 uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz 822}; 823 824struct note_command { 825 uint32_t cmd; // LC_NOTE 826 uint32_t cmdsize; // sizeof(struct note_command) 827 char data_owner[16]; // owner name for this LC_NOTE 828 uint64_t offset; // file offset of this data 829 uint64_t size; // length of data region 830}; 831 832struct build_tool_version { 833 uint32_t tool; // enum for the tool 834 uint32_t version; // version of the tool 835}; 836 837struct build_version_command { 838 uint32_t cmd; // LC_BUILD_VERSION 839 uint32_t cmdsize; // sizeof(struct build_version_command) + 840 // ntools * sizeof(struct build_tool_version) 841 uint32_t platform; // platform 842 uint32_t minos; // X.Y.Z is encoded in nibbles xxxx.yy.zz 843 uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz 844 uint32_t ntools; // number of tool entries following this 845}; 846 847struct dyld_info_command { 848 uint32_t cmd; 849 uint32_t cmdsize; 850 uint32_t rebase_off; 851 uint32_t rebase_size; 852 uint32_t bind_off; 853 uint32_t bind_size; 854 uint32_t weak_bind_off; 855 uint32_t weak_bind_size; 856 uint32_t lazy_bind_off; 857 uint32_t lazy_bind_size; 858 uint32_t export_off; 859 uint32_t export_size; 860}; 861 862struct linker_option_command { 863 uint32_t cmd; 864 uint32_t cmdsize; 865 uint32_t count; 866}; 867 868// The symseg_command is obsolete and no longer supported. 869struct symseg_command { 870 uint32_t cmd; 871 uint32_t cmdsize; 872 uint32_t offset; 873 uint32_t size; 874}; 875 876// The ident_command is obsolete and no longer supported. 877struct ident_command { 878 uint32_t cmd; 879 uint32_t cmdsize; 880}; 881 882// The fvmfile_command is obsolete and no longer supported. 883struct fvmfile_command { 884 uint32_t cmd; 885 uint32_t cmdsize; 886 uint32_t name; 887 uint32_t header_addr; 888}; 889 890struct tlv_descriptor_32 { 891 uint32_t thunk; 892 uint32_t key; 893 uint32_t offset; 894}; 895 896struct tlv_descriptor_64 { 897 uint64_t thunk; 898 uint64_t key; 899 uint64_t offset; 900}; 901 902struct tlv_descriptor { 903 uintptr_t thunk; 904 uintptr_t key; 905 uintptr_t offset; 906}; 907 908struct entry_point_command { 909 uint32_t cmd; 910 uint32_t cmdsize; 911 uint64_t entryoff; 912 uint64_t stacksize; 913}; 914 915// Structs from <mach-o/fat.h> 916struct fat_header { 917 uint32_t magic; 918 uint32_t nfat_arch; 919}; 920 921struct fat_arch { 922 uint32_t cputype; 923 uint32_t cpusubtype; 924 uint32_t offset; 925 uint32_t size; 926 uint32_t align; 927}; 928 929struct fat_arch_64 { 930 uint32_t cputype; 931 uint32_t cpusubtype; 932 uint64_t offset; 933 uint64_t size; 934 uint32_t align; 935 uint32_t reserved; 936}; 937 938// Structs from <mach-o/reloc.h> 939struct relocation_info { 940 int32_t r_address; 941 uint32_t r_symbolnum : 24, r_pcrel : 1, r_length : 2, r_extern : 1, 942 r_type : 4; 943}; 944 945struct scattered_relocation_info { 946#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN) 947 uint32_t r_scattered : 1, r_pcrel : 1, r_length : 2, r_type : 4, 948 r_address : 24; 949#else 950 uint32_t r_address : 24, r_type : 4, r_length : 2, r_pcrel : 1, 951 r_scattered : 1; 952#endif 953 int32_t r_value; 954}; 955 956// Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier 957struct any_relocation_info { 958 uint32_t r_word0, r_word1; 959}; 960 961// Structs from <mach-o/nlist.h> 962struct nlist_base { 963 uint32_t n_strx; 964 uint8_t n_type; 965 uint8_t n_sect; 966 uint16_t n_desc; 967}; 968 969struct nlist { 970 uint32_t n_strx; 971 uint8_t n_type; 972 uint8_t n_sect; 973 int16_t n_desc; 974 uint32_t n_value; 975}; 976 977struct nlist_64 { 978 uint32_t n_strx; 979 uint8_t n_type; 980 uint8_t n_sect; 981 uint16_t n_desc; 982 uint64_t n_value; 983}; 984 985// Byte order swapping functions for MachO structs 986 987inline void swapStruct(fat_header &mh) { 988 sys::swapByteOrder(mh.magic); 989 sys::swapByteOrder(mh.nfat_arch); 990} 991 992inline void swapStruct(fat_arch &mh) { 993 sys::swapByteOrder(mh.cputype); 994 sys::swapByteOrder(mh.cpusubtype); 995 sys::swapByteOrder(mh.offset); 996 sys::swapByteOrder(mh.size); 997 sys::swapByteOrder(mh.align); 998} 999 1000inline void swapStruct(fat_arch_64 &mh) { 1001 sys::swapByteOrder(mh.cputype); 1002 sys::swapByteOrder(mh.cpusubtype); 1003 sys::swapByteOrder(mh.offset); 1004 sys::swapByteOrder(mh.size); 1005 sys::swapByteOrder(mh.align); 1006 sys::swapByteOrder(mh.reserved); 1007} 1008 1009inline void swapStruct(mach_header &mh) { 1010 sys::swapByteOrder(mh.magic); 1011 sys::swapByteOrder(mh.cputype); 1012 sys::swapByteOrder(mh.cpusubtype); 1013 sys::swapByteOrder(mh.filetype); 1014 sys::swapByteOrder(mh.ncmds); 1015 sys::swapByteOrder(mh.sizeofcmds); 1016 sys::swapByteOrder(mh.flags); 1017} 1018 1019inline void swapStruct(mach_header_64 &H) { 1020 sys::swapByteOrder(H.magic); 1021 sys::swapByteOrder(H.cputype); 1022 sys::swapByteOrder(H.cpusubtype); 1023 sys::swapByteOrder(H.filetype); 1024 sys::swapByteOrder(H.ncmds); 1025 sys::swapByteOrder(H.sizeofcmds); 1026 sys::swapByteOrder(H.flags); 1027 sys::swapByteOrder(H.reserved); 1028} 1029 1030inline void swapStruct(load_command &lc) { 1031 sys::swapByteOrder(lc.cmd); 1032 sys::swapByteOrder(lc.cmdsize); 1033} 1034 1035inline void swapStruct(symtab_command &lc) { 1036 sys::swapByteOrder(lc.cmd); 1037 sys::swapByteOrder(lc.cmdsize); 1038 sys::swapByteOrder(lc.symoff); 1039 sys::swapByteOrder(lc.nsyms); 1040 sys::swapByteOrder(lc.stroff); 1041 sys::swapByteOrder(lc.strsize); 1042} 1043 1044inline void swapStruct(segment_command_64 &seg) { 1045 sys::swapByteOrder(seg.cmd); 1046 sys::swapByteOrder(seg.cmdsize); 1047 sys::swapByteOrder(seg.vmaddr); 1048 sys::swapByteOrder(seg.vmsize); 1049 sys::swapByteOrder(seg.fileoff); 1050 sys::swapByteOrder(seg.filesize); 1051 sys::swapByteOrder(seg.maxprot); 1052 sys::swapByteOrder(seg.initprot); 1053 sys::swapByteOrder(seg.nsects); 1054 sys::swapByteOrder(seg.flags); 1055} 1056 1057inline void swapStruct(segment_command &seg) { 1058 sys::swapByteOrder(seg.cmd); 1059 sys::swapByteOrder(seg.cmdsize); 1060 sys::swapByteOrder(seg.vmaddr); 1061 sys::swapByteOrder(seg.vmsize); 1062 sys::swapByteOrder(seg.fileoff); 1063 sys::swapByteOrder(seg.filesize); 1064 sys::swapByteOrder(seg.maxprot); 1065 sys::swapByteOrder(seg.initprot); 1066 sys::swapByteOrder(seg.nsects); 1067 sys::swapByteOrder(seg.flags); 1068} 1069 1070inline void swapStruct(section_64 §) { 1071 sys::swapByteOrder(sect.addr); 1072 sys::swapByteOrder(sect.size); 1073 sys::swapByteOrder(sect.offset); 1074 sys::swapByteOrder(sect.align); 1075 sys::swapByteOrder(sect.reloff); 1076 sys::swapByteOrder(sect.nreloc); 1077 sys::swapByteOrder(sect.flags); 1078 sys::swapByteOrder(sect.reserved1); 1079 sys::swapByteOrder(sect.reserved2); 1080} 1081 1082inline void swapStruct(section §) { 1083 sys::swapByteOrder(sect.addr); 1084 sys::swapByteOrder(sect.size); 1085 sys::swapByteOrder(sect.offset); 1086 sys::swapByteOrder(sect.align); 1087 sys::swapByteOrder(sect.reloff); 1088 sys::swapByteOrder(sect.nreloc); 1089 sys::swapByteOrder(sect.flags); 1090 sys::swapByteOrder(sect.reserved1); 1091 sys::swapByteOrder(sect.reserved2); 1092} 1093 1094inline void swapStruct(dyld_info_command &info) { 1095 sys::swapByteOrder(info.cmd); 1096 sys::swapByteOrder(info.cmdsize); 1097 sys::swapByteOrder(info.rebase_off); 1098 sys::swapByteOrder(info.rebase_size); 1099 sys::swapByteOrder(info.bind_off); 1100 sys::swapByteOrder(info.bind_size); 1101 sys::swapByteOrder(info.weak_bind_off); 1102 sys::swapByteOrder(info.weak_bind_size); 1103 sys::swapByteOrder(info.lazy_bind_off); 1104 sys::swapByteOrder(info.lazy_bind_size); 1105 sys::swapByteOrder(info.export_off); 1106 sys::swapByteOrder(info.export_size); 1107} 1108 1109inline void swapStruct(dylib_command &d) { 1110 sys::swapByteOrder(d.cmd); 1111 sys::swapByteOrder(d.cmdsize); 1112 sys::swapByteOrder(d.dylib.name); 1113 sys::swapByteOrder(d.dylib.timestamp); 1114 sys::swapByteOrder(d.dylib.current_version); 1115 sys::swapByteOrder(d.dylib.compatibility_version); 1116} 1117 1118inline void swapStruct(sub_framework_command &s) { 1119 sys::swapByteOrder(s.cmd); 1120 sys::swapByteOrder(s.cmdsize); 1121 sys::swapByteOrder(s.umbrella); 1122} 1123 1124inline void swapStruct(sub_umbrella_command &s) { 1125 sys::swapByteOrder(s.cmd); 1126 sys::swapByteOrder(s.cmdsize); 1127 sys::swapByteOrder(s.sub_umbrella); 1128} 1129 1130inline void swapStruct(sub_library_command &s) { 1131 sys::swapByteOrder(s.cmd); 1132 sys::swapByteOrder(s.cmdsize); 1133 sys::swapByteOrder(s.sub_library); 1134} 1135 1136inline void swapStruct(sub_client_command &s) { 1137 sys::swapByteOrder(s.cmd); 1138 sys::swapByteOrder(s.cmdsize); 1139 sys::swapByteOrder(s.client); 1140} 1141 1142inline void swapStruct(routines_command &r) { 1143 sys::swapByteOrder(r.cmd); 1144 sys::swapByteOrder(r.cmdsize); 1145 sys::swapByteOrder(r.init_address); 1146 sys::swapByteOrder(r.init_module); 1147 sys::swapByteOrder(r.reserved1); 1148 sys::swapByteOrder(r.reserved2); 1149 sys::swapByteOrder(r.reserved3); 1150 sys::swapByteOrder(r.reserved4); 1151 sys::swapByteOrder(r.reserved5); 1152 sys::swapByteOrder(r.reserved6); 1153} 1154 1155inline void swapStruct(routines_command_64 &r) { 1156 sys::swapByteOrder(r.cmd); 1157 sys::swapByteOrder(r.cmdsize); 1158 sys::swapByteOrder(r.init_address); 1159 sys::swapByteOrder(r.init_module); 1160 sys::swapByteOrder(r.reserved1); 1161 sys::swapByteOrder(r.reserved2); 1162 sys::swapByteOrder(r.reserved3); 1163 sys::swapByteOrder(r.reserved4); 1164 sys::swapByteOrder(r.reserved5); 1165 sys::swapByteOrder(r.reserved6); 1166} 1167 1168inline void swapStruct(thread_command &t) { 1169 sys::swapByteOrder(t.cmd); 1170 sys::swapByteOrder(t.cmdsize); 1171} 1172 1173inline void swapStruct(dylinker_command &d) { 1174 sys::swapByteOrder(d.cmd); 1175 sys::swapByteOrder(d.cmdsize); 1176 sys::swapByteOrder(d.name); 1177} 1178 1179inline void swapStruct(uuid_command &u) { 1180 sys::swapByteOrder(u.cmd); 1181 sys::swapByteOrder(u.cmdsize); 1182} 1183 1184inline void swapStruct(rpath_command &r) { 1185 sys::swapByteOrder(r.cmd); 1186 sys::swapByteOrder(r.cmdsize); 1187 sys::swapByteOrder(r.path); 1188} 1189 1190inline void swapStruct(source_version_command &s) { 1191 sys::swapByteOrder(s.cmd); 1192 sys::swapByteOrder(s.cmdsize); 1193 sys::swapByteOrder(s.version); 1194} 1195 1196inline void swapStruct(entry_point_command &e) { 1197 sys::swapByteOrder(e.cmd); 1198 sys::swapByteOrder(e.cmdsize); 1199 sys::swapByteOrder(e.entryoff); 1200 sys::swapByteOrder(e.stacksize); 1201} 1202 1203inline void swapStruct(encryption_info_command &e) { 1204 sys::swapByteOrder(e.cmd); 1205 sys::swapByteOrder(e.cmdsize); 1206 sys::swapByteOrder(e.cryptoff); 1207 sys::swapByteOrder(e.cryptsize); 1208 sys::swapByteOrder(e.cryptid); 1209} 1210 1211inline void swapStruct(encryption_info_command_64 &e) { 1212 sys::swapByteOrder(e.cmd); 1213 sys::swapByteOrder(e.cmdsize); 1214 sys::swapByteOrder(e.cryptoff); 1215 sys::swapByteOrder(e.cryptsize); 1216 sys::swapByteOrder(e.cryptid); 1217 sys::swapByteOrder(e.pad); 1218} 1219 1220inline void swapStruct(dysymtab_command &dst) { 1221 sys::swapByteOrder(dst.cmd); 1222 sys::swapByteOrder(dst.cmdsize); 1223 sys::swapByteOrder(dst.ilocalsym); 1224 sys::swapByteOrder(dst.nlocalsym); 1225 sys::swapByteOrder(dst.iextdefsym); 1226 sys::swapByteOrder(dst.nextdefsym); 1227 sys::swapByteOrder(dst.iundefsym); 1228 sys::swapByteOrder(dst.nundefsym); 1229 sys::swapByteOrder(dst.tocoff); 1230 sys::swapByteOrder(dst.ntoc); 1231 sys::swapByteOrder(dst.modtaboff); 1232 sys::swapByteOrder(dst.nmodtab); 1233 sys::swapByteOrder(dst.extrefsymoff); 1234 sys::swapByteOrder(dst.nextrefsyms); 1235 sys::swapByteOrder(dst.indirectsymoff); 1236 sys::swapByteOrder(dst.nindirectsyms); 1237 sys::swapByteOrder(dst.extreloff); 1238 sys::swapByteOrder(dst.nextrel); 1239 sys::swapByteOrder(dst.locreloff); 1240 sys::swapByteOrder(dst.nlocrel); 1241} 1242 1243inline void swapStruct(any_relocation_info &reloc) { 1244 sys::swapByteOrder(reloc.r_word0); 1245 sys::swapByteOrder(reloc.r_word1); 1246} 1247 1248inline void swapStruct(nlist_base &S) { 1249 sys::swapByteOrder(S.n_strx); 1250 sys::swapByteOrder(S.n_desc); 1251} 1252 1253inline void swapStruct(nlist &sym) { 1254 sys::swapByteOrder(sym.n_strx); 1255 sys::swapByteOrder(sym.n_desc); 1256 sys::swapByteOrder(sym.n_value); 1257} 1258 1259inline void swapStruct(nlist_64 &sym) { 1260 sys::swapByteOrder(sym.n_strx); 1261 sys::swapByteOrder(sym.n_desc); 1262 sys::swapByteOrder(sym.n_value); 1263} 1264 1265inline void swapStruct(linkedit_data_command &C) { 1266 sys::swapByteOrder(C.cmd); 1267 sys::swapByteOrder(C.cmdsize); 1268 sys::swapByteOrder(C.dataoff); 1269 sys::swapByteOrder(C.datasize); 1270} 1271 1272inline void swapStruct(linker_option_command &C) { 1273 sys::swapByteOrder(C.cmd); 1274 sys::swapByteOrder(C.cmdsize); 1275 sys::swapByteOrder(C.count); 1276} 1277 1278inline void swapStruct(version_min_command &C) { 1279 sys::swapByteOrder(C.cmd); 1280 sys::swapByteOrder(C.cmdsize); 1281 sys::swapByteOrder(C.version); 1282 sys::swapByteOrder(C.sdk); 1283} 1284 1285inline void swapStruct(note_command &C) { 1286 sys::swapByteOrder(C.cmd); 1287 sys::swapByteOrder(C.cmdsize); 1288 sys::swapByteOrder(C.offset); 1289 sys::swapByteOrder(C.size); 1290} 1291 1292inline void swapStruct(build_version_command &C) { 1293 sys::swapByteOrder(C.cmd); 1294 sys::swapByteOrder(C.cmdsize); 1295 sys::swapByteOrder(C.platform); 1296 sys::swapByteOrder(C.minos); 1297 sys::swapByteOrder(C.sdk); 1298 sys::swapByteOrder(C.ntools); 1299} 1300 1301inline void swapStruct(build_tool_version &C) { 1302 sys::swapByteOrder(C.tool); 1303 sys::swapByteOrder(C.version); 1304} 1305 1306inline void swapStruct(data_in_code_entry &C) { 1307 sys::swapByteOrder(C.offset); 1308 sys::swapByteOrder(C.length); 1309 sys::swapByteOrder(C.kind); 1310} 1311 1312inline void swapStruct(uint32_t &C) { sys::swapByteOrder(C); } 1313 1314// The prebind_cksum_command is obsolete and no longer supported. 1315inline void swapStruct(prebind_cksum_command &C) { 1316 sys::swapByteOrder(C.cmd); 1317 sys::swapByteOrder(C.cmdsize); 1318 sys::swapByteOrder(C.cksum); 1319} 1320 1321// The twolevel_hints_command is obsolete and no longer supported. 1322inline void swapStruct(twolevel_hints_command &C) { 1323 sys::swapByteOrder(C.cmd); 1324 sys::swapByteOrder(C.cmdsize); 1325 sys::swapByteOrder(C.offset); 1326 sys::swapByteOrder(C.nhints); 1327} 1328 1329// The prebound_dylib_command is obsolete and no longer supported. 1330inline void swapStruct(prebound_dylib_command &C) { 1331 sys::swapByteOrder(C.cmd); 1332 sys::swapByteOrder(C.cmdsize); 1333 sys::swapByteOrder(C.name); 1334 sys::swapByteOrder(C.nmodules); 1335 sys::swapByteOrder(C.linked_modules); 1336} 1337 1338// The fvmfile_command is obsolete and no longer supported. 1339inline void swapStruct(fvmfile_command &C) { 1340 sys::swapByteOrder(C.cmd); 1341 sys::swapByteOrder(C.cmdsize); 1342 sys::swapByteOrder(C.name); 1343 sys::swapByteOrder(C.header_addr); 1344} 1345 1346// The symseg_command is obsolete and no longer supported. 1347inline void swapStruct(symseg_command &C) { 1348 sys::swapByteOrder(C.cmd); 1349 sys::swapByteOrder(C.cmdsize); 1350 sys::swapByteOrder(C.offset); 1351 sys::swapByteOrder(C.size); 1352} 1353 1354// The ident_command is obsolete and no longer supported. 1355inline void swapStruct(ident_command &C) { 1356 sys::swapByteOrder(C.cmd); 1357 sys::swapByteOrder(C.cmdsize); 1358} 1359 1360inline void swapStruct(fvmlib &C) { 1361 sys::swapByteOrder(C.name); 1362 sys::swapByteOrder(C.minor_version); 1363 sys::swapByteOrder(C.header_addr); 1364} 1365 1366// The fvmlib_command is obsolete and no longer supported. 1367inline void swapStruct(fvmlib_command &C) { 1368 sys::swapByteOrder(C.cmd); 1369 sys::swapByteOrder(C.cmdsize); 1370 swapStruct(C.fvmlib); 1371} 1372 1373// Get/Set functions from <mach-o/nlist.h> 1374 1375static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) { 1376 return (((n_desc) >> 8u) & 0xffu); 1377} 1378 1379static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) { 1380 n_desc = (((n_desc)&0x00ff) | (((ordinal)&0xff) << 8)); 1381} 1382 1383static inline uint8_t GET_COMM_ALIGN(uint16_t n_desc) { 1384 return (n_desc >> 8u) & 0x0fu; 1385} 1386 1387static inline void SET_COMM_ALIGN(uint16_t &n_desc, uint8_t align) { 1388 n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u)); 1389} 1390 1391// Enums from <mach/machine.h> 1392enum : uint32_t { 1393 // Capability bits used in the definition of cpu_type. 1394 CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits 1395 CPU_ARCH_ABI64 = 0x01000000 // 64 bit ABI 1396}; 1397 1398// Constants for the cputype field. 1399enum CPUType { 1400 CPU_TYPE_ANY = -1, 1401 CPU_TYPE_X86 = 7, 1402 CPU_TYPE_I386 = CPU_TYPE_X86, 1403 CPU_TYPE_X86_64 = CPU_TYPE_X86 | CPU_ARCH_ABI64, 1404 /* CPU_TYPE_MIPS = 8, */ 1405 CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC 1406 CPU_TYPE_ARM = 12, 1407 CPU_TYPE_ARM64 = CPU_TYPE_ARM | CPU_ARCH_ABI64, 1408 CPU_TYPE_SPARC = 14, 1409 CPU_TYPE_POWERPC = 18, 1410 CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64 1411}; 1412 1413enum : uint32_t { 1414 // Capability bits used in the definition of cpusubtype. 1415 CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits 1416 CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries 1417 1418 // Special CPU subtype constants. 1419 CPU_SUBTYPE_MULTIPLE = ~0u 1420}; 1421 1422// Constants for the cpusubtype field. 1423enum CPUSubTypeX86 { 1424 CPU_SUBTYPE_I386_ALL = 3, 1425 CPU_SUBTYPE_386 = 3, 1426 CPU_SUBTYPE_486 = 4, 1427 CPU_SUBTYPE_486SX = 0x84, 1428 CPU_SUBTYPE_586 = 5, 1429 CPU_SUBTYPE_PENT = CPU_SUBTYPE_586, 1430 CPU_SUBTYPE_PENTPRO = 0x16, 1431 CPU_SUBTYPE_PENTII_M3 = 0x36, 1432 CPU_SUBTYPE_PENTII_M5 = 0x56, 1433 CPU_SUBTYPE_CELERON = 0x67, 1434 CPU_SUBTYPE_CELERON_MOBILE = 0x77, 1435 CPU_SUBTYPE_PENTIUM_3 = 0x08, 1436 CPU_SUBTYPE_PENTIUM_3_M = 0x18, 1437 CPU_SUBTYPE_PENTIUM_3_XEON = 0x28, 1438 CPU_SUBTYPE_PENTIUM_M = 0x09, 1439 CPU_SUBTYPE_PENTIUM_4 = 0x0a, 1440 CPU_SUBTYPE_PENTIUM_4_M = 0x1a, 1441 CPU_SUBTYPE_ITANIUM = 0x0b, 1442 CPU_SUBTYPE_ITANIUM_2 = 0x1b, 1443 CPU_SUBTYPE_XEON = 0x0c, 1444 CPU_SUBTYPE_XEON_MP = 0x1c, 1445 1446 CPU_SUBTYPE_X86_ALL = 3, 1447 CPU_SUBTYPE_X86_64_ALL = 3, 1448 CPU_SUBTYPE_X86_ARCH1 = 4, 1449 CPU_SUBTYPE_X86_64_H = 8 1450}; 1451static inline int CPU_SUBTYPE_INTEL(int Family, int Model) { 1452 return Family | (Model << 4); 1453} 1454static inline int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST) { 1455 return ((int)ST) & 0x0f; 1456} 1457static inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) { 1458 return ((int)ST) >> 4; 1459} 1460enum { CPU_SUBTYPE_INTEL_FAMILY_MAX = 15, CPU_SUBTYPE_INTEL_MODEL_ALL = 0 }; 1461 1462enum CPUSubTypeARM { 1463 CPU_SUBTYPE_ARM_ALL = 0, 1464 CPU_SUBTYPE_ARM_V4T = 5, 1465 CPU_SUBTYPE_ARM_V6 = 6, 1466 CPU_SUBTYPE_ARM_V5 = 7, 1467 CPU_SUBTYPE_ARM_V5TEJ = 7, 1468 CPU_SUBTYPE_ARM_XSCALE = 8, 1469 CPU_SUBTYPE_ARM_V7 = 9, 1470 // unused ARM_V7F = 10, 1471 CPU_SUBTYPE_ARM_V7S = 11, 1472 CPU_SUBTYPE_ARM_V7K = 12, 1473 CPU_SUBTYPE_ARM_V6M = 14, 1474 CPU_SUBTYPE_ARM_V7M = 15, 1475 CPU_SUBTYPE_ARM_V7EM = 16 1476}; 1477 1478enum CPUSubTypeARM64 { CPU_SUBTYPE_ARM64_ALL = 0 }; 1479 1480enum CPUSubTypeSPARC { CPU_SUBTYPE_SPARC_ALL = 0 }; 1481 1482enum CPUSubTypePowerPC { 1483 CPU_SUBTYPE_POWERPC_ALL = 0, 1484 CPU_SUBTYPE_POWERPC_601 = 1, 1485 CPU_SUBTYPE_POWERPC_602 = 2, 1486 CPU_SUBTYPE_POWERPC_603 = 3, 1487 CPU_SUBTYPE_POWERPC_603e = 4, 1488 CPU_SUBTYPE_POWERPC_603ev = 5, 1489 CPU_SUBTYPE_POWERPC_604 = 6, 1490 CPU_SUBTYPE_POWERPC_604e = 7, 1491 CPU_SUBTYPE_POWERPC_620 = 8, 1492 CPU_SUBTYPE_POWERPC_750 = 9, 1493 CPU_SUBTYPE_POWERPC_7400 = 10, 1494 CPU_SUBTYPE_POWERPC_7450 = 11, 1495 CPU_SUBTYPE_POWERPC_970 = 100, 1496 1497 CPU_SUBTYPE_MC980000_ALL = CPU_SUBTYPE_POWERPC_ALL, 1498 CPU_SUBTYPE_MC98601 = CPU_SUBTYPE_POWERPC_601 1499}; 1500 1501struct x86_thread_state32_t { 1502 uint32_t eax; 1503 uint32_t ebx; 1504 uint32_t ecx; 1505 uint32_t edx; 1506 uint32_t edi; 1507 uint32_t esi; 1508 uint32_t ebp; 1509 uint32_t esp; 1510 uint32_t ss; 1511 uint32_t eflags; 1512 uint32_t eip; 1513 uint32_t cs; 1514 uint32_t ds; 1515 uint32_t es; 1516 uint32_t fs; 1517 uint32_t gs; 1518}; 1519 1520struct x86_thread_state64_t { 1521 uint64_t rax; 1522 uint64_t rbx; 1523 uint64_t rcx; 1524 uint64_t rdx; 1525 uint64_t rdi; 1526 uint64_t rsi; 1527 uint64_t rbp; 1528 uint64_t rsp; 1529 uint64_t r8; 1530 uint64_t r9; 1531 uint64_t r10; 1532 uint64_t r11; 1533 uint64_t r12; 1534 uint64_t r13; 1535 uint64_t r14; 1536 uint64_t r15; 1537 uint64_t rip; 1538 uint64_t rflags; 1539 uint64_t cs; 1540 uint64_t fs; 1541 uint64_t gs; 1542}; 1543 1544enum x86_fp_control_precis { 1545 x86_FP_PREC_24B = 0, 1546 x86_FP_PREC_53B = 2, 1547 x86_FP_PREC_64B = 3 1548}; 1549 1550enum x86_fp_control_rc { 1551 x86_FP_RND_NEAR = 0, 1552 x86_FP_RND_DOWN = 1, 1553 x86_FP_RND_UP = 2, 1554 x86_FP_CHOP = 3 1555}; 1556 1557struct fp_control_t { 1558 unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1, 1559 precis : 1, : 2, pc : 2, rc : 2, : 1, : 3; 1560}; 1561 1562struct fp_status_t { 1563 unsigned short invalid : 1, denorm : 1, zdiv : 1, ovrfl : 1, undfl : 1, 1564 precis : 1, stkflt : 1, errsumm : 1, c0 : 1, c1 : 1, c2 : 1, tos : 3, 1565 c3 : 1, busy : 1; 1566}; 1567 1568struct mmst_reg_t { 1569 char mmst_reg[10]; 1570 char mmst_rsrv[6]; 1571}; 1572 1573struct xmm_reg_t { 1574 char xmm_reg[16]; 1575}; 1576 1577struct x86_float_state64_t { 1578 int32_t fpu_reserved[2]; 1579 fp_control_t fpu_fcw; 1580 fp_status_t fpu_fsw; 1581 uint8_t fpu_ftw; 1582 uint8_t fpu_rsrv1; 1583 uint16_t fpu_fop; 1584 uint32_t fpu_ip; 1585 uint16_t fpu_cs; 1586 uint16_t fpu_rsrv2; 1587 uint32_t fpu_dp; 1588 uint16_t fpu_ds; 1589 uint16_t fpu_rsrv3; 1590 uint32_t fpu_mxcsr; 1591 uint32_t fpu_mxcsrmask; 1592 mmst_reg_t fpu_stmm0; 1593 mmst_reg_t fpu_stmm1; 1594 mmst_reg_t fpu_stmm2; 1595 mmst_reg_t fpu_stmm3; 1596 mmst_reg_t fpu_stmm4; 1597 mmst_reg_t fpu_stmm5; 1598 mmst_reg_t fpu_stmm6; 1599 mmst_reg_t fpu_stmm7; 1600 xmm_reg_t fpu_xmm0; 1601 xmm_reg_t fpu_xmm1; 1602 xmm_reg_t fpu_xmm2; 1603 xmm_reg_t fpu_xmm3; 1604 xmm_reg_t fpu_xmm4; 1605 xmm_reg_t fpu_xmm5; 1606 xmm_reg_t fpu_xmm6; 1607 xmm_reg_t fpu_xmm7; 1608 xmm_reg_t fpu_xmm8; 1609 xmm_reg_t fpu_xmm9; 1610 xmm_reg_t fpu_xmm10; 1611 xmm_reg_t fpu_xmm11; 1612 xmm_reg_t fpu_xmm12; 1613 xmm_reg_t fpu_xmm13; 1614 xmm_reg_t fpu_xmm14; 1615 xmm_reg_t fpu_xmm15; 1616 char fpu_rsrv4[6 * 16]; 1617 uint32_t fpu_reserved1; 1618}; 1619 1620struct x86_exception_state64_t { 1621 uint16_t trapno; 1622 uint16_t cpu; 1623 uint32_t err; 1624 uint64_t faultvaddr; 1625}; 1626 1627inline void swapStruct(x86_thread_state32_t &x) { 1628 sys::swapByteOrder(x.eax); 1629 sys::swapByteOrder(x.ebx); 1630 sys::swapByteOrder(x.ecx); 1631 sys::swapByteOrder(x.edx); 1632 sys::swapByteOrder(x.edi); 1633 sys::swapByteOrder(x.esi); 1634 sys::swapByteOrder(x.ebp); 1635 sys::swapByteOrder(x.esp); 1636 sys::swapByteOrder(x.ss); 1637 sys::swapByteOrder(x.eflags); 1638 sys::swapByteOrder(x.eip); 1639 sys::swapByteOrder(x.cs); 1640 sys::swapByteOrder(x.ds); 1641 sys::swapByteOrder(x.es); 1642 sys::swapByteOrder(x.fs); 1643 sys::swapByteOrder(x.gs); 1644} 1645 1646inline void swapStruct(x86_thread_state64_t &x) { 1647 sys::swapByteOrder(x.rax); 1648 sys::swapByteOrder(x.rbx); 1649 sys::swapByteOrder(x.rcx); 1650 sys::swapByteOrder(x.rdx); 1651 sys::swapByteOrder(x.rdi); 1652 sys::swapByteOrder(x.rsi); 1653 sys::swapByteOrder(x.rbp); 1654 sys::swapByteOrder(x.rsp); 1655 sys::swapByteOrder(x.r8); 1656 sys::swapByteOrder(x.r9); 1657 sys::swapByteOrder(x.r10); 1658 sys::swapByteOrder(x.r11); 1659 sys::swapByteOrder(x.r12); 1660 sys::swapByteOrder(x.r13); 1661 sys::swapByteOrder(x.r14); 1662 sys::swapByteOrder(x.r15); 1663 sys::swapByteOrder(x.rip); 1664 sys::swapByteOrder(x.rflags); 1665 sys::swapByteOrder(x.cs); 1666 sys::swapByteOrder(x.fs); 1667 sys::swapByteOrder(x.gs); 1668} 1669 1670inline void swapStruct(x86_float_state64_t &x) { 1671 sys::swapByteOrder(x.fpu_reserved[0]); 1672 sys::swapByteOrder(x.fpu_reserved[1]); 1673 // TODO swap: fp_control_t fpu_fcw; 1674 // TODO swap: fp_status_t fpu_fsw; 1675 sys::swapByteOrder(x.fpu_fop); 1676 sys::swapByteOrder(x.fpu_ip); 1677 sys::swapByteOrder(x.fpu_cs); 1678 sys::swapByteOrder(x.fpu_rsrv2); 1679 sys::swapByteOrder(x.fpu_dp); 1680 sys::swapByteOrder(x.fpu_ds); 1681 sys::swapByteOrder(x.fpu_rsrv3); 1682 sys::swapByteOrder(x.fpu_mxcsr); 1683 sys::swapByteOrder(x.fpu_mxcsrmask); 1684 sys::swapByteOrder(x.fpu_reserved1); 1685} 1686 1687inline void swapStruct(x86_exception_state64_t &x) { 1688 sys::swapByteOrder(x.trapno); 1689 sys::swapByteOrder(x.cpu); 1690 sys::swapByteOrder(x.err); 1691 sys::swapByteOrder(x.faultvaddr); 1692} 1693 1694struct x86_state_hdr_t { 1695 uint32_t flavor; 1696 uint32_t count; 1697}; 1698 1699struct x86_thread_state_t { 1700 x86_state_hdr_t tsh; 1701 union { 1702 x86_thread_state64_t ts64; 1703 x86_thread_state32_t ts32; 1704 } uts; 1705}; 1706 1707struct x86_float_state_t { 1708 x86_state_hdr_t fsh; 1709 union { 1710 x86_float_state64_t fs64; 1711 } ufs; 1712}; 1713 1714struct x86_exception_state_t { 1715 x86_state_hdr_t esh; 1716 union { 1717 x86_exception_state64_t es64; 1718 } ues; 1719}; 1720 1721inline void swapStruct(x86_state_hdr_t &x) { 1722 sys::swapByteOrder(x.flavor); 1723 sys::swapByteOrder(x.count); 1724} 1725 1726enum X86ThreadFlavors { 1727 x86_THREAD_STATE32 = 1, 1728 x86_FLOAT_STATE32 = 2, 1729 x86_EXCEPTION_STATE32 = 3, 1730 x86_THREAD_STATE64 = 4, 1731 x86_FLOAT_STATE64 = 5, 1732 x86_EXCEPTION_STATE64 = 6, 1733 x86_THREAD_STATE = 7, 1734 x86_FLOAT_STATE = 8, 1735 x86_EXCEPTION_STATE = 9, 1736 x86_DEBUG_STATE32 = 10, 1737 x86_DEBUG_STATE64 = 11, 1738 x86_DEBUG_STATE = 12 1739}; 1740 1741inline void swapStruct(x86_thread_state_t &x) { 1742 swapStruct(x.tsh); 1743 if (x.tsh.flavor == x86_THREAD_STATE64) 1744 swapStruct(x.uts.ts64); 1745} 1746 1747inline void swapStruct(x86_float_state_t &x) { 1748 swapStruct(x.fsh); 1749 if (x.fsh.flavor == x86_FLOAT_STATE64) 1750 swapStruct(x.ufs.fs64); 1751} 1752 1753inline void swapStruct(x86_exception_state_t &x) { 1754 swapStruct(x.esh); 1755 if (x.esh.flavor == x86_EXCEPTION_STATE64) 1756 swapStruct(x.ues.es64); 1757} 1758 1759const uint32_t x86_THREAD_STATE32_COUNT = 1760 sizeof(x86_thread_state32_t) / sizeof(uint32_t); 1761 1762const uint32_t x86_THREAD_STATE64_COUNT = 1763 sizeof(x86_thread_state64_t) / sizeof(uint32_t); 1764const uint32_t x86_FLOAT_STATE64_COUNT = 1765 sizeof(x86_float_state64_t) / sizeof(uint32_t); 1766const uint32_t x86_EXCEPTION_STATE64_COUNT = 1767 sizeof(x86_exception_state64_t) / sizeof(uint32_t); 1768 1769const uint32_t x86_THREAD_STATE_COUNT = 1770 sizeof(x86_thread_state_t) / sizeof(uint32_t); 1771const uint32_t x86_FLOAT_STATE_COUNT = 1772 sizeof(x86_float_state_t) / sizeof(uint32_t); 1773const uint32_t x86_EXCEPTION_STATE_COUNT = 1774 sizeof(x86_exception_state_t) / sizeof(uint32_t); 1775 1776struct arm_thread_state32_t { 1777 uint32_t r[13]; 1778 uint32_t sp; 1779 uint32_t lr; 1780 uint32_t pc; 1781 uint32_t cpsr; 1782}; 1783 1784inline void swapStruct(arm_thread_state32_t &x) { 1785 for (int i = 0; i < 13; i++) 1786 sys::swapByteOrder(x.r[i]); 1787 sys::swapByteOrder(x.sp); 1788 sys::swapByteOrder(x.lr); 1789 sys::swapByteOrder(x.pc); 1790 sys::swapByteOrder(x.cpsr); 1791} 1792 1793struct arm_thread_state64_t { 1794 uint64_t x[29]; 1795 uint64_t fp; 1796 uint64_t lr; 1797 uint64_t sp; 1798 uint64_t pc; 1799 uint32_t cpsr; 1800 uint32_t pad; 1801}; 1802 1803inline void swapStruct(arm_thread_state64_t &x) { 1804 for (int i = 0; i < 29; i++) 1805 sys::swapByteOrder(x.x[i]); 1806 sys::swapByteOrder(x.fp); 1807 sys::swapByteOrder(x.lr); 1808 sys::swapByteOrder(x.sp); 1809 sys::swapByteOrder(x.pc); 1810 sys::swapByteOrder(x.cpsr); 1811} 1812 1813struct arm_state_hdr_t { 1814 uint32_t flavor; 1815 uint32_t count; 1816}; 1817 1818struct arm_thread_state_t { 1819 arm_state_hdr_t tsh; 1820 union { 1821 arm_thread_state32_t ts32; 1822 } uts; 1823}; 1824 1825inline void swapStruct(arm_state_hdr_t &x) { 1826 sys::swapByteOrder(x.flavor); 1827 sys::swapByteOrder(x.count); 1828} 1829 1830enum ARMThreadFlavors { 1831 ARM_THREAD_STATE = 1, 1832 ARM_VFP_STATE = 2, 1833 ARM_EXCEPTION_STATE = 3, 1834 ARM_DEBUG_STATE = 4, 1835 ARN_THREAD_STATE_NONE = 5, 1836 ARM_THREAD_STATE64 = 6, 1837 ARM_EXCEPTION_STATE64 = 7 1838}; 1839 1840inline void swapStruct(arm_thread_state_t &x) { 1841 swapStruct(x.tsh); 1842 if (x.tsh.flavor == ARM_THREAD_STATE) 1843 swapStruct(x.uts.ts32); 1844} 1845 1846const uint32_t ARM_THREAD_STATE_COUNT = 1847 sizeof(arm_thread_state32_t) / sizeof(uint32_t); 1848 1849const uint32_t ARM_THREAD_STATE64_COUNT = 1850 sizeof(arm_thread_state64_t) / sizeof(uint32_t); 1851 1852struct ppc_thread_state32_t { 1853 uint32_t srr0; 1854 uint32_t srr1; 1855 uint32_t r0; 1856 uint32_t r1; 1857 uint32_t r2; 1858 uint32_t r3; 1859 uint32_t r4; 1860 uint32_t r5; 1861 uint32_t r6; 1862 uint32_t r7; 1863 uint32_t r8; 1864 uint32_t r9; 1865 uint32_t r10; 1866 uint32_t r11; 1867 uint32_t r12; 1868 uint32_t r13; 1869 uint32_t r14; 1870 uint32_t r15; 1871 uint32_t r16; 1872 uint32_t r17; 1873 uint32_t r18; 1874 uint32_t r19; 1875 uint32_t r20; 1876 uint32_t r21; 1877 uint32_t r22; 1878 uint32_t r23; 1879 uint32_t r24; 1880 uint32_t r25; 1881 uint32_t r26; 1882 uint32_t r27; 1883 uint32_t r28; 1884 uint32_t r29; 1885 uint32_t r30; 1886 uint32_t r31; 1887 uint32_t ct; 1888 uint32_t xer; 1889 uint32_t lr; 1890 uint32_t ctr; 1891 uint32_t mq; 1892 uint32_t vrsave; 1893}; 1894 1895inline void swapStruct(ppc_thread_state32_t &x) { 1896 sys::swapByteOrder(x.srr0); 1897 sys::swapByteOrder(x.srr1); 1898 sys::swapByteOrder(x.r0); 1899 sys::swapByteOrder(x.r1); 1900 sys::swapByteOrder(x.r2); 1901 sys::swapByteOrder(x.r3); 1902 sys::swapByteOrder(x.r4); 1903 sys::swapByteOrder(x.r5); 1904 sys::swapByteOrder(x.r6); 1905 sys::swapByteOrder(x.r7); 1906 sys::swapByteOrder(x.r8); 1907 sys::swapByteOrder(x.r9); 1908 sys::swapByteOrder(x.r10); 1909 sys::swapByteOrder(x.r11); 1910 sys::swapByteOrder(x.r12); 1911 sys::swapByteOrder(x.r13); 1912 sys::swapByteOrder(x.r14); 1913 sys::swapByteOrder(x.r15); 1914 sys::swapByteOrder(x.r16); 1915 sys::swapByteOrder(x.r17); 1916 sys::swapByteOrder(x.r18); 1917 sys::swapByteOrder(x.r19); 1918 sys::swapByteOrder(x.r20); 1919 sys::swapByteOrder(x.r21); 1920 sys::swapByteOrder(x.r22); 1921 sys::swapByteOrder(x.r23); 1922 sys::swapByteOrder(x.r24); 1923 sys::swapByteOrder(x.r25); 1924 sys::swapByteOrder(x.r26); 1925 sys::swapByteOrder(x.r27); 1926 sys::swapByteOrder(x.r28); 1927 sys::swapByteOrder(x.r29); 1928 sys::swapByteOrder(x.r30); 1929 sys::swapByteOrder(x.r31); 1930 sys::swapByteOrder(x.ct); 1931 sys::swapByteOrder(x.xer); 1932 sys::swapByteOrder(x.lr); 1933 sys::swapByteOrder(x.ctr); 1934 sys::swapByteOrder(x.mq); 1935 sys::swapByteOrder(x.vrsave); 1936} 1937 1938struct ppc_state_hdr_t { 1939 uint32_t flavor; 1940 uint32_t count; 1941}; 1942 1943struct ppc_thread_state_t { 1944 ppc_state_hdr_t tsh; 1945 union { 1946 ppc_thread_state32_t ts32; 1947 } uts; 1948}; 1949 1950inline void swapStruct(ppc_state_hdr_t &x) { 1951 sys::swapByteOrder(x.flavor); 1952 sys::swapByteOrder(x.count); 1953} 1954 1955enum PPCThreadFlavors { 1956 PPC_THREAD_STATE = 1, 1957 PPC_FLOAT_STATE = 2, 1958 PPC_EXCEPTION_STATE = 3, 1959 PPC_VECTOR_STATE = 4, 1960 PPC_THREAD_STATE64 = 5, 1961 PPC_EXCEPTION_STATE64 = 6, 1962 PPC_THREAD_STATE_NONE = 7 1963}; 1964 1965inline void swapStruct(ppc_thread_state_t &x) { 1966 swapStruct(x.tsh); 1967 if (x.tsh.flavor == PPC_THREAD_STATE) 1968 swapStruct(x.uts.ts32); 1969} 1970 1971const uint32_t PPC_THREAD_STATE_COUNT = 1972 sizeof(ppc_thread_state32_t) / sizeof(uint32_t); 1973 1974// Define a union of all load command structs 1975#define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data; 1976 1977union macho_load_command { 1978#include "llvm/BinaryFormat/MachO.def" 1979}; 1980 1981} // end namespace MachO 1982} // end namespace llvm 1983 1984#endif 1985