]> git.ipfire.org Git - people/ms/linux.git/blob - include/uapi/linux/elf.h
Importing "grsecurity-3.1-3.19.2-201503201903.patch"
[people/ms/linux.git] / include / uapi / linux / elf.h
1 #ifndef _UAPI_LINUX_ELF_H
2 #define _UAPI_LINUX_ELF_H
3
4 #include <linux/types.h>
5 #include <linux/elf-em.h>
6
7 /* 32-bit ELF base types. */
8 typedef __u32 Elf32_Addr;
9 typedef __u16 Elf32_Half;
10 typedef __u32 Elf32_Off;
11 typedef __s32 Elf32_Sword;
12 typedef __u32 Elf32_Word;
13
14 /* 64-bit ELF base types. */
15 typedef __u64 Elf64_Addr;
16 typedef __u16 Elf64_Half;
17 typedef __s16 Elf64_SHalf;
18 typedef __u64 Elf64_Off;
19 typedef __s32 Elf64_Sword;
20 typedef __u32 Elf64_Word;
21 typedef __u64 Elf64_Xword;
22 typedef __s64 Elf64_Sxword;
23
24 /* These constants are for the segment types stored in the image headers */
25 #define PT_NULL 0
26 #define PT_LOAD 1
27 #define PT_DYNAMIC 2
28 #define PT_INTERP 3
29 #define PT_NOTE 4
30 #define PT_SHLIB 5
31 #define PT_PHDR 6
32 #define PT_TLS 7 /* Thread local storage segment */
33 #define PT_LOOS 0x60000000 /* OS-specific */
34 #define PT_HIOS 0x6fffffff /* OS-specific */
35 #define PT_LOPROC 0x70000000
36 #define PT_HIPROC 0x7fffffff
37 #define PT_GNU_EH_FRAME 0x6474e550
38
39 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
40 #define PT_GNU_RELRO (PT_LOOS + 0x474e552)
41
42 #define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
43
44 /* Constants for the e_flags field */
45 #define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
46 #define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
47 #define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
48 #define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
49 /*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
50 #define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
51
52 /*
53 * Extended Numbering
54 *
55 * If the real number of program header table entries is larger than
56 * or equal to PN_XNUM(0xffff), it is set to sh_info field of the
57 * section header at index 0, and PN_XNUM is set to e_phnum
58 * field. Otherwise, the section header at index 0 is zero
59 * initialized, if it exists.
60 *
61 * Specifications are available in:
62 *
63 * - Oracle: Linker and Libraries.
64 * Part No: 817–1984–19, August 2011.
65 * http://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf
66 *
67 * - System V ABI AMD64 Architecture Processor Supplement
68 * Draft Version 0.99.4,
69 * January 13, 2010.
70 * http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf
71 */
72 #define PN_XNUM 0xffff
73
74 /* These constants define the different elf file types */
75 #define ET_NONE 0
76 #define ET_REL 1
77 #define ET_EXEC 2
78 #define ET_DYN 3
79 #define ET_CORE 4
80 #define ET_LOPROC 0xff00
81 #define ET_HIPROC 0xffff
82
83 /* This is the info that is needed to parse the dynamic section of the file */
84 #define DT_NULL 0
85 #define DT_NEEDED 1
86 #define DT_PLTRELSZ 2
87 #define DT_PLTGOT 3
88 #define DT_HASH 4
89 #define DT_STRTAB 5
90 #define DT_SYMTAB 6
91 #define DT_RELA 7
92 #define DT_RELASZ 8
93 #define DT_RELAENT 9
94 #define DT_STRSZ 10
95 #define DT_SYMENT 11
96 #define DT_INIT 12
97 #define DT_FINI 13
98 #define DT_SONAME 14
99 #define DT_RPATH 15
100 #define DT_SYMBOLIC 16
101 #define DT_REL 17
102 #define DT_RELSZ 18
103 #define DT_RELENT 19
104 #define DT_PLTREL 20
105 #define DT_DEBUG 21
106 #define DT_TEXTREL 22
107 #define DT_JMPREL 23
108 #define DT_FLAGS 30
109 #define DF_TEXTREL 0x00000004
110 #define DT_ENCODING 32
111 #define OLD_DT_LOOS 0x60000000
112 #define DT_LOOS 0x6000000d
113 #define DT_HIOS 0x6ffff000
114 #define DT_VALRNGLO 0x6ffffd00
115 #define DT_VALRNGHI 0x6ffffdff
116 #define DT_ADDRRNGLO 0x6ffffe00
117 #define DT_ADDRRNGHI 0x6ffffeff
118 #define DT_VERSYM 0x6ffffff0
119 #define DT_RELACOUNT 0x6ffffff9
120 #define DT_RELCOUNT 0x6ffffffa
121 #define DT_FLAGS_1 0x6ffffffb
122 #define DT_VERDEF 0x6ffffffc
123 #define DT_VERDEFNUM 0x6ffffffd
124 #define DT_VERNEED 0x6ffffffe
125 #define DT_VERNEEDNUM 0x6fffffff
126 #define OLD_DT_HIOS 0x6fffffff
127 #define DT_LOPROC 0x70000000
128 #define DT_HIPROC 0x7fffffff
129
130 /* This info is needed when parsing the symbol table */
131 #define STB_LOCAL 0
132 #define STB_GLOBAL 1
133 #define STB_WEAK 2
134
135 #define STT_NOTYPE 0
136 #define STT_OBJECT 1
137 #define STT_FUNC 2
138 #define STT_SECTION 3
139 #define STT_FILE 4
140 #define STT_COMMON 5
141 #define STT_TLS 6
142
143 #define ELF_ST_BIND(x) ((x) >> 4)
144 #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
145 #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
146 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
147 #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
148 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
149
150 typedef struct dynamic{
151 Elf32_Sword d_tag;
152 union{
153 Elf32_Sword d_val;
154 Elf32_Addr d_ptr;
155 } d_un;
156 } Elf32_Dyn;
157
158 typedef struct {
159 Elf64_Sxword d_tag; /* entry tag value */
160 union {
161 Elf64_Xword d_val;
162 Elf64_Addr d_ptr;
163 } d_un;
164 } Elf64_Dyn;
165
166 /* The following are used with relocations */
167 #define ELF32_R_SYM(x) ((x) >> 8)
168 #define ELF32_R_TYPE(x) ((x) & 0xff)
169
170 #define ELF64_R_SYM(i) ((i) >> 32)
171 #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
172
173 typedef struct elf32_rel {
174 Elf32_Addr r_offset;
175 Elf32_Word r_info;
176 } Elf32_Rel;
177
178 typedef struct elf64_rel {
179 Elf64_Addr r_offset; /* Location at which to apply the action */
180 Elf64_Xword r_info; /* index and type of relocation */
181 } Elf64_Rel;
182
183 typedef struct elf32_rela{
184 Elf32_Addr r_offset;
185 Elf32_Word r_info;
186 Elf32_Sword r_addend;
187 } Elf32_Rela;
188
189 typedef struct elf64_rela {
190 Elf64_Addr r_offset; /* Location at which to apply the action */
191 Elf64_Xword r_info; /* index and type of relocation */
192 Elf64_Sxword r_addend; /* Constant addend used to compute value */
193 } Elf64_Rela;
194
195 typedef struct elf32_sym{
196 Elf32_Word st_name;
197 Elf32_Addr st_value;
198 Elf32_Word st_size;
199 unsigned char st_info;
200 unsigned char st_other;
201 Elf32_Half st_shndx;
202 } Elf32_Sym;
203
204 typedef struct elf64_sym {
205 Elf64_Word st_name; /* Symbol name, index in string tbl */
206 unsigned char st_info; /* Type and binding attributes */
207 unsigned char st_other; /* No defined meaning, 0 */
208 Elf64_Half st_shndx; /* Associated section index */
209 Elf64_Addr st_value; /* Value of the symbol */
210 Elf64_Xword st_size; /* Associated symbol size */
211 } Elf64_Sym;
212
213
214 #define EI_NIDENT 16
215
216 typedef struct elf32_hdr{
217 unsigned char e_ident[EI_NIDENT];
218 Elf32_Half e_type;
219 Elf32_Half e_machine;
220 Elf32_Word e_version;
221 Elf32_Addr e_entry; /* Entry point */
222 Elf32_Off e_phoff;
223 Elf32_Off e_shoff;
224 Elf32_Word e_flags;
225 Elf32_Half e_ehsize;
226 Elf32_Half e_phentsize;
227 Elf32_Half e_phnum;
228 Elf32_Half e_shentsize;
229 Elf32_Half e_shnum;
230 Elf32_Half e_shstrndx;
231 } Elf32_Ehdr;
232
233 typedef struct elf64_hdr {
234 unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
235 Elf64_Half e_type;
236 Elf64_Half e_machine;
237 Elf64_Word e_version;
238 Elf64_Addr e_entry; /* Entry point virtual address */
239 Elf64_Off e_phoff; /* Program header table file offset */
240 Elf64_Off e_shoff; /* Section header table file offset */
241 Elf64_Word e_flags;
242 Elf64_Half e_ehsize;
243 Elf64_Half e_phentsize;
244 Elf64_Half e_phnum;
245 Elf64_Half e_shentsize;
246 Elf64_Half e_shnum;
247 Elf64_Half e_shstrndx;
248 } Elf64_Ehdr;
249
250 /* These constants define the permissions on sections in the program
251 header, p_flags. */
252 #define PF_R 0x4
253 #define PF_W 0x2
254 #define PF_X 0x1
255
256 #define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
257 #define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
258 #define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
259 #define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
260 #define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
261 #define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
262 /*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
263 /*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
264 #define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
265 #define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
266 #define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
267 #define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
268
269 typedef struct elf32_phdr{
270 Elf32_Word p_type;
271 Elf32_Off p_offset;
272 Elf32_Addr p_vaddr;
273 Elf32_Addr p_paddr;
274 Elf32_Word p_filesz;
275 Elf32_Word p_memsz;
276 Elf32_Word p_flags;
277 Elf32_Word p_align;
278 } Elf32_Phdr;
279
280 typedef struct elf64_phdr {
281 Elf64_Word p_type;
282 Elf64_Word p_flags;
283 Elf64_Off p_offset; /* Segment file offset */
284 Elf64_Addr p_vaddr; /* Segment virtual address */
285 Elf64_Addr p_paddr; /* Segment physical address */
286 Elf64_Xword p_filesz; /* Segment size in file */
287 Elf64_Xword p_memsz; /* Segment size in memory */
288 Elf64_Xword p_align; /* Segment alignment, file & memory */
289 } Elf64_Phdr;
290
291 /* sh_type */
292 #define SHT_NULL 0
293 #define SHT_PROGBITS 1
294 #define SHT_SYMTAB 2
295 #define SHT_STRTAB 3
296 #define SHT_RELA 4
297 #define SHT_HASH 5
298 #define SHT_DYNAMIC 6
299 #define SHT_NOTE 7
300 #define SHT_NOBITS 8
301 #define SHT_REL 9
302 #define SHT_SHLIB 10
303 #define SHT_DYNSYM 11
304 #define SHT_NUM 12
305 #define SHT_LOPROC 0x70000000
306 #define SHT_HIPROC 0x7fffffff
307 #define SHT_LOUSER 0x80000000
308 #define SHT_HIUSER 0xffffffff
309
310 /* sh_flags */
311 #define SHF_WRITE 0x1
312 #define SHF_ALLOC 0x2
313 #define SHF_EXECINSTR 0x4
314 #define SHF_MASKPROC 0xf0000000
315
316 /* special section indexes */
317 #define SHN_UNDEF 0
318 #define SHN_LORESERVE 0xff00
319 #define SHN_LOPROC 0xff00
320 #define SHN_HIPROC 0xff1f
321 #define SHN_ABS 0xfff1
322 #define SHN_COMMON 0xfff2
323 #define SHN_HIRESERVE 0xffff
324
325 typedef struct elf32_shdr {
326 Elf32_Word sh_name;
327 Elf32_Word sh_type;
328 Elf32_Word sh_flags;
329 Elf32_Addr sh_addr;
330 Elf32_Off sh_offset;
331 Elf32_Word sh_size;
332 Elf32_Word sh_link;
333 Elf32_Word sh_info;
334 Elf32_Word sh_addralign;
335 Elf32_Word sh_entsize;
336 } Elf32_Shdr;
337
338 typedef struct elf64_shdr {
339 Elf64_Word sh_name; /* Section name, index in string tbl */
340 Elf64_Word sh_type; /* Type of section */
341 Elf64_Xword sh_flags; /* Miscellaneous section attributes */
342 Elf64_Addr sh_addr; /* Section virtual addr at execution */
343 Elf64_Off sh_offset; /* Section file offset */
344 Elf64_Xword sh_size; /* Size of section in bytes */
345 Elf64_Word sh_link; /* Index of another section */
346 Elf64_Word sh_info; /* Additional section information */
347 Elf64_Xword sh_addralign; /* Section alignment */
348 Elf64_Xword sh_entsize; /* Entry size if section holds table */
349 } Elf64_Shdr;
350
351 #define EI_MAG0 0 /* e_ident[] indexes */
352 #define EI_MAG1 1
353 #define EI_MAG2 2
354 #define EI_MAG3 3
355 #define EI_CLASS 4
356 #define EI_DATA 5
357 #define EI_VERSION 6
358 #define EI_OSABI 7
359 #define EI_PAD 8
360
361 #define EI_PAX 14
362
363 #define ELFMAG0 0x7f /* EI_MAG */
364 #define ELFMAG1 'E'
365 #define ELFMAG2 'L'
366 #define ELFMAG3 'F'
367 #define ELFMAG "\177ELF"
368 #define SELFMAG 4
369
370 #define ELFCLASSNONE 0 /* EI_CLASS */
371 #define ELFCLASS32 1
372 #define ELFCLASS64 2
373 #define ELFCLASSNUM 3
374
375 #define ELFDATANONE 0 /* e_ident[EI_DATA] */
376 #define ELFDATA2LSB 1
377 #define ELFDATA2MSB 2
378
379 #define EV_NONE 0 /* e_version, EI_VERSION */
380 #define EV_CURRENT 1
381 #define EV_NUM 2
382
383 #define ELFOSABI_NONE 0
384 #define ELFOSABI_LINUX 3
385
386 #ifndef ELF_OSABI
387 #define ELF_OSABI ELFOSABI_NONE
388 #endif
389
390 /*
391 * Notes used in ET_CORE. Architectures export some of the arch register sets
392 * using the corresponding note types via the PTRACE_GETREGSET and
393 * PTRACE_SETREGSET requests.
394 */
395 #define NT_PRSTATUS 1
396 #define NT_PRFPREG 2
397 #define NT_PRPSINFO 3
398 #define NT_TASKSTRUCT 4
399 #define NT_AUXV 6
400 /*
401 * Note to userspace developers: size of NT_SIGINFO note may increase
402 * in the future to accomodate more fields, don't assume it is fixed!
403 */
404 #define NT_SIGINFO 0x53494749
405 #define NT_FILE 0x46494c45
406 #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
407 #define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
408 #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
409 #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
410 #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
411 #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
412 #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
413 #define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
414 #define NT_S390_TIMER 0x301 /* s390 timer register */
415 #define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
416 #define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
417 #define NT_S390_CTRS 0x304 /* s390 control registers */
418 #define NT_S390_PREFIX 0x305 /* s390 prefix register */
419 #define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
420 #define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
421 #define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
422 #define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 upper half */
423 #define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */
424 #define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
425 #define NT_ARM_TLS 0x401 /* ARM TLS register */
426 #define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
427 #define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
428 #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
429 #define NT_METAG_CBUF 0x500 /* Metag catch buffer registers */
430 #define NT_METAG_RPIPE 0x501 /* Metag read pipeline state */
431 #define NT_METAG_TLS 0x502 /* Metag TLS pointer */
432
433
434 /* Note header in a PT_NOTE section */
435 typedef struct elf32_note {
436 Elf32_Word n_namesz; /* Name size */
437 Elf32_Word n_descsz; /* Content size */
438 Elf32_Word n_type; /* Content type */
439 } Elf32_Nhdr;
440
441 /* Note header in a PT_NOTE section */
442 typedef struct elf64_note {
443 Elf64_Word n_namesz; /* Name size */
444 Elf64_Word n_descsz; /* Content size */
445 Elf64_Word n_type; /* Content type */
446 } Elf64_Nhdr;
447
448 #endif /* _UAPI_LINUX_ELF_H */