x1aon1ao
驱动牛犊
驱动牛犊
  • 注册日期2009-12-04
  • 最后登录2012-02-25
  • 粉丝0
  • 关注0
  • 积分26分
  • 威望211点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2988回复:3

[求助]在passthru上开发来实现控制网速,接收包这块总是蓝屏,高手帮忙看下

楼主#
更多 发布于:2010-12-01 07:34
我先说下我的实现方法,大家帮忙看看有没有错误。
我在原来代码中所有的NdisMIndicateReceivePacket前都添加了判断流量的函数,如果超过流量了,就不调用NdisMIndicateReceivePacket函数,而把packet添加入链表中,
有个线程专门处理此链表,该线程延迟0.5s再调用NdisMIndicateReceivePacket(packet)通知上层收包完成了。

下面是代码:
//PtRecieve函数中的部分
if (pAdapt->MiniportHandle != NULL)
{
    Status = GetPacketSize(MyPacket, PACKET_TYPE_RECV, Status, pAdapt, TRUE);//GetPacketSize是我自己写的函数,用来判断数据量,并插入链表的。返回//NDIS_STATUS_PENDING表示超过流量了。
    if(Status != NDIS_STATUS_PENDING) NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1);
}
                

if(Status != NDIS_STATUS_PENDING) NdisDprFreePacket(MyPacket);

//GetPacketSize部分
NDIS_STATUS GetPacketSize(PNDIS_PACKET pPacket, PACKET_TYPE_ENUM enumPacketType,  NDIS_STATUS status, NDIS_HANDLE AdapterContext, BOOLEAN bNeedRelease)
{
    NDIS_STATUS statusRet = status;
    UINT bNeedToSleep = 0;
    PMyDataStruct pDataStru = NULL;
    
        
    //判断部分省略了
        
        if(bNeedToSleep)
        {
            //NdisStallExecution(50);
            statusRet = NDIS_STATUS_PENDING;
            pDataStru = (PMyDataStruct)ExAllocatePool(NonPagedPool, sizeof(MyDataStruct));
            pDataStru->packet = pPacket;
            pDataStru->enmType = enumPacketType;
            pDataStru->AdapterContext = AdapterContext;
            pDataStru->Status = status;
            pDataStru->bNeedRelease = bNeedRelease;
            ExInterlockedInsertTailList(&list_head, &pDataStru->ListEntry, &list_lock );
            KeSetEvent(&request_event, (KPRIORITY) 0, FALSE);  
        }
        else
        {
            statusRet = status;
        }

    return statusRet;
}

//结构体部分
typedef struct _MyDataStruct
{
    LIST_ENTRY ListEntry;
    PNDIS_PACKET packet;
    PACKET_TYPE_ENUM enmType;
    NDIS_STATUS Status;
    NDIS_HANDLE AdapterContext;
    BOOLEAN bNeedRelease;
}MyDataStruct, *PMyDataStruct;

//处理链表的线程部分
VOID  
DelayThread(  
            IN PVOID Context  
            )  
{  
    PLIST_ENTRY request;
    PMyDataStruct pDataStru;
    PNDIS_PACKET packet;
    PADAPT pAdapt = NULL;
    
    KeSetPriorityThread(KeGetCurrentThread(), LOW_REALTIME_PRIORITY);  
    
    for (;;)  
    {  
        KeWaitForSingleObject(&request_event,Executive,KernelMode,FALSE,NULL);  
        
        if (terminate_thread)  
        {  
            PsTerminateSystemThread(STATUS_SUCCESS);  
        }  
        
        while (request = ExInterlockedRemoveHeadList(&list_head,&list_lock))  
        {  
            pDataStru = CONTAINING_RECORD(request, MyDataStruct, ListEntry);  
            pAdapt = (PADAPT)(pDataStru->AdapterContext);
            packet = pDataStru->packet;  
            
            switch (pDataStru->enmType)
            {
            case PACKET_TYPE_SEND:
                NdisMSendComplete(pAdapt->MiniportHandle,packet,pDataStru->Status);
                break;
            case PACKET_TYPE_RECV:
                NdisMIndicateReceivePacket(pAdapt, &(packet), 1);
                break;
            }

            if(pDataStru->bNeedRelease) NdisDprFreePacket(packet);
            ExFreePool(pDataStru);
            pDataStru = NULL;
        }  
    }  
}  

