Re:[ntdev] Some questions about DDK's sample toaster?

Thanks for you detailed explaination, and also i share the same feeling with you: in field of driver development, experience is more important than IQ.

Bill McKenzie дµÀ£º >from the comment in source code, i can tell that the statement is trying to wait for some
>outstanding IRPs to complete. But what’s the principle in such situation? How can i know
>when to synchronize, and with whom to synchronize?

In general drivers wait in their stop handlers (or query stop handlers) for all I/O to be either completed or parked. That is I/O queues are generally flushed or stalled and requests sent to other drivers are cancelled or waited upon for completion.

Unfortunately, there is no one right way to do this. Well there is a generic way, but you would never implement it in a normal driver. When, where, and how you stall I/O and such depends somewhat on the usage of your driver, and what type of hardware you are working with. In general, the toaster sample provides a sufficient solution to follow. I say sufficient as it is actually impossible for you to correclty implement PnP and Power handling in your WDM driver. I say impossible because there are race conditions and such between I/O, PnP, and Power that you cannot possibly realize or solve from the available APIs and documentation. Let me make that clear, it is impossible to write a correct WDM driver with the information currently available from Microsoft. So, the best you can hope for is to get close and test the begeezus out of your driver. This is sufficient such that your driver will probably not blue screen most of the time. If this makes you uncomfortable, well
welcome to the world of Windows kernel development.

>above questions may be better expressed as follow:
>can i say that toaster’s dispatch routines may be classified into 4 categories, and dispatch
>routines for IRP_MJ_CREATE, IRP_MJ_CLOSE, IRP_MJ_READ and IRP_MJ_WRITE are
>called by I/O mgr, dispatch routine for IRP_MJ_PNP is called by PnP mgr, and dispatch
>routine IRP_MJ_POWER is called by Power mgr, and dispatch routine for
>IRP_MJ_SYSTEM_CONTROL is called by WMI ? and can i say that those 4 categories of
>dispatch routines may be called in parallel (i.e., several dispatch routines may be executing
>overlappedly)?
>and can i say that i should synchronize among them?

Actually, the PnP and Power managers still use the I/O manager to send IRPs to the driver, so all IRPs can be thought of as functioning somewhat the same. You are correct, however, in that PnP and Power IRPs have some special synchronization properties that other types of I/O do not, especially as relates to removal. That said, again there is no where you can turn to find all of the information you should have. The best source of information on WDM drivers today is Walter Oney’s “Programming the Windows Driver Model 2nd Ed.” That book along with the DDK documentation and samples will likely get you where you need to go.

Microsoft made a monumental mistake in exposing the complexities of PnP and power management to the driver development community. Their solution going forward, which I heavily disagree with, seems to be - not to document the necessary information - but rather to provide a driver framework which they call WDF. WDF is the Windows Driver Foundation, which essentially is a rehash of commercially available tools such as DriverWorks and the now defunct WinDK. WDF is better than these older tools in some ways because Microsoft has Windows source code at their finger tips, the developers of these other tools did not. Obviously, this makes for a more correct solution. However, WDF lacks many of the niceties these other tools provided (wizards, Visual Studio integration, etc.) and it is still yet another framework. I don’t think is particularly useful unless source is shipped alongside. So far, WDF source doesn’t look like it is going to make it out the door with WDF.

That said WDF almost completely removes the necessity for anyone to know anything about PnP or Power beyond their own device’s capabilities. Unfortunately, WDF is not going to be available until Vista, so that isn’t an option today.

>any article or hyperlink on this is also appreciated.

There aren’t any good articles on PnP or Power aside from Oney’s book that really explain the why of things. Oney’s book and the DDK are the best answer I can give. I have spent a lot of time on synchronization with I/O, PnP, and Power in WDM and I have yet to see a correct solution in any driver anywhere. In fact, I can guarantee there is no such correct driver except POSSIBLY WDF drivers, but we will likely never even know that for sure.

