From: John Hodge Date: Sun, 27 Sep 2009 09:13:05 +0000 (+0800) Subject: Fixed duplicate reference of heap locatons, and stopped CWD from being freed if it... X-Git-Tag: rel0.06~440 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=e831bb8c9823d0e8898a16edc91358027df9eb47;p=tpg%2Facess2.git Fixed duplicate reference of heap locatons, and stopped CWD from being freed if it is currently NULL --- diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index b5ff4fea..5cfc7a2e 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -236,6 +236,7 @@ void Proc_ChangeStack() int Proc_Clone(Uint *Err, Uint Flags) { tThread *newThread; + tThread *cur = Proc_GetCurThread(); Uint eip, esp, ebp; __asm__ __volatile__ ("mov %%esp, %0": "=r"(esp)); @@ -248,8 +249,10 @@ int Proc_Clone(Uint *Err, Uint Flags) *Err = -ENOMEM; return -1; } - // Base new thread on old - memcpy(newThread, gCurrentThread, sizeof(tThread)); + + // Base new thread on current + memcpy(newThread, cur, sizeof(tThread)); + // Initialise Memory Space (New Addr space or kernel stack) if(Flags & CLONE_VM) { newThread->TGID = newThread->TID; @@ -266,20 +269,20 @@ int Proc_Clone(Uint *Err, Uint Flags) } // Get ESP as a used size - esp = gCurrentThread->KernelStack - esp; + esp = cur->KernelStack - esp; // Copy used stack - memcpy( (void*)(newThread->KernelStack - esp), (void*)(gCurrentThread->KernelStack - esp), esp ); + memcpy( (void*)(newThread->KernelStack - esp), (void*)(cur->KernelStack - esp), esp ); // Get ESP as an offset in the new stack esp = newThread->KernelStack - esp; // Adjust EBP - ebp = newThread->KernelStack - (gCurrentThread->KernelStack - ebp); + ebp = newThread->KernelStack - (cur->KernelStack - ebp); // Repair EBPs & Stack Addresses // Catches arguments also, but may trash stack-address-like values for(tmpEbp = esp; tmpEbp < newThread->KernelStack; tmpEbp += 4) { - if(oldEsp < *(Uint*)tmpEbp && *(Uint*)tmpEbp < gCurrentThread->KernelStack) - *(Uint*)tmpEbp += newThread->KernelStack - gCurrentThread->KernelStack; + if(oldEsp < *(Uint*)tmpEbp && *(Uint*)tmpEbp < cur->KernelStack) + *(Uint*)tmpEbp += newThread->KernelStack - cur->KernelStack; } } @@ -287,7 +290,11 @@ int Proc_Clone(Uint *Err, Uint Flags) newThread->Next = NULL; newThread->IsLocked = 0; newThread->TID = giNextTID++; - newThread->PTID = gCurrentThread->TID; + newThread->PTID = cur->TID; + + // Create copy of name + newThread->ThreadName = malloc(strlen(cur->ThreadName)+1); + strcpy(newThread->ThreadName, cur->ThreadName); // Clear message list (messages are not inherited) newThread->Messages = NULL; diff --git a/Kernel/vfs/open.c b/Kernel/vfs/open.c index eebaa82d..dc10123b 100644 --- a/Kernel/vfs/open.c +++ b/Kernel/vfs/open.c @@ -538,8 +538,9 @@ int VFS_ChDir(char *New) // Close file VFS_Close(fd); - // Free working directory and set new one - free( CFGPTR(CFG_VFS_CWD) ); + // Free old working directory + if( CFGPTR(CFG_VFS_CWD) ) free( CFGPTR(CFG_VFS_CWD) ); + // Set new CFGPTR(CFG_VFS_CWD) = buf; Log("Updated CWD to '%s'", buf);