X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Kernel%2Fbin%2Felf.c;h=d04dbda45b2c3a669d24bb4bae80d01ef72a4aeb;hb=d7d0479311c4dba418ee880f27f01418fd536344;hp=731d151456cc8bd5bb7a967fd97258f1a9121446;hpb=30e30d7bc325852a8677819d11a47373b08d6271;p=tpg%2Facess2.git diff --git a/Kernel/bin/elf.c b/Kernel/bin/elf.c index 731d1514..d04dbda4 100644 --- a/Kernel/bin/elf.c +++ b/Kernel/bin/elf.c @@ -9,13 +9,12 @@ #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 = { @@ -35,14 +34,14 @@ tBinary *Elf_Load(int fp) int iPageCount; int count; - ENTER("ifp", fp); + ENTER("xfp", fp); // Read ELF Header VFS_Read(fp, sizeof(hdr), &hdr); // 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; @@ -126,13 +125,15 @@ tBinary *Elf_Load(int fp) LOG("phtab[%i] = {VAddr:0x%x,Offset:0x%x,FileSize:0x%x}", i, phtab[i].VAddr, phtab[i].Offset, phtab[i].FileSize); - if( (phtab[i].FileSize & 0xFFF) < 0x1000 - (phtab[i].VAddr & 0xFFF) ) - lastSize = phtab[i].FileSize; - else + //if( (phtab[i].FileSize & 0xFFF) < 0x1000 - (phtab[i].VAddr & 0xFFF) ) + // lastSize = phtab[i].FileSize; + //else lastSize = (phtab[i].FileSize & 0xFFF) + (phtab[i].VAddr & 0xFFF); - lastSize &= 0xFFF; + //lastSize &= 0xFFF; + + //LOG("lastSize = 0x%x", lastSize); - LOG("lastSize = 0x%x", lastSize); + lastSize = phtab[i].FileSize; // Get Pages count = ( (phtab[i].VAddr&0xFFF) + phtab[i].FileSize + 0xFFF) >> 12; @@ -152,6 +153,7 @@ tBinary *Elf_Load(int fp) ret->Pages[j+k].Size = 4096; LOG("ret->Pages[%i].Size = 0x%x", j+k, ret->Pages[j+k].Size); ret->Pages[j+k].Flags = 0; + lastSize -= ret->Pages[j+k].Size; } count = (phtab[i].MemSize + 0xFFF) >> 12; for(;kNumPages = j; @@ -283,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 ++ ) { @@ -345,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 ++) @@ -407,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; } } @@ -449,8 +455,8 @@ int Elf_Relocate(void *Base) return 0; } - LEAVE('x', hdr->entrypoint); - return hdr->entrypoint; + LEAVE('x', 1); + return 1; } /** @@ -526,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; @@ -579,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)