阅读:1354回复:1
获取管道句柄出错
我写了一个USB HID minidriver,在处理IOCTL_HID_READ_REPORT的时候总是蓝屏,经过调试发现是获取管道句柄时出错,能不能请高手帮我分析下??
TSTATUS ReadReport( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) /*++ Routine Description: Creates reports and sends it back to the requester. Arguments: DeviceObject - pointer to a device object. Irp - Pointer to Interrupt Request Packet. Return Value: NT status code. --*/ { ULONG bytesToCopy=0x01; PDEVICE_EXTENSION deviceExtension; PIO_STACK_LOCATION irpStack; PIO_STACK_LOCATION nextStack; PUSBD_PIPE_INFORMATION pipeInformation; ULONG urbFlags; PURB urb; ULONG LengthToOperate; PHID_CONTEXT Context; NTSTATUS ntstatus; PIRP NewIrp; KEVENT event; IO_STATUS_BLOCK ioStatus; PFILE_OBJECT fileobject; USBD_PIPE_HANDLE handle; irpStack=IoGetCurrentIrpStackLocation(Irp); urb=NULL; NewIrp=NULL; deviceExtension=GET_MINIDRIVER_DEVICE_EXTENSION(DeviceObject); Context=NULL; LengthToOperate=irpStack->Parameters.Read.Length; deviceExtension->buffer=ExAllocatePool(NonPagedPool,0x01); // 获取管道句柄,也就是出错的地方! fileobject=irpStack->FileObject; if(fileobject && fileobject->FsContext) { pipeInformation = fileobject->FsContext; } DebugPrint(("ReadCompletion")); //申请urb数据结构 urb=ExAllocatePool(NonPagedPool,sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER)); if(urb == NULL) { DebugPrint(("Failed to alloc mem for urb\n")); ntstatus = STATUS_INSUFFICIENT_RESOURCES; } //建立管道 urbFlags =USBD_TRANSFER_DIRECTION_IN|USBD_SHORT_TRANSFER_OK; UsbBuildInterruptOrBulkTransferRequest( urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), pipeInformation->PipeHandle,//管道句柄 Irp->UserBuffer, NULL, bytesToCopy, urbFlags,//USBD_TRANSFER_DIRECTION_IN NULL); KeInitializeEvent(&event, NotificationEvent, FALSE); NewIrp=IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_SUBMIT_URB, GET_NEXT_DEVICE_OBJECT(DeviceObject), NULL, 0, NULL, 0, TRUE, &event, &ioStatus); //设置下层堆栈参数 nextStack=IoGetNextIrpStackLocation(NewIrp); // nextStack->MajorFunction=IRP_MJ_INTERNAL_DEVICE_CONTROL; nextStack->Parameters.Others.Argument1=(PVOID)urb; // nextStack->Parameters.DeviceIoControl.IoControlCode=IOCTL_INTERNAL_USB_SUBMIT_URB; //设置完成例程 Context=(PHID_CONTEXT)ExAllocatePool(NonPagedPool,sizeof(HID_CONTEXT)); Context->urb=urb; Context->deviceExtention=deviceExtension; Context->ReadLength=LengthToOperate; Context->ParantIrp=Irp; IoSetCompletionRoutine(NewIrp, (PIO_COMPLETION_ROUTINE)ReadWriteCompletion, Context, TRUE, TRUE, TRUE); IoMarkIrpPending(Irp); ntstatus=IoCallDriver(GET_NEXT_DEVICE_OBJECT(DeviceObject),NewIrp); return STATUS_PENDING; } |
|
沙发#
发布于:2009-03-23 20:52
fileobject->FsContext !=NULL或者fileobject->FsContext ==NULL, FsContext可是Pvoid呀!
|
|