内核API笔记之IoBuildPartialMdl

来源:互联网 发布:心怀大局 知责有为 编辑:程序博客网 时间:2024/05/17 01:22

IoBuildPartialMdl

VOID
IoBuildPartialMdl(
    __in PMDL SourceMdl,
    __inout PMDL TargetMdl,
    __in PVOID VirtualAddress,
    __in ULONG Length
    );

驱动程序可以使用IoBuildPartialMdl来把一个IRP请求分解成多个IRP请求. The physical pages that the source MDL describes must be locked before the driver calls IoBuildPartialMdl. Typically, the source MDL describes a buffer in user address space, and the driver calls the MmProbeAndLockPages routine to lock the pages in this buffer. However, the driver can build the source MDL from nonpaged memory by calling the MmBuildMdlForNonPagedPool, MmAllocatePagesForMdlEx, or MmAllocatePagesForMdl routine.

意思就是说,如果分配的内存是不可置换的,则没什么事情,需要注意的是,如果源MDL是用户空间的,那么必须使用MmProbeAndLockPages 函数来锁定内存。

驱动程序可以使用MmGetSystemAddressForMdlSafe 宏来映射一部分用户空间MDL到系统空间中。如果这一部分用户空间的源MDL已经映射到系统空间,那么MmGetSystemAddressForMdlSafe宏使用已存在的源映射。否则, MmGetSystemAddressForMdlSafe宏就会创建一个新的映射, 为了防止新映射的内存存在泄漏,驱动在重新使用那一部分的MDL之前必须调用MmPrepareMdlForReuse。另外, IoFreeMdl函数会释放系统地址空间的映射, 当然了,前提是这个映射必须要存在啊,

原创粉丝点击