阅读:2962回复:3
我实在受不了了!,一调用 NdisMIndicateReceivePacket 就死机
编写中间层驱动时,PtReceivePacket 中每次调用 NdisMIndicateReceivePacket 就死机
我怎么也看不出来错在哪里,请大侠救命!!! 下面是代码说明: 以passthru 为样本,OS为win2k 专业版 PtReceivePacket( IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_PACKET pPacket ) { PADAPT pAdapt =(PADAPT)ProtocolBindingContext; NDIS_STATUS Status; PNDIS_PACKET pMyPacket; PNDIS_BUFFER pMyNdisBuffer; PRSVD Resvd; PVOID pVirtualAddress; // 在中间层驱动passthru的例子中,我对PtReceivePacket进行了一些简单的处理: // 分配新的内存 Status = NdisAllocateMemoryWithTag( &pVirtualAddress, TotalPacketLength,// 假设内存大小已经确定下来 TAG ); if(Status != NDIS_STATUS_SUCCESS){ // 如果分配内存失败,直接返回 DBGPRINT("NdisAllocateMemoryWithTag Failed!!!"); return 0; } // 将原来包的数据复制到刚分配的内存中 NdisMoveMemory(pVirtualAddress,原来包数据对应的内存地址,TotalPacketLength); // 分配包缓冲区 NdisAllocateBuffer( &Status, &pMyNdisBuffer, pAdapt->BufferPoolHandle, pVirtualAddress, TotalPacketLength); if (NDIS_STATUS_SUCCESS != Status){ // 如果分配包缓冲区失败,释放已申请的内存 NdisFreeMemory( pVirtualAddress, TotalPacketLength, TAG); DBGPRINT("NdisAllocateBuffer Failed!!!"); return 0; } NdisDprAllocatePacket(&Status, &pMyPacket, pAdapt->RecvPacketPoolHandle); if(Status != NDIS_STATUS_SUCCESS){ // 如果分配包失败,释放已申请的资源返回 NdisFreeMemory( pVirtualAddress, TotalPacketLength, TAG); NdisFreeBuffer (pMyNdisBuffer); DBGPRINT("NdisDprAllocatePacket Failed!!!"); return 0; } // 将Buffer链接入Packet NdisChainBufferAtFront (pMyPacket, pMyNdisBuffer); // ------------------------------------------------------------ // 设置 NdisPacket.Private.Flags 数据 NdisGetPacketFlags(pMyPacket) = NdisGetPacketFlags(pPacket); // 设置 OOB 数据 NdisMoveMemory ( NDIS_OOB_DATA_FROM_PACKET (pMyPacket), NDIS_OOB_DATA_FROM_PACKET (pPacket), sizeof (NDIS_PACKET_OOB_DATA)); NDIS_SET_PACKET_HEADER_SIZE(pMyPacket, NDIS_GET_PACKET_HEADER_SIZE(pPacket)); NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO(pMyPacket,0,0); NDIS_SET_PACKET_STATUS(pMyPacket, NDIS_STATUS_RESOURCES); // 设置 NDIS_PACKET_EXTENSION 信息 NDIS_SET_ORIGINAL_PACKET(pMyPacket, NDIS_GET_ORIGINAL_PACKET(pPacket)); // 接收数据前记录原始包 Resvd =(PRSVD)(pMyPacket->MiniportReserved); Resvd->OriginalPkt = pPacket; //每次执行到这一行就蓝屏 NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &pMyPacket, 1); Status = NDIS_GET_PACKET_STATUS(pMyPacket); if(Status != NDIS_STATUS_PENDING){ // 接收包成功,释放申请的资源 NdisFreeMemory( pVirtualAddress, TotalPacketLength, 0 ); NdisFreeBuffer(pMyNdisBuffer); NdisFreePacket(pMyPacket); // 向下层驱动返回包的所有权 NdisReturnPackets(&pPacket, 1); return 0; } else{ DBGPRINT("\nNdisMIndicateReceivePacket return NDIS_STATUS_PENDING"); return 1; } } |
|
沙发#
发布于:2004-03-02 09:25
在NdisAllocateMemoryWithTag之后,NdisMoveMemory之前加入如下代码:
NdisZeroMemory(pVirtualAddress,TotalPacketLength); 祝好运;) |
|
|
板凳#
发布于:2007-12-04 22:46
引用楼主gytlfj于2004-03-01 15:30发表的 我实在受不了了!,一调用 NdisMIndicateReceivePacket 就死机 : 你的这个问题解决了么?怎么解决的阿? 我也碰到了这个问题。 |
|
|
地板#
发布于:2007-12-05 15:49
谁能帮我解决问题呢,
|
|
|