This documents explains how to share memory between the Kernel PlugIn and the user mode using a common buffer, allocated in the kernel mode and mapped to the user mode.
NOTE
The document currently refers to the low-level WinDriver APIs. When using the latest versions you should use the high-level WDC API instead.
Call
Note: Beginning with version 6.0.0 of WinDriver, for Contiguous Buffer
DMA allocation
You can access the allocated memory from your user mode application
using the returned user mode mapped address
(
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
(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 —
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.
*********************************************************************
/* Sample user mode code: */
HANDLE hWD;
WD_DMA dma;
WD_KERNEL_PLUGIN kerPlug;
WD_KERNEL_PLUGIN_CALL kpCall;
WD_CARD_REGISTER cardReg; /* For version 5.2.2 or below */
hWD = WD_Open();
BZERO(dma);
dma.pUserAddr = NULL;
dma.dwBytes = 0x10000; /* allocate 16K */
dma.dwOptions = DMA_KERNEL_BUFFER_ALLOC; /* kernel contiguous buffer */
WD_DMALock(hWD, &dma);
if (!dma.hDma)
{
printf("failed allocating dma buffer\n");
/* exit*/
}
/* At this point, dma.pUserAddr holds the
user mode mapping of the allocated memory,
dma.pKernelAddr holds the kernel mapping of
the memory. */
////////////////////////////////////////////////////////////////
/* Pass the kernel address to the Kernel PlugIn: */
BZERO (kerPlug);
kerPlug.pcDriverName = KP_DRIVER_NAME;
WD_KernelPlugInOpen(hWD, &kerPlug);
if (!kerPlug.hKernelPlugIn)
{
printf("failed opening a handle to the Kernel PlugIn\n");
/* exit */
}
BZERO (kpCall);
kpCall.hKernelPlugIn = kerPlug.hKernelPlugIn;
kpCall.dwMessage = YOUR_MESSAGE;
kpCall.pData = dma.pKernelAddr;
WD_KernelPlugInCall(hWD, &kpCall);
*********************************************************************
For a detailed description of the relevant WinDriver APIs, used above, please
refer to the Function Reference section in the
WinDriver User's Manual.
|