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 /* FUNCTIONS *****************************************************************/
23 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace
)
26 * Don't bother with locking if we are the first thread.
28 if (KeGetCurrentThread() == NULL
)
32 ExAcquireFastMutex(&AddressSpace
->Lock
);
36 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace
)
39 * Don't bother locking if we are the first thread.
41 if (KeGetCurrentThread() == NULL
)
45 ExReleaseFastMutex(&AddressSpace
->Lock
);
49 MmInitializeKernelAddressSpace(VOID
)
51 MmInitializeAddressSpace(NULL
, &KernelAddressSpace
);
54 PMADDRESS_SPACE
MmGetCurrentAddressSpace(VOID
)
56 return(&PsGetCurrentProcess()->AddressSpace
);
59 PMADDRESS_SPACE
MmGetKernelAddressSpace(VOID
)
61 return(&KernelAddressSpace
);
65 MmInitializeAddressSpace(PEPROCESS Process
,
66 PMADDRESS_SPACE AddressSpace
)
68 AddressSpace
->MemoryAreaRoot
= NULL
;
69 ExInitializeFastMutex(&AddressSpace
->Lock
);
72 AddressSpace
->LowestAddress
= MM_LOWEST_USER_ADDRESS
;
76 AddressSpace
->LowestAddress
= MmSystemRangeStart
;
78 AddressSpace
->Process
= Process
;
82 Count
= MiGetUserPageDirectoryCount();
83 AddressSpace
->PageTableRefCountTable
=
84 ExAllocatePoolWithTag(NonPagedPool
, Count
* sizeof(USHORT
),
86 RtlZeroMemory(AddressSpace
->PageTableRefCountTable
, Count
* sizeof(USHORT
));
87 AddressSpace
->PageTableRefCountTableSize
= Count
;
91 AddressSpace
->PageTableRefCountTable
= NULL
;
92 AddressSpace
->PageTableRefCountTableSize
= 0;
94 return(STATUS_SUCCESS
);
98 MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace
)
100 if (AddressSpace
->PageTableRefCountTable
!= NULL
)
102 ExFreePool(AddressSpace
->PageTableRefCountTable
);
104 return(STATUS_SUCCESS
);