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
;
25 /* FUNCTIONS *****************************************************************/
29 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace
)
32 * Don't bother with locking if we are the first thread.
34 if (KeGetCurrentThread() == NULL
)
38 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&AddressSpace
->Lock
);
43 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace
)
46 * Don't bother locking if we are the first thread.
48 if (KeGetCurrentThread() == NULL
)
52 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&AddressSpace
->Lock
);
58 MmInitializeKernelAddressSpace(VOID
)
60 MmInitializeAddressSpace(NULL
, &KernelAddressSpace
);
65 MmGetCurrentAddressSpace(VOID
)
67 return(&PsGetCurrentProcess()->AddressSpace
);
72 MmGetKernelAddressSpace(VOID
)
74 return(&KernelAddressSpace
);
79 MmInitializeAddressSpace(PEPROCESS Process
,
80 PMADDRESS_SPACE AddressSpace
)
82 AddressSpace
->MemoryAreaRoot
= NULL
;
83 ExInitializeFastMutex(&AddressSpace
->Lock
);
86 AddressSpace
->LowestAddress
= MM_LOWEST_USER_ADDRESS
;
90 AddressSpace
->LowestAddress
= MmSystemRangeStart
;
92 AddressSpace
->Process
= Process
;
96 Count
= MiGetUserPageDirectoryCount();
97 AddressSpace
->PageTableRefCountTable
=
98 ExAllocatePoolWithTag(NonPagedPool
, Count
* sizeof(USHORT
),
100 RtlZeroMemory(AddressSpace
->PageTableRefCountTable
, Count
* sizeof(USHORT
));
101 AddressSpace
->PageTableRefCountTableSize
= Count
;
105 AddressSpace
->PageTableRefCountTable
= NULL
;
106 AddressSpace
->PageTableRefCountTableSize
= 0;
108 return(STATUS_SUCCESS
);
113 MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace
)
115 if (AddressSpace
->PageTableRefCountTable
!= NULL
)
117 ExFreePool(AddressSpace
->PageTableRefCountTable
);
119 return(STATUS_SUCCESS
);