总是在DelayThread中的NdisMIndicateReceivePacket(pAdapt, &(packet), 1)蓝屏。


蓝屏报告如下:SYSTEM_THREAD_EXCEPTION_NOT_HANDLED_M (1000007e)
This is a very common bugcheck.  Usually the exception address pinpoints
the driver/function that caused the problem.  Always note this address
as well as the link date of the driver/image that contains this address.
Some common problems are exception code 0x80000003.  This means a hard
coded breakpoint or assertion was hit, but this system was booted
/NODEBUG.  This is not supposed to happen as developers should never have
hardcoded breakpoints in retail code, but ...
If this happens, make sure a debugger gets connected, and the
system is booted /DEBUG.  This will let us see why this breakpoint is
happening.
Arguments:
Arg1: c0000005, The exception code that was not handled
Arg2: 00000000, The address that the exception occurred at
Arg3: f9f33cc0, Exception Record Address
Arg4: f9f339bc, Context Record Address

Debugging Details:
------------------


EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - "0x%08lx"

FAULTING_IP:
+16
00000000 ??              ???

EXCEPTION_RECORD:  f9f33cc0 -- (.exr 0xfffffffff9f33cc0)
ExceptionAddress: 00000000
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000000
   Parameter[1]: 00000000
Attempt to read from address 00000000

CONTEXT:  f9f339bc -- (.cxr 0xfffffffff9f339bc)
eax=816ed590 ebx=00000000 ecx=00000000 edx=816ed590 esi=816ed280 edi=00000000
eip=00000000 esp=f9f33d88 ebp=f9f33dac iopl=0         nv up ei pl zr na pe nc
cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00010246
00000000 ??              ???
Resetting default scope

CUSTOMER_CRASH_COUNT:  2

DEFAULT_BUCKET_ID:  INTEL_CPU_MICROCODE_ZERO

PROCESS_NAME:  System

ERROR_CODE: (NTSTATUS) 0xc0000005 - "0x%08lx"

EXCEPTION_PARAMETER1:  00000000

EXCEPTION_PARAMETER2:  00000000

READ_ADDRESS:  00000000

FOLLOWUP_IP:
passthru!DelayThread+c7 [c:\winddk\7600.16385.0\passthru\driver\passthru.c @ 591]
f9d2dea7 8b55f0          mov     edx,dword ptr [ebp-10h]

FAILED_INSTRUCTION_ADDRESS:
+2dd952f014adfdc
00000000 ??              ???

BUGCHECK_STR:  0x7E

LAST_CONTROL_TRANSFER:  from f9d2dea7 to 00000000

STACK_TEXT:  
WARNING: Frame IP not in any known module. Following frames may be wrong.
f9f33d84 f9d2dea7 816ed590 f9f33da0 00000001 0x0
f9f33dac 8057dfce 00000000 00000000 00000000 passthru!DelayThread+0xc7 [c:\winddk\7600.16385.0\passthru\driver\passthru.c @ 591]
f9f33ddc 804f98fa f9d2dde0 00000000 00000000 nt!PspSystemThreadStartup+0x34
00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x16


好心人帮忙看下呀
x1aon1ao
驱动牛犊
驱动牛犊
  • 注册日期2009-12-04
  • 最后登录2012-02-25
  • 粉丝0
  • 关注0
  • 积分26分
  • 威望211点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2010-12-04 19:36
   顶顶更健康
cyliu
论坛版主
论坛版主
  • 注册日期2003-06-13
  • 最后登录2014-04-11
  • 粉丝5
  • 关注0
  • 积分1238分
  • 威望2531点
  • 贡献值0点
  • 好评度577点
  • 原创分14分
  • 专家分10分
板凳#
发布于:2010-12-19 14:09
要防止RtRecv返回后,数据包被释放了。而在队列里面引用数据包指针已经无意义了
走走看看开源好 Solaris vs Linux
jscool520
驱动牛犊
驱动牛犊
  • 注册日期2009-03-13
  • 最后登录2012-12-20
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望101点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2011-03-22 15:29
后来如何了,我现在也遇到这样的问题。
游客

返回顶部