日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IoAttachDevice源码

發布時間:2025/5/22 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IoAttachDevice源码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

IoAttachDevice調用了IoAttachDeviceToDeviceStackSafe,

IoAttachDevice調用了IoAttachDeviceToDeviceStack

IoAttachDeviceToDeviceStack調用了IopAttachDeviceToDeviceStackSafe

IoAttachDeviceToDeviceStackSafe調用了IopAttachDeviceToDeviceStackSafe

?

IopAttachDeviceToDeviceStackSafe的代碼為:

PDEVICE_OBJECT IopAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice,IN PDEVICE_OBJECT TargetDevice,OUT PDEVICE_OBJECT *AttachedToDeviceObject OPTIONAL)/*++Routine Description:This routine attaches the source device object to the target deviceobject and returns a pointer to the actual device attached to, ifsuccessful.Arguments:SourceDevice - Specifies the device object that is to be attached tothe target device.TargetDevice - Specifies the device object to which the attachment isto occur.AttachedToDeviceObject - Specifies a pointer where the attached to device objectis stored. Its updated while holding the database lock so that when a filter gets an IRPits attached to device object field is updated correctly.Return Value:If successful, this function returns a pointer to the device object towhich the attachment actually occurred.If unsuccessful, this function returns NULL. (This could happen if thedevice currently at the top of the attachment chain is being unloaded,deleted or initialized.)--*/{PDEVICE_OBJECT deviceObject;PDEVOBJ_EXTENSION sourceExtension;KIRQL irql;//// Retrieve a pointer to the source device object's extension outside// of the IopDatabaseLock, since it isn't protected by that.// sourceExtension = SourceDevice->DeviceObjectExtension;//// Get a pointer to the topmost device object in the stack of devices,// beginning with the TargetDevice, and attach to it.// irql = KeAcquireQueuedSpinLock( LockQueueIoDatabaseLock );//// Tell the Special IRP code the stack has changed. Code that will reexamine// the stack takes the database lock, so we can place the call here. This// also allows us to assert correct behavior *before* the stack is built up.// IOV_ATTACH_DEVICE_TO_DEVICE_STACK(SourceDevice, TargetDevice);deviceObject = IoGetAttachedDevice( TargetDevice );//// Make sure that the SourceDevice object isn't already attached to// something else, this is now illegal.// ASSERT( sourceExtension->AttachedTo == NULL );//// Now attach to the device, provided that it is not being unloaded,// deleted or initializing.// if (deviceObject->Flags & DO_DEVICE_INITIALIZING ||deviceObject->DeviceObjectExtension->ExtensionFlags &(DOE_UNLOAD_PENDING | DOE_DELETE_PENDING | DOE_REMOVE_PENDING | DOE_REMOVE_PROCESSED)) {//// The device currently at the top of the attachment chain is being// unloaded, deleted or initialized.// deviceObject = (PDEVICE_OBJECT) NULL;} else {//// Perform the attachment. First update the device previously at the// top of the attachment chain.// deviceObject->AttachedDevice = SourceDevice;deviceObject->Spare1++;//// Now update the new top-of-attachment-chain.// SourceDevice->StackSize = (UCHAR) (deviceObject->StackSize + 1);SourceDevice->AlignmentRequirement = deviceObject->AlignmentRequirement;SourceDevice->SectorSize = deviceObject->SectorSize;if (deviceObject->DeviceObjectExtension->ExtensionFlags & DOE_START_PENDING) {SourceDevice->DeviceObjectExtension->ExtensionFlags |= DOE_START_PENDING;}//// Attachment chain is doubly-linked.// sourceExtension->AttachedTo = deviceObject;}//// Atomically update this field inside the lock.// The caller has to ensure that this location is in non-paged pool.// This is required so that a filesystem filter can attach to a device and before it// gets an IRP it can update its lower device object pointer.// if (AttachedToDeviceObject) {*AttachedToDeviceObject = deviceObject;}KeReleaseQueuedSpinLock( LockQueueIoDatabaseLock, irql );return deviceObject; }

轉載于:https://www.cnblogs.com/stonehat/archive/2012/07/20/2601799.html

總結

以上是生活随笔為你收集整理的IoAttachDevice源码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。