From: John Hodge Date: Sun, 23 Oct 2011 13:33:49 +0000 (+0800) Subject: AcessNative/ld-acess - Fixed forgetting to update for API changes X-Git-Tag: rel0.14~207 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b4e2712f6a0849de53207ad50a38c9f468f22651;p=tpg%2Facess2.git AcessNative/ld-acess - Fixed forgetting to update for API changes --- diff --git a/AcessNative/RunRootApp b/AcessNative/RunRootApp index b66000c3..39a30fac 100755 --- a/AcessNative/RunRootApp +++ b/AcessNative/RunRootApp @@ -1,2 +1,3 @@ #!/bin/sh -./ld-acess --open /Devices/VTerm/0 --open /Devices/VTerm/0 --open /Devices/VTerm/0 $* + +$DBG ./ld-acess --open /Devices/VTerm/0 --open /Devices/VTerm/0 --open /Devices/VTerm/0 $* diff --git a/AcessNative/ld-acess_src/binary.c b/AcessNative/ld-acess_src/binary.c index 746fbb8b..08ae6e9e 100644 --- a/AcessNative/ld-acess_src/binary.c +++ b/AcessNative/ld-acess_src/binary.c @@ -6,7 +6,7 @@ #include #include -#define LIBRARY_PATH "$$$$../Usermode/Output/i386/Libs" +#define LIBRARY_PATH "$$$$../Usermode/Output/x86/Libs" // === TYPES === typedef struct sBinary { @@ -20,7 +20,7 @@ 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[]; @@ -156,7 +156,7 @@ void *Binary_Load(const char *Filename, uintptr_t *EntryPoint) return NULL; } - acess_read(fd, 4, &dword); + acess_read(fd, &dword, 4); acess_seek(fd, 0, ACESS_SEEK_SET); if( memcmp(&dword, "\x7F""ELF", 4) == 0 ) { @@ -221,7 +221,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 +236,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,7 +246,7 @@ 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; } diff --git a/AcessNative/ld-acess_src/common.h b/AcessNative/ld-acess_src/common.h index 59be119f..0d1dee88 100644 --- a/AcessNative/ld-acess_src/common.h +++ b/AcessNative/ld-acess_src/common.h @@ -8,7 +8,7 @@ #include #include -extern int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value); +extern int Binary_GetSymbol(const char *SymbolName, uintptr_t *Value, size_t *Size); extern void *Binary_LoadLibrary(const char *Path); extern void *Binary_Load(const char *Path, uintptr_t *EntryPoint); extern void Binary_SetReadyToUse(void *Base); @@ -17,7 +17,7 @@ extern void Binary_SetReadyToUse(void *Base); static inline void *GetSymbol(const char*sym, size_t*sz) { uintptr_t rv; - if( Binary_GetSymbol(sym, &rv) ) + if( !Binary_GetSymbol(sym, &rv, sz) ) return NULL; return (void*)rv; } @@ -49,7 +49,7 @@ typedef struct sBinFmt { char *Name; void *(*Load)(int fd); uintptr_t (*Relocate)(void *base); - int (*GetSymbol)(void*,char*,uintptr_t*); + int (*GetSymbol)(void*,char*,uintptr_t*,size_t*); } tBinFmt; #endif diff --git a/AcessNative/ld-acess_src/elf_load.c b/AcessNative/ld-acess_src/elf_load.c index 49298699..9e5a0327 100644 --- a/AcessNative/ld-acess_src/elf_load.c +++ b/AcessNative/ld-acess_src/elf_load.c @@ -2,7 +2,7 @@ * Acess v0.1 * ELF Executable Loader Code */ -#define DEBUG 0 +#define DEBUG 1 #include #include #include @@ -17,7 +17,7 @@ #define PTR(_val) ((void*)(uintptr_t)(_val)) #if DEBUG -# define ENTER(...) +# define ENTER(...) printf("%s: ---- ENTER ----\n", __func__); # define LOG(s, ...) printf("%s: " s, __func__, __VA_ARGS__) # define LOGS(s) printf("%s: " s, __func__) # define LEAVE(...) @@ -38,7 +38,7 @@ void *Elf_Load(int FD) Elf32_Ehdr hdr; // Read ELF Header - acess_read(FD, sizeof(hdr), &hdr); + acess_read(FD, &hdr, sizeof(hdr)); // Check the file type if(hdr.e_ident[0] != 0x7F || hdr.e_ident[1] != 'E' || hdr.e_ident[2] != 'L' || hdr.e_ident[3] != 'F') { @@ -82,7 +82,7 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) } LOG("hdr.phoff = 0x%08x\n", hdr->phoff); acess_seek(FD, hdr->phoff, ACESS_SEEK_SET); - acess_read(FD, sizeof(Elf32_Phdr) * hdr->phentcount, phtab); + acess_read(FD, phtab, sizeof(Elf32_Phdr) * hdr->phentcount); // Count Pages iPageCount = 0; @@ -132,17 +132,6 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) // Load Pages for( i = 0; i < hdr->phentcount; i++ ) { - //LOG("phtab[%i].Type = 0x%x", i, phtab[i].Type); - LOG("phtab[%i] = {\n", i); - LOG(" .Type = 0x%08x\n", phtab[i].Type); - LOG(" .Offset = 0x%08x\n", phtab[i].Offset); - LOG(" .VAddr = 0x%08x\n", phtab[i].VAddr); - LOG(" .PAddr = 0x%08x\n", phtab[i].PAddr); - LOG(" .FileSize = 0x%08x\n", phtab[i].FileSize); - LOG(" .MemSize = 0x%08x\n", phtab[i].MemSize); - LOG(" .Flags = 0x%08x\n", phtab[i].Flags); - LOG(" .Align = 0x%08x\n", phtab[i].Align); - LOGS(" }\n"); // Get Interpreter Name if( phtab[i].Type == PT_INTERP ) { @@ -150,7 +139,7 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) //if(ret->Interpreter) continue; tmp = malloc(phtab[i].FileSize); acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET); - acess_read(FD, phtab[i].FileSize, tmp); + acess_read(FD, tmp, phtab[i].FileSize); //ret->Interpreter = Binary_RegInterp(tmp); LOG("Interpreter '%s'\n", tmp); free(tmp); @@ -159,8 +148,8 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) // Ignore non-LOAD types if(phtab[i].Type != PT_LOAD) continue; - LOG("phtab[%i] = {VAddr:0x%x,Offset:0x%x,FileSize:0x%x}\n", - i, phtab[i].VAddr+baseDiff, phtab[i].Offset, phtab[i].FileSize); + LOG("phtab[%i] = PT_LOAD {Adj VAddr:0x%x, Offset:0x%x, FileSize:0x%x, MemSize:0x%x}\n", + i, phtab[i].VAddr+baseDiff, phtab[i].Offset, phtab[i].FileSize, phtab[i].MemSize); addr = phtab[i].VAddr + baseDiff; @@ -172,7 +161,7 @@ void *Elf32Load(int FD, Elf32_Ehdr *hdr) } acess_seek(FD, phtab[i].Offset, ACESS_SEEK_SET); - acess_read(FD, phtab[i].FileSize, PTRMK(void, addr) ); + acess_read(FD, PTRMK(void, addr), phtab[i].FileSize); memset( PTRMK(char, addr) + phtab[i].FileSize, 0, phtab[i].MemSize - phtab[i].FileSize ); } diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index af9cc900..533c25b3 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -59,16 +59,16 @@ int acess_reopen(int FD, const char *Path, int Flags) { return _Syscall(SYS_REOPEN, ">i >s >i", FD, Path, Flags); } -size_t acess_read(int FD, size_t Bytes, void *Dest) { +size_t acess_read(int FD, void *Dest, size_t Bytes) { if(FD & NATIVE_FILE_MASK) - return native_read(FD & (NATIVE_FILE_MASK-1), Bytes, Dest); + return native_read(FD & (NATIVE_FILE_MASK-1), Dest, Bytes); DEBUG("read(0x%x, 0x%x, *%p)", FD, Bytes, Dest); return _Syscall(SYS_READ, ">i >i i >i >d", FD, Bytes, Bytes, Src); } diff --git a/AcessNative/ld-acess_src/exports.h b/AcessNative/ld-acess_src/exports.h index 7fd9bb57..43d620ff 100644 --- a/AcessNative/ld-acess_src/exports.h +++ b/AcessNative/ld-acess_src/exports.h @@ -13,15 +13,15 @@ extern uint64_t _Syscall(int SyscallID, const char *ArgTypes, ...); extern int native_open(const char *Path, int Flags); extern void native_close(int FD); -extern size_t native_read(int FD, size_t Bytes, void *Dest); -extern size_t native_write(int FD, size_t Bytes, const void *Src); +extern size_t native_read(int FD, void *Dest, size_t Bytes); +extern size_t native_write(int FD, const void *Src, size_t Bytes); extern int native_seek(int FD, int64_t Offset, int Dir); extern uint64_t native_tell(int FD); // Syscalls used by the linker extern int acess_open(const char *Path, int Flags); extern void acess_close(int FD); -extern size_t acess_read(int FD, size_t Bytes, void *Dest); +extern size_t acess_read(int FD, void *Dest, size_t Bytes); extern int acess_seek(int FD, int64_t Offset, int Dir); // Symbol type diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 3c07ef25..7bb3b039 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -290,12 +290,12 @@ void native_close(int FD) gaSyscall_LocalFPs[FD] = NULL; } -size_t native_read(int FD, size_t Bytes, void *Dest) +size_t native_read(int FD, void *Dest, size_t Bytes) { return fread( Dest, Bytes, 1, gaSyscall_LocalFPs[FD] ); } -size_t native_write(int FD, size_t Bytes, const void *Src) +size_t native_write(int FD, const void *Src, size_t Bytes) { return fwrite( Src, Bytes, 1, gaSyscall_LocalFPs[FD] ); }