none
IOCTL's from a static library linked to KMDF driver RRS feed

  • Question

  • Hi,

    Im trying to build a static library that can be used across multiple KMDF drivers. The library needs to send IOCTL's to another driver to access required functionality. 

    The library does not have access to the Wdf device object/objects of the KMDF drivers it is being linked to. 

    To send IOCTLs from the library, i thought i would use WdfIoTragetCreate/open and then use WdfIoTargetSendIoctlSynchronously. However, to create the IO target, i require a device object. 

    I thought i could call WdfGetDriver to get the driver object and create a dummy device object with no callbacks. However, all the examples and documentation seems to indicate that you only call WdfDeviceCreate inside EvtDeviceAdd or  EvtChildListCreateDevice callback, or from a call to WdfPdoInitAllocate

    Is it incorrect to call WdfDeviceCreate from a library which will be used way after the KMDF driver has come up ? 

    What options do i have to be able to send IOCTL's to other drivers from this static library?


    -R___K

    Thursday, March 5, 2015 8:55 PM

Answers

  • You need to pass in the actual device object, one of the many things that WDF does for you is cleanup things like reference counts etc, so you don't want to be using a dummy device object, since you will be entering the area of having to worry about when to clean it up.

    Since it is a static library you can use WDF calls unlike a DLL. 


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    • Marked as answer by R___K Thursday, March 5, 2015 9:20 PM
    Thursday, March 5, 2015 9:06 PM
  • Change your interface to pass it in.  You cannot get it without that.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    • Marked as answer by R___K Thursday, March 5, 2015 9:20 PM
    Thursday, March 5, 2015 9:17 PM

All replies

  • You need to pass in the actual device object, one of the many things that WDF does for you is cleanup things like reference counts etc, so you don't want to be using a dummy device object, since you will be entering the area of having to worry about when to clean it up.

    Since it is a static library you can use WDF calls unlike a DLL. 


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    • Marked as answer by R___K Thursday, March 5, 2015 9:20 PM
    Thursday, March 5, 2015 9:06 PM
  • Thanks for the reply. How do i get the actual Wdf object when i have no other informatioN ? the only thing i seem to have is WdfGetDriver(). How do i get the device object from there ?

    -R___K

    Thursday, March 5, 2015 9:15 PM
  • Change your interface to pass it in.  You cannot get it without that.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    • Marked as answer by R___K Thursday, March 5, 2015 9:20 PM
    Thursday, March 5, 2015 9:17 PM
  • Alright. THanks. 

    -R___K

    Thursday, March 5, 2015 9:19 PM
  • Don,

    Can i not use IoEnumerateDeviceObjectList and then do WdfWdmDeviceGetWdfDeviceHandle to get a device object ?  What are the pitfalls of doing this ? 


    -R___K

    Thursday, March 5, 2015 11:35 PM
  • Choose the wrong device object and when the device is removed or stopped, then either it could mess up a valid request since you choose device A to do work on behalf of device B, then A gets removed canceling the request, or else B is removed, but you are still doing work on behalf of it through A.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com

    Friday, March 6, 2015 12:15 AM
  • Thanks Don. Appreciate the response and useful info. 

    -R___K

    Friday, March 6, 2015 12:19 AM