阅读:1778回复:3
变量类型一问
不知道哪位大虾使用过WORK_QUEUE_ITEM定义过变量,能不能跟我详细介绍这个变量类型的作用和用法,告诉我在哪里能找到这方面的资料也行!多谢了!
|
|
沙发#
发布于:2002-05-17 09:41
你这个变量是在什么时候,什么情况下用的呀?
|
|
板凳#
发布于:2002-05-17 10:21
WORK_QUEUE_ITEM是系统工作线程。其作用是将在线程运行级别>= DISPATCH_LEVEL时将要运行但是要求级别为PASSIVE LEVEL的例程加入系统线程,再由系统在PASSIVE LEVEL调用。以下是在我的驱动程序中的一段代码,有助于你理解WORK_QUEUE_ITEM的用法。
typedef struct _FILE_WORK_ITEM { PVOID FileContext; WORK_QUEUE_ITEM WorkItem; HANDLE FileHandle; PCWSTR FileName; ULONG Length; } FILE_WORK_ITEM,*PFILE_WORK_ITEM; VOID UsbDriverCreateFile( IN PVOID Context, IN OUT HANDLE *FileHandle, IN PCWSTR FileName) { NTSTATUS ntStatus; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; UNICODE_STRING UniFileName; PFILE_WORK_ITEM workitem; if(KeGetCurrentIrql() < DISPATCH_LEVEL) { RtlInitUnicodeString(&UniFileName , FileName); InitializeObjectAttributes(&ObjectAttributes,&UniFileName, OBJ_CASE_INSENSITIVE,NULL,NULL); ntStatus=ZwCreateFile(FileHandle, GENERIC_WRITE|SYNCHRONIZE|GENERIC_READ, &ObjectAttributes, &IoStatusBlock, 0, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE, FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0); if(NT_SUCCESS(ntStatus) && FileHandle != NULL) { } } else { ntStatus = STATUS_PENDING; workitem = (PFILE_WORK_ITEM)ExAllocatePool(NonPagedPool, sizeof(FILE_WORK_ITEM)); if (workitem) { ExInitializeWorkItem(&workitem->WorkItem, UsbDriverFileWorkItem,//加入系统工作线程 workitem); workitem->FileContext = Context; workitem->FileHandle = *FileHandle; workitem->FileName = FileName; ExQueueWorkItem(&workitem->WorkItem, DelayedWorkQueue); } else { ntStatus = STATUS_INSUFFICIENT_RESOURCES; } } return ; } //系统在PASSIVE LEVEL 调用执行 VOID UsbDriverFileWorkItem( PVOID Context) { HANDLE FileHandle; NTSTATUS ntStatus; OBJECT_ATTRIBUTES ObjectAttributes; IO_STATUS_BLOCK IoStatusBlock; PCWSTR FileName; UNICODE_STRING UniFileName; LARGE_INTEGER ByteOffset; PFILE_WORK_ITEM workitem = (PFILE_WORK_ITEM) Context; FileHandle = workitem->FileHandle; FileName = workitem->FileName; RtlInitUnicodeString(&UniFileName , FileName); InitializeObjectAttributes(&ObjectAttributes,&UniFileName, OBJ_CASE_INSENSITIVE,NULL,NULL); ntStatus=ZwCreateFile(&FileHandle, GENERIC_WRITE|SYNCHRONIZE|GENERIC_READ, &ObjectAttributes, &IoStatusBlock, 0, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE, FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0); if(NT_SUCCESS(ntStatus) && FileHandle != NULL) { ExFreePool(workitem); } return; } |
|
|
地板#
发布于:2002-05-18 09:38
非常感谢!
|
|