-\r
-/**\r
- * \fn Uint IsFileLoaded(char *file)\r
- * \brief Determine if a file is already loaded\r
- */\r
-Uint IsFileLoaded(char *file)\r
-{\r
- int i;\r
- DEBUGS("IsFileLoaded: (file='%s')\n", file);\r
- for( i = 0; i < MAX_LOADED_LIBRARIES; i++ )\r
- {\r
- if(gLoadedLibraries[i].Base == 0) break; // Last entry has Base set to NULL\r
- if(strcmp(gLoadedLibraries[i].Name, file) == 0) {\r
- DEBUGS("IsFileLoaded: Found %i (0x%x)\n", i, gLoadedLibraries[i].Base);\r
- return gLoadedLibraries[i].Base;\r
- }\r
- }\r
- DEBUGS("IsFileLoaded: Not Found\n");\r
- return 0;\r
-}\r
-\r
-/**\r
- * \fn void AddLoaded(char *File, Uint base)\r
- * \brief Add a file to the loaded list\r
+
+/**
+ */
+Uint LoadLibrary(char *SoName, char *SearchDir, char **envp)
+{
+ char sTmpName[1024];
+ char *filename;
+ Uint iArg;
+ void (*fEntry)(int, int, char *[], char**);
+
+ DEBUGS("LoadLibrary: (filename='%s', envp=0x%x)\n", filename, envp);
+
+ // Create Temp Name
+ filename = FindLibrary(sTmpName, SoName, SearchDir);
+ if(filename == NULL) {
+ DEBUGS("LoadLibrary: RETURN 0\n");
+ return 0;
+ }
+ DEBUGS(" LoadLibrary: filename='%s'\n", filename);
+
+ if( (iArg = IsFileLoaded(filename)) )
+ return iArg;
+
+ // Load Library
+ iArg = SysLoadBin(filename, (Uint*)&fEntry);
+ if(iArg == 0) {
+ DEBUGS("LoadLibrary: RETURN 0\n");
+ return 0;
+ }
+
+ DEBUGS(" LoadLibrary: iArg=0x%x, iEntry=0x%x\n", iArg, fEntry);
+
+ // Load Symbols
+ fEntry = (void*)DoRelocate( iArg, envp, filename );
+
+ // Call Entrypoint
+ DEBUGS(" LoadLibrary: '%s' Entry 0x%x\n", SoName, fEntry);
+ fEntry(iArg, 0, NULL, envp);
+
+ DEBUGS("LoadLibrary: RETURN 1\n");
+ return iArg;
+}
+
+/**
+ * \fn Uint IsFileLoaded(char *file)
+ * \brief Determine if a file is already loaded
+ */
+Uint IsFileLoaded(char *file)
+{
+ int i;
+ DEBUGS("IsFileLoaded: (file='%s')", file);
+ 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);
+ return gLoadedLibraries[i].Base;
+ }
+ }
+ DEBUGS("IsFileLoaded: Not Found");
+ return 0;
+}
+
+/**
+ * \fn void AddLoaded(char *File, Uint base)
+ * \brief Add a file to the loaded list