win-pvdrivers

changeset 186:145b318c367c

Fix BSoD on shutdown after updates to xenhide
author James Harper <james.harper@bendigoit.com.au>
date Thu Feb 14 16:50:10 2008 +1100 (2008-02-14)
parents e13475347e4a
children 8c87bd40fe36
files common.inc xenhide/xenhide.c xenhide/xenhide.h
line diff
     1.1 --- a/common.inc	Wed Feb 13 23:27:00 2008 +1100
     1.2 +++ b/common.inc	Thu Feb 14 16:50:10 2008 +1100
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.7.0.44
     1.5 +VERSION=0.7.0.49
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  KMDF_VERSION=1
     1.8  !IF $(_NT_TOOLS_VERSION) > 0x700
     2.1 --- a/xenhide/xenhide.c	Wed Feb 13 23:27:00 2008 +1100
     2.2 +++ b/xenhide/xenhide.c	Thu Feb 14 16:50:10 2008 +1100
     2.3 @@ -28,6 +28,8 @@ XenHide_Pass(PDEVICE_OBJECT DeviceObject
     2.4  static NTSTATUS
     2.5  XenHide_Pnp(PDEVICE_OBJECT DeviceObject, PIRP Irp);
     2.6  static NTSTATUS
     2.7 +XenHide_Power(PDEVICE_OBJECT DeviceObject, PIRP Irp);
     2.8 +static NTSTATUS
     2.9  XenHide_AddDevice();
    2.10  //static NTSTATUS
    2.11  //XenHide_Unload();
    2.12 @@ -140,8 +142,12 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    2.13  
    2.14    for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
    2.15      DriverObject->MajorFunction[i] = XenHide_Pass;
    2.16 +
    2.17 +  DriverObject->MajorFunction[IRP_MJ_POWER] = XenHide_Power;
    2.18 +
    2.19    if (AutoEnumerate)
    2.20      DriverObject->MajorFunction[IRP_MJ_PNP] = XenHide_Pnp;
    2.21 +
    2.22    DriverObject->DriverExtension->AddDevice = XenHide_AddDevice;
    2.23  
    2.24    KdPrint((__DRIVER_NAME " <-- DriverEntry\n"));
    2.25 @@ -205,7 +211,7 @@ XenHide_AddDevice(
    2.26    DeviceObject->Characteristics = 
    2.27      DeviceExtension->NextLowerDevice->Characteristics;
    2.28  
    2.29 -  //INITIALIZE_PNP_STATE(DeviceExtension);
    2.30 +  IoInitializeRemoveLock(&DeviceExtension->RemoveLock, XENHIDE_POOL_TAG, 1, 100);
    2.31  
    2.32    if (AutoEnumerate)
    2.33    {
    2.34 @@ -337,6 +343,8 @@ XenHide_IoCompletion(PDEVICE_OBJECT Devi
    2.35        
    2.36          deviceObject->Characteristics = 
    2.37            NewDeviceExtension->NextLowerDevice->Characteristics;
    2.38 +
    2.39 +        IoInitializeRemoveLock(&NewDeviceExtension->RemoveLock, XENHIDE_POOL_TAG, 1, 100);
    2.40        
    2.41          NewDeviceExtension->Self = deviceObject;
    2.42          NewDeviceExtension->Type = XENHIDE_TYPE_HIDE;
    2.43 @@ -359,7 +367,13 @@ XenHide_Pass(PDEVICE_OBJECT DeviceObject
    2.44  {
    2.45    PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
    2.46    NTSTATUS Status;
    2.47 -    
    2.48 +
    2.49 +  Status = IoAcquireRemoveLock (&DeviceExtension->RemoveLock, Irp);
    2.50 +  if (!NT_SUCCESS(Status)) {
    2.51 +    Irp->IoStatus.Status = Status;
    2.52 +    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    2.53 +    return Status;
    2.54 +  }
    2.55    if (DeviceExtension->Type == XENHIDE_TYPE_HIDE)
    2.56    {
    2.57      Irp->IoStatus.Status = Status = STATUS_UNSUCCESSFUL;
    2.58 @@ -371,6 +385,28 @@ XenHide_Pass(PDEVICE_OBJECT DeviceObject
    2.59      IoSkipCurrentIrpStackLocation(Irp);
    2.60      Status = IoCallDriver(DeviceExtension->NextLowerDevice, Irp);
    2.61    }
    2.62 +  IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp); 
    2.63 +  return Status;
    2.64 +}
    2.65 +
    2.66 +static NTSTATUS
    2.67 +XenHide_Power(PDEVICE_OBJECT DeviceObject, PIRP Irp)
    2.68 +{
    2.69 +  NTSTATUS Status = STATUS_SUCCESS;
    2.70 +  PDEVICE_EXTENSION DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
    2.71 +
    2.72 +  Status = IoAcquireRemoveLock (&DeviceExtension->RemoveLock, Irp);
    2.73 +  if (!NT_SUCCESS(Status)) {
    2.74 +    Irp->IoStatus.Status = Status;
    2.75 +    PoStartNextPowerIrp(Irp);
    2.76 +    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    2.77 +    return Status;
    2.78 +  }
    2.79 +
    2.80 +  PoStartNextPowerIrp(Irp);
    2.81 +  IoSkipCurrentIrpStackLocation(Irp);
    2.82 +  Status = PoCallDriver(DeviceExtension->NextLowerDevice, Irp);
    2.83 +  IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp); 
    2.84    return Status;
    2.85  }
    2.86  
    2.87 @@ -385,6 +421,14 @@ XenHide_Pnp(PDEVICE_OBJECT DeviceObject,
    2.88    KdPrint((__DRIVER_NAME "     DeviceObject = %p\n", DeviceObject));
    2.89    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    2.90  
    2.91 +  Status = IoAcquireRemoveLock (&DeviceExtension->RemoveLock, Irp);
    2.92 +  if (!NT_SUCCESS(Status)) {
    2.93 +    Irp->IoStatus.Status = Status;
    2.94 +    IoCompleteRequest(Irp, IO_NO_INCREMENT);
    2.95 +    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", Status));
    2.96 +    return Status;
    2.97 +  }
    2.98 +
    2.99    Stack = IoGetCurrentIrpStackLocation(Irp);
   2.100  
   2.101    switch (Stack->MinorFunction)
   2.102 @@ -495,6 +539,7 @@ XenHide_Pnp(PDEVICE_OBJECT DeviceObject,
   2.103      {
   2.104      case IRP_MN_START_DEVICE:
   2.105      case IRP_MN_STOP_DEVICE:
   2.106 +    case IRP_MN_REMOVE_DEVICE:
   2.107        Irp->IoStatus.Status = Status = STATUS_SUCCESS;
   2.108        break;
   2.109      case IRP_MN_QUERY_PNP_DEVICE_STATE:
   2.110 @@ -526,6 +571,8 @@ XenHide_Pnp(PDEVICE_OBJECT DeviceObject,
   2.111  */
   2.112      break;
   2.113    }
   2.114 +
   2.115 +  IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp); 
   2.116    
   2.117    KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ " (returning with status %08x)\n", Status));
   2.118  
     3.1 --- a/xenhide/xenhide.h	Wed Feb 13 23:27:00 2008 +1100
     3.2 +++ b/xenhide/xenhide.h	Thu Feb 14 16:50:10 2008 +1100
     3.3 @@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fi
     3.4  
     3.5  #define __DRIVER_NAME "XenHide"
     3.6  
     3.7 +#define XENHIDE_POOL_TAG (ULONG) 'XHID'
     3.8 +
     3.9  //{CD433FE7-954F-4D51-BE29-D8A38DFA1108}
    3.10  DEFINE_GUID(GUID_XENHIDE_IFACE, 0xCD433FE7, 0x954F, 0x4D51, 0xBE, 0x29, 0xD8, 0xA3, 0x8D, 0xFA, 0x11, 0x08);
    3.11  
    3.12 @@ -39,8 +41,8 @@ DEFINE_GUID(GUID_XENHIDE_IFACE, 0xCD433F
    3.13  struct _DEVICE_EXTENSION {
    3.14    PDEVICE_OBJECT Self;
    3.15    PDRIVER_OBJECT DriverObject;
    3.16 -  BOOLEAN SeenQueryDeviceRelations;
    3.17    PDEVICE_OBJECT NextLowerDevice;
    3.18 +  IO_REMOVE_LOCK RemoveLock;
    3.19    UNICODE_STRING InterfaceName;
    3.20    ULONG Type;
    3.21    ULONG CallCount;