FireSync API
 All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kElf.h
Go to the documentation of this file.
1 
8 #ifndef K_FIRESYNC_ELF_H
9 #define K_FIRESYNC_ELF_H
10 
11 #include <kApi/kApiDef.h>
12 
13 /*
14  * References:
15  * https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
16  * http://refspecs.linuxbase.org/elf/elf.pdf
17  */
18 
19 #define kELF_ENDIAN_LITTLE (1)
20 #define kELF_ENDIAN_BIG (2)
21 
22 #define kELF_CLASS_32 (1)
23 #define kELF_CLASS_64 (2)
24 
25 #define kELF_MACHINE_ARM (0x28)
26 
27 #define kELF_SEGMENT_TYPE_LOAD (1)
28 
29 #define kELF_PERMISION_EXECUTE (0x01)
30 
31 #define kELF_SECTION_TYPE_PROGBITS (1)
32 #define kELF_SECTION_TYPE_SYMTAB (2)
33 #define kELF_SECTION_TYPE_STRTAB (3)
34 
35 typedef k32u kElf32Address;
36 
37 typedef struct kElf32Identity
38 {
39  kChar magic[4]; //0x7F followed by ELF in ASCII; these four bytes constitute the magic number.
40  k8u archClass; //This byte is set to either 1 or 2 to signify 32- or 64-bit format, respectively.
41  k8u endian; //This byte is set to either 1 or 2 to signify little or big endianness, respectively. This affects interpretation of multi-byte fields starting with offset 0x10.
42  k8u elfVersion; //Set to 1 for the original version of ELF.
43  k8u osAbi; //Identifies the target operating system ABI; It is often set to 0 regardless of the target platform.
44  k8u osAbiVersion; //Further specifies the ABI version. Its interpretation depends on the target ABI. Linux kernel (after at least 2.6) has no definition of it.[4] In that case, offset and size of EI_PAD are 8.
45  k8u reserved[7]; //Currently unused
46 } kElf32Identity;
47 
48 typedef struct kElf32Header
49 {
50  kElf32Identity identity;
51  k16u moduleType; //1, 2, 3, 4 specify whether the object is relocatable, executable, shared, or core, respectively.
52  k16u machine; //Specifies target instruction set architecture. Some examples are: 0x02 SPARC, 0x03 x86, 0x28 ARM, 0x32 IA-64, 0x3E x86-64, 0xB7 AArch64.
53  k32u moduleVersion; //Set to 1 for the original version of ELF.
54  kElf32Address entryPoint; //This is the memory address of the entry point from where the process starts executing. This field is either 32 or 64 bits long depending on the format defined earlier.
55  k32u programHeaderOffset; //Points to the start of the program header table. It usually follows the file header immediately making the offset 0x40 for 64-bit ELF executables.
56  k32u sectionHeaderOffset; //Points to the start of the section header table.
57  k32u flags; //Interpretation of this field depends on the target architecture.
58  k16u headerSize; //Contains the size of this header, normally 64 bytes for 64-bit and 52 for 32-bit format.
59  k16u programEntrySize; //Contains the size of a program header table entry.
60  k16u programEntryCount; //Contains the number of entries in the program header table.
61  k16u sectionEntrySize; //Contains the size of a section header table entry.
62  k16u sectionEntryCount; //Contains the number of entries in the section header table.
63  k16u nameSectionIndex; //Contains index of the section header table entry that contains the section names.
64 } kElf32Header;
65 
66 typedef struct kElf32SectionHeader
67 {
68  k32u name; //This member gives the section name (as index into string table)
69  k32u type; //This member gives the section type
70  k32u flags; //This member gives the section flags
71  kElf32Address address; //This member gives the section virtual addr at execution
72  k32u offset; //This member gives the section file offset
73  k32u size; //This member gives the section size in bytes
74  k32u link; //This member gives the link to another section
75  k32u info; //Additional section information
76  k32u addralign; //This member gives the section alignment
77  k32u entsize; //Entry size if section holds table
78 } kElf32SectionHeader;
79 
80 typedef struct kElf32Symbol
81 {
82  k32u name; //This member gives the name (as index into string table)
83  kElf32Address value; //This member gives the symbol value
84  k32u size; //This member gives the symbol size
85  kByte info; //This member gives the type and binding
86  kByte other; //This member has no meaning
87  k16u shndx; //This member gives the section header index
88 } kElf32Symbol;
89 
90 typedef struct kElf32ProgramEntry
91 {
92  k32u type; //This member tells what kind of segment this array element describes or how to interpret the array element's information.
93  k32u offset; //This member gives the offset from the beginning of the file at which the first byte of the segment resides.
94  kElf32Address virtAddr; //This member gives the virtual address at which the first byte of the segment resides in memory.
95  kElf32Address physAddr; //On systems for which physical addressing is relevant, this member is reserved for the segment's physical address. This member requires operating system specific information, which is described in the appendix at the end of Book III.
96  k32u fileSize; //This member gives the number of bytes in the file image of the segment; it may be zero.
97  k32u memSize; //This member gives the number of bytes in the memory image of the segment; it may be zero.
98  k32u flags; //This member gives flags relevant to the segment. Defined flag values appear below.
99  k32u align; //Loadable process segments must have congruent values for p_vaddr and p_offset, modulo the page size.This member gives the value to which the segments are aligned in memory and in the file.
100  //Values 0 and 1 mean that no alignment is required. Otherwise, p_align should be a positive, integral power of 2, and p_addr should equal p_offset, modulo p_align.
101 } kElf32ProgramEntry;
102 
103 #endif