Bugfixing
authorJohn Hodge <[email protected]>
Mon, 30 Jan 2012 05:57:24 +0000 (13:57 +0800)
committerJohn Hodge <[email protected]>
Mon, 30 Jan 2012 05:57:24 +0000 (13:57 +0800)
Kernel/binary.c
Kernel/modules.c
Kernel/threads.c
Kernel/vfs/handle.c

index a14bd4a..b776fed 100644 (file)
@@ -232,7 +232,17 @@ int Proc_Execve(const char *File, const char **ArgV, const char **EnvP, int Data
        Threads_SetName(File);
        
        // --- Clear User Address space
-       MM_ClearUser();
+       // NOTE: This is a little roundabout, maybe telling ClearUser to not touch the
+       //       PPD area would be a better idea.
+       {
+                int    nfd = *Threads_GetMaxFD();
+               void    *handles;
+               handles = VFS_SaveHandles(nfd, NULL);
+               VFS_CloseAllUserHandles();
+               MM_ClearUser();
+               VFS_RestoreHandles(nfd, handles);
+               VFS_FreeSavedHandles(nfd, handles);
+       }
        
        // --- Load new binary
        base = Binary_Load(File, &entry);
index c0c0216..98ca1a1 100644 (file)
@@ -168,7 +168,7 @@ int Module_int_Initialise(tModule *Module, const char *ArgString)
                        Log_Warning("Module", "Unable to load, reason: Miscelanious");
                        break;
                case MODULE_ERR_NOTNEEDED:
-                       Log_Warning("Module", "Unable to load, reason: Module not needed");
+                       Log_Debug("Module", "Unable to load, reason: Module not needed");
                        break;
                case MODULE_ERR_MALLOC:
                        Log_Warning("Module", "Unable to load, reason: Error in malloc/realloc/calloc, probably not good");
index 87d30d3..956eede 100644 (file)
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <hal_proc.h>
 #include <semaphore.h>
+#include <vfs_threads.h>       // VFS Handle maintainence
 
 // Configuration
 #define DEBUG_TRACE_TICKETS    0       // Trace ticket counts
@@ -151,11 +152,16 @@ void Threads_Delete(tThread *Thread)
        if( Thread->Process->nThreads == 0 )
        {
                tProcess        *proc = Thread->Process;
+               // VFS Cleanup
+               VFS_CloseAllUserHandles();
+               // Architecture cleanup
                Proc_ClearProcess( proc );
+               // VFS Configuration strings
                if( proc->CurrentWorkingDir)
                        free( proc->CurrentWorkingDir );
                if( proc->RootDir )
                        free( proc->RootDir );
+               // Process descriptor
                free( proc );
        }
        
@@ -319,6 +325,8 @@ tThread *Threads_CloneTCB(Uint Flags)
                else
                        newproc->RootDir = NULL;
                newproc->nThreads = 1;
+               // Reference all handles in the VFS
+               VFS_ReferenceUserHandles();
        }
        else {
                new->Process->nThreads ++;
index ae8b058..d22f965 100644 (file)
@@ -119,11 +119,17 @@ void VFS_ReferenceUserHandles(void)
 {
         int    i;
         int    max_handles = *Threads_GetMaxFD();
+
+       // Check if this process has any handles
+       if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
+               return ;
        
        for( i = 0; i < max_handles; i ++ )
        {
                tVFS_Handle     *h;
                h = &gaUserHandles[i];
+               if( !h->Node )
+                       continue ;
                if( h->Node->Type && h->Node->Type->Reference )
                        h->Node->Type->Reference( h->Node );
        }
@@ -133,11 +139,17 @@ void VFS_CloseAllUserHandles(void)
 {
         int    i;
         int    max_handles = *Threads_GetMaxFD();
+
+       // Check if this process has any handles
+       if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
+               return ;
        
        for( i = 0; i < max_handles; i ++ )
        {
                tVFS_Handle     *h;
                h = &gaUserHandles[i];
+               if( !h->Node )
+                       continue ;
                if( h->Node->Type && h->Node->Type->Close )
                        h->Node->Type->Close( h->Node );
        }
@@ -150,6 +162,7 @@ void *VFS_SaveHandles(int NumFDs, int *FDs)
 {
        tVFS_Handle     *ret;
         int    i;
+        int    max_handles = *Threads_GetMaxFD();
        
        // Check if this process has any handles
        if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
@@ -160,20 +173,29 @@ void *VFS_SaveHandles(int NumFDs, int *FDs)
        if( !ret )
                return NULL;    
 
+       if( NumFDs > max_handles )
+               NumFDs = max_handles;
+
        // Take copies of the handles
        for( i = 0; i < NumFDs; i ++ )
        {
                tVFS_Handle     *h;
-               h = VFS_GetHandle(FDs[i] & (VFS_KERNEL_FLAG - 1));
-               if(!h) {
-                       Log_Warning("VFS", "VFS_SaveHandles - Invalid FD %i",
-                               FDs[i] & (VFS_KERNEL_FLAG - 1) );
-                       free(ret);
-                       return NULL;
+               if( FDs == NULL )
+                       h = &gaUserHandles[i];
+               else {
+                       h = VFS_GetHandle(FDs[i] & (VFS_KERNEL_FLAG - 1));
+                       if(!h) {
+                               Log_Warning("VFS", "VFS_SaveHandles - Invalid FD %i",
+                                       FDs[i] & (VFS_KERNEL_FLAG - 1) );
+                               free(ret);
+                               return NULL;
+                       }
                }
                memcpy( &ret[i], h, sizeof(tVFS_Handle) );
                
                // Reference node
+               if( !h->Node )
+                       continue ;
                if( h->Node->Type && h->Node->Type->Reference )
                        h->Node->Type->Reference( h->Node );
        }       
@@ -218,6 +240,8 @@ void VFS_RestoreHandles(int NumFDs, void *Handles)
        {
                tVFS_Handle     *h = &handles[i];
        
+               if( !h->Node )
+                       continue ;
                if( h->Node->Type && h->Node->Type->Reference )
                        h->Node->Type->Reference( h->Node );
        }
@@ -227,12 +251,18 @@ void VFS_FreeSavedHandles(int NumFDs, void *Handles)
 {
        tVFS_Handle     *handles = Handles;
         int    i;
+
+       // NULL = nothing to do
+       if( !Handles )
+               return ;        
        
        // Dereference all saved nodes
        for( i = 0; i < NumFDs; i ++ )
        {
                tVFS_Handle     *h = &handles[i];
        
+               if( !h->Node )
+                       continue ;
                if( h->Node->Type && h->Node->Type->Close )
                        h->Node->Type->Close( h->Node );
        }

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