Ch 6. Initialization and Cleanup Routines - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Ch 6. Initialization and Cleanup Routines

Description:

Title: Module 1: Introduction Author: Marilyn Turnamian Last modified by: Povolon Created Date: 2/7/2000 7:26:30 PM Document presentation format – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 35
Provided by: Marily551
Category:

less

Transcript and Presenter's Notes

Title: Ch 6. Initialization and Cleanup Routines


1
Ch 6. Initialization andCleanup Routines
2
Contents
  1. Writing a DriverEntry Routine
  2. Code Example Driver Initialization
  3. Writing Reinitialize Routine
  4. Writing an Unload Routine
  5. Code Example Driver Unload
  6. Writing Shutdown Routine
  7. Testing the driver
  8. Summary

3
1. Writing a DriverEntry Routine
4
DriverEntry Routine
  • ?? Windows 2000? ?? ?? ????? WDM????? ? ??? ????
    DriverEntry Routine? ??.
  • ??? ??? ???? ???
  • ?? ?? ????? ?? ???? ?? ??? ??

5
DriverEntry Routine(1)
  • Function Prototype for DriverEntry

NTSTATUS DriverEntry IRQL PASSIVE LEVEL
Parameter Description
IN PDRIVER_OBJECT pDriverObject Address of driver object for this driver
IN PUNICODE_STRING pRegisterPath Registry path string for this drivers key
Return value STATUS_SUCCESS STATUS_XXX some error code
6
DriverEntry Routine(2)
  • Driver Entry Routine ? ??
  • ?????? ??? ????? ??
  • Driver Object? ?? Routine?? ??? ??
  • Controller ?? , Controller Extension ???
    (IoCreateController)
  • Device Object ??, Device Extension ???
    (IoCreateDevice)
  • Device Object? Win32????? ???? ?
    (IoCreateSymbolicLink)
  • Interrupt Object? ??(DPC Object??)
  • 46? ??? ?? device? ?? ?? ??
  • Return STATUS_SUCCESS to I/O manager

7
Announcing DriverEntry Point
  • Function pointer in Driver Object
  • ???? slot name? ??? Function
  • MajorFunction?? ?? ??? IRP Dispatch function
  • Ex) Function pointer initialize
  • pDO -gt DriverStartIO StartIO
  • pDO -gt DrtverUnload Unload
  • //
  • // ?? ?? ???? ???? ?? ???
  • //
  • pDO -gt MajorFunction IRP_MJ_CREATE
    DispatchCreate
  • pDO -gt MajorFunction IRP_MJ_CLOSE
    DispatchClose

8
Creating Device Object
  • IoCreateDevice
  • Driver Object? ?? ???? Device List? ??? Device
    Object? ??
  • AddDevice Routine?? ???? ??
  • WDM ? ???? Device
  • DriverEntry Routine? 1,36??? ???
  • (???? ?? ? ???? ???? ??? ??)
  • Dispatch Routine?? IoCreateDevice ? ??? ??
  • Device? Flags Field? DO_DEVICE_INITIALIZING bit?
    reset
  • Device? ?? or Reinitializing

9
Creating Device Object(1)
  • Function Prototype for IoCreateDevice

NTSTATUS IoCreateDevice IRQL PASSIVE LEVEL
Parameter Description
IN PDRIVER_OBJECT pDriverObject Pointer to driver object
IN ULONG DeviceExtensionSize DEVICE_EXTENSION? ???? ??
IN PUNICODE_STRING pDeviceName ?? ????? ??(internal name)
IN DEVICE_TYPE DeviceType FILE_DEVICE_XXX (NTDDK.h ??)
IN ULONG DeviceCharacteristics ??? ?? ????? ?? FILE_REMOVABLE_MEDIA FILE_READ_ONLY_DEVICE Etc.
IN BOOLEAN Exclusive Device? ???? ?? ?? ?? True
OUT PDEVICE_OBJECT pDeviceObject Device object? ?? pointer? ?? ??
Return value STATUS_SUCCESS STATUS_XXX some error code
10
Buffering Strategy
  • Device?? ??? Buffering strategy ? I/O Manager??
    ??
  • Device Flags Field
  • DO_BUFFER_I/O
  • DO_DIRECT_I/O
  • Neither bit - ??? ??? ??

11
Device Name
Name Directory Tree
Object Manager
Root
Ex) ?? \\Device\\Minimal0 FloppyDisk0 ,
FloppyDisk1
Ex) Symbolic Link Name \\??\\MINIMAL1 LPT1,
LPT2 , A Z
IoCreateSymbolicLink ( Device Name ,
UNICODE_STRING Symbolic Link Name )
12
2. Code Example Driver Initialization
13
Minimal driver
  • Device Name MINIMAL0
  • Symbolic Link Name MINI
  • DriverEntry
  • ?? ??? ???? ??(Announcing)
  • Logical Device ??

NTSTATUS DriverEntry ( IN PDRIVER_OBJECT
pDriverObject, IN PUNICODE_STRING
pRegistryPath ) NTSTATUS status
pDriverObject-gtDriverUnload DriverUnload
status CreateDevice ( pDriverObject,
) return status
14
Minimal driver (1)
  • CreateDevice
  • Device Name initialization
  • Device Object ??, Device Extension size ??
  • Device Extension initialization
  • Symbolic Link Name initialization Link

