Shared Memory Resource Allocation

To allocate shared memory resources for a VM queue, a miniport driver calls the NdisAllocateSharedMemory function. For example, the miniport driver allocates shared memory when it receives the OID_RECEIVE_FILTER_QUEUE_ALLOCATION_COMPLETE OID. Also, a miniport driver can allocate shared memory for the default queue during network adapter initialization. For more information about allocating queues, see Allocating a VM Queue.

The miniport driver can allocate more memory for the queue until the queue is freed. For more information about freeing a queue, see Freeing a VM Queue.

The NDIS_SHARED_MEMORY_PARAMETERS structure specifies the shared memory parameters for a shared memory allocation request. Miniport drivers pass this structure to the NdisAllocateSharedMemory function. NDIS passes this structure to the NetAllocateSharedMemory function (that is, the ALLOCATE_SHARED_MEMORY_HANDLER entry point).

When a miniport driver allocates shared memory, it specifies the following:

  • Queue identifier.

  • Shared memory length.

  • How the shared memory is used. For example, the miniport driver specifies NdisSharedMemoryUsageReceive if the shared memory is to be used for receive buffers.

If the NDIS_SHARED_MEM_PARAMETERS_CONTIGOUS flag is not set in the Flags member, shared memory can be specified in a scatter-gather list that is contained in non-contiguous memory.

The NDIS_SHARED_MEMORY_USAGE enumeration specifies how shared memory is used. The NDIS_SHARED_MEMORY_USAGE enumeration is used in the NDIS_SHARED_MEMORY_PARAMETERS and NDIS_SCATTER_GATHER_LIST_PARAMETERS structures. For information about shared memory parameters in VMQ receive data buffers, see Shared Memory in Receive Buffers.

The NdisAllocateSharedMemory function provides the following to the caller:

  • Virtual address of the allocated memory.

  • Scatter-gather list.

  • Shared memory handle - for receive indications.

  • Allocation handle - used to identify the memory later.

Miniport drivers call the NdisFreeSharedMemory function to free shared memory for a queue. If the miniport driver allocated the shared memory for a nondefault queue, it frees the shared memory in the context of the OID_RECEIVE_FILTER_FREE_QUEUE OID while it is freeing the queue. Miniport drivers free shared memory that they allocated for the default queue in the context of the MiniportHaltEx function.