ReactOS系统中MmLocateMemoryAreaByAddress函数的实现:搜索目标地址所在的节点
ReactOS系统中MmLocateMemoryAreaByAddress函数的实现:搜索目标地址所在的节点
文章目录
//搜索目标地址所在的节点MmLocateMemoryAreaByAddress
cpp
/* FUNCTIONS *****************************************************************/
PMEMORY_AREA NTAPI
MmLocateMemoryAreaByAddress(
PMMSUPPORT AddressSpace,
PVOID Address_)
{
ULONG_PTR StartVpn = (ULONG_PTR)Address_ / PAGE_SIZE;
PEPROCESS Process;
PMM_AVL_TABLE Table;
PMMADDRESS_NODE Node;
PMEMORY_AREA MemoryArea;
TABLE_SEARCH_RESULT Result;
PMMVAD_LONG Vad;
获取用户空间的AVL树
Process = MmGetAddressSpaceOwner(AddressSpace);
Table = (Process != NULL) ? &Process->VadRoot : &MiRosKernelVadRoot;
//检测该AVL树是否存在问题
Result = MiCheckForConflictingNode(StartVpn, StartVpn, Table, &Node);
if (Result != TableFoundNode)
{
return NULL;
}
// 根据二叉搜索树的性质进行和遍历,小到其左子树遍历,大则到其右子树遍历
Vad = (PMMVAD_LONG)Node;
if (Vad->u.VadFlags.Spare == 0)
{
/* Check if this is VM VAD */
if (Vad->ControlArea == NULL)
{
/* We store the reactos MEMORY_AREA here */
MemoryArea = (PMEMORY_AREA)Vad->FirstPrototypePte;
}
else
{
/* This is a section VAD. Store the MAREA here for now */
MemoryArea = (PMEMORY_AREA)Vad->u4.Banked;
}
}
else
{
MemoryArea = (PMEMORY_AREA)Node;
}
return MemoryArea;
}