static PMM_REGION
MmSplitRegion(PMM_REGION InitialRegion, PVOID InitialBaseAddress,
- PVOID StartAddress, ULONG Length, ULONG NewType,
+ PVOID StartAddress, SIZE_T Length, ULONG NewType,
ULONG NewProtect, PMMSUPPORT AddressSpace,
PMM_ALTER_REGION_FUNC AlterFunc)
{
PMM_REGION NewRegion1;
PMM_REGION NewRegion2;
- ULONG InternalLength;
+ SIZE_T InternalLength;
/* Allocate this in front otherwise the failure case is too difficult. */
NewRegion2 = ExAllocatePoolWithTag(NonPagedPool, sizeof(MM_REGION),
TAG_MM_REGION);
if (NewRegion1 == NULL)
{
- ExFreePool(NewRegion2);
+ ExFreePoolWithTag(NewRegion2, TAG_MM_REGION);
return(NULL);
}
NewRegion1->Type = NewType;
}
else
{
- ExFreePool(NewRegion2);
+ ExFreePoolWithTag(NewRegion2, TAG_MM_REGION);
}
/* Either remove or shrink the initial region. */
if (InitialBaseAddress == StartAddress)
{
RemoveEntryList(&InitialRegion->RegionListEntry);
- ExFreePool(InitialRegion);
+ ExFreePoolWithTag(InitialRegion, TAG_MM_REGION);
}
else
{
NTSTATUS
NTAPI
MmAlterRegion(PMMSUPPORT AddressSpace, PVOID BaseAddress,
- PLIST_ENTRY RegionListHead, PVOID StartAddress, ULONG Length,
+ PLIST_ENTRY RegionListHead, PVOID StartAddress, SIZE_T Length,
ULONG NewType, ULONG NewProtect, PMM_ALTER_REGION_FUNC AlterFunc)
{
PMM_REGION InitialRegion;
PLIST_ENTRY CurrentEntry;
PMM_REGION CurrentRegion = NULL;
PVOID CurrentBaseAddress;
- ULONG RemainingLength;
+ SIZE_T RemainingLength;
/*
* Find the first region containing part of the range of addresses to
*/
InitialRegion = MmFindRegion(BaseAddress, RegionListHead, StartAddress,
&InitialBaseAddress);
- if (((char*)StartAddress + Length) >
- ((char*)InitialBaseAddress + InitialRegion->Length))
- {
- RemainingLength = ((char*)StartAddress + Length) -
- ((char*)InitialBaseAddress + InitialRegion->Length);
- }
- else
- {
- RemainingLength = 0;
- }
-
/*
* If necessary then split the region into the affected and unaffected parts.
*/
{
return(STATUS_NO_MEMORY);
}
+ if(NewRegion->Length < Length)
+ RemainingLength = Length - NewRegion->Length;
+ else
+ RemainingLength = 0;
}
else
{
NewRegion = InitialRegion;
+ if(((ULONG_PTR)InitialBaseAddress + NewRegion->Length) <
+ ((ULONG_PTR)StartAddress + Length))
+ RemainingLength = ((ULONG_PTR)StartAddress + Length) - ((ULONG_PTR)InitialBaseAddress + NewRegion->Length);
+ else
+ RemainingLength = 0;
}
/*
while (RemainingLength > 0 && CurrentRegion->Length <= RemainingLength &&
CurrentEntry != RegionListHead)
{
- if (CurrentRegion->Type != NewType &&
+ if (CurrentRegion->Type != NewType ||
CurrentRegion->Protect != NewProtect)
{
AlterFunc(AddressSpace, CurrentBaseAddress, CurrentRegion->Length,
RemainingLength -= CurrentRegion->Length;
CurrentEntry = CurrentEntry->Flink;
RemoveEntryList(&CurrentRegion->RegionListEntry);
- ExFreePool(CurrentRegion);
+ ExFreePoolWithTag(CurrentRegion, TAG_MM_REGION);
CurrentRegion = CONTAINING_RECORD(CurrentEntry, MM_REGION,
RegionListEntry);
}
{
CurrentRegion = CONTAINING_RECORD(CurrentEntry, MM_REGION,
RegionListEntry);
- if (CurrentRegion->Type != NewType &&
+ if (CurrentRegion->Type != NewType ||
CurrentRegion->Protect != NewProtect)
{
- AlterFunc(AddressSpace, CurrentBaseAddress, CurrentRegion->Length,
+ AlterFunc(AddressSpace, CurrentBaseAddress, RemainingLength,
CurrentRegion->Type, CurrentRegion->Protect,
NewType, NewProtect);
}
{
NewRegion->Length += CurrentRegion->Length;
RemoveEntryList(&CurrentRegion->RegionListEntry);
- ExFreePool(CurrentRegion);
+ ExFreePoolWithTag(CurrentRegion, TAG_MM_REGION);
}
}
{
NewRegion->Length += CurrentRegion->Length;
RemoveEntryList(&CurrentRegion->RegionListEntry);
- ExFreePool(CurrentRegion);
+ ExFreePoolWithTag(CurrentRegion, TAG_MM_REGION);
}
}