axle OS
x86_32 UNIX-like hobby OS
src
kernel
util
macho
macho.h
1
#ifndef MACH_O_H
2
#define MACH_O_H
3
4
#include <stdint.h>
5
6
typedef
int
integer_t;
7
typedef
integer_t cpu_type_t;
8
typedef
integer_t cpu_subtype_t;
9
typedef
int
vm_prot_t;
10
11
/* Constant for the magic field of the mach_header (32-bit architectures) */
12
#define MH_MAGIC 0xfeedface
/* the mach magic number */
13
#define MH_CIGAM 0xcefaedfe
/* NXSwapInt(MH_MAGIC) */
14
15
/* Constant for the magic field of the mach_header_64 (64-bit architectures) */
16
#define MH_MAGIC_64 0xfeedfacf
/* the 64-bit mach magic number */
17
#define MH_CIGAM_64 0xcffaedfe
/* NXSwapInt(MH_MAGIC_64) */
18
19
/* Constants for the cmd field of all load commands, the type */
20
#define LC_SEGMENT 0x1
/* segment of this file to be mapped */
21
#define LC_SEGMENT_64 0x19
/* 64-bit segment of this file to be mapped */
22
23
/*
24
* The 32-bit mach header appears at the very beginning of the object file for
25
* 32-bit architectures.
26
*/
27
struct
mach_header
{
28
uint32_t magic;
/* mach magic number identifier */
29
cpu_type_t cputype;
/* cpu specifier */
30
cpu_subtype_t cpusubtype;
/* machine specifier */
31
uint32_t filetype;
/* type of file */
32
uint32_t ncmds;
/* number of load commands */
33
uint32_t sizeofcmds;
/* the size of all the load commands */
34
uint32_t flags;
/* flags */
35
};
36
37
/*
38
* The segment load command indicates that a part of this file is to be
39
* mapped into the task's address space. The size of this segment in memory,
40
* vmsize, maybe equal to or larger than the amount to map from this file,
41
* filesize. The file is mapped starting at fileoff to the beginning of
42
* the segment in memory, vmaddr. The rest of the memory of the segment,
43
* if any, is allocated zero fill on demand. The segment's maximum virtual
44
* memory protection and initial virtual memory protection are specified
45
* by the maxprot and initprot fields. If the segment has sections then the
46
* section structures directly follow the segment command and their size is
47
* reflected in cmdsize.
48
*/
49
struct
segment_command
{
/* for 32-bit architectures */
50
uint32_t cmd;
/* LC_SEGMENT */
51
uint32_t cmdsize;
/* includes sizeof section structs */
52
char
segname[16];
/* segment name */
53
uint32_t vmaddr;
/* memory address of this segment */
54
uint32_t vmsize;
/* memory size of this segment */
55
uint32_t fileoff;
/* file offset of this segment */
56
uint32_t filesize;
/* amount to map from the file */
57
vm_prot_t maxprot;
/* maximum VM protection */
58
vm_prot_t initprot;
/* initial VM protection */
59
uint32_t nsects;
/* number of sections in segment */
60
uint32_t flags;
/* flags */
61
};
62
63
struct
load_command
{
64
uint32_t cmd;
65
uint32_t cmdsize;
66
};
67
68
void
mach_load_file(
char
* filename);
69
70
#endif
segment_command
Definition:
macho.h:49
mach_header
Definition:
macho.h:27
load_command
Definition:
macho.h:63
Generated by
1.8.14