2.13.WD_KernelBufLock()

Purpose

Allocates a contiguous or non-contiguous non-paged kernel buffer, and maps it to user address space. This buffer should be used ONLY for shared buffer purposes (The buffer should NOT be used for DMA).

Prototype
DWORD WD_KernelBufLock(
    HANDLE hWD,
    WD_KERNEL_BUFFER *pKerBuf);
Parameters
NameTypeInput/Output
hWDHANDLEInput
pKerBufWD_KERNEL_BUFFER*
hKerBufDWORDOutput
dwOptionsDWORDInput
qwBytesUINT64Input
pKernelAddrKPTROutput
pUserAddrUPTROutput
Description
NameDescription
hWDHandle to WinDriver's kernel-mode driver as received from WD_Open()[5.2]
pKerBufPointer to a KERNEL_BUFFER information structure:
hKerBuf Kernel buffer handle which should be passed to WD_KernelBufUnlock()[2.14] when freeing the kernel buffer, or 0 if the kernel buffer lock failed
dwOptions Kernel buffer options bit-mask, which can consist of a combination of any of the following flags:
ALLOCATE_CONTIG_BUFFER:Allocates a physically contiguous buffer
ALLOCATE_CACHED_BUFFER:Allocates a cached buffer
qwBytes The size of the kernel buffer, in bytes.
pKernelAddrPointer to the physical address of the beginning of the buffer
pUserAddrPointer to the virtual address of the beginning of the buffer
Return Value

Returns WD_STATUS_SUCCESS (0) on success, or an appropriate error code otherwise[A].

Remarks
Example

The following code demonstrates allocation of contiguous cached buffer:

WD_KERNEL_BUFFER buf;
DWORD dwStatus;

BZERO(buf);
buf.qwBytes = 200000;
buf.dwOptions = ALLOCATE_CONTIG_BUFFER | ALLOCATE_CACHED_BUFFER;
dwStatus = WD_KernelBufLock(hWD, &buf);
if (dwStatus)
{
    printf("Could not lock down buffer\n");
}
else
{
    / * To access the memory from your user mode
        application, use buf.pUserAddr. */
}