diff options
author | Russ Cox <rsc@swtch.com> | 2010-09-24 12:25:25 -0400 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2010-09-24 12:25:25 -0400 |
commit | 873e5f5094b404c7ac62830341eca4eacf8b4afa (patch) | |
tree | db996fc4c5e5986616d12e36c5fe9814e90f0e7c /src/libmach/macho.h | |
parent | 875351f44f2fa7d79e3cd69ef8862cb9c822ab66 (diff) | |
download | plan9port-873e5f5094b404c7ac62830341eca4eacf8b4afa.tar.gz plan9port-873e5f5094b404c7ac62830341eca4eacf8b4afa.tar.bz2 plan9port-873e5f5094b404c7ac62830341eca4eacf8b4afa.zip |
libmach: more mach-o support
R=rsc
http://codereview.appspot.com/2277041
Diffstat (limited to 'src/libmach/macho.h')
-rw-r--r-- | src/libmach/macho.h | 126 |
1 files changed, 104 insertions, 22 deletions
diff --git a/src/libmach/macho.h b/src/libmach/macho.h index d2a1a2e8..2b449f04 100644 --- a/src/libmach/macho.h +++ b/src/libmach/macho.h @@ -1,11 +1,18 @@ typedef struct Macho Macho; typedef struct MachoCmd MachoCmd; +typedef struct MachoSeg MachoSeg; +typedef struct MachoSect MachoSect; +typedef struct MachoRel MachoRel; +typedef struct MachoSymtab MachoSymtab; +typedef struct MachoSym MachoSym; +typedef struct MachoDysymtab MachoDysymtab; enum { MachoCpuVax = 1, MachoCpu68000 = 6, MachoCpu386 = 7, + MachoCpuAmd64 = 0x1000007, MachoCpuMips = 8, MachoCpu98000 = 10, MachoCpuHppa = 11, @@ -20,6 +27,8 @@ enum MachoCmdSymtab = 2, MachoCmdSymseg = 3, MachoCmdThread = 4, + MachoCmdDysymtab = 11, + MachoCmdSegment64 = 25, MachoFileObject = 1, MachoFileExecutable = 2, @@ -28,40 +37,111 @@ enum MachoFilePreload = 5 }; +struct MachoSeg +{ + char name[16+1]; + uint64 vmaddr; + uint64 vmsize; + uint32 fileoff; + uint32 filesz; + uint32 maxprot; + uint32 initprot; + uint32 nsect; + uint32 flags; + MachoSect *sect; +}; + +struct MachoSect +{ + char name[16+1]; + char segname[16+1]; + uint64 addr; + uint64 size; + uint32 offset; + uint32 align; + uint32 reloff; + uint32 nreloc; + uint32 flags; + + MachoRel *rel; +}; + +struct MachoRel +{ + uint32 addr; + uint32 symnum; + uint8 pcrel; + uint8 length; + uint8 extrn; + uint8 type; +}; + +struct MachoSymtab +{ + uint32 symoff; + uint32 nsym; + uint32 stroff; + uint32 strsize; + + char *str; + MachoSym *sym; +}; + +struct MachoSym +{ + char *name; + uint8 type; + uint8 sectnum; + uint16 desc; + char kind; + uint64 value; +}; + +struct MachoDysymtab +{ + uint32 ilocalsym; + uint32 nlocalsym; + uint32 iextdefsym; + uint32 nextdefsym; + uint32 iundefsym; + uint32 nundefsym; + uint32 tocoff; + uint32 ntoc; + uint32 modtaboff; + uint32 nmodtab; + uint32 extrefsymoff; + uint32 nextrefsyms; + uint32 indirectsymoff; + uint32 nindirectsyms; + uint32 extreloff; + uint32 nextrel; + uint32 locreloff; + uint32 nlocrel; +}; + struct MachoCmd { int type; - ulong off; - ulong size; - struct { - char name[16+1]; - ulong vmaddr; - ulong vmsize; - ulong fileoff; - ulong filesz; - ulong maxprot; - ulong initprot; - ulong nsect; - ulong flags; - } seg; - struct { - ulong symoff; - ulong nsyms; - ulong stroff; - ulong strsize; - } sym; + uint32 off; + uint32 size; + MachoSeg seg; + MachoSymtab sym; + MachoDysymtab dsym; }; struct Macho { int fd; + int is64; uint cputype; uint subcputype; - ulong filetype; - ulong flags; + uint32 filetype; + uint32 flags; MachoCmd *cmd; uint ncmd; - u32int (*e4)(uchar*); + uint16 (*e2)(uchar*); + uint32 (*e4)(uchar*); + uint64 (*e8)(uchar*); int (*coreregs)(Macho*, uchar**); }; @@ -69,3 +149,5 @@ Macho *machoopen(char*); Macho *machoinit(int); void machoclose(Macho*); int coreregsmachopower(Macho*, uchar**); +int macholoadrel(Macho*, MachoSect*); +int macholoadsym(Macho*, MachoSymtab*); |