WdfMemoryAssignBuffer method

[Applies to KMDF and UMDF]

The WdfMemoryAssignBuffer method assigns a specified buffer to a memory object that a driver created by calling WdfMemoryCreatePreallocated.

Syntax


NTSTATUS WdfMemoryAssignBuffer(
  [in]  WDFMEMORY Memory,
  [in]  PVOID Buffer,
  [in]  size_t BufferSize
);

Parameters

Memory [in]

A handle to a framework memory object that was obtained by calling WdfMemoryCreatePreallocated.

Buffer [in]

A pointer to a driver-supplied buffer.

BufferSize [in]

The nonzero size, in bytes, of the buffer that Buffer points to.

Return value

WdfMemoryAssignBuffer returns STATUS_SUCCESS if the operation succeeds. Otherwise, this method might return one of the following values:

Return codeDescription
STATUS_INVALID_PARAMETER

An invalid parameter was detected.

 

This method also might return other NTSTATUS values.

A bug check occurs if the driver supplies an invalid object handle.

Remarks

The method can assign a buffer to a memory object that WdfMemoryCreatePreallocated created, but not to a memory object that WdfMemoryCreate created.

The buffer that the Buffer parameter points to can be allocated from the pageable or non-pageable memory pool. If the driver allocates the buffer from the pageable pool, or if the buffer is from pageable pool because it came from a user-mode application, the driver must access the buffer only at IRQL < DISPATCH_LEVEL. (Note that the driver's EvtCleanupCallback and EvtDestroyCallback callback functions, if provided, can be called at IRQL <= DISPATCH_LEVEL.)

For more information about framework memory objects, see Using Memory Buffers.

Examples

The following code example allocates a buffer and then assigns the buffer to a framework memory object.


PVOID  pNewBuffer = NULL;

pNewBuffer = ExAllocatePoolWithTag(
                                   NonPagedPool,
                                   NEW_BUFFER_SIZE,
                                   MY_DRIVER_TAG
                                   );
if (pNewBuffer == NULL){
    goto Error;
}

status = WdfMemoryAssignBuffer(
                               memHandle,
                               pNewBuffer,
                               NEW_BUFFER_SIZE
                               );

Requirements

Minimum KMDF version

1.0

Minimum UMDF version

2.0

Header

Wdfmemory.h (include Wdf.h)

Library

Wdf01000.sys (KMDF);
WUDFx02000.dll (UMDF)

IRQL

Any level

DDI compliance rules

BufAfterReqCompletedIntIoctlA, BufAfterReqCompletedIoctlA, BufAfterReqCompletedReadA, BufAfterReqCompletedWriteA, DriverCreate, MemAfterReqCompletedIntIoctlA, MemAfterReqCompletedIoctlA, MemAfterReqCompletedReadA, MemAfterReqCompletedWriteA

See also

ExAllocatePoolWithTag
WdfMemoryCreatePreallocated

 

 

Send comments about this topic to Microsoft

Mostrar:
© 2014 Microsoft