在一个空间中寻找与给定地址范围重合或部分重合的(已分配)区间
PMEMORY_AREA NTAPI MmLocateMemoryAreaByRegion(
PMADDRESS_SPACE AddressSpace,
PVOID Address,
ULONG_PTR Length
);
MmLocateMemoryAreaByRegion
c
/***************************************************************************************/
//在一个空间中寻找与给定地址范围重合或部分重合的(已分配)区间
PMEMORY_AREA STDCALL MmLocateMemoryAreaByRegion(PMADDRESS_SPACE AddressSpace,
PVOID Address, ULONG_PTR Length)
{
PMEMORY_AREA Node;
PVOID Extent = (PVOIDK(ULONG_PTR)Address + Length);//地址范围的终点
MmVerifyMemoryAreas(AddressSpace);//检测该AVL树是否存在问题
/*Special ease for empty tree.*/
if (AddressSpace->MemoryAreaBoot == NULL)
return NULL;
/* Traverse the tree from left to right.*/
for (Node = MmIterateFirstNode(AddressSpace->MemoryAreaRoot);
Node!= NULL;Node = MmIterateNextNode(Node))
{
if (Node->StartingAddress >= Address && Node->StartingAddress < Extent)
return Node;//部分重合,区间的起点落在给定范围之内
if (Node->EndingAddress > Address && Node->EndingAddress < Extent)
return Node;//部分重合,区间的终点落在给定范围之内
if (Node->StartingAddress <= Address && Node->EndingAddress >= Extent)
return Node;//全部重合,给定范围落在区间之内
if(Node->StartingAddress >= Extent)
return NULL;
} //end for
return NULL;
}
c