// // Allocate UserSendNetBufferListPool // NdisZeroMemory(&PoolParameters, sizeof(NET_BUFFER_LIST_POOL_PARAMETERS)); PoolParameters.Header.Type = NDIS_OBJECT_TYPE_DEFAULT; PoolParameters.Header.Revision = NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1; PoolParameters.Header.Size = sizeof(PoolParameters); PoolParameters.ProtocolId = NDIS_PROTOCOL_ID_DEFAULT; PoolParameters.ContextSize = sizeof(SEND_NETBUFLIST_RSVD); PoolParameters.fAllocateNetBuffer = TRUE; PoolParameters.PoolTag = FILTER_ALLOC_TAG; pFilter->UserSendNetBufferListPool = NdisAllocateNetBufferListPool( pFilter->FilterHandle, &PoolParameters); if (pFilter->UserSendNetBufferListPool != NULL) { DEBUGP(DL_ERROR, ("Successfully to allocate send net buffer list pool.\n")); }else{ DEBUGP(DL_ERROR, ("Failed to allocate send net buffer list pool.\n")); Status = NDIS_STATUS_RESOURCES; break; }
我一直分配不成功,而且网上问了 BlueScreen when calling NdisAllocatedNetBufferListPool(), 甚至高手贴出代码了,我也不成功,结果发现ContextSize有问题:一查,The ContextSize must be a multiple of the value defined by MEMORY_ALLOCATION_ALIGNMENT. 所以结构:SEND_NETBUFLIST_RSVD
// //Define SEND_NETBUFLIST_RSVD // typedef struct _SEND_NETBUFLIST_RSVD { ULONG IsMyPacket; NDIS_HANDLE pFilter; }SEND_NETBUFLIST_RSVD,*PSEND_NETBUFLIST_RSVD;
所以sizeof(SEND_NETBUFLIST_RSVD)的值必须是MEMORY_ALLOCATION_ALIGNMENT的倍数。而MEMORY_ALLOCATION_ALIGNMENT的值似乎是8?