X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Fld-acess_src%2Fbinary.c;h=59be8295b63de629475a262683053247629ccb20;hb=b7d9f86f7a1c23be18b50d5c647fd5d3c08369c3;hp=746fbb8b007af162e02b42ce6018cc70c9f7afe0;hpb=b8b25ae01e13c655608fb6705574e5218b1a519f;p=tpg%2Facess2.git diff --git a/AcessNative/ld-acess_src/binary.c b/AcessNative/ld-acess_src/binary.c index 746fbb8b..59be8295 100644 --- a/AcessNative/ld-acess_src/binary.c +++ b/AcessNative/ld-acess_src/binary.c @@ -1,12 +1,17 @@ /* - * AcessNative + * AcessNative Dynamic Linker + * - By John Hodge (thePowersGang) + * + * binary.c + * - Provides binary loading and type abstraction */ +#define DEBUG 0 #include "common.h" #include #include #include -#define LIBRARY_PATH "$$$$../Usermode/Output/i386/Libs" +#define LIBRARY_PATH "$$$$../Usermode/Output/x86_64/Libs" // === TYPES === typedef struct sBinary { @@ -20,9 +25,10 @@ typedef struct sBinary { // === IMPORTS === extern void *Elf_Load(int fd); extern uintptr_t ElfRelocate(void *Base); -extern int ElfGetSymbol(void *Base, char *Name, uintptr_t *ret); +extern int ElfGetSymbol(void *Base, char *Name, uintptr_t *ret, size_t *size); extern int ciNumBuiltinSymbols; extern tSym caBuiltinSymbols[]; +extern char **gEnvP; // === PROTOTYPES === void Binary_AddToList(const char *Filename, void *Base, tBinFmt *Format); @@ -59,9 +65,9 @@ char *Binary_LocateLibrary(const char *Name) strcat(tmp, "/"); strcat(tmp, Name); - fd = acess_open(tmp, 4); // OPENFLAG_EXEC + fd = acess__SysOpen(tmp, 4); // OPENFLAG_EXEC if(fd != -1) { - acess_close(fd); + acess__SysClose(fd); return strdup(tmp); } } @@ -78,9 +84,9 @@ char *Binary_LocateLibrary(const char *Name) printf("Binary_LocateLibrary: tmp = '%s'\n", tmp); #endif - fd = acess_open(tmp, 4); // OPENFLAG_EXEC + fd = acess__SysOpen(tmp, 4); // OPENFLAG_EXEC if(fd != -1) { - acess_close(fd); + acess__SysClose(fd); return strdup(tmp); } } @@ -108,7 +114,8 @@ void *Binary_LoadLibrary(const char *Name) } ret = Binary_Load(path, (uintptr_t*)&entry); - printf("LOADED '%s' to %p (Entry=%p)\n", path, ret, entry); + if( ret != (void*)-1 ) + Debug("LOADED '%s' to %p (Entry=%p)", path, ret, entry); free(path); #if DEBUG @@ -119,7 +126,7 @@ void *Binary_LoadLibrary(const char *Name) #if DEBUG printf("Calling '%s' entry point %p\n", Name, entry); #endif - entry(ret, 0, argv, NULL); + entry(ret, 0, argv, gEnvP); } return ret; @@ -149,32 +156,32 @@ void *Binary_Load(const char *Filename, uintptr_t *EntryPoint) } } - fd = acess_open(Filename, 2|1); // Execute and Read + fd = acess__SysOpen(Filename, 2|1); // Execute and Read if( fd == -1 ) { // TODO: Handle libary directories perror("Opening binary"); return NULL; } - acess_read(fd, 4, &dword); - acess_seek(fd, 0, ACESS_SEEK_SET); + acess__SysRead(fd, &dword, 4); + acess__SysSeek(fd, 0, ACESS_SEEK_SET); if( memcmp(&dword, "\x7F""ELF", 4) == 0 ) { fmt = &gElf_FormatDef; } else { fprintf(stderr, "Unknown executable format (0x%08x)\n", dword); - acess_close(fd); + acess__SysClose(fd); return NULL; } #if DEBUG - printf("fmt->Load(%i)...\n", fd); + printf("fmt->Load(0x%x)...\n", fd); #endif ret = fmt->Load(fd); - acess_close(fd); + acess__SysClose(fd); #if DEBUG - printf("fmt->Load(%p): %p\n", fd, ret); + printf("fmt->Load(0x%x): %p\n", fd, ret); #endif if( !ret ) { return NULL; @@ -221,7 +228,7 @@ void Binary_SetReadyToUse(void *Base) } } -int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value) +int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size) { int i; tBinary *bin; @@ -236,6 +243,7 @@ int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value) { if( strcmp(caBuiltinSymbols[i].Name, SymbolName) == 0 ) { *Value = (uintptr_t)caBuiltinSymbols[i].Value; + if(Size) *Size = 0; return 1; } } @@ -245,11 +253,13 @@ int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value) { if( !bin->Ready ) continue; //printf(" Binary_GetSymbol: bin = %p{%p, %s}\n", bin, bin->Base, bin->Path); - if( bin->Format->GetSymbol(bin->Base, (char*)SymbolName, Value) ) + if( bin->Format->GetSymbol(bin->Base, (char*)SymbolName, Value, Size) ) return 1; } //printf("Binary_GetSymbol: RETURN 0, not found\n"); - + printf("--- ERROR: Unable to find symbol '%s'\n", SymbolName); + + exit( -1 ); return 0; }