在Windows 10驱动程序中将内核空间虚拟地址映射到用户空间虚拟地址 [英] Mapping Kernel-Space Virtual Address to User-Space Virtual Address in Windows 10 Driver
问题描述
我正在Windows 10(64位)中编写内核模式驱动程序,其主要目的是从DMA读取数据,我想知道是否将内存块从内核空间复制到内存中分配的缓冲区中,而不是复制用户空间,我可以以某种方式向用户空间公开一个地址(当然不是物理地址),并保存在内存复制操作中.
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.
也许是这样的:
-
分配一块连续的物理内存(并将物理地址映射到内核空间中的虚拟地址).
Allocating a block of continuous physical memory (and mapping the physical address to a virtual address in the kernel space).
将内核空间中的虚拟地址映射到用户空间中的虚拟地址.
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...
感谢您的时间!
推荐答案
For your (2), how about MmMapLockedPagesSpecifyCache() with AccessMode = UserMode. 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, i.e. by doing the mapping in the driver code that directly handles a call from the user-mode code, e.g. DeviceIoControl(). Also note, to use this function, you need to supply an MDL describing the physical pages, and those pages must be locked down.
这篇关于在Windows 10驱动程序中将内核空间虚拟地址映射到用户空间虚拟地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!