Why is there no WDM kernel-mode driver template in Windows Driver Kit?
Asked Answered
E

1

0

I came across kernel-mode drivers with very little experience. Here's what I am trying to do:

  • Have a user-mode application that loads the driver.
  • Have the user-mode application write to it, in order to send it an instruction.
  • Have the driver send the RDMSR instruction to the Intel chip.
  • Return the results back to the user-mode application.

I've read this article that describes the different ways in which you can accomplish this behavior (Buffered I/O, Direct I/O, or Neither).

My problem is this...the article has code that represents the way you would structure a WDM driver, and I was expecting to be able to create a WDM KMDF project template using the Windows Driver Kit, but when I downloaded the Windows Driver Kit (WDK), the only KMDF driver template was for a WDF driver. MSDN has an article describing the differences between the two. This is kind of strange to me. I was expecting to get a template out of the box that I could modify to work like in the article I've linked, but I don't see it. Why is there no template for a WDM KMDF driver?

Just an added note, you can quite easily tell the type of the driver based on the way it creates the device (IoCreateDevice implies WDM, whereas WdfDeviceCreate implies WDF).

Exodus answered 3/6, 2014 at 13:27 Comment(0)
A
3

There is a lot of inconsistencies in the question. First of all, KMDF is a subset of WDF (and it's the only relevant WDF part when talking about kernel drivers), so there is no contradiction between the two. Every kernel driver is essentially a WDM driver. KMDF is a framework in the WDM and KMDF drivers are normally called, well, KMDF drivers, without mentioning WDM. WDM driver usually refers to driver that does not use any additional framework, such as KMDF. Second, WDK integrates with VS2012/2013 and you must have it installed in addition to WDK to get the templates. Third, WDM template does appear in the list. If you don't have it, I suggest reinstalling the WDK and VS.

Agnosia answered 3/6, 2014 at 13:43 Comment(11)
I find your answer confusing and I feel like I want to ask you a hundred questions to clarify a few points, but I think it's better if I just ask you this: Is there a driver template in WDK for a driver that runs in Ring 0 and creates a device using IoCreateDevice instead of WdfDeviceCreate? The WDM template you speak of is blank, no source code in it. I'm using VS2013.Exodus
@Exodus Yes, IoCreateDevice is for a naked WDM driver. The provided WDM template is indeed empty and all it provides is a logical tree of components. Why? That's a question to MSFT, could be because they strongly promote KMDF as a default framework. You can check out the WDK samples (msdn.microsoft.com/en-us/library/windows/hardware/…) to get an idea of how different drivers look, including WDM.Agnosia
I'm starting to get what you mean in your answer. Two streams of drivers, WDF and WDM. WDM is minimalistic, whereas WDF drivers are not because they use additional frameworks, like in the case of KMDF drivers (which as you pointed out are a subset of WDF). Is that correct?Exodus
icepack, I'm a minimalistic guy. I need to see things in their minimalistic form, and MSFT hasn't provided a sample, as far as I can tell, or even a template, that does that for me. This really sucks, because my mind always need to see things in base form and from first principles; its just the way I am and how I structure information. What would you recommend then, for me to use as a guide from the driver samples? I'm looking at them now, but most of these are overkill. I almost feel like it would be better to use the WDM code in the CodeProject article I linked earlier in my question.Exodus
...or maybe even find a KMDF sample that does the same thing, since that's the closest thing I can get to a working kernel-mode template.Exodus
I will mark your answer as the correct answer to this question since I was clearly inconsistent and someone facing the same concerns as me can learn from the same mistakes I made in the way I organized the two different driver types, and I will start a new question regarding WDM driver templates: #24018217Exodus
@Exodus You can check out the Toaster samples in the MSFT samples repository - go.microsoft.com/fwlink/?LinkId=301841Agnosia
I'll check those out.Exodus
Toaster is not a WDM driver, but...thanks to your suggestion I came across a driver inside of the package (thanks to a trusty grepWin search) called IOCTL: "This sample demonstrates the usage of four different types of IOCTLs (METHOD_IN_DIRECT, METHOD_OUT_DIRECT, METHOD_NEITHER, and METHOD_BUFFERED) supported by Windows, and how the user input & output buffer specified in the DeviceControl function is handled by the I/O subsystem and the driver in each case.", and "This is a minimal driver meant to demonstrate an OS feature."Exodus
@Exodus Toaster is a generic name for basic driver sample, there are many types of toasters, for various driver models and targets. Sometimes it's hard to pinpoint the exact needed sample, good to hear you found what you look forAgnosia
Ah, I thought you were making reference to the actual Toaster sample in that package (there is a sample by that name specifically), but its good to know that the jargon for toaster means a bare-bones implementation, never knew that :PExodus

© 2022 - 2024 — McMap. All rights reserved.