thank you for the look at the source
It’s from WDM.H, you know…
A quick look at the SwapBuffers driver shows that it must handle 3 or 4 different paths…
Dude… the SwapBuffers example is a File System Minifilter and was written (many years ago) specifically to demonstrate several instances of buffer manipulation. It is in no way, shape, manner, or form, representative of what drivers that are NOT File System Minifilters need to deal with. Heck, I’d argue that it’s not even representative of File System Minifilters. But that’s a discussion for another day, and another Forum.
To be clear, you are saying that in a well designed driver, that you ALWAYS know whether the IO buffers of the IRP are paged or nonpaged
Yes, assuming we read “ALWAYS know” to mean “can typically make assumptions about” – then, yes.
Am I missing something?
Yes, I think so. Something very important, in fact.
Carefully read what @Tim_Roberts said above, which is 100% correct and really cuts to the heart of the matter. That was good insight from Mr. Roberts, as usual.
There are established conventions – which are effectively contracts – in every branch of the device tree. If you’re a filter over the Volume driver, you’re not all of a sudden going to get a buffer that’s not described by Direct I/O, and if it’s using Direct I/O then the buffer has been pinned. Full stop. CAN some driver allocate a buffer from paged pool and then send it to you, without an MDL already having been built? Sure… But that’s a fatal bug in that other driver and not a situation about which you have to worry.
And see what @anton_bassov wrote (helpfully), too. If you’re the first driver entered from the I/O Manager, and you’re processing requests from user-mode, the I/O Manager will ensure your contract for Direct, Buffered, or Neither I/O is met. And, just so we’re clear, let’s take Neither I/O away from consideration… because unless you’re a file system or filter or doing something exceedingly special, this is not something a well-written driver will tangle with. If some OTHER driver in the system sends you requests that do not comply with your contract, _that’s a fatal bug in that other driver _and not a situation about which you have to worry.
So… CAN buffers arrive at your driver in all states and all manner of ways? Yes. Is this a situation with which we typically have to deal in writing Windows drivers? No. It would be mighty tiresome, and super prone to error (not to mention, demanding of several hundred lines of repeated boilerplate code) if we could make no assumptions about the buffers arriving at our drivers entry points. It would take, oh, something like ten minutes, for the owner of the I/O Subsystem to say to themselves “Gee, this is kinda chaotic… Perhaps I should write some centralized code to smooth this shit out?”
Peter