From 45aa70066eaed86fa03c0cb842b2031435019645 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 26 Apr 2013 13:20:52 +0800 Subject: [PATCH] Usermode/ld-acess - Bugfix and extra syscall - Fixes when programs are linked against ld-acess.so instead of libld-acess.so - SYS_COPYFD added - Cleaned up twiddling loaded library list from main() > Now hardcoded check in IsLoaded is used for *ld-acess.so --- Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h | 1 + Usermode/Libraries/ld-acess.so_src/loadlib.c | 12 +++++++++++- Usermode/Libraries/ld-acess.so_src/main.c | 5 ----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h index 78d34bf7..c7a7215c 100644 --- a/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h +++ b/Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h @@ -42,6 +42,7 @@ SYSCALL3(_SysSetMemFlags, SYS_SETFLAGS) // uint32_t SysSetMemFlags(uint addr, ui SYSCALL2(_SysOpen, SYS_OPEN) // char*, int SYSCALL3(_SysOpenChild, SYS_OPENCHILD) // int, char*, int SYSCALL3(_SysReopen, SYS_REOPEN) // int, char*, int +SYSCALL2(_SysCopyFD, SYS_COPYFD) // int, int SYSCALL1(_SysClose, SYS_CLOSE) // int SYSCALL3(_SysRead, SYS_READ) // int, uint, void* SYSCALL3(_SysWrite, SYS_WRITE) // int, uint, void* diff --git a/Usermode/Libraries/ld-acess.so_src/loadlib.c b/Usermode/Libraries/ld-acess.so_src/loadlib.c index dcacd8a8..53073019 100644 --- a/Usermode/Libraries/ld-acess.so_src/loadlib.c +++ b/Usermode/Libraries/ld-acess.so_src/loadlib.c @@ -24,6 +24,7 @@ extern const struct { } caLocalExports[]; extern const int ciNumLocalExports; extern char **gEnvP; +extern char gLinkedBase[]; // === GLOABLS === tLoadedLib gLoadedLibraries[MAX_LOADED_LIBRARIES]; @@ -108,6 +109,15 @@ void *IsFileLoaded(const char *file) { int i; DEBUGS("IsFileLoaded: (file='%s')", file); + + // Applications link against either libld-acess.so or ld-acess.so + if( strcmp(file, "/Acess/Libs/libld-acess.so") == 0 + || strcmp(file, "/Acess/Libs/ld-acess.so") == 0 ) + { + DEBUGS("IsFileLoaded: Found local (%p)", &gLinkedBase); + return &gLinkedBase; + } + for( i = 0; i < MAX_LOADED_LIBRARIES; i++ ) { if(gLoadedLibraries[i].Base == 0) break; // Last entry has Base set to NULL @@ -217,7 +227,7 @@ int GetSymbol(const char *name, void **Value, size_t *Size) } // Entry 0 is ld-acess, ignore it - for(i = 1; i < MAX_LOADED_LIBRARIES; i ++) + for(i = 0; i < MAX_LOADED_LIBRARIES; i ++) { if(gLoadedLibraries[i].Base == 0) break; diff --git a/Usermode/Libraries/ld-acess.so_src/main.c b/Usermode/Libraries/ld-acess.so_src/main.c index 985f9c8c..e379a70a 100644 --- a/Usermode/Libraries/ld-acess.so_src/main.c +++ b/Usermode/Libraries/ld-acess.so_src/main.c @@ -12,7 +12,6 @@ void *DoRelocate(void *base, char **envp, const char *Filename); // === Imports === extern char gLinkedBase[]; -extern tLoadedLib gLoadedLibraries[]; char **gEnvP; extern int memcmp(const void *m1, const void *m2, size_t size); @@ -41,10 +40,6 @@ void *SoMain(void *base, int argc, char **argv, char **envp) for(;;); } - gLoadedLibraries[0].Base = &gLinkedBase; - // 'libld-acess.so' because that is what applications link against - gLoadedLibraries[0].Name = "/Acess/Libs/libld-acess.so"; - // Otherwise do relocations //ret = DoRelocate( base, envp, "Executable" ); ret = DoRelocate( base, NULL, "Executable" ); -- 2.20.1