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 * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * PROJECT: ReactOS kernel
* FILE: ntoskrnl/cc/view.c * FILE: ntoskrnl/cc/view.c
@ -813,8 +813,7 @@ CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg)
#else #else
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryArea(MmGetKernelAddressSpace(),
CacheSeg->BaseAddress, CacheSeg->MemoryArea,
CacheSeg->Bcb->CacheSegmentSize,
CcFreeCachePage, CcFreeCachePage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); MmUnlockAddressSpace(MmGetKernelAddressSpace());

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -68,7 +68,7 @@ NTSTATUS
MmInitializeAddressSpace(PEPROCESS Process, MmInitializeAddressSpace(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace) PMADDRESS_SPACE AddressSpace)
{ {
InitializeListHead(&AddressSpace->MAreaListHead); AddressSpace->MemoryAreaRoot = NULL;
ExInitializeFastMutex(&AddressSpace->Lock); ExInitializeFastMutex(&AddressSpace->Lock);
if (Process != NULL) 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -42,7 +42,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
{ {
PMEMORY_AREA MArea; PMEMORY_AREA MArea;
NTSTATUS Status; NTSTATUS Status;
PVOID BaseAddress = 0; PVOID BaseAddress = NULL;
PFN_TYPE PBase; PFN_TYPE PBase;
ULONG Attributes; ULONG Attributes;
ULONG i; ULONG i;
@ -83,8 +83,7 @@ MmAllocateContiguousAlignedMemory(IN ULONG NumberOfBytes,
{ {
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryArea(MmGetKernelAddressSpace(),
BaseAddress, MArea,
0,
NULL, NULL,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); MmUnlockAddressSpace(MmGetKernelAddressSpace());
@ -174,9 +173,8 @@ VOID STDCALL
MmFreeContiguousMemory(IN PVOID BaseAddress) MmFreeContiguousMemory(IN PVOID BaseAddress)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
BaseAddress, BaseAddress,
0,
MmFreeContinuousPage, MmFreeContinuousPage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); MmUnlockAddressSpace(MmGetKernelAddressSpace());
@ -260,9 +258,8 @@ MmFreeContiguousMemorySpecifyCache(IN PVOID BaseAddress,
IN MEMORY_CACHING_TYPE CacheType) IN MEMORY_CACHING_TYPE CacheType)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
BaseAddress, BaseAddress,
NumberOfBytes,
MmFreeContinuousPage, MmFreeContinuousPage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -64,7 +64,7 @@ PVOID STDCALL
MmLockPagableDataSection(IN PVOID AddressWithinSection) MmLockPagableDataSection(IN PVOID AddressWithinSection)
{ {
PVOID Handle; PVOID Handle;
Handle = MmOpenMemoryAreaByAddress(NULL,AddressWithinSection); Handle = MmOpenMemoryAreaByAddress(NULL, AddressWithinSection);
MmLockPagableSectionByHandle(Handle); MmLockPagableSectionByHandle(Handle);
return(Handle); return(Handle);
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/iospace.c * FILE: ntoskrnl/mm/iospace.c
@ -127,7 +127,7 @@ MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
KEBUGCHECK(0); KEBUGCHECK(0);
} }
} }
return ((PVOID)((char*)Result + Offset)); return (PVOID)((ULONG_PTR)Result + Offset);
} }
@ -160,14 +160,15 @@ MmUnmapIoSpace (IN PVOID BaseAddress,
IN ULONG NumberOfBytes) IN ULONG NumberOfBytes)
{ {
ULONG Offset; ULONG Offset;
Offset = (ULONG_PTR)BaseAddress % PAGE_SIZE; PVOID Address = BaseAddress;
BaseAddress = (PVOID)((PUCHAR)BaseAddress - Offset);
Offset = (ULONG_PTR)Address % PAGE_SIZE;
Address -= Offset;
NumberOfBytes += Offset; NumberOfBytes += Offset;
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
BaseAddress, Address,
NumberOfBytes,
NULL, NULL,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); 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); KEBUGCHECK(0);
} }
Base = (char*)MiMdlMappingRegionBase + StartingOffset * PAGE_SIZE; Base = (PVOID)((ULONG_PTR)MiMdlMappingRegionBase + StartingOffset * PAGE_SIZE);
if (MiMdlMappingRegionHint == StartingOffset) if (MiMdlMappingRegionHint == StartingOffset)
{ {
@ -384,7 +384,7 @@ MmUnmapLockedPages(PVOID BaseAddress, PMDL Mdl)
NULL); NULL);
} }
if ((DWORD)BaseAddress >= KERNEL_BASE) if ((ULONG_PTR)BaseAddress >= KERNEL_BASE)
{ {
ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA); ASSERT(Mdl->MdlFlags & MDL_MAPPED_TO_SYSTEM_VA);
@ -416,7 +416,7 @@ MmUnmapLockedPages(PVOID BaseAddress, PMDL Mdl)
KEBUGCHECK(0); KEBUGCHECK(0);
} }
MmFreeMemoryArea( &Mdl->Process->AddressSpace, Marea->BaseAddress, 0, NULL, NULL ); MmFreeMemoryArea( &Mdl->Process->AddressSpace, Marea, NULL, NULL );
Mdl->Process = 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("MmReleaseMemoryArea(Process %x, Marea %x)\n",Process,Marea);
DPRINT("Releasing %x between %x %x (type %d)\n", DPRINT("Releasing %x between %x %x (type %d)\n",
Marea, Marea->BaseAddress, (char*)Marea->BaseAddress + Marea->Length, Marea, Marea->StartingAddress, Marea->EndingAddress,
Marea->Type); Marea->Type);
switch (Marea->Type) switch (Marea->Type)
{ {
case MEMORY_AREA_SECTION_VIEW: case MEMORY_AREA_SECTION_VIEW:
Status = MmUnmapViewOfSection(Process, Marea->BaseAddress); Status = MmUnmapViewOfSection(Process, (PVOID)Marea->StartingAddress);
ASSERT(Status == STATUS_SUCCESS); ASSERT(Status == STATUS_SUCCESS);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
@ -116,8 +116,7 @@ NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
case MEMORY_AREA_SHARED_DATA: case MEMORY_AREA_SHARED_DATA:
case MEMORY_AREA_NO_ACCESS: case MEMORY_AREA_NO_ACCESS:
Status = MmFreeMemoryArea(&Process->AddressSpace, Status = MmFreeMemoryArea(&Process->AddressSpace,
Marea->BaseAddress, Marea,
0,
NULL, NULL,
NULL); NULL);
break; break;
@ -135,20 +134,13 @@ NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
NTSTATUS MmReleaseMmInfo(PEPROCESS Process) NTSTATUS MmReleaseMmInfo(PEPROCESS Process)
{ {
PLIST_ENTRY CurrentEntry;
PMEMORY_AREA Current;
DPRINT("MmReleaseMmInfo(Process %x (%s))\n", Process, DPRINT("MmReleaseMmInfo(Process %x (%s))\n", Process,
Process->ImageFileName); Process->ImageFileName);
MmLockAddressSpace(&Process->AddressSpace); MmLockAddressSpace(&Process->AddressSpace);
while(!IsListEmpty(&Process->AddressSpace.MAreaListHead)) while (Process->AddressSpace.MemoryAreaRoot != NULL)
{ MmReleaseMemoryArea(Process, Process->AddressSpace.MemoryAreaRoot);
CurrentEntry = Process->AddressSpace.MAreaListHead.Flink;
Current = CONTAINING_RECORD(CurrentEntry, MEMORY_AREA, Entry);
MmReleaseMemoryArea(Process, Current);
}
Mmi386ReleaseMmInfo(Process); Mmi386ReleaseMmInfo(Process);
@ -208,7 +200,7 @@ BOOLEAN STDCALL MmIsAddressValid(PVOID VirtualAddress)
} }
NTSTATUS MmAccessFault(KPROCESSOR_MODE Mode, NTSTATUS MmAccessFault(KPROCESSOR_MODE Mode,
ULONG Address, ULONG Address, /* FiN TODO: Should be ULONG_PTR! */
BOOLEAN FromMdl) BOOLEAN FromMdl)
{ {
PMADDRESS_SPACE AddressSpace; PMADDRESS_SPACE AddressSpace;
@ -330,7 +322,7 @@ NTSTATUS MmCommitPagedPoolAddress(PVOID Address, BOOLEAN Locked)
} }
NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode, NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode,
ULONG Address, ULONG Address, /* FiN TODO: Should be ULONG_PTR! */
BOOLEAN FromMdl) BOOLEAN FromMdl)
{ {
PMADDRESS_SPACE AddressSpace; PMADDRESS_SPACE AddressSpace;

View file

@ -480,9 +480,8 @@ VOID
MiFreeInitMemory(VOID) MiFreeInitMemory(VOID)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
(PVOID)&_init_start__, (PVOID)&_init_start__,
PAGE_ROUND_UP((ULONG)&_init_end__) - (ULONG)&_init_start__,
MiFreeInitMemoryPage, MiFreeInitMemoryPage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -129,9 +129,8 @@ VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
IN ULONG NumberOfBytes) IN ULONG NumberOfBytes)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea (MmGetKernelAddressSpace(), MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
BaseAddress, BaseAddress,
NumberOfBytes,
MmFreeNonCachedPage, MmFreeNonCachedPage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); MmUnlockAddressSpace(MmGetKernelAddressSpace());

