Dr Andrew Scott G7VAV

My photo
 
June 2025
Mo Tu We Th Fr Sa Su
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6


elf.h
001: #ifndef _LINUX_ELF_H
002: #define _LINUX_ELF_H
003: 
004: #include <linux/types.h>
005: #include <linux/elf-em.h>
006: 
007: struct file;
008: 
009: #ifndef elf_read_implies_exec
010:   /* Executables for which elf_read_implies_exec() returns TRUE will
011:      have the READ_IMPLIES_EXEC personality flag set automatically.
012:      Override in asm/elf.h as needed.  */
013: # define elf_read_implies_exec(ex, have_pt_gnu_stack)   0
014: #endif
015: 
016: /* 32-bit ELF base types. */
017: typedef __u32   Elf32_Addr;
018: typedef __u16   Elf32_Half;
019: typedef __u32   Elf32_Off;
020: typedef __s32   Elf32_Sword;
021: typedef __u32   Elf32_Word;
022: 
023: /* 64-bit ELF base types. */
024: typedef __u64   Elf64_Addr;
025: typedef __u16   Elf64_Half;
026: typedef __s16   Elf64_SHalf;
027: typedef __u64   Elf64_Off;
028: typedef __s32   Elf64_Sword;
029: typedef __u32   Elf64_Word;
030: typedef __u64   Elf64_Xword;
031: typedef __s64   Elf64_Sxword;
032: 
033: /* These constants are for the segment types stored in the image headers */
034: #define PT_NULL    0
035: #define PT_LOAD    1
036: #define PT_DYNAMIC 2
037: #define PT_INTERP  3
038: #define PT_NOTE    4
039: #define PT_SHLIB   5
040: #define PT_PHDR    6
041: #define PT_TLS     7               /* Thread local storage segment */
042: #define PT_LOOS    0x60000000      /* OS-specific */
043: #define PT_HIOS    0x6fffffff      /* OS-specific */
044: #define PT_LOPROC  0x70000000
045: #define PT_HIPROC  0x7fffffff
046: #define PT_GNU_EH_FRAME         0x6474e550
047: 
048: #define PT_GNU_STACK    (PT_LOOS + 0x474e551)
049: 
050: /*
051:  * Extended Numbering
052:  *
053:  * If the real number of program header table entries is larger than
054:  * or equal to PN_XNUM(0xffff), it is set to sh_info field of the
055:  * section header at index 0, and PN_XNUM is set to e_phnum
056:  * field. Otherwise, the section header at index 0 is zero
057:  * initialized, if it exists.
058:  *
059:  * Specifications are available in:
060:  *
061:  * - Sun microsystems: Linker and Libraries.
062:  *   Part No: 817-1984-17, September 2008.
063:  *   URL: http://docs.sun.com/app/docs/doc/817-1984
064:  *
065:  * - System V ABI AMD64 Architecture Processor Supplement
066:  *   Draft Version 0.99.,
067:  *   May 11, 2009.
068:  *   URL: http://www.x86-64.org/
069:  */
070: #define PN_XNUM 0xffff
071: 
072: /* These constants define the different elf file types */
073: #define ET_NONE   0
074: #define ET_REL    1
075: #define ET_EXEC   2
076: #define ET_DYN    3
077: #define ET_CORE   4
078: #define ET_LOPROC 0xff00
079: #define ET_HIPROC 0xffff
080: 
081: /* This is the info that is needed to parse the dynamic section of the file */
082: #define DT_NULL         0
083: #define DT_NEEDED       1
084: #define DT_PLTRELSZ     2
085: #define DT_PLTGOT       3
086: #define DT_HASH         4
087: #define DT_STRTAB       5
088: #define DT_SYMTAB       6
089: #define DT_RELA         7
090: #define DT_RELASZ       8
091: #define DT_RELAENT      9
092: #define DT_STRSZ        10
093: #define DT_SYMENT       11
094: #define DT_INIT         12
095: #define DT_FINI         13
096: #define DT_SONAME       14
097: #define DT_RPATH        15
098: #define DT_SYMBOLIC     16
099: #define DT_REL          17
100: #define DT_RELSZ        18
101: #define DT_RELENT       19
102: #define DT_PLTREL       20
103: #define DT_DEBUG        21
104: #define DT_TEXTREL      22
105: #define DT_JMPREL       23
106: #define DT_ENCODING     32
107: #define OLD_DT_LOOS     0x60000000
108: #define DT_LOOS         0x6000000d
109: #define DT_HIOS         0x6ffff000
110: #define DT_VALRNGLO     0x6ffffd00
111: #define DT_VALRNGHI     0x6ffffdff
112: #define DT_ADDRRNGLO    0x6ffffe00
113: #define DT_ADDRRNGHI    0x6ffffeff
114: #define DT_VERSYM       0x6ffffff0
115: #define DT_RELACOUNT    0x6ffffff9
116: #define DT_RELCOUNT     0x6ffffffa
117: #define DT_FLAGS_1      0x6ffffffb
118: #define DT_VERDEF       0x6ffffffc
119: #define DT_VERDEFNUM    0x6ffffffd
120: #define DT_VERNEED      0x6ffffffe
121: #define DT_VERNEEDNUM   0x6fffffff
122: #define OLD_DT_HIOS     0x6fffffff
123: #define DT_LOPROC       0x70000000
124: #define DT_HIPROC       0x7fffffff
125: 
126: /* This info is needed when parsing the symbol table */
127: #define STB_LOCAL  0
128: #define STB_GLOBAL 1
129: #define STB_WEAK   2
130: 
131: #define STT_NOTYPE  0
132: #define STT_OBJECT  1
133: #define STT_FUNC    2
134: #define STT_SECTION 3
135: #define STT_FILE    4
136: #define STT_COMMON  5
137: #define STT_TLS     6
138: 
139: #define ELF_ST_BIND(x)          ((x) >> 4)
140: #define ELF_ST_TYPE(x)          (((unsigned int) x) & 0xf)
141: #define ELF32_ST_BIND(x)        ELF_ST_BIND(x)
142: #define ELF32_ST_TYPE(x)        ELF_ST_TYPE(x)
143: #define ELF64_ST_BIND(x)        ELF_ST_BIND(x)
144: #define ELF64_ST_TYPE(x)        ELF_ST_TYPE(x)
145: 
146: typedef struct dynamic{
147:   Elf32_Sword d_tag;
148:   union{
149:     Elf32_Sword d_val;
150:     Elf32_Addr  d_ptr;
151:   } d_un;
152: } Elf32_Dyn;
153: 
154: typedef struct {
155:   Elf64_Sxword d_tag;           /* entry tag value */
156:   union {
157:     Elf64_Xword d_val;
158:     Elf64_Addr d_ptr;
159:   } d_un;
160: } Elf64_Dyn;
161: 
162: /* The following are used with relocations */
163: #define ELF32_R_SYM(x) ((x) >> 8)
164: #define ELF32_R_TYPE(x) ((x) & 0xff)
165: 
166: #define ELF64_R_SYM(i)                  ((i) >> 32)
167: #define ELF64_R_TYPE(i)                 ((i) & 0xffffffff)
168: 
169: typedef struct elf32_rel {
170:   Elf32_Addr    r_offset;
171:   Elf32_Word    r_info;
172: } Elf32_Rel;
173: 
174: typedef struct elf64_rel {
175:   Elf64_Addr r_offset;  /* Location at which to apply the action */
176:   Elf64_Xword r_info;   /* index and type of relocation */
177: } Elf64_Rel;
178: 
179: typedef struct elf32_rela{
180:   Elf32_Addr    r_offset;
181:   Elf32_Word    r_info;
182:   Elf32_Sword   r_addend;
183: } Elf32_Rela;
184: 
185: typedef struct elf64_rela {
186:   Elf64_Addr r_offset;  /* Location at which to apply the action */
187:   Elf64_Xword r_info;   /* index and type of relocation */
188:   Elf64_Sxword r_addend;        /* Constant addend used to compute value */
189: } Elf64_Rela;
190: 
191: typedef struct elf32_sym{
192:   Elf32_Word    st_name;
193:   Elf32_Addr    st_value;
194:   Elf32_Word    st_size;
195:   unsigned char st_info;
196:   unsigned char st_other;
197:   Elf32_Half    st_shndx;
198: } Elf32_Sym;
199: 
200: typedef struct elf64_sym {
201:   Elf64_Word st_name;           /* Symbol name, index in string tbl */
202:   unsigned char st_info;        /* Type and binding attributes */
203:   unsigned char st_other;       /* No defined meaning, 0 */
204:   Elf64_Half st_shndx;          /* Associated section index */
205:   Elf64_Addr st_value;          /* Value of the symbol */
206:   Elf64_Xword st_size;          /* Associated symbol size */
207: } Elf64_Sym;
208: 
209: 
210: #define EI_NIDENT       16
211: 
212: typedef struct elf32_hdr{
213:   unsigned char e_ident[EI_NIDENT];
214:   Elf32_Half    e_type;
215:   Elf32_Half    e_machine;
216:   Elf32_Word    e_version;
217:   Elf32_Addr    e_entry;  /* Entry point */
218:   Elf32_Off     e_phoff;
219:   Elf32_Off     e_shoff;
220:   Elf32_Word    e_flags;
221:   Elf32_Half    e_ehsize;
222:   Elf32_Half    e_phentsize;
223:   Elf32_Half    e_phnum;
224:   Elf32_Half    e_shentsize;
225:   Elf32_Half    e_shnum;
226:   Elf32_Half    e_shstrndx;
227: } Elf32_Ehdr;
228: 
229: typedef struct elf64_hdr {
230:   unsigned char e_ident[EI_NIDENT];     /* ELF "magic number" */
231:   Elf64_Half e_type;
232:   Elf64_Half e_machine;
233:   Elf64_Word e_version;
234:   Elf64_Addr e_entry;           /* Entry point virtual address */
235:   Elf64_Off e_phoff;            /* Program header table file offset */
236:   Elf64_Off e_shoff;            /* Section header table file offset */
237:   Elf64_Word e_flags;
238:   Elf64_Half e_ehsize;
239:   Elf64_Half e_phentsize;
240:   Elf64_Half e_phnum;
241:   Elf64_Half e_shentsize;
242:   Elf64_Half e_shnum;
243:   Elf64_Half e_shstrndx;
244: } Elf64_Ehdr;
245: 
246: /* These constants define the permissions on sections in the program
247:    header, p_flags. */
248: #define PF_R            0x4
249: #define PF_W            0x2
250: #define PF_X            0x1
251: 
252: typedef struct elf32_phdr{
253:   Elf32_Word    p_type;
254:   Elf32_Off     p_offset;
255:   Elf32_Addr    p_vaddr;
256:   Elf32_Addr    p_paddr;
257:   Elf32_Word    p_filesz;
258:   Elf32_Word    p_memsz;
259:   Elf32_Word    p_flags;
260:   Elf32_Word    p_align;
261: } Elf32_Phdr;
262: 
263: typedef struct elf64_phdr {
264:   Elf64_Word p_type;
265:   Elf64_Word p_flags;
266:   Elf64_Off p_offset;           /* Segment file offset */
267:   Elf64_Addr p_vaddr;           /* Segment virtual address */
268:   Elf64_Addr p_paddr;           /* Segment physical address */
269:   Elf64_Xword p_filesz;         /* Segment size in file */
270:   Elf64_Xword p_memsz;          /* Segment size in memory */
271:   Elf64_Xword p_align;          /* Segment alignment, file & memory */
272: } Elf64_Phdr;
273: 
274: /* sh_type */
275: #define SHT_NULL        0
276: #define SHT_PROGBITS    1
277: #define SHT_SYMTAB      2
278: #define SHT_STRTAB      3
279: #define SHT_RELA        4
280: #define SHT_HASH        5
281: #define SHT_DYNAMIC     6
282: #define SHT_NOTE        7
283: #define SHT_NOBITS      8
284: #define SHT_REL         9
285: #define SHT_SHLIB       10
286: #define SHT_DYNSYM      11
287: #define SHT_NUM         12
288: #define SHT_LOPROC      0x70000000
289: #define SHT_HIPROC      0x7fffffff
290: #define SHT_LOUSER      0x80000000
291: #define SHT_HIUSER      0xffffffff
292: 
293: /* sh_flags */
294: #define SHF_WRITE       0x1
295: #define SHF_ALLOC       0x2
296: #define SHF_EXECINSTR   0x4
297: #define SHF_MASKPROC    0xf0000000
298: 
299: /* special section indexes */
300: #define SHN_UNDEF       0
301: #define SHN_LORESERVE   0xff00
302: #define SHN_LOPROC      0xff00
303: #define SHN_HIPROC      0xff1f
304: #define SHN_ABS         0xfff1
305: #define SHN_COMMON      0xfff2
306: #define SHN_HIRESERVE   0xffff
307:  
308: typedef struct elf32_shdr {
309:   Elf32_Word    sh_name;
310:   Elf32_Word    sh_type;
311:   Elf32_Word    sh_flags;
312:   Elf32_Addr    sh_addr;
313:   Elf32_Off     sh_offset;
314:   Elf32_Word    sh_size;
315:   Elf32_Word    sh_link;
316:   Elf32_Word    sh_info;
317:   Elf32_Word    sh_addralign;
318:   Elf32_Word    sh_entsize;
319: } Elf32_Shdr;
320: 
321: typedef struct elf64_shdr {
322:   Elf64_Word sh_name;           /* Section name, index in string tbl */
323:   Elf64_Word sh_type;           /* Type of section */
324:   Elf64_Xword sh_flags;         /* Miscellaneous section attributes */
325:   Elf64_Addr sh_addr;           /* Section virtual addr at execution */
326:   Elf64_Off sh_offset;          /* Section file offset */
327:   Elf64_Xword sh_size;          /* Size of section in bytes */
328:   Elf64_Word sh_link;           /* Index of another section */
329:   Elf64_Word sh_info;           /* Additional section information */
330:   Elf64_Xword sh_addralign;     /* Section alignment */
331:   Elf64_Xword sh_entsize;       /* Entry size if section holds table */
332: } Elf64_Shdr;
333: 
334: #define EI_MAG0         0               /* e_ident[] indexes */
335: #define EI_MAG1         1
336: #define EI_MAG2         2
337: #define EI_MAG3         3
338: #define EI_CLASS        4
339: #define EI_DATA         5
340: #define EI_VERSION      6
341: #define EI_OSABI        7
342: #define EI_PAD          8
343: 
344: #define ELFMAG0         0x7f            /* EI_MAG */
345: #define ELFMAG1         'E'
346: #define ELFMAG2         'L'
347: #define ELFMAG3         'F'
348: #define ELFMAG          "\177ELF"
349: #define SELFMAG         4
350: 
351: #define ELFCLASSNONE    0               /* EI_CLASS */
352: #define ELFCLASS32      1
353: #define ELFCLASS64      2
354: #define ELFCLASSNUM     3
355: 
356: #define ELFDATANONE     0               /* e_ident[EI_DATA] */
357: #define ELFDATA2LSB     1
358: #define ELFDATA2MSB     2
359: 
360: #define EV_NONE         0               /* e_version, EI_VERSION */
361: #define EV_CURRENT      1
362: #define EV_NUM          2
363: 
364: #define ELFOSABI_NONE   0
365: #define ELFOSABI_LINUX  3
366: 
367: #ifndef ELF_OSABI
368: #define ELF_OSABI ELFOSABI_NONE
369: #endif
370: 
371: /*
372:  * Notes used in ET_CORE. Architectures export some of the arch register sets
373:  * using the corresponding note types via the PTRACE_GETREGSET and
374:  * PTRACE_SETREGSET requests.
375:  */
376: #define NT_PRSTATUS     1
377: #define NT_PRFPREG      2
378: #define NT_PRPSINFO     3
379: #define NT_TASKSTRUCT   4
380: #define NT_AUXV         6
381: #define NT_PRXFPREG     0x46e62b7f      /* copied from gdb5.1/include/elf/common.h */
382: #define NT_PPC_VMX      0x100           /* PowerPC Altivec/VMX registers */
383: #define NT_PPC_SPE      0x101           /* PowerPC SPE/EVR registers */
384: #define NT_PPC_VSX      0x102           /* PowerPC VSX registers */
385: #define NT_386_TLS      0x200           /* i386 TLS slots (struct user_desc) */
386: #define NT_386_IOPERM   0x201           /* x86 io permission bitmap (1=deny) */
387: #define NT_X86_XSTATE   0x202           /* x86 extended state using xsave */
388: #define NT_S390_HIGH_GPRS       0x300   /* s390 upper register halves */
389: #define NT_S390_TIMER   0x301           /* s390 timer register */
390: #define NT_S390_TODCMP  0x302           /* s390 TOD clock comparator register */
391: #define NT_S390_TODPREG 0x303           /* s390 TOD programmable register */
392: #define NT_S390_CTRS    0x304           /* s390 control registers */
393: #define NT_S390_PREFIX  0x305           /* s390 prefix register */
394: #define NT_S390_LAST_BREAK      0x306   /* s390 breaking event address */
395: #define NT_S390_SYSTEM_CALL     0x307   /* s390 system call restart data */
396: #define NT_ARM_VFP      0x400           /* ARM VFP/NEON registers */
397: 
398: 
399: /* Note header in a PT_NOTE section */
400: typedef struct elf32_note {
401:   Elf32_Word    n_namesz;       /* Name size */
402:   Elf32_Word    n_descsz;       /* Content size */
403:   Elf32_Word    n_type;         /* Content type */
404: } Elf32_Nhdr;
405: 
406: /* Note header in a PT_NOTE section */
407: typedef struct elf64_note {
408:   Elf64_Word n_namesz;  /* Name size */
409:   Elf64_Word n_descsz;  /* Content size */
410:   Elf64_Word n_type;    /* Content type */
411: } Elf64_Nhdr;
412: 
413: #endif /* _LINUX_ELF_H */
414: 


for client (none)
© Andrew Scott 2006 - 2025,
All Rights Reserved
http://www.andrew-scott.uk/
Andrew Scott
http://www.andrew-scott.co.uk/