#endif
// === PROTOTYPES ===
-Uint IsFileLoaded(char *file);
- int GetSymbolFromBase(Uint base, char *name, Uint *ret);
+void *IsFileLoaded(char *file);
+ int GetSymbolFromBase(void *base, const char *name, void **ret);
-// === CONSTANTS ===
-const struct {
- Uint Value;
+// === IMPORTS ===
+extern const struct {
+ void *Value;
char *Name;
-} caLocalExports[] = {
- {(Uint)gLoadedLibraries, "gLoadedLibraries"}
-};
+} caLocalExports[];
+extern const int ciNumLocalExports;
// === GLOABLS ===
tLoadedLib gLoadedLibraries[MAX_LOADED_LIBRARIES];
/**
*/
-Uint LoadLibrary(char *SoName, char *SearchDir, char **envp)
+void *LoadLibrary(char *SoName, char *SearchDir, char **envp)
{
char sTmpName[1024];
char *filename;
- Uint iArg;
- void (*fEntry)(int, int, char *[], char**);
+ void *base;
+ void (*fEntry)(void *, int, char *[], char**);
DEBUGS("LoadLibrary: (filename='%s', envp=0x%x)\n", filename, envp);
}
DEBUGS(" LoadLibrary: filename='%s'\n", filename);
- if( (iArg = IsFileLoaded(filename)) )
- return iArg;
+ if( (base = IsFileLoaded(filename)) )
+ return base;
// Load Library
- iArg = SysLoadBin(filename, (Uint*)&fEntry);
- if(iArg == 0) {
+ base = SysLoadBin(filename, (void**)&fEntry);
+ if(!base) {
DEBUGS("LoadLibrary: RETURN 0\n");
return 0;
}
- DEBUGS(" LoadLibrary: iArg=0x%x, iEntry=0x%x\n", iArg, fEntry);
+ DEBUGS(" LoadLibrary: iArg=%p, iEntry=0x%x\n", base, fEntry);
// Load Symbols
- fEntry = (void*)DoRelocate( iArg, envp, filename );
+ fEntry = DoRelocate( base, envp, filename );
// Call Entrypoint
DEBUGS(" LoadLibrary: '%s' Entry 0x%x\n", SoName, fEntry);
- fEntry(iArg, 0, NULL, envp);
+ fEntry(base, 0, NULL, envp);
DEBUGS("LoadLibrary: RETURN 1\n");
- return iArg;
+ return base;
}
/**
* \fn Uint IsFileLoaded(char *file)
* \brief Determine if a file is already loaded
*/
-Uint IsFileLoaded(char *file)
+void *IsFileLoaded(char *file)
{
int i;
DEBUGS("IsFileLoaded: (file='%s')", file);
* \fn void AddLoaded(char *File, Uint base)
* \brief Add a file to the loaded list
*/
-void AddLoaded(char *File, Uint base)
+void AddLoaded(char *File, void *base)
{
int i, length;
char *name = gsNextAvailString;
/**
* \fn void Unload(Uint Base)
*/
-void Unload(Uint Base)
+void Unload(void *Base)
{
int i, j;
int id;
}
/**
- \fn Uint GetSymbol(char *name)
+ \fn Uint GetSymbol(const char *name)
\brief Gets a symbol value from a loaded library
*/
-Uint GetSymbol(char *name)
+void *GetSymbol(const char *name)
{
int i;
- Uint ret;
- for(i=0;i<sizeof(caLocalExports)/sizeof(caLocalExports[0]);i++)
+ void *ret;
+
+ //SysDebug("ciNumLocalExports = %i", ciNumLocalExports);
+ for(i=0;i<ciNumLocalExports;i++)
{
if( strcmp(caLocalExports[i].Name, name) == 0 )
return caLocalExports[i].Value;
}
- for(i=0;i<sizeof(gLoadedLibraries)/sizeof(gLoadedLibraries[0]);i++)
+ // Entry 0 is ld-acess, ignore it
+ for(i = 1; i < MAX_LOADED_LIBRARIES; i ++)
{
if(gLoadedLibraries[i].Base == 0) break;
- //SysDebug(" GetSymbol: Trying 0x%x, '%s'\n",
+ //SysDebug(" GetSymbol: Trying 0x%x, '%s'",
// gLoadedLibraries[i].Base, gLoadedLibraries[i].Name);
if(GetSymbolFromBase(gLoadedLibraries[i].Base, name, &ret)) return ret;
}
- SysDebug("GetSymbol: === Symbol '%s' not found ===\n", name);
+ SysDebug("GetSymbol: === Symbol '%s' not found ===", name);
return 0;
}
\fn int GetSymbolFromBase(Uint base, char *name, Uint *ret)
\breif Gets a symbol from a specified library
*/
-int GetSymbolFromBase(Uint base, char *name, Uint *ret)
+int GetSymbolFromBase(void *base, const char *name, void **ret)
{
if(*(Uint32*)base == (0x7F|('E'<<8)|('L'<<16)|('F'<<24)))
return ElfGetSymbol(base, name, ret);
if(*(Uint16*)base == ('M'|('Z'<<8)))
return PE_GetSymbol(base, name, ret);
+ SysDebug("Unknown type at %p", base);
return 0;
}