WDFREQUESTs are for sharing in KMDF v1.9

In my last post I described why a WDFREQUEST is unique to a particular WDFDEVICE.  There is one particular programming pattern where this is not the behavior you want.  This pattern is when you have each PDO accepting IO requests which it then forwards on to the parent WDFDEVICE for processing. One great in box…

2

WDFREQUESTs are not for sharing

FYI: this is a bit of a long post, but I wanted to be thorough and illustrative and give some insight into how the framework works and potential design that could have been made, but were not for the sake of simplicity and performance A common misconception a WDFREQUEST handle is the assumption that the…

1

How do I cancel an IRP that another thread may be completing at the same time?

Let’s say that you allocated a PIRP and sent it down your device stack.  You free the PIRP in the completion routine and then return STATUS_MORE_PROCESSING_REQUIRED.  To make life more fun, you decide that you want to be able to cancel the sent IRP after you have sent it so you try to do it…

1

EvtDevicePreprocessWdmIrp is not entirely free

One of the WDM escapes in KMDF is EvtDeviceWdmIrpPreprocess (or EvtDevicePreprocessWdmIrp in the API in which you register it) which you can register for by calling WdfDeviceInitAssignWdmIrpPreprocessCallback.  This function allows you to process a WDM PIRP before KMDF sees it and potentially processes it.  From a KMDF adoption point of view, this functionaltiy was a…

0

How to share HW resources with another driver not in the same PnP hierarchy

First, I have to say that I don’t agree with this design pattern at all.  I think it leads to too many problems and complications that are not worth the pain.  The only reason I am writing this entry is that I have seen so many people get this wrong or not account for some…

1

WdfDeviceRetrieveDeviceInterfaceString and PDOs

When you initially create a PDO, it takes a few steps for PnP to recognize it.  I wrote this problem of determining when a PDO becomes a PDO last year.  At the end of the post I mentioned that KMDF handles all of this state management for you underneath the covers.  This works for 99%…

1

Setting a security descriptor on a legacy device object

Setting the security descriptor allows you to control who can open a handle to the device object.  Typically you can call IoCreateDeviceSecure to create the device object and have the correct DACL from the start.  One issue with IoCreateDeviceSecure is that the SDDL string is limited to what it can describe, primarily you can only…

1

Having two names is not necessarily better than one, part 2

Previously I wrote about what happens when there are 2 devices in a stack with a name and all of the associated issues that arise from it.  In that vein I want to write about what happens when you give your device object a name in KMDF and compare it to WDM.  In a WDM driver, if…

0

Problems with not having a current IRP stack location, part 2

This problem falls into the category being hidden by a macro that does not indicate in its name what it touches. If you call IoMarkIrpPending on an IRP that you allocated in your driver, chances are that you are corrupting memory. First, let’s look at the implementation of this function (from wdm.h): #define IoMarkIrpPending( Irp…

2