한 걸음씩..

[Device Driver] Device Object 자료구조 본문

프로그래밍

[Device Driver] Device Object 자료구조

반엘 2013. 9. 5. 09:30


       Device Object 


Driver는 자신이 참여하는 모든 Device Stack을 위해서 DeviceObject를 생성하게 된다

생성된 모든 Driver의 DeviceObject는 Driver의 DriverObject를 통해 모두 찾을 수 있다.


1. DriverObject->DeviceObject  // 가장 최근에 드라이버가 생성한 DeviceObject


2. DriverObject->DeviceObject->NextDevice  //1의 DeviceObject 보다 바로 전에 생성했던 DeviceObject


3. DriverObject->DeviceObject->NextDevice->NextDevice  //2의 DeviceObject 보다 바로 전에 생성했던 DeviceObject




       Device Object 자료구조




typedef struct _DEVICE_OBJECT {

CSHORT Type;

USHORT Size;

LONG ReferenceCount;

// DDEVICE_OBJECT를 생성한 드라이버의 DriverObject

struct _DRIVER_OBJECT  *DriverObject;

// 같은 드라이버에 의해서 생성된 다른 DeviceObject를 가리키는 포인터

struct _DEVICE_OBJECT  *NextDevice;

// 현재 DeviceObject와 같이 속해있는 상위의 DeviceObject 포인터

struct _DEVICE_OBJECT  *AttachedDevice; 

// DriverStartIo 루틴이 처리중인 Irp를 기억하는 곳

struct _IRP  *CurrentIrp;

PIO_TIMER Timer;

ULONG Flags;

ULONG Characteristics;

__volatile PVPB Vpb;

PVOID DeviceExtension;

DEVICE_TYPE DeviceType;

// 현재 DeviceObject가 포함된 디바이스 스택상에서 자신의 위치

CCHAR StackSize;

union {

LIST_ENTRY ListEntry;

WAIT_CONTEXT_BLOCK Wcb;

} Queue;

ULONG AlignmentRequirement;


// IRP 명령어를 Queue에 담는 용도로 사용되는 구조체

KDEVICE_QUEUE DeviceQueue;

KDPC Dpc;

ULONG ActiveThreadCount;

PSECURITY_DESCRIPTOR SecurityDescriptor;

KEVENT DeviceLock;

USHORT SectorSize;

USHORT Spare1;

struct _DEVOBJ_EXTENSION  * DeviceObjectExtension;

PVOID Reserved;

} DEVICE_OBJECT, *PDEVICE_OBJECT;


출처 : 디바이스 드라이버 구조와 원리 그리고 제작 노하우