{"id":191,"date":"2007-09-03T10:09:24","date_gmt":"2007-09-03T10:09:24","guid":{"rendered":"https:\/\/driverentry.com.br\/en\/2007\/09\/03\/did-you-say-i-dont-like-blue-screens\/"},"modified":"2026-07-27T20:44:45","modified_gmt":"2026-07-27T20:44:45","slug":"did-you-say-i-dont-like-blue-screens","status":"publish","type":"post","link":"https:\/\/driverentry.com.br\/en\/2007\/09\/03\/did-you-say-i-dont-like-blue-screens\/","title":{"rendered":"Did you say I don&#8217;t like Blue Screens?"},"content":{"rendered":"<div style=\"text-align: right;\"><a href=\"https:\/\/driverentry.com.br\/2007\/09\/03\/como-assim-eu-nao-gosto-de-tela-azul\/\"><img loading=\"lazy\" decoding=\"async\" title=\"Em Portugu\u00eas\" src=\"https:\/\/driverentry.com.br\/en\/wp-content\/uploads\/2026\/07\/br.gif\" alt=\"\" width=\"21\" height=\"19\" \/><\/a><\/div>\n<p><img decoding=\"async\" style=\"float: right; margin: 0px 10px;\" src=\"https:\/\/driverentry.com.br\/en\/wp-content\/uploads\/2026\/07\/bsod_tshirt.jpg\" border=\"0\" alt=\"\" \/><\/p>\n<p>I&#8217;m not saying I love them. Blue screen is a sign that something went wrong but, it is better you see it than a customer calling you saying that he saw one. So we need to do our best to make it make it appear while your driver is under test. I&#8217;ve seen programmers escaping the blue screen just trying to hide themselves behind an exception handler. I do not need to say this is not that useful. This way, you just defer to find mistakes that you or someone else will find eventually. Computers that are using your drivers may have a sudden reboot here or there. But even blue screens can happen, it&#8217;s all a matter of luck; however, your customers can realize that using your drivers makes them too unlucky. In this post, I&#8217;ll give you some tips about how we can see more blue screens in our test drivers.<\/p>\n<h3>Going through with F8<\/h3>\n<p>Do not take this as <em>&#8220;Test Yourself,&#8221;<\/em> but take it as testing all the returning codes that you can. Remember that if something gets wrong, it is not just a <em>MessageBox<\/em> that will appear, but usually, everything ends up in &#8220;blue&#8221;, sooner or later. Let&#8217;s hope for &#8220;sooner&#8221;. I often use to say that every code deserves, at least, an F8 walkthrough, which is my <em>Step Into<\/em> key. Yeah, I know it&#8217;s different of the usual one, but when I started using <strong>Visual C\/C++ 1.52<\/strong>, its keyboard layout was it. But back to the point, once I have made a function that should simply read a file, I went through the code with F8 and received a return code that was not <strong>STATUS_SUCCESS<\/strong>, but passed the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff565436(VS.85).aspx\">NT_SUCCESS()<\/a> macro. The haste induced me to ignore it. It was not an error, it was just a warning. Weeks later, the test team told me that, for any reason, the driver was returning garbage when reading the file. A bit of debugging showed me that same returning code. Only after having loked at its definition in the file <strong>ntstatus.h<\/strong> I could understand everything.<\/p>\n<div style=\"font-family: Courier New; font-size: 9pt; color: black; background: #A4F64C; border: 1px outset; padding: 0 0 0 5px;\">\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: green;\">\/\/<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\"><span style=\"color: green;\">\/\/ MessageId: STATUS_PENDING<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: green;\">\/\/<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\"><span style=\"color: green;\">\/\/ MessageText:<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: green;\">\/\/<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\"><span style=\"color: green;\">\/\/  The operation that was requested is pending completion.<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: green;\">\/\/<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\"><span style=\"color: blue;\">#define<\/span> STATUS_PENDING                   ((NTSTATUS)<span style=\"color: purple;\">0x00000103L<\/span>)    <span style=\"color: green;\">\/\/ winnt<\/span><\/pre>\n<\/div>\n<p>During debug sessions, the system has enough time to do the I\/O that was deferred previously; but, freely running the code, the story can change.<\/p>\n<p>A code that has passed on its F8 test can run in various existing and imaginable environments. Therefore, this first phase is just to remove the grosser errors. After that, it is the test team should beat the victim. There are people who really have a gift to test software. I had worked at a company where the person who used to test the products should have had a personal problem with the software that we produced (or with us, go figure!). I could test the software for days, but when I delivered it for testing, it did not take half an hour for him to call me back saying that phrase that has become his trademark: <em>&#8220;Too bad !!!&#8221;<\/em>. There was no explanation. We used to say that his PC had been formatted over an Indian burial ground. No wonder that developer&#8217;s testing is so frowned upon.<\/p>\n<h3>Using ASSERT<\/h3>\n<p>I imagine most of you have already heard from <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff542107(VS.85).aspx\">ASSERT<\/a> macro. This macro is intended to ensure that a certain condition is true. If the condition is false, a blue screen just pops up. <strong>Wow, what an incredible macro that helped us very much!<\/strong> Yeah, I know, it is not quite that. Actually, this is the behavior we would have if the debugger was not attached to the system. Then, that macro would be perfect only in <strong>Checked<\/strong>. Do I must remind you that  <em>Checked<\/em> means <em>Debug<\/em> and <em><strong>Free<\/strong> <span style=\"font-style: normal;\">means <\/span>Release<\/em>? Well, already done. If we take a look at its definition, we will see that the obvious thing has already been thought.<\/p>\n<div style=\"font-family: Courier New; font-size: 9pt; color: black; background: #A4F64C; border: 1px outset; padding: 0 0 0 5px;\">\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: blue;\">#if<\/span> DBG<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">&nbsp;<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: blue;\">#define<\/span> ASSERT( exp ) \\<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">    ((!(exp)) ? \\<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\">        (RtlAssert( #exp, __FILE__, __LINE__, NULL ),FALSE) : \\<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">        TRUE)<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\">...<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">&nbsp;<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: blue;\">#else<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">&nbsp;<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: blue;\">#define<\/span> ASSERT( exp )         ((<span style=\"color: blue;\">void<\/span>) <span style=\"color: purple;\">0<\/span>)<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">&nbsp;<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\">...<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">&nbsp;<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: blue;\">#endif<\/span> <span style=\"color: green;\">\/\/ DBG<\/span><\/pre>\n<\/div>\n<p><strong>But what happens if we have the debugger attached to the system?<\/strong> Good question, this is a really interesting question; I&#8217;m glad you have asked it. Has anyone ever told you that you have some knack for programming? Anyway, I have changed one of our examples to enforce this condition.<\/p>\n<div style=\"font-family: Courier New; font-size: 9pt; color: black; background: #A4F64C; border: 1px outset; padding: 0 0 0 5px;\">\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\"><span style=\"color: blue;\">extern<\/span> <span style=\"color: #a31515;\">\"C\"<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObj,<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\">                     IN PUNICODE_STRING pusRegistryPath)<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">{<\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\">    <span style=\"color: green;\">\/\/-f--&gt; I think I'm sure that this count is right.<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">    ASSERT(<span style=\"color: purple;\">1<\/span> + <span style=\"color: purple;\">1<\/span> == <span style=\"color: purple;\">3<\/span>);<\/pre>\n<\/div>\n<p>If the condition fails and we have a <em>kernel debugger<\/em> attached to the system, it will display the condition that had failed at the output window and it will request us an answer among the  four alternatives, as it is shown below.<\/p>\n<div style=\"text-align: center;\"><img decoding=\"async\" src=\"https:\/\/driverentry.com.br\/en\/wp-content\/uploads\/2026\/07\/AssertError.png\" alt=\"\" \/><\/div>\n<p>As you can see, the <em>ASSERT<\/em> is practical, easy and not fattening. It just requires a bit of brain, as well. I&#8217;m sying this because we&#8217;ve all had bad days, and after 11:00 pm, no programmers should answer for any produced code. Once, it took me some time to figure out why the code below was not working properly. Although everything was working perfectly fine when compiled on <em>Checked,<\/em> it seemed to me that a certain function simply was not being called in <em>Free<\/em>. If you take one more looking at the definition of this macro, you will see that the condition disappears when compiled in <em>Free<\/em>, and in this case, the call too.<\/p>\n<div style=\"font-family: Courier New; font-size: 9pt; color: black; background: #A4F64C; border: 1px outset; padding: 0 0 0 5px;\">\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\">    <span style=\"color: green;\">\/\/-f--&gt; Programming is just not enough, thinking is required.<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FFFFFF;\">    <span style=\"color: green;\">\/\/      &lt;&lt; Don't copy this &gt;&gt;<\/span><\/pre>\n<pre style=\"margin: 0px; padding: 0 0 0 5px; background: #FAFAFA;\">    ASSERT(DoSomeThing() == STATUS_SUCCESS);<\/pre>\n<\/div>\n<h3>A system in <span style=\"font-style: italic;\">Checked<\/span><\/h3>\n<p>Wouldn&#8217;t it be nice to have an entire operating system full of ASSERTs and tests to detect the slightest sign of trouble and on finding one, the system would present us with a nice blue screen? Well, you&#8217;ve probably heard of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff543457(VS.85).aspx\">Checked Build<\/a> versions. They are exactly what I have just written. An entire operating system built on <em>Checked<\/em>. This means that all of ASSERTs that were at the sources have been included in the final binaries and they are checking the system for you. It may seem silly to have to install your driver on one of these systems, but believe me, it is worth. I&#8217;ve had drivers that worked very well for months until my manager suggested that they should be tested on <em>Checked<\/em> versions. From the top of my arrogance, I thought to myself: &#8220;I see no reason for that&#8221;. Well, we are always learning as we are living. The test machine has not even has started with my drivers. Several blue screens were shown, one after another. <em>Checked Build<\/em> versions are still able to check for <a href=\"http:\/\/en.wikipedia.org\/wiki\/Deadlock\">deadlocks<\/a>. Could you guess what would happen if a<em> spinlock<\/em> was held for more than a certain time? I bet you do.<\/p>\n<p><strong>Since <\/strong><em><strong>Checked Build<\/strong><\/em><strong> versions are foolproof, I can use them as my default system?<\/strong> Actually you can, but everything is much slower, thousands of checks are being made all the time and the code has no optimization applied. In a fresh installation without installing any additional software, you can find ASSERTs at <em>Internet Explorer<\/em> or other programs. That&#8217;s right, not just the kernel is <em>Checked<\/em>, but the entire system is as well. You always have to let a <em>kernel debugger<\/em> attached to your system, because the slightest hint of smoke would be more than an enough reason for one more blue screen.<\/p>\n<p><strong>If my driver has passed by the <\/strong><em><strong>Checked Build,<\/strong><\/em><strong> then is the driver perfect?<\/strong> Sorry to disappoint you. Remember that the performance impact caused by so many tests can hide problems like <a href=\"http:\/\/en.wikipedia.org\/wiki\/Race_condition\">race conditions<\/a>. The ideal is to test your drivers in both versions. One setting allows us having only the system image and <strong>HAL<\/strong> in <em>Checked,<\/em> while the rest of the system stays in <em>Free<\/em>. This may provide you with additional tests in the kernel while the rest of the system runs the lighter version. <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ff547196(VS.85).aspx\">This link<\/a> explains how.<\/p>\n<h3>OK, is my driver beautiful now?<\/h3>\n<p>Actually, this still is only the minimum you should do. Another excellent tool for generating blue screens is the <strong>Driver Verifier<\/strong>. This application works in conjunction with the system to track actions from a list of drivers composed by you. From Windows 2000, <em>DriverVerifier<\/em> comes already installed. Try it now! It doesn&#8217;t require any skill or even practice. Type &#8220;Verifier&#8221; at the Windows <em>&#8220;Run&#8230;&#8221; <\/em>window and a simple <em>Wizard<\/em> starts. As I intend to finish this post still alive, I won&#8217;t describe how to use this tool step by step, but there are several links on the <a href=\"http:\/\/www.microsoft.com\/whdc\/DevTools\/tools\/DrvVerifier.mspx\">product page<\/a> that can help you with this.<\/p>\n<h3>OK, now I know you really love Blue Screens!<\/h3>\n<p>To get an idea of how importnat a search for blue screens is for a software company, Microsoft promotes <a href=\"http:\/\/www.microsoft.com\/whdc\/driver\/filterdrv\/IFSPlugfest.mspx\">IFS Plug Fest<\/a> in order to test the interoperability of different products that implement <strong>File Systems<\/strong> or filters for them. The event is for free, but each company must pay for travel expenses and lodging of its representatives. In these meetings, the professionals around the world gather together to do the tests with each other and they can get in touch and ask possible questions concerning this complex model of development. There are also sponsored seminars that discuss common problems faced by this community. I have not been at one of these, but maybe one day I will be able to.<\/p>\n<h3>Stay calm, there are even more<\/h3>\n<p>Beyond the mentioned tools, there are some others that I could not forget mentioning; however, I won&#8217;t take long on explaining how each of them works.<\/p>\n<ul>\n<li><a href=\"http:\/\/www.microsoft.com\/whdc\/DevTools\/tools\/PREfast.mspx\">Pre<span style=\"font-style: italic;\">f<\/span>ast<\/a> &#8211; A tool that analyses the source code to be compiled by the DDK, looking for usual programming mistakes for Kernel drivers.<\/li>\n<li><a href=\"http:\/\/www.microsoft.com\/whdc\/DevTools\/tools\/SDV.mspx\">Static Driver Verifier<\/a> &#8211; That tool makes a binary analysis on the driver file already built. The test takes longer but, it detects more defects than using Pre<em>f<\/em>ast.<\/li>\n<li><a href=\"http:\/\/www.microsoft.com\/whdc\/DevTools\/HCTKit.mspx\">Hardware Compatibility Test<\/a> &#8211; A set of software to apply tests to get drivers certified by Microsoft. It was discontinued a while ago.<\/li>\n<li><a href=\"http:\/\/www.microsoft.com\/whdc\/DevTools\/WDK\/DTM.mspx\">Driver Test Manager<\/a> &#8211; That&#8217;s the new test software used to get your drivers certified.<\/li>\n<\/ul>\n<p>After so many blue screens, only drinking some coffee can help us!.<br \/>\nCYA!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m not saying I love them. Blue screen is a sign that something went wrong but, it is better you see it than a customer calling you saying that he saw one. So we need to do our best to make it make it appear while your driver is under test. I&#8217;ve seen programmers escaping [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-191","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/posts\/191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/comments?post=191"}],"version-history":[{"count":3,"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/posts\/191\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/posts\/191\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/media?parent=191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/categories?post=191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/driverentry.com.br\/en\/wp-json\/wp\/v2\/tags?post=191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}