View file

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

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -91,7 +91,7 @@ MmWritePagePhysicalAddress(PFN_TYPE Page)
} }
Process = entry->Process; Process = entry->Process;
Address = entry->Address; Address = entry->Address;
if ((((ULONG)Address) & 0xFFF) != 0) if ((((ULONG_PTR)Address) & 0xFFF) != 0)
{ {
KEBUGCHECK(0); KEBUGCHECK(0);
} }
@ -131,7 +131,7 @@ MmWritePagePhysicalAddress(PFN_TYPE Page)
Type = MemoryArea->Type; Type = MemoryArea->Type;
if (Type == MEMORY_AREA_SECTION_VIEW) 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 * Get or create a pageop
@ -220,7 +220,7 @@ MmPageOutPhysicalAddress(PFN_TYPE Page)
} }
Process = entry->Process; Process = entry->Process;
Address = entry->Address; Address = entry->Address;
if ((((ULONG)Address) & 0xFFF) != 0) if ((((ULONG_PTR)Address) & 0xFFF) != 0)
{ {
KEBUGCHECK(0); KEBUGCHECK(0);
} }
@ -255,7 +255,7 @@ MmPageOutPhysicalAddress(PFN_TYPE Page)
Type = MemoryArea->Type; Type = MemoryArea->Type;
if (Type == MEMORY_AREA_SECTION_VIEW) 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 * Get or create a pageop

