- Removed the member OldProcess from the ETHREAD structure.
authorHartmut Birr <osexpert@googlemail.com>
Tue, 31 Aug 2004 20:17:18 +0000 (20:17 +0000)
committerHartmut Birr <osexpert@googlemail.com>
Tue, 31 Aug 2004 20:17:18 +0000 (20:17 +0000)
svn path=/trunk/; revision=10759

reactos/drivers/video/videoprt/videoprt.c
reactos/ntoskrnl/include/internal/i386/ps.h
reactos/ntoskrnl/include/internal/ps.h
reactos/ntoskrnl/ke/i386/tskswitch.S
reactos/ntoskrnl/ke/main.c
reactos/ntoskrnl/ke/process.c
reactos/ntoskrnl/ldr/sysdll.c
reactos/ntoskrnl/lpc/send.c
reactos/ntoskrnl/mm/virtual.c
reactos/ntoskrnl/ps/kill.c
reactos/ntoskrnl/ps/process.c

index 32a0236..7e7e167 100644 (file)
@@ -18,7 +18,7 @@
  * If not, write to the Free Software Foundation,
  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- * $Id: videoprt.c,v 1.26 2004/07/03 17:40:21 navaraf Exp $
+ * $Id: videoprt.c,v 1.27 2004/08/31 20:17:17 hbirr Exp $
  */
 
 #include "videoprt.h"
