-
Notifications
You must be signed in to change notification settings - Fork 0
/
elf.h
59 lines (50 loc) · 1.1 KB
/
elf.h
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
#ifndef __ELF_H__
#define __ELF_H__
#include <stdint.h>
#include "list.h"
#include "memory.h"
#define ELF_NIDENT 16
#define ELF_CLASS 4
#define ELF_DATA 5
#define ELF_CLASS64 2
#define ELF_DATA2LSB 1
#define ELF_EXEC 2
struct elf_hdr {
uint8_t e_ident[ELF_NIDENT];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
uint64_t e_entry;
uint64_t e_phoff;
uint64_t e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} __attribute__((packed));
#define PT_NULL 0
#define PT_LOAD 1
#define PF_X 0x1
#define PF_W 0x2
#define PF_R 0x4
struct elf_phdr {
uint32_t p_type;
uint32_t p_flags;
uint64_t p_offset;
uint64_t p_vaddr;
uint64_t p_paddr;
uint64_t p_filesz;
uint64_t p_memsz;
uint64_t p_align;
} __attribute__((packed));
typedef struct {
virt_t entry;
struct list_head mm_list_head;
}elf_contents;
elf_contents * parse_elf(const char * path);
elf_contents * create_elf_contents();
void destroy_elf_contents(elf_contents * contents);
#endif /*__ELF_H__*/