Bewerken

Delen via


NdisAllocateNetBufferAndNetBufferList function (ndis/nblapi.h)

Call the NdisAllocateNetBufferAndNetBufferList function to allocate and initialize a NET_BUFFER_LIST structure that is initialized with a preallocated NET_BUFFER structure.

Syntax

NDIS_EXPORTED_ROUTINE NET_BUFFER_LIST * NdisAllocateNetBufferAndNetBufferList(
  [in]           NDIS_HANDLE          PoolHandle,
  [in]           USHORT               ContextSize,
  [in]           USHORT               ContextBackFill,
  [in, optional] __drv_aliasesMem MDL *MdlChain,
  [in]           ULONG                DataOffset,
  [in]           SIZE_T               DataLength
);

Parameters

[in] PoolHandle

A NET_BUFFER_LIST structure pool handle that was previously returned from the NdisAllocateNetBufferListPool function. The fAllocateNetBuffer member of the NET_BUFFER_LIST_POOL_PARAMETERS structure that the caller passed to NdisAllocateNetBufferListPool must have been set to TRUE and the DataSize member set to zero.

[in] ContextSize

The amount of used data space in the NET_BUFFER_LIST_CONTEXT structure to reserve for the caller. The ContextSize must be a multiple of the value defined by MEMORY_ALLOCATION_ALIGNMENT.

[in] ContextBackFill

The amount of unused data space (backfill space) that the caller requires. NDIS adds this value to the ContextSize and allocates additional space. The ContextBackFill must be a multiple of the value defined by MEMORY_ALLOCATION_ALIGNMENT.

[in, optional] MdlChain

A pointer to an MDL chain that NDIS uses to initialize the preallocated NET_BUFFER structure. MdlChain can be NULL.

[in] DataOffset

The initial offset, in bytes, from the start of the buffer to the start of the used data space in the MDL chain. Data space ahead of this offset is unused data space. Therefore, this value also represents the initial amount of available backfill space in the MDL chain. If MdlChain is NULL, DataOffset must be 0.

[in] DataLength

The length, in bytes, of the used data space in the MDL chain. If MdlChain is NULL, DataLength must be 0.

Return value

NdisAllocateNetBufferAndNetBufferList returns a pointer to the allocated NET_BUFFER_LIST structure. The NET_BUFFER_LIST structure includes a NET_BUFFER structure. If the allocation was unsuccessful, this pointer is NULL.

Remarks

The structures that the NdisAllocateNetBufferAndNetBufferList function allocates must come from a pool that includes NET_BUFFER_LIST structures that are paired with preallocated NET_BUFFER structures. To create such a pool, you must call the NdisAllocateNetBufferListPool function with the fAllocateNetBuffer member of the NET_BUFFER_LIST_POOL_PARAMETERS structure set to TRUE, and the DataSize member set to zero.

Note  NET_BUFFER and NET_BUFFER_LIST structures must be allocated from an NDIS buffer pool. A driver must not allocate and initialize a NET_BUFFER_LIST or NET_BUFFER structure from its private memory pool or the stack.
 
Call the NdisFreeNetBufferList function to free a NET_BUFFER_LIST structure.

The preallocated NET_BUFFER can be reused by reinitializing it with another MDL chain when it owns NET_BUFFER, but the DataOffset, DataLength, CurrentMdl, and CurrentMdlOffset fields in the NET_BUFFER must be consistent with the new MDL chain.

For example, if the original MDL chain contains X DataLength and Y DataOffset, and CurrentMdl starts with the second MDL (M) in the original MDL chain, CurrentMdlOffset is Z. The MdlChain field in NET_BUFFER_DATA then needs to point to a new MDL chain that contains X' DataLength and Y' DataOffset. If CurrentMdl starts with the third MDL (M') in the new MDL chain, CurrentMdlOffset is Z', and the following macros need to be used to set fields in NET_BUFFER:

NET_BUFFER_FIRST_MDL(_NB) = New MDL chain;
NET_BUFFER_DATA_LENGTH(_NB) = X';
NET_BUFFER_DATA_OFFSET(_NB) = Y';
NET_BUFFER_CURRENT_MDL(_NB) = M';
NET_BUFFER_CURRENT_MDL_OFFSET(_NB) = Z';

Requirements

Requirement Value
Minimum supported client Supported in NDIS 6.0 and later.
Target Platform Universal
Header ndis/nblapi.h (include ndis.h)
Library Ndis.lib
IRQL <= DISPATCH_LEVEL
DDI compliance rules Irql_NetBuffer_Function(ndis), NdisAllocateNetBufferList(ndis), NdisAllocateNetBufferList_InitFail(ndis)

See also

NET_BUFFER

NET_BUFFER_LIST

NET_BUFFER_LIST_CONTEXT

NET_BUFFER_LIST_POOL_PARAMETERS

NdisAllocateNetBufferListPool

NdisFreeNetBufferList