00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __elf_h
00009 #define __elf_h
00010
00011 #include <system/config.h>
00012 #include "elf-linux.h"
00013
00014 __BEGIN_SYS
00015
00016 class ELF: private Elf32_Ehdr
00017 {
00018 public:
00019 ELF() {}
00020
00021 bool valid() {
00022 return (e_ident[EI_MAG0] == ELFMAG0) && (e_ident[EI_MAG1] == ELFMAG1)
00023 && (e_ident[EI_MAG2] == ELFMAG2) && (e_ident[EI_MAG3] == ELFMAG3);
00024 }
00025
00026 void * entry() { return (void *)((int)e_entry); }
00027 int segments() { return e_phnum; }
00028
00029 Elf32_Word segment_type(int i) {
00030 return (i > segments()) ? PT_NULL : seg(i)->p_type;
00031 }
00032
00033
00034 void * segment_address(int i) {
00035 return (i > segments()) ? 0 :
00036 (char *)((int)(seg(i)->p_vaddr & ~(seg(i)->p_align - 1)));
00037 }
00038 int segment_size(int i) {
00039 return (i > segments()) ? -1 : (int)(
00040 ((seg(i)->p_offset % seg(i)->p_align)
00041 + seg(i)->p_memsz
00042 + seg(i)->p_align - 1)
00043 & ~(seg(i)->p_align - 1));
00044 }
00045
00046 int load_segment(int i, void * addr = 0);
00047
00048 private:
00049 Elf32_Phdr * pht() { return (Elf32_Phdr *)(((char *) this) + e_phoff); }
00050 Elf32_Phdr * seg(int i) { return &pht()[i]; }
00051 };
00052
00053 __END_SYS
00054
00055 #endif
00056