Changeset c0699467 in mainline for kernel/generic/include/lib/elf.h


Ignore:
Timestamp:
2011-08-09T18:08:23Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b538ca5c
Parents:
3666d38
Message:

do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared
externalize headers which serve as kernel/uspace API/ABI into a special tree

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/lib/elf.h

    r3666d38 rc0699467  
    3636#define KERN_ELF_H_
    3737
     38#include <typedefs.h>
     39#include <abi/elf.h>
    3840#include <arch/elf.h>
    39 #include <typedefs.h>
    40 
    41 /**
    42  * current ELF version
    43  */
    44 #define EV_CURRENT  1
    45 
    46 /**
    47  * ELF types
    48  */
    49 #define ET_NONE    0       /* No type */
    50 #define ET_REL     1       /* Relocatable file */
    51 #define ET_EXEC    2       /* Executable */
    52 #define ET_DYN     3       /* Shared object */
    53 #define ET_CORE    4       /* Core */
    54 #define ET_LOPROC  0xff00  /* Processor specific */
    55 #define ET_HIPROC  0xffff  /* Processor specific */
    56 
    57 /**
    58  * ELF machine types
    59  */
    60 #define EM_NO           0   /* No machine */
    61 #define EM_SPARC        2   /* SPARC */
    62 #define EM_386          3   /* i386 */
    63 #define EM_MIPS         8   /* MIPS RS3000 */
    64 #define EM_MIPS_RS3_LE  10  /* MIPS RS3000 LE */
    65 #define EM_PPC          20  /* PPC32 */
    66 #define EM_PPC64        21  /* PPC64 */
    67 #define EM_ARM          40  /* ARM */
    68 #define EM_SPARCV9      43  /* SPARC64 */
    69 #define EM_IA_64        50  /* IA-64 */
    70 #define EM_X86_64       62  /* AMD64/EMT64 */
    71 
    72 /**
    73  * ELF identification indexes
    74  */
    75 #define EI_MAG0        0
    76 #define EI_MAG1        1
    77 #define EI_MAG2        2
    78 #define EI_MAG3        3
    79 #define EI_CLASS       4   /* File class */
    80 #define EI_DATA        5   /* Data encoding */
    81 #define EI_VERSION     6   /* File version */
    82 #define EI_OSABI       7
    83 #define EI_ABIVERSION  8
    84 #define EI_PAD         9   /* Start of padding bytes */
    85 #define EI_NIDENT      16  /* ELF identification table size */
    86 
    87 /**
    88  * ELF magic number
    89  */
    90 #define ELFMAG0  0x7f
    91 #define ELFMAG1  'E'
    92 #define ELFMAG2  'L'
    93 #define ELFMAG3  'F'
    94 
    95 /**
    96  * ELF file classes
    97  */
    98 #define ELFCLASSNONE  0
    99 #define ELFCLASS32    1
    100 #define ELFCLASS64    2
    101 
    102 /**
    103  * ELF data encoding types
    104  */
    105 #define ELFDATANONE  0
    106 #define ELFDATA2LSB  1  /* Least significant byte first (little endian) */
    107 #define ELFDATA2MSB  2  /* Most signigicant byte first (big endian) */
    108 
    109 /**
    110  * ELF section types
    111  */
    112 #define SHT_NULL      0
    113 #define SHT_PROGBITS  1
    114 #define SHT_SYMTAB    2
    115 #define SHT_STRTAB    3
    116 #define SHT_RELA      4
    117 #define SHT_HASH      5
    118 #define SHT_DYNAMIC   6
    119 #define SHT_NOTE      7
    120 #define SHT_NOBITS    8
    121 #define SHT_REL       9
    122 #define SHT_SHLIB     10
    123 #define SHT_DYNSYM    11
    124 #define SHT_LOOS      0x60000000
    125 #define SHT_HIOS      0x6fffffff
    126 #define SHT_LOPROC    0x70000000
    127 #define SHT_HIPROC    0x7fffffff
    128 #define SHT_LOUSER    0x80000000
    129 #define SHT_HIUSER    0xffffffff
    130 
    131 /**
    132  * ELF section flags
    133  */
    134 #define SHF_WRITE      0x1
    135 #define SHF_ALLOC      0x2
    136 #define SHF_EXECINSTR  0x4
    137 #define SHF_TLS        0x400
    138 #define SHF_MASKPROC   0xf0000000
    139 
    140 /** Macros for decomposing elf_symbol.st_info into binging and type */
    141 #define ELF_ST_BIND(i)     ((i) >> 4)
    142 #define ELF_ST_TYPE(i)     ((i) & 0x0f)
    143 #define ELF_ST_INFO(b, t)  (((b) << 4) + ((t) & 0x0f))
    144 
    145 /**
    146  * Symbol binding
    147  */
    148 #define STB_LOCAL   0
    149 #define STB_GLOBAL  1
    150 #define STB_WEAK    2
    151 #define STB_LOPROC  13
    152 #define STB_HIPROC  15
    153 
    154 /**
    155  * Symbol types
    156  */
    157 #define STT_NOTYPE   0
    158 #define STT_OBJECT   1
    159 #define STT_FUNC     2
    160 #define STT_SECTION  3
    161 #define STT_FILE     4
    162 #define STT_LOPROC   13
    163 #define STT_HIPROC   15
    164 
    165 /**
    166  * Program segment types
    167  */
    168 #define PT_NULL     0
    169 #define PT_LOAD     1
    170 #define PT_DYNAMIC  2
    171 #define PT_INTERP   3
    172 #define PT_NOTE     4
    173 #define PT_SHLIB    5
    174 #define PT_PHDR     6
    175 #define PT_LOPROC   0x70000000
    176 #define PT_HIPROC   0x7fffffff
    177 
    178 /**
    179  * Program segment attributes.
    180  */
    181 #define PF_X  1
    182 #define PF_W  2
    183 #define PF_R  4
    184 
    185 /**
    186  * ELF data types
    187  *
    188  * These types are found to be identical in both 32-bit and 64-bit
    189  * ELF object file specifications. They are the only types used
    190  * in ELF header.
    191  */
    192 typedef uint64_t elf_xword;
    193 typedef int64_t elf_sxword;
    194 typedef uint32_t elf_word;
    195 typedef int32_t elf_sword;
    196 typedef uint16_t elf_half;
    197 
    198 /**
    199  * 32-bit ELF data types.
    200  *
    201  * These types are specific for 32-bit format.
    202  */
    203 typedef uint32_t elf32_addr;
    204 typedef uint32_t elf32_off;
    205 
    206 /**
    207  * 64-bit ELF data types.
    208  *
    209  * These types are specific for 64-bit format.
    210  */
    211 typedef uint64_t elf64_addr;
    212 typedef uint64_t elf64_off;
    213 
    214 /** ELF header */
    215 struct elf32_header {
    216         uint8_t e_ident[EI_NIDENT];
    217         elf_half e_type;
    218         elf_half e_machine;
    219         elf_word e_version;
    220         elf32_addr e_entry;
    221         elf32_off e_phoff;
    222         elf32_off e_shoff;
    223         elf_word e_flags;
    224         elf_half e_ehsize;
    225         elf_half e_phentsize;
    226         elf_half e_phnum;
    227         elf_half e_shentsize;
    228         elf_half e_shnum;
    229         elf_half e_shstrndx;
    230 };
    231 
    232 struct elf64_header {
    233         uint8_t e_ident[EI_NIDENT];
    234         elf_half e_type;
    235         elf_half e_machine;
    236         elf_word e_version;
    237         elf64_addr e_entry;
    238         elf64_off e_phoff;
    239         elf64_off e_shoff;
    240         elf_word e_flags;
    241         elf_half e_ehsize;
    242         elf_half e_phentsize;
    243         elf_half e_phnum;
    244         elf_half e_shentsize;
    245         elf_half e_shnum;
    246         elf_half e_shstrndx;
    247 };
    248 
    249 /**
    250  * ELF segment header.
    251  * Segments headers are also known as program headers.
    252  */
    253 struct elf32_segment_header {
    254         elf_word p_type;
    255         elf32_off p_offset;
    256         elf32_addr p_vaddr;
    257         elf32_addr p_paddr;
    258         elf_word p_filesz;
    259         elf_word p_memsz;
    260         elf_word p_flags;
    261         elf_word p_align;
    262 };
    263 
    264 struct elf64_segment_header {
    265         elf_word p_type;
    266         elf_word p_flags;
    267         elf64_off p_offset;
    268         elf64_addr p_vaddr;
    269         elf64_addr p_paddr;
    270         elf_xword p_filesz;
    271         elf_xword p_memsz;
    272         elf_xword p_align;
    273 };
    274 
    275 /**
    276  * ELF section header
    277  */
    278 struct elf32_section_header {
    279         elf_word sh_name;
    280         elf_word sh_type;
    281         elf_word sh_flags;
    282         elf32_addr sh_addr;
    283         elf32_off sh_offset;
    284         elf_word sh_size;
    285         elf_word sh_link;
    286         elf_word sh_info;
    287         elf_word sh_addralign;
    288         elf_word sh_entsize;
    289 };
    290 
    291 struct elf64_section_header {
    292         elf_word sh_name;
    293         elf_word sh_type;
    294         elf_xword sh_flags;
    295         elf64_addr sh_addr;
    296         elf64_off sh_offset;
    297         elf_xword sh_size;
    298         elf_word sh_link;
    299         elf_word sh_info;
    300         elf_xword sh_addralign;
    301         elf_xword sh_entsize;
    302 };
    303 
    304 /**
    305  * ELF symbol table entry
    306  */
    307 struct elf32_symbol {
    308         elf_word st_name;
    309         elf32_addr st_value;
    310         elf_word st_size;
    311         uint8_t st_info;
    312         uint8_t st_other;
    313         elf_half st_shndx;
    314 };
    315 
    316 struct elf64_symbol {
    317         elf_word st_name;
    318         uint8_t st_info;
    319         uint8_t st_other;
    320         elf_half st_shndx;
    321         elf64_addr st_value;
    322         elf_xword st_size;
    323 };
    324 
    325 /*
    326  * ELF note segment entry
    327  */
    328 struct elf32_note {
    329         elf_word namesz;
    330         elf_word descsz;
    331         elf_word type;
    332 };
    333 
    334 /*
    335  * NOTE: namesz, descsz and type should be 64-bits wide (elf_xword)
    336  * per the 64-bit ELF spec. The Linux kernel however screws up and
    337  * defines them as Elf64_Word, which is 32-bits wide(!). We are trying
    338  * to make our core files compatible with Linux GDB target so we copy
    339  * the blunder here.
    340  */
    341 struct elf64_note {
    342         elf_word namesz;
    343         elf_word descsz;
    344         elf_word type;
    345 };
    346 
    347 #ifdef __32_BITS__
    348 typedef struct elf32_header elf_header_t;
    349 typedef struct elf32_segment_header elf_segment_header_t;
    350 typedef struct elf32_section_header elf_section_header_t;
    351 typedef struct elf32_symbol elf_symbol_t;
    352 typedef struct elf32_note elf_note_t;
    353 #endif
    354 
    355 #ifdef __64_BITS__
    356 typedef struct elf64_header elf_header_t;
    357 typedef struct elf64_segment_header elf_segment_header_t;
    358 typedef struct elf64_section_header elf_section_header_t;
    359 typedef struct elf64_symbol elf_symbol_t;
    360 typedef struct elf64_note elf_note_t;
    361 #endif
    36241
    36342/** Interpreter string used to recognize the program loader */
Note: See TracChangeset for help on using the changeset viewer.