<?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 : Diagnostics</title><link>http://msmvps.com/blogs/windrvr/archive/tags/Diagnostics/default.aspx</link><description>Tags: Diagnostics</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><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>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>