Merge branch 'master' of github.com:thepowersgang/acess2
[tpg/acess2.git] / Usermode / Libraries / ld-acess.so_src / loadlib.c
index f59caf2..5307301 100644 (file)
@@ -4,6 +4,7 @@
 */
 #include "common.h"
 #include <stdint.h>
+#include <acess/sys.h>
 
 #define DEBUG  0
 
@@ -23,6 +24,7 @@ extern const struct {
 }      caLocalExports[];
 extern const int       ciNumLocalExports;
 extern char    **gEnvP;
+extern char    gLinkedBase[];
 
 // === GLOABLS ===
 tLoadedLib     gLoadedLibraries[MAX_LOADED_LIBRARIES];
@@ -77,7 +79,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;
@@ -107,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
@@ -172,7 +183,7 @@ void Unload(void *Base)
        if(id == MAX_LOADED_LIBRARIES)  return;
        
        // Unload Binary
-       SysUnloadBin( Base );
+       _SysUnloadBin( Base );
        // Save String Pointer
        str = gLoadedLibraries[id].Name;
        
@@ -216,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;

UCC git Repository :: git.ucc.asn.au