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 #if defined (ALLOC_PRAGMA)
17 #pragma alloc_text(INIT, MmInitializeKernelAddressSpace)
21 /* GLOBALS ******************************************************************/
23 static MADDRESS_SPACE KernelAddressSpace
;
24 FAST_MUTEX KernelAddressSpaceLock
;
26 /* FUNCTIONS *****************************************************************/
30 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace
)
33 * Don't bother with locking if we are the first thread.
35 if (KeGetCurrentThread() == NULL
)
40 if (AddressSpace
->Process
)
42 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&AddressSpace
->Process
->AddressCreationLock
);
46 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&KernelAddressSpaceLock
);
52 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace
)
55 * Don't bother locking if we are the first thread.
57 if (KeGetCurrentThread() == NULL
)
61 if (AddressSpace
->Process
)
63 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&AddressSpace
->Process
->AddressCreationLock
);
67 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&KernelAddressSpaceLock
);
74 MmInitializeKernelAddressSpace(VOID
)
76 MmInitializeAddressSpace(NULL
, &KernelAddressSpace
);
81 MmGetCurrentAddressSpace(VOID
)
83 return((PMADDRESS_SPACE
)&(PsGetCurrentProcess())->VadRoot
);
88 MmGetKernelAddressSpace(VOID
)
90 return(&KernelAddressSpace
);
95 MmInitializeAddressSpace(PEPROCESS Process
,
96 PMADDRESS_SPACE AddressSpace
)
98 AddressSpace
->MemoryAreaRoot
= NULL
;
101 ExInitializeFastMutex(&Process
->AddressCreationLock
);
105 ExInitializeFastMutex(&KernelAddressSpaceLock
);
109 AddressSpace
->LowestAddress
= MM_LOWEST_USER_ADDRESS
;
113 AddressSpace
->LowestAddress
= MmSystemRangeStart
;
115 AddressSpace
->Process
= Process
;
119 Count
= MiGetUserPageDirectoryCount();
120 AddressSpace
->PageTableRefCountTable
=
121 ExAllocatePoolWithTag(NonPagedPool
, Count
* sizeof(USHORT
),
123 RtlZeroMemory(AddressSpace
->PageTableRefCountTable
, Count
* sizeof(USHORT
));
124 AddressSpace
->PageTableRefCountTableSize
= Count
;
128 AddressSpace
->PageTableRefCountTable
= NULL
;
129 AddressSpace
->PageTableRefCountTableSize
= 0;
131 return(STATUS_SUCCESS
);
136 MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace
)
138 if (AddressSpace
->PageTableRefCountTable
!= NULL
)
140 ExFreePool(AddressSpace
->PageTableRefCountTable
);
142 return(STATUS_SUCCESS
);