From: John Hodge Date: Mon, 30 Jan 2012 05:57:24 +0000 (+0800) Subject: Bugfixing X-Git-Tag: rel0.15~792^2~4 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=675118a5a3e81149709179b4f52281d52092b233;p=tpg%2Facess2.git Bugfixing --- diff --git a/Kernel/binary.c b/Kernel/binary.c index a14bd4a9..b776fed0 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -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); diff --git a/Kernel/modules.c b/Kernel/modules.c index c0c02161..98ca1a1e 100644 --- a/Kernel/modules.c +++ b/Kernel/modules.c @@ -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"); diff --git a/Kernel/threads.c b/Kernel/threads.c index 87d30d3d..956eede8 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -9,6 +9,7 @@ #include #include #include +#include // 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 ++; diff --git a/Kernel/vfs/handle.c b/Kernel/vfs/handle.c index ae8b058f..d22f9656 100644 --- a/Kernel/vfs/handle.c +++ b/Kernel/vfs/handle.c @@ -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 ); }