View file

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

View file

@ -204,9 +204,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_FREE; Info->State = MEM_FREE;
Info->Protect = MemoryArea->Attributes; Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes; Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress; Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->BaseAddress; Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = MemoryArea->Length; Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION); *ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break; break;
@ -215,9 +216,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_COMMIT; Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes; Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes; Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress; Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->BaseAddress; Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = MemoryArea->Length; Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION); *ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break; break;
@ -235,9 +237,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_COMMIT; Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes; Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes; Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress; Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->BaseAddress; Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = MemoryArea->Length; Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION); *ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break; break;
@ -255,9 +258,10 @@ MiQueryVirtualMemory (IN HANDLE ProcessHandle,
Info->State = MEM_COMMIT; Info->State = MEM_COMMIT;
Info->Protect = MemoryArea->Attributes; Info->Protect = MemoryArea->Attributes;
Info->AllocationProtect = MemoryArea->Attributes; Info->AllocationProtect = MemoryArea->Attributes;
Info->BaseAddress = MemoryArea->BaseAddress; Info->BaseAddress = MemoryArea->StartingAddress;
Info->AllocationBase = MemoryArea->BaseAddress; Info->AllocationBase = MemoryArea->StartingAddress;
Info->RegionSize = MemoryArea->Length; Info->RegionSize = (ULONG_PTR)MemoryArea->EndingAddress -
(ULONG_PTR)MemoryArea->StartingAddress;
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
*ResultLength = sizeof(MEMORY_BASIC_INFORMATION); *ResultLength = sizeof(MEMORY_BASIC_INFORMATION);
break; 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -163,9 +163,8 @@ VOID STATIC
PsFreeCallbackStack(PVOID StackLimit) PsFreeCallbackStack(PVOID StackLimit)
{ {
MmLockAddressSpace(MmGetKernelAddressSpace()); MmLockAddressSpace(MmGetKernelAddressSpace());
MmFreeMemoryArea(MmGetKernelAddressSpace(), MmFreeMemoryAreaByPtr(MmGetKernelAddressSpace(),
StackLimit, StackLimit,
MM_STACK_SIZE,
PsFreeCallbackStackPage, PsFreeCallbackStackPage,
NULL); NULL);
MmUnlockAddressSpace(MmGetKernelAddressSpace()); MmUnlockAddressSpace(MmGetKernelAddressSpace());