IBNOS
elf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Michael Müller
3  * Copyright (c) 2014, Sebastian Lackner
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef _H_ELF_
29 #define _H_ELF_
30 
31 #include <stdint.h>
32 #include <stdbool.h>
33 
34 #define ELF_IDENT_MAG0 0
35 #define ELF_IDENT_MAG1 1
36 #define ELF_IDENT_MAG2 2
37 #define ELF_IDENT_MAG3 3
38 #define ELF_IDENT_CLASS 4
39 #define ELF_IDENT_DATA 5
40 #define ELF_IDENT_VERSION 6
41 #define ELF_IDENT_OSABI 7
42 #define ELF_IDENT_ABIVERSION 8
43 #define ELF_IDENT_PAD 9
44 #define ELF_NIDENT 16
45 
46 #define ELF_MAG0 0x7f
47 #define ELF_MAG1 'E'
48 #define ELF_MAG2 'L'
49 #define ELF_MAG3 'F'
50 
51 #define ELF_CLASS_NONE 0
52 #define ELF_CLASS_32 1
53 #define ELF_CLASS_64 2
54 
55 /* see http://www.sco.com/developers/gabi/2000-07-17/ch4.eheader.html for the other 81 types*/
56 #define ELF_MACHINE_386 3
57 
58 #define ELF_DATA_NONE 0
59 #define ELF_DATA_2LSB 1
60 #define ELF_DATA_2MSB 2
61 
62 #define ELF_TYPE_NONE 0
63 #define ELF_TYPE_REL 1
64 #define ELF_TYPE_EXEC 2
65 #define ELF_TYPE_DYN 3
66 #define ELF_TYPE_CORE 4
67 #define ELF_TYPE_LOOS 0xfe00
68 #define ELF_TYPE_HIOS 0xfeff
69 #define ELF_TYPE_LOPROC 0xff00
70 #define ELF_TYPE_HIPROC 0xffff
71 
72 #define ELF_SHN_UNDELF 0
73 #define ELF_SHN_LORESERVE 0xff00
74 #define ELF_SHN_LOPROC 0xff00
75 #define ELF_SHN_HIPROC 0xff1f
76 #define ELF_SHN_LOOS 0xff20
77 #define ELF_SHN_HIOS 0xff3f
78 #define ELF_SHN_ABS 0xfff1
79 #define ELF_SHN_COMMON 0xfff2
80 #define ELF_SHN_XINDEX 0xffff
81 #define ELF_SHN_HIRESERVE 0xffff
82 
83 #define ELF_STYPE_NULL 0
84 #define ELF_STYPE_PROGBITS 1
85 #define ELF_STYPE_SYMTAB 2
86 #define ELF_STYPE_STRTAB 3
87 #define ELF_STYPE_RELA 4
88 #define ELF_STYPE_HASH 5
89 #define ELF_STYPE_DYNAMIC 6
90 #define ELF_STYPE_NOTE 7
91 #define ELF_STYPE_NOBITS 8
92 #define ELF_STYPE_REL 9
93 #define ELF_STYPE_SHLIB 10
94 #define ELF_STYPE_DYNSYM 11
95 #define ELF_STYPE_INIT_ARRAY 14
96 #define ELF_STYPE_FINI_ARRAY 15
97 #define ELF_STYPE_PREINIT_ARRAY 16
98 #define ELF_STYPE_GROUP 17
99 #define ELF_STYPE_SYMTAB_SHNDX 18
100 #define ELF_STYPE_LOOS 0x60000000
101 #define ELF_STYPE_HIOS 0x6fffffff
102 #define ELF_STYPE_LOPROC 0x70000000
103 #define ELF_STYPE_HIPROC 0x7fffffff
104 #define ELF_STYPE_LOUSER 0x80000000
105 #define ELF_STYPE_HIUSER 0xffffffff
106 
107 #define ELF_SFLAGS_WRITE 0x1
108 #define ELF_SFLAGS_ALLOC 0x2
109 #define ELF_SFLAGS_EXECINSTR 0x4
110 #define ELF_SFLAGS_MERGE 0x10
111 #define ELF_SFLAGS_STRINGS 0x20
112 #define ELF_SFLAGS_INFO_LINK 0x40
113 #define ELF_SFLAGS_LINK_ORDER 0x80
114 #define ELF_SFLAGS_OS_NONCONFORMING 0x100
115 #define ELF_SFLAGS_GROUP 0x200
116 #define ELF_SFLAGS_MASKOS 0x0ff00000
117 #define ELF_SFLAGS_MASKPROC 0xf0000000
118 
119 #define ELF_PTYPE_NULL 0
120 #define ELF_PTYPE_LOAD 1
121 #define ELF_PTYPE_DYNAMIC 2
122 #define ELF_PTYPE_INTERP 3
123 #define ELF_PTYPE_NOTE 4
124 #define ELF_PTYPE_SHLIB 5
125 #define ELF_PTYPE_PHDR 6
126 #define ELF_PTYPE_LOOS 0x60000000
127 #define ELF_PTYPE_HIOS 0x6fffffff
128 #define ELF_PTYPE_LOPROC 0x70000000
129 #define ELF_PTYPE_HIPROC 0x7fffffff
130 
131 struct elfHeader
132 {
133  uint8_t ident[ELF_NIDENT];
134  uint16_t type;
135  uint16_t machine;
136  uint32_t version;
137  uint32_t entry;
138  uint32_t phoff;
139  uint32_t shoff;
140  uint32_t flags;
141  uint16_t ehsize;
142  uint16_t phentsize;
143  uint16_t phnum;
144  uint16_t shentsize;
145  uint16_t shnum;
146  uint16_t shstrndx;
147 };
148 
149 
151 {
152  uint32_t name;
153  uint32_t type;
154  uint32_t flags;
155  uint32_t addr;
156  uint32_t offset;
157  uint32_t size;
158  uint32_t link;
159  uint32_t info;
160  uint32_t addralign;
161  uint32_t entsize;
162 };
163 
165 {
166  uint32_t name;
167  uint32_t value;
168  uint32_t size;
169  uint8_t info;
170  uint8_t other;
171  uint16_t shndx;
172 };
173 
175 {
176  uint16_t boundto;
177  uint16_t flags;
178 };
179 
181 {
182  uint32_t offset;
183  uint32_t info;
184 };
185 
187 {
188  uint32_t offset;
189  uint32_t info;
190  uint32_t addend;
191 };
192 
194 {
195  uint32_t type;
196  uint32_t offset;
197  uint32_t vaddr;
198  uint32_t paddr;
199  uint32_t filesz;
200  uint32_t memsz;
201  uint32_t flags;
202  uint32_t align;
203 };
204 
206 {
207  uint32_t tag;
208  union
209  {
210  uint32_t val;
211  uint32_t ptr;
212  } un;
213 };
214 
215 #ifdef __KERNEL__
216 
217  #include <stdbool.h>
218  #include <stdint.h>
219 
220  #include <process/process.h>
221 
222  bool elfLoadBinary(struct process *p, void *addr, uint32_t length);
223 
224 #endif
225 
226 #endif /* _H_ELF_ */
uint32_t ptr
Definition: elf.h:211
uint16_t phentsize
Definition: elf.h:142
uint32_t type
Definition: elf.h:195
uint32_t type
Definition: elf.h:153
uint32_t version
Definition: elf.h:136
uint32_t tag
Definition: elf.h:207
uint32_t size
Definition: elf.h:168
uint32_t info
Definition: elf.h:159
uint32_t name
Definition: elf.h:152
uint32_t value
Definition: elf.h:167
uint32_t addr
Definition: elf.h:155
uint32_t offset
Definition: elf.h:182
uint32_t addralign
Definition: elf.h:160
uint16_t phnum
Definition: elf.h:143
uint32_t link
Definition: elf.h:158
uint16_t flags
Definition: elf.h:177
uint16_t boundto
Definition: elf.h:176
uint32_t info
Definition: elf.h:183
uint32_t align
Definition: elf.h:202
uint32_t size
Definition: elf.h:157
Definition: elf.h:131
uint32_t flags
Definition: elf.h:140
uint32_t vaddr
Definition: elf.h:197
uint16_t shstrndx
Definition: elf.h:146
uint32_t name
Definition: elf.h:166
bool elfLoadBinary(struct process *p, void *addr, uint32_t length)
Loads an ELF executable stored in the memory into a process.
Definition: elf.c:104
uint32_t paddr
Definition: elf.h:198
uint32_t offset
Definition: elf.h:196
uint32_t shoff
Definition: elf.h:139
uint16_t type
Definition: elf.h:134
uint8_t info
Definition: elf.h:169
uint32_t filesz
Definition: elf.h:199
uint16_t ehsize
Definition: elf.h:141
uint8_t other
Definition: elf.h:170
uint16_t shentsize
Definition: elf.h:144
uint16_t machine
Definition: elf.h:135
uint32_t flags
Definition: elf.h:154
uint32_t entsize
Definition: elf.h:161
uint32_t offset
Definition: elf.h:156
uint32_t phoff
Definition: elf.h:138
uint16_t shndx
Definition: elf.h:171
uint32_t memsz
Definition: elf.h:200
uint8_t ident[ELF_NIDENT]
Definition: elf.h:133
uint32_t val
Definition: elf.h:210
uint16_t shnum
Definition: elf.h:145
#define ELF_NIDENT
Definition: elf.h:44
uint32_t flags
Definition: elf.h:201
uint32_t entry
Definition: elf.h:137