1
2 #ifndef _UAPI_LINUX_ELF_H
3 #define _UAPI_LINUX_ELF_H
4
5 #include <linux/types.h>
6 #include <linux/elf-em.h>
7
8
9 typedef __u32 Elf32_Addr;
10 typedef __u16 Elf32_Half;
11 typedef __u32 Elf32_Off;
12 typedef __s32 Elf32_Sword;
13 typedef __u32 Elf32_Word;
14
15
16 typedef __u64 Elf64_Addr;
17 typedef __u16 Elf64_Half;
18 typedef __s16 Elf64_SHalf;
19 typedef __u64 Elf64_Off;
20 typedef __s32 Elf64_Sword;
21 typedef __u32 Elf64_Word;
22 typedef __u64 Elf64_Xword;
23 typedef __s64 Elf64_Sxword;
24
25
26 #define PT_NULL 0
27 #define PT_LOAD 1
28 #define PT_DYNAMIC 2
29 #define PT_INTERP 3
30 #define PT_NOTE 4
31 #define PT_SHLIB 5
32 #define PT_PHDR 6
33 #define PT_TLS 7
34 #define PT_LOOS 0x60000000
35 #define PT_HIOS 0x6fffffff
36 #define PT_LOPROC 0x70000000
37 #define PT_HIPROC 0x7fffffff
38 #define PT_GNU_EH_FRAME 0x6474e550
39
40 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 #define PN_XNUM 0xffff
63
64
65 #define ET_NONE 0
66 #define ET_REL 1
67 #define ET_EXEC 2
68 #define ET_DYN 3
69 #define ET_CORE 4
70 #define ET_LOPROC 0xff00
71 #define ET_HIPROC 0xffff
72
73
74 #define DT_NULL 0
75 #define DT_NEEDED 1
76 #define DT_PLTRELSZ 2
77 #define DT_PLTGOT 3
78 #define DT_HASH 4
79 #define DT_STRTAB 5
80 #define DT_SYMTAB 6
81 #define DT_RELA 7
82 #define DT_RELASZ 8
83 #define DT_RELAENT 9
84 #define DT_STRSZ 10
85 #define DT_SYMENT 11
86 #define DT_INIT 12
87 #define DT_FINI 13
88 #define DT_SONAME 14
89 #define DT_RPATH 15
90 #define DT_SYMBOLIC 16
91 #define DT_REL 17
92 #define DT_RELSZ 18
93 #define DT_RELENT 19
94 #define DT_PLTREL 20
95 #define DT_DEBUG 21
96 #define DT_TEXTREL 22
97 #define DT_JMPREL 23
98 #define DT_ENCODING 32
99 #define OLD_DT_LOOS 0x60000000
100 #define DT_LOOS 0x6000000d
101 #define DT_HIOS 0x6ffff000
102 #define DT_VALRNGLO 0x6ffffd00
103 #define DT_VALRNGHI 0x6ffffdff
104 #define DT_ADDRRNGLO 0x6ffffe00
105 #define DT_ADDRRNGHI 0x6ffffeff
106 #define DT_VERSYM 0x6ffffff0
107 #define DT_RELACOUNT 0x6ffffff9
108 #define DT_RELCOUNT 0x6ffffffa
109 #define DT_FLAGS_1 0x6ffffffb
110 #define DT_VERDEF 0x6ffffffc
111 #define DT_VERDEFNUM 0x6ffffffd
112 #define DT_VERNEED 0x6ffffffe
113 #define DT_VERNEEDNUM 0x6fffffff
114 #define OLD_DT_HIOS 0x6fffffff
115 #define DT_LOPROC 0x70000000
116 #define DT_HIPROC 0x7fffffff
117
118
119 #define STB_LOCAL 0
120 #define STB_GLOBAL 1
121 #define STB_WEAK 2
122
123 #define STT_NOTYPE 0
124 #define STT_OBJECT 1
125 #define STT_FUNC 2
126 #define STT_SECTION 3
127 #define STT_FILE 4
128 #define STT_COMMON 5
129 #define STT_TLS 6
130
131 #define ELF_ST_BIND(x) ((x) >> 4)
132 #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
133 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
134 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
135 #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
136 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
137
138 typedef struct dynamic{
139 Elf32_Sword d_tag;
140 union{
141 Elf32_Sword d_val;
142 Elf32_Addr d_ptr;
143 } d_un;
144 } Elf32_Dyn;
145
146 typedef struct {
147 Elf64_Sxword d_tag;
148 union {
149 Elf64_Xword d_val;
150 Elf64_Addr d_ptr;
151 } d_un;
152 } Elf64_Dyn;
153
154
155 #define ELF32_R_SYM(x) ((x) >> 8)
156 #define ELF32_R_TYPE(x) ((x) & 0xff)
157
158 #define ELF64_R_SYM(i) ((i) >> 32)
159 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
160
161 typedef struct elf32_rel {
162 Elf32_Addr r_offset;
163 Elf32_Word r_info;
164 } Elf32_Rel;
165
166 typedef struct elf64_rel {
167 Elf64_Addr r_offset;
168 Elf64_Xword r_info;
169 } Elf64_Rel;
170
171 typedef struct elf32_rela{
172 Elf32_Addr r_offset;
173 Elf32_Word r_info;
174 Elf32_Sword r_addend;
175 } Elf32_Rela;
176
177 typedef struct elf64_rela {
178 Elf64_Addr r_offset;
179 Elf64_Xword r_info;
180 Elf64_Sxword r_addend;
181 } Elf64_Rela;
182
183 typedef struct elf32_sym{
184 Elf32_Word st_name;
185 Elf32_Addr st_value;
186 Elf32_Word st_size;
187 unsigned char st_info;
188 unsigned char st_other;
189 Elf32_Half st_shndx;
190 } Elf32_Sym;
191
192 typedef struct elf64_sym {
193 Elf64_Word st_name;
194 unsigned char st_info;
195 unsigned char st_other;
196 Elf64_Half st_shndx;
197 Elf64_Addr st_value;
198 Elf64_Xword st_size;
199 } Elf64_Sym;
200
201
202 #define EI_NIDENT 16
203
204 typedef struct elf32_hdr{
205 unsigned char e_ident[EI_NIDENT];
206 Elf32_Half e_type;
207 Elf32_Half e_machine;
208 Elf32_Word e_version;
209 Elf32_Addr e_entry;
210 Elf32_Off e_phoff;
211 Elf32_Off e_shoff;
212 Elf32_Word e_flags;
213 Elf32_Half e_ehsize;
214 Elf32_Half e_phentsize;
215 Elf32_Half e_phnum;
216 Elf32_Half e_shentsize;
217 Elf32_Half e_shnum;
218 Elf32_Half e_shstrndx;
219 } Elf32_Ehdr;
220
221 typedef struct elf64_hdr {
222 unsigned char e_ident[EI_NIDENT];
223 Elf64_Half e_type;
224 Elf64_Half e_machine;
225 Elf64_Word e_version;
226 Elf64_Addr e_entry;
227 Elf64_Off e_phoff;
228 Elf64_Off e_shoff;
229 Elf64_Word e_flags;
230 Elf64_Half e_ehsize;
231 Elf64_Half e_phentsize;
232 Elf64_Half e_phnum;
233 Elf64_Half e_shentsize;
234 Elf64_Half e_shnum;
235 Elf64_Half e_shstrndx;
236 } Elf64_Ehdr;
237
238
239
240 #define PF_R 0x4
241 #define PF_W 0x2
242 #define PF_X 0x1
243
244 typedef struct elf32_phdr{
245 Elf32_Word p_type;
246 Elf32_Off p_offset;
247 Elf32_Addr p_vaddr;
248 Elf32_Addr p_paddr;
249 Elf32_Word p_filesz;
250 Elf32_Word p_memsz;
251 Elf32_Word p_flags;
252 Elf32_Word p_align;
253 } Elf32_Phdr;
254
255 typedef struct elf64_phdr {
256 Elf64_Word p_type;
257 Elf64_Word p_flags;
258 Elf64_Off p_offset;
259 Elf64_Addr p_vaddr;
260 Elf64_Addr p_paddr;
261 Elf64_Xword p_filesz;
262 Elf64_Xword p_memsz;
263 Elf64_Xword p_align;
264 } Elf64_Phdr;
265
266
267 #define SHT_NULL 0
268 #define SHT_PROGBITS 1
269 #define SHT_SYMTAB 2
270 #define SHT_STRTAB 3
271 #define SHT_RELA 4
272 #define SHT_HASH 5
273 #define SHT_DYNAMIC 6
274 #define SHT_NOTE 7
275 #define SHT_NOBITS 8
276 #define SHT_REL 9
277 #define SHT_SHLIB 10
278 #define SHT_DYNSYM 11
279 #define SHT_NUM 12
280 #define SHT_LOPROC 0x70000000
281 #define SHT_HIPROC 0x7fffffff
282 #define SHT_LOUSER 0x80000000
283 #define SHT_HIUSER 0xffffffff
284
285
286 #define SHF_WRITE 0x1
287 #define SHF_ALLOC 0x2
288 #define SHF_EXECINSTR 0x4
289 #define SHF_RELA_LIVEPATCH 0x00100000
290 #define SHF_RO_AFTER_INIT 0x00200000
291 #define SHF_MASKPROC 0xf0000000
292
293
294 #define SHN_UNDEF 0
295 #define SHN_LORESERVE 0xff00
296 #define SHN_LOPROC 0xff00
297 #define SHN_HIPROC 0xff1f
298 #define SHN_LIVEPATCH 0xff20
299 #define SHN_ABS 0xfff1
300 #define SHN_COMMON 0xfff2
301 #define SHN_HIRESERVE 0xffff
302
303 typedef struct elf32_shdr {
304 Elf32_Word sh_name;
305 Elf32_Word sh_type;
306 Elf32_Word sh_flags;
307 Elf32_Addr sh_addr;
308 Elf32_Off sh_offset;
309 Elf32_Word sh_size;
310 Elf32_Word sh_link;
311 Elf32_Word sh_info;
312 Elf32_Word sh_addralign;
313 Elf32_Word sh_entsize;
314 } Elf32_Shdr;
315
316 typedef struct elf64_shdr {
317 Elf64_Word sh_name;
318 Elf64_Word sh_type;
319 Elf64_Xword sh_flags;
320 Elf64_Addr sh_addr;
321 Elf64_Off sh_offset;
322 Elf64_Xword sh_size;
323 Elf64_Word sh_link;
324 Elf64_Word sh_info;
325 Elf64_Xword sh_addralign;
326 Elf64_Xword sh_entsize;
327 } Elf64_Shdr;
328
329 #define EI_MAG0 0
330 #define EI_MAG1 1
331 #define EI_MAG2 2
332 #define EI_MAG3 3
333 #define EI_CLASS 4
334 #define EI_DATA 5
335 #define EI_VERSION 6
336 #define EI_OSABI 7
337 #define EI_PAD 8
338
339 #define ELFMAG0 0x7f
340 #define ELFMAG1 'E'
341 #define ELFMAG2 'L'
342 #define ELFMAG3 'F'
343 #define ELFMAG "\177ELF"
344 #define SELFMAG 4
345
346 #define ELFCLASSNONE 0
347 #define ELFCLASS32 1
348 #define ELFCLASS64 2
349 #define ELFCLASSNUM 3
350
351 #define ELFDATANONE 0
352 #define ELFDATA2LSB 1
353 #define ELFDATA2MSB 2
354
355 #define EV_NONE 0
356 #define EV_CURRENT 1
357 #define EV_NUM 2
358
359 #define ELFOSABI_NONE 0
360 #define ELFOSABI_LINUX 3
361
362 #ifndef ELF_OSABI
363 #define ELF_OSABI ELFOSABI_NONE
364 #endif
365
366
367
368
369
370
371 #define NT_PRSTATUS 1
372 #define NT_PRFPREG 2
373 #define NT_PRPSINFO 3
374 #define NT_TASKSTRUCT 4
375 #define NT_AUXV 6
376
377
378
379
380 #define NT_SIGINFO 0x53494749
381 #define NT_FILE 0x46494c45
382 #define NT_PRXFPREG 0x46e62b7f
383 #define NT_PPC_VMX 0x100
384 #define NT_PPC_SPE 0x101
385 #define NT_PPC_VSX 0x102
386 #define NT_PPC_TAR 0x103
387 #define NT_PPC_PPR 0x104
388 #define NT_PPC_DSCR 0x105
389 #define NT_PPC_EBB 0x106
390 #define NT_PPC_PMU 0x107
391 #define NT_PPC_TM_CGPR 0x108
392 #define NT_PPC_TM_CFPR 0x109
393 #define NT_PPC_TM_CVMX 0x10a
394 #define NT_PPC_TM_CVSX 0x10b
395 #define NT_PPC_TM_SPR 0x10c
396 #define NT_PPC_TM_CTAR 0x10d
397 #define NT_PPC_TM_CPPR 0x10e
398 #define NT_PPC_TM_CDSCR 0x10f
399 #define NT_PPC_PKEY 0x110
400 #define NT_386_TLS 0x200
401 #define NT_386_IOPERM 0x201
402 #define NT_X86_XSTATE 0x202
403 #define NT_S390_HIGH_GPRS 0x300
404 #define NT_S390_TIMER 0x301
405 #define NT_S390_TODCMP 0x302
406 #define NT_S390_TODPREG 0x303
407 #define NT_S390_CTRS 0x304
408 #define NT_S390_PREFIX 0x305
409 #define NT_S390_LAST_BREAK 0x306
410 #define NT_S390_SYSTEM_CALL 0x307
411 #define NT_S390_TDB 0x308
412 #define NT_S390_VXRS_LOW 0x309
413 #define NT_S390_VXRS_HIGH 0x30a
414 #define NT_S390_GS_CB 0x30b
415 #define NT_S390_GS_BC 0x30c
416 #define NT_S390_RI_CB 0x30d
417 #define NT_ARM_VFP 0x400
418 #define NT_ARM_TLS 0x401
419 #define NT_ARM_HW_BREAK 0x402
420 #define NT_ARM_HW_WATCH 0x403
421 #define NT_ARM_SYSTEM_CALL 0x404
422 #define NT_ARM_SVE 0x405
423 #define NT_ARM_PAC_MASK 0x406
424 #define NT_ARM_PACA_KEYS 0x407
425 #define NT_ARM_PACG_KEYS 0x408
426 #define NT_ARC_V2 0x600
427 #define NT_VMCOREDD 0x700
428 #define NT_MIPS_DSP 0x800
429 #define NT_MIPS_FP_MODE 0x801
430 #define NT_MIPS_MSA 0x802
431
432
433 typedef struct elf32_note {
434 Elf32_Word n_namesz;
435 Elf32_Word n_descsz;
436 Elf32_Word n_type;
437 } Elf32_Nhdr;
438
439
440 typedef struct elf64_note {
441 Elf64_Word n_namesz;
442 Elf64_Word n_descsz;
443 Elf64_Word n_type;
444 } Elf64_Nhdr;
445
446 #endif