Kernel base address and system space start can be distinct addresses, so use KERNEL_B...
[reactos.git] / reactos / ntoskrnl / mm / aspace.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/aspace.c
6 * PURPOSE: Manages address spaces
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #include <internal/debug.h>
15
16 /* GLOBALS ******************************************************************/
17
18 STATIC MADDRESS_SPACE KernelAddressSpace;
19
20 /* FUNCTIONS *****************************************************************/
21
22 VOID
23 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
24 {
25 /*
26 * Don't bother with locking if we are the first thread.
27 */
28 if (KeGetCurrentThread() == NULL)
29 {
30 return;
31 }
32 ExAcquireFastMutex(&AddressSpace->Lock);
33 }
34
35 VOID
36 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
37 {
38 /*
39 * Don't bother locking if we are the first thread.
40 */
41 if (KeGetCurrentThread() == NULL)
42 {
43 return;
44 }
45 ExReleaseFastMutex(&AddressSpace->Lock);
46 }
47
48 VOID INIT_FUNCTION
49 MmInitializeKernelAddressSpace(VOID)
50 {
51 MmInitializeAddressSpace(NULL, &KernelAddressSpace);
52 }
53
54 PMADDRESS_SPACE MmGetCurrentAddressSpace(VOID)
55 {
56 return(&PsGetCurrentProcess()->AddressSpace);
57 }
58
59 PMADDRESS_SPACE MmGetKernelAddressSpace(VOID)
60 {
61 return(&KernelAddressSpace);
62 }
63
64 NTSTATUS
65 MmInitializeAddressSpace(PEPROCESS Process,
66 PMADDRESS_SPACE AddressSpace)
67 {
68 AddressSpace->MemoryAreaRoot = NULL;
69 ExInitializeFastMutex(&AddressSpace->Lock);
70 if (Process != NULL)
71 {
72 AddressSpace->LowestAddress = MM_LOWEST_USER_ADDRESS;
73 }
74 else
75 {
76 AddressSpace->LowestAddress = MmSystemRangeStart;
77 }
78 AddressSpace->Process = Process;
79 if (Process != NULL)
80 {
81 ULONG Count;
82 Count = MiGetUserPageDirectoryCount();
83 AddressSpace->PageTableRefCountTable =
84 ExAllocatePoolWithTag(NonPagedPool, Count * sizeof(USHORT),
85 TAG_PTRC);
86 RtlZeroMemory(AddressSpace->PageTableRefCountTable, Count * sizeof(USHORT));
87 AddressSpace->PageTableRefCountTableSize = Count;
88 }
89 else
90 {
91 AddressSpace->PageTableRefCountTable = NULL;
92 AddressSpace->PageTableRefCountTableSize = 0;
93 }
94 return(STATUS_SUCCESS);
95 }
96
97 NTSTATUS
98 MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace)
99 {
100 if (AddressSpace->PageTableRefCountTable != NULL)
101 {
102 ExFreePool(AddressSpace->PageTableRefCountTable);
103 }
104 return(STATUS_SUCCESS);
105 }
106
107 /* EOF */