阅读:4406回复:4
求助,ptReceive处理
在ptReceive函数中,我的网卡是走PacketSize<=LookAheadBufferSize的情况的,如下面的程序,但程序中,跑到NdisMIndicateReceivePacket(pAdapt->MiniportHandle,&MyPacket,1);这句就出现问题,只要这句存在,就会蓝屏。请问各位大哥,PacketSize<=LookAheadBufferSize的处理有出错么?我看了多个程序,都机会上是这样处理的,不知道是什么问题
NDIS_STATUS PtReceive( IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_HANDLE MacReceiveContext, IN PVOID HeaderBuffer, IN UINT HeaderBufferSize, IN PVOID LookAheadBuffer, IN UINT LookAheadBufferSize, IN UINT PacketSize ) /*++ Routine Description: LBFO - need to use primary for all receives Arguments: Return Value: --*/ { PADAPT OutAdapt; PADAPT pAdapt =(PADAPT)ProtocolBindingContext; PNDIS_PACKET MyPacket, Packet,MyPacket1; NDIS_STATUS Status = NDIS_STATUS_SUCCESS; PUCHAR pPacketContent,pBakContent; PNDIS_BUFFER pPacketBuffer,pBakBuffer; UINT PacketLen; PRSVD Rsvd = NULL; UINT BytesTransferred; UINT OffsetSize; if(!pAdapt->MiniportHandle) { Status = NDIS_STATUS_FAILURE; } else do { // // We should not be getting Receives on a Secondary, this is just specific to our LBFO driver // if(pAdapt->isSecondary) { DBGPRINT("PASSTHRU GETTING RECIEVES ON SECONDARY\n"); ASSERT(0); } // // If this was indicated by the miniport below as a packet, then get that packet pointer and indicate // it as a packet as well(with appropriate status). This way the OOB stuff is accessible to the // transport above us. // /*Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext); if(Packet != NULL) { // // Get a packet off the pool and indicate that up // NdisDprAllocatePacket(&Status, &MyPacket, pAdapt->RecvPacketPoolHandle); if(Status == NDIS_STATUS_SUCCESS) { MyPacket->Private.Head = Packet->Private.Head; MyPacket->Private.Tail = Packet->Private.Tail; // // Get the original packet(it could be the same packet as one received or a different one // based on # of layered MPs) and set it on the indicated packet so the OOB stuff is visible // correctly at the top. // NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize); // // Set Packet Flags // NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); // // Make sure the status is set to NDIS_STATUS_RESOURCES. // NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES); NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); ASSERT(NDIS_GET_PACKET_STATUS(MyPacket) == NDIS_STATUS_RESOURCES); NdisDprFreePacket(MyPacket); break; } } // // Fall through if the miniport below us has either not indicated a packet or we could not // allocate one // pAdapt->IndicateRcvComplete = TRUE; switch(pAdapt->Medium) { case NdisMedium802_3: NdisMEthIndicateReceive(pAdapt->MiniportHandle, MacReceiveContext, HeaderBuffer, HeaderBufferSize, LookAheadBuffer, LookAheadBufferSize, PacketSize); break; case NdisMedium802_5: NdisMTrIndicateReceive(pAdapt->MiniportHandle, MacReceiveContext, HeaderBuffer, HeaderBufferSize, LookAheadBuffer, LookAheadBufferSize, PacketSize); break; case NdisMediumFddi: NdisMFddiIndicateReceive(pAdapt->MiniportHandle, MacReceiveContext, HeaderBuffer, HeaderBufferSize, LookAheadBuffer, LookAheadBufferSize, PacketSize); break; default: ASSERT(0); break; }*/ if(PacketSize<=LookAheadBufferSize) { Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax); if(Status!=NDIS_STATUS_SUCCESS) { DbgPrint("PtReceive NdisAllocateMemory error!\n"); return NDIS_STATUS_NOT_ACCEPTED; } if(pPacketContent==NULL) { DbgPrint("PtReceive pPacketContent==NULL\n"); return NDIS_STATUS_NOT_ACCEPTED; } NdisZeroMemory(pPacketContent,BUFFER_SIZE); NdisMoveMemory(pPacketContent,HeaderBuffer,HeaderBufferSize); NdisMoveMemory(pPacketContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize); PacketLen=PacketSize+HeaderBufferSize; NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle); if(Status==NDIS_STATUS_SUCCESS) { NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvPacketPoolHandle,pPacketContent,PacketLen); NdisChainBufferAtFront(MyPacket,pPacketBuffer); MyPacket->Private.Head->Next=NULL; MyPacket->Private.Tail=NULL; Rsvd=(PRSVD)(MyPacket->MiniportReserved); Rsvd->OriginalPkt=NULL; NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize); NdisMIndicateReceivePacket(pAdapt->MiniportHandle,&MyPacket,1); if(NDIS_GET_PACKET_STATUS(MyPacket)!=NDIS_STATUS_PENDING) { DbgPrint("PtReceive Free Memory\n"); NdisFreeBuffer(pPacketBuffer); NdisFreeMemory(pPacketBuffer,BUFFER_SIZE,0); NdisDprFreePacket(MyPacket); } } break; }//end if(PacketSize<LookAheadBufferSize) else { Status=NdisAllocateMemory(&pPacketContent,BUFFER_SIZE,0,HighestAcceptableMax); if(Status!=NDIS_STATUS_SUCCESS) { DbgPrint("PtReceive NdisAllocateMemory error!\n"); return NDIS_STATUS_NOT_ACCEPTED; } if(pPacketContent==NULL) { DbgPrint("PtReceive pPackContent NULL!\n"); return NDIS_STATUS_NOT_ACCEPTED; } NdisZeroMemory(pPacketContent,BUFFER_SIZE); NdisDprAllocatePacket(&Status,&MyPacket,pAdapt->RecvPacketPoolHandle); Status=NdisAllocateMemory(&pBakContent,BUFFER_SIZE,0,HighestAcceptableMax); if(Status!=NDIS_STATUS_SUCCESS) { DbgPrint("PtReceive NdisAllocateMemory error!\n"); return NDIS_STATUS_NOT_ACCEPTED; } if(pBakContent==NULL) { DbgPrint("PtReceite pBakContent NULL\n"); return NDIS_STATUS_NOT_ACCEPTED; } NdisZeroMemory(pBakContent,BUFFER_SIZE); NdisMoveMemory(pBakContent,HeaderBuffer,HeaderBufferSize); NdisMoveMemory(pBakContent+HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize); PacketLen=HeaderBufferSize+PacketSize; NdisAllocateBuffer(&Status,&pPacketBuffer,pAdapt->RecvBufferPoolHandle,pPacketContent,PacketSize-LookAheadBufferSize); NdisChainBufferAtFront(MyPacket,pPacketBuffer); MyPacket->Private.Head->Next=NULL; MyPacket->Private.Tail=NULL; OffsetSize=HeaderBufferSize+LookAheadBufferSize; NdisDprAllocatePacket(&Status,&MyPacket1,pAdapt->RecvPacketPoolHandle); NdisAllocateBuffer(&Status,&pBakBuffer,pAdapt->RecvBufferPoolHandle,pBakContent,OffsetSize); NdisChainBufferAtFront(MyPacket1,pBakBuffer); Rsvd=(PRSVD)(MyPacket->MiniportReserved); Rsvd->OriginalPkt=(PNDIS_PACKET)MyPacket1; NDIS_SET_PACKET_HEADER_SIZE(MyPacket,HeaderBufferSize); NdisTransferData(&Status,pAdapt->BindingHandle,MacReceiveContext,LookAheadBufferSize,PacketSize-LookAheadBufferSize,MyPacket,&BytesTransferred); if(Status!=NDIS_STATUS_PENDING) { PtTransferDataComplete((NDIS_HANDLE)pAdapt,MyPacket,Status,BytesTransferred); } break; } pAdapt->IndicateRcvComplete=TRUE; } while(FALSE); return Status; } |
|
沙发#
发布于:2008-06-27 21:55
出现蓝屏,提示
DRIVER_IRQL_NOT_LESS_OR_EQUAL |
|
板凳#
发布于:2008-06-29 21:31
原来是MPReturnPacket函数里面释放内存有问题
|
|
地板#
发布于:2008-07-08 18:17
能说得具体点嘛?谢谢
我也有同样的疑问 |
|
地下室#
发布于:2008-07-18 18:40
VOID
MPReturnPacket( IN NDIS_HANDLE MiniportAdapterContext, IN PNDIS_PACKET Packet ) /*++ Routine Description: NDIS Miniport entry point called whenever protocols are done with a packet that we had indicated up and they had queued up for returning later. Arguments: MiniportAdapterContext - pointer to ADAPT structure Packet - packet being returned. Return Value: None. --*/ { /*PADAPT pAdapt = (PADAPT)MiniportAdapterContext; #ifdef NDIS51 // // Packet stacking: Check if this packet belongs to us. // if (NdisGetPoolFromPacket(Packet) != pAdapt->RecvPacketPoolHandle) { // // We reused the original packet in a receive indication. // Simply return it to the miniport below us. // NdisReturnPackets(&Packet, 1); } else #endif // NDIS51 { // // This is a packet allocated from this IM's receive packet pool. // Reclaim our packet, and return the original to the driver below. // PNDIS_PACKET MyPacket; PRECV_RSVD RecvRsvd; RecvRsvd = (PRECV_RSVD)(Packet->MiniportReserved); MyPacket = RecvRsvd->OriginalPkt; NdisFreePacket(Packet); ///ADD BY SH /// NdisUnchainBufferAtBack(MyPacket,&PktBuffer); /// NdisFreeBuffer(PktBuffer); /// NdisFreeMemory(MemoryVA, /// TotalPacketLength, //Maybe add a checksum length /// 0); ///ADD BY SH NdisReturnPackets(&MyPacket, 1); }*/ PADAPT pAdapt = (PADAPT)MiniportAdapterContext; PNDIS_PACKET MyPacket; PRECV_RSVD Resvd; PNDIS_BUFFER pNdisBuffer; PUCHAR pPacketContent; UINT BufferLen; Resvd = (PRECV_RSVD)(Packet->MiniportReserved); MyPacket = Resvd->OriginalPkt; //DBGPRINT(("In MPReturnPacket()\n")); if(MyPacket) { NdisFreePacket(Packet); NdisReturnPackets(&MyPacket, 1); } // I Add This Code for NdisIndicateReceivePacket //ÔÚPtReceiveºó£¬×Ô¶¯µ÷Óøú¯Êý£¬ÊÍ·ÅÄÚ´æ else { NdisUnchainBufferAtFront(Packet,&pNdisBuffer); NdisQueryBufferSafe(pNdisBuffer,(PVOID *)&pPacketContent,&BufferLen,32); NdisFreeBuffer(pNdisBuffer); NdisFreeMemory(pPacketContent,2000,0); NdisFreePacket(Packet); } } |
|