简体   繁体   English

在Windows 10驱动程序中将内核空间虚拟地址映射到用户空间虚拟地址

[英]Mapping Kernel-Space Virtual Address to User-Space Virtual Address in Windows 10 Driver

I'm writing a kernel mode driver in Windows 10 (64-bit), whose main purpose is to read from a DMA, and I was wondering if instead of copying blocks of memory from the kernel space to buffers allocated in the user space, I could somehow expose an address to the user space (of course not the physical address), and save on the memory copy operation. 我正在用Windows 10(64位)编写内核模式驱动程序,其主要目的是从DMA读取数据,我想知道是否将内存块从内核空间复制到用户空间中分配的缓冲区中,而不是将其复制,我可以以某种方式向用户空间公开一个地址(当然不是物理地址),然后保存在内存复制操作中。

Perhaps something like this: 也许是这样的:

  1. Allocating a block of continuous physical memory (and mapping the physical address to a virtual address in the kernel space). 分配一块连续的物理内存(并将物理地址映射到内核空间中的虚拟地址)。

  2. Mapping the virtual address in the kernel space to a virtual address in the user space. 将内核空间中的虚拟地址映射到用户空间中的虚拟地址。

By the way, since there's only one kernel space, and as many user spaces as there are processes running in the system (is that correct?), I would have to use some kind of a handle to the calling process, in order to get the virtual address in the appropriate process... 顺便说一句,由于只有一个内核空间,并且与系统中正在运行的进程一样多的用户空间(对吗?),我将不得不对调用进程使用某种类型的句柄,以便获得在适当的过程中的虚拟地址...

Thanks for your time! 谢谢你的时间!

For your (2), how about MmMapLockedPagesSpecifyCache() with AccessMode = UserMode. 对于您的(2),使用AccessMode = UserMode的MmMapLockedPagesSpecifyCache()怎么样。 Note the important caveat, "The routine returns a user address that is valid in the context of the process in which the driver is running," so you'll need to ensure the driver is running in your user-mode app's process when you perform the mapping, ie by doing the mapping in the driver code that directly handles a call from the user-mode code, eg DeviceIoControl(). 注意一个重要的警告,“例程返回一个在驱动程序正在运行的进程的上下文中有效的用户地址”,因此在执行时,您需要确保驱动程序正在用户模式应用程序的进程中运行映射,即通过在直接处理来自用户模式代码(例如DeviceIoControl())的调用的驱动程序代码中进行映射。 Also note, to use this function, you need to supply an MDL describing the physical pages, and those pages must be locked down. 还要注意,要使用此功能,您需要提供描述物理页面的MDL,并且这些页面必须被锁定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM