PageRenderTime 26ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/include/linux/elf.h

http://github.com/JoeyJiao/android-huawei-kernel-common
C Header | 410 lines | 340 code | 51 blank | 19 comment | 1 complexity | d0ed958727f900ec8b1f1d2912dd3c6a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. #ifndef _LINUX_ELF_H
  2. #define _LINUX_ELF_H
  3. #include <linux/types.h>
  4. #include <linux/elf-em.h>
  5. #ifdef __KERNEL__
  6. #include <asm/elf.h>
  7. #endif
  8. struct file;
  9. #ifndef elf_read_implies_exec
  10. /* Executables for which elf_read_implies_exec() returns TRUE will
  11. have the READ_IMPLIES_EXEC personality flag set automatically.
  12. Override in asm/elf.h as needed. */
  13. # define elf_read_implies_exec(ex, have_pt_gnu_stack) 0
  14. #endif
  15. /* 32-bit ELF base types. */
  16. typedef __u32 Elf32_Addr;
  17. typedef __u16 Elf32_Half;
  18. typedef __u32 Elf32_Off;
  19. typedef __s32 Elf32_Sword;
  20. typedef __u32 Elf32_Word;
  21. /* 64-bit ELF base types. */
  22. typedef __u64 Elf64_Addr;
  23. typedef __u16 Elf64_Half;
  24. typedef __s16 Elf64_SHalf;
  25. typedef __u64 Elf64_Off;
  26. typedef __s32 Elf64_Sword;
  27. typedef __u32 Elf64_Word;
  28. typedef __u64 Elf64_Xword;
  29. typedef __s64 Elf64_Sxword;
  30. /* These constants are for the segment types stored in the image headers */
  31. #define PT_NULL 0
  32. #define PT_LOAD 1
  33. #define PT_DYNAMIC 2
  34. #define PT_INTERP 3
  35. #define PT_NOTE 4
  36. #define PT_SHLIB 5
  37. #define PT_PHDR 6
  38. #define PT_TLS 7 /* Thread local storage segment */
  39. #define PT_LOOS 0x60000000 /* OS-specific */
  40. #define PT_HIOS 0x6fffffff /* OS-specific */
  41. #define PT_LOPROC 0x70000000
  42. #define PT_HIPROC 0x7fffffff
  43. #define PT_GNU_EH_FRAME 0x6474e550
  44. #define PT_GNU_STACK (PT_LOOS + 0x474e551)
  45. /* These constants define the different elf file types */
  46. #define ET_NONE 0
  47. #define ET_REL 1
  48. #define ET_EXEC 2
  49. #define ET_DYN 3
  50. #define ET_CORE 4
  51. #define ET_LOPROC 0xff00
  52. #define ET_HIPROC 0xffff
  53. /* This is the info that is needed to parse the dynamic section of the file */
  54. #define DT_NULL 0
  55. #define DT_NEEDED 1
  56. #define DT_PLTRELSZ 2
  57. #define DT_PLTGOT 3
  58. #define DT_HASH 4
  59. #define DT_STRTAB 5
  60. #define DT_SYMTAB 6
  61. #define DT_RELA 7
  62. #define DT_RELASZ 8
  63. #define DT_RELAENT 9
  64. #define DT_STRSZ 10
  65. #define DT_SYMENT 11
  66. #define DT_INIT 12
  67. #define DT_FINI 13
  68. #define DT_SONAME 14
  69. #define DT_RPATH 15
  70. #define DT_SYMBOLIC 16
  71. #define DT_REL 17
  72. #define DT_RELSZ 18
  73. #define DT_RELENT 19
  74. #define DT_PLTREL 20
  75. #define DT_DEBUG 21
  76. #define DT_TEXTREL 22
  77. #define DT_JMPREL 23
  78. #define DT_ENCODING 32
  79. #define OLD_DT_LOOS 0x60000000
  80. #define DT_LOOS 0x6000000d
  81. #define DT_HIOS 0x6ffff000
  82. #define DT_VALRNGLO 0x6ffffd00
  83. #define DT_VALRNGHI 0x6ffffdff
  84. #define DT_ADDRRNGLO 0x6ffffe00
  85. #define DT_ADDRRNGHI 0x6ffffeff
  86. #define DT_VERSYM 0x6ffffff0
  87. #define DT_RELACOUNT 0x6ffffff9
  88. #define DT_RELCOUNT 0x6ffffffa
  89. #define DT_FLAGS_1 0x6ffffffb
  90. #define DT_VERDEF 0x6ffffffc
  91. #define DT_VERDEFNUM 0x6ffffffd
  92. #define DT_VERNEED 0x6ffffffe
  93. #define DT_VERNEEDNUM 0x6fffffff
  94. #define OLD_DT_HIOS 0x6fffffff
  95. #define DT_LOPROC 0x70000000
  96. #define DT_HIPROC 0x7fffffff
  97. /* This info is needed when parsing the symbol table */
  98. #define STB_LOCAL 0
  99. #define STB_GLOBAL 1
  100. #define STB_WEAK 2
  101. #define STT_NOTYPE 0
  102. #define STT_OBJECT 1
  103. #define STT_FUNC 2
  104. #define STT_SECTION 3
  105. #define STT_FILE 4
  106. #define STT_COMMON 5
  107. #define STT_TLS 6
  108. #define ELF_ST_BIND(x) ((x) >> 4)
  109. #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
  110. #define ELF32_ST_BIND(x) ELF_ST_BIND(x)
  111. #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
  112. #define ELF64_ST_BIND(x) ELF_ST_BIND(x)
  113. #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
  114. typedef struct dynamic{
  115. Elf32_Sword d_tag;
  116. union{
  117. Elf32_Sword d_val;
  118. Elf32_Addr d_ptr;
  119. } d_un;
  120. } Elf32_Dyn;
  121. typedef struct {
  122. Elf64_Sxword d_tag; /* entry tag value */
  123. union {
  124. Elf64_Xword d_val;
  125. Elf64_Addr d_ptr;
  126. } d_un;
  127. } Elf64_Dyn;
  128. /* The following are used with relocations */
  129. #define ELF32_R_SYM(x) ((x) >> 8)
  130. #define ELF32_R_TYPE(x) ((x) & 0xff)
  131. #define ELF64_R_SYM(i) ((i) >> 32)
  132. #define ELF64_R_TYPE(i) ((i) & 0xffffffff)
  133. typedef struct elf32_rel {
  134. Elf32_Addr r_offset;
  135. Elf32_Word r_info;
  136. } Elf32_Rel;
  137. typedef struct elf64_rel {
  138. Elf64_Addr r_offset; /* Location at which to apply the action */
  139. Elf64_Xword r_info; /* index and type of relocation */
  140. } Elf64_Rel;
  141. typedef struct elf32_rela{
  142. Elf32_Addr r_offset;
  143. Elf32_Word r_info;
  144. Elf32_Sword r_addend;
  145. } Elf32_Rela;
  146. typedef struct elf64_rela {
  147. Elf64_Addr r_offset; /* Location at which to apply the action */
  148. Elf64_Xword r_info; /* index and type of relocation */
  149. Elf64_Sxword r_addend; /* Constant addend used to compute value */
  150. } Elf64_Rela;
  151. typedef struct elf32_sym{
  152. Elf32_Word st_name;
  153. Elf32_Addr st_value;
  154. Elf32_Word st_size;
  155. unsigned char st_info;
  156. unsigned char st_other;
  157. Elf32_Half st_shndx;
  158. } Elf32_Sym;
  159. typedef struct elf64_sym {
  160. Elf64_Word st_name; /* Symbol name, index in string tbl */
  161. unsigned char st_info; /* Type and binding attributes */
  162. unsigned char st_other; /* No defined meaning, 0 */
  163. Elf64_Half st_shndx; /* Associated section index */
  164. Elf64_Addr st_value; /* Value of the symbol */
  165. Elf64_Xword st_size; /* Associated symbol size */
  166. } Elf64_Sym;
  167. #define EI_NIDENT 16
  168. typedef struct elf32_hdr{
  169. unsigned char e_ident[EI_NIDENT];
  170. Elf32_Half e_type;
  171. Elf32_Half e_machine;
  172. Elf32_Word e_version;
  173. Elf32_Addr e_entry; /* Entry point */
  174. Elf32_Off e_phoff;
  175. Elf32_Off e_shoff;
  176. Elf32_Word e_flags;
  177. Elf32_Half e_ehsize;
  178. Elf32_Half e_phentsize;
  179. Elf32_Half e_phnum;
  180. Elf32_Half e_shentsize;
  181. Elf32_Half e_shnum;
  182. Elf32_Half e_shstrndx;
  183. } Elf32_Ehdr;
  184. typedef struct elf64_hdr {
  185. unsigned char e_ident[EI_NIDENT]; /* ELF "magic number" */
  186. Elf64_Half e_type;
  187. Elf64_Half e_machine;
  188. Elf64_Word e_version;
  189. Elf64_Addr e_entry; /* Entry point virtual address */
  190. Elf64_Off e_phoff; /* Program header table file offset */
  191. Elf64_Off e_shoff; /* Section header table file offset */
  192. Elf64_Word e_flags;
  193. Elf64_Half e_ehsize;
  194. Elf64_Half e_phentsize;
  195. Elf64_Half e_phnum;
  196. Elf64_Half e_shentsize;
  197. Elf64_Half e_shnum;
  198. Elf64_Half e_shstrndx;
  199. } Elf64_Ehdr;
  200. /* These constants define the permissions on sections in the program
  201. header, p_flags. */
  202. #define PF_R 0x4
  203. #define PF_W 0x2
  204. #define PF_X 0x1
  205. typedef struct elf32_phdr{
  206. Elf32_Word p_type;
  207. Elf32_Off p_offset;
  208. Elf32_Addr p_vaddr;
  209. Elf32_Addr p_paddr;
  210. Elf32_Word p_filesz;
  211. Elf32_Word p_memsz;
  212. Elf32_Word p_flags;
  213. Elf32_Word p_align;
  214. } Elf32_Phdr;
  215. typedef struct elf64_phdr {
  216. Elf64_Word p_type;
  217. Elf64_Word p_flags;
  218. Elf64_Off p_offset; /* Segment file offset */
  219. Elf64_Addr p_vaddr; /* Segment virtual address */
  220. Elf64_Addr p_paddr; /* Segment physical address */
  221. Elf64_Xword p_filesz; /* Segment size in file */
  222. Elf64_Xword p_memsz; /* Segment size in memory */
  223. Elf64_Xword p_align; /* Segment alignment, file & memory */
  224. } Elf64_Phdr;
  225. /* sh_type */
  226. #define SHT_NULL 0
  227. #define SHT_PROGBITS 1
  228. #define SHT_SYMTAB 2
  229. #define SHT_STRTAB 3
  230. #define SHT_RELA 4
  231. #define SHT_HASH 5
  232. #define SHT_DYNAMIC 6
  233. #define SHT_NOTE 7
  234. #define SHT_NOBITS 8
  235. #define SHT_REL 9
  236. #define SHT_SHLIB 10
  237. #define SHT_DYNSYM 11
  238. #define SHT_NUM 12
  239. #define SHT_LOPROC 0x70000000
  240. #define SHT_HIPROC 0x7fffffff
  241. #define SHT_LOUSER 0x80000000
  242. #define SHT_HIUSER 0xffffffff
  243. /* sh_flags */
  244. #define SHF_WRITE 0x1
  245. #define SHF_ALLOC 0x2
  246. #define SHF_EXECINSTR 0x4
  247. #define SHF_MASKPROC 0xf0000000
  248. /* special section indexes */
  249. #define SHN_UNDEF 0
  250. #define SHN_LORESERVE 0xff00
  251. #define SHN_LOPROC 0xff00
  252. #define SHN_HIPROC 0xff1f
  253. #define SHN_ABS 0xfff1
  254. #define SHN_COMMON 0xfff2
  255. #define SHN_HIRESERVE 0xffff
  256. typedef struct {
  257. Elf32_Word sh_name;
  258. Elf32_Word sh_type;
  259. Elf32_Word sh_flags;
  260. Elf32_Addr sh_addr;
  261. Elf32_Off sh_offset;
  262. Elf32_Word sh_size;
  263. Elf32_Word sh_link;
  264. Elf32_Word sh_info;
  265. Elf32_Word sh_addralign;
  266. Elf32_Word sh_entsize;
  267. } Elf32_Shdr;
  268. typedef struct elf64_shdr {
  269. Elf64_Word sh_name; /* Section name, index in string tbl */
  270. Elf64_Word sh_type; /* Type of section */
  271. Elf64_Xword sh_flags; /* Miscellaneous section attributes */
  272. Elf64_Addr sh_addr; /* Section virtual addr at execution */
  273. Elf64_Off sh_offset; /* Section file offset */
  274. Elf64_Xword sh_size; /* Size of section in bytes */
  275. Elf64_Word sh_link; /* Index of another section */
  276. Elf64_Word sh_info; /* Additional section information */
  277. Elf64_Xword sh_addralign; /* Section alignment */
  278. Elf64_Xword sh_entsize; /* Entry size if section holds table */
  279. } Elf64_Shdr;
  280. #define EI_MAG0 0 /* e_ident[] indexes */
  281. #define EI_MAG1 1
  282. #define EI_MAG2 2
  283. #define EI_MAG3 3
  284. #define EI_CLASS 4
  285. #define EI_DATA 5
  286. #define EI_VERSION 6
  287. #define EI_OSABI 7
  288. #define EI_PAD 8
  289. #define ELFMAG0 0x7f /* EI_MAG */
  290. #define ELFMAG1 'E'
  291. #define ELFMAG2 'L'
  292. #define ELFMAG3 'F'
  293. #define ELFMAG "\177ELF"
  294. #define SELFMAG 4
  295. #define ELFCLASSNONE 0 /* EI_CLASS */
  296. #define ELFCLASS32 1
  297. #define ELFCLASS64 2
  298. #define ELFCLASSNUM 3
  299. #define ELFDATANONE 0 /* e_ident[EI_DATA] */
  300. #define ELFDATA2LSB 1
  301. #define ELFDATA2MSB 2
  302. #define EV_NONE 0 /* e_version, EI_VERSION */
  303. #define EV_CURRENT 1
  304. #define EV_NUM 2
  305. #define ELFOSABI_NONE 0
  306. #define ELFOSABI_LINUX 3
  307. #ifndef ELF_OSABI
  308. #define ELF_OSABI ELFOSABI_NONE
  309. #endif
  310. /* Notes used in ET_CORE */
  311. #define NT_PRSTATUS 1
  312. #define NT_PRFPREG 2
  313. #define NT_PRPSINFO 3
  314. #define NT_TASKSTRUCT 4
  315. #define NT_AUXV 6
  316. #define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
  317. #define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
  318. #define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
  319. #define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
  320. #define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
  321. #define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
  322. #define NT_PRXSTATUS 0x300 /* s390 upper register halves */
  323. /* Note header in a PT_NOTE section */
  324. typedef struct elf32_note {
  325. Elf32_Word n_namesz; /* Name size */
  326. Elf32_Word n_descsz; /* Content size */
  327. Elf32_Word n_type; /* Content type */
  328. } Elf32_Nhdr;
  329. /* Note header in a PT_NOTE section */
  330. typedef struct elf64_note {
  331. Elf64_Word n_namesz; /* Name size */
  332. Elf64_Word n_descsz; /* Content size */
  333. Elf64_Word n_type; /* Content type */
  334. } Elf64_Nhdr;
  335. #ifdef __KERNEL__
  336. #if ELF_CLASS == ELFCLASS32
  337. extern Elf32_Dyn _DYNAMIC [];
  338. #define elfhdr elf32_hdr
  339. #define elf_phdr elf32_phdr
  340. #define elf_note elf32_note
  341. #define elf_addr_t Elf32_Off
  342. #else
  343. extern Elf64_Dyn _DYNAMIC [];
  344. #define elfhdr elf64_hdr
  345. #define elf_phdr elf64_phdr
  346. #define elf_note elf64_note
  347. #define elf_addr_t Elf64_Off
  348. #endif
  349. /* Optional callbacks to write extra ELF notes. */
  350. #ifndef ARCH_HAVE_EXTRA_ELF_NOTES
  351. static inline int elf_coredump_extra_notes_size(void) { return 0; }
  352. static inline int elf_coredump_extra_notes_write(struct file *file,
  353. loff_t *foffset) { return 0; }
  354. #else
  355. extern int elf_coredump_extra_notes_size(void);
  356. extern int elf_coredump_extra_notes_write(struct file *file, loff_t *foffset);
  357. #endif
  358. #endif /* __KERNEL__ */
  359. #endif /* _LINUX_ELF_H */