/* $Id$
- *
- * COPYRIGHT: See COPYING in the top level directory
+ *
+ * Copyright (C) 1998-2005 ReactOS Team (and the authors from the programmers section)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/marea.c
* PURPOSE: Implements memory areas
- *
- * PROGRAMMERS: David Welch (welch@mcmail.com)
+ *
+ * PROGRAMMERS: Rex Jolliff
+ * David Welch
+ * Eric Kohl
+ * Philip Susi
+ * Casper Hornstrup
+ * Eric Kohl
+ * Ge van Geldorp
+ * Royce Mitchell III
+ * Aleksey Bragin
+ * Jason Filby
+ * Thomas Weidenmueller
+ * Gunnar Andre' Dalsnes
+ * Mike Nordell
+ * Alex Ionescu
+ * Filip Navara
+ * Herve Poussineau
+ * Steven Edwards
*/
/* INCLUDES *****************************************************************/
#define NDEBUG
#include <internal/debug.h>
-/* GLOBALS *******************************************************************/
-
-#define TAG_MAREA TAG('M', 'A', 'R', 'E')
+#if defined (ALLOC_PRAGMA)
+#pragma alloc_text(INIT, MmInitMemoryAreas)
+#endif
/* #define VALIDATE_MEMORY_AREAS */
}
/**
- * @name MmIterateFirstNode
+ * @name MmIterateLastNode
*
* @param Node
* Head node of the MEMORY_AREA tree.
}
/**
- * @name MmIterateNextNode
+ * @name MmIteratePreviousNode
*
* @param Node
* Current node in the tree.
Node != NULL;
Node = MmIterateNextNode(Node))
{
- DbgPrint("Start %p End %p Attributes %x\n",
+ DbgPrint("Start %p End %p Protect %x Flags %x\n",
Node->StartingAddress, Node->EndingAddress,
- Node->Attributes);
+ Node->Protect, Node->Flags);
}
DbgPrint("Finished MmDumpMemoryAreas()\n");
DPRINT("MmLocateMemoryAreaByAddress(AddressSpace %p, Address %p)\n",
AddressSpace, Address);
- if (!(KdDebugState & KD_DEBUG_SCREEN))
- MmVerifyMemoryAreas(AddressSpace);
+ MmVerifyMemoryAreas(AddressSpace);
while (Node != NULL)
{
ULONG_PTR Length,
ULONG_PTR Granularity)
{
- PVOID HighestAddress = AddressSpace->LowestAddress < (PVOID)KERNEL_BASE ?
- (PVOID)(KERNEL_BASE - 1) : (PVOID)MAXULONG_PTR;
+ PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+ (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
PVOID AlignedAddress;
PMEMORY_AREA Node;
PMEMORY_AREA FirstNode;
ULONG_PTR Length,
ULONG_PTR Granularity)
{
- PVOID HighestAddress = AddressSpace->LowestAddress < (PVOID)KERNEL_BASE ?
- (PVOID)(KERNEL_BASE - 1) : (PVOID)MAXULONG_PTR;
+ PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+ (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
PVOID AlignedAddress;
PMEMORY_AREA Node;
PMEMORY_AREA PreviousNode;
{
PMEMORY_AREA Node = AddressSpace->MemoryAreaRoot;
PMEMORY_AREA RightNeighbour = NULL;
- PVOID HighestAddress = AddressSpace->LowestAddress < (PVOID)KERNEL_BASE ?
- (PVOID)(KERNEL_BASE - 1) : (PVOID)MAXULONG_PTR;
+ PVOID HighestAddress = AddressSpace->LowestAddress < MmSystemRangeStart ?
+ (PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
MmVerifyMemoryAreas(AddressSpace);
Address = MM_ROUND_DOWN(Address, PAGE_SIZE);
- if (AddressSpace->LowestAddress < (PVOID)KERNEL_BASE)
+ if (AddressSpace->LowestAddress < MmSystemRangeStart)
{
- if (Address >= (PVOID)KERNEL_BASE)
+ if (Address >= MmSystemRangeStart)
{
return 0;
}
* Initialize the memory area list implementation.
*/
-NTSTATUS INIT_FUNCTION
+NTSTATUS
+INIT_FUNCTION
+NTAPI
MmInitMemoryAreas(VOID)
{
DPRINT("MmInitMemoryAreas()\n",0);
PMEMORY_AREA *ParentReplace;
ULONG_PTR Address;
PVOID EndAddress;
- PEPROCESS CurrentProcess = PsGetCurrentProcess();
+ PROS_EPROCESS CurrentProcess = (PROS_EPROCESS)PsGetCurrentProcess();
if (AddressSpace->Process != NULL &&
AddressSpace->Process != CurrentProcess)
}
else
{
- BOOL Dirty = FALSE;
+ BOOLEAN Dirty = FALSE;
SWAPENTRY SwapEntry = 0;
PFN_TYPE Page = 0;
}
}
- ExFreePool(MemoryArea);
+ ExFreePoolWithTag(MemoryArea, TAG_MAREA);
DPRINT("MmFreeMemoryAreaByNode() succeeded\n");
*/
NTSTATUS STDCALL
-MmCreateMemoryArea(PEPROCESS Process,
- PMADDRESS_SPACE AddressSpace,
+MmCreateMemoryArea(PMADDRESS_SPACE AddressSpace,
ULONG Type,
PVOID *BaseAddress,
ULONG_PTR Length,
- ULONG Attributes,
+ ULONG Protect,
PMEMORY_AREA *Result,
BOOLEAN FixedAddress,
- BOOLEAN TopDown,
+ ULONG AllocationFlags,
PHYSICAL_ADDRESS BoundaryAddressMultiple)
{
PVOID EndAddress;
*BaseAddress = MmFindGap(AddressSpace,
tmpLength,
Granularity,
- TopDown != 0);
+ (AllocationFlags & MEM_TOP_DOWN) == MEM_TOP_DOWN);
if ((*BaseAddress) == 0)
{
DPRINT("No suitable gap\n");
- (ULONG_PTR) MM_ROUND_DOWN(*BaseAddress, Granularity));
*BaseAddress = MM_ROUND_DOWN(*BaseAddress, Granularity);
- if (AddressSpace->LowestAddress == (PVOID)KERNEL_BASE &&
- *BaseAddress < (PVOID)KERNEL_BASE)
+ if (AddressSpace->LowestAddress == MmSystemRangeStart &&
+ *BaseAddress < MmSystemRangeStart)
{
CHECKPOINT;
return STATUS_ACCESS_VIOLATION;
}
- if (AddressSpace->LowestAddress < (PVOID)KERNEL_BASE &&
- (ULONG_PTR)(*BaseAddress) + tmpLength > KERNEL_BASE)
+ if (AddressSpace->LowestAddress < MmSystemRangeStart &&
+ (ULONG_PTR)(*BaseAddress) + tmpLength > (ULONG_PTR)MmSystemRangeStart)
{
CHECKPOINT;
return STATUS_ACCESS_VIOLATION;
MemoryArea->Type = Type;
MemoryArea->StartingAddress = *BaseAddress;
MemoryArea->EndingAddress = (PVOID)((ULONG_PTR)*BaseAddress + tmpLength);
- MemoryArea->Attributes = Attributes;
+ MemoryArea->Protect = Protect;
+ MemoryArea->Flags = AllocationFlags;
MemoryArea->LockCount = 0;
- MemoryArea->Process = Process;
MemoryArea->PageOpCount = 0;
MemoryArea->DeleteInProgress = FALSE;
VOID STDCALL
-MmReleaseMemoryAreaIfDecommitted(PEPROCESS Process,
+MmReleaseMemoryAreaIfDecommitted(PROS_EPROCESS Process,
PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress)
{