PLIST_ENTRY Next = ListEntry->Flink;
PXENFILT_DX Dx = CONTAINING_RECORD(ListEntry, XENFILT_DX, ListEntry);
PXENFILT_PDO Pdo = Dx->Pdo;
- BOOLEAN Missing;
- Missing = TRUE;
for (Index = 0; Index < Count; Index++) {
if (PdoGetPhysicalDeviceObject(Pdo) == PhysicalDeviceObject[Index]) {
- Missing = FALSE;
-#pragma prefast(suppress:6387) // PhysicalDeviceObject[Index] could be NULL
- ObDereferenceObject(PhysicalDeviceObject[Index]);
PhysicalDeviceObject[Index] = NULL; // avoid duplication
break;
}
}
- if (Missing &&
- !PdoIsMissing(Pdo) &&
- PdoGetDevicePnpState(Pdo) != Deleted) {
- PdoSetMissing(Pdo, "device disappeared");
-
- // If the PDO has not yet been enumerated then we can go ahead
- // and mark it as deleted, otherwise we need to notify PnP manager and
- // wait for the REMOVE_DEVICE IRP.
- if (PdoGetDevicePnpState(Pdo) == Present) {
- PdoSetDevicePnpState(Pdo, Deleted);
- PdoDestroy(Pdo);
- }
- }
-
ListEntry = Next;
}
// Walk the list and create PDO filters for any new devices
for (Index = 0; Index < Count; Index++) {
#pragma warning(suppress:6385) // Reading invalid data from 'PhysicalDeviceObject'
- if (PhysicalDeviceObject[Index] != NULL) {
+ if (PhysicalDeviceObject[Index] != NULL)
(VOID) FdoAddDevice(Fdo, PhysicalDeviceObject[Index]);
- ObDereferenceObject(PhysicalDeviceObject[Index]);
- }
}
__FdoReleaseMutex(Fdo);
KEVENT Event;
PIO_STACK_LOCATION StackLocation;
ULONG Size;
+ PDEVICE_RELATIONS LowerRelations;
PDEVICE_RELATIONS Relations;
- PLIST_ENTRY ListEntry;
XENFILT_FILTER_STATE State;
ULONG Count;
NTSTATUS status;
if (StackLocation->Parameters.QueryDeviceRelations.Type != BusRelations)
goto done;
- Relations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
-
- if (Relations->Count != 0)
- FdoEnumerate(Fdo, Relations);
+ LowerRelations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
- ExFreePool(Relations);
-
- __FdoAcquireMutex(Fdo);
+ if (LowerRelations->Count != 0)
+ FdoEnumerate(Fdo, LowerRelations);
State = DriverGetFilterState();
- Count = 0;
- if (State == XENFILT_FILTER_DISABLED) {
- for (ListEntry = Fdo->List.Flink;
- ListEntry != &Fdo->List;
- ListEntry = ListEntry->Flink)
- Count++;
- }
+ Count = (State == XENFILT_FILTER_DISABLED) ? LowerRelations->Count : 0;
Size = FIELD_OFFSET(DEVICE_RELATIONS, Objects) +
(sizeof (PDEVICE_OBJECT) * __max(Count, 1));
goto fail3;
if (State == XENFILT_FILTER_DISABLED) {
- for (ListEntry = Fdo->List.Flink;
- ListEntry != &Fdo->List;
- ListEntry = ListEntry->Flink) {
- PXENFILT_DX Dx = CONTAINING_RECORD(ListEntry, XENFILT_DX, ListEntry);
- PXENFILT_PDO Pdo = Dx->Pdo;
-
- ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
-
- if (PdoGetDevicePnpState(Pdo) == Present)
- PdoSetDevicePnpState(Pdo, Enumerated);
-
- ObReferenceObject(PdoGetPhysicalDeviceObject(Pdo));
- Relations->Objects[Relations->Count++] = PdoGetPhysicalDeviceObject(Pdo);
- }
-
- ASSERT3U(Relations->Count, <=, Count);
+ ASSERT3U(Count, ==, LowerRelations->Count);
+ RtlCopyMemory(Relations, LowerRelations, Size);
Trace("%s: %d PDO(s)\n",
__FdoGetName(Fdo),
Relations->Count);
} else {
+ ULONG Index;
+
Trace("%s: FILTERED\n",
__FdoGetName(Fdo));
+ for (Index = 0; Index < LowerRelations->Count; Index++)
+ ObDereferenceObject(LowerRelations->Objects[Index]);
+
IoInvalidateDeviceRelations(__FdoGetPhysicalDeviceObject(Fdo),
BusRelations);
}
- __FdoReleaseMutex(Fdo);
+ ExFreePool(LowerRelations);
Irp->IoStatus.Information = (ULONG_PTR)Relations;
status = STATUS_SUCCESS;
return status;
fail3:
- __FdoReleaseMutex(Fdo);
+ Error("fail3\n");
fail2:
+ Error("fail2\n");
+
IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
fail1:
+ Error("fail1 (%08x)\n", status);
+
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
PIRP DevicePowerIrp;
PXENFILT_FDO Fdo;
- BOOLEAN Missing;
- const CHAR *Reason;
XENFILT_EMULATED_OBJECT_TYPE Type;
PXENFILT_EMULATED_OBJECT EmulatedObject;
return Pdo->PhysicalDeviceObject;
}
-static FORCEINLINE VOID
-__PdoSetMissing(
- IN PXENFILT_PDO Pdo,
- IN const CHAR *Reason
- )
-{
- Pdo->Reason = Reason;
- Pdo->Missing = TRUE;
-}
-
-VOID
-PdoSetMissing(
- IN PXENFILT_PDO Pdo,
- IN const CHAR *Reason
- )
-{
- __PdoSetMissing(Pdo, Reason);
-}
-
-static FORCEINLINE BOOLEAN
-__PdoIsMissing(
- IN PXENFILT_PDO Pdo
- )
-{
- return Pdo->Missing;
-}
-
-BOOLEAN
-PdoIsMissing(
- IN PXENFILT_PDO Pdo
- )
-{
- return __PdoIsMissing(Pdo);
-}
-
static FORCEINLINE PDEVICE_OBJECT
__PdoGetDeviceObject(
IN PXENFILT_PDO Pdo
__PdoSetDevicePowerState(Pdo, PowerDeviceD3);
done:
- if (__PdoIsMissing(Pdo)) {
- __PdoSetDevicePnpState(Pdo, Deleted);
- IoReleaseRemoveLockAndWait(&Pdo->Dx->RemoveLock, Irp);
- } else {
- __PdoSetDevicePnpState(Pdo, Enumerated);
- IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
- }
+ FdoAcquireMutex(Fdo);
+ __PdoSetDevicePnpState(Pdo, Deleted);
+ FdoReleaseMutex(Fdo);
+
+ IoReleaseRemoveLockAndWait(&Pdo->Dx->RemoveLock, Irp);
status = PdoForwardIrpSynchronously(Pdo, Irp);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
- if (__PdoIsMissing(Pdo)) {
- FdoAcquireMutex(Fdo);
- PdoDestroy(Pdo);
- FdoReleaseMutex(Fdo);
- }
+ FdoAcquireMutex(Fdo);
+ PdoDestroy(Pdo);
+ FdoReleaseMutex(Fdo);
return status;
PXENFILT_FDO Fdo = __PdoGetFdo(Pdo);
NTSTATUS status;
- __PdoSetMissing(Pdo, "Ejected");
__PdoSetDevicePnpState(Pdo, Deleted);
status = PdoForwardIrpSynchronously(Pdo, Irp);
ASSERT3U(__PdoGetDevicePnpState(Pdo), ==, Deleted);
- ASSERT(__PdoIsMissing(Pdo));
- Pdo->Missing = FALSE;
-
FdoRemovePhysicalDeviceObject(Fdo, Pdo);
Dx->Pdo = NULL;
- Info("%p (%s) (%s)\n",
+ Info("%p (%s)\n",
FilterDeviceObject,
- __PdoGetName(Pdo),
- Pdo->Reason);
- Pdo->Reason = NULL;
+ __PdoGetName(Pdo));
RtlZeroMemory(Pdo->Name, sizeof (Pdo->Name));