IoCreateDevice(): Fixed missing initialization of 'CreatedDeviceObject->Vpb'
[reactos.git] / ntoskrnl / io / device.c
index 6e8b696..40551eb 100644 (file)
@@ -76,9 +76,15 @@ IoDeleteDevice(PDEVICE_OBJECT DeviceObject)
 #endif /* !LIBCAPTIVE */
        }
 
+#ifndef LIBCAPTIVE
+       /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+        * Undocumented by W32!
+        * See also IoCreateDevice().
+        */
        /* free device extension */
        if (DeviceObject->DeviceObjectExtension)
                ExFreePool (DeviceObject->DeviceObjectExtension);
+#endif /* LIBCAPTIVE */
 
        /* remove device from driver device list */
        Previous = DeviceObject->DriverObject->DeviceObject;
@@ -626,6 +632,12 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
    
    assert_irql(PASSIVE_LEVEL);
    
+   assert(sizeof(CreatedDeviceObject->Queue.Wcb) == 40);
+   assert(sizeof(CreatedDeviceObject->DeviceQueue) == 20);
+   assert(sizeof(CreatedDeviceObject->Dpc) == 32);
+   assert(sizeof(CreatedDeviceObject->DeviceLock) == 16);
+   assert(sizeof(DEVICE_OBJECT) == 184);
+
    if (DeviceName != NULL)
      {
        DPRINT("IoCreateDevice(DriverObject %x, DeviceName %S)\n",DriverObject,
@@ -636,6 +648,15 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
        DPRINT("IoCreateDevice(DriverObject %x)\n",DriverObject);
      }
    
+#ifdef LIBCAPTIVE
+   /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+    * Undocumented by W32!
+    * See also IoDeleteDevice().
+    */
+   /* TODO:thread */
+   IoDeviceObjectType->NonpagedPoolCharge = sizeof (DEVICE_OBJECT) + DeviceExtensionSize;
+#endif /* LIBCAPTIVE */
+
    if (DeviceName != NULL)
      {
        InitializeObjectAttributes(&ObjectAttributes,DeviceName,0,NULL,NULL);
@@ -654,6 +675,15 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
                                (PVOID*)&CreatedDeviceObject);
      }
    
+#ifdef LIBCAPTIVE
+   /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+    * Undocumented by W32!
+    * See also IoDeleteDevice().
+    */
+   /* TODO:thread */
+   IoDeviceObjectType->NonpagedPoolCharge = sizeof (DEVICE_OBJECT);    /* restore */
+#endif /* LIBCAPTIVE */
+
    *DeviceObject = NULL;
    
    if (!NT_SUCCESS(Status))
@@ -680,10 +710,20 @@ IoCreateDevice(PDRIVER_OBJECT DriverObject,
   CreatedDeviceObject->CurrentIrp = NULL;
   CreatedDeviceObject->Flags = 0;
   CreatedDeviceObject->Characteristics = DeviceCharacteristics;
+  CreatedDeviceObject->Timer = NULL;
+  CreatedDeviceObject->Vpb = NULL;
 
+#ifndef LIBCAPTIVE
   CreatedDeviceObject->DeviceExtension = 
     ExAllocatePoolWithTag(NonPagedPool, DeviceExtensionSize,
                          TAG_DEVICE_EXTENSION);
+#else /* !LIBCAPTIVE */
+  /* W32 expects CreatedDeviceObject->DeviceExtension to follow *CreatedDeviceObject!
+   * Undocumented by W32!
+   * See also IoDeleteDevice().
+   */
+  CreatedDeviceObject->DeviceExtension = (void *)(CreatedDeviceObject+1);
+#endif /* LIBCAPTIVE */
   if (DeviceExtensionSize > 0 && CreatedDeviceObject->DeviceExtension == NULL)
     {
       ExFreePool(CreatedDeviceObject);