Changeset 227 for trunk/kernel/libk
- Timestamp:
- Jul 18, 2017, 12:32:31 PM (7 years ago)
- Location:
- trunk/kernel/libk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/elf.c
r204 r227 38 38 // - return false with an error message if illegal header. 39 39 /////////////////////////////////////////////////////////////////// 40 static bool_t elf_isValidHeader(Elf 32_Ehdr *header)40 static bool_t elf_isValidHeader(Elf_Ehdr *header) 41 41 { 42 42 if((header->e_ident[EI_CLASS] == ELFCLASS32) … … 98 98 } 99 99 100 Elf 32_Ehdr * header = (Elf32_Ehdr *)buffer;100 Elf_Ehdr * header = (Elf_Ehdr *)buffer; 101 101 102 102 if( (header->e_ident[EI_MAG0] != ELFMAG0) || … … 141 141 vseg_t * vseg; 142 142 143 Elf 32_Phdr * seg_ptr = (Elf32_Phdr *)segs_base;143 Elf_Phdr * seg_ptr = (Elf_Phdr *)segs_base; 144 144 145 145 // loop on segments … … 223 223 { 224 224 kmem_req_t req; // kmem request for program header 225 Elf 32_Ehdrheader; // local buffer for .elf header225 Elf_Ehdr header; // local buffer for .elf header 226 226 void * segs_base; // pointer on buffer for segment descriptors array 227 227 uint32_t segs_size; // size of buffer for segment descriptors array … … 255 255 error = elf_header_load( file_xp , 256 256 &header, 257 sizeof(Elf 32_Ehdr) );257 sizeof(Elf_Ehdr) ); 258 258 if( error ) 259 259 { … … 273 273 274 274 // compute buffer size for segment descriptors array 275 segs_size = sizeof(Elf 32_Phdr) * header.e_phnum;275 segs_size = sizeof(Elf_Phdr) * header.e_phnum; 276 276 277 277 // allocate memory for segment descriptors array -
trunk/kernel/libk/elf.h
r204 r227 28 28 */ 29 29 30 /* Type for a 16-bit quantity. */ 30 #define EI_NIDENT (16) 31 32 /* 32bit version */ 31 33 typedef uint16_t Elf32_Half; 32 33 /* Types for signed and unsigned 32-bit quantities. */34 34 typedef uint32_t Elf32_Word; 35 typedef int32_t Elf32_Sword; 36 37 /* Type of addresses. */ 35 typedef int32_t Elf32_Sword; 38 36 typedef uint32_t Elf32_Addr; 39 40 /* Type of file offsets. */41 37 typedef uint32_t Elf32_Off; 42 38 43 /* Type for section indices, which are 16-bit quantities. */ 44 typedef uint16_t Elf32_Section; 45 46 /* Type for version symbol information. */ 47 typedef Elf32_Half Elf32_Versym; 48 49 /************************************************************************************* 50 * This structure defines the ELF file header (first bytes in the file) 51 *************************************************************************************/ 52 53 #define EI_NIDENT (16) 54 55 typedef struct 56 { 57 unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ 39 /* 64bit version */ 40 typedef uint16_t Elf64_Half; 41 typedef uint32_t Elf64_Word; 42 typedef int32_t Elf64_Sword; 43 typedef uint64_t Elf64_Addr; 44 typedef uint64_t Elf64_Off; 45 46 /* ELF header - 32bit version. */ 47 typedef struct 48 { 49 unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ 58 50 Elf32_Half e_type; /* Object file type */ 59 51 Elf32_Half e_machine; /* Architecture */ 60 52 Elf32_Word e_version; /* Object file version */ 61 Elf32_Addr 62 Elf32_Off 63 Elf32_Off 53 Elf32_Addr e_entry; /* Entry point virtual address */ 54 Elf32_Off e_phoff; /* Program header table file offset */ 55 Elf32_Off e_shoff; /* Section header table file offset */ 64 56 Elf32_Word e_flags; /* Processor-specific flags */ 65 57 Elf32_Half e_ehsize; /* ELF header size in bytes */ … … 71 63 } 72 64 Elf32_Ehdr; 65 66 /* ELF header - 64bit version. */ 67 typedef struct 68 { 69 unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ 70 Elf64_Half e_type; /* Object file type */ 71 Elf64_Half e_machine; /* Architecture */ 72 Elf64_Word e_version; /* Object file version */ 73 Elf64_Addr e_entry; /* Entry point virtual address */ 74 Elf64_Off e_phoff; /* Program header table file offset */ 75 Elf64_Off e_shoff; /* Section header table file offset */ 76 Elf64_Word e_flags; /* Processor-specific flags */ 77 Elf64_Half e_ehsize; /* ELF header size in bytes */ 78 Elf64_Half e_phentsize; /* Program header table entry size */ 79 Elf64_Half e_phnum; /* Program header table entry count */ 80 Elf64_Half e_shentsize; /* Section header table entry size */ 81 Elf64_Half e_shnum; /* Section header table entry count */ 82 Elf64_Half e_shstrndx; /* Section header string table index */ 83 } 84 Elf64_Ehdr; 73 85 74 86 /* … … 132 144 #define EV_NUM 2 133 145 134 /* Program segment header. */ 135 136 typedef struct 137 { 138 Elf32_Word p_type; /* Segment type */ 139 Elf32_Off p_offset; /* Segment file offset */ 140 Elf32_Addr p_vaddr; /* Segment virtual address */ 141 Elf32_Addr p_paddr; /* Segment physical address */ 142 Elf32_Word p_filesz; /* Segment size in file */ 143 Elf32_Word p_memsz; /* Segment size in memory */ 144 Elf32_Word p_flags; /* Segment flags */ 145 Elf32_Word p_align; /* Segment alignment */ 146 /* Program segment header - 32bit version. */ 147 typedef struct 148 { 149 Elf32_Word p_type; /* Segment type */ 150 Elf32_Off p_offset; /* Segment file offset */ 151 Elf32_Addr p_vaddr; /* Segment virtual address */ 152 Elf32_Addr p_paddr; /* Segment physical address */ 153 Elf32_Word p_filesz; /* Segment size in file */ 154 Elf32_Word p_memsz; /* Segment size in memory */ 155 Elf32_Word p_flags; /* Segment flags */ 156 Elf32_Word p_align; /* Segment alignment */ 146 157 } 147 158 Elf32_Phdr; 159 160 /* Program segment header - 64bit version. */ 161 typedef struct 162 { 163 Elf64_Word p_type; /* Segment type */ 164 Elf64_Word p_flags; /* Segment flags */ 165 Elf64_Off p_offset; /* Segment file offset */ 166 Elf64_Addr p_vaddr; /* Segment virtual address */ 167 Elf64_Addr p_paddr; /* Segment physical address */ 168 Elf64_Word p_filesz; /* Segment size in file */ 169 Elf64_Word p_memsz; /* Segment size in memory */ 170 Elf64_Word p_align; /* Segment alignment */ 171 } 172 Elf64_Phdr; 148 173 149 174 /* Legal values for p_type (segment type). */ … … 176 201 #define PF_MASKPROC 0xf0000000 /* Processor-specific */ 177 202 203 #if defined(HAL_32BIT) 204 #define Elf_Half Elf32_Half 205 #define Elf_Word Elf32_Word 206 #define Elf_Sword Elf32_Sword 207 #define Elf_Addr Elf32_Addr 208 #define Elf_Off Elf32_Off 209 #define Elf_Ehdr Elf32_Ehdr 210 #define Elf_Phdr Elf32_Phdr 211 #elif defined (HAL_64BIT) 212 #define Elf_Half Elf64_Half 213 #define Elf_Word Elf64_Word 214 #define Elf_Sword Elf64_Sword 215 #define Elf_Addr Elf64_Addr 216 #define Elf_Off Elf64_Off 217 #define Elf_Ehdr Elf64_Ehdr 218 #define Elf_Phdr Elf64_Phdr 219 #else 220 #error "Must define HAL_64BIT/HAL_32BIT" 221 #endif 178 222 179 223 /****************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.