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);
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");
#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
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 );
}
else
newproc->RootDir = NULL;
newproc->nThreads = 1;
+ // Reference all handles in the VFS
+ VFS_ReferenceUserHandles();
}
else {
new->Process->nThreads ++;
{
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 );
}
{
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 );
}
{
tVFS_Handle *ret;
int i;
+ int max_handles = *Threads_GetMaxFD();
// Check if this process has any handles
if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 )
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 );
}
{
tVFS_Handle *h = &handles[i];
+ if( !h->Node )
+ continue ;
if( h->Node->Type && h->Node->Type->Reference )
h->Node->Type->Reference( h->Node );
}
{
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 );
}