chapter 5.4: 创建对象
来源:互联网 发布:c 网络验证源码 编辑:程序博客网 时间:2024/06/05 07:42
KMDF:先初始化object attributes structure和object configuration structure,再调用create方法
创建UMDF对象
UMDF对每种object提供了不同的创建方法:device, file, I/O request, memory, queue object,过程:
1. 若driver对某个object支持callback,则新分配一个对应的callback object
2. 创建对应的object,并关联callback object
对象的创建方法需要callback object的IUnknown interface来确定callback object支持那种callback interface
Fx2_Driver的ControlQueue.cpp的创建一个queue object的代码:
queue = new CMyControlQueue(Device); . . . //Code omittedIUnknown *callback = QueryIUnknown();hr = m_Device->GetFxDevice()->CreateIoQueue( callback, Default, DispatchType, PowerManaged, FALSE, &fxQueue );callback->Release();if (FAILED(hr)) { . . . //Error handling omitted; }fxQueue->Release();代码中create的参数:callback object interface指针,四个queue-specific参数,和一个指向变量的指针(接收IWDFIoQueue interface的地址)
driver然后释放了由QueryIUnknown在IUnknown interface中获取的引用,这是由于framework device object已经维护了它的引用
driver释放了CreateIoQueue使用的fxQueue object的引用,这是由于framework object tree已经维护了该对象的引用
创建KMDF对象
过程:
1.按需要初始化configuration structure
2.按需要初始化sttribute structure
3.调用创建方法
KMDF object configuration structure
名称:WDF_[Object]_CONFIG, 维护驱动对该对象的event callback function指针,及其他内容
KMDF定义了WDF_[Object]_CONFIG_INIT来初始化configuration structure,但不是所有object都具有configuration以及init函数
KMDF Object Attribute structure
*不是所有的参数都能应用在所有对象上
Field
Description
ContextSizeOverride
Size of the context area, which overrides the value in ContextTypeInfo>ContextSize. This field is useful for context areas that have variable sizes.
ContextTypeInfo
Pointer to the type information for the object context area.
EvtCleanupCallback
Pointer to a callback routine that is invoked to clean up the object before it is deleted. The object might still have references.
EvtDestroyCallback
Pointer to a callback routine that is invoked when the reference count reaches zero for an object that is marked for deletion.
ExecutionLevel
Maximum IRQL at which KMDF can invoke certain object callbacks.
ParentObject
Handle for the object's parent.
Size
Size of the structure in bytes.
SynchronizationScope
Level at which certain callbacks for this object are synchronized. This field applies only to driver, device, and file objects.
名称:WDF_OBJECT_ATTRIBUTES函数:
WDF_OBJECT_ATTRIBUTES_INIT:设置了关于同步和执行级别的变量(哪些callback可以同步调用,它们最高的IRQL级别,默认为父对象的配置)
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(设置了object context area信息)
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(设置了object context area信息)
可以使用参数默认值:driver定义的WDF_NO_OBJECT_ATTRIBUTES,即WDF定义的NULL。若driver定义了context area,则必须设置参数
KMDF对象创建方法
命名:Wdf[Object]Create 返回handle
处理过程:
1.为object和context area分配**nonpaged pool**
2.初始化对象attributes
3.为对象context area清零
4.配置对象:保存event callback指针,及其他属性
若处理失败,framework会删除对象
示例代码:Osrusbfx2 driver的Device.c
NTSTATUS status = STATUS_SUCCESS;WDFDEVICE device;WDF_IO_QUEUE_CONFIG ioQueueConfig;WDF_IO_QUEUE_CONFIG_INIT(&ioQueueConfig, WdfIoQueueDispatchSequential);ioQueueConfig.EvtIoRead = OsrFxEvtIoRead;ioQueueConfig.EvtIoStop = OsrFxEvtIoStop;status = WdfIoQueueCreate( device, &ioQueueConfig, WDF_NO_OBJECT_ATTRIBUTES, &queue // queue handle );if (!NT_SUCCESS (status)) { . . . //Error handling omitted}图解:
代码创建了一个queue object
1.通过WDF_IO_QUEUE_CONFIG_INIT初始化configuration structure,向它传递一个如何分配请求的参数。
2.在configuration structure中注册event callback
3.由于没有设置其他object attribute,所以不需要初始化attribute structure
4.最终调用WdfIoQueueCreate创建对象。参数如下:
1.queue相关的device handle
2.指向初始化过的queue configuration structure指针
3.WDF_NO_OBJECT_ATTRIBUTE常数,默认的参数。
4.一个方法返回queue一个handle的location
要通过annotate callback function来帮助SDV进行编译分析
- chapter 5.4: 创建对象
- chapter 6.6: UMDF 设备对象的创建和初始化
- chapter 6.7: KMDF设备对象的创建和初始化
- effective Java chapter 2创建和销毁对象
- chapter 3: 内核对象
- chapter 6.2: 驱动对象
- Chapter 6面向对象
- Chapter 03 - 面向对象
- Chapter 4 类与对象
- Chapter 2 类与对象
- Chapter 25.面向对象编程
- chapter 3.3: WDF对象模型
- chapter 9.3: 创建I/O request
- Chapter 6 创建云的入口
- chapter 5.2: UMDF对象模型的实现
- chapter 5.3: KMDF对象模型实现
- chapter 5.5: 对象层次及生命周期
- chapter 6.4: Queue和其他支持对象
- UVa 10487 - Closest Sums
- xml做mysql的配置文件及php对配置文件信息的读取 连接数据库
- C++程序设计-第2周结构体应用
- HBase Block Cache实现机制分析
- [翻译]ACMer 2013 Daily Training- 2nd Mar for 11x&&12x
- chapter 5.4: 创建对象
- 用PHP 通过DOM方式创建一个book.xml文件
- Merkel Tree在BitTorren中的应用
- 正则表达式笔记
- 上班第二周
- vim最基本的命令
- POJ3087--Shuffle'm Up
- linux脚本判断条件总结
- PHP DOS cli 模式运行