X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Fbin%2Felf.c;h=d04dbda45b2c3a669d24bb4bae80d01ef72a4aeb;hb=d7d0479311c4dba418ee880f27f01418fd536344;hp=4bf15fa2f9a2524ba23663c8d7d267008f7b1379;hpb=b9615a08ff1f70d112b480673ebd5079468658a4;p=tpg%2Facess2.git diff --git a/Kernel/bin/elf.c b/Kernel/bin/elf.c index 4bf15fa2..d04dbda4 100644 --- a/Kernel/bin/elf.c +++ b/Kernel/bin/elf.c @@ -2,20 +2,19 @@ * Acess v0.1 * ELF Executable Loader Code */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include "elf.h" #define DEBUG_WARN 1 - // === PROTOTYPES === tBinary *Elf_Load(int fp); int Elf_Relocate(void *Base); - int Elf_GetSymbol(void *Base, char *Name, Uint *ret); + int Elf_GetSymbol(void *Base, const char *Name, Uint *ret); int Elf_Int_DoRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symtab, Uint base); -Uint Elf_Int_HashString(char *str); +Uint Elf_Int_HashString(const char *str); // === GLOBALS === tBinaryType gELF_Info = { @@ -42,7 +41,7 @@ tBinary *Elf_Load(int fp) // Check the file type if(hdr.ident[0] != 0x7F || hdr.ident[1] != 'E' || hdr.ident[2] != 'L' || hdr.ident[3] != 'F') { - Warning("Non-ELF File was passed to the ELF loader\n"); + Log_Warning("ELF", "Non-ELF File was passed to the ELF loader"); LEAVE('n'); return NULL; } @@ -50,7 +49,7 @@ tBinary *Elf_Load(int fp) // Check for a program header if(hdr.phoff == 0) { #if DEBUG_WARN - Warning("ELF File does not contain a program header\n"); + Log_Warning("ELF", "File does not contain a program header (phoff == 0)"); #endif LEAVE('n'); return NULL; @@ -223,7 +222,7 @@ tBinary *Elf_Load(int fp) // Reallocate ret = realloc( ret, sizeof(tBinary) + 3*sizeof(Uint)*j ); if(!ret) { - Warning("BIN", "ElfLoad: Unable to reallocate return structure"); + Log_Warning("BIN", "ElfLoad: Unable to reallocate return structure"); return NULL; } ret->NumPages = j; @@ -286,7 +285,7 @@ int Elf_Relocate(void *Base) ENTER("pBase", Base); // Parse Program Header to get Dynamic Table - phtab = Base + hdr->phoff; + phtab = (void *)( (tVAddr)Base + hdr->phoff ); iSegmentCount = hdr->phentcount; for(i = 0; i < iSegmentCount; i ++ ) { @@ -348,6 +347,10 @@ int Elf_Relocate(void *Base) } } + if( !dynsymtab && iSymCount > 0 ) { + Log_Warning("ELF", "Elf_Relocate: No Dynamic symbol table, but count >0"); + return 0; + } // Alter Symbols to true base for(i = 0; i < iSymCount; i ++) @@ -410,7 +413,7 @@ int Elf_Relocate(void *Base) for( i = 0; i < j; i++ ) { ptr = (void*)(iBaseDiff + rela[i].r_offset); - if( !Elf_Int_DoRelocate(rel[i].r_info, ptr, rela[i].r_addend, dynsymtab, (Uint)Base) ) { + if( !Elf_Int_DoRelocate(rela[i].r_info, ptr, rela[i].r_addend, dynsymtab, (Uint)Base) ) { bFailed = 1; } } @@ -452,8 +455,8 @@ int Elf_Relocate(void *Base) return 0; } - LEAVE('x', hdr->entrypoint); - return hdr->entrypoint; + LEAVE('x', 1); + return 1; } /** @@ -529,10 +532,10 @@ int Elf_Int_DoRelocate(Uint r_info, Uint32 *ptr, Uint32 addend, Elf32_Sym *symta } /** - * \fn int Elf_GetSymbol(void *Base, char *name, Uint *ret) + * \fn int Elf_GetSymbol(void *Base, const char *name, Uint *ret) * \brief Get a symbol from the loaded binary */ -int Elf_GetSymbol(void *Base, char *Name, Uint *ret) +int Elf_GetSymbol(void *Base, const char *Name, Uint *ret) { Elf32_Ehdr *hdr = (void*)Base; Elf32_Sym *symtab; @@ -582,7 +585,7 @@ int Elf_GetSymbol(void *Base, char *Name, Uint *ret) * \param str String to hash * \return Hash value */ -Uint Elf_Int_HashString(char *str) +Uint Elf_Int_HashString(const char *str) { Uint h = 0, g; while(*str)