WRK的IoDeleteDevice源码 原本想解读一下 IoDeleteDevice 但发现实际上会调用 IovDeleteDevice 但没有找到IovDeleteDevice 相关的代码 那就暂时搁置 回头具体分析
VOID
IoDeleteDevice(
IN PDEVICE_OBJECT DeviceObject
)
/*++
Routine Description:
This routine deletes the specified device object from the system so that
it may no longer be referenced. It is invoked when either the device
driver is being unloaded from the system, or the driver's initialization
routine failed to properly initialize the device or a fatal driver
initialization error was encountered, or when the device is being removed
from the system.
Arguments:
DeviceObject - Pointer to the device object that is to be deleted.
Return Value:
None.
--*/
{
KIRQL irql;
IOV_DELETE_DEVICE(DeviceObject);
//
// Check to see whether or not the device has registered a shutdown
// handler if necessary, and if so, unregister it.
//
if (DeviceObject->Flags & DO_SHUTDOWN_REGISTERED) {
IoUnregisterShutdownNotification( DeviceObject );
}
//
// Release the pool that was allocated to contain the timer dispatch
// routine and its associated context if there was one.
//
if (DeviceObject->Timer) {
PIO_TIMER timer;
timer = DeviceObject->Timer;
IopRemoveTimerFromTimerList(timer);
ExFreePool( timer );
}
//
// If this device has a name, then mark the
// object as temporary so that when it is dereferenced it will be
// deleted.
//
if (DeviceObject->Flags & DO_DEVICE_HAS_NAME) {
ObMakeTemporaryObject( DeviceObject );
}
//
// PoRunDownDeviceObject will clean up any power management
// structures attached to the device object.
//
PoRunDownDeviceObject(DeviceObject);
//
// Mark the device object as deleted.
//
irql = KeAcquireQueuedSpinLock( LockQueueIoDatabaseLock );
DeviceObject->DeviceObjectExtension->ExtensionFlags |= DOE_DELETE_PENDING;
if (!DeviceObject->ReferenceCount) {
IopCompleteUnloadOrDelete( DeviceObject, FALSE, irql );
} else {
KeReleaseQueuedSpinLock( LockQueueIoDatabaseLock, irql );
}
}