<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>WinDrvr : Driver Design</title><link>http://msmvps.com/blogs/windrvr/archive/tags/Driver+Design/default.aspx</link><description>Tags: Driver Design</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Coding Guidelines</title><link>http://msmvps.com/blogs/windrvr/archive/2007/06/24/coding-guidelines.aspx</link><pubDate>Sun, 24 Jun 2007 23:59:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:985546</guid><dc:creator>DonBurn</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/windrvr/rsscomments.aspx?PostID=985546</wfw:commentRss><comments>http://msmvps.com/blogs/windrvr/archive/2007/06/24/coding-guidelines.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 6pt;"&gt;&lt;font size="3"&gt;When I get a new client, I ask for a copy of their driver coding guidelines.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;Typically I get one of several responses.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;We trust our developers to do the right thing.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;The last time we brought this up there was almost open revolt.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;They hand me a corporate standard for coding applications, most of which is worthless for drivers.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt;TEXT-INDENT:0in;mso-list:none;tab-stops:.5in;"&gt;&lt;font size="3"&gt;Whether companies recognize it or not, they need a set of coding guidelines for drivers.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;There are a lot of ways of doing things in drivers that can cause problems, and a good set of guidelines can help.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Consider some of the following areas:&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;C++ - &lt;/b&gt;There can be an argument for this in many cases, but if C++ is used for drivers, there needs to be limits placed upon the language for it to work in the kernel.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Undocumented or unusual routines – &lt;/b&gt;What is your company’s policy on the use of undocumented kernel interfaces?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;What about routines not normally used in the kernel, but documented for user space?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;How about functions from the IFS kit for a regular driver?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;There are a lot decisions to make here.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;WDM, WDF or 3&lt;sup&gt;rd&lt;/sup&gt; party toolkits – &lt;/b&gt;What is your policy on drivers: &lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;should they be the traditional WDM model, the new WDF models or a 3&lt;sup&gt;rd&lt;/sup&gt; party model?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Development Environment – &lt;/b&gt;What do you require for a development environment?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;This should be simple; namely a specific version of the DDK/WDK, but if you don’t spec it you can get anything.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Windows Logo –&lt;/b&gt; Do you want your drivers to have a Windows Logo?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;This impacts the routines, models, and methodology for developing drivers.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Static Verification tools – &lt;/b&gt;What is your policy on code passing static and dynamic verification tools?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Do you require code to be PREfast clean?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Does your code need to run through Static Driver Verifier?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Do you require annotations to aid the above tools in finding bugs?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Do you use PC-Lint and do you have your own definitions file?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Testing – &lt;/b&gt;Does the code need to pass Driver Verifier?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;For Server 2003, does your code need to pass Call Usage Verifier? Is there a code coverage tool and standards to be met?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;What other tests are required?&lt;/font&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Diagnostics – &lt;/b&gt;What is your model for tracing and debug prints?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Do you require event logging?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Do you expect data to be presented to the performance monitor?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Is there information going to Windows Management Instrumentation?&lt;/font&gt;&lt;/p&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt;&lt;span style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Coding style –&lt;/b&gt; This is the one that causes the biggest fights.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;You should probably not be dictating the location of braces or indentation, but there are things that make code easier to review or for the next person to work on it.&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt; &lt;/blockquote&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt;TEXT-INDENT:0in;mso-list:none;tab-stops:.5in;"&gt;&lt;font size="3"&gt;The above is not a complete list, but even more needs to be considered. &lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/span&gt;If you do not have the resources in-house, consider engaging a consultant to develop the guidelines based on your current practice.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt;TEXT-INDENT:0in;mso-list:none;tab-stops:.5in;"&gt;&lt;font size="3"&gt;You do not want to end up like one firm I know that hired a contractor to develop a driver.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;When the driver was delivered, the company discovered the contractor had used a toolkit the firm did not own and would cost over $100,000 to buy for the developers and train them on.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;The choice between slipping the product schedule and buying the tool was not a pleasant one.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;With some preparation up front in specifying coding guidelines, such scenarios can be prevented and time and money saved in the end.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=985546" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/windrvr/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Driver+Design/default.aspx">Driver Design</category></item><item><title>Tag, you're it</title><link>http://msmvps.com/blogs/windrvr/archive/2007/06/15/tag-you-re-it.aspx</link><pubDate>Fri, 15 Jun 2007 23:31:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:965502</guid><dc:creator>DonBurn</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/windrvr/rsscomments.aspx?PostID=965502</wfw:commentRss><comments>http://msmvps.com/blogs/windrvr/archive/2007/06/15/tag-you-re-it.aspx#comments</comments><description>&lt;p&gt;I’ve been spending the last couple of days tracking down a bug in a driver I am writing. The effort reminded me of how great tags on memory allocations and frees can be. Also, the work reminded me that there are at least a couple of features Microsoft does not promote and I rarely see. &lt;/p&gt;
&lt;p&gt;For the uninitiated, tags are a four character value that is passed as an argument in memory allocation calls. The tag gives you a way to identify what the memory was allocated for by having a different tag for each common structure allocated. Here is a common problem: many driver developers commonly assume that they have only one tag for their whole driver because so many of the common samples do this. There is nothing stopping you from having multiple tags, and in fact there is a strong reason to have them. &lt;/p&gt;
&lt;p&gt;Right now I am developing a file system mini-filter that has twenty-one different tags it uses for allocations. All the major buffer types and context blocks each have a unique tag for their allocations and frees. &lt;/p&gt;
&lt;p&gt;Yes, I said frees. Part of the reason to have multiple tags is that you can also put the tag on the free of the memory by using the call ExFreePoolWithTag. Unfortunately, this call has been described as worthless in Walter Oney’s Programming the Windows Driver Model and is incorrectly documented by Microsoft. &lt;/p&gt;
&lt;p&gt;The value of ExFreePoolWithTag is when you combine it with a tag with the PROTECTED_POOL bit set. This bit requires that you free the memory with ExFreePoolWithTag, and the OS will bug check if the memory being freed does not have the matching tag. Unfortunately, PROTECTED_POOL is not documented except in include files, and is not used by any Microsoft sample. Using ExFreePoolWithTag with PROTECTED_POOL tags gives you an automatic check that you are freeing what you intended to. &lt;/p&gt;
&lt;p&gt;You do have to be careful on memory you allocate that the system will be freeing, since Windows will not know what tag you are using, so the system frees everything without tags. For everything except the rare instance where the system frees the memory, using multiple tags with PROTECTED_POOL is worthwhile. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=965502" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/windrvr/archive/tags/General/default.aspx">General</category><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Diagnostics/default.aspx">Diagnostics</category><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Driver+Design/default.aspx">Driver Design</category><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Tools/default.aspx">Tools</category></item><item><title>Crossing the Undocumented Line</title><link>http://msmvps.com/blogs/windrvr/archive/2007/05/27/crossing-the-undocumented-line.aspx</link><pubDate>Sun, 27 May 2007 16:32:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:928577</guid><dc:creator>DonBurn</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/windrvr/rsscomments.aspx?PostID=928577</wfw:commentRss><comments>http://msmvps.com/blogs/windrvr/archive/2007/05/27/crossing-the-undocumented-line.aspx#comments</comments><description>&lt;p class="MsoNormal" style="MARGIN:0in 0in 6pt;"&gt;&lt;font size="3"&gt;As a consultant who has more than once taken on projects Microsoft has said are impossible, many people assume I often use undocumented calls in Windows in my work.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;In fact, I try to avoid them if at all possible, and am extremely careful in crossing the &lt;i style="mso-bidi-font-style:normal;"&gt;undocumented line.&lt;/i&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 6pt;"&gt;&lt;font size="3"&gt;A developer should ask a set of questions when considering using an undocumented technique; these are:&lt;/font&gt;&lt;/p&gt;
&lt;ol style="MARGIN-TOP:0in;"&gt;
&lt;li class="MsoNormal" style="MARGIN:0in 0in 6pt;mso-list:l0 level1 lfo1;tab-stops:list .5in;"&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Is it really needed?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/b&gt;Before anything else, ask yourself if there is any other way to do this.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Be sure to not constrain your design when you ask this question.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;For instance, requiring something be done in the kernel may force an undocumented technique where building a helper application could allow a documented approach.&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;
&lt;li class="MsoNormal" style="MARGIN:0in 0in 6pt;mso-list:l0 level1 lfo1;tab-stops:list .5in;"&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;How undocumented is it?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/b&gt;There is a lot of variation here; there are plenty of undocumented calls that are never mentioned by Microsoft.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;These I consider pretty undocumented even if there are examples on the web.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt;&lt;font size="3"&gt;There are calls that have been in the Microsoft DDK include files for years, but are not documented.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;For example, a number of the ZwXXX calls have options that are not described in the documentation, but are in the includes with all the needed data structures.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;font size="3"&gt;Another variant of undocumented is the call that is documented in later OS’s but works for your driver in previous versions.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;In the early days of the DDK, there were calls in the samples that were not documented.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;These calls are not completely safe, but they are better than the totally undocumented calls.&lt;/font&gt;&lt;/p&gt;
&lt;ol style="MARGIN-TOP:0in;" start="3"&gt;
&lt;li class="MsoNormal" style="MARGIN:0in 0in 6pt;mso-list:l0 level1 lfo1;tab-stops:list .5in;"&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Which OS’s require the undocumented stuff?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/b&gt;If you are looking at an undocumented call for an older OS, the function you need in later OS’s is not present, so you are probably safer than expecting a call to be there in the future.&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;
&lt;li class="MsoNormal" style="MARGIN:0in 0in 6pt;mso-list:l0 level1 lfo1;tab-stops:list .5in;"&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;What is the scope of the input and usage of the undocumented stuff?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;&lt;/b&gt;If you are using the undocumented calls in a constrained environment you are in a safer position than a having a widespread and flexible use.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;It is hard to test any piece of code, but if the inputs or patterns of use vary, the testing of this area just got harder.&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;
&lt;li class="MsoNormal" style="MARGIN:0in 0in 6pt;mso-list:l0 level1 lfo1;tab-stops:list .5in;"&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;What is the fallback plan? &lt;/b&gt;If you do go ahead and do this, what will you do if it breaks tomorrow?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Has your design kept the undocumented stuff limited so it can be replaced in the code?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Is there likely to be an alternative for the replacement?&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;What is the plan if there is no replacement?&lt;b style="mso-bidi-font-weight:normal;"&gt;&lt;/b&gt;&lt;/font&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p class="MsoNormal" style="MARGIN:0in 0in 6pt;"&gt;&lt;font size="3"&gt;If you decide you have to cross the line and use an undocumented call, there are some things you should be doing:&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;tab-stops:list .5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-bidi-font-family:Symbol;mso-fareast-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Let the customer know &lt;/b&gt;– Document the call and the answers to the above questions to the customer or your management.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;Crossing the line should be a decision made by more than just the developer.&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt 0.5in;tab-stops:list .5in;"&gt;&lt;span style="FONT-FAMILY:Symbol;mso-bidi-font-family:Symbol;mso-fareast-font-family:Symbol;"&gt;&lt;span style="mso-list:Ignore;"&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="FONT:7pt &amp;#39;Times New Roman&amp;#39;;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;b style="mso-bidi-font-weight:normal;"&gt;Plan for a long testing cycle &lt;/b&gt;– You have chosen to use something you cannot rely on, so your testing pain just went up.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;You really need to test all the likely OS configurations the end user could have.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;This means not just testing on the current version of a Windows OS, but instead the base, all service packs, and the &lt;i style="mso-bidi-font-style:normal;"&gt;current version&lt;/i&gt; , i.e., all the latest hotfixes and downloads.&lt;span style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/span&gt;For 32-bit Windows, that is sixteen full tests if you want to support Windows 2000 up to Vista!&lt;/font&gt;&lt;/p&gt;
&lt;p class="Style1" style="MARGIN:0in 0in 6pt;TEXT-INDENT:0in;mso-list:none;tab-stops:.5in;"&gt;&lt;font size="3"&gt;There are times to cross the line, but be sure you have a plan and a strong justification before you enter the undocumented territory.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=928577" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Driver+Design/default.aspx">Driver Design</category></item><item><title>Using the event log in your driver</title><link>http://msmvps.com/blogs/windrvr/archive/2007/02/19/using-the-event-log-in-your-driver.aspx</link><pubDate>Mon, 19 Feb 2007 22:02:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:599084</guid><dc:creator>DonBurn</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/windrvr/rsscomments.aspx?PostID=599084</wfw:commentRss><comments>http://msmvps.com/blogs/windrvr/archive/2007/02/19/using-the-event-log-in-your-driver.aspx#comments</comments><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;I wrote previously that drivers should use the event log.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;This time I am going to give some things to consider when using events. The challenge for using the event log is that many components use it poorly.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;The two common problems are superfluous messages and lazy definitions.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;The event log is commonly configured as a circular log with a limited capacity.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Thus, having a bunch of superfluous messages can cause the important events that lead up to a failure to be lost. If you want to put in things like the driver started or stopped, provide a registry value or other control so these can be disabled.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;The second problem, lazy definitions, happens because building the message catalog where the event strings are stored and setting up the registry for it require additional steps.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Developers looked around and found that a number of the common Microsoft error codes took a string for the log entry, and decided to use the Microsoft definition instead of their own.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;This is a poor approach for two reasons.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;First, since all your errors are coded as the same event, this makes it hard for tools to look for problems in the log.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Second, the event log is designed for internationalization but the strings you dump from your driver will all be in one language.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;For internationalization, consider making the message catalog where the text of the messages resides a separate file, rather than including it in the device driver.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;The advantage of this is that you can provide the components needed for a support organization to add a new language without having to sign the driver again.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;So what should go in the event log?&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Some obvious things are:&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Style1 style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Failures in DriverEntry, AddDevice and Unload – In all these cases, there is no user request to which to report the problem.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Style1 style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Resource failures – These include a malfunction in the hardware or supporting software (for instance, a service that supports the driver) that impacts many requests.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Style1 style="MARGIN:0in 0in 6pt 0.5in;"&gt;&lt;SPAN style="FONT-FAMILY:Symbol;mso-fareast-font-family:Symbol;mso-bidi-font-family:Symbol;"&gt;&lt;SPAN style="mso-list:Ignore;"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT:7pt 'Times New Roman';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;Anomalous behavior – This is anything that is unexpected, whether it fails a request or not.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;If something you really didn’t expect occurs, even if the driver handles it, log it.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=Style1 style="MARGIN:0in 0in 6pt;TEXT-INDENT:0in;mso-list:none;tab-stops:.5in;"&gt;&lt;FONT size=3&gt;My overall message is that you should add the event log to the diagnostic capabilities you provide your support people and your customers. If you already do this, great!&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;And if you already have working guidelines for event log use, please share them with a comment to this blog.&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=599084" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Diagnostics/default.aspx">Diagnostics</category><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Driver+Design/default.aspx">Driver Design</category></item><item><title>Why your driver should use the event log</title><link>http://msmvps.com/blogs/windrvr/archive/2007/02/18/why-your-driver-should-use-the-event-log.aspx</link><pubDate>Sun, 18 Feb 2007 14:34:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:592884</guid><dc:creator>DonBurn</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/windrvr/rsscomments.aspx?PostID=592884</wfw:commentRss><comments>http://msmvps.com/blogs/windrvr/archive/2007/02/18/why-your-driver-should-use-the-event-log.aspx#comments</comments><description>&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;Do you use the event log in your driver? &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;Event logging should be standard in almost every driver, yet few drivers support logging.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Event logging is the place to record anomalous conditions and events that are detected by your code. Specifically, it is the recognized way to report errors that are not related to a particular request to the device.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;The event log consists of small records about events of interest.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;The record is based on an NTSTATUS code, whether it is a standard code or a custom status code for your software.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Think of the event log as a series of alerts to inform you of what is happening on the system.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;If you haven’t looked at it lately, open the event viewer from &lt;I style="mso-bidi-font-style:normal;"&gt;Administrative Tools, &lt;/I&gt;and look at the entries since the last boot of your machine.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;There are articles for developers that contend that no one reads the event log.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Yes, the normal user does not look at it, but system administrators certainly do.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;When there is a problem with a system, the event log is the first place admins will look to establish a chronology of what happened and possibly see what failed.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;The event log is also integrated into many network management tools that administrators use to monitor system health.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;So why don’t more drivers use the event log?&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Part of the reason for this is Microsoft.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;The DDK used to provide a specific sample to illustrate logging, but this was removed years ago.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;Worse, some Microsoft developers do not understand the use of the event log.&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;A few years ago a Microsoft talk confused the purpose of Event Logging with the more recent Event Tracing for Windows (ETW).&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;ETW is a great capability, but it is designed to provide detailed diagnostics for the developer, not simple alerts for the administrator.&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN:0in 0in 6pt;"&gt;&lt;FONT size=3&gt;So if you are not using the event log in your drivers, ask yourself or your developers, why aren’t you?&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;If you are using the event log, there are a number of things to consider, but that needs to wait for another post.&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=592884" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Diagnostics/default.aspx">Diagnostics</category><category domain="http://msmvps.com/blogs/windrvr/archive/tags/Driver+Design/default.aspx">Driver Design</category></item></channel></rss>