github.com/varialus/godfly@v0.0.0-20130904042352-1934f9f095ab/src/libmach/macho.h (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 * Definitions needed for accessing MACH object headers. 7 */ 8 9 typedef struct { 10 uint32 magic; /* mach magic number identifier */ 11 uint32 cputype; /* cpu specifier */ 12 uint32 cpusubtype; /* machine specifier */ 13 uint32 filetype; /* type of file */ 14 uint32 ncmds; /* number of load commands */ 15 uint32 sizeofcmds; /* the size of all the load commands */ 16 uint32 flags; /* flags */ 17 uint32 reserved; /* reserved */ 18 } Machhdr; 19 20 typedef struct { 21 uint32 type; /* type of load command */ 22 uint32 size; /* total size in bytes */ 23 } MachCmd; 24 25 typedef struct { 26 MachCmd cmd; 27 char segname[16]; /* segment name */ 28 uint32 vmaddr; /* memory address of this segment */ 29 uint32 vmsize; /* memory size of this segment */ 30 uint32 fileoff; /* file offset of this segment */ 31 uint32 filesize; /* amount to map from the file */ 32 uint32 maxprot; /* maximum VM protection */ 33 uint32 initprot; /* initial VM protection */ 34 uint32 nsects; /* number of sections in segment */ 35 uint32 flags; /* flags */ 36 } MachSeg32; /* for 32-bit architectures */ 37 38 typedef struct { 39 MachCmd cmd; 40 char segname[16]; /* segment name */ 41 uvlong vmaddr; /* memory address of this segment */ 42 uvlong vmsize; /* memory size of this segment */ 43 uvlong fileoff; /* file offset of this segment */ 44 uvlong filesize; /* amount to map from the file */ 45 uint32 maxprot; /* maximum VM protection */ 46 uint32 initprot; /* initial VM protection */ 47 uint32 nsects; /* number of sections in segment */ 48 uint32 flags; /* flags */ 49 } MachSeg64; /* for 64-bit architectures */ 50 51 typedef struct { 52 MachCmd cmd; 53 uint32 fileoff; /* file offset of this segment */ 54 uint32 filesize; /* amount to map from the file */ 55 } MachSymSeg; 56 57 typedef struct { 58 char sectname[16]; /* name of this section */ 59 char segname[16]; /* segment this section goes in */ 60 uint32 addr; /* memory address of this section */ 61 uint32 size; /* size in bytes of this section */ 62 uint32 offset; /* file offset of this section */ 63 uint32 align; /* section alignment (power of 2) */ 64 uint32 reloff; /* file offset of relocation entries */ 65 uint32 nreloc; /* number of relocation entries */ 66 uint32 flags; /* flags (section type and attributes)*/ 67 uint32 reserved1; /* reserved (for offset or index) */ 68 uint32 reserved2; /* reserved (for count or sizeof) */ 69 } MachSect32; /* for 32-bit architectures */ 70 71 typedef struct { 72 char sectname[16]; /* name of this section */ 73 char segname[16]; /* segment this section goes in */ 74 uvlong addr; /* memory address of this section */ 75 uvlong size; /* size in bytes of this section */ 76 uint32 offset; /* file offset of this section */ 77 uint32 align; /* section alignment (power of 2) */ 78 uint32 reloff; /* file offset of relocation entries */ 79 uint32 nreloc; /* number of relocation entries */ 80 uint32 flags; /* flags (section type and attributes)*/ 81 uint32 reserved1; /* reserved (for offset or index) */ 82 uint32 reserved2; /* reserved (for count or sizeof) */ 83 uint32 reserved3; /* reserved */ 84 } MachSect64; /* for 64-bit architectures */ 85 86 enum { 87 MACH_CPU_TYPE_X86_64 = (1<<24)|7, 88 MACH_CPU_TYPE_X86 = 7, 89 MACH_CPU_SUBTYPE_X86 = 3, 90 MACH_EXECUTABLE_TYPE = 2, 91 MACH_SEGMENT_32 = 1, /* 32-bit mapped segment */ 92 MACH_SEGMENT_64 = 0x19, /* 64-bit mapped segment */ 93 MACH_SYMSEG = 3, /* obsolete gdb symtab, reused by go */ 94 MACH_UNIXTHREAD = 0x5, /* thread (for stack) */ 95 }; 96 97 98 #define MACH64_MAG ((0xcf<<24) | (0xfa<<16) | (0xed<<8) | 0xfe) 99 #define MACH32_MAG ((0xce<<24) | (0xfa<<16) | (0xed<<8) | 0xfe)