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 *****************************************************************/
24 MmLockAddressSpace(PMADDRESS_SPACE AddressSpace
)
27 * Don't bother with locking if we are the first thread.
29 if (KeGetCurrentThread() == NULL
)
33 ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&AddressSpace
->Lock
);
38 MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace
)
41 * Don't bother locking if we are the first thread.
43 if (KeGetCurrentThread() == NULL
)
47 ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&AddressSpace
->Lock
);
53 MmInitializeKernelAddressSpace(VOID
)
55 MmInitializeAddressSpace(NULL
, &KernelAddressSpace
);
60 MmGetCurrentAddressSpace(VOID
)
62 return(&PsGetCurrentProcess()->AddressSpace
);
67 MmGetKernelAddressSpace(VOID
)
69 return(&KernelAddressSpace
);
74 MmInitializeAddressSpace(PEPROCESS Process
,
75 PMADDRESS_SPACE AddressSpace
)
77 AddressSpace
->MemoryAreaRoot
= NULL
;
78 ExInitializeFastMutex(&AddressSpace
->Lock
);
81 AddressSpace
->LowestAddress
= MM_LOWEST_USER_ADDRESS
;
85 AddressSpace
->LowestAddress
= MmSystemRangeStart
;
87 AddressSpace
->Process
= Process
;
91 Count
= MiGetUserPageDirectoryCount();
92 AddressSpace
->PageTableRefCountTable
=
93 ExAllocatePoolWithTag(NonPagedPool
, Count
* sizeof(USHORT
),
95 RtlZeroMemory(AddressSpace
->PageTableRefCountTable
, Count
* sizeof(USHORT
));
96 AddressSpace
->PageTableRefCountTableSize
= Count
;
100 AddressSpace
->PageTableRefCountTable
= NULL
;
101 AddressSpace
->PageTableRefCountTableSize
= 0;
103 return(STATUS_SUCCESS
);
108 MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace
)
110 if (AddressSpace
->PageTableRefCountTable
!= NULL
)
112 ExFreePool(AddressSpace
->PageTableRefCountTable
);
114 return(STATUS_SUCCESS
);