| [2949] | 1 | /* $Id $ */ | 
|---|
|  | 2 | /** @file | 
|---|
|  | 3 | * Mach-0 structures, types and defines. | 
|---|
|  | 4 | */ | 
|---|
|  | 5 |  | 
|---|
|  | 6 | #ifndef __kLdrModMachO_h__ | 
|---|
|  | 7 | #define __kLdrModMachO_h__ | 
|---|
|  | 8 |  | 
|---|
| [2958] | 9 | /** @defgroup grp_mach_o    The Mach-O Structures, Types, and Defines. | 
|---|
|  | 10 | * @{ | 
|---|
|  | 11 | */ | 
|---|
| [2949] | 12 |  | 
|---|
| [2958] | 13 |  | 
|---|
| [2949] | 14 | #ifndef IMAGE_FAT_SIGNATURE | 
|---|
|  | 15 | /** The FAT signature (universal binaries). */ | 
|---|
|  | 16 | # define IMAGE_FAT_SIGNATURE            UINT32_C(0xcafebabe) | 
|---|
|  | 17 | #endif | 
|---|
|  | 18 | #ifndef IMAGE_FAT_SIGNATURE_OE | 
|---|
|  | 19 | /** The FAT signature (universal binaries), other endian. */ | 
|---|
|  | 20 | # define IMAGE_FAT_SIGNATURE_OE         UINT32_C(0xbebafeca) | 
|---|
|  | 21 | #endif | 
|---|
|  | 22 |  | 
|---|
|  | 23 | /** | 
|---|
|  | 24 | * The fat header found at the start of universal binaries. | 
|---|
|  | 25 | * It is followed by \a nfat_arch numbers of \a fat_arch structures. | 
|---|
|  | 26 | */ | 
|---|
|  | 27 | typedef struct fat_header | 
|---|
|  | 28 | { | 
|---|
|  | 29 | uint32_t        magic; | 
|---|
|  | 30 | uint32_t        nfat_arch; | 
|---|
| [2950] | 31 | } fat_header_t; | 
|---|
| [2949] | 32 |  | 
|---|
|  | 33 | /** | 
|---|
|  | 34 | * Description of fat file item. | 
|---|
|  | 35 | */ | 
|---|
| [2971] | 36 | typedef struct fat_arch | 
|---|
| [2949] | 37 | { | 
|---|
|  | 38 | int32_t         cputype; | 
|---|
|  | 39 | int32_t         cpusubtype; | 
|---|
|  | 40 | uint32_t        offset; | 
|---|
|  | 41 | uint32_t        size; | 
|---|
|  | 42 | uint32_t        align;          /**< Power of 2. */ | 
|---|
| [2950] | 43 | } fat_arch_t; | 
|---|
| [2949] | 44 |  | 
|---|
|  | 45 |  | 
|---|
|  | 46 |  | 
|---|
| [2952] | 47 | #ifndef IMAGE_MACHO32_SIGNATURE | 
|---|
| [2949] | 48 | /** The 32-bit Mach-O signature. */ | 
|---|
|  | 49 | # define IMAGE_MACHO32_SIGNATURE        UINT32_C(0xfeedface) | 
|---|
|  | 50 | #endif | 
|---|
| [2952] | 51 | #ifndef IMAGE_MACHO32_SIGNATURE_OE | 
|---|
| [2949] | 52 | /** The 32-bit Mach-O signature, other endian. */ | 
|---|
|  | 53 | # define IMAGE_MACHO32_SIGNATURE_OE     UINT32_C(0xcefaedfe) | 
|---|
|  | 54 | #endif | 
|---|
|  | 55 | #define MH_MAGIC    IMAGE_MACHO32_SIGNATURE | 
|---|
|  | 56 | #define MH_CIGAM    IMAGE_MACHO32_SIGNATURE_OE | 
|---|
|  | 57 |  | 
|---|
|  | 58 | /** | 
|---|
|  | 59 | * 32-bit Mach-O header. | 
|---|
|  | 60 | * This is followed by \a ncmds number of load commands. | 
|---|
|  | 61 | * @see mach_header_64 | 
|---|
|  | 62 | */ | 
|---|
|  | 63 | typedef struct mach_header_32 | 
|---|
|  | 64 | { | 
|---|
|  | 65 | uint32_t        magic; | 
|---|
|  | 66 | int32_t         cputype; | 
|---|
|  | 67 | int32_t         cpusubtype; | 
|---|
|  | 68 | uint32_t        filetype; | 
|---|
|  | 69 | uint32_t        ncmds; | 
|---|
|  | 70 | uint32_t        sizeofcmds; | 
|---|
|  | 71 | uint32_t        flags; | 
|---|
| [2950] | 72 | } mach_header_32_t; | 
|---|
| [2949] | 73 |  | 
|---|
|  | 74 |  | 
|---|
|  | 75 |  | 
|---|
| [2952] | 76 | #ifndef IMAGE_MACHO64_SIGNATURE | 
|---|
| [2949] | 77 | /** The 64-bit Mach-O signature. */ | 
|---|
|  | 78 | # define IMAGE_MACHO64_SIGNATURE        UINT32_C(0xfeedfacf) | 
|---|
|  | 79 | #endif | 
|---|
| [2952] | 80 | #ifndef IMAGE_MACHO64_SIGNATURE_OE | 
|---|
| [2949] | 81 | /** The 64-bit Mach-O signature, other endian. */ | 
|---|
|  | 82 | # define IMAGE_MACHO64_SIGNATURE_OE     UINT32_C(0xfefaedfe) | 
|---|
|  | 83 | #endif | 
|---|
|  | 84 | #define MH_MAGIC_64 IMAGE_MACHO64_SIGNATURE | 
|---|
|  | 85 | #define MH_CIGAM_64 IMAGE_MACHO64_SIGNATURE_OE | 
|---|
|  | 86 |  | 
|---|
|  | 87 | /** | 
|---|
|  | 88 | * 64-bit Mach-O header. | 
|---|
|  | 89 | * This is followed by \a ncmds number of load commands. | 
|---|
|  | 90 | * @see mach_header | 
|---|
|  | 91 | */ | 
|---|
|  | 92 | typedef struct mach_header_64 | 
|---|
|  | 93 | { | 
|---|
|  | 94 | uint32_t        magic; | 
|---|
|  | 95 | int32_t         cputype; | 
|---|
|  | 96 | int32_t         cpusubtype; | 
|---|
|  | 97 | uint32_t        filetype; | 
|---|
|  | 98 | uint32_t        ncmds; | 
|---|
|  | 99 | uint32_t        sizeofcmds; | 
|---|
|  | 100 | uint32_t        flags; | 
|---|
|  | 101 | uint32_t        reserved;       /**< (for proper struct and command alignment I guess) */ | 
|---|
| [2950] | 102 | } mach_header_64_t; | 
|---|
| [2949] | 103 |  | 
|---|
|  | 104 |  | 
|---|
| [2950] | 105 | /** @name File types (mach_header_64::filetype, mach_header_32::filetype) | 
|---|
|  | 106 | * @{ | 
|---|
|  | 107 | */ | 
|---|
|  | 108 | #define MH_OBJECT           UINT32_C(1) /**< Object (relocatable). */ | 
|---|
|  | 109 | #define MH_EXECUTE          UINT32_C(2) /**< Executable (demand paged). */ | 
|---|
|  | 110 | #define MH_FVMLIB           UINT32_C(3) /**< Fixed VM shared library. */ | 
|---|
|  | 111 | #define MH_CORE             UINT32_C(4) /**< Core file. */ | 
|---|
|  | 112 | #define MH_PRELOAD          UINT32_C(5) /**< Preloaded executable. */ | 
|---|
|  | 113 | #define MH_DYLIB            UINT32_C(6) /**< Dynamically bound shared library. */ | 
|---|
|  | 114 | #define MH_DYLINKER         UINT32_C(7) /**< Dynamic linker. */ | 
|---|
|  | 115 | #define MH_BUNDLE           UINT32_C(8) /**< Dymamically bound bundle. */ | 
|---|
|  | 116 | #define MH_DYLIB_STUB       UINT32_C(9) /**< Shared library stub for static linking. */ | 
|---|
|  | 117 | #define MH_DSYM             UINT32_C(10)/**< Debug symbols. */ | 
|---|
| [2949] | 118 |  | 
|---|
| [2950] | 119 | /** @} */ | 
|---|
|  | 120 |  | 
|---|
|  | 121 |  | 
|---|
|  | 122 | /** @name Mach-O Header flags (mach_header_64::flags, mach_header_32::flags) | 
|---|
| [2949] | 123 | * @{ | 
|---|
|  | 124 | */ | 
|---|
| [2950] | 125 | #define MH_NOUNDEFS                 UINT32_C(0x00000001) /**< No undefined symbols. */ | 
|---|
|  | 126 | #define MH_INCRLINK                 UINT32_C(0x00000002) /**< Partial increment link output. */ | 
|---|
|  | 127 | #define MH_DYLDLINK                 UINT32_C(0x00000004) /**< Food for the dynamic linker, not for ld. */ | 
|---|
|  | 128 | #define MH_BINDATLOAD               UINT32_C(0x00000008) /**< Bind all undefined symbols at load time. */ | 
|---|
|  | 129 | #define MH_PREBOUND                 UINT32_C(0x00000010) /**< Contains prebound undefined symbols. */ | 
|---|
|  | 130 | #define MH_SPLIT_SEGS               UINT32_C(0x00000020) /**< Read-only and read-write segments are split. */ | 
|---|
|  | 131 | #define MH_LAZY_INIT                UINT32_C(0x00000040) /**< Obsolete flag for doing lazy init when data is written. */ | 
|---|
|  | 132 | #define MH_TWOLEVEL                 UINT32_C(0x00000080) /**< Uses two-level name space bindings. */ | 
|---|
|  | 133 | #define MH_FORCE_FLAT               UINT32_C(0x00000100) /**< Task: The executable forces all images to use flat name space bindings. */ | 
|---|
|  | 134 | #define MH_NOMULTIDEFS              UINT32_C(0x00000200) /**< No multiple symbol definitions, safe to use two-level namespace hints. */ | 
|---|
|  | 135 | #define MH_NOFIXPREBINDING          UINT32_C(0x00000400) /**< The dynamic linker should not notify the prebinding agent about this executable. */ | 
|---|
|  | 136 | #define MH_PREBINDABLE              UINT32_C(0x00000800) /**< Not prebound, but it can be. Invalid if MH_PREBOUND is set. */ | 
|---|
|  | 137 | #define MH_ALLMODSBOUND             UINT32_C(0x00001000) /**< Binds to all two-level namespace modules of preqs. Requires MH_PREBINDABLE and MH_TWOLEVEL to be set. */ | 
|---|
|  | 138 | #define MH_SUBSECTIONS_VIA_SYMBOLS  UINT32_C(0x00002000) /**< Safe to divide sections into sub-sections via symbols for dead code stripping. */ | 
|---|
|  | 139 | #define MH_CANONICAL                UINT32_C(0x00004000) /**< Canonicalized via unprebind. */ | 
|---|
|  | 140 | #define MH_WEAK_DEFINES             UINT32_C(0x00008000) /**< The (finally) linked image has weak symbols. */ | 
|---|
|  | 141 | #define MH_BINDS_TO_WEAK            UINT32_C(0x00010000) /**< The (finally) linked image uses weak symbols. */ | 
|---|
|  | 142 | #define MH_ALLOW_STACK_EXECUTION    UINT32_C(0x00020000) /**< Task: allow stack execution. (MH_EXECUTE only) */ | 
|---|
| [2952] | 143 | #define MH_VALID_FLAGS              UINT32_C(0x0003ffff) /**< Mask containing the defined flags. */ | 
|---|
| [2950] | 144 | /** @} */ | 
|---|
|  | 145 |  | 
|---|
|  | 146 |  | 
|---|
|  | 147 | /** @name CPU types / bits (mach_header_64::cputype, mach_header_32::cputype, fat_arch::cputype) | 
|---|
|  | 148 | * @{ | 
|---|
|  | 149 | */ | 
|---|
| [2949] | 150 | #define CPU_ARCH_MASK               INT32_C(0xff000000) | 
|---|
|  | 151 | #define CPU_ARCH_ABI64              INT32_C(0x01000000) | 
|---|
|  | 152 | #define CPU_TYPE_ANY                INT32_C(-1) | 
|---|
|  | 153 | #define CPU_TYPE_VAX                INT32_C(1) | 
|---|
|  | 154 | #define CPU_TYPE_MC680x0            INT32_C(6) | 
|---|
|  | 155 | #define CPU_TYPE_X86                INT32_C(7) | 
|---|
|  | 156 | #define CPU_TYPE_I386               CPU_TYPE_X86 | 
|---|
|  | 157 | #define CPU_TYPE_X86_64             (CPU_TYPE_X86 | CPU_ARCH_ABI64) | 
|---|
|  | 158 | #define CPU_TYPE_MC98000            INT32_C(10) | 
|---|
|  | 159 | #define CPU_TYPE_HPPA               INT32_C(11) | 
|---|
|  | 160 | #define CPU_TYPE_MC88000            INT32_C(13) | 
|---|
|  | 161 | #define CPU_TYPE_SPARC              INT32_C(14) | 
|---|
|  | 162 | #define CPU_TYPE_I860               INT32_C(15) | 
|---|
|  | 163 | #define CPU_TYPE_POWERPC            INT32_C(18) | 
|---|
|  | 164 | #define CPU_TYPE_POWERPC64          (CPU_TYPE_POWERPC | CPU_ARCH_ABI64) | 
|---|
|  | 165 | /** @} */ | 
|---|
|  | 166 |  | 
|---|
| [2950] | 167 |  | 
|---|
|  | 168 | /** @name CPU subtypes (mach_header_64::cpusubtype, mach_header_32::cpusubtype, fat_arch::cpusubtype) | 
|---|
| [2949] | 169 | * @{ */ | 
|---|
|  | 170 | #define CPU_SUBTYPE_MULTIPLE        INT32_C(-1) | 
|---|
|  | 171 | #define CPU_SUBTYPE_LITTLE_ENDIAN   INT32_C(0)  /**< figure this one out. */ | 
|---|
|  | 172 | #define CPU_SUBTYPE_BIG_ENDIAN      INT32_C(1)  /**< ditto */ | 
|---|
|  | 173 |  | 
|---|
|  | 174 | /* VAX */ | 
|---|
|  | 175 | #define CPU_SUBTYPE_VAX_ALL         INT32_C(0) | 
|---|
|  | 176 | #define CPU_SUBTYPE_VAX780          INT32_C(1) | 
|---|
|  | 177 | #define CPU_SUBTYPE_VAX785          INT32_C(2) | 
|---|
|  | 178 | #define CPU_SUBTYPE_VAX750          INT32_C(3) | 
|---|
|  | 179 | #define CPU_SUBTYPE_VAX730          INT32_C(4) | 
|---|
|  | 180 | #define CPU_SUBTYPE_UVAXI           INT32_C(5) | 
|---|
|  | 181 | #define CPU_SUBTYPE_UVAXII          INT32_C(6) | 
|---|
|  | 182 | #define CPU_SUBTYPE_VAX8200         INT32_C(7) | 
|---|
|  | 183 | #define CPU_SUBTYPE_VAX8500         INT32_C(8) | 
|---|
|  | 184 | #define CPU_SUBTYPE_VAX8600         INT32_C(9) | 
|---|
|  | 185 | #define CPU_SUBTYPE_VAX8650         INT32_C(10) | 
|---|
|  | 186 | #define CPU_SUBTYPE_VAX8800         INT32_C(11) | 
|---|
|  | 187 | #define CPU_SUBTYPE_UVAXIII         INT32_C(12) | 
|---|
|  | 188 |  | 
|---|
|  | 189 | /* MC680xx */ | 
|---|
|  | 190 | #define CPU_SUBTYPE_MC680x0_ALL     INT32_C(1) | 
|---|
|  | 191 | #define CPU_SUBTYPE_MC68030         INT32_C(1) | 
|---|
|  | 192 | #define CPU_SUBTYPE_MC68040         INT32_C(2) | 
|---|
|  | 193 | #define CPU_SUBTYPE_MC68030_ONLY    INT32_C(3) | 
|---|
|  | 194 |  | 
|---|
|  | 195 | /* I386 */ | 
|---|
|  | 196 | #define CPU_SUBTYPE_INTEL(fam, model)       ( (int32_t)(((model) << 4) | (fam)) ) | 
|---|
|  | 197 | #define CPU_SUBTYPE_INTEL_FAMILY(subtype)   ( (subtype) & 0xf ) | 
|---|
|  | 198 | #define CPU_SUBTYPE_INTEL_MODEL(subtype)    ( (subtype) >> 4 ) | 
|---|
|  | 199 | #define CPU_SUBTYPE_INTEL_FAMILY_MAX        0xf | 
|---|
|  | 200 | #define CPU_SUBTYPE_INTEL_MODEL_ALL         0 | 
|---|
|  | 201 |  | 
|---|
|  | 202 | #define CPU_SUBTYPE_I386_ALL        CPU_SUBTYPE_INTEL(3, 0) | 
|---|
|  | 203 | #define CPU_SUBTYPE_386             CPU_SUBTYPE_INTEL(3, 0) | 
|---|
|  | 204 | #define CPU_SUBTYPE_486             CPU_SUBTYPE_INTEL(4, 0) | 
|---|
|  | 205 | #define CPU_SUBTYPE_486SX           CPU_SUBTYPE_INTEL(4, 8) | 
|---|
|  | 206 | #define CPU_SUBTYPE_586             CPU_SUBTYPE_INTEL(5, 0) | 
|---|
|  | 207 | #define CPU_SUBTYPE_PENT            CPU_SUBTYPE_INTEL(5, 0) | 
|---|
|  | 208 | #define CPU_SUBTYPE_PENTPRO         CPU_SUBTYPE_INTEL(6, 1) | 
|---|
|  | 209 | #define CPU_SUBTYPE_PENTII_M3       CPU_SUBTYPE_INTEL(6, 3) | 
|---|
|  | 210 | #define CPU_SUBTYPE_PENTII_M5       CPU_SUBTYPE_INTEL(6, 5) | 
|---|
|  | 211 | #define CPU_SUBTYPE_CELERON         CPU_SUBTYPE_INTEL(7, 6) | 
|---|
|  | 212 | #define CPU_SUBTYPE_CELERON_MOBILE  CPU_SUBTYPE_INTEL(7, 7) | 
|---|
|  | 213 | #define CPU_SUBTYPE_PENTIUM_3       CPU_SUBTYPE_INTEL(8, 0) | 
|---|
|  | 214 | #define CPU_SUBTYPE_PENTIUM_3_M     CPU_SUBTYPE_INTEL(8, 1) | 
|---|
|  | 215 | #define CPU_SUBTYPE_PENTIUM_3_XEON  CPU_SUBTYPE_INTEL(8, 2) | 
|---|
|  | 216 | #define CPU_SUBTYPE_PENTIUM_M       CPU_SUBTYPE_INTEL(9, 0) | 
|---|
|  | 217 | #define CPU_SUBTYPE_PENTIUM_4       CPU_SUBTYPE_INTEL(10, 0) | 
|---|
|  | 218 | #define CPU_SUBTYPE_PENTIUM_4_M     CPU_SUBTYPE_INTEL(10, 1) | 
|---|
|  | 219 | #define CPU_SUBTYPE_ITANIUM         CPU_SUBTYPE_INTEL(11, 0) | 
|---|
|  | 220 | #define CPU_SUBTYPE_ITANIUM_2       CPU_SUBTYPE_INTEL(11, 1) | 
|---|
|  | 221 | #define CPU_SUBTYPE_XEON            CPU_SUBTYPE_INTEL(12, 0) | 
|---|
|  | 222 | #define CPU_SUBTYPE_XEON_MP         CPU_SUBTYPE_INTEL(12, 1) | 
|---|
|  | 223 |  | 
|---|
|  | 224 | /* X86 */ | 
|---|
|  | 225 | #define CPU_SUBTYPE_X86_ALL         INT32_C(3) /* CPU_SUBTYPE_I386_ALL */ | 
|---|
|  | 226 | #define CPU_SUBTYPE_X86_64_ALL      INT32_C(3) /* CPU_SUBTYPE_I386_ALL */ | 
|---|
|  | 227 | #define CPU_SUBTYPE_X86_ARCH1       INT32_C(4) /* CPU_SUBTYPE_I486_ALL */ | 
|---|
|  | 228 |  | 
|---|
|  | 229 | /* MIPS */ | 
|---|
|  | 230 | #define CPU_SUBTYPE_MIPS_ALL        INT32_C(0) | 
|---|
|  | 231 | #define CPU_SUBTYPE_MIPS_R2300      INT32_C(1) | 
|---|
|  | 232 | #define CPU_SUBTYPE_MIPS_R2600      INT32_C(2) | 
|---|
|  | 233 | #define CPU_SUBTYPE_MIPS_R2800      INT32_C(3) | 
|---|
|  | 234 | #define CPU_SUBTYPE_MIPS_R2000a     INT32_C(4) | 
|---|
|  | 235 | #define CPU_SUBTYPE_MIPS_R2000      INT32_C(5) | 
|---|
|  | 236 | #define CPU_SUBTYPE_MIPS_R3000a     INT32_C(6) | 
|---|
|  | 237 | #define CPU_SUBTYPE_MIPS_R3000      INT32_C(7) | 
|---|
|  | 238 |  | 
|---|
|  | 239 | /* MC98000 (PowerPC) */ | 
|---|
|  | 240 | #define CPU_SUBTYPE_MC98000_ALL     INT32_C(0) | 
|---|
|  | 241 | #define CPU_SUBTYPE_MC98601         INT32_C(1) | 
|---|
|  | 242 |  | 
|---|
|  | 243 | /* HP-PA */ | 
|---|
|  | 244 | #define CPU_SUBTYPE_HPPA_ALL        INT32_C(0) | 
|---|
|  | 245 | #define CPU_SUBTYPE_HPPA_7100       INT32_C(0) | 
|---|
|  | 246 | #define CPU_SUBTYPE_HPPA_7100LC     INT32_C(1) | 
|---|
|  | 247 |  | 
|---|
|  | 248 | /* MC88000 */ | 
|---|
|  | 249 | #define CPU_SUBTYPE_MC88000_ALL     INT32_C(0) | 
|---|
|  | 250 | #define CPU_SUBTYPE_MC88100         INT32_C(1) | 
|---|
|  | 251 | #define CPU_SUBTYPE_MC88110         INT32_C(2) | 
|---|
|  | 252 |  | 
|---|
|  | 253 | /* SPARC */ | 
|---|
|  | 254 | #define CPU_SUBTYPE_SPARC_ALL       INT32_C(0) | 
|---|
|  | 255 |  | 
|---|
|  | 256 | /* I860 */ | 
|---|
|  | 257 | #define CPU_SUBTYPE_I860_ALL        INT32_C(0) | 
|---|
|  | 258 | #define CPU_SUBTYPE_I860_860        INT32_C(1) | 
|---|
|  | 259 |  | 
|---|
|  | 260 | /* PowerPC */ | 
|---|
|  | 261 | #define CPU_SUBTYPE_POWERPC_ALL     INT32_C(0) | 
|---|
|  | 262 | #define CPU_SUBTYPE_POWERPC_601     INT32_C(1) | 
|---|
|  | 263 | #define CPU_SUBTYPE_POWERPC_602     INT32_C(2) | 
|---|
|  | 264 | #define CPU_SUBTYPE_POWERPC_603     INT32_C(3) | 
|---|
|  | 265 | #define CPU_SUBTYPE_POWERPC_603e    INT32_C(4) | 
|---|
|  | 266 | #define CPU_SUBTYPE_POWERPC_603ev   INT32_C(5) | 
|---|
|  | 267 | #define CPU_SUBTYPE_POWERPC_604     INT32_C(6) | 
|---|
|  | 268 | #define CPU_SUBTYPE_POWERPC_604e    INT32_C(7) | 
|---|
|  | 269 | #define CPU_SUBTYPE_POWERPC_620     INT32_C(8) | 
|---|
|  | 270 | #define CPU_SUBTYPE_POWERPC_750     INT32_C(9) | 
|---|
|  | 271 | #define CPU_SUBTYPE_POWERPC_7400    INT32_C(10) | 
|---|
|  | 272 | #define CPU_SUBTYPE_POWERPC_7450    INT32_C(11) | 
|---|
|  | 273 | #define CPU_SUBTYPE_POWERPC_Max     INT32_C(10) | 
|---|
|  | 274 | #define CPU_SUBTYPE_POWERPC_SCVger  INT32_C(11) | 
|---|
|  | 275 | #define CPU_SUBTYPE_POWERPC_970     INT32_C(100) | 
|---|
|  | 276 |  | 
|---|
|  | 277 | /** @} */ | 
|---|
|  | 278 |  | 
|---|
| [2950] | 279 |  | 
|---|
| [2958] | 280 |  | 
|---|
|  | 281 | /** @defgroup grp_macho_o_lc        Load Commands | 
|---|
|  | 282 | * @{ */ | 
|---|
|  | 283 |  | 
|---|
| [2950] | 284 | /** | 
|---|
|  | 285 | * The load command common core structure. | 
|---|
|  | 286 | * | 
|---|
|  | 287 | * After the Mach-O header follows an array of variable sized | 
|---|
|  | 288 | * load command which all has this header in common. | 
|---|
|  | 289 | */ | 
|---|
|  | 290 | typedef struct load_command | 
|---|
|  | 291 | { | 
|---|
|  | 292 | uint32_t        cmd;            /**< The load command id. */ | 
|---|
| [2954] | 293 | uint32_t        cmdsize;        /**< The size of the command (including this header). */ | 
|---|
| [2950] | 294 | } load_command_t; | 
|---|
|  | 295 |  | 
|---|
|  | 296 | /** @name Load Command IDs (load_command::cmd) | 
|---|
|  | 297 | * @{ | 
|---|
|  | 298 | */ | 
|---|
|  | 299 | /** Flag that when set requires the dynamic linker to fail if it doesn't | 
|---|
|  | 300 | * grok the command. The dynamic linker will otherwise ignore commands it | 
|---|
|  | 301 | * doesn't understand. Introduced with Mac OS X 10.1. */ | 
|---|
|  | 302 | #define LC_REQ_DYLD         UINT32_C(0x80000000) | 
|---|
|  | 303 |  | 
|---|
|  | 304 | #define LC_SEGMENT_32       UINT32_C(0x01)  /**< Segment to be mapped (32-bit). See segment_command_32. */ | 
|---|
|  | 305 | #define LC_SYMTAB           UINT32_C(0x02)  /**< 'stab' symbol table. See symtab_command. */ | 
|---|
|  | 306 | #define LC_SYMSEG           UINT32_C(0x03)  /**< Obsoleted gdb symbol table. */ | 
|---|
|  | 307 | #define LC_THREAD           UINT32_C(0x04)  /**< Thread. See thread_command. */ | 
|---|
|  | 308 | #define LC_UNIXTHREAD       UINT32_C(0x05)  /**< Unix thread (includes stack and stuff). See thread_command. */ | 
|---|
|  | 309 | #define LC_LOADFVMLIB       UINT32_C(0x06)  /**< Load a specified fixed VM shared library  (obsolete?). See fvmlib_command. */ | 
|---|
|  | 310 | #define LC_IDFVMLIB         UINT32_C(0x07)  /**< Fixed VM shared library id (obsolete?). See fvmlib_command. */ | 
|---|
|  | 311 | #define LC_IDENT            UINT32_C(0x08)  /**< Identification info (obsolete). See ident_command. */ | 
|---|
|  | 312 | #define LC_FVMFILE          UINT32_C(0x09)  /**< Fixed VM file inclusion (internal). See fvmfile_command. */ | 
|---|
|  | 313 | #define LC_PREPAGE          UINT32_C(0x0a)  /**< Prepage command (internal). See ?? */ | 
|---|
|  | 314 | #define LC_DYSYMTAB         UINT32_C(0x0b)  /**< Symbol table for dynamic linking. See dysymtab_command. */ | 
|---|
|  | 315 | #define LC_LOAD_DYLIB       UINT32_C(0x0c)  /**< Load a dynamically linked shared library. See dylib_command. */ | 
|---|
|  | 316 | #define LC_ID_DYLIB         UINT32_C(0x0d)  /**< Dynamically linked share library ident. See dylib_command. */ | 
|---|
|  | 317 | #define LC_LOAD_DYLINKER    UINT32_C(0x0e)  /**< Load a dynamical link editor. See dylinker_command. */ | 
|---|
| [2954] | 318 | #define LC_ID_DYLINKER      UINT32_C(0x0f)  /**< Dynamic link editor ident. See dylinker_command. */ | 
|---|
| [2950] | 319 | #define LC_PREBOUND_DYLIB   UINT32_C(0x10)  /**< Prebound modules for dynamically linking of a shared lib. See prebound_dylib_command. */ | 
|---|
|  | 320 | #define LC_ROUTINES         UINT32_C(0x11)  /**< Image routines. See routines_command_32. */ | 
|---|
|  | 321 | #define LC_SUB_FRAMEWORK    UINT32_C(0x12)  /**< Sub framework. See sub_framework_command. */ | 
|---|
|  | 322 | #define LC_SUB_UMBRELLA     UINT32_C(0x13)  /**< Sub umbrella. See sub_umbrella_command. */ | 
|---|
| [2951] | 323 | #define LC_SUB_CLIENT       UINT32_C(0x14)  /**< Sub client. See sub_client_command. */ | 
|---|
| [2950] | 324 | #define LC_SUB_LIBRARY      UINT32_C(0x15)  /**< Sub library. See sub_library_command. */ | 
|---|
|  | 325 | #define LC_TWOLEVEL_HINTS   UINT32_C(0x16)  /**< Two-level namespace lookup hints. See twolevel_hints_command. */ | 
|---|
|  | 326 | #define LC_PREBIND_CKSUM    UINT32_C(0x17)  /**< Prebind checksum. See prebind_cksum_command. */ | 
|---|
|  | 327 | #define LC_LOAD_WEAK_DYLIB (UINT32_C(0x18) | LC_REQ_DYLD) /**< Dylib that can be missing, all symbols weak. See dylib_command. */ | 
|---|
|  | 328 | #define LC_SEGMENT_64       UINT32_C(0x19)  /**< segment to be mapped (64-bit). See segment_command_32. */ | 
|---|
|  | 329 | #define LC_ROUTINES_64      UINT32_C(0x1a)  /**< Image routines (64-bit). See routines_command_32. */ | 
|---|
|  | 330 | #define LC_UUID             UINT32_C(0x1b)  /**< The UUID of the object module. See uuid_command.  */ | 
|---|
|  | 331 | /** @} */ | 
|---|
|  | 332 |  | 
|---|
| [2951] | 333 |  | 
|---|
|  | 334 | /** | 
|---|
|  | 335 | * Load Command String. | 
|---|
|  | 336 | */ | 
|---|
|  | 337 | typedef struct lc_str | 
|---|
|  | 338 | { | 
|---|
|  | 339 | /** Offset of the string relative to the load_command structure. | 
|---|
|  | 340 | * The string is zero-terminated. the size of the load command | 
|---|
|  | 341 | * is zero padded up to a multiple of 4 bytes. */ | 
|---|
|  | 342 | uint32_t        offset; | 
|---|
|  | 343 | } lc_str_t; | 
|---|
|  | 344 |  | 
|---|
|  | 345 |  | 
|---|
|  | 346 | /** | 
|---|
|  | 347 | * Segment load command (32-bit). | 
|---|
|  | 348 | */ | 
|---|
|  | 349 | typedef struct segment_command_32 | 
|---|
|  | 350 | { | 
|---|
|  | 351 | uint32_t        cmd;            /**< LC_SEGMENT */ | 
|---|
|  | 352 | uint32_t        cmdsize;        /**< sizeof(self) + sections. */ | 
|---|
|  | 353 | char            segname[16];    /**< The segment name. */ | 
|---|
|  | 354 | uint32_t        vmaddr;         /**< Memory address of this segment. */ | 
|---|
|  | 355 | uint32_t        vmsize;         /**< Size of this segment. */ | 
|---|
|  | 356 | uint32_t        fileoff;        /**< The file location of the segment. */ | 
|---|
|  | 357 | uint32_t        filesize;       /**< The file size of the segment. */ | 
|---|
|  | 358 | uint32_t        maxprot;        /**< Maximum VM protection. */ | 
|---|
|  | 359 | uint32_t        initprot;       /**< Initial VM protection. */ | 
|---|
|  | 360 | uint32_t        nsects;         /**< Number of section desciptors following this structure. */ | 
|---|
|  | 361 | uint32_t        flags;          /**< Flags (SG_*). */ | 
|---|
|  | 362 | } segment_command_32_t; | 
|---|
|  | 363 |  | 
|---|
|  | 364 |  | 
|---|
|  | 365 | /** | 
|---|
|  | 366 | * Segment load command (64-bit). | 
|---|
|  | 367 | * Same as segment_command_32 except 4 members has been blown up to 64-bit. | 
|---|
|  | 368 | */ | 
|---|
|  | 369 | typedef struct segment_command_64 | 
|---|
|  | 370 | { | 
|---|
|  | 371 | uint32_t        cmd;            /**< LC_SEGMENT */ | 
|---|
|  | 372 | uint32_t        cmdsize;        /**< sizeof(self) + sections. */ | 
|---|
|  | 373 | char            segname[16];    /**< The segment name. */ | 
|---|
|  | 374 | uint64_t        vmaddr;         /**< Memory address of this segment. */ | 
|---|
|  | 375 | uint64_t        vmsize;         /**< Size of this segment. */ | 
|---|
|  | 376 | uint64_t        fileoff;        /**< The file location of the segment. */ | 
|---|
|  | 377 | uint64_t        filesize;       /**< The file size of the segment. */ | 
|---|
|  | 378 | uint32_t        maxprot;        /**< Maximum VM protection. */ | 
|---|
|  | 379 | uint32_t        initprot;       /**< Initial VM protection. */ | 
|---|
|  | 380 | uint32_t        nsects;         /**< Number of section desciptors following this structure. */ | 
|---|
|  | 381 | uint32_t        flags;          /**< Flags (SG_*). */ | 
|---|
|  | 382 | } segment_command_64_t; | 
|---|
|  | 383 |  | 
|---|
|  | 384 | /** @name Segment flags (segment_command_64::flags, segment_command_32::flags) | 
|---|
|  | 385 | * @{ */ | 
|---|
|  | 386 | /** Map the file bits in the top end of the memory area for the segment | 
|---|
|  | 387 | * instead of the low end. Intended for stacks in core dumps. | 
|---|
|  | 388 | * The part of the segment memory not covered by file bits will be zeroed. */ | 
|---|
|  | 389 | #define SG_HIGHVM           UINT32_C(0x00000001) | 
|---|
|  | 390 | /** This segment is the virtual memory allocated by a fixed VM library. | 
|---|
|  | 391 | * (Used for overlap checking in the linker.) */ | 
|---|
|  | 392 | #define SG_FVMLIB           UINT32_C(0x00000002) | 
|---|
|  | 393 | /** No relocations for or symbols that's relocated to in this segment. | 
|---|
|  | 394 | * The segment can therefore safely be replaced. */ | 
|---|
|  | 395 | #define SG_NORELOC          UINT32_C(0x00000004) | 
|---|
|  | 396 | /** The segment is protected. | 
|---|
|  | 397 | * The first page isn't protected if it starts at file offset 0 | 
|---|
|  | 398 | * (so that the mach header and this load command can be easily mapped). */ | 
|---|
|  | 399 | #define SG_PROTECTED_VERSION_1 UINT32_C(0x00000008) | 
|---|
|  | 400 | /** @} */ | 
|---|
|  | 401 |  | 
|---|
|  | 402 |  | 
|---|
|  | 403 | /** | 
|---|
|  | 404 | * 32-bit section (part of a segment load command). | 
|---|
|  | 405 | */ | 
|---|
|  | 406 | typedef struct section_32 | 
|---|
|  | 407 | { | 
|---|
|  | 408 | char            sectname[16];   /**< The section name. */ | 
|---|
|  | 409 | char            segname[16];    /**< The name of the segment this section goes into. */ | 
|---|
|  | 410 | uint32_t        addr;           /**< The memory address of this section. */ | 
|---|
|  | 411 | uint32_t        size;           /**< The size of this section. */ | 
|---|
|  | 412 | uint32_t        offset;         /**< The file offset of this section. */ | 
|---|
|  | 413 | uint32_t        align;          /**< The section alignment (**2). */ | 
|---|
|  | 414 | uint32_t        reloff;         /**< The file offset of the relocations. */ | 
|---|
|  | 415 | uint32_t        nreloc;         /**< The number of relocations. */ | 
|---|
|  | 416 | uint32_t        flags;          /**< The section flags; section type and attribs */ | 
|---|
|  | 417 | uint32_t        reserved1;      /**< Reserved / offset / index. */ | 
|---|
|  | 418 | uint32_t        reserved2;      /**< Reserved / count / sizeof. */ | 
|---|
|  | 419 | } section_32_t; | 
|---|
|  | 420 |  | 
|---|
|  | 421 | /** | 
|---|
|  | 422 | * 64-bit section (part of a segment load command). | 
|---|
|  | 423 | */ | 
|---|
|  | 424 | typedef struct section_64 | 
|---|
|  | 425 | { | 
|---|
|  | 426 | char            sectname[16];   /**< The section name. */ | 
|---|
|  | 427 | char            segname[16];    /**< The name of the segment this section goes into. */ | 
|---|
|  | 428 | uint64_t        addr;           /**< The memory address of this section. */ | 
|---|
|  | 429 | uint64_t        size;           /**< The size of this section. */ | 
|---|
|  | 430 | uint32_t        offset;         /**< The file offset of this section. */ | 
|---|
|  | 431 | uint32_t        align;          /**< The section alignment (**2). */ | 
|---|
|  | 432 | uint32_t        reloff;         /**< The file offset of the relocations. */ | 
|---|
|  | 433 | uint32_t        nreloc;         /**< The number of relocations. */ | 
|---|
|  | 434 | uint32_t        flags;          /**< The section flags; section type and attribs */ | 
|---|
|  | 435 | uint32_t        reserved1;      /**< Reserved / offset / index. */ | 
|---|
|  | 436 | uint32_t        reserved2;      /**< Reserved / count / sizeof. */ | 
|---|
|  | 437 | uint32_t        reserved3;      /**< (Just) Reserved. */ | 
|---|
|  | 438 | } section_64_t; | 
|---|
|  | 439 |  | 
|---|
|  | 440 | /** @name Section flags (section_64::flags, section_32::flags) | 
|---|
|  | 441 | * @{ | 
|---|
|  | 442 | */ | 
|---|
|  | 443 | /** Section type mask. */ | 
|---|
|  | 444 | #define SECTION_TYPE                UINT32_C(0x000000ff) | 
|---|
|  | 445 | /** Regular section. */ | 
|---|
|  | 446 | #define S_REGULAR                   0x0 | 
|---|
|  | 447 | /** Zero filled section. */ | 
|---|
|  | 448 | #define S_ZEROFILL                  0x1 | 
|---|
|  | 449 | /** C literals. */ | 
|---|
|  | 450 | #define S_CSTRING_LITERALS          0x2 | 
|---|
|  | 451 | /** 4 byte literals. */ | 
|---|
|  | 452 | #define S_4BYTE_LITERALS            0x3 | 
|---|
|  | 453 | /** 8 byte literals. */ | 
|---|
|  | 454 | #define S_8BYTE_LITERALS            0x4 | 
|---|
|  | 455 | /** Pointer to literals. */ | 
|---|
|  | 456 | #define S_LITERAL_POINTERS          0x5 | 
|---|
|  | 457 | /** Section containing non-lazy symbol pointers. | 
|---|
|  | 458 | * Reserved1 == start index in the indirect symbol table. */ | 
|---|
|  | 459 | #define S_NON_LAZY_SYMBOL_POINTERS  0x6 | 
|---|
|  | 460 | /** Section containing lazy symbol pointers. | 
|---|
|  | 461 | * Reserved1 == start index in the indirect symbol table. */ | 
|---|
|  | 462 | #define S_LAZY_SYMBOL_POINTERS      0x7 | 
|---|
|  | 463 | /** Section containing symbol stubs. | 
|---|
|  | 464 | * Reserved2 == stub size. */ | 
|---|
|  | 465 | #define S_SYMBOL_STUBS              0x8 | 
|---|
|  | 466 | /** Section containing function pointers for module initialization. . */ | 
|---|
|  | 467 | #define S_MOD_INIT_FUNC_POINTERS    0x9 | 
|---|
|  | 468 | /** Section containing function pointers for module termination. . */ | 
|---|
|  | 469 | #define S_MOD_TERM_FUNC_POINTERS    0xa | 
|---|
|  | 470 | /** Section containing symbols that are to be coalesced. */ | 
|---|
|  | 471 | #define S_COALESCED                 0xb | 
|---|
|  | 472 | /** Zero filled section that be larger than 4GB. */ | 
|---|
|  | 473 | #define S_GB_ZEROFILL               0xc | 
|---|
|  | 474 | /** Section containing pairs of function pointers for interposing. */ | 
|---|
|  | 475 | #define S_INTERPOSING               0xd | 
|---|
|  | 476 | /** 16 byte literals. */ | 
|---|
|  | 477 | #define S_16BYTE_LITERALS           0xe | 
|---|
|  | 478 |  | 
|---|
|  | 479 | /** Section attribute mask. */ | 
|---|
|  | 480 | #define SECTION_ATTRIBUTES          UINT32_C(0xffffff00) | 
|---|
|  | 481 |  | 
|---|
|  | 482 | /** User settable attribute mask. */ | 
|---|
|  | 483 | #define SECTION_ATTRIBUTES_USR      UINT32_C(0xff000000) | 
|---|
|  | 484 | /** Pure instruction (code). */ | 
|---|
|  | 485 | #define S_ATTR_PURE_INSTRUCTIONS    UINT32_C(0x80000000) | 
|---|
|  | 486 | /** ranlib, ignore my symbols... */ | 
|---|
|  | 487 | #define S_ATTR_NO_TOC               UINT32_C(0x40000000) | 
|---|
|  | 488 | /** May strip static symbols when linking int a MH_DYLDLINK file. */ | 
|---|
|  | 489 | #define S_ATTR_STRIP_STATIC_SYMS    UINT32_C(0x20000000) | 
|---|
|  | 490 | /** No dead stripping. */ | 
|---|
|  | 491 | #define S_ATTR_NO_DEAD_STRIP        UINT32_C(0x10000000) | 
|---|
|  | 492 | /** Live support. */ | 
|---|
|  | 493 | #define S_ATTR_LIVE_SUPPORT         UINT32_C(0x08000000) | 
|---|
|  | 494 | /** Contains self modifying code (generally i386 code stub for dyld). */ | 
|---|
|  | 495 | #define S_ATTR_SELF_MODIFYING_CODE  UINT32_C(0x04000000) | 
|---|
|  | 496 | /** Debug info (DWARF usually). */ | 
|---|
|  | 497 | #define S_ATTR_DEBUG                UINT32_C(0x02000000) | 
|---|
|  | 498 |  | 
|---|
|  | 499 | /** System settable attribute mask. */ | 
|---|
|  | 500 | #define SECTION_ATTRIBUTES_SYS      UINT32_C(0x00ffff00) | 
|---|
|  | 501 | /** Contains some instructions (code). */ | 
|---|
|  | 502 | #define S_ATTR_SOME_INSTRUCTIONS    UINT32_C(0x00000400) | 
|---|
|  | 503 | /** Has external relocations. */ | 
|---|
|  | 504 | #define S_ATTR_EXT_RELOC            UINT32_C(0x00000200) | 
|---|
|  | 505 | /** Has internal (local) relocations. */ | 
|---|
|  | 506 | #define S_ATTR_LOC_RELOC            UINT32_C(0x00000100) | 
|---|
|  | 507 | /** @} */ | 
|---|
|  | 508 |  | 
|---|
|  | 509 | /** @name Known Segment and Section Names. | 
|---|
|  | 510 | * Some of these implies special linker behaviour. | 
|---|
|  | 511 | * @{ | 
|---|
|  | 512 | */ | 
|---|
|  | 513 | /** Page zero - not-present page for catching invalid access. (MH_EXECUTE typically) */ | 
|---|
|  | 514 | #define SEG_PAGEZERO        "__PAGEZERO" | 
|---|
|  | 515 | /** Traditional UNIX text segment. | 
|---|
|  | 516 | * Defaults to R-X. */ | 
|---|
|  | 517 | #define SEG_TEXT            "__TEXT" | 
|---|
|  | 518 | /** The text part of SEG_TEXT. */ | 
|---|
|  | 519 | #define SECT_TEXT               "__text" | 
|---|
|  | 520 | /** The fvmlib initialization. */ | 
|---|
|  | 521 | #define SECT_FVMLIB_INIT0       "__fvmlib_init0" | 
|---|
|  | 522 | /** The section following the fvmlib initialization. */ | 
|---|
|  | 523 | #define SECT_FVMLIB_INIT1       "__fvmlib_init1" | 
|---|
|  | 524 | /** The traditional UNIX data segment. (DGROUP to DOS and OS/2 people.) */ | 
|---|
|  | 525 | #define SEG_DATA            "__DATA" | 
|---|
|  | 526 | /** The initialized data section. */ | 
|---|
|  | 527 | #define SECT_DATA               "__data" | 
|---|
|  | 528 | /** The uninitialized data section. */ | 
|---|
|  | 529 | #define SECT_BSS                "__bss" | 
|---|
|  | 530 | /** The common symbol section. */ | 
|---|
|  | 531 | #define SECT_COMMON             "__common" | 
|---|
|  | 532 | /** Objective-C runtime segment. */ | 
|---|
|  | 533 | #define SEG_OBJC            "__OBJC" | 
|---|
|  | 534 | /** Objective-C symbol table section. */ | 
|---|
|  | 535 | #define SECT_OBJC_SYMBOLS       "__symbol_table" | 
|---|
|  | 536 | /** Objective-C module information section. */ | 
|---|
|  | 537 | #define SECT_OBJC_MODULES       "__module_info" | 
|---|
|  | 538 | /** Objective-C string table section. */ | 
|---|
|  | 539 | #define SECT_OBJC_STRINGS       "__selector_strs" | 
|---|
|  | 540 | /** Objective-C string table section. */ | 
|---|
|  | 541 | #define SECT_OBJC_REFS          "__selector_refs" | 
|---|
|  | 542 | /** Icon segment. */ | 
|---|
|  | 543 | #define SEG_ICON            "__ICON" | 
|---|
|  | 544 | /** The icon headers. */ | 
|---|
|  | 545 | #define SECT_ICON_HEADER        "__header" | 
|---|
|  | 546 | /** The icons in the TIFF format. */ | 
|---|
|  | 547 | #define SECT_ICON_TIFF          "__tiff" | 
|---|
|  | 548 | /** ld -seglinkedit segment containing all the structs create and maintained | 
|---|
|  | 549 | * by the linker. MH_EXECUTE and MH_FVMLIB only. */ | 
|---|
|  | 550 | #define SEG_LINKEDIT        "__LINKEDIT" | 
|---|
|  | 551 | /** The unix stack segment. */ | 
|---|
|  | 552 | #define SEG_UNIXSTACK       "__UNIXSTACK" | 
|---|
|  | 553 | /** The segment for the self modifying code for dynamic linking. | 
|---|
|  | 554 | * Implies RWX permissions. */ | 
|---|
|  | 555 | #define SEG_IMPORT          "__IMPORT" | 
|---|
|  | 556 | /** @} */ | 
|---|
|  | 557 |  | 
|---|
|  | 558 |  | 
|---|
|  | 559 | /** @todo fvmlib */ | 
|---|
|  | 560 | /** @todo fvmlib_command (LC_IDFVMLIB or LC_LOADFVMLIB) */ | 
|---|
|  | 561 | /** @todo dylib */ | 
|---|
|  | 562 | /** @todo dylib_command (LC_ID_DYLIB, LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB) */ | 
|---|
|  | 563 | /** @todo sub_framework_command (LC_SUB_FRAMEWORK) */ | 
|---|
|  | 564 | /** @todo sub_client_command (LC_SUB_CLIENT) */ | 
|---|
|  | 565 | /** @todo sub_umbrella_command (LC_SUB_UMBRELLA) */ | 
|---|
|  | 566 | /** @todo sub_library_command (LC_SUB_LIBRARY) */ | 
|---|
|  | 567 | /** @todo prebound_dylib_command (LC_PREBOUND_DYLIB) */ | 
|---|
|  | 568 | /** @todo dylinker_command (LC_ID_DYLINKER or LC_LOAD_DYLINKER) */ | 
|---|
|  | 569 |  | 
|---|
|  | 570 |  | 
|---|
|  | 571 | /** | 
|---|
|  | 572 | * Thread command. | 
|---|
|  | 573 | * | 
|---|
|  | 574 | * State description of a thread that is to be created. The description | 
|---|
|  | 575 | * is made up of a number of state structures preceded by a 32-bit flavor | 
|---|
|  | 576 | * and 32-bit count field stating the kind of stat structure and it's size | 
|---|
|  | 577 | * in uint32_t items respecitvly. | 
|---|
|  | 578 | * | 
|---|
|  | 579 | * LC_UNIXTHREAD differs from LC_THREAD in that it implies stack creation | 
|---|
|  | 580 | * and that it's started with the typical main(int, char **, char **) frame | 
|---|
|  | 581 | * on the stack. | 
|---|
|  | 582 | */ | 
|---|
|  | 583 | typedef struct thread_command | 
|---|
|  | 584 | { | 
|---|
|  | 585 | uint32_t        cmd;        /**< LC_UNIXTHREAD or LC_THREAD. */ | 
|---|
|  | 586 | uint32_t        cmdsize;    /**< The size of the command (including this header). */ | 
|---|
|  | 587 | } thread_command_t; | 
|---|
|  | 588 |  | 
|---|
|  | 589 |  | 
|---|
|  | 590 | /** @todo routines_command (LC_ROUTINES) */ | 
|---|
|  | 591 | /** @todo routines_command_64 (LC_ROUTINES_64) */ | 
|---|
|  | 592 |  | 
|---|
|  | 593 |  | 
|---|
|  | 594 | /** | 
|---|
|  | 595 | * Symbol table command. | 
|---|
|  | 596 | * Contains a.out style symbol table with some tricks. | 
|---|
|  | 597 | */ | 
|---|
|  | 598 | typedef struct symtab_command | 
|---|
|  | 599 | { | 
|---|
|  | 600 | uint32_t        cmd;        /**< LC_SYMTAB */ | 
|---|
|  | 601 | uint32_t        cmdsize;    /** sizeof(symtab_command_t) */ | 
|---|
|  | 602 | uint32_t        symoff;     /** The file offset of the symbol table. */ | 
|---|
|  | 603 | uint32_t        nsyms;      /** The number of symbols in the symbol table. */ | 
|---|
|  | 604 | uint32_t        stroff;     /** The file offset of the string table. */ | 
|---|
|  | 605 | uint32_t        strsize;    /** The size of the string table. */ | 
|---|
|  | 606 | } symtab_command_t; | 
|---|
|  | 607 |  | 
|---|
|  | 608 |  | 
|---|
|  | 609 | /** @todo dysymtab_command (LC_DYSYMTAB)  */ | 
|---|
|  | 610 | /** @todo dylib_table_of_contents */ | 
|---|
|  | 611 | /** @todo dylib_module_32 */ | 
|---|
|  | 612 | /** @todo dylib_module_64 */ | 
|---|
|  | 613 | /** @todo dylib_reference */ | 
|---|
|  | 614 | /** @todo twolevel_hints_command (LC_TWOLEVEL_HINTS) */ | 
|---|
|  | 615 | /** @todo twolevel_hint */ | 
|---|
|  | 616 | /** @todo prebind_cksum_command (LC_PREBIND_CKSUM) */ | 
|---|
|  | 617 |  | 
|---|
|  | 618 |  | 
|---|
|  | 619 | /** | 
|---|
|  | 620 | * UUID generated by ld. | 
|---|
|  | 621 | */ | 
|---|
|  | 622 | typedef struct uuid_command | 
|---|
|  | 623 | { | 
|---|
|  | 624 | uint32_t        cmd;        /**< LC_UUID */ | 
|---|
|  | 625 | uint32_t        cmdsize;    /**< sizeof(uuid_command_t) */ | 
|---|
|  | 626 | uint8_t         uuid[16];   /** The UUID bytes. */ | 
|---|
|  | 627 | } uuid_command_t; | 
|---|
|  | 628 |  | 
|---|
|  | 629 |  | 
|---|
|  | 630 | /** @todo symseg_command (LC_SYMSEG) */ | 
|---|
| [2971] | 631 | /** @todo ident_command (LC_IDENT) */ | 
|---|
| [2951] | 632 | /** @todo fvmfile_command (LC_FVMFILE) */ | 
|---|
| [2957] | 633 |  | 
|---|
| [2958] | 634 | /** @} */ | 
|---|
| [2957] | 635 |  | 
|---|
|  | 636 |  | 
|---|
|  | 637 |  | 
|---|
| [2958] | 638 | /** @defgroup grp_macho_o_syms  Symbol Table | 
|---|
|  | 639 | * @{ */ | 
|---|
| [2957] | 640 |  | 
|---|
|  | 641 | /** | 
|---|
|  | 642 | * The 32-bit Mach-O version of the nlist structure. | 
|---|
| [2963] | 643 | * | 
|---|
|  | 644 | * This differs from the a.out nlist struct in that the unused n_other field | 
|---|
| [2957] | 645 | * was renamed to n_sect and used for keeping the relevant section number. | 
|---|
|  | 646 | * @remark  This structure is not name mach_nlist_32 in the Apple headers, but nlist. | 
|---|
|  | 647 | */ | 
|---|
|  | 648 | typedef struct macho_nlist_32 | 
|---|
|  | 649 | { | 
|---|
| [2963] | 650 | union | 
|---|
| [2957] | 651 | { | 
|---|
|  | 652 | int32_t n_strx;         /**< Offset (index) into the string table. 0 means "". */ | 
|---|
|  | 653 | }           n_un; | 
|---|
|  | 654 | uint8_t     n_type;         /**< Symbol type. */ | 
|---|
|  | 655 | uint8_t     n_sect;         /**< Section number of NO_SECT. */ | 
|---|
|  | 656 | int16_t     n_desc;         /**< Type specific, debug info details mostly.*/ | 
|---|
|  | 657 | uint32_t    n_value;        /**< The symbol value or stab offset. */ | 
|---|
|  | 658 | } macho_nlist_32_t; | 
|---|
|  | 659 |  | 
|---|
|  | 660 |  | 
|---|
|  | 661 | /** | 
|---|
|  | 662 | * The 64-bit Mach-O version of the nlist structure. | 
|---|
|  | 663 | * @see macho_nlist_32 | 
|---|
|  | 664 | */ | 
|---|
|  | 665 | typedef struct macho_nlist_64 | 
|---|
|  | 666 | { | 
|---|
| [2963] | 667 | union | 
|---|
| [2957] | 668 | { | 
|---|
| [2961] | 669 | uint32_t n_strx;        /**< Offset (index) into the string table. 0 means "". */ | 
|---|
| [2957] | 670 | }           n_un; | 
|---|
|  | 671 | uint8_t     n_type;         /**< Symbol type. */ | 
|---|
|  | 672 | uint8_t     n_sect;         /**< Section number of NO_SECT. */ | 
|---|
|  | 673 | int16_t     n_desc;         /**< Type specific, debug info details mostly.*/ | 
|---|
|  | 674 | uint64_t    n_value;        /**< The symbol value or stab offset. */ | 
|---|
|  | 675 | } macho_nlist_64_t; | 
|---|
|  | 676 |  | 
|---|
|  | 677 |  | 
|---|
| [2963] | 678 | /** @name Symbol Type Constants (macho_nlist_32_t::n_type, macho_nlist_64_t::n_type) | 
|---|
|  | 679 | * | 
|---|
| [2957] | 680 | * In the Mach-O world n_type is somewhat similar to a.out, meaning N_EXT, N_UNDF, N_ABS | 
|---|
|  | 681 | * and the debug symbols are essentially the same, but the remaining stuff is different. | 
|---|
| [2963] | 682 | * The main reason for this is that the encoding of section has been moved to n_sect | 
|---|
|  | 683 | * to permit up to 255 sections instead of the fixed 3 a.out sections (not counting | 
|---|
| [2957] | 684 | * the abs symbols and set vectors). | 
|---|
| [2963] | 685 | * | 
|---|
|  | 686 | * To avoid confusion with a.out the Mach-O constants has been fitted with a MACHO_ | 
|---|
| [2957] | 687 | * prefix here. | 
|---|
| [2963] | 688 | * | 
|---|
|  | 689 | * Common symbols (aka communal symbols and comdefs) are represented by | 
|---|
|  | 690 | * n_type = MACHO_N_EXT | MACHO_N_UNDF, n_sect = NO_SECT and n_value giving | 
|---|
| [2957] | 691 | * the size. | 
|---|
| [2963] | 692 | * | 
|---|
|  | 693 | * | 
|---|
| [2957] | 694 | * Symbol table entries can be inserted directly in the assembly code using | 
|---|
|  | 695 | * this notation: | 
|---|
|  | 696 | * @code | 
|---|
|  | 697 | *      .stabs "n_name", n_type, n_sect, n_desc, n_value | 
|---|
|  | 698 | * @endcode | 
|---|
| [2963] | 699 | * | 
|---|
| [2957] | 700 | * (1) The line number is optional, GCC doesn't set it. | 
|---|
|  | 701 | * (2) The type is optional, GCC doesn't set it. | 
|---|
|  | 702 | * (3) The binutil header is "skeptical" about the line. I'm skeptical about the whole thing... :-) | 
|---|
|  | 703 | * (M) Mach-O specific? | 
|---|
|  | 704 | * (S) Sun specific? | 
|---|
|  | 705 | * @{ | 
|---|
|  | 706 | */ | 
|---|
|  | 707 |  | 
|---|
|  | 708 | /* Base masks. */ | 
|---|
|  | 709 | #define MACHO_N_EXT     UINT8_C(0x01)   /**< External symbol (when set) (N_EXT). */ | 
|---|
|  | 710 | #define MACHO_N_TYPE    UINT8_C(0x0e)   /**< Symbol type (N_TYPE without the 8th bit). */ | 
|---|
| [2962] | 711 | #define MACHO_N_PEXT    UINT8_C(0x10)   /**< Private extern symbol (when set). (M) */ | 
|---|
| [2957] | 712 | #define MACHO_N_STAB    UINT8_C(0xe0)   /**< Debug symbol mask (N_STAB). */ | 
|---|
|  | 713 |  | 
|---|
|  | 714 | /* MACHO_N_TYPE values. */ | 
|---|
|  | 715 | #define MACHO_N_UNDF    UINT8_C(0x00)   /**< MACHO_N_TYPE: Undefined symbol (N_UNDF). n_sect = NO_SECT. */ | 
|---|
|  | 716 | #define MACHO_N_ABS     UINT8_C(0x02)   /**< MACHO_N_TYPE: Absolute symbol (N_UNDF). n_sect = NO_SECT. */ | 
|---|
| [2962] | 717 | #define MACHO_N_INDR    UINT8_C(0x0a)   /**< MACHO_N_TYPE: Indirect symbol, n_value is the index of the symbol. (M) */ | 
|---|
|  | 718 | #define MACHO_N_PBUD    UINT8_C(0x0c)   /**< MACHO_N_TYPE: Prebound undefined symbo (defined in a dylib). (M) */ | 
|---|
|  | 719 | #define MACHO_N_SECT    UINT8_C(0x0e)   /**< MACHO_N_TYPE: Defined in the section given by n_sects. (M) */ | 
|---|
| [2957] | 720 |  | 
|---|
|  | 721 | /* Debug symbols. */ | 
|---|
|  | 722 | #define MACHO_N_GSYM    UINT8_C(0x20)   /**< Global variable.       "name",, NO_SECT, type, 0       (2) */ | 
|---|
|  | 723 | #define MACHO_N_FNAME   UINT8_C(0x22)   /**< Function name (F77).   "name",, NO_SECT, 0, 0 */ | 
|---|
|  | 724 | #define MACHO_N_FUN     UINT8_C(0x24)   /**< Function / text var.   "name",, section, line, address (1) */ | 
|---|
|  | 725 | #define MACHO_N_STSYM   UINT8_C(0x26)   /**< Static data symbol.    "name",, section, type, address (2) */ | 
|---|
|  | 726 | #define MACHO_N_LCSYM   UINT8_C(0x28)   /**< static bss symbol.     "name",, section, type, address (2) */ | 
|---|
|  | 727 | /* omits N_MAIN and N_ROSYM. */ | 
|---|
|  | 728 | #define MACHO_N_BNSYM   UINT8_C(0x2e)   /**< Begin nsect symbol.         0,, section, 0, address (M) */ | 
|---|
|  | 729 | #define MACHO_N_PC      UINT8_C(0x30)   /**< Global pascal symbol.  "name",, NO_SECT, subtype?, line (3) */ | 
|---|
|  | 730 | /* omits N_NSYMS, N_NOMAP and N_OBJ. */ | 
|---|
| [2963] | 731 | #define MACHO_N_OPT     UINT8_C(0x3c)   /**< Options for the debugger related to the language of the | 
|---|
| [2957] | 732 | source file.           "options?",,,, */ | 
|---|
|  | 733 | #define MACHO_N_RSYM    UINT8_C(0x40)   /**< Register variable.     "name",, NO_SECT, type, register */ | 
|---|
|  | 734 | /* omits N_M2C */ | 
|---|
|  | 735 | #define MACHO_N_SLINE   UINT8_C(0x44)   /**< Source line.                0,, section, line, address */ | 
|---|
|  | 736 | /* omits N_DSLINE, N_BSLINE / N_BROWS, N_DEFD and N_FLINE. */ | 
|---|
|  | 737 | #define MACHO_N_ENSYM   UINT8_C(0x4e)   /**< End nsect symbol.           0,, section, 0, address (M) */ | 
|---|
|  | 738 | /* omits N_EHDECL / N_MOD2 and N_CATCH. */ | 
|---|
|  | 739 | #define MACHO_N_SSYM    UINT8_C(0x60)   /**< Struct/union element.  "name",, NO_SECT, type, offset */ | 
|---|
|  | 740 | /* omits N_ENDM */ | 
|---|
|  | 741 | #define MACHO_N_SO      UINT8_C(0x64)   /**< Source file name.      "fname",, section, 0, address */ | 
|---|
|  | 742 | #define MACHO_N_OSO     UINT8_C(0x66)   /**< Object file name.      "fname",, 0, 0, st_mtime (M?) */ | 
|---|
|  | 743 | /* omits N_ALIAS */ | 
|---|
|  | 744 | #define MACHO_N_LSYM    UINT8_C(0x80)   /**< Stack variable.        "name",, NO_SECT, type, frame_offset */ | 
|---|
|  | 745 | #define MACHO_N_BINCL   UINT8_C(0x82)   /**< Begin #include.        "fname",, NO_SECT, 0, sum? */ | 
|---|
|  | 746 | #define MACHO_N_SOL     UINT8_C(0x84)   /**< #included file.        "fname",, section, 0, start_address (S) */ | 
|---|
|  | 747 | #define MACHO_N_PARAMS  UINT8_C(0x86)   /**< Compiler params.       "params",, NO_SECT, 0, 0 */ | 
|---|
|  | 748 | #define MACHO_N_VERSION UINT8_C(0x88)   /**< Compiler version.      "version",, NO_SECT, 0, 0 */ | 
|---|
|  | 749 | #define MACHO_N_OLEVEL  UINT8_C(0x8A)   /**< Compiler -O level.     "level",, NO_SECT, 0, 0 */ | 
|---|
|  | 750 | #define MACHO_N_PSYM    UINT8_C(0xa0)   /**< Parameter variable.    "name",, NO_SECT, type, frame_offset */ | 
|---|
|  | 751 | #define MACHO_N_EINCL   UINT8_C(0xa2)   /**< End #include.          "fname",, NO_SECT, 0, 0 (S) */ | 
|---|
|  | 752 | #define MACHO_N_ENTRY   UINT8_C(0xa4)   /**< Alternate entry point. "name",, section, line, address */ | 
|---|
|  | 753 | #define MACHO_N_LBRAC   UINT8_C(0xc0)   /**< Left bracket.               0,, NO_SECT, nesting_level, address */ | 
|---|
|  | 754 | #define MACHO_N_EXCL    UINT8_C(0xc2)   /**< Deleted include file.  "fname",, NO_SECT, 0, sum?  (S) */ | 
|---|
|  | 755 | /* omits N_SCOPE */ | 
|---|
|  | 756 | #define MACHO_N_RBRAC   UINT8_C(0xe0)   /**< Right bracket.              0,, NO_SECT, nesting_level, address */ | 
|---|
|  | 757 | #define MACHO_N_BCOMM   UINT8_C(0xe2)   /**< Begin common.          "name",, NO_SECT?, 0, 0 */ | 
|---|
|  | 758 | #define MACHO_N_ECOMM   UINT8_C(0xe4)   /**< End common.            "name",, section, 0, 0 */ | 
|---|
|  | 759 | #define MACHO_N_ECOML   UINT8_C(0xe8)   /**< End local common.           0,, section, 0, address */ | 
|---|
| [2963] | 760 | #define MACHO_N_LENG    UINT8_C(0xfe)   /**< Length-value of the preceding entry. | 
|---|
| [2957] | 761 | "name",, NO_SECT, 0, length */ | 
|---|
|  | 762 |  | 
|---|
|  | 763 | /** @} */ | 
|---|
|  | 764 |  | 
|---|
| [2963] | 765 | /** @name Symbol Description Bits (macho_nlist_32_t::n_desc, macho_nlist_64_t::n_desc) | 
|---|
|  | 766 | * | 
|---|
|  | 767 | * Mach-O puts the n_desc field to a number of uses, like lazy binding , library | 
|---|
| [2957] | 768 | * ordinal numbers for -twolevel_namespace, stripping and weak symbol handling. | 
|---|
| [2963] | 769 | * | 
|---|
|  | 770 | * @remark The REFERENCE_FLAGS_* are really not flags in the normal sense (bit), | 
|---|
| [2957] | 771 | *         they are more like enum values. | 
|---|
|  | 772 | * @{ | 
|---|
|  | 773 | */ | 
|---|
|  | 774 |  | 
|---|
|  | 775 | #define REFERENCE_TYPE                  UINT16_C(0x000f)    /**< The reference type mask. */ | 
|---|
|  | 776 | #define REFERENCE_FLAG_UNDEFINED_NON_LAZY             0     /**< Normal undefined symbol. */ | 
|---|
|  | 777 | #define REFERENCE_FLAG_UNDEFINED_LAZY                 1     /**< Lazy undefined symbol. */ | 
|---|
|  | 778 | #define REFERENCE_FLAG_DEFINED                        2     /**< Defined symbol (dynamic linking). */ | 
|---|
|  | 779 | #define REFERENCE_FLAG_PRIVATE_DEFINED                3     /**< Defined private symbol (dynamic linking). */ | 
|---|
|  | 780 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY     4     /**< Normal undefined private symbol. */ | 
|---|
|  | 781 | #define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY         5     /**< Lazy undefined private symbol. */ | 
|---|
|  | 782 |  | 
|---|
|  | 783 | #define REFERENCED_DYNAMICALLY          UINT16_C(0x0010)    /**< Don't strip. */ | 
|---|
|  | 784 |  | 
|---|
|  | 785 |  | 
|---|
|  | 786 | /** Get the dynamic library ordinal. */ | 
|---|
|  | 787 | #define GET_LIBRARY_ORDINAL(n_desc)     \ | 
|---|
|  | 788 | (((n_desc) >> 8) & 0xff) | 
|---|
|  | 789 | /** Set the dynamic library ordinal. */ | 
|---|
|  | 790 | #define SET_LIBRARY_ORDINAL(n_desc, ordinal) \ | 
|---|
|  | 791 | (n_desc) = (((n_desc) & 0xff) | (((ordinal) & 0xff) << 8)) | 
|---|
|  | 792 | #define SELF_LIBRARY_ORDINAL            0x00                /**< Special ordinal for refering to onself. */ | 
|---|
|  | 793 | #define MAX_LIBRARY_ORDINAL             0xfd                /**< Maximum ordinal number. */ | 
|---|
|  | 794 | #define DYNAMIC_LOOKUP_ORDINAL          0xfe                /**< Special ordinal number for dynamic lookup. (Mac OS X 10.3 and later) */ | 
|---|
|  | 795 | #define EXECUTABLE_ORDINAL              0xff                /**< Special ordinal number for the executable.  */ | 
|---|
|  | 796 |  | 
|---|
|  | 797 |  | 
|---|
|  | 798 | /** Only MH_OBJECT: Never dead strip me! */ | 
|---|
|  | 799 | #define N_NO_DEAD_STRIP                 UINT16_C(0x0020) | 
|---|
|  | 800 | /** Not MH_OBJECT: Discarded symbol. */ | 
|---|
|  | 801 | #define N_DESC_DISCARDED                UINT16_C(0x0020) | 
|---|
|  | 802 | /** Weak external symbol. Symbol can be missing, in which case it's will have the value 0. */ | 
|---|
|  | 803 | #define N_WEAK_REF                      UINT16_C(0x0040) | 
|---|
| [2963] | 804 | /** Weak symbol definition. The symbol can be overridden by another weak | 
|---|
|  | 805 | * symbol already present or by a non-weak (strong) symbol definition. | 
|---|
|  | 806 | * Currently only supported for coalesed symbols. | 
|---|
| [2957] | 807 | * @remark This bit means something differently for undefined symbols, see N_REF_TO_WEAK. | 
|---|
|  | 808 | */ | 
|---|
|  | 809 | #define N_WEAK_DEF                      UINT16_C(0x0080) | 
|---|
|  | 810 | /** Reference to a weak symbol, resolve using flat namespace searching. | 
|---|
|  | 811 | * @remark This bit means something differently for defined symbols, see N_WEAK_DEF. */ | 
|---|
|  | 812 | #define N_REF_TO_WEAK                   UINT16_C(0x0080) | 
|---|
|  | 813 |  | 
|---|
|  | 814 | /** @} */ | 
|---|
|  | 815 |  | 
|---|
| [2958] | 816 | /** @} */ | 
|---|
|  | 817 |  | 
|---|
|  | 818 |  | 
|---|
|  | 819 | /** @defgroup grp_macho_o_relocs    Relocations | 
|---|
|  | 820 | * @{ */ | 
|---|
|  | 821 |  | 
|---|
|  | 822 | /** | 
|---|
|  | 823 | * Relocation entry. | 
|---|
| [2963] | 824 | * | 
|---|
|  | 825 | * Differs from a.out in the meaning of r_symbolnum when r_extern=0 and | 
|---|
|  | 826 | * that r_pad is made into r_type. | 
|---|
|  | 827 | * | 
|---|
| [2958] | 828 | * @remark  This structure and type has been prefixed with macho_ to avoid | 
|---|
|  | 829 | *          confusion with the original a.out type. | 
|---|
|  | 830 | */ | 
|---|
| [2963] | 831 | typedef struct macho_relocation_info | 
|---|
| [2958] | 832 | { | 
|---|
| [2963] | 833 | int32_t     r_address;          /**< Section relative address of the fixup. | 
|---|
|  | 834 | The top bit (signed) indicates that this is a scattered | 
|---|
| [2958] | 835 | relocation if set, see scattered_relocation_info_t. */ | 
|---|
|  | 836 | uint32_t    r_symbolnum : 24,   /**< r_extern=1: Symbol table index, relocate with the address of this symbol. | 
|---|
|  | 837 | r_extern=0: Section ordinal, relocate with the address of this section. */ | 
|---|
|  | 838 | r_pcrel : 1,        /**< PC (program counter) relative fixup; subtract the fixup address. */ | 
|---|
|  | 839 | r_length : 2,       /**< Fixup length: 0=uint8_t, 1=uint16_t, 2=uint32_t, 3=uint64_t. */ | 
|---|
|  | 840 | r_extern : 1,       /**< External or internal fixup, decides the r_symbolnum interpretation.. */ | 
|---|
|  | 841 | r_type : 4;         /**< Relocation type; 0 is standard, non-zero are machine specific. */ | 
|---|
|  | 842 | } macho_relocation_info_t; | 
|---|
|  | 843 |  | 
|---|
|  | 844 | /** Special section ordinal value for absolute relocations. */ | 
|---|
|  | 845 | #define R_ABS           0 | 
|---|
|  | 846 |  | 
|---|
| [2963] | 847 | /** Flag in r_address indicating that the relocation is of the | 
|---|
| [2958] | 848 | * scattered_relocation_info_t kind and not macho_relocation_info_t. */ | 
|---|
|  | 849 | #define R_SCATTERED     UINT32_C(0x80000000) | 
|---|
|  | 850 |  | 
|---|
|  | 851 | /** | 
|---|
|  | 852 | * Scattered relocation. | 
|---|
| [2963] | 853 | * | 
|---|
|  | 854 | * This is a hack mainly for RISC machines which restricts section size | 
|---|
| [2958] | 855 | * to 16MB among other things. | 
|---|
| [2963] | 856 | * | 
|---|
| [2958] | 857 | * The reason for the big/little endian differences here is of course because | 
|---|
| [2963] | 858 | * of the R_SCATTERED mask and the way bitfields are implemented by the | 
|---|
| [2958] | 859 | * C/C++ compilers. | 
|---|
|  | 860 | */ | 
|---|
|  | 861 | typedef struct scattered_relocation_info | 
|---|
|  | 862 | { | 
|---|
|  | 863 | #ifdef KLDR_LITTLE_ENDIAN | 
|---|
|  | 864 | uint32_t    r_address : 24,     /**< Section relative address of the fixup. (macho_relocation_info_t::r_address) */ | 
|---|
|  | 865 | r_type : 4,         /**< Relocation type; 0 is standard, non-zero are machine specific. (macho_relocation_info_t::r_type) */ | 
|---|
|  | 866 | r_length : 2,       /**< Fixup length: 0=uint8_t, 1=uint16_t, 2=uint32_t, 3=uint64_t. (macho_relocation_info_t::r_length) */ | 
|---|
|  | 867 | r_pcrel : 1,        /**< PC (program counter) relative fixup; subtract the fixup address. (macho_relocation_info_t::r_pcrel) */ | 
|---|
|  | 868 | r_scattered : 1;    /**< Set if scattered relocation, clear if normal relocation. */ | 
|---|
|  | 869 | #elif defined(KLDR_BIG_ENDIAN) | 
|---|
|  | 870 | uint32_t    r_scattered : 1,    /**< Set if scattered relocation, clear if normal relocation. */ | 
|---|
|  | 871 | r_pcrel : 1,        /**< PC (program counter) relative fixup; subtract the fixup address. (macho_relocation_info_t::r_pcrel) */ | 
|---|
|  | 872 | r_length : 2,       /**< Fixup length: 0=uint8_t, 1=uint16_t, 2=uint32_t, 3=uint64_t. (macho_relocation_info_t::r_length) */ | 
|---|
|  | 873 | r_type : 4,         /**< Relocation type; 0 is standard, non-zero are machine specific. (macho_relocation_info_t::r_type) */ | 
|---|
|  | 874 | r_address : 24;     /**< Section relative address of the fixup. (macho_relocation_info_t::r_address) */ | 
|---|
|  | 875 | #else | 
|---|
|  | 876 | # error "Neither KLDR_LITTLE_ENDIAN nor KLDR_BIG_ENDIAN is defined!" | 
|---|
| [2949] | 877 | #endif | 
|---|
| [2963] | 878 | int32_t     r_value;            /**< The value the fixup is refering to (without offset added). */ | 
|---|
| [2958] | 879 | } scattered_relocation_info_t; | 
|---|
| [2949] | 880 |  | 
|---|
| [2958] | 881 | /** | 
|---|
|  | 882 | * Relocation type values for a generic implementation (for r_type). | 
|---|
|  | 883 | */ | 
|---|
|  | 884 | typedef enum reloc_type_generic | 
|---|
|  | 885 | { | 
|---|
| [2963] | 886 | GENERIC_RELOC_VANILLA = 0,      /**< Standard relocation. */ | 
|---|
| [2958] | 887 | GENERIC_RELOC_PAIR,             /**< Follows GENERIC_RELOC_SECTDIFF. */ | 
|---|
|  | 888 | GENERIC_RELOC_SECTDIFF,         /**< ??? */ | 
|---|
|  | 889 | GENERIC_RELOC_PB_LA_PTR,        /**< Prebound lazy pointer whatever that. */ | 
|---|
|  | 890 | GENERIC_RELOC_LOCAL_SECTDIFF    /**< ??? */ | 
|---|
|  | 891 | } reloc_type_generic_t; | 
|---|
|  | 892 |  | 
|---|
|  | 893 | /** @} */ | 
|---|
|  | 894 |  | 
|---|
|  | 895 |  | 
|---|
|  | 896 | /** @} */ | 
|---|
|  | 897 | #endif | 
|---|
|  | 898 |  | 
|---|