阅读:2405回复:3
关于KeSetTimerEx 和KeWaitForsingleObject的问题,极度困惑中,
问题如下:
我定义了一个扩展结构,如下: typedef struct _FDO_DEVICE_DATA { KDPC DPCPolling; // DPC routine used for polling PIO_WORKITEM PollingWorker; // The worker routine structure LONG PollingAllowed; LONG PollingNotQueued; LONG Polling; ULONG PollingPeriod; KTIMER PollingTimer; KEVENT PollingEvent; KEVENT PollStateEvent; LONG bTakeAction; // The name returned from IoRegisterDeviceClass Association, // which is used as a handle for IoSetDev... and friends. } FDO_DEVICE_DATA, *PFDO_DEVICE_DATA; 在驱动的入口处我对上面的结构的数据进行初始化, DeviceData = (PFDO_DEVICE_DATA) deviceObject->DeviceExtension; RtlFillMemory (DeviceData, sizeof (FDO_DEVICE_DATA), 0); DeviceData->Polling = 0; DeviceData->PollingPeriod = 10; DeviceData->PollingWorker = IoAllocateWorkItem(deviceObject); if (DeviceData->PollingWorker == NULL) { KdPrint(("Insufficient memory for Polling Routine.\n")); return STATUS_INSUFFICIENT_RESOURCES; } // // Initialize the timer used for dynamic detection of attachment // and removal of PNP devices. // KeInitializeEvent(&DeviceData->PollingEvent, SynchronizationEvent, FALSE); KeInitializeEvent(&DeviceData->PollStateEvent, SynchronizationEvent, TRUE); KeInitializeDpc( &DeviceData->DPCPolling, (PKDEFERRED_ROUTINE) PollingTimerRoutine, DeviceData); 如果在这个driverentry函数里我像下面一样地调用 KeWaitForSingleObject(&FdoData->PollStateEvent, Executive, KernelMode, FALSE, NULL); 是不会有任何问题的. 但是如果我在dispathioctl函数中也是这样调用的话就会马上抛出异常,说是Page Fault; exception e; fault ==2;忽略异常之后系统自动重启. 代码如下: NTSTATUS DispatchIoctl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PFDO_DEVICE_DATA pDeviceData; pDeviceData = (PFDO_DEVICE_DATA)DeviceObject->DeviceObjectExtension; ......... swith..(IoControlCode) { case IOCTL_TESTDPC_START_POLLING: if(!pDeviceData->Polling) { StartPolling(pDeviceData); KeWaitForSingleObject(&(pDeviceData->PollStateEvent), Executive,UserMode,FALSE,NULL); KeSetEvent(&(pDeviceData->PollStateEvent),1,FALSE); } } } 我检查过里的irql <= DISPATCH_LEVEL. 为什么呢????? 还望大侠指点迷津. |
|
沙发#
发布于:2004-08-14 11:23
<=DISPATCH_LEVEL ?
should be == so the thread cannot be block via kewaitforsingleobject() |
|
板凳#
发布于:2004-08-14 14:33
不明白
|
|
|
地板#
发布于:2004-09-01 18:35
pDeviceData = (PFDO_DEVICE_DATA)DeviceObject->DeviceObjectExtension;
呵呵,其实是这一句写错了.笔误.哈哈.好久没有来,不好意思. 应该是这样才对 pDeviceData= (PFDO_DEVICE_DATA) deviceObject->DeviceExtension; |
|