:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / ke / process.c
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4  *
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.
9  *
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.
14  *
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.
18  */
19 /* $Id$
20  *
21  * PROJECT:         ReactOS kernel
22  * FILE:            ntoskrnl/ke/process.c
23  * PURPOSE:         Microkernel process management
24  * PROGRAMMER:      David Welch (welch@cwcom.net)
25  * PORTABILITY:     No.
26  * UPDATE HISTORY:
27  *                  Created 22/05/98
28  */
29
30 /* INCLUDES *****************************************************************/
31
32 #include <ddk/ntddk.h>
33 #include <internal/ke.h>
34 #include <internal/mm.h>
35 #include <internal/ps.h>
36
37 #define NDEBUG
38 #include <internal/debug.h>
39
40 /* FUNCTIONS *****************************************************************/
41
42 VOID STDCALL
43 KeAttachProcess (PEPROCESS Process)
44 {
45    KIRQL oldlvl;
46    PETHREAD CurrentThread;
47    ULONG PageDir;
48    
49    DPRINT("KeAttachProcess(Process %x)\n",Process);
50    
51    CurrentThread = PsGetCurrentThread();
52
53    if (CurrentThread->OldProcess != NULL)
54      {
55         DbgPrint("Invalid attach (thread is already attached)\n");
56         KeBugCheck(0);
57      }
58    
59    KeRaiseIrql(DISPATCH_LEVEL, &oldlvl);
60    
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"
66            : /* no inputs */
67            : "r" (PageDir));
68    
69    
70    KeLowerIrql(oldlvl);
71 }
72
73 VOID STDCALL
74 KeDetachProcess (VOID)
75 {
76    KIRQL oldlvl;
77    PETHREAD CurrentThread;
78    ULONG PageDir;
79    
80    DPRINT("KeDetachProcess()\n");
81    
82    CurrentThread = PsGetCurrentThread();
83
84    if (CurrentThread->OldProcess == NULL)
85      {
86         DbgPrint("Invalid detach (thread was not attached)\n");
87         KeBugCheck(0);
88      }
89    
90    KeRaiseIrql(DISPATCH_LEVEL, &oldlvl);
91    
92    CurrentThread->ThreadsProcess = CurrentThread->OldProcess;
93    CurrentThread->OldProcess = NULL;
94    PageDir = CurrentThread->ThreadsProcess->Pcb.DirectoryTableBase.u.LowPart;
95    __asm__("movl %0,%%cr3\n\t"
96            : /* no inputs */
97            : "r" (PageDir));
98    
99    KeLowerIrql(oldlvl);
100 }
101
102 /* EOF */