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
相关推荐
吞下星星的少年·-·几秒前
牛客技能树:区间翻转
算法·滑动窗口
小白还菜42 分钟前
linux(Debian)使用mdadm组磁盘RAID1阵列
linux·运维
tkevinjd1 小时前
力扣148-排序链表
算法·leetcode·链表
qeen871 小时前
【C++】vector的模拟实现详解(二)
c++·学习·算法·迭代器·stl
不怕犯错,就怕不做1 小时前
GIT的简单打patch应用format-patch and git am
linux·git·全文检索
web守墓人2 小时前
【go语言】gotar:使用go语言复刻tar命令,并加入7z支持,可独立运行在windows、linux、macos上
linux·macos·golang
就牙白2 小时前
中科方德服务器打包RPM
linux·python
REDcker2 小时前
基于 eBPF 的网络可观测:协议栈路径与 sk_buff
linux·服务器·网络·php·ebpf·bpf
看-是灰机2 小时前
使用go语言实现对接
linux·开发语言·后端·docker·语言模型·golang·飞书
草莓熊Lotso2 小时前
【Linux网络】深入理解Linux IO多路复用:从本质到select服务器实战
linux·运维·服务器·c语言·网络·数据库·c++