Author: gedmurphy Date: Tue Jan 5 18:58:32 2016 New Revision: 70496 URL: http://svn.reactos.org/svn/reactos?rev=70496&view=rev Log: [NTOSKRNL] - Use the LockQueueIoDatabaseLock spinlock to guard the device list instead of blindly raising the IRQL - Add missing lock to IopEditDeviceList
Modified: trunk/reactos/ntoskrnl/io/iomgr/device.c Modified: trunk/reactos/ntoskrnl/io/iomgr/device.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/device.c?rev=70496&r1=70495&r2=70496&view=diff ============================================================================== --- trunk/reactos/ntoskrnl/io/iomgr/device.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/io/iomgr/device.c [iso-8859-1] Tue Jan 5 18:58:32 2016 @@ -333,6 +333,10 @@ IN IOP_DEVICE_LIST_OPERATION Type) { PDEVICE_OBJECT Previous; + KIRQL OldIrql; + + /* Lock the Device list while we edit it */ + OldIrql = KeAcquireQueuedSpinLock(LockQueueIoDatabaseLock); /* Check the type of operation */ if (Type == IopRemove) @@ -353,7 +357,12 @@ /* Not this one, keep moving */ if (!Previous->NextDevice) { - DPRINT1("Failed to remove PDO %p on driver %wZ (not found)\n", DeviceObject, &DeviceObject->DriverObject->DriverName); + DPRINT1("Failed to remove PDO %p on driver %wZ (not found)\n", + DeviceObject, + &DeviceObject->DriverObject->DriverName); + + ASSERT(FALSE); + KeReleaseQueuedSpinLock(LockQueueIoDatabaseLock, OldIrql); return; } Previous = Previous->NextDevice; @@ -369,6 +378,9 @@ DeviceObject->NextDevice = DriverObject->DeviceObject; DriverObject->DeviceObject = DeviceObject; } + + /* Release the device list lock */ + KeReleaseQueuedSpinLock(LockQueueIoDatabaseLock, OldIrql); } VOID @@ -1090,8 +1102,8 @@ PDEVICE_OBJECT CurrentDevice = DriverObject->DeviceObject; KIRQL OldIrql; - /* Raise to dispatch level */ - KeRaiseIrql(DISPATCH_LEVEL, &OldIrql); + /* Lock the Device list while we enumerate it */ + OldIrql = KeAcquireQueuedSpinLock(LockQueueIoDatabaseLock); /* Find out how many devices we'll enumerate */ while ((CurrentDevice = CurrentDevice->NextDevice)) ActualDevices++; @@ -1106,7 +1118,7 @@ if ((ActualDevices * sizeof(PDEVICE_OBJECT)) > DeviceObjectListSize) { /* Fail because the buffer was too small */ - KeLowerIrql(OldIrql); + KeReleaseQueuedSpinLock(LockQueueIoDatabaseLock, OldIrql); return STATUS_BUFFER_TOO_SMALL; } @@ -1129,8 +1141,8 @@ } } - /* Return back to previous IRQL */ - KeLowerIrql(OldIrql); + /* Release the device list lock */ + KeReleaseQueuedSpinLock(LockQueueIoDatabaseLock, OldIrql); /* Return the status */ return STATUS_SUCCESS;