User-Mode Driver Framework
From Wikipedia, the free encyclopedia
The User-Mode Driver Framework is a device-driver development platform first introduced with Microsoft's Windows Vista operating system, and is also available for Windows XP. It facilitates the creation of drivers for certain classes of devices.
Badly written drivers can cause severe damage to a system since all drivers have high privileges and direct access to the kernel. The new User-Mode Drivers in Windows Vista are not able to directly access the kernel but instead use it through a dedicated API. If an error occurs the new framework allows for an immediate restart of the driver and does not impact the system. Typically these devices are connected to the computer through a bus technology such as USB or Firewire.
The first version of the UMDF was shipped as part of Windows Media Player version 10. Code-named "Crescent", it was designed to support the Media Transfer Protocol driver, and no public interfaces or documentation was provided for it. After this, Microsoft decided to turn UMDF into a device driver development platform.[1]
Contents |
[edit] COM-style Architecture
A UMDF Driver is a COM based DLL, but UMDF doesn't use the COM runtime library, only usings COM as a programming pattern. UMDF does not use COM for loading, unloading, or controlling concurrency (that is apartment)
UMDF calls DllGetClassObject to get a pointer to an IClassFactory interface in the driver and then uses the CreateInstance method of the IClassFactory interface to create an instance of the driver object. The DLL provides routines that COM will use to get the IWDFDriver-based object:
- DllCanUnloadNow
- DllGetClassObject
- DllRegisterServer
- DllUnregisterServer
[edit] DllMain
UMDF driver is a Dynamic Link Library (DLL), that runs as an in-process COM server, and contains the code for DllMain, which is a well-known entry point for a DLL.
BOOL WINAPI DllMain( HINSTANCE ModuleHandle, DWORD Reason, PVOID /* Reserved */) { if (DLL_PROCESS_ATTACH == Reason) { WPP_INIT_TRACING(MYDRIVER_TRACING_ID); g_ModuleHandle = ModuleHandle; } else if (DLL_PROCESS_DETACH == Reason) { WPP_CLEANUP(); } return TRUE; };
UMDF supports IXX abstract classes with which any KMDF developer as following:
- IWDFDriver
- IWDFDevice
- IWDFFile
- IWDFIoQueue
- IWDFIoRequest
- IWDFIoTarget
- IWDFMemory
- IWDFObject
[edit] IUnknown interface
COM interfaces are C++ abstract base classes. These UDMF objects provide signatures for the routines (callback functions) they support in the form of abstract classes (interfaces), that are pure virtual functions, UDMF driver which support an interface must implement all the functions in that callback's interface. And COM objects all support an interface called IUnknown.
IUnknown interface supports three methods:
interface IUnknown { virtual ULONG AddRef(void) = 0; virtual HRESULT QueryInterface(REFIID riid, void **ppvObject) = 0; virtual ULONG Release(void) = 0; };
[edit] IDriverEntry interface
UMDF driver must support IDriverEntry interface, and need to implement OnAddDevice callbacks.
class CMyDriver : public IDriverEntry, public CUnknown { virtual ULONG STDMETHODCALLTYPE AddRef(VOID){ return __super::AddRef(); } virtual ULONG STDMETHODCALLTYPE Release(VOID){ return __super::Release(); } virtual HRESULT STDMETHODCALLTYPE QueryInterface(__in REFIID InterfaceId, __out PVOID *Object){ return __super::Release(InterfaceId, Object); } virtual HRESULT Initialize(__in IWDFDriver* FxDriver,__in IWDFDeviceInitialize * FxDeviceInit){...} virtual HRESULT STDMETHODCALLTYPE OnDeviceAdd( __in IWDFDriver *FxWdfDriver, __in IWDFDeviceInitialize *FxDeviceInit){ ... } virtual VOID STDMETHODCALLTYPE OnDeinitialize(__in IWDFDriver *FxWdfDriver) { return; } ... };
[edit] IDevicePnpHardware interface
Create CMyDevice class that inherits from IIDevicePnpHardware and CUnknown class.
class CMyDevice : public CUnknown, public IDevicePnpHardware { private: IWDFDevice *m_FxDevice; public: HRESULT Initialize(__in IWDFDriver* FxDriver,__in IWDFDeviceInitialize * FxDeviceInit) { return S_OK; } HRESULT OnPrepareHardware(__in IWDFDevice * /* FxDevice */) { return S_OK; } ... };
[edit] References
[edit] See also
[edit] External links
- User-Mode Driver Framework Homepage
- Peter Wieland's blog – developer lead on the UMDF team at Microsoft