Jungo WinDriver  
Official Documentation

◆ WDS_SharedBufferAlloc()

DWORD DLLCALLCONV WDS_SharedBufferAlloc ( _In_ UINT64  qwBytes,
_In_ DWORD  dwOptions,
_Outptr_ WD_KERNEL_BUFFER **  ppKerBuf 
)

Allocates a memory buffer that can be shared between the user mode and the kernel mode ("shared buffer"), and returns user-mode and kernel-mode virtual address space mappings of the allocated buffer.

Parameters
[in]qwBytesThe size of the buffer to allocate, in bytes
[in]dwOptionsKernel buffer options bit-mask, which can consist of a combination of the enumeration values listed below.
  • KER_BUF_ALLOC_NON_CONTIG: Allocates a non contiguous buffer
  • KER_BUF_ALLOC_CONTIG: Allocates a physically contiguous buffer
  • KER_BUF_ALLOC_CACHED: Allocates a cached buffer. This option can be set with KER_BUF_ALLOC_NON_CONTIG or KER_BUF_ALLOC_CONTIG buffer
[out]ppKerBufPointer to a WD_KERNEL_BUFFER pointer, to be filled by the function. The caller should use *ppBuf->pUserAddr usermode mapped address. When the buffer is no longer needed, (*ppBuf) should be passed to WDS_SharedBufferFree()
Returns
Returns WD_STATUS_SUCCESS (0) on success, or an appropriate error code otherwise
Remarks
This function is currently only supported from the user mode. This function is supported only for Windows and Linux.
// Static global pointer is used only for simplicity
static WD_KERNEL_BUFFER *pSharedKerBuf = NULL;
static void IpcKerBufAllocAndShare(void)
{
DWORD size = 0x100;
DWORD dwStatus;
DWORD dwOptions = KER_BUF_ALLOC_CONTIG; // Or any other WD_KER_BUF_OPTION
/* If kernel buffer was allocated in the past, release it */
dwStatus = WDS_SharedBufferFree(pSharedKerBuf);
if (WD_STATUS_SUCCESS != dwStatus)
{
printf("Failed freeing shared buffer. Error [0x%lx - %s]\n",
dwStatus, Stat2Str(dwStatus));
}
dwStatus = WDS_SharedBufferAlloc(size, dwOptions, &pSharedKerBuf);
if (WD_STATUS_SUCCESS != dwStatus)
{
printf("Failed allocating shared kernel buffer. size [%lu], "
"Error [0x%lx - %s]\n", size, dwStatus, Stat2Str(dwStatus));
return;
}
printf("Successful kernel buffer allocation. UserAddr [0x%"UPRI"x], "
"KernelAddr [0x%"KPRI"x], size [%lu]\n", pSharedKerBuf->pUserAddr,
pSharedKerBuf->pKernelAddr, size);
}
#define NULL
Definition: kpstdlib.h:268
const char *DLLCALLCONV Stat2Str(_In_ DWORD dwStatus)
Retrieves the status string that corresponds to a status code.
KPTR pKernelAddr
Kernel address.
Definition: windrvr.h:582
UPTR pUserAddr
User address.
Definition: windrvr.h:583
DWORD DLLCALLCONV WDS_SharedBufferAlloc(_In_ UINT64 qwBytes, _In_ DWORD dwOptions, _Outptr_ WD_KERNEL_BUFFER **ppKerBuf)
Allocates a memory buffer that can be shared between the user mode and the kernel mode ("shared buffe...
DWORD DLLCALLCONV WDS_SharedBufferFree(_In_ WD_KERNEL_BUFFER *pKerBuf)
Frees a shared buffer that was allocated by a previous call to WDS_SharedBufferAlloc().
#define KPRI
formatting for printing a kernel pointer
Definition: windrvr.h:361
@ KER_BUF_ALLOC_CONTIG
Definition: windrvr.h:572
@ WD_STATUS_SUCCESS
[0] Operation completed successfully
Definition: windrvr.h:1066
#define UPRI
Definition: windrvr.h:362