1
by Martin Decky
Initial import |
1 |
/*
|
2 |
* Copyright (c) 2006 Sergey Bondari
|
|
3 |
* All rights reserved.
|
|
4 |
*
|
|
5 |
* Redistribution and use in source and binary forms, with or without
|
|
6 |
* modification, are permitted provided that the following conditions
|
|
7 |
* are met:
|
|
8 |
*
|
|
9 |
* - Redistributions of source code must retain the above copyright
|
|
10 |
* notice, this list of conditions and the following disclaimer.
|
|
11 |
* - Redistributions in binary form must reproduce the above copyright
|
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
|
13 |
* documentation and/or other materials provided with the distribution.
|
|
14 |
* - The name of the author may not be used to endorse or promote products
|
|
15 |
* derived from this software without specific prior written permission.
|
|
16 |
*
|
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
18 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
19 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20 |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
22 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27 |
*/
|
|
28 |
||
488
by Martin Decky
cstyle changes |
29 |
/** @addtogroup generic
|
1
by Martin Decky
Initial import |
30 |
* @{
|
31 |
*/
|
|
32 |
/** @file
|
|
33 |
*/
|
|
34 |
||
1137
by Martin Decky
do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared |
35 |
#ifndef ABI_ELF_H_
|
36 |
#define ABI_ELF_H_
|
|
1
by Martin Decky
Initial import |
37 |
|
38 |
/**
|
|
1137
by Martin Decky
do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared |
39 |
* Current ELF version
|
1
by Martin Decky
Initial import |
40 |
*/
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
41 |
#define EV_CURRENT 1
|
1
by Martin Decky
Initial import |
42 |
|
327
by Martin Decky
use [u]int{8|16|32|64}_t type definitions as detected by the autotool |
43 |
/**
|
44 |
* ELF types
|
|
1
by Martin Decky
Initial import |
45 |
*/
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
46 |
#define ET_NONE 0 /* No type */ |
47 |
#define ET_REL 1 /* Relocatable file */ |
|
48 |
#define ET_EXEC 2 /* Executable */ |
|
49 |
#define ET_DYN 3 /* Shared object */ |
|
50 |
#define ET_CORE 4 /* Core */ |
|
51 |
#define ET_LOPROC 0xff00 /* Processor specific */ |
|
52 |
#define ET_HIPROC 0xffff /* Processor specific */ |
|
1
by Martin Decky
Initial import |
53 |
|
488
by Martin Decky
cstyle changes |
54 |
/**
|
1
by Martin Decky
Initial import |
55 |
* ELF machine types
|
56 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
57 |
#define EM_NO 0 /* No machine */ |
58 |
#define EM_SPARC 2 /* SPARC */ |
|
59 |
#define EM_386 3 /* i386 */ |
|
60 |
#define EM_MIPS 8 /* MIPS RS3000 */ |
|
61 |
#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 LE */ |
|
62 |
#define EM_PPC 20 /* PPC32 */ |
|
63 |
#define EM_PPC64 21 /* PPC64 */ |
|
64 |
#define EM_ARM 40 /* ARM */ |
|
65 |
#define EM_SPARCV9 43 /* SPARC64 */ |
|
66 |
#define EM_IA_64 50 /* IA-64 */ |
|
67 |
#define EM_X86_64 62 /* AMD64/EMT64 */ |
|
1
by Martin Decky
Initial import |
68 |
|
69 |
/**
|
|
70 |
* ELF identification indexes
|
|
71 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
72 |
#define EI_MAG0 0
|
73 |
#define EI_MAG1 1
|
|
74 |
#define EI_MAG2 2
|
|
75 |
#define EI_MAG3 3
|
|
76 |
#define EI_CLASS 4 /* File class */ |
|
77 |
#define EI_DATA 5 /* Data encoding */ |
|
78 |
#define EI_VERSION 6 /* File version */ |
|
79 |
#define EI_OSABI 7
|
|
80 |
#define EI_ABIVERSION 8
|
|
81 |
#define EI_PAD 9 /* Start of padding bytes */ |
|
82 |
#define EI_NIDENT 16 /* ELF identification table size */ |
|
1
by Martin Decky
Initial import |
83 |
|
84 |
/**
|
|
85 |
* ELF magic number
|
|
86 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
87 |
#define ELFMAG0 0x7f
|
88 |
#define ELFMAG1 'E'
|
|
89 |
#define ELFMAG2 'L'
|
|
90 |
#define ELFMAG3 'F'
|
|
1
by Martin Decky
Initial import |
91 |
|
92 |
/**
|
|
93 |
* ELF file classes
|
|
94 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
95 |
#define ELFCLASSNONE 0
|
96 |
#define ELFCLASS32 1
|
|
97 |
#define ELFCLASS64 2
|
|
1
by Martin Decky
Initial import |
98 |
|
99 |
/**
|
|
100 |
* ELF data encoding types
|
|
101 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
102 |
#define ELFDATANONE 0
|
103 |
#define ELFDATA2LSB 1 /* Least significant byte first (little endian) */ |
|
104 |
#define ELFDATA2MSB 2 /* Most signigicant byte first (big endian) */ |
|
1
by Martin Decky
Initial import |
105 |
|
106 |
/**
|
|
107 |
* ELF section types
|
|
108 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
109 |
#define SHT_NULL 0
|
110 |
#define SHT_PROGBITS 1
|
|
111 |
#define SHT_SYMTAB 2
|
|
112 |
#define SHT_STRTAB 3
|
|
113 |
#define SHT_RELA 4
|
|
114 |
#define SHT_HASH 5
|
|
115 |
#define SHT_DYNAMIC 6
|
|
116 |
#define SHT_NOTE 7
|
|
117 |
#define SHT_NOBITS 8
|
|
118 |
#define SHT_REL 9
|
|
119 |
#define SHT_SHLIB 10
|
|
120 |
#define SHT_DYNSYM 11
|
|
121 |
#define SHT_LOOS 0x60000000
|
|
122 |
#define SHT_HIOS 0x6fffffff
|
|
123 |
#define SHT_LOPROC 0x70000000
|
|
124 |
#define SHT_HIPROC 0x7fffffff
|
|
125 |
#define SHT_LOUSER 0x80000000
|
|
126 |
#define SHT_HIUSER 0xffffffff
|
|
1
by Martin Decky
Initial import |
127 |
|
128 |
/**
|
|
129 |
* ELF section flags
|
|
130 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
131 |
#define SHF_WRITE 0x1
|
132 |
#define SHF_ALLOC 0x2
|
|
133 |
#define SHF_EXECINSTR 0x4
|
|
134 |
#define SHF_TLS 0x400
|
|
135 |
#define SHF_MASKPROC 0xf0000000
|
|
1113
by Jiri Svoboda
Eliminate userspace copy of elf.h (ELF format definitions). |
136 |
|
137 |
/** Macros for decomposing elf_symbol.st_info into binging and type */
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
138 |
#define ELF_ST_BIND(i) ((i) >> 4)
|
139 |
#define ELF_ST_TYPE(i) ((i) & 0x0f)
|
|
140 |
#define ELF_ST_INFO(b, t) (((b) << 4) + ((t) & 0x0f))
|
|
1
by Martin Decky
Initial import |
141 |
|
142 |
/**
|
|
143 |
* Symbol binding
|
|
144 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
145 |
#define STB_LOCAL 0
|
146 |
#define STB_GLOBAL 1
|
|
147 |
#define STB_WEAK 2
|
|
148 |
#define STB_LOPROC 13
|
|
149 |
#define STB_HIPROC 15
|
|
1
by Martin Decky
Initial import |
150 |
|
151 |
/**
|
|
152 |
* Symbol types
|
|
153 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
154 |
#define STT_NOTYPE 0
|
155 |
#define STT_OBJECT 1
|
|
156 |
#define STT_FUNC 2
|
|
157 |
#define STT_SECTION 3
|
|
158 |
#define STT_FILE 4
|
|
159 |
#define STT_LOPROC 13
|
|
160 |
#define STT_HIPROC 15
|
|
1
by Martin Decky
Initial import |
161 |
|
162 |
/**
|
|
163 |
* Program segment types
|
|
164 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
165 |
#define PT_NULL 0
|
166 |
#define PT_LOAD 1
|
|
167 |
#define PT_DYNAMIC 2
|
|
168 |
#define PT_INTERP 3
|
|
169 |
#define PT_NOTE 4
|
|
170 |
#define PT_SHLIB 5
|
|
171 |
#define PT_PHDR 6
|
|
172 |
#define PT_LOPROC 0x70000000
|
|
173 |
#define PT_HIPROC 0x7fffffff
|
|
1
by Martin Decky
Initial import |
174 |
|
175 |
/**
|
|
176 |
* Program segment attributes.
|
|
177 |
*/
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
178 |
#define PF_X 1
|
179 |
#define PF_W 2
|
|
180 |
#define PF_R 4
|
|
1
by Martin Decky
Initial import |
181 |
|
182 |
/**
|
|
183 |
* ELF data types
|
|
184 |
*
|
|
185 |
* These types are found to be identical in both 32-bit and 64-bit
|
|
186 |
* ELF object file specifications. They are the only types used
|
|
187 |
* in ELF header.
|
|
188 |
*/
|
|
189 |
typedef uint64_t elf_xword; |
|
190 |
typedef int64_t elf_sxword; |
|
191 |
typedef uint32_t elf_word; |
|
192 |
typedef int32_t elf_sword; |
|
193 |
typedef uint16_t elf_half; |
|
194 |
||
195 |
/**
|
|
196 |
* 32-bit ELF data types.
|
|
197 |
*
|
|
198 |
* These types are specific for 32-bit format.
|
|
199 |
*/
|
|
200 |
typedef uint32_t elf32_addr; |
|
201 |
typedef uint32_t elf32_off; |
|
202 |
||
203 |
/**
|
|
204 |
* 64-bit ELF data types.
|
|
205 |
*
|
|
206 |
* These types are specific for 64-bit format.
|
|
207 |
*/
|
|
208 |
typedef uint64_t elf64_addr; |
|
209 |
typedef uint64_t elf64_off; |
|
210 |
||
211 |
/** ELF header */
|
|
212 |
struct elf32_header { |
|
213 |
uint8_t e_ident[EI_NIDENT]; |
|
214 |
elf_half e_type; |
|
215 |
elf_half e_machine; |
|
216 |
elf_word e_version; |
|
217 |
elf32_addr e_entry; |
|
218 |
elf32_off e_phoff; |
|
219 |
elf32_off e_shoff; |
|
220 |
elf_word e_flags; |
|
221 |
elf_half e_ehsize; |
|
222 |
elf_half e_phentsize; |
|
223 |
elf_half e_phnum; |
|
224 |
elf_half e_shentsize; |
|
225 |
elf_half e_shnum; |
|
226 |
elf_half e_shstrndx; |
|
227 |
};
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
228 |
|
1
by Martin Decky
Initial import |
229 |
struct elf64_header { |
230 |
uint8_t e_ident[EI_NIDENT]; |
|
231 |
elf_half e_type; |
|
232 |
elf_half e_machine; |
|
233 |
elf_word e_version; |
|
234 |
elf64_addr e_entry; |
|
235 |
elf64_off e_phoff; |
|
236 |
elf64_off e_shoff; |
|
237 |
elf_word e_flags; |
|
238 |
elf_half e_ehsize; |
|
239 |
elf_half e_phentsize; |
|
240 |
elf_half e_phnum; |
|
241 |
elf_half e_shentsize; |
|
242 |
elf_half e_shnum; |
|
243 |
elf_half e_shstrndx; |
|
244 |
};
|
|
245 |
||
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
246 |
/**
|
1
by Martin Decky
Initial import |
247 |
* ELF segment header.
|
248 |
* Segments headers are also known as program headers.
|
|
249 |
*/
|
|
250 |
struct elf32_segment_header { |
|
251 |
elf_word p_type; |
|
252 |
elf32_off p_offset; |
|
253 |
elf32_addr p_vaddr; |
|
254 |
elf32_addr p_paddr; |
|
255 |
elf_word p_filesz; |
|
256 |
elf_word p_memsz; |
|
257 |
elf_word p_flags; |
|
258 |
elf_word p_align; |
|
259 |
};
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
260 |
|
1
by Martin Decky
Initial import |
261 |
struct elf64_segment_header { |
262 |
elf_word p_type; |
|
263 |
elf_word p_flags; |
|
264 |
elf64_off p_offset; |
|
265 |
elf64_addr p_vaddr; |
|
266 |
elf64_addr p_paddr; |
|
267 |
elf_xword p_filesz; |
|
268 |
elf_xword p_memsz; |
|
269 |
elf_xword p_align; |
|
270 |
};
|
|
271 |
||
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
272 |
/**
|
1
by Martin Decky
Initial import |
273 |
* ELF section header
|
274 |
*/
|
|
275 |
struct elf32_section_header { |
|
276 |
elf_word sh_name; |
|
277 |
elf_word sh_type; |
|
278 |
elf_word sh_flags; |
|
279 |
elf32_addr sh_addr; |
|
280 |
elf32_off sh_offset; |
|
281 |
elf_word sh_size; |
|
282 |
elf_word sh_link; |
|
283 |
elf_word sh_info; |
|
284 |
elf_word sh_addralign; |
|
285 |
elf_word sh_entsize; |
|
286 |
};
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
287 |
|
1
by Martin Decky
Initial import |
288 |
struct elf64_section_header { |
289 |
elf_word sh_name; |
|
290 |
elf_word sh_type; |
|
291 |
elf_xword sh_flags; |
|
292 |
elf64_addr sh_addr; |
|
293 |
elf64_off sh_offset; |
|
294 |
elf_xword sh_size; |
|
295 |
elf_word sh_link; |
|
296 |
elf_word sh_info; |
|
297 |
elf_xword sh_addralign; |
|
298 |
elf_xword sh_entsize; |
|
299 |
};
|
|
300 |
||
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
301 |
/**
|
1
by Martin Decky
Initial import |
302 |
* ELF symbol table entry
|
303 |
*/
|
|
304 |
struct elf32_symbol { |
|
305 |
elf_word st_name; |
|
306 |
elf32_addr st_value; |
|
307 |
elf_word st_size; |
|
308 |
uint8_t st_info; |
|
309 |
uint8_t st_other; |
|
310 |
elf_half st_shndx; |
|
311 |
};
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
312 |
|
1
by Martin Decky
Initial import |
313 |
struct elf64_symbol { |
314 |
elf_word st_name; |
|
315 |
uint8_t st_info; |
|
316 |
uint8_t st_other; |
|
317 |
elf_half st_shndx; |
|
318 |
elf64_addr st_value; |
|
319 |
elf_xword st_size; |
|
320 |
};
|
|
321 |
||
1113
by Jiri Svoboda
Eliminate userspace copy of elf.h (ELF format definitions). |
322 |
/*
|
323 |
* ELF note segment entry
|
|
324 |
*/
|
|
325 |
struct elf32_note { |
|
326 |
elf_word namesz; |
|
327 |
elf_word descsz; |
|
328 |
elf_word type; |
|
329 |
};
|
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
330 |
|
1131
by Jiri Svoboda
Write register state to core files (amd64). |
331 |
/*
|
332 |
* NOTE: namesz, descsz and type should be 64-bits wide (elf_xword)
|
|
333 |
* per the 64-bit ELF spec. The Linux kernel however screws up and
|
|
334 |
* defines them as Elf64_Word, which is 32-bits wide(!). We are trying
|
|
335 |
* to make our core files compatible with Linux GDB target so we copy
|
|
336 |
* the blunder here.
|
|
337 |
*/
|
|
1113
by Jiri Svoboda
Eliminate userspace copy of elf.h (ELF format definitions). |
338 |
struct elf64_note { |
1131
by Jiri Svoboda
Write register state to core files (amd64). |
339 |
elf_word namesz; |
340 |
elf_word descsz; |
|
341 |
elf_word type; |
|
1113
by Jiri Svoboda
Eliminate userspace copy of elf.h (ELF format definitions). |
342 |
};
|
343 |
||
488
by Martin Decky
cstyle changes |
344 |
#ifdef __32_BITS__
|
1
by Martin Decky
Initial import |
345 |
typedef struct elf32_header elf_header_t; |
346 |
typedef struct elf32_segment_header elf_segment_header_t; |
|
347 |
typedef struct elf32_section_header elf_section_header_t; |
|
348 |
typedef struct elf32_symbol elf_symbol_t; |
|
1113
by Jiri Svoboda
Eliminate userspace copy of elf.h (ELF format definitions). |
349 |
typedef struct elf32_note elf_note_t; |
1
by Martin Decky
Initial import |
350 |
#endif
|
1134
by Martin Decky
do not use tabs for in-line spacing, use spaces |
351 |
|
1
by Martin Decky
Initial import |
352 |
#ifdef __64_BITS__
|
353 |
typedef struct elf64_header elf_header_t; |
|
354 |
typedef struct elf64_segment_header elf_segment_header_t; |
|
355 |
typedef struct elf64_section_header elf_section_header_t; |
|
356 |
typedef struct elf64_symbol elf_symbol_t; |
|
1113
by Jiri Svoboda
Eliminate userspace copy of elf.h (ELF format definitions). |
357 |
typedef struct elf64_note elf_note_t; |
1
by Martin Decky
Initial import |
358 |
#endif
|
359 |
||
360 |
#endif
|
|
361 |
||
362 |
/** @}
|
|
363 |
*/
|