鱼C论坛

 找回密码
 立即注册
查看: 3397|回复: 1

理解驱动对象(DriverObject)

[复制链接]
发表于 2015-3-30 20:05:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
        每个驱动程序都会有唯一一个驱动对象表示,驱动对象是对驱动程序的实例化。她由Ring0层的执行体组件中的IO管理器负责加载,并且每个驱动只加载一个实例。在wdm.h头文件中。DriverObject结构如下:
  1. typedef struct _DRIVER_OBJECT {
  2.     CSHORT Type;
  3.     CSHORT Size;

  4.     //
  5.     // The following links all of the devices created by a single driver
  6.     // together on a list, and the Flags word provides an extensible flag
  7.     // location for driver objects.
  8.     //

  9.     PDEVICE_OBJECT DeviceObject;
  10.     ULONG Flags;

  11.     //
  12.     // The following section describes where the driver is loaded.  The count
  13.     // field is used to count the number of times the driver has had its
  14.     // registered reinitialization routine invoked.
  15.     //

  16.     PVOID DriverStart;
  17.     ULONG DriverSize;
  18.     PVOID DriverSection;
  19.     PDRIVER_EXTENSION DriverExtension;

  20.     //
  21.     // The driver name field is used by the error log thread
  22.     // determine the name of the driver that an I/O request is/was bound.
  23.     //

  24.     UNICODE_STRING DriverName;

  25.     //
  26.     // The following section is for registry support.  Thise is a pointer
  27.     // to the path to the hardware information in the registry
  28.     //

  29.     PUNICODE_STRING HardwareDatabase;

  30.     //
  31.     // The following section contains the optional pointer to an array of
  32.     // alternate entry points to a driver for "fast I/O" support.  Fast I/O
  33.     // is performed by invoking the driver routine directly with separate
  34.     // parameters, rather than using the standard IRP call mechanism.  Note
  35.     // that these functions may only be used for synchronous I/O, and when
  36.     // the file is cached.
  37.     //

  38.     PFAST_IO_DISPATCH FastIoDispatch;

  39.     //
  40.     // The following section describes the entry points to this particular
  41.     // driver.  Note that the major function dispatch table must be the last
  42.     // field in the object so that it remains extensible.
  43.     //

  44.     PDRIVER_INITIALIZE DriverInit;
  45.     PDRIVER_STARTIO DriverStartIo;
  46.     PDRIVER_UNLOAD DriverUnload;
  47.     PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1];

  48. } DRIVER_OBJECT;
复制代码

DeviceObject:每个驱动会有一个或者多个设备对象。这些设备对象通过链表的方式组织。每个设备对象有一nextDevice的指针指向链表的下一个设备对象。但是注意:驱动对象里面的这个DeviceObject相当设备链表的头节点。他指向的是:本驱动程序自己创建的第一个设备对象。
DriverName:驱动的名字
DriverStartIO:处理多个irp的时候。需要这个来序列化。
DriverUnload:卸载驱动的时候的回调函数。
Driverextension:驱动的扩展。和设备的扩展差不多。
majorFunction:IRP派遣函数。这个感觉也相当于回调。只不过是向操作系统注册IRP的处理函数。
Flag:标志位。


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-4-13 10:24:37 | 显示全部楼层
好文章顶下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-26 01:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表