Commit in reactos on MAIN
drivers/video/videoprt/videoprt.c+2-21.26 -> 1.27
ntoskrnl/include/internal/ps.h+3-61.65 -> 1.66
ntoskrnl/include/internal/i386/ps.h+1-11.9 -> 1.10
ntoskrnl/ke/i386/tskswitch.S+2-21.16 -> 1.17
ntoskrnl/ke/main.c+2-21.192 -> 1.193
           /process.c+14-121.26 -> 1.27
ntoskrnl/ldr/sysdll.c+31-91.23 -> 1.24
ntoskrnl/lpc/send.c+3-31.16 -> 1.17
ntoskrnl/mm/virtual.c+57-401.79 -> 1.80
ntoskrnl/ps/kill.c+11-31.73 -> 1.74
           /process.c+10-41.139 -> 1.140
+136-84
11 modified files
- Removed the member OldProcess from the ETHREAD structure.

reactos/drivers/video/videoprt
videoprt.c 1.26 -> 1.27
diff -u -r1.26 -r1.27
--- videoprt.c	3 Jul 2004 17:40:21 -0000	1.26
+++ videoprt.c	31 Aug 2004 20:17:17 -0000	1.27
@@ -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 @@
    *CallingProcess = PsGetCurrentProcess(); 
    if (*CallingProcess != Csrss) 
    { 
-      if (PsGetCurrentThread()->OldProcess != NULL)
+      if (PsGetCurrentThread()->ThreadsProcess != *CallingProcess)
       { 
          *PrevAttachedProcess = *CallingProcess; 
          KeDetachProcess(); 

reactos/ntoskrnl/include/internal
ps.h 1.65 -> 1.66
diff -u -r1.65 -r1.66
--- ps.h	21 Aug 2004 12:34:58 -0000	1.65
+++ ps.h	31 Aug 2004 20:17:17 -0000	1.66
@@ -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 @@
    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 @@
   BOOLEAN ActiveImpersonationInfo;                  /* 23B/267 */
   ULONG PerformanceCountHigh;                       /* 23C/268 */
 
-  /*
-   * Added by David Welch (welch@cwcom.net)
-   */
-  struct _EPROCESS* OldProcess;                     /* 240/26C */
 
   struct _W32THREAD* Win32Thread;
   

reactos/ntoskrnl/include/internal/i386
ps.h 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- ps.h	30 Dec 2003 18:52:04 -0000	1.9
+++ ps.h	31 Aug 2004 20:17:17 -0000	1.10
@@ -26,12 +26,12 @@
 #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

reactos/ntoskrnl/ke/i386
tskswitch.S 1.16 -> 1.17
diff -u -r1.16 -r1.17
--- tskswitch.S	19 Aug 2004 21:51:06 -0000	1.16
+++ tskswitch.S	31 Aug 2004 20:17:18 -0000	1.17
@@ -87,7 +87,7 @@
 	 * 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 @@
 	/*
 	 * 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
 

reactos/ntoskrnl/ke
main.c 1.192 -> 1.193
diff -u -r1.192 -r1.193
--- main.c	15 Aug 2004 16:39:05 -0000	1.192
+++ main.c	31 Aug 2004 20:17:18 -0000	1.193
@@ -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 @@
   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);

reactos/ntoskrnl/ke
process.c 1.26 -> 1.27
diff -u -r1.26 -r1.27
--- process.c	27 Aug 2004 10:24:04 -0000	1.26
+++ process.c	31 Aug 2004 20:17:18 -0000	1.27
@@ -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 @@
    
    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 @@
 
    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 @@
    
    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);

reactos/ntoskrnl/ldr
sysdll.c 1.23 -> 1.24
diff -u -r1.23 -r1.24
--- sysdll.c	15 Aug 2004 16:39:06 -0000	1.23
+++ sysdll.c	31 Aug 2004 20:17:18 -0000	1.24
@@ -77,7 +77,7 @@
    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 @@
 	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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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);

reactos/ntoskrnl/lpc
send.c 1.16 -> 1.17
diff -u -r1.16 -r1.17
--- send.c	15 Aug 2004 16:39:06 -0000	1.16
+++ send.c	31 Aug 2004 20:17:18 -0000	1.17
@@ -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 @@
       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();
      }
 

reactos/ntoskrnl/mm
virtual.c 1.79 -> 1.80
diff -u -r1.79 -r1.80
--- virtual.c	17 Jul 2004 03:03:52 -0000	1.79
+++ virtual.c	31 Aug 2004 20:17:18 -0000	1.80
@@ -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 @@
    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 @@
       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 @@
       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;
 

reactos/ntoskrnl/ps
kill.c 1.73 -> 1.74
diff -u -r1.73 -r1.74
--- kill.c	15 Aug 2004 16:39:10 -0000	1.73
+++ kill.c	31 Aug 2004 20:17:18 -0000	1.74
@@ -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 @@
 		   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 @@
         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);

reactos/ntoskrnl/ps
process.c 1.139 -> 1.140
diff -u -r1.139 -r1.140
--- process.c	15 Aug 2004 16:39:10 -0000	1.139
+++ process.c	31 Aug 2004 20:17:18 -0000	1.140
@@ -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 @@
 
   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 @@
 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);
      }
 }
 
CVSspam 0.2.8