1 //===-- llvm/Support/MachO.h - The MachO file format ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines manifest constants for the MachO object file format.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_MACHO_H
15 #define LLVM_SUPPORT_MACHO_H
17 #include "llvm/Support/Compiler.h"
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/Support/Host.h"
23 // Enums from <mach-o/loader.h>
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
38 // Constants for the "filetype" field in llvm::MachO::mach_header and
39 // llvm::MachO::mach_header_64
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,
78 MH_DEAD_STRIPPABLE_DYLIB = 0x00400000u,
79 MH_HAS_TLV_DESCRIPTORS = 0x00800000u,
80 MH_NO_HEAP_EXECUTION = 0x01000000u,
81 MH_APP_EXTENSION_SAFE = 0x02000000u
85 // Flags for the "cmd" field in llvm::MachO::load_command
86 LC_REQ_DYLD = 0x80000000u
89 #define HANDLE_LOAD_COMMAND(LCName, LCValue, LCStruct) \
92 enum LoadCommandType : uint32_t {
93 #include "llvm/Support/MachO.def"
96 #undef HANDLE_LOAD_COMMAND
99 // Constant bits for the "flags" field in llvm::MachO::segment_command
103 SG_PROTECTED_VERSION_1 = 0x8u,
105 // Constant masks for the "flags" field in llvm::MachO::section and
106 // llvm::MachO::section_64
107 SECTION_TYPE = 0x000000ffu, // SECTION_TYPE
108 SECTION_ATTRIBUTES = 0xffffff00u, // SECTION_ATTRIBUTES
109 SECTION_ATTRIBUTES_USR = 0xff000000u, // SECTION_ATTRIBUTES_USR
110 SECTION_ATTRIBUTES_SYS = 0x00ffff00u // SECTION_ATTRIBUTES_SYS
113 /// These are the section type and attributes fields. A MachO section can
114 /// have only one Type, but can have any of the attributes specified.
115 enum SectionType : uint32_t {
116 // Constant masks for the "flags[7:0]" field in llvm::MachO::section and
117 // llvm::MachO::section_64 (mask "flags" with SECTION_TYPE)
119 /// S_REGULAR - Regular section.
121 /// S_ZEROFILL - Zero fill on demand section.
123 /// S_CSTRING_LITERALS - Section with literal C strings.
124 S_CSTRING_LITERALS = 0x02u,
125 /// S_4BYTE_LITERALS - Section with 4 byte literals.
126 S_4BYTE_LITERALS = 0x03u,
127 /// S_8BYTE_LITERALS - Section with 8 byte literals.
128 S_8BYTE_LITERALS = 0x04u,
129 /// S_LITERAL_POINTERS - Section with pointers to literals.
130 S_LITERAL_POINTERS = 0x05u,
131 /// S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
132 S_NON_LAZY_SYMBOL_POINTERS = 0x06u,
133 /// S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
134 S_LAZY_SYMBOL_POINTERS = 0x07u,
135 /// S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in
136 /// the Reserved2 field.
137 S_SYMBOL_STUBS = 0x08u,
138 /// S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for
140 S_MOD_INIT_FUNC_POINTERS = 0x09u,
141 /// S_MOD_TERM_FUNC_POINTERS - Section with only function pointers for
143 S_MOD_TERM_FUNC_POINTERS = 0x0au,
144 /// S_COALESCED - Section contains symbols that are to be coalesced.
146 /// S_GB_ZEROFILL - Zero fill on demand section (that can be larger than 4
148 S_GB_ZEROFILL = 0x0cu,
149 /// S_INTERPOSING - Section with only pairs of function pointers for
151 S_INTERPOSING = 0x0du,
152 /// S_16BYTE_LITERALS - Section with only 16 byte literals.
153 S_16BYTE_LITERALS = 0x0eu,
154 /// S_DTRACE_DOF - Section contains DTrace Object Format.
155 S_DTRACE_DOF = 0x0fu,
156 /// S_LAZY_DYLIB_SYMBOL_POINTERS - Section with lazy symbol pointers to
157 /// lazy loaded dylibs.
158 S_LAZY_DYLIB_SYMBOL_POINTERS = 0x10u,
159 /// S_THREAD_LOCAL_REGULAR - Thread local data section.
160 S_THREAD_LOCAL_REGULAR = 0x11u,
161 /// S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
162 S_THREAD_LOCAL_ZEROFILL = 0x12u,
163 /// S_THREAD_LOCAL_VARIABLES - Section with thread local variable
165 S_THREAD_LOCAL_VARIABLES = 0x13u,
166 /// S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread
167 /// local structures.
168 S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14u,
169 /// S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local
170 /// variable initialization pointers to functions.
171 S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15u,
173 LAST_KNOWN_SECTION_TYPE = S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
177 // Constant masks for the "flags[31:24]" field in llvm::MachO::section and
178 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_USR)
180 /// S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine
182 S_ATTR_PURE_INSTRUCTIONS = 0x80000000u,
183 /// S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be
184 /// in a ranlib table of contents.
185 S_ATTR_NO_TOC = 0x40000000u,
186 /// S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section
187 /// in files with the MY_DYLDLINK flag.
188 S_ATTR_STRIP_STATIC_SYMS = 0x20000000u,
189 /// S_ATTR_NO_DEAD_STRIP - No dead stripping.
190 S_ATTR_NO_DEAD_STRIP = 0x10000000u,
191 /// S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
192 S_ATTR_LIVE_SUPPORT = 0x08000000u,
193 /// S_ATTR_SELF_MODIFYING_CODE - Used with i386 code stubs written on by
195 S_ATTR_SELF_MODIFYING_CODE = 0x04000000u,
196 /// S_ATTR_DEBUG - A debug section.
197 S_ATTR_DEBUG = 0x02000000u,
199 // Constant masks for the "flags[23:8]" field in llvm::MachO::section and
200 // llvm::MachO::section_64 (mask "flags" with SECTION_ATTRIBUTES_SYS)
202 /// S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.
203 S_ATTR_SOME_INSTRUCTIONS = 0x00000400u,
204 /// S_ATTR_EXT_RELOC - Section has external relocation entries.
205 S_ATTR_EXT_RELOC = 0x00000200u,
206 /// S_ATTR_LOC_RELOC - Section has local relocation entries.
207 S_ATTR_LOC_RELOC = 0x00000100u,
209 // Constant masks for the value of an indirect symbol in an indirect
211 INDIRECT_SYMBOL_LOCAL = 0x80000000u,
212 INDIRECT_SYMBOL_ABS = 0x40000000u
215 enum DataRegionType {
216 // Constants for the "kind" field in a data_in_code_entry structure
218 DICE_KIND_JUMP_TABLE8 = 2u,
219 DICE_KIND_JUMP_TABLE16 = 3u,
220 DICE_KIND_JUMP_TABLE32 = 4u,
221 DICE_KIND_ABS_JUMP_TABLE32 = 5u
225 REBASE_TYPE_POINTER = 1u,
226 REBASE_TYPE_TEXT_ABSOLUTE32 = 2u,
227 REBASE_TYPE_TEXT_PCREL32 = 3u
231 REBASE_OPCODE_MASK = 0xF0u,
232 REBASE_IMMEDIATE_MASK = 0x0Fu
236 REBASE_OPCODE_DONE = 0x00u,
237 REBASE_OPCODE_SET_TYPE_IMM = 0x10u,
238 REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x20u,
239 REBASE_OPCODE_ADD_ADDR_ULEB = 0x30u,
240 REBASE_OPCODE_ADD_ADDR_IMM_SCALED = 0x40u,
241 REBASE_OPCODE_DO_REBASE_IMM_TIMES = 0x50u,
242 REBASE_OPCODE_DO_REBASE_ULEB_TIMES = 0x60u,
243 REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB = 0x70u,
244 REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u
248 BIND_TYPE_POINTER = 1u,
249 BIND_TYPE_TEXT_ABSOLUTE32 = 2u,
250 BIND_TYPE_TEXT_PCREL32 = 3u
253 enum BindSpecialDylib {
254 BIND_SPECIAL_DYLIB_SELF = 0,
255 BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE = -1,
256 BIND_SPECIAL_DYLIB_FLAT_LOOKUP = -2
260 BIND_SYMBOL_FLAGS_WEAK_IMPORT = 0x1u,
261 BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION = 0x8u,
263 BIND_OPCODE_MASK = 0xF0u,
264 BIND_IMMEDIATE_MASK = 0x0Fu
268 BIND_OPCODE_DONE = 0x00u,
269 BIND_OPCODE_SET_DYLIB_ORDINAL_IMM = 0x10u,
270 BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB = 0x20u,
271 BIND_OPCODE_SET_DYLIB_SPECIAL_IMM = 0x30u,
272 BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM = 0x40u,
273 BIND_OPCODE_SET_TYPE_IMM = 0x50u,
274 BIND_OPCODE_SET_ADDEND_SLEB = 0x60u,
275 BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB = 0x70u,
276 BIND_OPCODE_ADD_ADDR_ULEB = 0x80u,
277 BIND_OPCODE_DO_BIND = 0x90u,
278 BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB = 0xA0u,
279 BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED = 0xB0u,
280 BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u
284 EXPORT_SYMBOL_FLAGS_KIND_MASK = 0x03u,
285 EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION = 0x04u,
286 EXPORT_SYMBOL_FLAGS_REEXPORT = 0x08u,
287 EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER = 0x10u
290 enum ExportSymbolKind {
291 EXPORT_SYMBOL_FLAGS_KIND_REGULAR = 0x00u,
292 EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL = 0x01u,
293 EXPORT_SYMBOL_FLAGS_KIND_ABSOLUTE = 0x02u
297 // Constant masks for the "n_type" field in llvm::MachO::nlist and
298 // llvm::MachO::nlist_64
306 // Constants for the "n_type & N_TYPE" llvm::MachO::nlist and
307 // llvm::MachO::nlist_64
315 enum SectionOrdinal {
316 // Constants for the "n_sect" field in llvm::MachO::nlist and
317 // llvm::MachO::nlist_64
323 // Constant masks for the "n_desc" field in llvm::MachO::nlist and
324 // llvm::MachO::nlist_64
325 // The low 3 bits are the for the REFERENCE_TYPE.
326 REFERENCE_TYPE = 0x7,
327 REFERENCE_FLAG_UNDEFINED_NON_LAZY = 0,
328 REFERENCE_FLAG_UNDEFINED_LAZY = 1,
329 REFERENCE_FLAG_DEFINED = 2,
330 REFERENCE_FLAG_PRIVATE_DEFINED = 3,
331 REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY = 4,
332 REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY = 5,
333 // Flag bits (some overlap with the library ordinal bits).
334 N_ARM_THUMB_DEF = 0x0008u,
335 REFERENCED_DYNAMICALLY = 0x0010u,
336 N_NO_DEAD_STRIP = 0x0020u,
337 N_WEAK_REF = 0x0040u,
338 N_WEAK_DEF = 0x0080u,
339 N_SYMBOL_RESOLVER = 0x0100u,
340 N_ALT_ENTRY = 0x0200u,
341 // For undefined symbols coming from libraries, see GET_LIBRARY_ORDINAL()
342 // as these are in the top 8 bits.
343 SELF_LIBRARY_ORDINAL = 0x0,
344 MAX_LIBRARY_ORDINAL = 0xfd,
345 DYNAMIC_LOOKUP_ORDINAL = 0xfe,
346 EXECUTABLE_ORDINAL = 0xff
350 // Constant values for the "n_type" field in llvm::MachO::nlist and
351 // llvm::MachO::nlist_64 when "(n_type & N_STAB) != 0"
386 // Constant values for the r_symbolnum field in an
387 // llvm::MachO::relocation_info structure when r_extern is 0.
390 // Constant bits for the r_address field in an
391 // llvm::MachO::relocation_info structure.
392 R_SCATTERED = 0x80000000
395 enum RelocationInfoType {
396 // Constant values for the r_type field in an
397 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
399 GENERIC_RELOC_VANILLA = 0,
400 GENERIC_RELOC_PAIR = 1,
401 GENERIC_RELOC_SECTDIFF = 2,
402 GENERIC_RELOC_PB_LA_PTR = 3,
403 GENERIC_RELOC_LOCAL_SECTDIFF = 4,
404 GENERIC_RELOC_TLV = 5,
406 // Constant values for the r_type field in a PowerPC architecture
407 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
409 PPC_RELOC_VANILLA = GENERIC_RELOC_VANILLA,
410 PPC_RELOC_PAIR = GENERIC_RELOC_PAIR,
417 PPC_RELOC_SECTDIFF = 8,
418 PPC_RELOC_PB_LA_PTR = 9,
419 PPC_RELOC_HI16_SECTDIFF = 10,
420 PPC_RELOC_LO16_SECTDIFF = 11,
421 PPC_RELOC_HA16_SECTDIFF = 12,
423 PPC_RELOC_LO14_SECTDIFF = 14,
424 PPC_RELOC_LOCAL_SECTDIFF = 15,
426 // Constant values for the r_type field in an ARM architecture
427 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
429 ARM_RELOC_VANILLA = GENERIC_RELOC_VANILLA,
430 ARM_RELOC_PAIR = GENERIC_RELOC_PAIR,
431 ARM_RELOC_SECTDIFF = GENERIC_RELOC_SECTDIFF,
432 ARM_RELOC_LOCAL_SECTDIFF = 3,
433 ARM_RELOC_PB_LA_PTR = 4,
435 ARM_THUMB_RELOC_BR22 = 6,
436 ARM_THUMB_32BIT_BRANCH = 7, // obsolete
438 ARM_RELOC_HALF_SECTDIFF = 9,
440 // Constant values for the r_type field in an ARM64 architecture
441 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
445 ARM64_RELOC_UNSIGNED = 0,
446 // Must be followed by an ARM64_RELOC_UNSIGNED
447 ARM64_RELOC_SUBTRACTOR = 1,
448 // A B/BL instruction with 26-bit displacement.
449 ARM64_RELOC_BRANCH26 = 2,
450 // PC-rel distance to page of target.
451 ARM64_RELOC_PAGE21 = 3,
452 // Offset within page, scaled by r_length.
453 ARM64_RELOC_PAGEOFF12 = 4,
454 // PC-rel distance to page of GOT slot.
455 ARM64_RELOC_GOT_LOAD_PAGE21 = 5,
456 // Offset within page of GOT slot, scaled by r_length.
457 ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6,
458 // For pointers to GOT slots.
459 ARM64_RELOC_POINTER_TO_GOT = 7,
460 // PC-rel distance to page of TLVP slot.
461 ARM64_RELOC_TLVP_LOAD_PAGE21 = 8,
462 // Offset within page of TLVP slot, scaled by r_length.
463 ARM64_RELOC_TLVP_LOAD_PAGEOFF12 = 9,
464 // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12.
465 ARM64_RELOC_ADDEND = 10,
467 // Constant values for the r_type field in an x86_64 architecture
468 // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info
470 X86_64_RELOC_UNSIGNED = 0,
471 X86_64_RELOC_SIGNED = 1,
472 X86_64_RELOC_BRANCH = 2,
473 X86_64_RELOC_GOT_LOAD = 3,
474 X86_64_RELOC_GOT = 4,
475 X86_64_RELOC_SUBTRACTOR = 5,
476 X86_64_RELOC_SIGNED_1 = 6,
477 X86_64_RELOC_SIGNED_2 = 7,
478 X86_64_RELOC_SIGNED_4 = 8,
482 // Values for segment_command.initprot.
483 // From <mach/vm_prot.h>
487 VM_PROT_EXECUTE = 0x4
490 // Structs from <mach-o/loader.h>
502 struct mach_header_64 {
513 struct load_command {
518 struct segment_command {
532 struct segment_command_64 {
577 uint32_t minor_version;
578 uint32_t header_addr;
581 struct fvmlib_command {
584 struct fvmlib fvmlib;
590 uint32_t current_version;
591 uint32_t compatibility_version;
594 struct dylib_command {
600 struct sub_framework_command {
606 struct sub_client_command {
612 struct sub_umbrella_command {
615 uint32_t sub_umbrella;
618 struct sub_library_command {
621 uint32_t sub_library;
624 struct prebound_dylib_command {
629 uint32_t linked_modules;
632 struct dylinker_command {
638 struct thread_command {
643 struct routines_command {
646 uint32_t init_address;
647 uint32_t init_module;
656 struct routines_command_64 {
659 uint64_t init_address;
660 uint64_t init_module;
669 struct symtab_command {
678 struct dysymtab_command {
691 uint32_t extrefsymoff;
692 uint32_t nextrefsyms;
693 uint32_t indirectsymoff;
694 uint32_t nindirectsyms;
701 struct dylib_table_of_contents {
702 uint32_t symbol_index;
703 uint32_t module_index;
706 struct dylib_module {
707 uint32_t module_name;
716 uint32_t iinit_iterm;
717 uint32_t ninit_nterm;
718 uint32_t objc_module_info_addr;
719 uint32_t objc_module_info_size;
722 struct dylib_module_64 {
723 uint32_t module_name;
732 uint32_t iinit_iterm;
733 uint32_t ninit_nterm;
734 uint32_t objc_module_info_size;
735 uint64_t objc_module_info_addr;
738 struct dylib_reference {
743 struct twolevel_hints_command {
750 struct twolevel_hint {
751 uint32_t isub_image:8,
755 struct prebind_cksum_command {
761 struct uuid_command {
767 struct rpath_command {
773 struct linkedit_data_command {
780 struct data_in_code_entry {
786 struct source_version_command {
792 struct encryption_info_command {
800 struct encryption_info_command_64 {
809 struct version_min_command {
810 uint32_t cmd; // LC_VERSION_MIN_MACOSX or
811 // LC_VERSION_MIN_IPHONEOS
812 uint32_t cmdsize; // sizeof(struct version_min_command)
813 uint32_t version; // X.Y.Z is encoded in nibbles xxxx.yy.zz
814 uint32_t sdk; // X.Y.Z is encoded in nibbles xxxx.yy.zz
817 struct dyld_info_command {
821 uint32_t rebase_size;
824 uint32_t weak_bind_off;
825 uint32_t weak_bind_size;
826 uint32_t lazy_bind_off;
827 uint32_t lazy_bind_size;
829 uint32_t export_size;
832 struct linker_option_command {
838 struct symseg_command {
845 struct ident_command {
850 struct fvmfile_command {
854 uint32_t header_addr;
857 struct tlv_descriptor_32 {
863 struct tlv_descriptor_64 {
869 struct tlv_descriptor {
875 struct entry_point_command {
882 // Structs from <mach-o/fat.h>
905 // Structs from <mach-o/reloc.h>
906 struct relocation_info {
908 uint32_t r_symbolnum:24,
915 struct scattered_relocation_info {
916 #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)
917 uint32_t r_scattered:1,
923 uint32_t r_address:24,
932 // Structs NOT from <mach-o/reloc.h>, but that make LLVM's life easier
933 struct any_relocation_info {
934 uint32_t r_word0, r_word1;
937 // Structs from <mach-o/nlist.h>
961 // Byte order swapping functions for MachO structs
963 inline void swapStruct(fat_header &mh) {
964 sys::swapByteOrder(mh.magic);
965 sys::swapByteOrder(mh.nfat_arch);
968 inline void swapStruct(fat_arch &mh) {
969 sys::swapByteOrder(mh.cputype);
970 sys::swapByteOrder(mh.cpusubtype);
971 sys::swapByteOrder(mh.offset);
972 sys::swapByteOrder(mh.size);
973 sys::swapByteOrder(mh.align);
976 inline void swapStruct(fat_arch_64 &mh) {
977 sys::swapByteOrder(mh.cputype);
978 sys::swapByteOrder(mh.cpusubtype);
979 sys::swapByteOrder(mh.offset);
980 sys::swapByteOrder(mh.size);
981 sys::swapByteOrder(mh.align);
982 sys::swapByteOrder(mh.reserved);
985 inline void swapStruct(mach_header &mh) {
986 sys::swapByteOrder(mh.magic);
987 sys::swapByteOrder(mh.cputype);
988 sys::swapByteOrder(mh.cpusubtype);
989 sys::swapByteOrder(mh.filetype);
990 sys::swapByteOrder(mh.ncmds);
991 sys::swapByteOrder(mh.sizeofcmds);
992 sys::swapByteOrder(mh.flags);
995 inline void swapStruct(mach_header_64 &H) {
996 sys::swapByteOrder(H.magic);
997 sys::swapByteOrder(H.cputype);
998 sys::swapByteOrder(H.cpusubtype);
999 sys::swapByteOrder(H.filetype);
1000 sys::swapByteOrder(H.ncmds);
1001 sys::swapByteOrder(H.sizeofcmds);
1002 sys::swapByteOrder(H.flags);
1003 sys::swapByteOrder(H.reserved);
1006 inline void swapStruct(load_command &lc) {
1007 sys::swapByteOrder(lc.cmd);
1008 sys::swapByteOrder(lc.cmdsize);
1011 inline void swapStruct(symtab_command &lc) {
1012 sys::swapByteOrder(lc.cmd);
1013 sys::swapByteOrder(lc.cmdsize);
1014 sys::swapByteOrder(lc.symoff);
1015 sys::swapByteOrder(lc.nsyms);
1016 sys::swapByteOrder(lc.stroff);
1017 sys::swapByteOrder(lc.strsize);
1020 inline void swapStruct(segment_command_64 &seg) {
1021 sys::swapByteOrder(seg.cmd);
1022 sys::swapByteOrder(seg.cmdsize);
1023 sys::swapByteOrder(seg.vmaddr);
1024 sys::swapByteOrder(seg.vmsize);
1025 sys::swapByteOrder(seg.fileoff);
1026 sys::swapByteOrder(seg.filesize);
1027 sys::swapByteOrder(seg.maxprot);
1028 sys::swapByteOrder(seg.initprot);
1029 sys::swapByteOrder(seg.nsects);
1030 sys::swapByteOrder(seg.flags);
1033 inline void swapStruct(segment_command &seg) {
1034 sys::swapByteOrder(seg.cmd);
1035 sys::swapByteOrder(seg.cmdsize);
1036 sys::swapByteOrder(seg.vmaddr);
1037 sys::swapByteOrder(seg.vmsize);
1038 sys::swapByteOrder(seg.fileoff);
1039 sys::swapByteOrder(seg.filesize);
1040 sys::swapByteOrder(seg.maxprot);
1041 sys::swapByteOrder(seg.initprot);
1042 sys::swapByteOrder(seg.nsects);
1043 sys::swapByteOrder(seg.flags);
1046 inline void swapStruct(section_64 §) {
1047 sys::swapByteOrder(sect.addr);
1048 sys::swapByteOrder(sect.size);
1049 sys::swapByteOrder(sect.offset);
1050 sys::swapByteOrder(sect.align);
1051 sys::swapByteOrder(sect.reloff);
1052 sys::swapByteOrder(sect.nreloc);
1053 sys::swapByteOrder(sect.flags);
1054 sys::swapByteOrder(sect.reserved1);
1055 sys::swapByteOrder(sect.reserved2);
1058 inline void swapStruct(section §) {
1059 sys::swapByteOrder(sect.addr);
1060 sys::swapByteOrder(sect.size);
1061 sys::swapByteOrder(sect.offset);
1062 sys::swapByteOrder(sect.align);
1063 sys::swapByteOrder(sect.reloff);
1064 sys::swapByteOrder(sect.nreloc);
1065 sys::swapByteOrder(sect.flags);
1066 sys::swapByteOrder(sect.reserved1);
1067 sys::swapByteOrder(sect.reserved2);
1070 inline void swapStruct(dyld_info_command &info) {
1071 sys::swapByteOrder(info.cmd);
1072 sys::swapByteOrder(info.cmdsize);
1073 sys::swapByteOrder(info.rebase_off);
1074 sys::swapByteOrder(info.rebase_size);
1075 sys::swapByteOrder(info.bind_off);
1076 sys::swapByteOrder(info.bind_size);
1077 sys::swapByteOrder(info.weak_bind_off);
1078 sys::swapByteOrder(info.weak_bind_size);
1079 sys::swapByteOrder(info.lazy_bind_off);
1080 sys::swapByteOrder(info.lazy_bind_size);
1081 sys::swapByteOrder(info.export_off);
1082 sys::swapByteOrder(info.export_size);
1085 inline void swapStruct(dylib_command &d) {
1086 sys::swapByteOrder(d.cmd);
1087 sys::swapByteOrder(d.cmdsize);
1088 sys::swapByteOrder(d.dylib.name);
1089 sys::swapByteOrder(d.dylib.timestamp);
1090 sys::swapByteOrder(d.dylib.current_version);
1091 sys::swapByteOrder(d.dylib.compatibility_version);
1094 inline void swapStruct(sub_framework_command &s) {
1095 sys::swapByteOrder(s.cmd);
1096 sys::swapByteOrder(s.cmdsize);
1097 sys::swapByteOrder(s.umbrella);
1100 inline void swapStruct(sub_umbrella_command &s) {
1101 sys::swapByteOrder(s.cmd);
1102 sys::swapByteOrder(s.cmdsize);
1103 sys::swapByteOrder(s.sub_umbrella);
1106 inline void swapStruct(sub_library_command &s) {
1107 sys::swapByteOrder(s.cmd);
1108 sys::swapByteOrder(s.cmdsize);
1109 sys::swapByteOrder(s.sub_library);
1112 inline void swapStruct(sub_client_command &s) {
1113 sys::swapByteOrder(s.cmd);
1114 sys::swapByteOrder(s.cmdsize);
1115 sys::swapByteOrder(s.client);
1118 inline void swapStruct(routines_command &r) {
1119 sys::swapByteOrder(r.cmd);
1120 sys::swapByteOrder(r.cmdsize);
1121 sys::swapByteOrder(r.init_address);
1122 sys::swapByteOrder(r.init_module);
1123 sys::swapByteOrder(r.reserved1);
1124 sys::swapByteOrder(r.reserved2);
1125 sys::swapByteOrder(r.reserved3);
1126 sys::swapByteOrder(r.reserved4);
1127 sys::swapByteOrder(r.reserved5);
1128 sys::swapByteOrder(r.reserved6);
1131 inline void swapStruct(routines_command_64 &r) {
1132 sys::swapByteOrder(r.cmd);
1133 sys::swapByteOrder(r.cmdsize);
1134 sys::swapByteOrder(r.init_address);
1135 sys::swapByteOrder(r.init_module);
1136 sys::swapByteOrder(r.reserved1);
1137 sys::swapByteOrder(r.reserved2);
1138 sys::swapByteOrder(r.reserved3);
1139 sys::swapByteOrder(r.reserved4);
1140 sys::swapByteOrder(r.reserved5);
1141 sys::swapByteOrder(r.reserved6);
1144 inline void swapStruct(thread_command &t) {
1145 sys::swapByteOrder(t.cmd);
1146 sys::swapByteOrder(t.cmdsize);
1149 inline void swapStruct(dylinker_command &d) {
1150 sys::swapByteOrder(d.cmd);
1151 sys::swapByteOrder(d.cmdsize);
1152 sys::swapByteOrder(d.name);
1155 inline void swapStruct(uuid_command &u) {
1156 sys::swapByteOrder(u.cmd);
1157 sys::swapByteOrder(u.cmdsize);
1160 inline void swapStruct(rpath_command &r) {
1161 sys::swapByteOrder(r.cmd);
1162 sys::swapByteOrder(r.cmdsize);
1163 sys::swapByteOrder(r.path);
1166 inline void swapStruct(source_version_command &s) {
1167 sys::swapByteOrder(s.cmd);
1168 sys::swapByteOrder(s.cmdsize);
1169 sys::swapByteOrder(s.version);
1172 inline void swapStruct(entry_point_command &e) {
1173 sys::swapByteOrder(e.cmd);
1174 sys::swapByteOrder(e.cmdsize);
1175 sys::swapByteOrder(e.entryoff);
1176 sys::swapByteOrder(e.stacksize);
1179 inline void swapStruct(encryption_info_command &e) {
1180 sys::swapByteOrder(e.cmd);
1181 sys::swapByteOrder(e.cmdsize);
1182 sys::swapByteOrder(e.cryptoff);
1183 sys::swapByteOrder(e.cryptsize);
1184 sys::swapByteOrder(e.cryptid);
1187 inline void swapStruct(encryption_info_command_64 &e) {
1188 sys::swapByteOrder(e.cmd);
1189 sys::swapByteOrder(e.cmdsize);
1190 sys::swapByteOrder(e.cryptoff);
1191 sys::swapByteOrder(e.cryptsize);
1192 sys::swapByteOrder(e.cryptid);
1193 sys::swapByteOrder(e.pad);
1196 inline void swapStruct(dysymtab_command &dst) {
1197 sys::swapByteOrder(dst.cmd);
1198 sys::swapByteOrder(dst.cmdsize);
1199 sys::swapByteOrder(dst.ilocalsym);
1200 sys::swapByteOrder(dst.nlocalsym);
1201 sys::swapByteOrder(dst.iextdefsym);
1202 sys::swapByteOrder(dst.nextdefsym);
1203 sys::swapByteOrder(dst.iundefsym);
1204 sys::swapByteOrder(dst.nundefsym);
1205 sys::swapByteOrder(dst.tocoff);
1206 sys::swapByteOrder(dst.ntoc);
1207 sys::swapByteOrder(dst.modtaboff);
1208 sys::swapByteOrder(dst.nmodtab);
1209 sys::swapByteOrder(dst.extrefsymoff);
1210 sys::swapByteOrder(dst.nextrefsyms);
1211 sys::swapByteOrder(dst.indirectsymoff);
1212 sys::swapByteOrder(dst.nindirectsyms);
1213 sys::swapByteOrder(dst.extreloff);
1214 sys::swapByteOrder(dst.nextrel);
1215 sys::swapByteOrder(dst.locreloff);
1216 sys::swapByteOrder(dst.nlocrel);
1219 inline void swapStruct(any_relocation_info &reloc) {
1220 sys::swapByteOrder(reloc.r_word0);
1221 sys::swapByteOrder(reloc.r_word1);
1224 inline void swapStruct(nlist_base &S) {
1225 sys::swapByteOrder(S.n_strx);
1226 sys::swapByteOrder(S.n_desc);
1229 inline void swapStruct(nlist &sym) {
1230 sys::swapByteOrder(sym.n_strx);
1231 sys::swapByteOrder(sym.n_desc);
1232 sys::swapByteOrder(sym.n_value);
1235 inline void swapStruct(nlist_64 &sym) {
1236 sys::swapByteOrder(sym.n_strx);
1237 sys::swapByteOrder(sym.n_desc);
1238 sys::swapByteOrder(sym.n_value);
1241 inline void swapStruct(linkedit_data_command &C) {
1242 sys::swapByteOrder(C.cmd);
1243 sys::swapByteOrder(C.cmdsize);
1244 sys::swapByteOrder(C.dataoff);
1245 sys::swapByteOrder(C.datasize);
1248 inline void swapStruct(linker_option_command &C) {
1249 sys::swapByteOrder(C.cmd);
1250 sys::swapByteOrder(C.cmdsize);
1251 sys::swapByteOrder(C.count);
1254 inline void swapStruct(version_min_command&C) {
1255 sys::swapByteOrder(C.cmd);
1256 sys::swapByteOrder(C.cmdsize);
1257 sys::swapByteOrder(C.version);
1258 sys::swapByteOrder(C.sdk);
1261 inline void swapStruct(data_in_code_entry &C) {
1262 sys::swapByteOrder(C.offset);
1263 sys::swapByteOrder(C.length);
1264 sys::swapByteOrder(C.kind);
1267 inline void swapStruct(uint32_t &C) {
1268 sys::swapByteOrder(C);
1271 inline void swapStruct(prebind_cksum_command &C) {
1272 sys::swapByteOrder(C.cmd);
1273 sys::swapByteOrder(C.cmdsize);
1274 sys::swapByteOrder(C.cksum);
1277 inline void swapStruct(twolevel_hints_command &C) {
1278 sys::swapByteOrder(C.cmd);
1279 sys::swapByteOrder(C.cmdsize);
1280 sys::swapByteOrder(C.offset);
1281 sys::swapByteOrder(C.nhints);
1284 inline void swapStruct(prebound_dylib_command &C) {
1285 sys::swapByteOrder(C.cmd);
1286 sys::swapByteOrder(C.cmdsize);
1287 sys::swapByteOrder(C.name);
1288 sys::swapByteOrder(C.nmodules);
1289 sys::swapByteOrder(C.linked_modules);
1292 inline void swapStruct(fvmfile_command &C) {
1293 sys::swapByteOrder(C.cmd);
1294 sys::swapByteOrder(C.cmdsize);
1295 sys::swapByteOrder(C.name);
1296 sys::swapByteOrder(C.header_addr);
1299 inline void swapStruct(symseg_command &C) {
1300 sys::swapByteOrder(C.cmd);
1301 sys::swapByteOrder(C.cmdsize);
1302 sys::swapByteOrder(C.offset);
1303 sys::swapByteOrder(C.size);
1306 inline void swapStruct(ident_command &C) {
1307 sys::swapByteOrder(C.cmd);
1308 sys::swapByteOrder(C.cmdsize);
1311 inline void swapStruct(fvmlib &C) {
1312 sys::swapByteOrder(C.name);
1313 sys::swapByteOrder(C.minor_version);
1314 sys::swapByteOrder(C.header_addr);
1317 inline void swapStruct(fvmlib_command &C) {
1318 sys::swapByteOrder(C.cmd);
1319 sys::swapByteOrder(C.cmdsize);
1320 swapStruct(C.fvmlib);
1323 // Get/Set functions from <mach-o/nlist.h>
1325 static inline uint16_t GET_LIBRARY_ORDINAL(uint16_t n_desc) {
1326 return (((n_desc) >> 8u) & 0xffu);
1329 static inline void SET_LIBRARY_ORDINAL(uint16_t &n_desc, uint8_t ordinal) {
1330 n_desc = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8));
1333 static inline uint8_t GET_COMM_ALIGN (uint16_t n_desc) {
1334 return (n_desc >> 8u) & 0x0fu;
1337 static inline void SET_COMM_ALIGN (uint16_t &n_desc, uint8_t align) {
1338 n_desc = ((n_desc & 0xf0ffu) | ((align & 0x0fu) << 8u));
1341 // Enums from <mach/machine.h>
1343 // Capability bits used in the definition of cpu_type.
1344 CPU_ARCH_MASK = 0xff000000, // Mask for architecture bits
1345 CPU_ARCH_ABI64 = 0x01000000 // 64 bit ABI
1348 // Constants for the cputype field.
1352 CPU_TYPE_I386 = CPU_TYPE_X86,
1353 CPU_TYPE_X86_64 = CPU_TYPE_X86 | CPU_ARCH_ABI64,
1354 /* CPU_TYPE_MIPS = 8, */
1355 CPU_TYPE_MC98000 = 10, // Old Motorola PowerPC
1357 CPU_TYPE_ARM64 = CPU_TYPE_ARM | CPU_ARCH_ABI64,
1358 CPU_TYPE_SPARC = 14,
1359 CPU_TYPE_POWERPC = 18,
1360 CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC | CPU_ARCH_ABI64
1364 // Capability bits used in the definition of cpusubtype.
1365 CPU_SUBTYPE_MASK = 0xff000000, // Mask for architecture bits
1366 CPU_SUBTYPE_LIB64 = 0x80000000, // 64 bit libraries
1368 // Special CPU subtype constants.
1369 CPU_SUBTYPE_MULTIPLE = ~0u
1372 // Constants for the cpusubtype field.
1373 enum CPUSubTypeX86 {
1374 CPU_SUBTYPE_I386_ALL = 3,
1375 CPU_SUBTYPE_386 = 3,
1376 CPU_SUBTYPE_486 = 4,
1377 CPU_SUBTYPE_486SX = 0x84,
1378 CPU_SUBTYPE_586 = 5,
1379 CPU_SUBTYPE_PENT = CPU_SUBTYPE_586,
1380 CPU_SUBTYPE_PENTPRO = 0x16,
1381 CPU_SUBTYPE_PENTII_M3 = 0x36,
1382 CPU_SUBTYPE_PENTII_M5 = 0x56,
1383 CPU_SUBTYPE_CELERON = 0x67,
1384 CPU_SUBTYPE_CELERON_MOBILE = 0x77,
1385 CPU_SUBTYPE_PENTIUM_3 = 0x08,
1386 CPU_SUBTYPE_PENTIUM_3_M = 0x18,
1387 CPU_SUBTYPE_PENTIUM_3_XEON = 0x28,
1388 CPU_SUBTYPE_PENTIUM_M = 0x09,
1389 CPU_SUBTYPE_PENTIUM_4 = 0x0a,
1390 CPU_SUBTYPE_PENTIUM_4_M = 0x1a,
1391 CPU_SUBTYPE_ITANIUM = 0x0b,
1392 CPU_SUBTYPE_ITANIUM_2 = 0x1b,
1393 CPU_SUBTYPE_XEON = 0x0c,
1394 CPU_SUBTYPE_XEON_MP = 0x1c,
1396 CPU_SUBTYPE_X86_ALL = 3,
1397 CPU_SUBTYPE_X86_64_ALL = 3,
1398 CPU_SUBTYPE_X86_ARCH1 = 4,
1399 CPU_SUBTYPE_X86_64_H = 8
1401 static inline int CPU_SUBTYPE_INTEL(int Family, int Model) {
1402 return Family | (Model << 4);
1404 static inline int CPU_SUBTYPE_INTEL_FAMILY(CPUSubTypeX86 ST) {
1405 return ((int)ST) & 0x0f;
1407 static inline int CPU_SUBTYPE_INTEL_MODEL(CPUSubTypeX86 ST) {
1408 return ((int)ST) >> 4;
1411 CPU_SUBTYPE_INTEL_FAMILY_MAX = 15,
1412 CPU_SUBTYPE_INTEL_MODEL_ALL = 0
1415 enum CPUSubTypeARM {
1416 CPU_SUBTYPE_ARM_ALL = 0,
1417 CPU_SUBTYPE_ARM_V4T = 5,
1418 CPU_SUBTYPE_ARM_V6 = 6,
1419 CPU_SUBTYPE_ARM_V5 = 7,
1420 CPU_SUBTYPE_ARM_V5TEJ = 7,
1421 CPU_SUBTYPE_ARM_XSCALE = 8,
1422 CPU_SUBTYPE_ARM_V7 = 9,
1423 // unused ARM_V7F = 10,
1424 CPU_SUBTYPE_ARM_V7S = 11,
1425 CPU_SUBTYPE_ARM_V7K = 12,
1426 CPU_SUBTYPE_ARM_V6M = 14,
1427 CPU_SUBTYPE_ARM_V7M = 15,
1428 CPU_SUBTYPE_ARM_V7EM = 16
1431 enum CPUSubTypeARM64 {
1432 CPU_SUBTYPE_ARM64_ALL = 0
1435 enum CPUSubTypeSPARC {
1436 CPU_SUBTYPE_SPARC_ALL = 0
1439 enum CPUSubTypePowerPC {
1440 CPU_SUBTYPE_POWERPC_ALL = 0,
1441 CPU_SUBTYPE_POWERPC_601 = 1,
1442 CPU_SUBTYPE_POWERPC_602 = 2,
1443 CPU_SUBTYPE_POWERPC_603 = 3,
1444 CPU_SUBTYPE_POWERPC_603e = 4,
1445 CPU_SUBTYPE_POWERPC_603ev = 5,
1446 CPU_SUBTYPE_POWERPC_604 = 6,
1447 CPU_SUBTYPE_POWERPC_604e = 7,
1448 CPU_SUBTYPE_POWERPC_620 = 8,
1449 CPU_SUBTYPE_POWERPC_750 = 9,
1450 CPU_SUBTYPE_POWERPC_7400 = 10,
1451 CPU_SUBTYPE_POWERPC_7450 = 11,
1452 CPU_SUBTYPE_POWERPC_970 = 100,
1454 CPU_SUBTYPE_MC980000_ALL = CPU_SUBTYPE_POWERPC_ALL,
1455 CPU_SUBTYPE_MC98601 = CPU_SUBTYPE_POWERPC_601
1458 struct x86_thread_state64_t {
1482 enum x86_fp_control_precis {
1483 x86_FP_PREC_24B = 0,
1484 x86_FP_PREC_53B = 2,
1488 enum x86_fp_control_rc {
1489 x86_FP_RND_NEAR = 0,
1490 x86_FP_RND_DOWN = 1,
1495 struct fp_control_t {
1510 struct fp_status_t {
1537 struct x86_float_state64_t {
1538 int32_t fpu_reserved[2];
1539 fp_control_t fpu_fcw;
1540 fp_status_t fpu_fsw;
1551 uint32_t fpu_mxcsrmask;
1552 mmst_reg_t fpu_stmm0;
1553 mmst_reg_t fpu_stmm1;
1554 mmst_reg_t fpu_stmm2;
1555 mmst_reg_t fpu_stmm3;
1556 mmst_reg_t fpu_stmm4;
1557 mmst_reg_t fpu_stmm5;
1558 mmst_reg_t fpu_stmm6;
1559 mmst_reg_t fpu_stmm7;
1570 xmm_reg_t fpu_xmm10;
1571 xmm_reg_t fpu_xmm11;
1572 xmm_reg_t fpu_xmm12;
1573 xmm_reg_t fpu_xmm13;
1574 xmm_reg_t fpu_xmm14;
1575 xmm_reg_t fpu_xmm15;
1576 char fpu_rsrv4[6*16];
1577 uint32_t fpu_reserved1;
1580 struct x86_exception_state64_t {
1584 uint64_t faultvaddr;
1587 inline void swapStruct(x86_thread_state64_t &x) {
1588 sys::swapByteOrder(x.rax);
1589 sys::swapByteOrder(x.rbx);
1590 sys::swapByteOrder(x.rcx);
1591 sys::swapByteOrder(x.rdx);
1592 sys::swapByteOrder(x.rdi);
1593 sys::swapByteOrder(x.rsi);
1594 sys::swapByteOrder(x.rbp);
1595 sys::swapByteOrder(x.rsp);
1596 sys::swapByteOrder(x.r8);
1597 sys::swapByteOrder(x.r9);
1598 sys::swapByteOrder(x.r10);
1599 sys::swapByteOrder(x.r11);
1600 sys::swapByteOrder(x.r12);
1601 sys::swapByteOrder(x.r13);
1602 sys::swapByteOrder(x.r14);
1603 sys::swapByteOrder(x.r15);
1604 sys::swapByteOrder(x.rip);
1605 sys::swapByteOrder(x.rflags);
1606 sys::swapByteOrder(x.cs);
1607 sys::swapByteOrder(x.fs);
1608 sys::swapByteOrder(x.gs);
1611 inline void swapStruct(x86_float_state64_t &x) {
1612 sys::swapByteOrder(x.fpu_reserved[0]);
1613 sys::swapByteOrder(x.fpu_reserved[1]);
1614 // TODO swap: fp_control_t fpu_fcw;
1615 // TODO swap: fp_status_t fpu_fsw;
1616 sys::swapByteOrder(x.fpu_fop);
1617 sys::swapByteOrder(x.fpu_ip);
1618 sys::swapByteOrder(x.fpu_cs);
1619 sys::swapByteOrder(x.fpu_rsrv2);
1620 sys::swapByteOrder(x.fpu_dp);
1621 sys::swapByteOrder(x.fpu_ds);
1622 sys::swapByteOrder(x.fpu_rsrv3);
1623 sys::swapByteOrder(x.fpu_mxcsr);
1624 sys::swapByteOrder(x.fpu_mxcsrmask);
1625 sys::swapByteOrder(x.fpu_reserved1);
1628 inline void swapStruct(x86_exception_state64_t &x) {
1629 sys::swapByteOrder(x.trapno);
1630 sys::swapByteOrder(x.cpu);
1631 sys::swapByteOrder(x.err);
1632 sys::swapByteOrder(x.faultvaddr);
1635 struct x86_state_hdr_t {
1640 struct x86_thread_state_t {
1641 x86_state_hdr_t tsh;
1643 x86_thread_state64_t ts64;
1647 struct x86_float_state_t {
1648 x86_state_hdr_t fsh;
1650 x86_float_state64_t fs64;
1654 struct x86_exception_state_t {
1655 x86_state_hdr_t esh;
1657 x86_exception_state64_t es64;
1661 inline void swapStruct(x86_state_hdr_t &x) {
1662 sys::swapByteOrder(x.flavor);
1663 sys::swapByteOrder(x.count);
1666 enum X86ThreadFlavors {
1667 x86_THREAD_STATE32 = 1,
1668 x86_FLOAT_STATE32 = 2,
1669 x86_EXCEPTION_STATE32 = 3,
1670 x86_THREAD_STATE64 = 4,
1671 x86_FLOAT_STATE64 = 5,
1672 x86_EXCEPTION_STATE64 = 6,
1673 x86_THREAD_STATE = 7,
1674 x86_FLOAT_STATE = 8,
1675 x86_EXCEPTION_STATE = 9,
1676 x86_DEBUG_STATE32 = 10,
1677 x86_DEBUG_STATE64 = 11,
1678 x86_DEBUG_STATE = 12
1681 inline void swapStruct(x86_thread_state_t &x) {
1683 if (x.tsh.flavor == x86_THREAD_STATE64)
1684 swapStruct(x.uts.ts64);
1687 inline void swapStruct(x86_float_state_t &x) {
1689 if (x.fsh.flavor == x86_FLOAT_STATE64)
1690 swapStruct(x.ufs.fs64);
1693 inline void swapStruct(x86_exception_state_t &x) {
1695 if (x.esh.flavor == x86_EXCEPTION_STATE64)
1696 swapStruct(x.ues.es64);
1699 const uint32_t x86_THREAD_STATE64_COUNT =
1700 sizeof(x86_thread_state64_t) / sizeof(uint32_t);
1701 const uint32_t x86_FLOAT_STATE64_COUNT =
1702 sizeof(x86_float_state64_t) / sizeof(uint32_t);
1703 const uint32_t x86_EXCEPTION_STATE64_COUNT =
1704 sizeof(x86_exception_state64_t) / sizeof(uint32_t);
1706 const uint32_t x86_THREAD_STATE_COUNT =
1707 sizeof(x86_thread_state_t) / sizeof(uint32_t);
1708 const uint32_t x86_FLOAT_STATE_COUNT =
1709 sizeof(x86_float_state_t) / sizeof(uint32_t);
1710 const uint32_t x86_EXCEPTION_STATE_COUNT =
1711 sizeof(x86_exception_state_t) / sizeof(uint32_t);
1713 // Define a union of all load command structs
1714 #define LOAD_COMMAND_STRUCT(LCStruct) LCStruct LCStruct##_data;
1716 union macho_load_command {
1717 #include "llvm/Support/MachO.def"
1720 } // end namespace MachO
1721 } // end namespace llvm