@@ -457,7 +457,7 @@ IntAttachToCSRSS(PEPROCESS *CallingProcess, PEPROCESS *PrevAttachedProcess)
    *CallingProcess = PsGetCurrentProcess(); 
    if (*CallingProcess != Csrss) 
    { 
-      if (PsGetCurrentThread()->OldProcess != NULL)
+      if (PsGetCurrentThread()->ThreadsProcess != *CallingProcess)
       { 
          *PrevAttachedProcess = *CallingProcess; 
          KeDetachProcess(); 
index 69e501e..16c6eda 100644 (file)
 #define KTHREAD_STACK_LIMIT       0x1C
 #define KTHREAD_TEB               0x20
 #define KTHREAD_KERNEL_STACK      0x28
+#define KTHREAD_APCSTATE_PROCESS  0x44
 #define KTHREAD_SERVICE_TABLE     0xDC
 #define KTHREAD_PREVIOUS_MODE     0x137
 #define KTHREAD_TRAP_FRAME        0x128
 #define KTHREAD_CALLBACK_STACK    0x120
 
-#define ETHREAD_THREADS_PROCESS   0x234
 
 #define KPROCESS_DIRECTORY_TABLE_BASE 0x18
 #define KPROCESS_LDT_DESCRIPTOR0      0x20
index e94d773..94c3b26 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: ps.h,v 1.65 2004/08/21 12:34:58 tamlin Exp $
+/* $Id: ps.h,v 1.66 2004/08/31 20:17:17 hbirr Exp $
  *
  * FILE:            ntoskrnl/ke/kthread.c
  * PURPOSE:         Process manager definitions
@@ -62,7 +62,8 @@ typedef struct _KAPC_STATE
    struct _KPROCESS* Process;
    UCHAR KernelApcInProgress;
    UCHAR KernelApcPending;
-   USHORT UserApcPending;
+   UCHAR UserApcPending;
+   UCHAR Reserved;
 } KAPC_STATE, *PKAPC_STATE, *__restrict PRKAPC_STATE;
 
 #include <poppack.h>
@@ -223,10 +224,6 @@ typedef struct _ETHREAD
   BOOLEAN ActiveImpersonationInfo;                  /* 23B/267 */
   ULONG PerformanceCountHigh;                       /* 23C/268 */
 
-  /*
-   * Added by David Welch (welch@cwcom.net)
-   */
-  struct _EPROCESS* OldProcess;                     /* 240/26C */
 
   struct _W32THREAD* Win32Thread;
   
index aa4e616..c35c930 100644 (file)
@@ -87,7 +87,7 @@ _Ki386ContextSwitch:
         * Set the current LDT
         */
         xorl   %eax, %eax
-       movl    ETHREAD_THREADS_PROCESS(%ebx), %edi
+       movl    KTHREAD_APCSTATE_PROCESS(%ebx), %edi
        testw   $0xFFFF, KPROCESS_LDT_DESCRIPTOR0(%edi)
        jz      .L4
 
@@ -141,7 +141,7 @@ _Ki386ContextSwitch:
        /*
         * Change the address space
         */
-       movl    ETHREAD_THREADS_PROCESS(%ebx), %ebx
+       movl    KTHREAD_APCSTATE_PROCESS(%ebx), %ebx
        movl    KPROCESS_DIRECTORY_TABLE_BASE(%ebx), %eax
        movl    %eax, %cr3
 
index da58ecc..dbda6c0 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: main.c,v 1.192 2004/08/15 16:39:05 chorns Exp $
+/* $Id: main.c,v 1.193 2004/08/31 20:17:18 hbirr Exp $
  *
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ke/main.c
@@ -292,7 +292,7 @@ ExpInitializeExecutive(VOID)
   assert(FIELD_OFFSET(KTHREAD, PreviousMode) == KTHREAD_PREVIOUS_MODE);
   assert(FIELD_OFFSET(KTHREAD, TrapFrame) == KTHREAD_TRAP_FRAME);
   assert(FIELD_OFFSET(KTHREAD, CallbackStack) == KTHREAD_CALLBACK_STACK);
-  assert(FIELD_OFFSET(ETHREAD, ThreadsProcess) == ETHREAD_THREADS_PROCESS);
+  assert(FIELD_OFFSET(KTHREAD, ApcState.Process) == KTHREAD_APCSTATE_PROCESS);
   assert(FIELD_OFFSET(KPROCESS, DirectoryTableBase) == 
         KPROCESS_DIRECTORY_TABLE_BASE);
   assert(FIELD_OFFSET(KPROCESS, IopmOffset) == KPROCESS_IOPM_OFFSET);
index d79b641..38208f8 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: process.c,v 1.26 2004/08/27 10:24:04 hbirr Exp $
+/* $Id: process.c,v 1.27 2004/08/31 20:17:18 hbirr Exp $
  *
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ke/process.c
@@ -49,11 +49,17 @@ KeAttachProcess (PEPROCESS Process)
    
    CurrentThread = PsGetCurrentThread();
 
-   if (CurrentThread->OldProcess != NULL)
+   if (&CurrentThread->ThreadsProcess->Pcb != CurrentThread->Tcb.ApcState.Process)
      {
-       DbgPrint("Invalid attach (thread is already attached)\n");
+       DPRINT1("Invalid attach (thread is already attached)\n");
        KEBUGCHECK(INVALID_PROCESS_ATTACH_ATTEMPT);
      }
+   if (&Process->Pcb == CurrentThread->Tcb.ApcState.Process)
+     {
+       DPRINT1("Invalid attach (process is the same)\n");
+       KEBUGCHECK(INVALID_PROCESS_ATTACH_ATTEMPT);
+     }
+
    
    /* The stack and the thread structure of the current process may be 
       located in a page which is not present in the page directory of 
@@ -71,8 +77,7 @@ KeAttachProcess (PEPROCESS Process)
 
    KiSwapApcEnvironment(&CurrentThread->Tcb, &Process->Pcb);
 
-   CurrentThread->OldProcess = PsGetCurrentProcess();
-   CurrentThread->ThreadsProcess = Process;
+   CurrentThread->Tcb.ApcState.Process = &Process->Pcb;
    PageDir = Process->Pcb.DirectoryTableBase.u.LowPart;
    DPRINT("Switching process context to %x\n",PageDir);
    Ke386SetPageTableDirectory(PageDir);
@@ -93,19 +98,16 @@ KeDetachProcess (VOID)
    
    CurrentThread = PsGetCurrentThread();
 
-   if (CurrentThread->OldProcess == NULL)
+   if (&CurrentThread->ThreadsProcess->Pcb == CurrentThread->Tcb.ApcState.Process)
      {
-       DbgPrint("Invalid detach (thread was not attached)\n");
+       DPRINT1("Invalid detach (thread was not attached)\n");
        KEBUGCHECK(INVALID_PROCESS_DETACH_ATTEMPT);
      }
    
    KeRaiseIrql(DISPATCH_LEVEL, &oldlvl);
 
-   KiSwapApcEnvironment(&CurrentThread->Tcb, &CurrentThread->OldProcess->Pcb);   
-   
-   CurrentThread->ThreadsProcess = CurrentThread->OldProcess;
-   CurrentThread->OldProcess = NULL;
-   PageDir = CurrentThread->ThreadsProcess->Pcb.DirectoryTableBase.u.LowPart;
+   KiSwapApcEnvironment(&CurrentThread->Tcb, CurrentThread->Tcb.SavedApcState.Process);
+   PageDir = CurrentThread->Tcb.ApcState.Process->DirectoryTableBase.u.LowPart;
    Ke386SetPageTableDirectory(PageDir);
 
    KeLowerIrql(oldlvl);
index 00e693e..67e2874 100644 (file)
@@ -77,7 +77,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
    UNICODE_STRING DllPathname = ROS_STRING_INITIALIZER(L"\\SystemRoot\\system32\\ntdll.dll");
    PIMAGE_DOS_HEADER   DosHeader;
    PIMAGE_NT_HEADERS   NTHeaders;
-   PEPROCESS Process;
+   PEPROCESS Process, CurrentProcess;
    ANSI_STRING ProcedureName;
    ULONG ViewSize;
    IO_STATUS_BLOCK Iosb;
@@ -190,8 +190,12 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
        return(Status);
      }
 
-   DPRINT("Attaching to Process\n");
-   KeAttachProcess(Process);
+   CurrentProcess = PsGetCurrentProcess();
+   if (Process != CurrentProcess)
+     {
+       DPRINT("Attaching to Process\n");
+       KeAttachProcess(Process);
+     }
 
    /*
     * retrieve ntdll's startup address
@@ -207,7 +211,10 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
        if (!NT_SUCCESS(Status))
         {
           DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
-          KeDetachProcess();
+          if (Process != CurrentProcess)
+            {
+              KeDetachProcess();
+            }
           ObDereferenceObject(Process);
           ZwClose(NTDllSectionHandle);
           return (Status);
@@ -229,7 +236,10 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
        if (!NT_SUCCESS(Status))
         {
           DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
-          KeDetachProcess();
+          if (Process != CurrentProcess)
+            {
+              KeDetachProcess();
+            }
           ObDereferenceObject(Process);
           ZwClose(NTDllSectionHandle);
           return (Status);
@@ -250,7 +260,10 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
        if (!NT_SUCCESS(Status))
         {
           DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
-          KeDetachProcess();
+          if (Process != CurrentProcess)
+            {
+              KeDetachProcess();
+            }
           ObDereferenceObject(Process);
           ZwClose(NTDllSectionHandle);
           return (Status);
@@ -271,7 +284,10 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
        if (!NT_SUCCESS(Status))
         {
           DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
-          KeDetachProcess();
+          if (Process != CurrentProcess)
+            {
+              KeDetachProcess();
+            }
           ObDereferenceObject(Process);
           ZwClose(NTDllSectionHandle);
           return (Status);
@@ -292,14 +308,20 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
        if (!NT_SUCCESS(Status))
         {
           DbgPrint ("LdrGetProcedureAddress failed (Status %x)\n", Status);
-          KeDetachProcess();
+          if (Process != CurrentProcess)
+            {
+              KeDetachProcess();
+            }
           ObDereferenceObject(Process);
           ZwClose(NTDllSectionHandle);
           return (Status);
         }
      }
    
-   KeDetachProcess();
+   if (Process != CurrentProcess)
+     {
+       KeDetachProcess();
+     }
    ObDereferenceObject(Process);
 
    ZwClose(NTDllSectionHandle);
index 48fa904..d29d216 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: send.c,v 1.16 2004/08/15 16:39:06 chorns Exp $
+/* $Id: send.c,v 1.17 2004/08/31 20:17:18 hbirr Exp $
  * 
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -245,13 +245,13 @@ NtRequestWaitReplyPort (IN HANDLE PortHandle,
       handle we can undo this, so everything is normal again. Need to
       re-KeAttach() before returning though */
    CurrentThread = PsGetCurrentThread();
-   if (NULL == CurrentThread->OldProcess)
+   if (&CurrentThread->ThreadsProcess->Pcb == CurrentThread->Tcb.ApcState.Process)
      {
        AttachedProcess = NULL;
      }
    else
      {
-       AttachedProcess = CurrentThread->ThreadsProcess;
+       AttachedProcess = (PEPROCESS)CurrentThread->Tcb.ApcState.Process;
        KeDetachProcess();
      }
 
index d2eae03..7640748 100644 (file)
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: virtual.c,v 1.79 2004/07/17 03:03:52 ion Exp $
+/* $Id: virtual.c,v 1.80 2004/08/31 20:17:18 hbirr Exp $
  *
  * PROJECT:     ReactOS kernel
  * FILE:        ntoskrnl/mm/virtual.c
@@ -376,7 +376,8 @@ NtReadVirtualMemory(IN HANDLE ProcessHandle,
    NTSTATUS Status;
    PMDL Mdl;
    PVOID SystemAddress;
-   PEPROCESS Process;
+   PEPROCESS Process, CurrentProcess;
+
 
    DPRINT("NtReadVirtualMemory(ProcessHandle %x, BaseAddress %x, "
           "Buffer %x, NumberOfBytesToRead %d)\n",ProcessHandle,BaseAddress,
@@ -393,31 +394,40 @@ NtReadVirtualMemory(IN HANDLE ProcessHandle,
       return(Status);
    }
 
-   Mdl = MmCreateMdl(NULL,
-                     Buffer,
-                     NumberOfBytesToRead);
-   if(Mdl == NULL) 
+   CurrentProcess = PsGetCurrentProcess();
+
+   if (Process == CurrentProcess)
    {
-      ObDereferenceObject(Process);
-      return(STATUS_NO_MEMORY);
+      memcpy(Buffer, BaseAddress, NumberOfBytesToRead);
    }
-   MmProbeAndLockPages(Mdl,
-                       UserMode,
-                       IoWriteAccess);
+   else
+   {
+      Mdl = MmCreateMdl(NULL,
+                        Buffer,
+                        NumberOfBytesToRead);
+      if(Mdl == NULL) 
+      {
+         ObDereferenceObject(Process);
+         return(STATUS_NO_MEMORY);
+      }
+      MmProbeAndLockPages(Mdl,
+                          UserMode,
+                          IoWriteAccess);
 
-   KeAttachProcess(Process);
+      KeAttachProcess(Process);
 
-   SystemAddress = MmGetSystemAddressForMdl(Mdl);
-   memcpy(SystemAddress, BaseAddress, NumberOfBytesToRead);
+      SystemAddress = MmGetSystemAddressForMdl(Mdl);
+      memcpy(SystemAddress, BaseAddress, NumberOfBytesToRead);
 
-   KeDetachProcess();
+      KeDetachProcess();
 
-   if (Mdl->MappedSystemVa != NULL)
-   {
-      MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
+      if (Mdl->MappedSystemVa != NULL)
+      {
+         MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
+      }
+      MmUnlockPages(Mdl);
+      ExFreePool(Mdl);
    }
-   MmUnlockPages(Mdl);
-   ExFreePool(Mdl);
 
    ObDereferenceObject(Process);
 
@@ -515,32 +525,39 @@ NtWriteVirtualMemory(IN HANDLE ProcessHandle,
       return(Status);
    }
 
-   Mdl = MmCreateMdl(NULL,
-                     Buffer,
-                     NumberOfBytesToWrite);
-   MmProbeAndLockPages(Mdl,
-                       UserMode,
-                       IoReadAccess);
-   if(Mdl == NULL)
+   if (Process == PsGetCurrentProcess())
    {
-      ObDereferenceObject(Process);
-      return(STATUS_NO_MEMORY);
+      memcpy(BaseAddress, Buffer, NumberOfBytesToWrite);
    }
-   KeAttachProcess(Process);
-
-   SystemAddress = MmGetSystemAddressForMdl(Mdl);
-   memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite);
+   else
+   {
+      Mdl = MmCreateMdl(NULL,
+                        Buffer,
+                        NumberOfBytesToWrite);
+      MmProbeAndLockPages(Mdl,
+                          UserMode,
+                          IoReadAccess);
+      if(Mdl == NULL)
+      {
+         ObDereferenceObject(Process);
+         return(STATUS_NO_MEMORY);
+      }
+      KeAttachProcess(Process);
 
-   KeDetachProcess();
+      SystemAddress = MmGetSystemAddressForMdl(Mdl);
+      memcpy(BaseAddress, SystemAddress, NumberOfBytesToWrite);
 
-   ObDereferenceObject(Process);
+      KeDetachProcess();
 
-   if (Mdl->MappedSystemVa != NULL)
-   {
-      MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
+      if (Mdl->MappedSystemVa != NULL)
+      {
+         MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
+      }
+      MmUnlockPages(Mdl);
+      ExFreePool(Mdl);
    }
-   MmUnlockPages(Mdl);
-   ExFreePool(Mdl);
+
+   ObDereferenceObject(Process);
 
    *NumberOfBytesWritten = NumberOfBytesToWrite;
 
index c132fda..3b020d4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: kill.c,v 1.73 2004/08/15 16:39:10 chorns Exp $
+/* $Id: kill.c,v 1.74 2004/08/31 20:17:18 hbirr Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -254,6 +254,7 @@ PiTerminateProcess(PEPROCESS Process,
                   NTSTATUS ExitStatus)
 {
    KIRQL OldIrql;
+   PEPROCESS CurrentProcess;
 
    DPRINT("PiTerminateProcess(Process %x, ExitStatus %x) PC %d HC %d\n",
           Process, ExitStatus, ObGetObjectPointerCount(Process),
@@ -267,9 +268,16 @@ PiTerminateProcess(PEPROCESS Process,
         ObDereferenceObject(Process);
        return(STATUS_SUCCESS);
      }
-   KeAttachProcess( Process );
+   CurrentProcess = PsGetCurrentProcess();
+   if (Process != CurrentProcess)
+   {
+      KeAttachProcess( Process );
+   }
    ObCloseAllHandles(Process);
-   KeDetachProcess();
+   if (Process != CurrentProcess)
+   {
+      KeDetachProcess();
+   }
    OldIrql = KeAcquireDispatcherDatabaseLock ();
    Process->Pcb.DispatcherHeader.SignalState = TRUE;
    KeDispatcherObjectWake(&Process->Pcb.DispatcherHeader);
index 54cb0fb..9a49c44 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: process.c,v 1.139 2004/08/15 16:39:10 chorns Exp $
+/* $Id: process.c,v 1.140 2004/08/31 20:17:18 hbirr Exp $
  *
  * COPYRIGHT:         See COPYING in the top level directory
  * PROJECT:           ReactOS kernel
@@ -387,7 +387,13 @@ PiDeleteProcess(PVOID ObjectBody)
 
   Context.Process = (PEPROCESS)ObjectBody;
 
-  if (PsGetCurrentProcess() == Context.Process || PsGetCurrentThread()->OldProcess == NULL)
+  if (PsGetCurrentProcess() == Context.Process ||
+      PsGetCurrentThread()->ThreadsProcess == Context.Process)
+    {
+       KEBUGCHECK(0);
+    }
+
+  if (PsGetCurrentThread()->ThreadsProcess == PsGetCurrentProcess())
     {
       Context.IsWorkerQueue = FALSE;
       PiDeleteProcessWorker(&Context);
@@ -525,13 +531,13 @@ PEPROCESS STDCALL
 IoGetCurrentProcess(VOID)
 {
    if (PsGetCurrentThread() == NULL || 
-       PsGetCurrentThread()->ThreadsProcess == NULL)
+       PsGetCurrentThread()->Tcb.ApcState.Process == NULL)
      {
        return(PsInitialSystemProcess);
      }
    else
      {
-       return(PsGetCurrentThread()->ThreadsProcess);
+       return(PEPROCESS)(PsGetCurrentThread()->Tcb.ApcState.Process);
      }
 }