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
相关推荐
骑着蜗牛撵大象3271 小时前
Linux 进程间通信之管道:从 pipe() 的内核语义到 FIFO 落地排错
android·java·linux·系统编程·fifo·管道·进程间通信
爱读书的小胖1 小时前
LeetCode 122:买卖股票的最佳时机 II(C)解题分析
算法
结局无敌1 小时前
React Native for OpenHarmony 实战:三方库 react-native-modal-dialog 的鸿蒙化适配指南
深度学习·算法·react native·react.js·harmonyos
..Dauntless..1 小时前
【Linux】一切皆文件和缓冲区
linux·运维·服务器
QMCY_jason1 小时前
x86 ubuntu2204 无gui 安装 openeuler 2203 aarch64版本
linux·运维·服务器
重生之小比特1 小时前
【Linux系统】12 进程程序替换 自定义Shell 命令行解释器
linux·运维·服务器
OPEN-F2 小时前
ROS2系列教程:上位机建图与导航(原理综合)
算法·机器人
weixin_307779132 小时前
C++代码实现MATLAB中的fitrtree函数功能
开发语言·c++·算法·matlab
Uncertainty!!2 小时前
Windows 10 与 Ubuntu 22.04 通过 Samba 共享文件夹
windows·ubuntu·共享文件夹
tomwang03222 小时前
路径优化建模、优化算法分类及工程化小结
算法·数学建模·分类