Good luck.

Bill M.

“identifier scorpio” wrote in message news:xxxxx@ntdev…
In the dispatch routine ToasterDispatchPnp() in toaster\func\toaster.c,
when dealing with case IRP_MN_QUERY_STOP_DEVICE, the driver uses following statement to do some synchronization work:

ToasterIoDecrement(fdoData);
KeWaitForSingleObject(
&fdoData->StopEvent,
Executive, // Waiting for reason of a driver
KernelMode, // Waiting in kernel mode
FALSE, // No allert
NULL); // No timeout

and there are also some other similar KeWaitForXXX statements in other case, e.g., IRP_MN_QUERY_REMOVE_DEVICE and IRP_MN_REMOVE_DEVICE.

from the comment in source code, i can tell that the statement is trying to wait for some outstanding IRPs to complete. But what’s the principle in such situation? How can i know when to synchronize, and with whom to synchronize?

above questions may be better expressed as follow:
can i say that toaster’s dispatch routines may be classified into 4 categories, and dispatch routines for IRP_MJ_CREATE, IRP_MJ_CLOSE, IRP_MJ_READ and IRP_MJ_WRITE are called by I/O mgr, dispatch routine for IRP_MJ_PNP is called by PnP mgr, and dispatch routine IRP_MJ_POWER is called by Power mgr, and dispatch routine for IRP_MJ_SYSTEM_CONTROL is called by WMI ? and can i say that those 4 categories of dispatch routines may be called in parallel (i.e., several dispatch routines may be executing overlappedly)?
and can i say that i should synchronize among them?

DDK just tell me what to do, but never tell me why. some internel information on how I/O mgr and PnP mgr is going will be great help for me.

any article or hyperlink on this is also appreciated.

thanks in advance for clarifying it.
WeiYu, Dong


¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?
http://cn.mail.yahoo.com

“identifier scorpio” wrote in message news:xxxxx@ntdev…
In the dispatch routine ToasterDispatchPnp() in toaster\func\toaster.c,
when dealing with case IRP_MN_QUERY_STOP_DEVICE, the driver uses following statement to do some synchronization work:

ToasterIoDecrement(fdoData);
KeWaitForSingleObject(
&fdoData->StopEvent,
Executive, // Waiting for reason of a driver
KernelMode, // Waiting in kernel mode
FALSE, // No allert
NULL); // No timeout

and there are also some other similar KeWaitForXXX statements in other case, e.g., IRP_MN_QUERY_REMOVE_DEVICE and IRP_MN_REMOVE_DEVICE.

from the comment in source code, i can tell that the statement is trying to wait for some outstanding IRPs to complete. But what’s the principle in such situation? How can i know when to synchronize, and with whom to synchronize?

above questions may be better expressed as follow:
can i say that toaster’s dispatch routines may be classified into 4 categories, and dispatch routines for IRP_MJ_CREATE, IRP_MJ_CLOSE, IRP_MJ_READ and IRP_MJ_WRITE are called by I/O mgr, dispatch routine for IRP_MJ_PNP is called by PnP mgr, and dispatch routine IRP_MJ_POWER is called by Power mgr, and dispatch routine for IRP_MJ_SYSTEM_CONTROL is called by WMI ? and can i say that those 4 categories of dispatch routines may be called in parallel (i.e., several dispatch routines may be executing overlappedly)?
and can i say that i should synchronize among them?

DDK just tell me what to do, but never tell me why. some internel information on how I/O mgr and PnP mgr is going will be great help for me.

any article or hyperlink on this is also appreciated.

thanks in advance for clarifying it.
WeiYu, Dong


¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?
http://cn.mail.yahoo.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

---------------------------------
ÎÞÏÞÈÝÁ¿ÑÅ»¢Ïà²á£¬Ô­Í¼µÈ´óÏÂÔØ£¬³¬¿ìËÙ¶È£¬¸Ï¿ìÇÀ×¢£¡