3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/mm/aspace.c
6 * PURPOSE: Manages address spaces
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
11 /* INCLUDES *****************************************************************/
14 #include <internal/debug.h>
16 /* GLOBALS ******************************************************************/
18 STATIC MADDRESS_SPACE KernelAddressSpace
;
20 #define TAG_PTRC TAG('P', 'T', 'R', 'C')
22 /* FUNCTIONS *****************************************************************/
25 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace
)
28 * Don't bother with locking if we are the first thread.
30 if (KeGetCurrentThread() == NULL
)
34 ExAcquireFastMutex(&AddressSpace
->Lock
);
38 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace
)
41 * Don't bother locking if we are the first thread.
43 if (KeGetCurrentThread() == NULL
)
47 ExReleaseFastMutex(&AddressSpace
->Lock
);
51 MmInitializeKernelAddressSpace(VOID
)
53 MmInitializeAddressSpace(NULL
, &KernelAddressSpace
);
56 PMADDRESS_SPACE
MmGetCurrentAddressSpace(VOID
)
58 return(&PsGetCurrentProcess()->AddressSpace
);
61 PMADDRESS_SPACE
MmGetKernelAddressSpace(VOID
)
63 return(&KernelAddressSpace
);
67 MmInitializeAddressSpace(PEPROCESS Process
,
68 PMADDRESS_SPACE AddressSpace
)
70 AddressSpace
->MemoryAreaRoot
= NULL
;
71 ExInitializeFastMutex(&AddressSpace
->Lock
);
74 AddressSpace
->LowestAddress
= MM_LOWEST_USER_ADDRESS
;
78 AddressSpace
->LowestAddress
= (PVOID
)KERNEL_BASE
;
80 AddressSpace
->Process
= Process
;
84 Count
= MiGetUserPageDirectoryCount();
85 AddressSpace
->PageTableRefCountTable
=
86 ExAllocatePoolWithTag(NonPagedPool
, Count
* sizeof(USHORT
),
88 RtlZeroMemory(AddressSpace
->PageTableRefCountTable
, Count
* sizeof(USHORT
));
89 AddressSpace
->PageTableRefCountTableSize
= Count
;
93 AddressSpace
->PageTableRefCountTable
= NULL
;
94 AddressSpace
->PageTableRefCountTableSize
= 0;
96 return(STATUS_SUCCESS
);
100 MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace
)
102 if (AddressSpace
->PageTableRefCountTable
!= NULL
)
104 ExFreePool(AddressSpace
->PageTableRefCountTable
);
106 return(STATUS_SUCCESS
);