Replace rand() implementation - fixes threading lockups
[tpg/acess2.git] / Kernel / binary.c
index 72e8210..dffb178 100644 (file)
@@ -2,7 +2,7 @@
  * Acess2
  * Common Binary Loader
  */
-#define DEBUG  0
+#define DEBUG  1
 #include <acess.h>
 #include <binary.h>
 #include <mm_virt.h>
@@ -45,11 +45,11 @@ Uint        Binary_GetSymbolEx(char *Name, Uint *Value);
 Uint   Binary_FindSymbol(void *Base, char *Name, Uint *Val);
 
 // === GLOBALS ===
- int   glBinListLock = 0;
+tShortSpinlock glBinListLock;
 tBinary        *glLoadedBinaries = NULL;
 char   **gsaRegInterps = NULL;
  int   giRegInterps = 0;
- int   glKBinListLock = 0;
+tShortSpinlock glKBinListLock;
 tKernelBin     *glLoadedKernelLibs;
 tBinaryType    *gRegBinTypes = &gELF_Info;
  
@@ -121,6 +121,7 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP)
        argenvBuf = malloc(argenvBytes);
        if(argenvBuf == NULL) {
                Log_Error("BIN", "Proc_Execve - What the hell? The kernel is out of heap space");
+               LEAVE('i', 0);
                return 0;
        }
        strBuf = argenvBuf + (argc+1)*sizeof(void*) + (envc+1)*sizeof(void*);
@@ -158,6 +159,7 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP)
        if(bases[0] == 0)
        {
                Log_Warning("BIN", "Proc_Execve - Unable to load '%s'", Threads_GetName(-1));
+               LEAVE('-');
                Threads_Exit(0, 0);
                for(;;);
        }
@@ -171,6 +173,9 @@ int Proc_Execve(char *File, char **ArgV, char **EnvP)
 
 /**
  * \fn Uint Binary_Load(char *file, Uint *entryPoint)
+ * \brief Load a binary into the current address space
+ * \param file Path to binary to load
+ * \param entryPoint   Pointer for exectuable entry point
  */
 Uint Binary_Load(char *file, Uint *entryPoint)
 {
@@ -178,7 +183,7 @@ Uint Binary_Load(char *file, Uint *entryPoint)
        tBinary *pBinary;
        Uint    base = -1;
 
-       ENTER("sfile", file);
+       ENTER("sfile pentryPoint", file, entryPoint);
        
        // Sanity Check Argument
        if(file == NULL) {
@@ -188,6 +193,7 @@ Uint Binary_Load(char *file, Uint *entryPoint)
 
        // Get True File Path
        sTruePath = VFS_GetTruePath(file);
+       LOG("sTruePath = %p", sTruePath);
        
        if(sTruePath == NULL) {
                Log_Warning("BIN", "'%s' does not exist.", file);
@@ -196,6 +202,8 @@ Uint Binary_Load(char *file, Uint *entryPoint)
        }
        
        LOG("sTruePath = '%s'", sTruePath);
+       
+       // TODO: Also get modifcation time
 
        // Check if the binary has already been loaded
        if( !(pBinary = Binary_GetInfo(sTruePath)) )
@@ -501,10 +509,10 @@ tBinary *Binary_DoLoad(char *truePath)
        VFS_Close(fp);
        
        // Add to the list
-       LOCK(&glBinListLock);
+       SHORTLOCK(&glBinListLock);
        pBinary->Next = glLoadedBinaries;
        glLoadedBinaries = pBinary;
-       RELEASE(&glBinListLock);
+       SHORTREL(&glBinListLock);
        
        // Return
        LEAVE('p', pBinary);
@@ -745,10 +753,10 @@ void *Binary_LoadKernel(char *File)
        pKBinary = malloc(sizeof(*pKBinary));
        pKBinary->Base = (void*)base;
        pKBinary->Info = pBinary;
-       LOCK( &glKBinListLock );
+       SHORTLOCK( &glKBinListLock );
        pKBinary->Next = glLoadedKernelLibs;
        glLoadedKernelLibs = pKBinary;
-       RELEASE( &glKBinListLock );
+       SHORTREL( &glKBinListLock );
        
        LEAVE('p', base);
        return (void*)base;

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