summaryrefslogtreecommitdiff
path: root/src/libmach/macho.h
blob: 9dfea5a85c0f92c3d24ec1866f889351e8e66abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*
 *	Definitions needed for  accessing MACH object headers.
 */

typedef struct {
	uint32	magic;		/* mach magic number identifier */
	uint32	cputype;	/* cpu specifier */
	uint32	cpusubtype;	/* machine specifier */
	uint32	filetype;	/* type of file */
	uint32	ncmds;		/* number of load commands */
	uint32	sizeofcmds;	/* the size of all the load commands */
	uint32	flags;		/* flags */
	uint32	reserved;	/* reserved */
} Machhdr;

typedef struct {
	uint32	type;	/* type of load command */
	uint32	size;	/* total size in bytes */
} MachCmd;

typedef struct  {
	MachCmd	cmd;
	char		segname[16];	/* segment name */
	uint32	vmaddr;		/* memory address of this segment */
	uint32	vmsize;		/* memory size of this segment */
	uint32	fileoff;	/* file offset of this segment */
	uint32	filesize;	/* amount to map from the file */
	uint32	maxprot;	/* maximum VM protection */
	uint32	initprot;	/* initial VM protection */
	uint32	nsects;		/* number of sections in segment */
	uint32	flags;		/* flags */
} MachSeg32; /* for 32-bit architectures */

typedef struct  {
	MachCmd	cmd;
	char		segname[16];	/* segment name */
	uvlong	vmaddr;		/* memory address of this segment */
	uvlong	vmsize;		/* memory size of this segment */
	uvlong	fileoff;	/* file offset of this segment */
	uvlong	filesize;	/* amount to map from the file */
	uint32	maxprot;	/* maximum VM protection */
	uint32	initprot;	/* initial VM protection */
	uint32	nsects;		/* number of sections in segment */
	uint32	flags;		/* flags */
} MachSeg64; /* for 64-bit architectures */

typedef struct  {
	MachCmd	cmd;
	uint32	fileoff;	/* file offset of this segment */
	uint32	filesize;	/* amount to map from the file */
} MachSymSeg;

typedef struct  {
	char		sectname[16];	/* name of this section */
	char		segname[16];	/* segment this section goes in */
	uint32	addr;		/* memory address of this section */
	uint32	size;		/* size in bytes of this section */
	uint32	offset;		/* file offset of this section */
	uint32	align;		/* section alignment (power of 2) */
	uint32	reloff;		/* file offset of relocation entries */
	uint32	nreloc;		/* number of relocation entries */
	uint32	flags;		/* flags (section type and attributes)*/
	uint32	reserved1;	/* reserved (for offset or index) */
	uint32	reserved2;	/* reserved (for count or sizeof) */
} MachSect32; /* for 32-bit architectures */

typedef struct  {
	char		sectname[16];	/* name of this section */
	char		segname[16];	/* segment this section goes in */
	uvlong	addr;		/* memory address of this section */
	uvlong	size;		/* size in bytes of this section */
	uint32	offset;		/* file offset of this section */
	uint32	align;		/* section alignment (power of 2) */
	uint32	reloff;		/* file offset of relocation entries */
	uint32	nreloc;		/* number of relocation entries */
	uint32	flags;		/* flags (section type and attributes)*/
	uint32	reserved1;	/* reserved (for offset or index) */
	uint32	reserved2;	/* reserved (for count or sizeof) */
	uint32	reserved3;	/* reserved */
} MachSect64; /* for 64-bit architectures */

enum {
	MACH_CPU_TYPE_X86_64 = (1<<24)|7,
	MACH_CPU_TYPE_X86 = 7,
	MACH_CPU_SUBTYPE_X86 = 3,
	MACH_CPU_SUBTYPE_X86_64 = (1<<31)|3,
	MACH_EXECUTABLE_TYPE = 2,
	MACH_SEGMENT_32 = 1,	/* 32-bit mapped segment */
	MACH_SEGMENT_64 = 0x19,	/* 64-bit mapped segment */
	MACH_SYMSEG = 3,	/* obsolete gdb symtab, reused by go */
	MACH_UNIXTHREAD = 0x5,	/* thread (for stack) */
};


#define	MACH64_MAG		((0xcf<<24) | (0xfa<<16) | (0xed<<8) | 0xfe)
#define	MACH32_MAG		((0xce<<24) | (0xfa<<16) | (0xed<<8) | 0xfe)