X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Fld-acess.so_src%2Floadlib.c;h=88aafc31a98010ebbed0ec94810612be8d0e04c1;hb=7b64f5e7f00e445a5637e9e3289a1332a14d28e5;hp=3f8e674260b3a988554a9ae724d216b75c1e57a5;hpb=c9f3dc274e9e95b07966bc50c02b73887822556a;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/ld-acess.so_src/loadlib.c b/Usermode/Libraries/ld-acess.so_src/loadlib.c index 3f8e6742..88aafc31 100644 --- a/Usermode/Libraries/ld-acess.so_src/loadlib.c +++ b/Usermode/Libraries/ld-acess.so_src/loadlib.c @@ -4,6 +4,7 @@ */ #include "common.h" #include +#include #define DEBUG 0 @@ -15,7 +16,6 @@ // === PROTOTYPES === void *IsFileLoaded(const char *file); - int GetSymbolFromBase(void *base, const char *name, void **ret, size_t *size); // === IMPORTS === extern const struct { @@ -24,6 +24,7 @@ extern const struct { } caLocalExports[]; extern const int ciNumLocalExports; extern char **gEnvP; +extern char gLinkedBase[]; // === GLOABLS === tLoadedLib gLoadedLibraries[MAX_LOADED_LIBRARIES]; @@ -32,6 +33,18 @@ char *gsNextAvailString = gsLoadedStrings; //tLoadLib *gpLoadedLibraries = NULL; // === CODE === +void ldacess_DumpLoadedLibraries(void) +{ + for( int i = 0; i < MAX_LOADED_LIBRARIES; i ++ ) + { + if(gLoadedLibraries[i].Base == 0) break; // Last entry has Base set to NULL + _SysDebug("%p: %s", + gLoadedLibraries[i].Base, + gLoadedLibraries[i].Name + ); + } +} + const char *FindLibrary(char *DestBuf, const char *SoName, const char *ExtraSearchDir) { // -- #1: Executable Specified @@ -78,7 +91,7 @@ void *LoadLibrary(const char *SoName, const char *SearchDir, char **envp) DEBUGS(" LoadLibrary: SysLoadBin()"); // Load Library - base = SysLoadBin(filename, (void**)&fEntry); + base = _SysLoadBin(filename, (void**)&fEntry); if(!base) { DEBUGS("LoadLibrary: RETURN 0"); return 0; @@ -88,6 +101,9 @@ void *LoadLibrary(const char *SoName, const char *SearchDir, char **envp) // Load Symbols fEntry = DoRelocate( base, envp, filename ); + if( !fEntry ) { + return 0; + } // Call Entrypoint DEBUGS(" LoadLibrary: '%s' Entry %p", SoName, fEntry); @@ -105,6 +121,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 @@ -170,7 +195,7 @@ void Unload(void *Base) if(id == MAX_LOADED_LIBRARIES) return; // Unload Binary - SysUnloadBin( Base ); + _SysUnloadBin( Base ); // Save String Pointer str = gLoadedLibraries[id].Name; @@ -198,26 +223,31 @@ void Unload(void *Base) \fn Uint GetSymbol(const char *name) \brief Gets a symbol value from a loaded library */ -void *GetSymbol(const char *name, size_t *Size) +int GetSymbol(const char *name, void **Value, size_t *Size) { int i; - void *ret; //SysDebug("ciNumLocalExports = %i", ciNumLocalExports); for(i=0;i