[NTOSKRNL]

Convert StartingAddress and EndingAddress members in MEMORY_AREA to ULONG_PTR. Remove unused MmFindGapAtAddress.

svn path=/trunk/; revision=67784
This commit is contained in:
Timo Kreuzer 2015-05-16 20:09:40 +00:00
parent 199d9183e6
commit 418daaac86
4 changed files with 26 additions and 91 deletions

View file

@ -201,8 +201,8 @@ typedef struct _ROS_SECTION_OBJECT
typedef struct _MEMORY_AREA typedef struct _MEMORY_AREA
{ {
PVOID StartingAddress; ULONG_PTR StartingAddress;
PVOID EndingAddress; ULONG_PTR EndingAddress;
struct _MEMORY_AREA *Parent; struct _MEMORY_AREA *Parent;
struct _MEMORY_AREA *LeftChild; struct _MEMORY_AREA *LeftChild;
struct _MEMORY_AREA *RightChild; struct _MEMORY_AREA *RightChild;
@ -495,14 +495,6 @@ MmLocateMemoryAreaByAddress(
PVOID Address PVOID Address
); );
// fixme: unused?
ULONG_PTR
NTAPI
MmFindGapAtAddress_(
PMMSUPPORT AddressSpace,
PVOID Address
);
NTSTATUS NTSTATUS
NTAPI NTAPI
MmFreeMemoryArea( MmFreeMemoryArea(

View file

@ -5317,10 +5317,10 @@ NtFreeVirtualMemory(IN HANDLE ProcessHandle,
Vad->u.VadFlags.CommitCharge -= CommitReduction; Vad->u.VadFlags.CommitCharge -= CommitReduction;
// For ReactOS: shrink the corresponding memory area // For ReactOS: shrink the corresponding memory area
MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)StartingAddress); MemoryArea = MmLocateMemoryAreaByAddress(AddressSpace, (PVOID)StartingAddress);
ASSERT(Vad->StartingVpn << PAGE_SHIFT == (ULONG_PTR)MemoryArea->StartingAddress); ASSERT(Vad->StartingVpn << PAGE_SHIFT == MemoryArea->StartingAddress);
ASSERT((Vad->EndingVpn + 1) << PAGE_SHIFT == (ULONG_PTR)MemoryArea->EndingAddress); ASSERT((Vad->EndingVpn + 1) << PAGE_SHIFT == MemoryArea->EndingAddress);
Vad->EndingVpn = ((ULONG_PTR)StartingAddress - 1) >> PAGE_SHIFT; Vad->EndingVpn = (StartingAddress - 1) >> PAGE_SHIFT;
MemoryArea->EndingAddress = (PVOID)(StartingAddress); MemoryArea->EndingAddress = StartingAddress;
} }
else else
{ {

View file

@ -162,9 +162,10 @@ static PMEMORY_AREA MmIteratePrevNode(PMEMORY_AREA Node)
PMEMORY_AREA NTAPI PMEMORY_AREA NTAPI
MmLocateMemoryAreaByAddress( MmLocateMemoryAreaByAddress(
PMMSUPPORT AddressSpace, PMMSUPPORT AddressSpace,
PVOID Address) PVOID Address_)
{ {
PMEMORY_AREA Node = (PMEMORY_AREA)AddressSpace->WorkingSetExpansionLinks.Flink; PMEMORY_AREA Node = (PMEMORY_AREA)AddressSpace->WorkingSetExpansionLinks.Flink;
ULONG_PTR Address = (ULONG_PTR)Address_;
DPRINT("MmLocateMemoryAreaByAddress(AddressSpace %p, Address %p)\n", DPRINT("MmLocateMemoryAreaByAddress(AddressSpace %p, Address %p)\n",
AddressSpace, Address); AddressSpace, Address);
@ -190,11 +191,12 @@ MmLocateMemoryAreaByAddress(
PMEMORY_AREA NTAPI PMEMORY_AREA NTAPI
MmLocateMemoryAreaByRegion( MmLocateMemoryAreaByRegion(
PMMSUPPORT AddressSpace, PMMSUPPORT AddressSpace,
PVOID Address, PVOID Address_,
ULONG_PTR Length) ULONG_PTR Length)
{ {
PMEMORY_AREA Node; PMEMORY_AREA Node;
PVOID Extent = (PVOID)((ULONG_PTR)Address + Length); ULONG_PTR Address = (ULONG_PTR)Address_;
ULONG_PTR Extent = Address + Length;
/* Special case for empty tree. */ /* Special case for empty tree. */
if (AddressSpace->WorkingSetExpansionLinks.Flink == NULL) if (AddressSpace->WorkingSetExpansionLinks.Flink == NULL)
@ -376,7 +378,8 @@ MmInsertMemoryArea(
PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace); PEPROCESS Process = MmGetAddressSpaceOwner(AddressSpace);
/* Build a lame VAD if this is a user-space allocation */ /* Build a lame VAD if this is a user-space allocation */
if ((marea->EndingAddress < MmSystemRangeStart) && (marea->Type != MEMORY_AREA_OWNED_BY_ARM3)) if ((marea->EndingAddress < (ULONG_PTR)MmSystemRangeStart) &&
(marea->Type != MEMORY_AREA_OWNED_BY_ARM3))
{ {
PMMVAD Vad; PMMVAD Vad;
@ -610,66 +613,6 @@ MmFindGap(
return MmFindGapBottomUp(AddressSpace, Length, Granularity); return MmFindGapBottomUp(AddressSpace, Length, Granularity);
} }
ULONG_PTR NTAPI
MmFindGapAtAddress(
PMMSUPPORT AddressSpace,
PVOID Address)
{
PMEMORY_AREA Node = (PMEMORY_AREA)AddressSpace->WorkingSetExpansionLinks.Flink;
PMEMORY_AREA RightNeighbour = NULL;
PVOID LowestAddress = MmGetAddressSpaceOwner(AddressSpace) ? MM_LOWEST_USER_ADDRESS : MmSystemRangeStart;
PVOID HighestAddress = MmGetAddressSpaceOwner(AddressSpace) ?
(PVOID)((ULONG_PTR)MmSystemRangeStart - 1) : (PVOID)MAXULONG_PTR;
Address = MM_ROUND_DOWN(Address, PAGE_SIZE);
if (LowestAddress < MmSystemRangeStart)
{
if (Address >= MmSystemRangeStart)
{
return 0;
}
}
else
{
if (Address < LowestAddress)
{
return 0;
}
}
while (Node != NULL)
{
if (Address < Node->StartingAddress)
{
RightNeighbour = Node;
Node = Node->LeftChild;
}
else if (Address >= Node->EndingAddress)
{
Node = Node->RightChild;
}
else
{
DPRINT("MmFindGapAtAddress: 0\n");
return 0;
}
}
if (RightNeighbour)
{
DPRINT("MmFindGapAtAddress: %p [%p]\n", Address,
(ULONG_PTR)RightNeighbour->StartingAddress - (ULONG_PTR)Address);
return (ULONG_PTR)RightNeighbour->StartingAddress - (ULONG_PTR)Address;
}
else
{
DPRINT("MmFindGapAtAddress: %p [%p]\n", Address,
(ULONG_PTR)HighestAddress - (ULONG_PTR)Address);
return (ULONG_PTR)HighestAddress - (ULONG_PTR)Address;
}
}
VOID VOID
NTAPI NTAPI
MiRemoveNode(IN PMMADDRESS_NODE Node, MiRemoveNode(IN PMMADDRESS_NODE Node,
@ -687,10 +630,10 @@ MiRosCheckMemoryAreasRecursive(
/* Check some fields */ /* Check some fields */
ASSERT(Node->Magic == 'erAM'); ASSERT(Node->Magic == 'erAM');
ASSERT(PAGE_ALIGN(Node->StartingAddress) == Node->StartingAddress); ASSERT(PAGE_ALIGN(Node->StartingAddress) == (PVOID)Node->StartingAddress);
ASSERT(Node->EndingAddress != NULL); ASSERT(Node->EndingAddress != 0);
ASSERT(PAGE_ALIGN(Node->EndingAddress) == Node->EndingAddress); ASSERT(PAGE_ALIGN(Node->EndingAddress) == (PVOID)Node->EndingAddress);
ASSERT((ULONG_PTR)Node->StartingAddress < (ULONG_PTR)Node->EndingAddress); ASSERT(Node->StartingAddress < Node->EndingAddress);
ASSERT((Node->Type == 0) || ASSERT((Node->Type == 0) ||
(Node->Type == MEMORY_AREA_CACHE) || (Node->Type == MEMORY_AREA_CACHE) ||
// (Node->Type == MEMORY_AREA_CACHE_SEGMENT) || // (Node->Type == MEMORY_AREA_CACHE_SEGMENT) ||
@ -872,7 +815,7 @@ MmFreeMemoryArea(
if (MemoryArea->Vad) if (MemoryArea->Vad)
{ {
ASSERT(MemoryArea->EndingAddress < MmSystemRangeStart); ASSERT(MemoryArea->EndingAddress < (ULONG_PTR)MmSystemRangeStart);
ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW || MemoryArea->Type == MEMORY_AREA_CACHE); ASSERT(MemoryArea->Type == MEMORY_AREA_SECTION_VIEW || MemoryArea->Type == MEMORY_AREA_CACHE);
/* MmCleanProcessAddressSpace might have removed it (and this would be MmDeleteProcessAdressSpace) */ /* MmCleanProcessAddressSpace might have removed it (and this would be MmDeleteProcessAdressSpace) */
@ -1065,8 +1008,8 @@ MmCreateMemoryArea(PMMSUPPORT AddressSpace,
RtlZeroMemory(MemoryArea, sizeof(MEMORY_AREA)); RtlZeroMemory(MemoryArea, sizeof(MEMORY_AREA));
MemoryArea->Type = Type; MemoryArea->Type = Type;
MemoryArea->StartingAddress = *BaseAddress; MemoryArea->StartingAddress = (ULONG_PTR)*BaseAddress;
MemoryArea->EndingAddress = (PVOID)((ULONG_PTR)*BaseAddress + tmpLength); MemoryArea->EndingAddress = ((ULONG_PTR)*BaseAddress + tmpLength);
MemoryArea->Protect = Protect; MemoryArea->Protect = Protect;
MemoryArea->Flags = AllocationFlags; MemoryArea->Flags = AllocationFlags;
//MemoryArea->LockCount = 0; //MemoryArea->LockCount = 0;

View file

@ -1328,7 +1328,7 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
Segment = MemoryArea->Data.SectionData.Segment; Segment = MemoryArea->Data.SectionData.Segment;
Section = MemoryArea->Data.SectionData.Section; Section = MemoryArea->Data.SectionData.Section;
Region = MmFindRegion(MemoryArea->StartingAddress, Region = MmFindRegion((PVOID)MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead, &MemoryArea->Data.SectionData.RegionListHead,
Address, NULL); Address, NULL);
ASSERT(Region != NULL); ASSERT(Region != NULL);
@ -1705,7 +1705,7 @@ MmAccessFaultSectionView(PMMSUPPORT AddressSpace,
Segment = MemoryArea->Data.SectionData.Segment; Segment = MemoryArea->Data.SectionData.Segment;
Section = MemoryArea->Data.SectionData.Section; Section = MemoryArea->Data.SectionData.Section;
Region = MmFindRegion(MemoryArea->StartingAddress, Region = MmFindRegion((PVOID)MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead, &MemoryArea->Data.SectionData.RegionListHead,
Address, NULL); Address, NULL);
ASSERT(Region != NULL); ASSERT(Region != NULL);
@ -2520,11 +2520,11 @@ MmProtectSectionView(PMMSUPPORT AddressSpace,
NTSTATUS Status; NTSTATUS Status;
ULONG_PTR MaxLength; ULONG_PTR MaxLength;
MaxLength = (ULONG_PTR)MemoryArea->EndingAddress - (ULONG_PTR)BaseAddress; MaxLength = MemoryArea->EndingAddress - (ULONG_PTR)BaseAddress;
if (Length > MaxLength) if (Length > MaxLength)
Length = (ULONG)MaxLength; Length = (ULONG)MaxLength;
Region = MmFindRegion(MemoryArea->StartingAddress, Region = MmFindRegion((PVOID)MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead, &MemoryArea->Data.SectionData.RegionListHead,
BaseAddress, NULL); BaseAddress, NULL);
ASSERT(Region != NULL); ASSERT(Region != NULL);
@ -2536,7 +2536,7 @@ MmProtectSectionView(PMMSUPPORT AddressSpace,
} }
*OldProtect = Region->Protect; *OldProtect = Region->Protect;
Status = MmAlterRegion(AddressSpace, MemoryArea->StartingAddress, Status = MmAlterRegion(AddressSpace, (PVOID)MemoryArea->StartingAddress,
&MemoryArea->Data.SectionData.RegionListHead, &MemoryArea->Data.SectionData.RegionListHead,
BaseAddress, Length, Region->Type, Protect, BaseAddress, Length, Region->Type, Protect,
MmAlterViewAttributes); MmAlterViewAttributes);
@ -2572,7 +2572,7 @@ MmQuerySectionView(PMEMORY_AREA MemoryArea,
} }
else else
{ {
Info->AllocationBase = MemoryArea->StartingAddress; Info->AllocationBase = (PVOID)MemoryArea->StartingAddress;
Info->Type = MEM_MAPPED; Info->Type = MEM_MAPPED;
} }
Info->BaseAddress = RegionBaseAddress; Info->BaseAddress = RegionBaseAddress;