1 /**************************************************************************** 2 **************************************************************************** 3 *** 4 *** This header was automatically generated from a Linux kernel header 5 *** of the same name, to make information necessary for userspace to 6 *** call into the kernel available to libc. It contains only constants, 7 *** structures, and macros generated from the original header, and thus, 8 *** contains no copyrightable information. 9 *** 10 **************************************************************************** 11 ****************************************************************************/ 12 #ifndef _LINUX_ELF_H 13 #define _LINUX_ELF_H 14 15 #include <stdint.h> 16 17 #ifndef elf_read_implies_exec 18 #define elf_read_implies_exec(ex, have_pt_gnu_stack) 0 19 #endif 20 21 typedef uint32_t Elf32_Addr; 22 typedef uint16_t Elf32_Half; 23 typedef uint32_t Elf32_Off; 24 typedef int32_t Elf32_Sword; 25 typedef uint32_t Elf32_Word; 26 27 typedef uint64_t Elf64_Addr; 28 typedef uint16_t Elf64_Half; 29 typedef int16_t Elf64_SHalf; 30 typedef uint64_t Elf64_Off; 31 typedef int32_t Elf64_Sword; 32 typedef uint32_t Elf64_Word; 33 typedef uint64_t Elf64_Xword; 34 typedef int64_t Elf64_Sxword; 35 36 #define PT_NULL 0 37 #define PT_LOAD 1 38 #define PT_DYNAMIC 2 39 #define PT_INTERP 3 40 #define PT_NOTE 4 41 #define PT_SHLIB 5 42 #define PT_PHDR 6 43 #define PT_TLS 7 44 #define PT_LOOS 0x60000000 45 #define PT_HIOS 0x6fffffff 46 #define PT_LOPROC 0x70000000 47 #define PT_HIPROC 0x7fffffff 48 #define PT_GNU_EH_FRAME 0x6474e550 49 50 #define PT_GNU_STACK (PT_LOOS + 0x474e551) 51 52 #define ET_NONE 0 53 #define ET_REL 1 54 #define ET_EXEC 2 55 #define ET_DYN 3 56 #define ET_CORE 4 57 #define ET_LOPROC 0xff00 58 #define ET_HIPROC 0xffff 59 60 #define DT_NULL 0 61 #define DT_NEEDED 1 62 #define DT_PLTRELSZ 2 63 #define DT_PLTGOT 3 64 #define DT_HASH 4 65 #define DT_STRTAB 5 66 #define DT_SYMTAB 6 67 #define DT_RELA 7 68 #define DT_RELASZ 8 69 #define DT_RELAENT 9 70 #define DT_STRSZ 10 71 #define DT_SYMENT 11 72 #define DT_INIT 12 73 #define DT_FINI 13 74 #define DT_SONAME 14 75 #define DT_RPATH 15 76 #define DT_SYMBOLIC 16 77 #define DT_REL 17 78 #define DT_RELSZ 18 79 #define DT_RELENT 19 80 #define DT_PLTREL 20 81 #define DT_DEBUG 21 82 #define DT_TEXTREL 22 83 #define DT_JMPREL 23 84 #define DT_LOPROC 0x70000000 85 #define DT_HIPROC 0x7fffffff 86 87 #define STB_LOCAL 0 88 #define STB_GLOBAL 1 89 #define STB_WEAK 2 90 91 #define STT_NOTYPE 0 92 #define STT_OBJECT 1 93 #define STT_FUNC 2 94 #define STT_SECTION 3 95 #define STT_FILE 4 96 #define STT_COMMON 5 97 #define STT_TLS 6 98 99 #define ELF_ST_BIND(x) ((x) >> 4) 100 #define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf) 101 #define ELF32_ST_BIND(x) ELF_ST_BIND(x) 102 #define ELF32_ST_TYPE(x) ELF_ST_TYPE(x) 103 #define ELF64_ST_BIND(x) ELF_ST_BIND(x) 104 #define ELF64_ST_TYPE(x) ELF_ST_TYPE(x) 105 106 typedef struct dynamic{ 107 Elf32_Sword d_tag; 108 union{ 109 Elf32_Sword d_val; 110 Elf32_Addr d_ptr; 111 } d_un; 112 } Elf32_Dyn; 113 114 typedef struct { 115 Elf64_Sxword d_tag; 116 union { 117 Elf64_Xword d_val; 118 Elf64_Addr d_ptr; 119 } d_un; 120 } Elf64_Dyn; 121 122 #define ELF32_R_SYM(x) ((x) >> 8) 123 #define ELF32_R_TYPE(x) ((x) & 0xff) 124 125 #define ELF64_R_SYM(i) ((i) >> 32) 126 #define ELF64_R_TYPE(i) ((i) & 0xffffffff) 127 128 typedef struct elf32_rel { 129 Elf32_Addr r_offset; 130 Elf32_Word r_info; 131 } Elf32_Rel; 132 133 typedef struct elf64_rel { 134 Elf64_Addr r_offset; 135 Elf64_Xword r_info; 136 } Elf64_Rel; 137 138 typedef struct elf32_rela{ 139 Elf32_Addr r_offset; 140 Elf32_Word r_info; 141 Elf32_Sword r_addend; 142 } Elf32_Rela; 143 144 typedef struct elf64_rela { 145 Elf64_Addr r_offset; 146 Elf64_Xword r_info; 147 Elf64_Sxword r_addend; 148 } Elf64_Rela; 149 150 typedef struct elf32_sym{ 151 Elf32_Word st_name; 152 Elf32_Addr st_value; 153 Elf32_Word st_size; 154 unsigned char st_info; 155 unsigned char st_other; 156 Elf32_Half st_shndx; 157 } Elf32_Sym; 158 159 typedef struct elf64_sym { 160 Elf64_Word st_name; 161 unsigned char st_info; 162 unsigned char st_other; 163 Elf64_Half st_shndx; 164 Elf64_Addr st_value; 165 Elf64_Xword st_size; 166 } Elf64_Sym; 167 168 #define EI_NIDENT 16 169 170 typedef struct elf32_hdr{ 171 unsigned char e_ident[EI_NIDENT]; 172 Elf32_Half e_type; 173 Elf32_Half e_machine; 174 Elf32_Word e_version; 175 Elf32_Addr e_entry; 176 Elf32_Off e_phoff; 177 Elf32_Off e_shoff; 178 Elf32_Word e_flags; 179 Elf32_Half e_ehsize; 180 Elf32_Half e_phentsize; 181 Elf32_Half e_phnum; 182 Elf32_Half e_shentsize; 183 Elf32_Half e_shnum; 184 Elf32_Half e_shstrndx; 185 } Elf32_Ehdr; 186 187 typedef struct elf64_hdr { 188 unsigned char e_ident[16]; 189 Elf64_Half e_type; 190 Elf64_Half e_machine; 191 Elf64_Word e_version; 192 Elf64_Addr e_entry; 193 Elf64_Off e_phoff; 194 Elf64_Off e_shoff; 195 Elf64_Word e_flags; 196 Elf64_Half e_ehsize; 197 Elf64_Half e_phentsize; 198 Elf64_Half e_phnum; 199 Elf64_Half e_shentsize; 200 Elf64_Half e_shnum; 201 Elf64_Half e_shstrndx; 202 } Elf64_Ehdr; 203 204 #define PF_R 0x4 205 #define PF_W 0x2 206 #define PF_X 0x1 207 208 typedef struct elf32_phdr{ 209 Elf32_Word p_type; 210 Elf32_Off p_offset; 211 Elf32_Addr p_vaddr; 212 Elf32_Addr p_paddr; 213 Elf32_Word p_filesz; 214 Elf32_Word p_memsz; 215 Elf32_Word p_flags; 216 Elf32_Word p_align; 217 } Elf32_Phdr; 218 219 typedef struct elf64_phdr { 220 Elf64_Word p_type; 221 Elf64_Word p_flags; 222 Elf64_Off p_offset; 223 Elf64_Addr p_vaddr; 224 Elf64_Addr p_paddr; 225 Elf64_Xword p_filesz; 226 Elf64_Xword p_memsz; 227 Elf64_Xword p_align; 228 } Elf64_Phdr; 229 230 #define SHT_NULL 0 231 #define SHT_PROGBITS 1 232 #define SHT_SYMTAB 2 233 #define SHT_STRTAB 3 234 #define SHT_RELA 4 235 #define SHT_HASH 5 236 #define SHT_DYNAMIC 6 237 #define SHT_NOTE 7 238 #define SHT_NOBITS 8 239 #define SHT_REL 9 240 #define SHT_SHLIB 10 241 #define SHT_DYNSYM 11 242 #define SHT_NUM 12 243 #define SHT_LOPROC 0x70000000 244 #define SHT_HIPROC 0x7fffffff 245 #define SHT_LOUSER 0x80000000 246 #define SHT_HIUSER 0xffffffff 247 248 #define SHF_WRITE 0x1 249 #define SHF_ALLOC 0x2 250 #define SHF_EXECINSTR 0x4 251 #define SHF_MASKPROC 0xf0000000 252 253 #define SHN_UNDEF 0 254 #define SHN_LORESERVE 0xff00 255 #define SHN_LOPROC 0xff00 256 #define SHN_HIPROC 0xff1f 257 #define SHN_ABS 0xfff1 258 #define SHN_COMMON 0xfff2 259 #define SHN_HIRESERVE 0xffff 260 261 typedef struct elf32_shdr{ 262 Elf32_Word sh_name; 263 Elf32_Word sh_type; 264 Elf32_Word sh_flags; 265 Elf32_Addr sh_addr; 266 Elf32_Off sh_offset; 267 Elf32_Word sh_size; 268 Elf32_Word sh_link; 269 Elf32_Word sh_info; 270 Elf32_Word sh_addralign; 271 Elf32_Word sh_entsize; 272 } Elf32_Shdr; 273 274 typedef struct elf64_shdr { 275 Elf64_Word sh_name; 276 Elf64_Word sh_type; 277 Elf64_Xword sh_flags; 278 Elf64_Addr sh_addr; 279 Elf64_Off sh_offset; 280 Elf64_Xword sh_size; 281 Elf64_Word sh_link; 282 Elf64_Word sh_info; 283 Elf64_Xword sh_addralign; 284 Elf64_Xword sh_entsize; 285 } Elf64_Shdr; 286 287 #define EI_MAG0 0 288 #define EI_MAG1 1 289 #define EI_MAG2 2 290 #define EI_MAG3 3 291 #define EI_CLASS 4 292 #define EI_DATA 5 293 #define EI_VERSION 6 294 #define EI_OSABI 7 295 #define EI_PAD 8 296 297 #define ELFMAG0 0x7f 298 #define ELFMAG1 'E' 299 #define ELFMAG2 'L' 300 #define ELFMAG3 'F' 301 #define ELFMAG "\177ELF" 302 #define SELFMAG 4 303 304 #define ELFCLASSNONE 0 305 #define ELFCLASS32 1 306 #define ELFCLASS64 2 307 #define ELFCLASSNUM 3 308 309 #define ELFDATANONE 0 310 #define ELFDATA2LSB 1 311 #define ELFDATA2MSB 2 312 313 #define EV_NONE 0 314 #define EV_CURRENT 1 315 #define EV_NUM 2 316 317 #define ELFOSABI_NONE 0 318 #define ELFOSABI_LINUX 3 319 320 #ifndef ELF_OSABI 321 #define ELF_OSABI ELFOSABI_NONE 322 #endif 323 324 #define NT_PRSTATUS 1 325 #define NT_PRFPREG 2 326 #define NT_PRPSINFO 3 327 #define NT_TASKSTRUCT 4 328 #define NT_AUXV 6 329 #define NT_PRXFPREG 0x46e62b7f 330 331 typedef struct elf32_note { 332 Elf32_Word n_namesz; 333 Elf32_Word n_descsz; 334 Elf32_Word n_type; 335 } Elf32_Nhdr; 336 337 typedef struct elf64_note { 338 Elf64_Word n_namesz; 339 Elf64_Word n_descsz; 340 Elf64_Word n_type; 341 } Elf64_Nhdr; 342 343 #if ELF_CLASS == ELFCLASS32 344 345 #define elfhdr Elf32_Ehdr 346 #define elf_phdr Elf32_Phdr 347 #define elf_note Elf32_Nhdr 348 #define elf_shdr Elf32_Shdr 349 350 #else 351 352 #define elfhdr Elf64_Ehdr 353 #define elf_phdr Elf64_Phdr 354 #define elf_note Elf64_Nhdr 355 #define elf_shdr Elf64_Shdr 356 357 #endif 358 359 #endif 360