X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Fld-acess.so_src%2Floadlib.c;h=53073019330baac99c440289cd7c442a2165743d;hb=b806b8f55067584cb90fe20277235369a1111c66;hp=a5f0bc260c9f8e65d92f326cd6505e7f61df7b36;hpb=560e97380a10c4a8cd8b14b2b7f5d133e32759e0;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 a5f0bc26..53073019 100644 --- a/Usermode/Libraries/ld-acess.so_src/loadlib.c +++ b/Usermode/Libraries/ld-acess.so_src/loadlib.c @@ -3,6 +3,8 @@ By thePowersGang */ #include "common.h" +#include +#include #define DEBUG 0 @@ -13,15 +15,16 @@ #endif // === PROTOTYPES === -Uint IsFileLoaded(char *file); - int GetSymbolFromBase(Uint base, char *name, Uint *ret); +void *IsFileLoaded(const char *file); // === IMPORTS === extern const struct { - Uint Value; + void *Value; char *Name; } caLocalExports[]; extern const int ciNumLocalExports; +extern char **gEnvP; +extern char gLinkedBase[]; // === GLOABLS === tLoadedLib gLoadedLibraries[MAX_LOADED_LIBRARIES]; @@ -30,7 +33,7 @@ char *gsNextAvailString = gsLoadedStrings; //tLoadLib *gpLoadedLibraries = NULL; // === CODE === -char *FindLibrary(char *DestBuf, char *SoName, char *ExtraSearchDir) +const char *FindLibrary(char *DestBuf, const char *SoName, const char *ExtraSearchDir) { // -- #1: Executable Specified if(ExtraSearchDir) @@ -54,60 +57,73 @@ char *FindLibrary(char *DestBuf, char *SoName, char *ExtraSearchDir) /** */ -Uint LoadLibrary(char *SoName, char *SearchDir, char **envp) +void *LoadLibrary(const char *SoName, const char *SearchDir, char **envp) { char sTmpName[1024]; - char *filename; - Uint iArg; - void (*fEntry)(int, int, char *[], char**); + const char *filename; + void *base; + void (*fEntry)(void *, int, char *[], char**); - DEBUGS("LoadLibrary: (filename='%s', envp=0x%x)\n", filename, envp); + DEBUGS("LoadLibrary: (SoName='%s', SearchDir='%s', envp=%p)", SoName, SearchDir, envp); // Create Temp Name filename = FindLibrary(sTmpName, SoName, SearchDir); if(filename == NULL) { - DEBUGS("LoadLibrary: RETURN 0\n"); + DEBUGS("LoadLibrary: RETURN 0"); return 0; } - DEBUGS(" LoadLibrary: filename='%s'\n", filename); - - if( (iArg = IsFileLoaded(filename)) ) - return iArg; + DEBUGS(" LoadLibrary: filename='%s'", filename); + if( (base = IsFileLoaded(filename)) ) + return base; + + DEBUGS(" LoadLibrary: SysLoadBin()"); // Load Library - iArg = SysLoadBin(filename, (Uint*)&fEntry); - if(iArg == 0) { - DEBUGS("LoadLibrary: RETURN 0\n"); + base = _SysLoadBin(filename, (void**)&fEntry); + if(!base) { + DEBUGS("LoadLibrary: RETURN 0"); return 0; } - DEBUGS(" LoadLibrary: iArg=0x%x, iEntry=0x%x\n", iArg, fEntry); + DEBUGS(" LoadLibrary: iArg=%p, fEntry=%p", base, fEntry); // Load Symbols - fEntry = (void*)DoRelocate( iArg, envp, filename ); + fEntry = DoRelocate( base, envp, filename ); + if( !fEntry ) { + return 0; + } // Call Entrypoint - DEBUGS(" LoadLibrary: '%s' Entry 0x%x\n", SoName, fEntry); - fEntry(iArg, 0, NULL, envp); + DEBUGS(" LoadLibrary: '%s' Entry %p", SoName, fEntry); + fEntry(base, 0, NULL, gEnvP); - DEBUGS("LoadLibrary: RETURN 1\n"); - return iArg; + DEBUGS("LoadLibrary: RETURN 1"); + return base; } /** * \fn Uint IsFileLoaded(char *file) * \brief Determine if a file is already loaded */ -Uint IsFileLoaded(char *file) +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 DEBUGS(" strcmp('%s', '%s')", gLoadedLibraries[i].Name, file); if(strcmp(gLoadedLibraries[i].Name, file) == 0) { - DEBUGS("IsFileLoaded: Found %i (0x%x)", i, gLoadedLibraries[i].Base); + DEBUGS("IsFileLoaded: Found %i (%p)", i, gLoadedLibraries[i].Base); return gLoadedLibraries[i].Base; } } @@ -119,12 +135,12 @@ Uint IsFileLoaded(char *file) * \fn void AddLoaded(char *File, Uint base) * \brief Add a file to the loaded list */ -void AddLoaded(char *File, Uint base) +void AddLoaded(const char *File, void *base) { int i, length; char *name = gsNextAvailString; - DEBUGS("AddLoaded: (File='%s', base=0x%x)", File, base); + DEBUGS("AddLoaded: (File='%s', base=%p)", File, base); // Find a free slot for( i = 0; i < MAX_LOADED_LIBRARIES; i ++ ) @@ -148,14 +164,14 @@ void AddLoaded(char *File, Uint base) strcpy(name, File); gLoadedLibraries[i].Name = name; gsNextAvailString = &name[length+1]; - DEBUGS("'%s' (0x%x) loaded as %i\n", name, base, i); + DEBUGS("'%s' (%p) loaded as %i", name, base, i); return; } /** * \fn void Unload(Uint Base) */ -void Unload(Uint Base) +void Unload(void *Base) { int i, j; int id; @@ -167,7 +183,7 @@ void Unload(Uint Base) if(id == MAX_LOADED_LIBRARIES) return; // Unload Binary - SysUnloadBin( Base ); + _SysUnloadBin( Base ); // Save String Pointer str = gLoadedLibraries[id].Name; @@ -192,28 +208,34 @@ void Unload(Uint Base) } /** - \fn Uint GetSymbol(char *name) + \fn Uint GetSymbol(const char *name) \brief Gets a symbol value from a loaded library */ -Uint GetSymbol(char *name) +int GetSymbol(const char *name, void **Value, size_t *Size) { int i; - Uint ret; //SysDebug("ciNumLocalExports = %i", ciNumLocalExports); for(i=0;i