博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IoAttachDevice源码
阅读量:5984 次
发布时间:2019-06-20

本文共 4277 字,大约阅读时间需要 14 分钟。

IoAttachDevice调用了IoAttachDeviceToDeviceStackSafe,

IoAttachDevice调用了IoAttachDeviceToDeviceStack

IoAttachDeviceToDeviceStack调用了IopAttachDeviceToDeviceStackSafe

IoAttachDeviceToDeviceStackSafe调用了IopAttachDeviceToDeviceStackSafe

 

IopAttachDeviceToDeviceStackSafe的代码为:

PDEVICE_OBJECTIopAttachDeviceToDeviceStackSafe(    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 device    object and returns a pointer to the actual device attached to, if    successful.Arguments:    SourceDevice - Specifies the device object that is to be attached to        the target device.    TargetDevice - Specifies the device object to which the attachment is        to occur.    AttachedToDeviceObject - Specifies a pointer  where the attached to device object        is stored. Its updated while holding the database lock so that when a filter gets an IRP        its attached to device object field is updated correctly.Return Value:    If successful, this function returns a pointer to the device object to    which the attachment actually occurred.    If unsuccessful, this function returns NULL.  (This could happen if the    device 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

你可能感兴趣的文章
分布式系统唯一ID生成方案汇总【转】
查看>>
并查集hdu1232
查看>>
Mysql 监视工具
查看>>
博客搬家了
查看>>
Python中使用ElementTree解析xml
查看>>
linux的日志服务器关于屏蔽一些关键字的方法
查看>>
mysql多实例实例化数据库
查看>>
javascript 操作DOM元素样式
查看>>
HBase 笔记3
查看>>
【Linux】Linux 在线安装yum
查看>>
Atom 编辑器系列视频课程
查看>>
[原][osgearth]osgearthviewer读取earth文件,代码解析(earth文件读取的一帧)
查看>>
通过IP判断登录地址
查看>>
深入浅出JavaScript (五) 详解Document.write()方法
查看>>
Beta冲刺——day6
查看>>
代码生成工具Database2Sharp中增加视图的代码生成以及主从表界面生成功能
查看>>
我的友情链接
查看>>
IDE---Python IDE之Eric5在window下的安装
查看>>
基本安装lnmp环境
查看>>
logstash消费阿里云kafka消息
查看>>