danielxu22
驱动中牛
驱动中牛
  • 注册日期2002-11-22
  • 最后登录2014-03-24
  • 粉丝0
  • 关注1
  • 积分2分
  • 威望18点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
阅读:1340回复:7

BSOD of HID device

楼主#
更多 发布于:2003-03-25 18:31
NTSTATUS
InternalIoctl
    (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    )
{......
case IOCTL_HID_READ_REPORT:
        //
        //Return a report from the device into a class driver-supplied buffer.
        //
        DebugPrint((\"IOCTL_HID_READ_REPORT\\n\"));
      
       ntStatus = OrbQueueReadReport(DeviceObject, Irp);
  ntStatus = ReadReport(DeviceObject, Irp);
  return ntStatus;
......
Irp->IoStatus.Status = ntStatus;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    ntStatus = STATUS_SUCCESS;

    return ntStatus;
}


NTSTATUS
ReadReport(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    )
{
    NTSTATUS ntStatus = STATUS_SUCCESS;
    PDEVICE_EXTENSION   deviceInfo;
    PIO_STACK_LOCATION  IrpStack;
    LARGE_INTEGER timeout;
    PREAD_TIMER    readTimerStruct;
PMOUSE_FEATURE_DATA mouseData;
//PIRP mouseIrp;

    DebugPrint((\"ReadReport Entry\\n\"));
    //
    // Get a pointer to the device extension
    //
    deviceInfo = GET_MINIDRIVER_DEVICE_EXTENSION(DeviceObject);

DebugPrint((\"Before ExAllocatePoolWithTag = %x\\n\", KeGetCurrentIrql()));


 readTimerStruct = ExAllocatePoolWithTag(NonPagedPool,
                                            sizeof(READ_TIMER),
                                            VHID_POOL_TAG
                                            );
DebugPrint((\"After ExAllocatePoolWithTag = %x\\n\", KeGetCurrentIrql()));
   if(!readTimerStruct){
        DebugPrint((\"Mem allocation for readTimerStruct failed\\n\"));
        Irp->IoStatus.Status = ntStatus = STATUS_INSUFFICIENT_RESOURCES;
        IoCompleteRequest(Irp, IO_NO_INCREMENT);
        return ntStatus;
    }

    else{

        RtlZeroMemory(readTimerStruct, sizeof(READ_TIMER));
        //
        //remember the Irp
        //
        readTimerStruct->Irp = Irp;
//readTimerStruct->deviceInfo=deviceInfo;
        //
        // Initialize the DPC structure and Timer
        //
        DebugPrint((\"Before KeInitializeDpc = %x\\n\", KeGetCurrentIrql()));
        KeInitializeDpc(&readTimerStruct->ReadTimerDpc,
                        ReadTimerDpcRoutine,
                        (PVOID)readTimerStruct
                        );
        DebugPrint((\"After KeInitializeDpc = %x\\n\", KeGetCurrentIrql()));

DebugPrint((\"Before KeInitializeTimer = %x\\n\", KeGetCurrentIrql()));
        KeInitializeTimer(&readTimerStruct->ReadTimer);
DebugPrint((\"After KeInitializeTimer = %x\\n\", KeGetCurrentIrql()));
        //
        // Queue the timer DPC  
        //
        timeout.HighPart = -1;
        timeout.LowPart = -(LONG)(10*1000*5000);  //in 100 ns.total 5 sec
       DebugPrint((\"Before KeSetTimer = %x\\n\", KeGetCurrentIrql()));
        KeSetTimer(&readTimerStruct->ReadTimer,
                   timeout,
                   &readTimerStruct->ReadTimerDpc
                   );
         DebugPrint((\"After KeSetTimer = %x\\n\", KeGetCurrentIrql()));          
  
    }
DebugPrint((\"ReadReport Exit = 0x%x\\n\", ntStatus));

    return ntStatus;
}

其中:
typedef struct _DEVICE_EXTENSION{

    HID_DESCRIPTOR              HidDescriptor;

    PHID_REPORT_DESCRIPTOR          ReportDescriptor;

    BOOLEAN                           ReadReportDescFromRegistry;

    DEVICE_PNP_STATE    DevicePnPState;   // Track the state of the device

    DEVICE_PNP_STATE    PreviousPnPState; // Remembers the previous pnp state
BOOLEAN Removed; // Is device being removed?
PDEVICE_OBJECT nextDevObj; // PDO that BUS gave to us

// queue stuff
KSPIN_LOCK readQueueLock; // Spin lock //add 2
LIST_ENTRY readQueueList; // List
NPAGED_LOOKASIDE_LIST readQueuePool; // Lookaside list
ULONG readsPending; // Reads pending
} DEVICE_EXTENSION, * PDEVICE_EXTENSION;

typedef struct _READ_TIMER{
    
    KDPC             ReadTimerDpc;
    KTIMER          ReadTimer;
    PIRP              Irp;
  
} READ_TIMER, * PREAD_TIMER;

VOID
ReadTimerDpcRoutine(  
    IN PKDPC Dpc,
    IN PVOID DeferredContext,
    IN PVOID SystemArgument1,
    IN PVOID SystemArgument2
    )
{
发送两个数
}


NTSTATUS
OrbQueueReadReport(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PORB_QUEUE_ITEM item;
NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES;
    PDEVICE_EXTENSION   devExt;
DebugPrint((\"Before OrbQueueReadReport = %x\\n\", KeGetCurrentIrql()));

  devExt = GET_MINIDRIVER_DEVICE_EXTENSION(DeviceObject);

// New way:
// We allocate item from lookaside list, this is more effective
// and pool doesn\'t get fragmented.
item = ExAllocateFromNPagedLookasideList(&devExt->readQueuePool);
// Fail if no memory
if (item == NULL) {
// Bad luck
DebugPrint((\"OrbQueueReadReport(): no item\\n\"));

// Complete Irp with error
return CompleteIrp(Irp, status, 0);
}
// Remember to always mark Irp pending
IoMarkIrpPending(Irp);
// Save Irp pointer for later processing
item->Irp = Irp;
// Insert into queue of pending requests
ExInterlockedInsertHeadList(&devExt->readQueueList, &item->List, &devExt->readQueueLock);
// Increment pending I/O count
InterlockedIncrement(&devExt->readsPending);
Irp->IoStatus.Status = STATUS_PENDING;
Irp->IoStatus.Information = sizeof(devExt->readsPending);
DebugPrint((\"After OrbQueueReadReport = %x\\n\", KeGetCurrentIrql()));
return STATUS_PENDING;
}
请问:
readTimer和DPC可以删除吗?
这段代码有问题,老是出现蓝屏,请教高手!大大给分!
今天我发现我家的金鱼淹死了,:(
danielxu22
驱动中牛
驱动中牛
  • 注册日期2002-11-22
  • 最后登录2014-03-24
  • 粉丝0
  • 关注1
  • 积分2分
  • 威望18点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-03-26 09:41
顶一下:)
今天我发现我家的金鱼淹死了,:(
danielxu22
驱动中牛
驱动中牛
  • 注册日期2002-11-22
  • 最后登录2014-03-24
  • 粉丝0
  • 关注1
  • 积分2分
  • 威望18点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-03-27 17:38
ding
今天我发现我家的金鱼淹死了,:(
danielxu22
驱动中牛
驱动中牛
  • 注册日期2002-11-22
  • 最后登录2014-03-24
  • 粉丝0
  • 关注1
  • 积分2分
  • 威望18点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-03-31 09:34
没有人帮我:(
今天我发现我家的金鱼淹死了,:(
rayyang2000
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2012-09-13
  • 粉丝3
  • 关注0
  • 积分1036分
  • 威望925点
  • 贡献值3点
  • 好评度823点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-04-04 22:49
这么长代码,谁有空看啊!你应该标出在哪里出现BSOD
天天coding-debugging中----超稀饭memory dump file ======================================================== [b]Windows Device Driver Development and Consulting Service[/b] [color=blue][url]http://www.ybwork.com[/url][/color] ========================================================
danielxu22
驱动中牛
驱动中牛
  • 注册日期2002-11-22
  • 最后登录2014-03-24
  • 粉丝0
  • 关注1
  • 积分2分
  • 威望18点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2003-04-08 17:53
老大,这还不是全部了,我只是选区了一小部分
今天我发现我家的金鱼淹死了,:(
danielxu22
驱动中牛
驱动中牛
  • 注册日期2002-11-22
  • 最后登录2014-03-24
  • 粉丝0
  • 关注1
  • 积分2分
  • 威望18点
  • 贡献值0点
  • 好评度7点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2003-04-08 17:56
IoCompleteRequest(Irp, IO_NO_INCREMENT);
是这句话出错,

这个程序是鼠标的hid驱动,我用app让它画矩形,很奇怪的是,开始没有问题,画300*300的正方形,当画到28圈的时候蓝屏

不解啊!
今天我发现我家的金鱼淹死了,:(
yyx_200
禁止发言
禁止发言
  • 注册日期2001-12-24
  • 最后登录2018-06-02
  • 粉丝0
  • 关注0
  • 积分72283分
  • 威望361771点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2003-10-17 15:43
用户被禁言,该主题自动屏蔽!
游客

返回顶部