
Beginning with v9.2.1 of WinDriver, you can use the
Following is an explanation of how to share memory between the user mode and
the
NOTE
The following refers to low-level WinDriver APIs. When using a newer version of WinDriver, which supports the WDC API, use the relevant high-level WDC APIs instead. For versions 9.2.1 and above of WinDriver, simply use the WDC_SharedBufferAlloc() function, as indicated above.
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 WinDriver APIs used above, refer to the
Function Reference section in the |