ReactOS系统中平衡二叉树。给定地址超导其所属区块MmFindRegion()

系列文章目录

PMM_REGION NTAPI MmFindRegion(

PVOID BaseAddress,

PLIST_ENTRY RegionListHead,

PVOID Address,

PVOID* RegionBaseAddress

);

宏函数

//给定地址找到其中所属区块

c 复制代码
#define CONTAINING_RECORD(address,type,field) ((type FAR *\
    (PCHAR)(address)-(PCHAR)(&((type *)0)->field)))获取外层数据结构的指针
    ```
@[TOC](文章目录)

---

# MmFindRegion()
```c
//给定地址超导其所属区块
PMM_REGION NTAPI 
MmFindRegion(PVOID BaseAddress, PLIST_ENTRY RegionListHead,
    PVOID Address, PVOID * RegionBaseAddress)
{
    PLIST_ENTRY current_entry;
    PMM_REGION current;
    PVOID StartAddress = BaseAddress;//搜索的起点
    current_entry = RegionListHead->Flink;//获得第一个MM REGION区块指针
    while (current_entry != RegionListHead)//遍历一个MEMORY AREA即某个区间的区块双向链表
    {
        //curren获得该指向该结构的首地址
        current = CONTAINING_RECORD(current entry, MM REGION, RegionListEntry);
        //若目标地址在(StartAddress ~startAddress+current->Length)说明找到了该地址所在区块
        if (StartAddress <= Address &&
            ((char*)StartAddresS + current->Length) > (char*)Address) {//找到了
            if (RegionBaseAddress != NULL)
                *RegionBaseAddress = StartAddress;//将区块开始地址给RegionBaseAddress返回return(current);//返回该区块的结构信息
            currententry = current_entry->Flink://下一个区块StartAddress =(PVOID)((ULONG PTR)StartAddress + current->Length);
            return(NULL);
        }
        current_entry = current_entry->Flink;//下一个区块
        StartAddress = (PVOID)((ULONG_PTR)StartAddress + current->Length);
    }
    return (NULL);
}
c
相关推荐
unable code1 天前
磁盘取证-Flying_High
网络安全·ctf·misc·1024程序员节·磁盘取证
unable code2 天前
磁盘取证-ColorfulDisk
网络安全·ctf·misc·1024程序员节·内存取证
unable code3 天前
磁盘取证-[第十章][10.1.2 磁盘取证方法]磁盘取证1
网络安全·ctf·misc·1024程序员节·内存取证
开开心心就好4 天前
免费抽奖工具支持批量导入+自定义主题
linux·运维·服务器·macos·pdf·phpstorm·1024程序员节
开开心心就好8 天前
卸载工具清理残留,检测垃圾颜色标识状态
linux·运维·服务器·python·安全·tornado·1024程序员节
子燕若水9 天前
Facebook reels 运营指南
1024程序员节
尘觉12 天前
创作 1024 天|把热爱写成长期主义
数据库·1024程序员节
写点什么呢13 天前
Word使用记录
word·1024程序员节
开开心心就好13 天前
内存清理工具点击清理,自动间隔自启
linux·运维·服务器·安全·硬件架构·材料工程·1024程序员节
开开心心就好14 天前
内存清理工具开源免费,自动优化清理项
linux·运维·服务器·python·django·pdf·1024程序员节