Change the MEMORY_AREAs to be stored it a binary search tree instead of linked list. Thanks to Royce Mitchell III and Mike Nordell for helping me.

svn path=/trunk/; revision=12728
This commit is contained in:
Filip Navara 2005-01-02 17:55:06 +00:00
parent d57bd697fd
commit 2644fdc88a
20 changed files with 1058 additions and 611 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: view.c,v 1.79 2004/10/22 20:11:12 ekohl Exp $
/* $Id$
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/cc/view.c
@ -813,8 +813,7 @@ CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg)
#else
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
CacheSeg->BaseAddress,
CacheSeg->Bcb->CacheSegmentSize,
CacheSeg->MemoryArea,
CcFreeCachePage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());

View file

@ -184,15 +184,17 @@ typedef struct _PAGEFAULT_HISTORY
#endif /* __USE_W32API */
typedef struct
typedef struct _MEMORY_AREA
{
PVOID StartingAddress;
PVOID EndingAddress;
struct _MEMORY_AREA *Parent;
struct _MEMORY_AREA *LeftChild;
struct _MEMORY_AREA *RightChild;
ULONG Type;
PVOID BaseAddress;
ULONG Length;
ULONG Attributes;
LIST_ENTRY Entry;
ULONG LockCount;
struct _EPROCESS* Process;
struct _EPROCESS* Process; /* FIXME: We don't need this! */
BOOLEAN DeleteInProgress;
ULONG PageOpCount;
union
@ -215,7 +217,7 @@ typedef struct
typedef struct _MADDRESS_SPACE
{
LIST_ENTRY MAreaListHead;
PMEMORY_AREA MemoryAreaRoot;
FAST_MUTEX Lock;
PVOID LowestAddress;
struct _EPROCESS* Process;
@ -333,6 +335,10 @@ typedef struct _MM_REGION
LIST_ENTRY RegionListEntry;
} MM_REGION, *PMM_REGION;
typedef VOID (*PMM_FREE_PAGE_FUNC)(PVOID Context, PMEMORY_AREA MemoryArea,
PVOID Address, PFN_TYPE Page,
SWAPENTRY SwapEntry, BOOLEAN Dirty);
/* FUNCTIONS */
/* aspace.c ******************************************************************/
@ -354,48 +360,67 @@ NTSTATUS MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace);
/* marea.c *******************************************************************/
NTSTATUS MmCreateMemoryArea(struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace,
ULONG Type,
PVOID* BaseAddress,
ULONG Length,
ULONG Attributes,
MEMORY_AREA** Result,
BOOL FixedAddress,
BOOL TopDown,
PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL);
NTSTATUS INIT_FUNCTION
MmInitMemoryAreas(VOID);
MEMORY_AREA* MmOpenMemoryAreaByAddress(PMADDRESS_SPACE AddressSpace,
PVOID Address);
NTSTATUS STDCALL
MmCreateMemoryArea(
struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace,
ULONG Type,
PVOID *BaseAddress,
ULONG_PTR Length,
ULONG Attributes,
PMEMORY_AREA *Result,
BOOLEAN FixedAddress,
BOOLEAN TopDown,
PHYSICAL_ADDRESS BoundaryAddressMultiple OPTIONAL);
ULONG MmFindGapAtAddress(PMADDRESS_SPACE AddressSpace,
PVOID Address);
PMEMORY_AREA STDCALL
MmOpenMemoryAreaByAddress(
PMADDRESS_SPACE AddressSpace,
PVOID Address);
NTSTATUS MmInitMemoryAreas(VOID);
ULONG STDCALL
MmFindGapAtAddress(
PMADDRESS_SPACE AddressSpace,
PVOID Address);
NTSTATUS MmFreeMemoryArea(PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress,
ULONG Length,
VOID (*FreePage)(PVOID Context, MEMORY_AREA* MemoryArea,
PVOID Address, PFN_TYPE Page, SWAPENTRY SwapEntry,
BOOLEAN Dirty),
PVOID FreePageContext);
NTSTATUS STDCALL
MmFreeMemoryArea(
PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA MemoryArea,
PMM_FREE_PAGE_FUNC FreePage,
PVOID FreePageContext);
VOID MmDumpMemoryAreas(PLIST_ENTRY ListHead);
NTSTATUS STDCALL
MmFreeMemoryAreaByPtr(
PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress,
PMM_FREE_PAGE_FUNC FreePage,
PVOID FreePageContext);
NTSTATUS MmLockMemoryArea(MEMORY_AREA* MemoryArea);
VOID STDCALL
MmDumpMemoryAreas(PMADDRESS_SPACE AddressSpace);
NTSTATUS MmUnlockMemoryArea(MEMORY_AREA* MemoryArea);
PMEMORY_AREA STDCALL
MmOpenMemoryAreaByRegion(
PMADDRESS_SPACE AddressSpace,
PVOID Address,
ULONG_PTR Length);
MEMORY_AREA* MmOpenMemoryAreaByRegion(PMADDRESS_SPACE AddressSpace,
PVOID Address,
ULONG Length);
PVOID STDCALL
MmFindGap(
PMADDRESS_SPACE AddressSpace,
ULONG_PTR Length,
ULONG_PTR Granularity,
BOOLEAN TopDown);
PVOID MmFindGap(PMADDRESS_SPACE AddressSpace, ULONG Length, ULONG Granularity, BOOL TopDown);
void MmReleaseMemoryAreaIfDecommitted(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress);
VOID STDCALL
MmReleaseMemoryAreaIfDecommitted(
PEPROCESS Process,
PMADDRESS_SPACE AddressSpace,
PVOID BaseAddress);
/* npool.c *******************************************************************/

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: bug.c,v 1.48 2004/12/12 17:42:00 hbirr Exp $
/* $Id$
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/bug.c
@ -116,6 +116,11 @@ KeBugCheckWithTf(ULONG BugCheckCode,
Ke386DisableInterrupts();
DebugLogDumpMessages();
if (MmGetKernelAddressSpace()->Lock.Owner == KeGetCurrentThread())
{
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}
if (KeGetCurrentIrql() < DISPATCH_LEVEL)
{
KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);

View file

@ -320,7 +320,7 @@ KiDoubleFaultHandler(VOID)
{
KeRosPrintAddress((PVOID)Frame[1]);
Frame = (PULONG)Frame[0];
DbgPrint(" ");
DbgPrint("\n");
}
#else
DbgPrint("Frames: ");
@ -663,7 +663,7 @@ KeDumpStackFrames(PULONG Frame)
break;
StackBase = Frame;
Frame = (PULONG)Frame[0];
DbgPrint(" ");
DbgPrint("\n");
}
}
_SEH_HANDLE

View file

@ -90,11 +90,10 @@ KeReleaseThread(PKTHREAD Thread)
if (Thread->StackLimit != (ULONG_PTR)&init_stack)
{
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
(PVOID)Thread->StackLimit,
MM_STACK_SIZE,
KeFreeStackPage,
NULL);
MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
(PVOID)Thread->StackLimit,
KeFreeStackPage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}
Thread->StackLimit = 0;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: anonmem.c,v 1.34 2004/12/19 16:16:57 navaraf Exp $
/* $Id$
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/anonmem.c
@ -261,7 +261,7 @@ MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
/*
* Get the segment corresponding to the virtual address
*/
Region = MmFindRegion(MemoryArea->BaseAddress,
Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead,
Address, NULL);
if (Region->Type == MEM_RESERVE || Region->Protect == PAGE_NOACCESS)
@ -525,6 +525,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
{
PEPROCESS Process;
MEMORY_AREA* MemoryArea;
ULONG_PTR MemoryAreaLength;
ULONG Type;
NTSTATUS Status;
PMADDRESS_SPACE AddressSpace;
@ -582,39 +583,43 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
BaseAddress);
if (MemoryArea != NULL &&
MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY &&
MemoryArea->Length >= RegionSize)
if (MemoryArea != NULL)
{
Status =
MmAlterRegion(AddressSpace,
MemoryArea->BaseAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead,
BaseAddress, RegionSize,
Type, Protect, MmModifyAttributes);
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
else if (MemoryArea != NULL && MemoryArea->Length >= RegionSize)
{
Status =
MmAlterRegion(AddressSpace,
MemoryArea->BaseAddress,
&MemoryArea->Data.SectionData.RegionListHead,
BaseAddress, RegionSize,
Type, Protect, MmModifyAttributes);
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
else if (MemoryArea != NULL)
{
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL);
MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
if (MemoryArea->Type == MEMORY_AREA_VIRTUAL_MEMORY &&
MemoryAreaLength >= RegionSize)
{
Status =
MmAlterRegion(AddressSpace,
MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead,
BaseAddress, RegionSize,
Type, Protect, MmModifyAttributes);
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
else if (MemoryAreaLength >= RegionSize)
{
Status =
MmAlterRegion(AddressSpace,
MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
BaseAddress, RegionSize,
Type, Protect, MmModifyAttributes);
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
else
{
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL);
}
}
}
@ -626,7 +631,7 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
Protect,
&MemoryArea,
PBaseAddress != 0,
(AllocationType & MEM_TOP_DOWN),
(AllocationType & MEM_TOP_DOWN) == MEM_TOP_DOWN,
BoundaryAddressMultiple);
if (!NT_SUCCESS(Status))
{
@ -635,18 +640,22 @@ NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
DPRINT("NtAllocateVirtualMemory() = %x\n",Status);
return(Status);
}
MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
MmInitialiseRegion(&MemoryArea->Data.VirtualMemoryData.RegionListHead,
MemoryArea->Length, Type, Protect);
MemoryAreaLength, Type, Protect);
if ((AllocationType & MEM_COMMIT) &&
((Protect & PAGE_READWRITE) ||
(Protect & PAGE_EXECUTE_READWRITE)))
{
MmReserveSwapPages(MemoryArea->Length);
MmReserveSwapPages(MemoryAreaLength);
}
*UBaseAddress = BaseAddress;
*URegionSize = MemoryArea->Length;
*URegionSize = MemoryAreaLength;
DPRINT("*UBaseAddress %x *URegionSize %x\n", BaseAddress, RegionSize);
MmUnlockAddressSpace(AddressSpace);
@ -702,7 +711,11 @@ MmFreeVirtualMemory(PEPROCESS Process,
*/
if (MemoryArea->PageOpCount > 0)
{
for (i = 0; i < PAGE_ROUND_UP(MemoryArea->Length) / PAGE_SIZE; i++)
ULONG_PTR MemoryAreaLength = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
/* FiN TODO: Optimize loop counter! */
for (i = 0; i < PAGE_ROUND_UP(MemoryAreaLength) / PAGE_SIZE; i++)
{
PMM_PAGEOP PageOp;
@ -712,7 +725,7 @@ MmFreeVirtualMemory(PEPROCESS Process,
}
PageOp = MmCheckForPageOp(MemoryArea, Process->UniqueProcessId,
(char*)MemoryArea->BaseAddress + (i * PAGE_SIZE),
(PVOID)((ULONG_PTR)MemoryArea->StartingAddress + (i * PAGE_SIZE)),
NULL, 0);
if (PageOp != NULL)
{
@ -745,8 +758,7 @@ MmFreeVirtualMemory(PEPROCESS Process,
/* Actually free the memory area. */
MmFreeMemoryArea(&Process->AddressSpace,
MemoryArea->BaseAddress,
0,
MemoryArea,
MmFreeVirtualMemoryPage,
(PVOID)Process);
}
@ -814,7 +826,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
{
case MEM_RELEASE:
/* We can only free a memory area in one step. */
if (MemoryArea->BaseAddress != BaseAddress ||
if (MemoryArea->StartingAddress != BaseAddress ||
MemoryArea->Type != MEMORY_AREA_VIRTUAL_MEMORY)
{
MmUnlockAddressSpace(AddressSpace);
@ -829,7 +841,7 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
case MEM_DECOMMIT:
Status =
MmAlterRegion(AddressSpace,
MemoryArea->BaseAddress,
MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead,
BaseAddress,
RegionSize,
@ -856,11 +868,11 @@ MmProtectAnonMem(PMADDRESS_SPACE AddressSpace,
PMM_REGION Region;
NTSTATUS Status;
Region = MmFindRegion(MemoryArea->BaseAddress,
Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead,
BaseAddress, NULL);
*OldProtect = Region->Protect;
Status = MmAlterRegion(AddressSpace, MemoryArea->BaseAddress,
Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead,
BaseAddress, Length, Region->Type, Protect,
MmModifyAttributes);
@ -878,11 +890,11 @@ MmQueryAnonMem(PMEMORY_AREA MemoryArea,
Info->BaseAddress = (PVOID)PAGE_ROUND_DOWN(Address);
Region = MmFindRegion(MemoryArea->BaseAddress,
Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.VirtualMemoryData.RegionListHead,
Address, &RegionBase);
Info->BaseAddress = RegionBase;
Info->AllocationBase = MemoryArea->BaseAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->AllocationProtect = MemoryArea->Attributes;
Info->RegionSize = (char*)RegionBase + Region->Length - (char*)Info->BaseAddress;
Info->State = Region->Type;

View file

@ -68,7 +68,7 @@ NTSTATUS
MmInitializeAddressSpace(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace)
{
InitializeListHead(&AddressSpace->MAreaListHead);
AddressSpace->MemoryAreaRoot = NULL;
ExInitializeFastMutex(&AddressSpace->Lock);
if (Process != NULL)
{

View file

@ -1,4 +1,4 @@
/* $Id: cont.c,v 1.35 2004/10/22 20:38:22 ekohl Exp $
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -42,7 +42,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
{
PMEMORY_AREA MArea;
NTSTATUS Status;
PVOID BaseAddress = 0;
PVOID BaseAddress = NULL;
PFN_TYPE PBase;
ULONG Attributes;
ULONG i;
@ -83,8 +83,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
{
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress,
0,
MArea,
NULL,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
@ -174,11 +173,10 @@ VOID STDCALL
MmFreeContiguousMemory(IN PVOID BaseAddress)
{
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress,
0,
MmFreeContinuousPage,
NULL);
MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
BaseAddress,
MmFreeContinuousPage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}
@ -260,11 +258,10 @@ MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress,
IN MEMORY_CACHING_TYPE CacheType)
{
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress,
NumberOfBytes,
MmFreeContinuousPage,
NULL);
MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
BaseAddress,
MmFreeContinuousPage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}

View file

@ -1,4 +1,4 @@
/* $Id: drvlck.c,v 1.6 2004/08/15 16:39:06 chorns Exp $
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -64,7 +64,7 @@ PVOID STDCALL
MmLockPagableDataSection(IN PVOID AddressWithinSection)
{
PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection);
Handle = MmOpenMemoryAreaByAddress(NULL, AddressWithinSection);
MmLockPagableSectionByHandle(Handle);
return(Handle);
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: iospace.c,v 1.30 2004/08/15 16:39:07 chorns Exp $
/* $Id$
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/iospace.c
@ -127,7 +127,7 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
KEBUGCHECK(0);
}
}
return ((PVOID)((char*)Result + Offset));
return (PVOID)((ULONG_PTR)Result + Offset);
}
@ -160,16 +160,17 @@ MmUnmapIoSpace (IN PVOID BaseAddress,
IN ULONG NumberOfBytes)
{
ULONG Offset;
Offset = (ULONG_PTR)BaseAddress % PAGE_SIZE;
BaseAddress = (PVOID)((PUCHAR)BaseAddress - Offset);
PVOID Address = BaseAddress;
Offset = (ULONG_PTR)Address % PAGE_SIZE;
Address -= Offset;
NumberOfBytes += Offset;
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress,
NumberOfBytes,
NULL,
NULL);
MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
Address,
NULL,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}

File diff suppressed because it is too large Load diff

View file

@ -269,7 +269,7 @@ MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode)
KEBUGCHECK(0);
}
Base = (char*)MiMdlMappingRegionBase + StartingOffset * PAGE_SIZE;
Base = (PVOID)((ULONG_PTR)MiMdlMappingRegionBase + StartingOffset * PAGE_SIZE);
if (MiMdlMappingRegionHint == StartingOffset)
{
@ -384,7 +384,7 @@ MmUnmapLockedPages(PVOID BaseAddress, PMDL Mdl)
NULL);
}
if ((DWORD)BaseAddress >= KERNEL_BASE)
if ((ULONG_PTR)BaseAddress >= KERNEL_BASE)
{
ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
@ -416,7 +416,7 @@ MmUnmapLockedPages(PVOID BaseAddress, PMDL Mdl)
KEBUGCHECK(0);
}
MmFreeMemoryArea( &Mdl->Process->AddressSpace, Marea->BaseAddress, 0, NULL, NULL );
MmFreeMemoryArea( &Mdl->Process->AddressSpace, Marea, NULL, NULL );
Mdl->Process = NULL;
}

View file

@ -99,13 +99,13 @@ NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
DPRINT("MmReleaseMemoryArea(Process %x, Marea %x)\n",Process,Marea);
DPRINT("Releasing %x between %x %x (type %d)\n",
Marea, Marea->BaseAddress, (char*)Marea->BaseAddress + Marea->Length,
Marea, Marea->StartingAddress, Marea->EndingAddress,
Marea->Type);
switch (Marea->Type)
{
case MEMORY_AREA_SECTION_VIEW:
Status = MmUnmapViewOfSection(Process, Marea->BaseAddress);
Status = MmUnmapViewOfSection(Process, (PVOID)Marea->StartingAddress);
ASSERT(Status == STATUS_SUCCESS);
return(STATUS_SUCCESS);
@ -116,8 +116,7 @@ NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
case MEMORY_AREA_SHARED_DATA:
case MEMORY_AREA_NO_ACCESS:
Status = MmFreeMemoryArea(&Process->AddressSpace,
Marea->BaseAddress,
0,
Marea,
NULL,
NULL);
break;
@ -135,20 +134,13 @@ NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
NTSTATUS MmReleaseMmInfo(PEPROCESS Process)
{
PLIST_ENTRY CurrentEntry;
PMEMORY_AREA Current;
DPRINT("MmReleaseMmInfo(Process %x (%s))\n", Process,
Process->ImageFileName);
MmLockAddressSpace(&Process->AddressSpace);
while(!IsListEmpty(&Process->AddressSpace.MAreaListHead))
{
CurrentEntry = Process->AddressSpace.MAreaListHead.Flink;
Current = CONTAINING_RECORD(CurrentEntry, MEMORY_AREA, Entry);
MmReleaseMemoryArea(Process, Current);
}
while (Process->AddressSpace.MemoryAreaRoot != NULL)
MmReleaseMemoryArea(Process, Process->AddressSpace.MemoryAreaRoot);
Mmi386ReleaseMmInfo(Process);
@ -208,7 +200,7 @@ BOOLEAN STDCALL MmIsAddressValid(PVOID VirtualAddress)
}
NTSTATUS MmAccessFault(KPROCESSOR_MODE Mode,
ULONG Address,
ULONG Address, /* FiN TODO: Should be ULONG_PTR! */
BOOLEAN FromMdl)
{
PMADDRESS_SPACE AddressSpace;
@ -330,7 +322,7 @@ NTSTATUS MmCommitPagedPoolAddress(PVOID Address, BOOLEAN Locked)
}
NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode,
ULONG Address,
ULONG Address, /* FiN TODO: Should be ULONG_PTR! */
BOOLEAN FromMdl)
{
PMADDRESS_SPACE AddressSpace;

View file

@ -480,10 +480,9 @@ VOID
MiFreeInitMemory(VOID)
{
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
(PVOID)&_init_start__,
PAGE_ROUND_UP((ULONG)&_init_end__) - (ULONG)&_init_start__,
MiFreeInitMemoryPage,
NULL);
MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
(PVOID)&_init_start__,
MiFreeInitMemoryPage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}

View file

@ -1,4 +1,4 @@
/* $Id: ncache.c,v 1.31 2004/10/22 20:38:22 ekohl Exp $
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -129,11 +129,10 @@ VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
IN ULONG NumberOfBytes)
{
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea (MmGetKernelAddressSpace(),
BaseAddress,
NumberOfBytes,
MmFreeNonCachedPage,
NULL);
MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
BaseAddress,
MmFreeNonCachedPage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: pe.c,v 1.2 2004/12/30 05:59:11 hyperion Exp $
/* $Id$
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/pe.c
@ -35,7 +35,7 @@
#include <ntoskrnl.h>
#define NDEBUG
//#define NDEBUG
#include <internal/debug.h>
#include <reactos/exeformat.h>
@ -666,8 +666,10 @@ l_ReadHeaderFromFile:
DIE(("PointerToRawData[%u] is not aligned\n", i));
/* sections must be contiguous, ordered by base address and non-overlapping */
#if 0
if(pishSectionHeaders[i].PointerToRawData != nPrevFileEndOfSegment)
DIE(("File gap between section %u and the previous\n", i));
#endif
/* conversion */
pssSegments[i].FileOffset = pishSectionHeaders[i].PointerToRawData;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: rmap.c,v 1.32 2004/12/24 17:06:59 navaraf Exp $
/* $Id$
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -91,7 +91,7 @@ MmWritePagePhysicalAddress(PFN_TYPE Page)
}
Process = entry->Process;
Address = entry->Address;
if ((((ULONG)Address) & 0xFFF) != 0)
if ((((ULONG_PTR)Address) & 0xFFF) != 0)
{
KEBUGCHECK(0);
}
@ -131,7 +131,7 @@ MmWritePagePhysicalAddress(PFN_TYPE Page)
Type = MemoryArea->Type;
if (Type == MEMORY_AREA_SECTION_VIEW)
{
Offset = (ULONG)((char*)Address - (ULONG)MemoryArea->BaseAddress);
Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
/*
* Get or create a pageop
@ -220,7 +220,7 @@ MmPageOutPhysicalAddress(PFN_TYPE Page)
}
Process = entry->Process;
Address = entry->Address;
if ((((ULONG)Address) & 0xFFF) != 0)
if ((((ULONG_PTR)Address) & 0xFFF) != 0)
{
KEBUGCHECK(0);
}
@ -255,7 +255,7 @@ MmPageOutPhysicalAddress(PFN_TYPE Page)
Type = MemoryArea->Type;
if (Type == MEMORY_AREA_SECTION_VIEW)
{
Offset = (ULONG)((char*)Address - (ULONG)MemoryArea->BaseAddress);
Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
/*
* Get or create a pageop

View file

@ -611,7 +611,7 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
ULONG Offset;
PFN_TYPE Page;
NTSTATUS Status;
ULONG PAddress;
PVOID PAddress;
PSECTION_OBJECT Section;
PMM_SECTION_SEGMENT Segment;
ULONG Entry;
@ -635,12 +635,12 @@ MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
return(STATUS_SUCCESS);
}
PAddress = (ULONG)PAGE_ROUND_DOWN(((ULONG)Address));
Offset = PAddress - (ULONG)MemoryArea->BaseAddress;
PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
Offset = (ULONG_PTR)PAddress - (ULONG_PTR)MemoryArea->StartingAddress;
Segment = MemoryArea->Data.SectionData.Segment;
Section = MemoryArea->Data.SectionData.Section;
Region = MmFindRegion(MemoryArea->BaseAddress,
Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
Address, NULL);
/*
@ -1129,7 +1129,7 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
PFN_TYPE NewPage;
PVOID NewAddress;
NTSTATUS Status;
ULONG PAddress;
PVOID PAddress;
ULONG Offset;
PMM_PAGEOP PageOp;
PMM_REGION Region;
@ -1148,12 +1148,12 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
/*
* Find the offset of the page
*/
PAddress = (ULONG)PAGE_ROUND_DOWN(((ULONG)Address));
Offset = PAddress - (ULONG)MemoryArea->BaseAddress;
PAddress = MM_ROUND_DOWN(Address, PAGE_SIZE);
Offset = (ULONG_PTR)PAddress - (ULONG_PTR)MemoryArea->StartingAddress;
Segment = MemoryArea->Data.SectionData.Segment;
Section = MemoryArea->Data.SectionData.Section;
Region = MmFindRegion(MemoryArea->BaseAddress,
Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
Address, NULL);
/*
@ -1181,7 +1181,7 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
PFN_FROM_SSE(Entry) != OldPage)
{
/* This is a private page. We must only change the page protection. */
MmSetPageProtect(AddressSpace->Process, (PVOID)PAddress, Region->Protect);
MmSetPageProtect(AddressSpace->Process, PAddress, Region->Protect);
return(STATUS_SUCCESS);
}
@ -1244,7 +1244,7 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
*/
NewAddress = ExAllocatePageWithPhysPage(NewPage);
memcpy(NewAddress, (PVOID)PAddress, PAGE_SIZE);
memcpy(NewAddress, PAddress, PAGE_SIZE);
ExUnmapPage(NewAddress);
/*
@ -1267,7 +1267,7 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
KEBUGCHECK(0);
return(Status);
}
MmInsertRmap(NewPage, AddressSpace->Process, (PVOID)PAddress);
MmInsertRmap(NewPage, AddressSpace->Process, PAddress);
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
@ -1282,7 +1282,7 @@ MmAccessFaultSectionView(PMADDRESS_SPACE AddressSpace,
/*
* Unshare the old page.
*/
MmDeleteRmap(OldPage, AddressSpace->Process, (PVOID)PAddress);
MmDeleteRmap(OldPage, AddressSpace->Process, PAddress);
MmLockSectionSegment(Segment);
MmUnsharePageEntrySectionSegment(Section, Segment, Offset, FALSE, FALSE);
MmUnlockSectionSegment(Segment);
@ -1351,7 +1351,7 @@ MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
Context.Segment = MemoryArea->Data.SectionData.Segment;
Context.Section = MemoryArea->Data.SectionData.Section;
Context.Offset = (ULONG)((char*)Address - (ULONG)MemoryArea->BaseAddress);
Context.Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
FileOffset = Context.Offset + Context.Segment->FileOffset;
IsImageSection = Context.Section->AllocationAttributes & SEC_IMAGE ? TRUE : FALSE;
@ -1691,7 +1691,7 @@ MmWritePageSectionView(PMADDRESS_SPACE AddressSpace,
Address = (PVOID)PAGE_ROUND_DOWN(Address);
Offset = (ULONG)((char*)Address - (ULONG)MemoryArea->BaseAddress);
Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
/*
* Get the segment and section.
@ -1855,7 +1855,7 @@ MmAlterViewAttributes(PMADDRESS_SPACE AddressSpace,
ULONG Entry;
PFN_TYPE Page;
Offset = (ULONG)Address - (ULONG)MemoryArea->BaseAddress;
Offset = (ULONG_PTR)Address - (ULONG_PTR)MemoryArea->StartingAddress;
Entry = MmGetPageEntrySectionSegment(Segment, Offset);
Page = MmGetPfnForProcess(AddressSpace->Process, Address);
@ -1887,14 +1887,17 @@ MmProtectSectionView(PMADDRESS_SPACE AddressSpace,
{
PMM_REGION Region;
NTSTATUS Status;
ULONG_PTR MaxLength;
Length =
min(Length, (ULONG) ((char*)MemoryArea->BaseAddress + MemoryArea->Length - (char*)BaseAddress));
Region = MmFindRegion(MemoryArea->BaseAddress,
MaxLength = (ULONG_PTR)MemoryArea->EndingAddress - (ULONG_PTR)BaseAddress;
if (Length > MaxLength)
Length = MaxLength;
Region = MmFindRegion(MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
BaseAddress, NULL);
*OldProtect = Region->Protect;
Status = MmAlterRegion(AddressSpace, MemoryArea->BaseAddress,
Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
BaseAddress, Length, Region->Type, Protect,
MmAlterViewAttributes);
@ -1915,7 +1918,7 @@ MmQuerySectionView(PMEMORY_AREA MemoryArea,
PMEMORY_AREA CurrentMArea;
KIRQL oldIrql;
Region = MmFindRegion(MemoryArea->BaseAddress,
Region = MmFindRegion((PVOID)MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead,
Address, &RegionBaseAddress);
if (Region == NULL)
@ -1934,11 +1937,11 @@ MmQuerySectionView(PMEMORY_AREA MemoryArea,
CurrentEntry = CurrentEntry->Flink;
if (Info->AllocationBase == NULL)
{
Info->AllocationBase = CurrentMArea->BaseAddress;
Info->AllocationBase = CurrentMArea->StartingAddress;
}
else if (CurrentMArea->BaseAddress < Info->AllocationBase)
else if (CurrentMArea->StartingAddress < Info->AllocationBase)
{
Info->AllocationBase = CurrentMArea->BaseAddress;
Info->AllocationBase = CurrentMArea->StartingAddress;
}
}
KeReleaseSpinLock(&Section->ViewListLock, oldIrql);
@ -1949,11 +1952,12 @@ MmQuerySectionView(PMEMORY_AREA MemoryArea,
else
{
Info->BaseAddress = RegionBaseAddress;
Info->AllocationBase = MemoryArea->BaseAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->AllocationProtect = MemoryArea->Attributes;
Info->Type = MEM_MAPPED;
}
Info->RegionSize = PAGE_ROUND_UP(MemoryArea->Length);
Info->RegionSize = PAGE_ROUND_UP((ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress);
Info->State = MEM_COMMIT;
Info->Protect = Region->Protect;
@ -3583,7 +3587,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
Address = (PVOID)PAGE_ROUND_DOWN(Address);
Offset = ((ULONG_PTR)Address - (ULONG_PTR)MArea->BaseAddress) +
Offset = ((ULONG_PTR)Address - (ULONG_PTR)MArea->StartingAddress) +
MemoryArea->Data.SectionData.ViewOffset;
Section = MArea->Data.SectionData.Section;
@ -3711,16 +3715,14 @@ MmUnmapViewOfSegment(PMADDRESS_SPACE AddressSpace,
if (Section->AllocationAttributes & SEC_PHYSICALMEMORY)
{
Status = MmFreeMemoryArea(AddressSpace,
BaseAddress,
0,
MemoryArea,
NULL,
NULL);
}
else
{
Status = MmFreeMemoryArea(AddressSpace,
BaseAddress,
0,
MemoryArea,
MmFreeSectionPage,
MemoryArea);
}
@ -4087,7 +4089,7 @@ MmAllocateSection (IN ULONG Length, PVOID BaseAddress)
KEBUGCHECK(0);
}
Status = MmCreateVirtualMapping (NULL,
((char*)Result + (i * PAGE_SIZE)),
(PVOID)(Result + (i * PAGE_SIZE)),
PAGE_READWRITE,
&Page,
1);
@ -4178,7 +4180,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
{
ULONG i;
ULONG NrSegments;
PVOID ImageBase;
ULONG_PTR ImageBase;
ULONG ImageSize;
PMM_IMAGE_SECTION_OBJECT ImageSectionObject;
PMM_SECTION_SEGMENT SectionSegments;
@ -4188,10 +4190,10 @@ MmMapViewOfSection(IN PVOID SectionObject,
NrSegments = ImageSectionObject->NrSegments;
ImageBase = *BaseAddress;
if (ImageBase == NULL)
ImageBase = (ULONG_PTR)*BaseAddress;
if (ImageBase == 0)
{
ImageBase = (PVOID)ImageSectionObject->ImageBase;
ImageBase = ImageSectionObject->ImageBase;
}
ImageSize = 0;
@ -4207,7 +4209,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
}
/* Check there is enough space to map the section at that point. */
if (MmOpenMemoryAreaByRegion(AddressSpace, ImageBase,
if (MmOpenMemoryAreaByRegion(AddressSpace, (PVOID)ImageBase,
PAGE_ROUND_UP(ImageSize)) != NULL)
{
/* Fail if the user requested a fixed base address. */
@ -4217,8 +4219,8 @@ MmMapViewOfSection(IN PVOID SectionObject,
return(STATUS_UNSUCCESSFUL);
}
/* Otherwise find a gap to map the image. */
ImageBase = MmFindGap(AddressSpace, PAGE_ROUND_UP(ImageSize), PAGE_SIZE, FALSE);
if (ImageBase == NULL)
ImageBase = (ULONG_PTR)MmFindGap(AddressSpace, PAGE_ROUND_UP(ImageSize), PAGE_SIZE, FALSE);
if (ImageBase == 0)
{
MmUnlockAddressSpace(AddressSpace);
return(STATUS_UNSUCCESSFUL);
@ -4250,7 +4252,7 @@ MmMapViewOfSection(IN PVOID SectionObject,
}
}
*BaseAddress = ImageBase;
*BaseAddress = (PVOID)ImageBase;
}
else
{

View file

@ -204,9 +204,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_FREE;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress;
Info->AllocationBase = MemoryArea->BaseAddress;
Info->RegionSize = MemoryArea->Length;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break;
@ -215,9 +216,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress;
Info->AllocationBase = MemoryArea->BaseAddress;
Info->RegionSize = MemoryArea->Length;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break;
@ -235,9 +237,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress;
Info->AllocationBase = MemoryArea->BaseAddress;
Info->RegionSize = MemoryArea->Length;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break;
@ -255,9 +258,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress;
Info->AllocationBase = MemoryArea->BaseAddress;
Info->RegionSize = MemoryArea->Length;
Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break;

View file

@ -1,4 +1,4 @@
/* $Id: w32call.c,v 1.21 2004/11/28 18:14:02 blight Exp $
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -163,11 +163,10 @@ VOID STATIC
PsFreeCallbackStack(PVOID StackLimit)
{
MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(),
StackLimit,
MM_STACK_SIZE,
PsFreeCallbackStackPage,
NULL);
MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
StackLimit,
PsFreeCallbackStackPage,
NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace());
}