-/* $Id: aspace.c,v 1.7 2001/11/25 15:21:11 dwelch Exp $
- *
+/* $Id$
+ *
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/aspace.c
* PURPOSE: Manages address spaces
- * PROGRAMMER: David Welch (welch@cwcom.net)
- * UPDATE HISTORY:
- * Created 22/05/98
+ *
+ * PROGRAMMERS: David Welch (welch@cwcom.net)
*/
/* INCLUDES *****************************************************************/
-#include <ddk/ntddk.h>
-#include <internal/mm.h>
-#include <internal/ps.h>
-#include <internal/pool.h>
-
+#include <ntoskrnl.h>
#include <internal/debug.h>
+#if defined (ALLOC_PRAGMA)
+#pragma alloc_text(INIT, MmInitializeKernelAddressSpace)
+#endif
+
+
/* GLOBALS ******************************************************************/
STATIC MADDRESS_SPACE KernelAddressSpace;
-#define TAG_PTRC TAG('P', 'T', 'R', 'C')
-
/* FUNCTIONS *****************************************************************/
-VOID
+VOID
+NTAPI
MmLockAddressSpace(PMADDRESS_SPACE AddressSpace)
{
- /*
- * Don't bother with locking if we are the first thread.
- */
- if (KeGetCurrentThread() == NULL)
- {
+ /*
+ * Don't bother with locking if we are the first thread.
+ */
+ if (KeGetCurrentThread() == NULL)
+ {
return;
- }
- (VOID)KeWaitForMutexObject(&AddressSpace->Lock,
- 0,
- KernelMode,
- FALSE,
- NULL);
+ }
+ ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&AddressSpace->Lock);
}
-VOID
+VOID
+NTAPI
MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace)
{
- /*
- * Don't bother locking if we are the first thread.
- */
- if (KeGetCurrentThread() == NULL)
- {
+ /*
+ * Don't bother locking if we are the first thread.
+ */
+ if (KeGetCurrentThread() == NULL)
+ {
return;
- }
- KeReleaseMutex(&AddressSpace->Lock, FALSE);
+ }
+ ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&AddressSpace->Lock);
}
-VOID
+VOID
+INIT_FUNCTION
+NTAPI
MmInitializeKernelAddressSpace(VOID)
{
MmInitializeAddressSpace(NULL, &KernelAddressSpace);
}
-PMADDRESS_SPACE MmGetCurrentAddressSpace(VOID)
+PMADDRESS_SPACE
+NTAPI
+MmGetCurrentAddressSpace(VOID)
{
- return(&PsGetCurrentProcess()->AddressSpace);
+ return(&((PROS_EPROCESS)PsGetCurrentProcess())->AddressSpace);
}
-PMADDRESS_SPACE MmGetKernelAddressSpace(VOID)
+PMADDRESS_SPACE
+NTAPI
+MmGetKernelAddressSpace(VOID)
{
return(&KernelAddressSpace);
}
-NTSTATUS
-MmInitializeAddressSpace(PEPROCESS Process,
- PMADDRESS_SPACE AddressSpace)
+NTSTATUS
+NTAPI
+MmInitializeAddressSpace(PROS_EPROCESS Process,
+ PMADDRESS_SPACE AddressSpace)
{
- InitializeListHead(&AddressSpace->MAreaListHead);
- KeInitializeMutex(&AddressSpace->Lock, 1);
+ AddressSpace->MemoryAreaRoot = NULL;
+ ExInitializeFastMutex(&AddressSpace->Lock);
if (Process != NULL)
- {
- AddressSpace->LowestAddress = MM_LOWEST_USER_ADDRESS;
- }
+ {
+ AddressSpace->LowestAddress = MM_LOWEST_USER_ADDRESS;
+ }
else
- {
- AddressSpace->LowestAddress = KERNEL_BASE;
- }
+ {
+ AddressSpace->LowestAddress = MmSystemRangeStart;
+ }
AddressSpace->Process = Process;
if (Process != NULL)
- {
- MmInitializeWorkingSet(Process, AddressSpace);
- }
- if (Process != NULL)
- {
- AddressSpace->PageTableRefCountTable =
- ExAllocatePoolWithTag(NonPagedPool, 768 * sizeof(USHORT),
- TAG_PTRC);
- AddressSpace->PageTableRefCountTableSize = 768;
- }
+ {
+ ULONG Count;
+ Count = MiGetUserPageDirectoryCount();
+ AddressSpace->PageTableRefCountTable =
+ ExAllocatePoolWithTag(NonPagedPool, Count * sizeof(USHORT),
+ TAG_PTRC);
+ RtlZeroMemory(AddressSpace->PageTableRefCountTable, Count * sizeof(USHORT));
+ AddressSpace->PageTableRefCountTableSize = Count;
+ }
else
- {
- AddressSpace->PageTableRefCountTable = NULL;
- AddressSpace->PageTableRefCountTableSize = 0;
- }
+ {
+ AddressSpace->PageTableRefCountTable = NULL;
+ AddressSpace->PageTableRefCountTableSize = 0;
+ }
return(STATUS_SUCCESS);
}
-NTSTATUS
+NTSTATUS
+NTAPI
MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace)
{
- if (AddressSpace->PageTableRefCountTable != NULL)
- {
+ if (AddressSpace->PageTableRefCountTable != NULL)
+ {
ExFreePool(AddressSpace->PageTableRefCountTable);
- }
+ }
return(STATUS_SUCCESS);
}
+
+/* EOF */