From: John Hodge Date: Sat, 7 May 2011 13:17:03 +0000 (+0800) Subject: Debugging a segfault in ELF loader (when loading CLIShell) X-Git-Tag: rel0.10~125 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a2b49f92646ef666e17172faf72a9dcc0d18942a;p=tpg%2Facess2.git Debugging a segfault in ELF loader (when loading CLIShell) --- diff --git a/AcessNative/ld-acess_src/elf.c b/AcessNative/ld-acess_src/elf.c index b99f1901..c01d24d4 100644 --- a/AcessNative/ld-acess_src/elf.c +++ b/AcessNative/ld-acess_src/elf.c @@ -2,7 +2,7 @@ * Acess v0.1 * ELF Executable Loader Code */ -#define DEBUG 0 +#define DEBUG 1 #include #include #include @@ -248,6 +248,9 @@ uintptr_t Elf_Relocate(void *Base) hdr->entrypoint += iBaseDiff; + hdr->misc.SymTable = 0; + hdr->misc.HashTable = 0; + // === Get Symbol table and String Table === for( j = 0; dynamicTab[j].d_tag != DT_NULL; j++) { @@ -274,6 +277,9 @@ uintptr_t Elf_Relocate(void *Base) break; } } + + LOG("hdr->misc.SymTable = %x, hdr->misc.HashTable = %x", + hdr->misc.SymTable, hdr->misc.HashTable); // Alter Symbols to true base @@ -486,6 +492,9 @@ int Elf_GetSymbol(void *Base, char *Name, uintptr_t *ret) pBuckets = PTR(hdr->misc.HashTable); symtab = PTR(hdr->misc.SymTable); + if(!pBuckets || !symtab) + return 0; + nbuckets = pBuckets[0]; iSymCount = pBuckets[1]; pBuckets = &pBuckets[2]; diff --git a/AcessNative/ld-acess_src/request.c b/AcessNative/ld-acess_src/request.c index 75565f15..8655377e 100644 --- a/AcessNative/ld-acess_src/request.c +++ b/AcessNative/ld-acess_src/request.c @@ -1,5 +1,15 @@ /* */ +#define DEBUG 0 + + +#if DEBUG +# define DEBUG_S printf +#else +# define DEBUG_S(...) +# define DONT_INCLUDE_SYSCALL_NAMES +#endif + #include #include #include @@ -154,31 +164,31 @@ int SendRequest(tRequestHeader *Request, int RequestSize, int ResponseSize) { int i; char *data = (char*)&Request->Params[Request->NParams]; - printf("Request #%i (%s) -", Request->CallID, casSYSCALL_NAMES[Request->CallID]); + DEBUG_S("Request #%i (%s) -", Request->CallID, casSYSCALL_NAMES[Request->CallID]); for( i = 0; i < Request->NParams; i ++ ) { switch(Request->Params[i].Type) { case ARG_TYPE_INT32: - printf(" 0x%08x", *(uint32_t*)data); + DEBUG_S(" 0x%08x", *(uint32_t*)data); data += sizeof(uint32_t); break; case ARG_TYPE_INT64: - printf(" 0x%016llx", *(uint64_t*)data); + DEBUG_S(" 0x%016llx", *(uint64_t*)data); data += sizeof(uint64_t); break; case ARG_TYPE_STRING: - printf(" '%s'", (char*)data); + DEBUG_S(" '%s'", (char*)data); data += Request->Params[i].Length; break; case ARG_TYPE_DATA: - printf(" %p:0x%x", (char*)data, Request->Params[i].Length); + DEBUG_S(" %p:0x%x", (char*)data, Request->Params[i].Length); if( !(Request->Params[i].Flags & ARG_FLAG_ZEROED) ) data += Request->Params[i].Length; break; } } - printf("\n"); + DEBUG_S("\n"); } // Send it off @@ -246,7 +256,7 @@ int ReadData(void *Dest, int MaxLength, int Timeout) exit(-1); } - printf("%i bytes read from socket\n", ret); + DEBUG_S("%i bytes read from socket\n", ret); return ret; } diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 2a63622a..58824351 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -271,7 +271,7 @@ uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...) free( req ); free( retPtrs ); - printf("Return %llx\n", retValue); + DEBUG(": %llx\n", retValue); return retValue; } @@ -289,7 +289,7 @@ int acess_open(const char *Path, int Flags) if(!gaSyscall_LocalFPs[ret]) return -1; return ret|NATIVE_FILE_MASK; } - DEBUG("open(\"%s\", 0x%x)\n", Path, Flags); + DEBUG("open(\"%s\", 0x%x)", Path, Flags); return _Syscall(SYS_OPEN, ">s >i", Path, Flags); } @@ -299,26 +299,26 @@ void acess_close(int FD) { gaSyscall_LocalFPs[FD & (NATIVE_FILE_MASK-1)] = NULL; return ; } - DEBUG("close(%i)\n", FD); + DEBUG("close(%i)", FD); _Syscall(SYS_CLOSE, ">i", FD); } int acess_reopen(int FD, const char *Path, int Flags) { - DEBUG("reopen(0x%x, \"%s\", 0x%x)\n", FD, Path, Flags); + DEBUG("reopen(0x%x, \"%s\", 0x%x)", FD, Path, Flags); return _Syscall(SYS_REOPEN, ">i >s >i", FD, Path, Flags); } size_t acess_read(int FD, size_t Bytes, void *Dest) { if(FD & NATIVE_FILE_MASK) return fread( Dest, Bytes, 1, gaSyscall_LocalFPs[FD & (NATIVE_FILE_MASK-1)] ); - DEBUG("read(0x%x, 0x%x, *%p)\n", FD, Bytes, Dest); + DEBUG("read(0x%x, 0x%x, *%p)", FD, Bytes, Dest); return _Syscall(SYS_READ, ">i >i i >i >d", FD, Bytes, Bytes, Src); } @@ -332,7 +332,7 @@ int acess_seek(int FD, int64_t Ofs, int Dir) { } return fseek( gaSyscall_LocalFPs[FD & (NATIVE_FILE_MASK-1)], Ofs, Dir ); } - DEBUG("seek(0x%x, 0x%llx, %i)\n", FD, Ofs, Dir); + DEBUG("seek(0x%x, 0x%llx, %i)", FD, Ofs, Dir); return _Syscall(SYS_SEEK, ">i >I >i", FD, Ofs, Dir); } @@ -390,9 +390,9 @@ int acess_clone(int flags, void *stack) extern int fork(void); if(flags & CLONE_VM) { int ret, newID, kernel_tid=0; - printf("fork()\n"); + printf("fork()"); - newID = _Syscall(SYS_FORK, "i i