阅读:1307回复:5
关于设备扩展得问题
我些了个WDM的框架程序,在ADDDEVICE例程里初始化设备扩展变量ULONG A=10;然后在删除设备例程里,写了很简单的一些代码:设备接口无效,清除GUID缓冲区,从设备堆栈删除该设备,删除设备对象,应该室很常规的操作.
我的问题是当程序运行完删除设备例程后,发生蓝屏,错误代码0x0a,是说在大于或者等于DISPATCH_LEVEL的级别上使用了分页内存,引起错误的文件是内核文件:ntoskrnl.exe. 当我在ADDDEVICE例程里把A=10去掉的话,能正常卸载设备,不发生蓝屏的问题. 难道在ADDDEVICE里不能初始化ULONG类型的变量?我想不可能这样吧 |
|
|
沙发#
发布于:2004-08-03 12:10
详细代码看看。。。。。
|
|
|
板凳#
发布于:2004-08-03 13:55
代码如下:
/////////////////////////////// lianxi.c: /////////////////////////////// #include "lianxi.h" #include "guid.h" #define INITGUID NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { #if DBG DbgPrint("LIANXI:enter the DriveEntry.\n"); DbgPrint("the irql is %x\n",KeGetCurrentIrql()); #endif DriverObject->MajorFunction[IRP_MJ_CREATE]=liandispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE]=liandispatch; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=liandispatch; DriverObject->MajorFunction[IRP_MJ_PNP]=lianpnphandle; DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL]=lianwmi; DriverObject->DriverExtension->AddDevice=AddDevice; DriverObject->DriverUnload=lianunload; return STATUS_SUCCESS; } VOID lianunload(PDRIVER_OBJECT DriverObject) { DbgPrint("LIANXI:Unload\n"); DbgPrint("the irql is %x\n",KeGetCurrentIrql()); return; } NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PDO ) { PDEVICE_OBJECT FDO; PLIAN_DEVICE_EXTENSION DEX; NTSTATUS status; DbgPrint("LIANXI:enter the AddDevice .\n"); DbgPrint("the irql is %x\n",KeGetCurrentIrql()); status=IoCreateDevice(DriverObject, sizeof(PLIAN_DEVICE_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, 0, FALSE, &FDO); if(!NT_SUCCESS(status)) { DbgPrint("LIANXI:create device failed.\n"); return status; } DEX=(PLIAN_DEVICE_EXTENSION)FDO->DeviceExtension; status=IoRegisterDeviceInterface(PDO, &SAMPLE, NULL, &DEX->LINKNAME ); if(!NT_SUCCESS(status)) { DbgPrint("LIANXI:register deviceinterface failed.\n"); IoDeleteDevice(FDO); return status; } IoSetDeviceInterfaceState(&DEX->LINKNAME,TRUE); DEX->LOWDEVICE=IoAttachDeviceToDeviceStack(FDO,PDO); if (!DEX->LOWDEVICE) { DbgPrint("LIANXI:attact FDO to PDO failed.\n"); lianunload(DriverObject); // return STATUS_UNSUCCESSFUL; } DEX->PDO=PDO; DEX->FDO=FDO; FDO->Flags |= DO_DIRECT_IO; FDO->Flags |= DO_POWER_PAGABLE; FDO->Flags &= ~DO_DEVICE_INITIALIZING; DEX->ADD=10; DbgPrint("LIANXI:We have adddevice successed.\n"); return STATUS_SUCCESS; } NTSTATUS lianpnphandle(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PIO_STACK_LOCATION IrpStack; PLIAN_DEVICE_EXTENSION DEX; ULONG MinorFunction ; ULONG MajorFunction; NTSTATUS status ; DEX=(PLIAN_DEVICE_EXTENSION)DeviceObject->DeviceExtension; IrpStack = IoGetCurrentIrpStackLocation(Irp); MinorFunction = IrpStack->MinorFunction; MajorFunction=IrpStack->MajorFunction; DbgPrint("LIANXI:enter the PnP,MajorFunction:0x%x,MinorFunction:0x%x\n",MajorFunction,MinorFunction); //然后把这个Minor Function传递给下一个设备栈: DbgPrint("the irql is %x\n",KeGetCurrentIrql()); IoSkipCurrentIrpStackLocation(Irp); status = IoCallDriver( DEX->LOWDEVICE, Irp); if( MinorFunction==IRP_MN_START_DEVICE) { DbgPrint("LIANXI:IRP_MN_START_DEVICE.\n"); } if( MinorFunction==IRP_MN_QUERY_REMOVE_DEVICE) { DbgPrint("LIANXI:IRP_MN_QUERY_REMOVE_DEVICE.\n"); } if( MinorFunction==IRP_MN_QUERY_DEVICE_RELATIONS) { DbgPrint("LIANXI:IRP_MN_QUERY_DEVICE_RELATIONS.\n"); } if( MinorFunction==IRP_MN_QUERY_CAPABILITIES) { DbgPrint("LIANXI:IRP_MN_QUERY_CAPABILITIES.\n"); } if( MinorFunction==IRP_MN_FILTER_RESOURCE_REQUIREMENTS) { DbgPrint("LIANXI:IRP_MN_FILTER_RESOURCE_REQUIREMENTS.\n"); } if( MinorFunction==IRP_MN_QUERY_PNP_DEVICE_STATE) { DbgPrint("LIANXI:IRP_MN_QUERY_PNP_DEVICE_STATE.\n"); } //处理“即插即用”次功能代码: //当Minor Function等于IRP_MN_REMOVE_DEVICE时,说明有设备被拔出或卸下,这时要取消资源分配并删除设备: if(IRP_MN_REMOVE_DEVICE==MinorFunction) { DbgPrint("LIANXI:IRP_MN_REMOVE_DEVICE.\n"); //取消设备接口: IoSetDeviceInterfaceState(&DEX->LINKNAME, FALSE); RtlFreeUnicodeString(&DEX->LINKNAME); //调用IoDetachDevice()把fdo从设备栈中脱开: if (DEX->LOWDEVICE) IoDetachDevice(DEX->LOWDEVICE); //删除fdo: IoDeleteDevice(DeviceObject); // DbgPrint("LIANXI:We have remove the device.\n"); } DbgPrint("the return status is 0x%x\n",status); //返回值: return status; // DbgPrint("the return status is 0x%x",status); } /////////////////////////////////////// lianxi.h //////////////////////////////////////// #include "wdm.h" #include "lianioctl.h" typedef struct _LIAN_DEVICE_EXTENSION { PDEVICE_OBJECT FDO; PDEVICE_OBJECT PDO; PDEVICE_OBJECT LOWDEVICE; UNICODE_STRING LINKNAME; ULONG ADD; } LIAN_DEVICE_EXTENSION, *PLIAN_DEVICE_EXTENSION; VOID lianunload(IN PDRIVER_OBJECT DriverObject); NTSTATUS liandispatch(IN PDEVICE_OBJECT FDO,IN PIRP Irp); NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PDO ); NTSTATUS lianpnphandle(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); NTSTATUS lianpower(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp); NTSTATUS lianwmi(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp); |
|
|
地板#
发布于:2004-08-04 10:19
代码已经给出,大家看看吧!
|
|
|
地下室#
发布于:2004-08-04 15:28
wowocock哪去了????
|
|
|
5楼#
发布于:2004-08-05 08:30
ding !!!!
|
|
|