NTSTATUS CreateDevice ( IN PDRIVER_OBJECT
pDriverObject, IN ULONG
ulDeviceNumber) NTSTATUS status PDEVICE_OBJ
ECT pDevObj PDEVICE_EXTENSION pDevExt
CUString devName(\\Device\\MINIMAL) devName
CUString(ulDeviceNumber)
15
Minimal driver (2)
status IoCreateDevice ( pDriverObject, )
pDevExt (PDEVICE_EXTENSION)pDevObj-gtDeviceExten
sion pDevExt-gtpDevice pDevObj // Back
pointer pDevExt-gtDeviceNumber
ulDeviceNumber pDevExt-gtustrDeviceName
devName CUString SymLinkName(\\??\\MINI) Sy
mLinkName CUString(ulDeviceNumber1) pDevExt-
gtustrSymLinkName SymLinkName status
IoCreateSymbolicLink( ) //??? ?? Device
Object? ??? ?? return STATUS_SUCCESS
16
3. Writing Reinitialize Routines
17
Reinitialize Routine
  • IoRegisterDriverReinitialize
  • ???? Bootstrap? ??? ???? ??? ??? ??? ??? ??? ????
  • I/O Manage? Bootstrap? ??? Reinitialize routine
    ??
  • Booting?? ???? load?? ????? ??
  • ????? ???? ??? ??
  • Function Prototype for Reinitialize

VOID Reinitialize IRQL PASSIVE LEVEL
Parameter Description
IN PDRIVER_OBJECT pDriverObject Pointer of driver object
IN PVOID Context ??? ??? Context Block
In ULONG Count Reinitialize call? ?? ???(0)
Return value (void)
18
4. Writing an Unload Routine
19
Unload Routine
  • ????? Unload?? ?? ?? ?? Unload routine? ??? ??
  • I/O Manager? ??, ???? ??(Unload ??)
  • Function Prototype for Unload

VOID Unload IRQL PASSIVE LEVEL
Parameter Description
IN PDRIVER_OBJECT pDriverObject Pointer of driver object
Return value (void)
20
Unload Routine(1)
  • Unload Routine ? ??
  • ?? load?? ?? ??? ?? Device? ????? registry? ??
  • Interrupt disable, disconnect Interrupt object
  • Hardware ??
  • Remove Symbolic Link Name from Win32 namespace
  • IoDeleteDevice Device Object ??
  • ?? Controller? ????? 45?? ??, IoDeleteController
    Controller Object ??
  • 46? ??? ?? Device Controller? ?? ?? ??
  • Deallocate pool memory
  • WDM? ?? RemoveDevice?? ??

21
5. Code Example Driver Unload
22
Unload Routine(2)
  • Driver Entry Routine? ??? ??? ??
  • Symbolic Link Name ? Device Object? ??

VOID DriverUnload ( IN PDRIVER_OBJECT
pDriverObject ) PDEVICE_OBJECT pNextObj
pNextobj pDriverObject-gtDeviceObject while
( pNextObj ! NULL ) PDEVICE_EXTENSION
pDevExt (PDEVICE_EXTENSION) pNextObj-gtDeviceExt
ension UNICODE_STRING pLinkName
pDevExt-gtustrSymLinkName IoDeleteSymbolicLink(
pLinkName ) pNextObj pNextObj -gt
NextDevice IoDeleteDevice ( pDevExt-gtpDevice
) //IoReportResourceUsage
23
6. Writing Shutdown Routines
24
Shutdown Routine
  • OS? ??? Driver?? ?? ? ???? ??? ??
  • Shutdown??? Unload routine? ???? ??
  • Device? ???? ??? ?
  • Device? ?? ??? ??
  • OS? ???? ??? ??? ???
  • Function Prototype for Shutdown

NTSTATUS Shutdown IRQL PASSIVE LEVEL
Parameter Description
IN PDRIVER_OBJECT pDriverObject Pointer of driver object
IN PIRP pirp Shutdown IRP? ?? pointer
Return value STATUS_SUCCESS STATUS_XXX
25
Shutdown Routine(1)
  • ??? I/O??
  • MajorFunction ?? ???????? ??
  • IoRegisterShutdownNotification Shutdown ??

NTSTATUS DriverEntry ( IN PDRIVER_OBJECT
pDriverObject , IN PUNICODE_STRING
pRegistryPath) pDriverObject-gtMajorFunction
IRP_MJ_SHUTDOWN Shutdown IoCreateDevice(
pDriverObject , , pDeviceObject) IoRegisterShu
tdownNotification ( pDriverObject )
26
7. Testing the Driver
27
Test
  • ???? Compile , Link
  • ??? ??? ?? load Unload ??
  • Device Object ? Win32 Symbolic Link ??
  • Unload? ?? ??

28
Tool ??
  • ?? ?? ?? Minimal.dsw? ??? ? ??
  • ??? Minimal.sys? \winnt\system32\drivers? ??
  • Regedit? HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlS
    et\Service? ???? ??( ex Minimal )? ???
  • ?????? ?????
  • ErrorControl1(DWORD),Start3(DWORD),Type1(DWORD)
  • ?? Minimal.reg? ???
  • DisplayName ??? ?? ??? ??? ??

29
Test
30
Test
31
Test
32
Test
33
Summary
34
Summary
  • Windows 2000? Device Driver ?? ??? ??
  • ????? ?? , ??
  • ?? ?? ????? ?? ???
Write a Comment
User Comments (0)
About PowerShow.com