mmProbeAndLockPages使用示例
时间: 2023-02-10 13:29:22 浏览: 52
这是一个用来锁定内存页的 Windows 函数。用法如下:
```
BOOL mmProbeAndLockPages(
PMDL MemoryDescriptorList,
KPROCESSOR_MODE AccessMode,
LOCK_OPERATION Operation
);
```
其中,`MemoryDescriptorList` 参数是一个内存描述符列表 (MDL) 结构指针,描述了要锁定的内存页。`AccessMode` 参数指定了访问模式,即调用者的身份。有效的值包括 `KernelMode` 和 `UserMode`。`Operation` 参数指定了要进行的操作,可以是 `IoReadAccess`、`IoWriteAccess` 或 `IoModifyAccess`。
示例代码如下:
```
#include <Windows.h>
#include <Winternl.h>
#define SystemMemoryListHead ((PLIST_ENTRY)((PBYTE)(MmSystemRangeStart) + \
0x40))
void LockPagesInList(PLIST_ENTRY ListHead)
{
PLIST_ENTRY Entry;
PMDL Mdl;
PVOID VirtualAddress;
SIZE_T Length;
Entry = ListHead->Flink;
while (Entry != ListHead)
{
Mdl = CONTAINING_RECORD(Entry, MDL, ListEntry);
VirtualAddress = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
Length = Mdl->ByteCount;
if (!VirtualAddress)
{
printf("Failed to get VA for MDL.\n");
return;
}
if (!mmProbeAndLockPages(Mdl, KernelMode, IoModifyAccess))
{
printf("Failed to lock pages.\n");
return;
}
Entry = Entry->Flink;
}
}
int main()
{
LockPagesInList(SystemMemoryListHead);
return 0;
}
```
这个程序会遍历系统内存列表,并尝试锁定列表中每个内存块的所有页面。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)