How do I share a memory buffer between Kernel PlugIn and user mode projects for DMA or other purposes?
Sharing a memory buffer between Kernel PlugIn and user mode is done using a common buffer, allocated in the kernel mode and mapped to the user mode. Call WD_DMALock() from the user mode to allocate a buffer in the kernel. To allocate a contiguous kernel buffer, set the DMA_KERNEL_BUFFER_ALLOC flag in the dwOptions field of the WD_DMA structure. WD_DMALock() returns a mapping of the physical address of the allocated buffer to both the kernel and user-mode address space. Note: Beginning with version 6.0.0 of WinDriver,
for Contiguous Buffer DMA allocation WD_DMALock() also returns the kernel mapping of the
allocated buffer — within dma.pKernelAddr. You can access the allocated memory from your user mode application using the returned user mode mapped address (dma.pUserAddr) as if it was the result of a malloc() call. To access the shared memory buffer from the Kernel PlugIn application, you need to pass the kernel mapping of the allocated buffer to the Kernel PlugIn. This address is returned by WD_DMALock() in dma.pKernelAddr. [Do not try to access the kernel mapped address directly in the user mode. Since this is a kernel mode address, you will generate a protection violation exception if you try to access it from the user mode. For direct user mode access, use the user mode mapping — dma.pUserAddr.]
Now you should pass the kernel virtual address to the Kernel PlugIn.
You can then pass this structure to the Kernel PlugIn in one of the following
ways:
After retrieving the kernel virtual buffer address in the Kernel PlugIn, store it in the Kernel PlugIn module (in a global variable or an allocated memory location). Now, you can access the same memory buffer in both kernel mode and user mode.
Note: The access to the common buffer is not synchronized by WinDriver.
You may add access synchronization.
For a detailed description of the relevant WinDriver APIs, used above, please
refer to the Function Reference section in the WinDriver User's
Manual. |
(WinDriver related)
Documents Navigator:
WinDriver: Support Center
WinDriver: Product Page
Can't find what you need?