ReactOS系统中平衡二叉树,在一个空间中寻找与给定地址范围重合或部分重合的(已分配)区间

在一个空间中寻找与给定地址范围重合或部分重合的(已分配)区间

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
相关推荐
夜月yeyue1 小时前
Linux内高端内存
linux·运维·单片机·嵌入式硬件·ci/cd·硬件架构
smj2302_796826521 小时前
解决leetcode第3768题.固定长度子数组中的最小逆序对数目
python·算法·leetcode
cynicme1 小时前
力扣3531——统计被覆盖的建筑
算法·leetcode
猫豆~1 小时前
nginx实战-PHP——day2
linux·centos·云计算
杨云龙UP1 小时前
MySQL 自动备份与覆盖恢复实战:一套脚本搞定全库/按库备份恢复
linux·运维·数据库·sql·mysql
三小尛2 小时前
Linux的常见指令
linux
core5122 小时前
深度解析DeepSeek-R1中GRPO强化学习算法
人工智能·算法·机器学习·deepseek·grpo
mit6.8242 小时前
计数if|
算法
starvapour2 小时前
Ubuntu下sudo的免密操作
linux·ubuntu
sjg200104142 小时前
Deepin 20.9 误装gcc-8-base_8.4.0-1ubuntu1~16.04.1_amd64 后卸载
linux·运维·服务器