New Windows Drive Framework WDF (Windows Driver Foundation)

zhaozj2021-02-12  131

http://www.blogcn.com/user8/flier_lu/index.html?id=2507847

WDM (Windows Driver Model) has not fully understood that M $ has launched a WDF (Windows Driver Foundation) that will fully replace WDM on Winhec. OSR Online briefly introduces some new features of WDF, and gives an actual WDF example in a New Framework. Because there is no development environment, you can only look at the article, feel that the structure adjustment is not considered to my needs. Highlights are mainly for further optimization and adjustment of new PNP / POWER models, which can be abandoned (for example, in Longhorn can be interrupted and discarded), new storage architecture (do not understand: (), flexible task request queue (Support serial, parallel and custom task distribution), as well as some other details. In the driving model, WDF uses some new types of drive WDM's corresponding type and makes a certain extension: WDF type WDM type WDFDRIVER Driver_Object WDFDEVICE DEVICE_OBJECT WDFREQUEST IRP WDFQUEUE DPC Queue WDFINTERRUPT ISR & DPCFORSR DriveErentry is only responsible for the initialization and constructive of WDFDriver type objects in WDF, and the management of the device is fully lost into the DioeEvtdEVICEADD function, called by the WDF framework when it is appropriate.

The following program code is: NTSTATUSDriverEntry (PDRIVER_OBJECT DriverObj, PUNICODE_STRING RegistryPath) {NTSTATUS code; WDF_DRIVER_CONFIG config; WDFDRIVER hDriver; DbgPrint ( "WDFDIO Driver - Compiled% s% s", __ DATE__, __TIME__); // // Initialize the Driver config structure: // Specify our Device Add event callback // WDF_DRIVER_CONFIG_INIT_NO_CONSTRAINTS (& config, DioEvtDeviceAdd); // // // Create a WDFDRIVER object // // We specify no object attributes, because we do not need a cleanup //. or destroy event callback, or any per-driver context // code = WdfDriverCreate (DriverObj, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, & config, // ptr to config structure NULL);.! // Optional ptr to get WDFDRIVER handle if (NT_SUCCESS (code) ) {DBGPRINT ("WDFDriverCreate Failed with Status 0x% 0X", CODE);} #if DBG DBGPRINT ("DriveRentry: Leaving "); # Endif return (code);} and DioevtdEVICEADD functions first initialize PNP and power management related structures.

The following program code is: WDFSTATUSDioEvtDeviceAdd (WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit) {WDFSTATUS status = STATUS_SUCCESS; WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; WDF_OBJECT_ATTRIBUTES objAttributes; WDFDEVICE device; PDIO_DEVICE_CONTEXT devContext; WDF_IO_QUEUE_CONFIG ioCallbacks; WDF_INTERRUPT_CONFIG interruptConfig; WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS idleSettings; // // Initialize the PnpPowerCallbacks structure. // WDF_PNPPOWER_EVENT_CALLBACKS_INIT (& pnpPowerCallbacks); // // Setup the callbacks to manage our hardware resources // // Prepare is called at START_DEVICE time // Release is called at STOP_DEVICE or rEMOVE_DEVICE time // pnpPowerCallbacks.EvtDevicePrepareHardware = DioEvtPrepareHardware;. pnpPowerCallbacks. EvtdeviceReleasehardware = DioevTreleasehardware; // // There Two Callbacks Set Up and Tear Down Hardware State That // BE DONE EVERY TIME The Device Moves in And Out of Time D0-Working // . State // pnpPowerCallbacks.EvtDeviceD0Entry = DioEvtDeviceD0Entry; pnpPowerCallbacks.EvtDeviceD0Exit = DioEvtDeviceD0Exit; // // Register the PnP and power callbacks // WdfDeviceInitSetPnpPowerEventCallbacks (DeviceInit, pnpPowerCallbacks);. // ...} and then initializes the device object structure, similar Previous CreateDevice and IOCREATESYMBOLICLICLINK calls in WDM.

The following program code is: WDFSTATUSDioEvtDeviceAdd (WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit) {// ... // Create our Device Object and its associated context // WDF_OBJECT_ATTRIBUTES_INIT (& objAttributes); WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE (& objAttributes, DIO_DEVICE_CONTEXT); // // We want our device object NAMED, thank you very much // status = WdfDeviceInitUpdateName (DeviceInit, L "/ device / WDFDIO"); (! NT_SUCCESS (status)) if {DbgPrint ( "WdfDeviceInitUpdateName failed 0x% 0x", status); return ( status);} // // Because we DO NOT provide callbacks for Create or Close, WDF will // just succeed them automagically // // // Create the device now // status = WdfDeviceCreate (& DeviceInit, // Device Init. Structure & objattributes, // attributes for wdf device & device); // Returns Pointer to New WDF Device if (! NT_Success (status)) {DBGPrint ("WDFDEviceInitialize Failed 0x% 0X", Status); Return (status);} // // Device Creation is Complete // // Get Our device Extension // devcontext = DioGetContextFromDevice (device); devContext-> WdfDevice = device; // // Create a symbolic link for the control object so that usermode can // open the device // status = WdfDeviceCreateSymbolicLink (device, L "/ DosDevices / WDFDIO"). ; If (! Nt_success (status)) {DBGPRINT ("WDFDeviceCreateSymbolicLink Failed 0x% 0x", Status; Return (STATUS);} // ...}

Interesting is that WDF provides the concept of requesting queue. A device can have multiple request queues, each request queue can have a mode, such as the simplest WDFioqueueDispatchSerial mode, request queue to process after serialization; and WDFioQueuedispatchParallel mode automatically calls IO when each request arrives The callback function; Finally, you can also pass the WDFioqueueueDispatchManual mode, call the evtiostart event handler to manually distribute the request when requested, similar to the WDM's working mode. The request queue provides the automatic saving and recovery mechanism for the request queue when Power Down is available. This way, the driver can be left, huh, huh. A New Framework is more extensive discussion in the article, it is not coming.

The following program code is: WDFSTATUS DioEvtDeviceAdd (WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit) {// ... // // Configure our queue of incoming requests // // We only use the default queue, and we only support // IRP_MJ_DEVICE_CONTROL. // // Not supplying a callback results in the request being completed // with STATUS_NOT_SUPPORTED // WDF_IO_QUEUE_CONFIG_INIT (& ioCallbacks, WdfIoQueueDispatchSerial, WDF_NO_EVENT_CALLBACK, // StartIo WDF_NO_EVENT_CALLBACK);. // CancelRoutine ioCallbacks.EvtIoDeviceControl = DioEvtDeviceControlIoctl; status = WdfDeviceCreateDefaultQueue (device, & Iocallbacks, WDF_NO_Object_attributes, null; // Pointer To Default Queue IF (! NT_Success (status)) {DBGPRINT ("WDFDeviceCreatedEfaultqueue Failed 0x% 0X", Status; RETU RN (status);} // ...}

For interruption, WDF also organizes several callback functions in WDM using OO Thought, but the function is still similar.

The following program code: WDFSTATUS DioEvtDeviceAdd (WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit) {// ... // // Create an interrupt object that will later be associated with the // device's interrupt resource and connected by the Framework // /. / // Configure the Interrupt object // WDF_INTERRUPT_CONFIG_INIT (& interruptConfig, FALSE, // auto-queue DPC DioIsr, DioDpc?); interruptConfig.EvtInterruptEnable = DioEvtInterruptEnable; interruptConfig.EvtInterruptDisable = DioEvtInterruptDisable; status = WdfInterruptCreate (device, & interruptConfig, & objAttributes, & devContext -> wdfinterrupt); if (! Nt_success (status)) {DBGPRINT ("WDFINTERRUPTCREATE FAILED 0X% 0X", Status); Return Status;} // ...} Finally, WDF in order to support power management Provide a callback function when auxiliary state change is provided, simplifies the management code implementation in the drive.

The following program code is: WDFSTATUS DioEvtDeviceAdd (WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit) {// ... // // Initialize our idle policy // WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT (& idleSettings, IdleCannotWakeFromS0); status = WdfDeviceUpdateS0IdleSettings (device, & idleSettings); if (! NT_Success (status)) {DBGPRINT ("WDFDeviceUpdates0 IDleSettings Failed 0x% 0X", Status; Return Status;} Return (status);

Because I haven't got the development of the debugging environment, even the OSR's example can be downloaded, I can only talk. Wait until the actual thing is discussed in detail, huh, huh, interested friends can take a look

There are several related articles on OSR Online, and it is more detailed.

转载请注明原文地址:https://www.9cbs.com/read-6590.html

New Post(0)