9.3. Buffer sharing between multiple processes

This section describes how to share a contiguous DMA buffer or a kernel buffer between multiple processes.
The buffer sharing mechanism can be used to improve the work of multiple processes by allowing the developer avoiding unnecessary buffer copying.
Coupled with the WinDriver IPC mechanism it might also be used as a way for two processes to convey large messages/data.

Currently WinDriver supports sharing DMA contiguous buffer (See WDC_DMAContigBufLock() [B.3.33]) and Kernel buffer (See WDS_SharedBufferAlloc() [B.6.1]).

In order to share a buffer the developer must first pass its global handle to the other process(es). See Macros WDS_SharedBufferGetGlobalHandle() [B.6.4] and WDC_DMAGetGlobalHandle() [B.3.38] for getting a buffer's global handle.
Than, the handle should be passed to the other process(es). E.g. by WinDriver IPC calls: WDS_IpcUidUnicast() [C.2.8], WDS_IpcSubGroupMulticast() [C.2.7] or WDS_IpcMulticast() [C.2.6].

After a process gets the global buffer handle, it should use WDC_DMABufGet() [B.3.37] or WDS_SharedBufferGet() [B.6.3] to retrieve the buffer. WinDriver will re-map the buffer to the new process virtual memory (I.e. user-space) and will fill all the necessary information as though the buffer was allocated from the calling process.

Once the process no longer needs the shared buffer it should use the regular unlock/free calls - WDC_DMABufUnlock() [B.3.36], WDS_SharedBufferFree() [B.6.2] appropriately.

WinDriver manages all system resources, hence the call to WDC_DMABufUnlock() [B.3.36], WDS_SharedBufferFree() [B.6.2] will not remove system resources until all processes no longer use the buffer.