3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: process.c,v 1.11 2002/09/08 10:23:29 chorns Exp $
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/ke/process.c
23 * PURPOSE: Microkernel process management
24 * PROGRAMMER: David Welch (welch@cwcom.net)
30 /* INCLUDES *****************************************************************/
32 #include <ddk/ntddk.h>
33 #include <internal/ke.h>
34 #include <internal/mm.h>
35 #include <internal/ps.h>
38 #include <internal/debug.h>
40 /* FUNCTIONS *****************************************************************/
43 KeAttachProcess (PEPROCESS Process
)
46 PETHREAD CurrentThread
;
49 DPRINT("KeAttachProcess(Process %x)\n",Process
);
51 CurrentThread
= PsGetCurrentThread();
53 if (CurrentThread
->OldProcess
!= NULL
)
55 DbgPrint("Invalid attach (thread is already attached)\n");
59 KeRaiseIrql(DISPATCH_LEVEL
, &oldlvl
);
61 CurrentThread
->OldProcess
= PsGetCurrentProcess();
62 CurrentThread
->ThreadsProcess
= Process
;
63 PageDir
= CurrentThread
->ThreadsProcess
->Pcb
.DirectoryTableBase
.u
.LowPart
;
64 DPRINT("Switching process context to %x\n",PageDir
)
65 __asm__("movl %0,%%cr3\n\t"
74 KeDetachProcess (VOID
)
77 PETHREAD CurrentThread
;
80 DPRINT("KeDetachProcess()\n");
82 CurrentThread
= PsGetCurrentThread();
84 if (CurrentThread
->OldProcess
== NULL
)
86 DbgPrint("Invalid detach (thread was not attached)\n");
90 KeRaiseIrql(DISPATCH_LEVEL
, &oldlvl
);
92 CurrentThread
->ThreadsProcess
= CurrentThread
->OldProcess
;
93 CurrentThread
->OldProcess
= NULL
;
94 PageDir
= CurrentThread
->ThreadsProcess
->Pcb
.DirectoryTableBase
.u
.LowPart
;
95 __asm__("movl %0,%%cr3\n\t"