130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#ifndef _UAPI_LINUX_ELF_H
230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define _UAPI_LINUX_ELF_H
330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#include <linux/types.h>
530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#include <linux/elf-em.h>
630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 32-bit ELF base types. */
830692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u32	Elf32_Addr;
930692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u16	Elf32_Half;
1030692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u32	Elf32_Off;
1130692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __s32	Elf32_Sword;
1230692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u32	Elf32_Word;
1330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
1430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* 64-bit ELF base types. */
1530692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u64	Elf64_Addr;
1630692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u16	Elf64_Half;
1730692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __s16	Elf64_SHalf;
1830692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u64	Elf64_Off;
1930692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __s32	Elf64_Sword;
2030692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u32	Elf64_Word;
2130692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __u64	Elf64_Xword;
2230692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef __s64	Elf64_Sxword;
2330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
2430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* These constants are for the segment types stored in the image headers */
2530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_NULL    0
2630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_LOAD    1
2730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_DYNAMIC 2
2830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_INTERP  3
2930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_NOTE    4
3030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_SHLIB   5
3130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_PHDR    6
3230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_TLS     7               /* Thread local storage segment */
3330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_LOOS    0x60000000      /* OS-specific */
3430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_HIOS    0x6fffffff      /* OS-specific */
3530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_LOPROC  0x70000000
3630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_HIPROC  0x7fffffff
3730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_GNU_EH_FRAME		0x6474e550
3830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
3930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PT_GNU_STACK	(PT_LOOS + 0x474e551)
4030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
4130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
4230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Extended Numbering
4330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
4430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * If the real number of program header table entries is larger than
4530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * or equal to PN_XNUM(0xffff), it is set to sh_info field of the
4630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * section header at index 0, and PN_XNUM is set to e_phnum
4730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * field. Otherwise, the section header at index 0 is zero
4830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * initialized, if it exists.
4930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
5030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Specifications are available in:
5130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
5230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * - Oracle: Linker and Libraries.
5330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   Part No: 817–1984–19, August 2011.
5430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   http://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf
5530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *
5630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * - System V ABI AMD64 Architecture Processor Supplement
5730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   Draft Version 0.99.4,
5830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   January 13, 2010.
5930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng *   http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf
6030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
6130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PN_XNUM 0xffff
6230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
6330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* These constants define the different elf file types */
6430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ET_NONE   0
6530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ET_REL    1
6630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ET_EXEC   2
6730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ET_DYN    3
6830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ET_CORE   4
6930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ET_LOPROC 0xff00
7030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ET_HIPROC 0xffff
7130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
7230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* This is the info that is needed to parse the dynamic section of the file */
7330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_NULL		0
7430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_NEEDED	1
7530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_PLTRELSZ	2
7630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_PLTGOT	3
7730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_HASH		4
7830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_STRTAB	5
7930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_SYMTAB	6
8030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RELA		7
8130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RELASZ	8
8230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RELAENT	9
8330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_STRSZ	10
8430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_SYMENT	11
8530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_INIT		12
8630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_FINI		13
8730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_SONAME	14
8830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RPATH 	15
8930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_SYMBOLIC	16
9030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_REL	        17
9130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RELSZ	18
9230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RELENT	19
9330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_PLTREL	20
9430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_DEBUG	21
9530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_TEXTREL	22
9630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_JMPREL	23
9730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_ENCODING	32
9830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define OLD_DT_LOOS	0x60000000
9930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_LOOS		0x6000000d
10030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_HIOS		0x6ffff000
10130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_VALRNGLO	0x6ffffd00
10230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_VALRNGHI	0x6ffffdff
10330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_ADDRRNGLO	0x6ffffe00
10430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_ADDRRNGHI	0x6ffffeff
10530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_VERSYM	0x6ffffff0
10630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RELACOUNT	0x6ffffff9
10730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_RELCOUNT	0x6ffffffa
10830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_FLAGS_1	0x6ffffffb
10930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_VERDEF	0x6ffffffc
11030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	DT_VERDEFNUM	0x6ffffffd
11130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_VERNEED	0x6ffffffe
11230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	DT_VERNEEDNUM	0x6fffffff
11330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define OLD_DT_HIOS     0x6fffffff
11430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_LOPROC	0x70000000
11530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define DT_HIPROC	0x7fffffff
11630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
11730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* This info is needed when parsing the symbol table */
11830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STB_LOCAL  0
11930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STB_GLOBAL 1
12030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STB_WEAK   2
12130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
12230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STT_NOTYPE  0
12330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STT_OBJECT  1
12430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STT_FUNC    2
12530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STT_SECTION 3
12630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STT_FILE    4
12730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STT_COMMON  5
12830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define STT_TLS     6
12930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
13030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF_ST_BIND(x)		((x) >> 4)
13130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF_ST_TYPE(x)		(((unsigned int) x) & 0xf)
13230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF32_ST_BIND(x)	ELF_ST_BIND(x)
13330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF32_ST_TYPE(x)	ELF_ST_TYPE(x)
13430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF64_ST_BIND(x)	ELF_ST_BIND(x)
13530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF64_ST_TYPE(x)	ELF_ST_TYPE(x)
13630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
13730692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct dynamic{
13830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Sword d_tag;
13930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  union{
14030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng    Elf32_Sword	d_val;
14130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng    Elf32_Addr	d_ptr;
14230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  } d_un;
14330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Dyn;
14430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
14530692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct {
14630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Sxword d_tag;		/* entry tag value */
14730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  union {
14830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng    Elf64_Xword d_val;
14930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng    Elf64_Addr d_ptr;
15030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  } d_un;
15130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Dyn;
15230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
15330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* The following are used with relocations */
15430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF32_R_SYM(x) ((x) >> 8)
15530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF32_R_TYPE(x) ((x) & 0xff)
15630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
15730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF64_R_SYM(i)			((i) >> 32)
15830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF64_R_TYPE(i)			((i) & 0xffffffff)
15930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
16030692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf32_rel {
16130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Addr	r_offset;
16230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	r_info;
16330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Rel;
16430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
16530692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf64_rel {
16630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Addr r_offset;	/* Location at which to apply the action */
16730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword r_info;	/* index and type of relocation */
16830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Rel;
16930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
17030692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf32_rela{
17130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Addr	r_offset;
17230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	r_info;
17330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Sword	r_addend;
17430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Rela;
17530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
17630692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf64_rela {
17730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Addr r_offset;	/* Location at which to apply the action */
17830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword r_info;	/* index and type of relocation */
17930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Sxword r_addend;	/* Constant addend used to compute value */
18030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Rela;
18130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
18230692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf32_sym{
18330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	st_name;
18430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Addr	st_value;
18530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	st_size;
18630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  unsigned char	st_info;
18730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  unsigned char	st_other;
18830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	st_shndx;
18930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Sym;
19030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
19130692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf64_sym {
19230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word st_name;		/* Symbol name, index in string tbl */
19330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  unsigned char	st_info;	/* Type and binding attributes */
19430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  unsigned char	st_other;	/* No defined meaning, 0 */
19530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half st_shndx;		/* Associated section index */
19630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Addr st_value;		/* Value of the symbol */
19730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword st_size;		/* Associated symbol size */
19830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Sym;
19930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
20030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
20130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define EI_NIDENT	16
20230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
20330692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf32_hdr{
20430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  unsigned char	e_ident[EI_NIDENT];
20530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_type;
20630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_machine;
20730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	e_version;
20830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Addr	e_entry;  /* Entry point */
20930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Off	e_phoff;
21030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Off	e_shoff;
21130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	e_flags;
21230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_ehsize;
21330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_phentsize;
21430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_phnum;
21530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_shentsize;
21630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_shnum;
21730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Half	e_shstrndx;
21830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Ehdr;
21930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
22030692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf64_hdr {
22130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  unsigned char	e_ident[EI_NIDENT];	/* ELF "magic number" */
22230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_type;
22330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_machine;
22430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word e_version;
22530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Addr e_entry;		/* Entry point virtual address */
22630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Off e_phoff;		/* Program header table file offset */
22730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Off e_shoff;		/* Section header table file offset */
22830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word e_flags;
22930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_ehsize;
23030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_phentsize;
23130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_phnum;
23230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_shentsize;
23330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_shnum;
23430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Half e_shstrndx;
23530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Ehdr;
23630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
23730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* These constants define the permissions on sections in the program
23830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng   header, p_flags. */
23930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PF_R		0x4
24030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PF_W		0x2
24130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define PF_X		0x1
24230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
24330692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf32_phdr{
24430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	p_type;
24530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Off	p_offset;
24630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Addr	p_vaddr;
24730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Addr	p_paddr;
24830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	p_filesz;
24930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	p_memsz;
25030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	p_flags;
25130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	p_align;
25230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Phdr;
25330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
25430692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf64_phdr {
25530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word p_type;
25630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word p_flags;
25730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Off p_offset;		/* Segment file offset */
25830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Addr p_vaddr;		/* Segment virtual address */
25930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Addr p_paddr;		/* Segment physical address */
26030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword p_filesz;		/* Segment size in file */
26130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword p_memsz;		/* Segment size in memory */
26230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword p_align;		/* Segment alignment, file & memory */
26330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Phdr;
26430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
26530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* sh_type */
26630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_NULL	0
26730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_PROGBITS	1
26830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_SYMTAB	2
26930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_STRTAB	3
27030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_RELA	4
27130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_HASH	5
27230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_DYNAMIC	6
27330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_NOTE	7
27430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_NOBITS	8
27530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_REL		9
27630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_SHLIB	10
27730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_DYNSYM	11
27830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_NUM		12
27930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_LOPROC	0x70000000
28030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_HIPROC	0x7fffffff
28130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_LOUSER	0x80000000
28230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHT_HIUSER	0xffffffff
28330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
28430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* sh_flags */
28530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHF_WRITE	0x1
28630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHF_ALLOC	0x2
28730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHF_EXECINSTR	0x4
28830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHF_MASKPROC	0xf0000000
28930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
29030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* special section indexes */
29130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHN_UNDEF	0
29230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHN_LORESERVE	0xff00
29330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHN_LOPROC	0xff00
29430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHN_HIPROC	0xff1f
29530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHN_ABS		0xfff1
29630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHN_COMMON	0xfff2
29730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define SHN_HIRESERVE	0xffff
29830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
29930692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf32_shdr {
30030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_name;
30130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_type;
30230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_flags;
30330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Addr	sh_addr;
30430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Off	sh_offset;
30530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_size;
30630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_link;
30730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_info;
30830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_addralign;
30930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	sh_entsize;
31030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Shdr;
31130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
31230692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf64_shdr {
31330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word sh_name;		/* Section name, index in string tbl */
31430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word sh_type;		/* Type of section */
31530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword sh_flags;		/* Miscellaneous section attributes */
31630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Addr sh_addr;		/* Section virtual addr at execution */
31730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Off sh_offset;		/* Section file offset */
31830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword sh_size;		/* Size of section in bytes */
31930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word sh_link;		/* Index of another section */
32030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word sh_info;		/* Additional section information */
32130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword sh_addralign;	/* Section alignment */
32230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Xword sh_entsize;	/* Entry size if section holds table */
32330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Shdr;
32430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
32530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_MAG0		0		/* e_ident[] indexes */
32630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_MAG1		1
32730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_MAG2		2
32830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_MAG3		3
32930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_CLASS	4
33030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_DATA		5
33130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_VERSION	6
33230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_OSABI	7
33330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	EI_PAD		8
33430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
33530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFMAG0		0x7f		/* EI_MAG */
33630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFMAG1		'E'
33730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFMAG2		'L'
33830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFMAG3		'F'
33930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFMAG		"\177ELF"
34030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	SELFMAG		4
34130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
34230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFCLASSNONE	0		/* EI_CLASS */
34330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFCLASS32	1
34430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFCLASS64	2
34530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define	ELFCLASSNUM	3
34630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
34730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELFDATANONE	0		/* e_ident[EI_DATA] */
34830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELFDATA2LSB	1
34930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELFDATA2MSB	2
35030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
35130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define EV_NONE		0		/* e_version, EI_VERSION */
35230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define EV_CURRENT	1
35330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define EV_NUM		2
35430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
35530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELFOSABI_NONE	0
35630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELFOSABI_LINUX	3
35730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
35830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#ifndef ELF_OSABI
35930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define ELF_OSABI ELFOSABI_NONE
36030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#endif
36130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
36230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
36330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Notes used in ET_CORE. Architectures export some of the arch register sets
36430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * using the corresponding note types via the PTRACE_GETREGSET and
36530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * PTRACE_SETREGSET requests.
36630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
36730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_PRSTATUS	1
36830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_PRFPREG	2
36930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_PRPSINFO	3
37030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_TASKSTRUCT	4
37130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_AUXV		6
37230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/*
37330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * Note to userspace developers: size of NT_SIGINFO note may increase
37430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng * in the future to accomodate more fields, don't assume it is fixed!
37530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng */
37630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_SIGINFO      0x53494749
37730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_FILE         0x46494c45
37830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_PRXFPREG     0x46e62b7f      /* copied from gdb5.1/include/elf/common.h */
37930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_PPC_VMX	0x100		/* PowerPC Altivec/VMX registers */
38030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_PPC_SPE	0x101		/* PowerPC SPE/EVR registers */
38130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_PPC_VSX	0x102		/* PowerPC VSX registers */
38230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_386_TLS	0x200		/* i386 TLS slots (struct user_desc) */
38330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_386_IOPERM	0x201		/* x86 io permission bitmap (1=deny) */
38430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_X86_XSTATE	0x202		/* x86 extended state using xsave */
38530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_HIGH_GPRS	0x300	/* s390 upper register halves */
38630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_TIMER	0x301		/* s390 timer register */
38730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_TODCMP	0x302		/* s390 TOD clock comparator register */
38830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_TODPREG	0x303		/* s390 TOD programmable register */
38930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_CTRS	0x304		/* s390 control registers */
39030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_PREFIX	0x305		/* s390 prefix register */
39130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_LAST_BREAK	0x306	/* s390 breaking event address */
39230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_SYSTEM_CALL	0x307	/* s390 system call restart data */
39330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_S390_TDB	0x308		/* s390 transaction diagnostic block */
39430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_ARM_VFP	0x400		/* ARM VFP/NEON registers */
39530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_ARM_TLS	0x401		/* ARM TLS register */
39630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_ARM_HW_BREAK	0x402		/* ARM hardware breakpoint registers */
39730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_ARM_HW_WATCH	0x403		/* ARM hardware watchpoint registers */
39830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_METAG_CBUF	0x500		/* Metag catch buffer registers */
39930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_METAG_RPIPE	0x501		/* Metag read pipeline state */
40030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#define NT_METAG_TLS	0x502		/* Metag TLS pointer */
40130692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
40230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
40330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Note header in a PT_NOTE section */
40430692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf32_note {
40530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	n_namesz;	/* Name size */
40630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	n_descsz;	/* Content size */
40730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf32_Word	n_type;		/* Content type */
40830692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf32_Nhdr;
40930692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
41030692c65c4174412c90e79489e98ab85c1a7412fBen Cheng/* Note header in a PT_NOTE section */
41130692c65c4174412c90e79489e98ab85c1a7412fBen Chengtypedef struct elf64_note {
41230692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word n_namesz;	/* Name size */
41330692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word n_descsz;	/* Content size */
41430692c65c4174412c90e79489e98ab85c1a7412fBen Cheng  Elf64_Word n_type;	/* Content type */
41530692c65c4174412c90e79489e98ab85c1a7412fBen Cheng} Elf64_Nhdr;
41630692c65c4174412c90e79489e98ab85c1a7412fBen Cheng
41730692c65c4174412c90e79489e98ab85c1a7412fBen Cheng#endif /* _UAPI_LINUX_ELF_H */
418