diff --git a/ntoskrnl/fsrtl/fastio.c b/ntoskrnl/fsrtl/fastio.c index 03b07d95b51..87cdf1228b4 100644 --- a/ntoskrnl/fsrtl/fastio.c +++ b/ntoskrnl/fsrtl/fastio.c @@ -1571,10 +1571,10 @@ FsRtlAcquireFileExclusiveCommon(IN PFILE_OBJECT FileObject, /* Get master FsRtl lock */ FsRtlEnterFileSystem(); - DriverExtension = (PEXTENDED_DRIVER_EXTENSION)DeviceObject->DriverObject->DriverExtension; + DriverExtension = IoGetDrvObjExtension(DeviceObject->DriverObject); FilterCallbacks = DriverExtension->FsFilterCallbacks; - /* Check if Filter Cllbacks are supported */ + /* Check if Filter Callbacks are supported */ if (FilterCallbacks && FilterCallbacks->PreAcquireForSectionSynchronization) { NTSTATUS Status; @@ -2038,7 +2038,7 @@ FsRtlRegisterFileSystemFilterCallbacks( RtlCopyMemory(NewCallbacks, Callbacks, Callbacks->SizeOfFsFilterCallbacks); /* Set the callbacks in the driver extension */ - DriverExtension = (PEXTENDED_DRIVER_EXTENSION)FilterDriverObject->DriverExtension; + DriverExtension = IoGetDrvObjExtension(FilterDriverObject); DriverExtension->FsFilterCallbacks = NewCallbacks; return STATUS_SUCCESS; diff --git a/ntoskrnl/include/internal/io.h b/ntoskrnl/include/internal/io.h index f149b946f67..806bd7dd4cd 100644 --- a/ntoskrnl/include/internal/io.h +++ b/ntoskrnl/include/internal/io.h @@ -118,24 +118,23 @@ typedef struct _FILE_OBJECT_EXTENSION // Determines if the IRP is Synchronous // #define IsIrpSynchronous(Irp, FileObject) \ - ((Irp->Flags & IRP_SYNCHRONOUS_API) || \ - (!(FileObject) ? \ - FALSE : \ - FileObject->Flags & FO_SYNCHRONOUS_IO)) \ + (((Irp)->Flags & IRP_SYNCHRONOUS_API) || \ + (!(FileObject) ? FALSE : \ + (FileObject)->Flags & FO_SYNCHRONOUS_IO)) // // Returns the internal Device Object Extension // #define IoGetDevObjExtension(DeviceObject) \ ((PEXTENDED_DEVOBJ_EXTENSION) \ - (DeviceObject->DeviceObjectExtension)) \ + ((DeviceObject)->DeviceObjectExtension)) // // Returns the internal Driver Object Extension // #define IoGetDrvObjExtension(DriverObject) \ ((PEXTENDED_DRIVER_EXTENSION) \ - (DriverObject->DriverExtension)) \ + ((DriverObject)->DriverExtension)) /* * VOID diff --git a/ntoskrnl/io/iomgr/device.c b/ntoskrnl/io/iomgr/device.c index a424f23672b..bcdfa6921f3 100644 --- a/ntoskrnl/io/iomgr/device.c +++ b/ntoskrnl/io/iomgr/device.c @@ -1522,10 +1522,9 @@ IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject) /* Make sure it's not getting deleted */ DeviceExtension = IoGetDevObjExtension(DeviceObject); - if (!(DeviceExtension->ExtensionFlags & (DOE_UNLOAD_PENDING | - DOE_DELETE_PENDING | - DOE_REMOVE_PENDING | - DOE_REMOVE_PROCESSED))) + if (!(DeviceExtension->ExtensionFlags & + (DOE_UNLOAD_PENDING | DOE_DELETE_PENDING | + DOE_REMOVE_PENDING | DOE_REMOVE_PROCESSED))) { /* Get the Lower Device Object */ LowerDeviceObject = DeviceExtension->AttachedTo; diff --git a/ntoskrnl/io/iomgr/deviface.c b/ntoskrnl/io/iomgr/deviface.c index f7d55ed9796..5cfe1790234 100644 --- a/ntoskrnl/io/iomgr/deviface.c +++ b/ntoskrnl/io/iomgr/deviface.c @@ -962,7 +962,7 @@ IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, if (PhysicalDeviceObject != NULL) { /* Parameters must pass three border of checks */ - DeviceObjectExtension = (PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension; + DeviceObjectExtension = IoGetDevObjExtension(PhysicalDeviceObject); /* 1st level: Presence of a Device Node */ if (DeviceObjectExtension->DeviceNode == NULL) @@ -1463,7 +1463,7 @@ IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, PhysicalDeviceObject, ReferenceString); /* Parameters must pass three border of checks */ - DeviceObjectExtension = (PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension; + DeviceObjectExtension = IoGetDevObjExtension(PhysicalDeviceObject); /* 1st level: Presence of a Device Node */ if (DeviceObjectExtension->DeviceNode == NULL) @@ -1512,8 +1512,8 @@ IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, ASSERT(PdoNameInfo->Name.Length); /* Create base key name for this interface: HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses\{GUID} */ - ASSERT(((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode); - InstancePath = &((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode->InstancePath; + ASSERT(IoGetDevObjExtension(PhysicalDeviceObject)->DeviceNode); + InstancePath = &(IoGetDevObjExtension(PhysicalDeviceObject)->DeviceNode->InstancePath); BaseKeyName.Length = (USHORT)wcslen(BaseKeyString) * sizeof(WCHAR); BaseKeyName.MaximumLength = BaseKeyName.Length + GuidString.Length; diff --git a/ntoskrnl/io/iomgr/file.c b/ntoskrnl/io/iomgr/file.c index 865cd52fc78..1c3e55540b8 100644 --- a/ntoskrnl/io/iomgr/file.c +++ b/ntoskrnl/io/iomgr/file.c @@ -136,14 +136,12 @@ IopCheckDeviceAndDriver(IN POPEN_PACKET OpenPacket, IN PDEVICE_OBJECT DeviceObject) { /* Make sure the object is valid */ - if ((IoGetDevObjExtension(DeviceObject)->ExtensionFlags & - (DOE_UNLOAD_PENDING | - DOE_DELETE_PENDING | - DOE_REMOVE_PENDING | - DOE_REMOVE_PROCESSED)) || - (DeviceObject->Flags & DO_DEVICE_INITIALIZING)) + if ((DeviceObject->Flags & DO_DEVICE_INITIALIZING) || + (IoGetDevObjExtension(DeviceObject)->ExtensionFlags & + (DOE_UNLOAD_PENDING | DOE_DELETE_PENDING | + DOE_REMOVE_PENDING | DOE_REMOVE_PROCESSED))) { - /* It's unloading or initializing, so fail */ + /* It's initializing or unloading, so fail */ DPRINT1("You are seeing this because the following ROS driver: %wZ\n" " sucks. Please fix it's AddDevice Routine\n", &DeviceObject->DriverObject->DriverName); @@ -156,7 +154,6 @@ IopCheckDeviceAndDriver(IN POPEN_PACKET OpenPacket, { return STATUS_ACCESS_DENIED; } - else { /* Increase reference count */ @@ -1488,8 +1485,8 @@ IopGetDeviceAttachmentBase(IN PDEVICE_OBJECT DeviceObject) PDEVICE_OBJECT PDO = DeviceObject; /* Go down the stack to attempt to get the PDO */ - for (; ((PEXTENDED_DEVOBJ_EXTENSION)PDO->DeviceObjectExtension)->AttachedTo != NULL; - PDO = ((PEXTENDED_DEVOBJ_EXTENSION)PDO->DeviceObjectExtension)->AttachedTo); + while (IoGetDevObjExtension(PDO)->AttachedTo != NULL) + PDO = IoGetDevObjExtension(PDO)->AttachedTo; return PDO; } diff --git a/ntoskrnl/io/iomgr/iotimer.c b/ntoskrnl/io/iomgr/iotimer.c index 4bd8ab2ca1f..4a4437a04c5 100644 --- a/ntoskrnl/io/iomgr/iotimer.c +++ b/ntoskrnl/io/iomgr/iotimer.c @@ -136,11 +136,9 @@ IoStartTimer(IN PDEVICE_OBJECT DeviceObject) PIO_TIMER IoTimer = DeviceObject->Timer; /* Make sure the device isn't unloading */ - if (!(((PEXTENDED_DEVOBJ_EXTENSION)(DeviceObject->DeviceObjectExtension))-> - ExtensionFlags & (DOE_UNLOAD_PENDING | - DOE_DELETE_PENDING | - DOE_REMOVE_PENDING | - DOE_REMOVE_PROCESSED))) + if (!(IoGetDevObjExtension(DeviceObject)->ExtensionFlags & + (DOE_UNLOAD_PENDING | DOE_DELETE_PENDING | + DOE_REMOVE_PENDING | DOE_REMOVE_PROCESSED))) { /* Lock Timers */ KeAcquireSpinLock(&IopTimerLock, &OldIrql); diff --git a/ntoskrnl/io/pnpmgr/devnode.c b/ntoskrnl/io/pnpmgr/devnode.c index f59a3ddaf7a..6b36e587713 100644 --- a/ntoskrnl/io/pnpmgr/devnode.c +++ b/ntoskrnl/io/pnpmgr/devnode.c @@ -27,7 +27,7 @@ FASTCALL IopGetDeviceNode( _In_ PDEVICE_OBJECT DeviceObject) { - return ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode; + return IoGetDevObjExtension(DeviceObject)->DeviceNode; } PDEVICE_NODE @@ -66,7 +66,7 @@ PipAllocateDeviceNode( { /* Link it and remove the init flag */ DeviceNode->PhysicalDeviceObject = PhysicalDeviceObject; - ((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = DeviceNode; + IoGetDevObjExtension(PhysicalDeviceObject)->DeviceNode = DeviceNode; PhysicalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; } @@ -294,7 +294,7 @@ IopCreateDeviceNode( Node->PhysicalDeviceObject = PhysicalDeviceObject; - ((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = Node; + IoGetDevObjExtension(PhysicalDeviceObject)->DeviceNode = Node; if (ParentNode) { @@ -391,7 +391,7 @@ IopFreeDeviceNode( ExFreePool(DeviceNode->BootResources); } - ((PEXTENDED_DEVOBJ_EXTENSION)DeviceNode->PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode = NULL; + IoGetDevObjExtension(DeviceNode->PhysicalDeviceObject)->DeviceNode = NULL; ExFreePoolWithTag(DeviceNode, TAG_IO_DEVNODE); return STATUS_SUCCESS; diff --git a/ntoskrnl/io/pnpmgr/plugplay.c b/ntoskrnl/io/pnpmgr/plugplay.c index de28f2f06bc..807b10f5aa3 100644 --- a/ntoskrnl/io/pnpmgr/plugplay.c +++ b/ntoskrnl/io/pnpmgr/plugplay.c @@ -545,7 +545,7 @@ IopGetDeviceProperty(PPLUGPLAY_CONTROL_PROPERTY_DATA PropertyData) } - DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode; + DeviceNode = IoGetDevObjExtension(DeviceObject)->DeviceNode; if (Property == PNP_PROPERTY_POWER_DATA) { @@ -787,7 +787,7 @@ IopGetRelatedDevice(PPLUGPLAY_CONTROL_RELATED_DEVICE_DATA RelatedDeviceData) if (DeviceObject == NULL) return STATUS_NO_SUCH_DEVICE; - DeviceNode = ((PEXTENDED_DEVOBJ_EXTENSION)DeviceObject->DeviceObjectExtension)->DeviceNode; + DeviceNode = IoGetDevObjExtension(DeviceObject)->DeviceNode; } switch (Relation)