MDL的使用(一) IoAllocateMdl / MmInitializeMdl

来源:互联网 发布:spss modeler 18 mac 编辑:程序博客网 时间:2024/05/04 14:44

MDL (memory descriptor list)通常用于描述Va对应的物理内存的位置。通常Driver中可以访问的内容包括Next、MdlFlags。

WDK中定义了几个常用的宏来访问MDL中的一些变量,包括:


MmGetMdlVirtualAddress returns the virtual memory address of the buffer.// 虚拟内存地址

MmGetMdlByteCount returns the size, in bytes, of the buffer.// 虚拟内存长度

MmGetMdlByteOffset returns the offset within a physical page of the beginning of the buffer.// 物理内存中首地址相对于page起始地址的偏移量

MmGetMdlPfnArray returns a pointer to an array of physical page numbers. The size of this array can be computed from the buffer starting address and length by using ADDRESS_AND_SIZE_TO_SPAN_PAGES.// 物理内存page list


通常我们通过 IoAllocateMdl 来创建一个 MDL,通过 IoFreeMdl 来释放它。

另外,还可以通过ExAllocatePool创建的memory,利用MmInitializeMdl来将它格式化成一个MDL。此时的Memory必须是NonPageable的。当然释放还是需要透过ExFreePool来进行的。

原创粉丝点击