<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Windows Driver Kit (WDK) Documentation Blog : code annotation</title><link>http://blogs.msdn.com/wdkdocs/archive/tags/code+annotation/default.aspx</link><description>Tags: code annotation</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Resources to help you annotate code for static analysis</title><link>http://blogs.msdn.com/wdkdocs/archive/2008/04/16/resources-to-help-you-annotate-code-for-static-analysis.aspx</link><pubDate>Thu, 17 Apr 2008 00:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8399604</guid><dc:creator>wdkblog</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/wdkdocs/comments/8399604.aspx</comments><wfw:commentRss>http://blogs.msdn.com/wdkdocs/commentrss.aspx?PostID=8399604</wfw:commentRss><description>&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=4&gt;What are annotations?&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo2; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Essentially comments in the code that can be understood by static analysis tools (PREfast for Drivers, &lt;B style="mso-bidi-font-weight: normal"&gt;/analyze&lt;/B&gt; option in Visual Studio)&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=4&gt;Why are annotations needed?&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo1; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Because they find bugs!&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo1; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Annotations describe the contract between the calling function and the called function &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo1; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;The static tools use the annotations to verify the contract specifications (initialization, return values, and so on.)&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l3 level1 lfo1; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;They improve the results of static analysis tools (for example, the signal-to-noise ratio) &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 12pt 0in 10pt"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;If you have looked at the header files in the Windows Driver Kit (WDK), or looked at the source code for some of the sample drivers in the WDK, you might have noticed modifiers that are associated with function parameters. The modifiers, such as &lt;B&gt;__in&lt;/B&gt;, &lt;B&gt;__out, __ecount(&lt;I style="mso-bidi-font-style: normal"&gt;size&lt;/I&gt;),&lt;/B&gt; and &lt;B&gt;__bcount(&lt;I style="mso-bidi-font-style: normal"&gt;size&lt;/I&gt;),&lt;/B&gt; are called &lt;I style="mso-bidi-font-style: normal"&gt;annotations&lt;/I&gt;, and they describe how a function operates and interacts with its parameters or return values. Annotations are &lt;/SPAN&gt;ignored by the compiler, but are understood by static analysis tools, such as &lt;/FONT&gt;&lt;/FONT&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkID=116387&amp;amp;clcid=0x409" mce_href="http://go.microsoft.com/fwlink/?LinkID=116387&amp;amp;clcid=0x409"&gt;&lt;FONT face="Times New Roman" size=3&gt;PREfast for Drivers&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt; or by the &lt;SPAN style="mso-bidi-font-weight: bold"&gt;code analysis option &lt;/SPAN&gt;in Visual Studio (&lt;B&gt;/analyze&lt;/B&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;). &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 12pt 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;Annotations can provide additional information about a parameter that is not otherwise expressible. By adding annotations to your driver code, you can improve the accuracy of results from the static analysis tools. And in turn, by adding annotations, you gain a better understanding how your code is supposed to work.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Because annotations and static tools can help you catch bugs earlier in the development process (during compilation), you can improve the effectiveness of the time you spend testing and debugging.&lt;/SPAN&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 12pt 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;You add annotations on the driver-supplied function prototypes and function definitions in your driver source code. You can use as many or as few annotations as you need. The payback for all this work is that you benefit from the annotations every time you call those functions and run the static analysis tools. Additionally, you benefit from the annotations that Microsoft has added to the system-supplied functions. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=4&gt;Example of an annotated driver-supplied function &lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The following is a function declaration from the &lt;I style="mso-bidi-font-style: normal"&gt;Toaster&lt;/I&gt; sample function driver in the WDK (&lt;I style="mso-bidi-font-style: normal"&gt;WDKroot&lt;/I&gt;\&lt;I style="mso-bidi-font-style: normal"&gt;version&lt;/I&gt;&lt;B&gt;\src\general\toaster\func\&lt;/B&gt;). This function uses some simple annotations that enable PREfast for Drivers to report errors if it finds that uninitialized values are used incorrectly when this function is called.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;NTSTATUS&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;ToasterQueryWmiDataBlock(&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__in&lt;/SPAN&gt;&lt;/B&gt; PDEVICE_OBJECT DeviceObject,&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;_&lt;SPAN style="COLOR: red"&gt;_in&lt;/SPAN&gt;&lt;/B&gt; PIRP Irp,&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__in&lt;/SPAN&gt;&lt;/B&gt; ULONG GuidIndex,&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;_&lt;B style="mso-bidi-font-weight: normal"&gt;_in&lt;/B&gt;&lt;/SPAN&gt; ULONG InstanceIndex,&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__in&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="COLOR: red"&gt; &lt;/SPAN&gt;ULONG InstanceCount,&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__inout&lt;/SPAN&gt;&lt;/B&gt; PULONG InstanceLengthArray,&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__in&lt;/SPAN&gt;&lt;/B&gt; ULONG BufferAvail,&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__out_bcount(BufferAvail)&lt;/SPAN&gt;&lt;/B&gt; PUCHAR Buffer&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;);&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;o:p&gt;&lt;FONT face=Consolas&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/PRE&gt;
&lt;H3 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=3&gt;Annotations to indicate Input and output parameters&lt;/FONT&gt;&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;In the&lt;I style="mso-bidi-font-style: normal"&gt; &lt;/I&gt;&lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;ToasterQueryWmiDataBlock&lt;/I&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt; function, the &lt;B&gt;__in&lt;/B&gt; annotation indicates the parameter is an input to a function. That is, the parameter must be valid (&lt;I&gt;initialized&lt;/I&gt;) before the function call. Conversely, an &lt;B&gt;__out&lt;/B&gt; annotation indicates that the parameter is initialized after the function call and thus is safe to use as an &lt;B&gt;__in&lt;/B&gt; parameter to a subsequent function. The annotations can be combined.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If a parameter is marked &lt;B&gt;__inout&lt;/B&gt;, the parameter is initialized before the call and thus it is assumed to be safe to use as an &lt;B&gt;__in&lt;/B&gt; parameter to a subsequent function. These annotations are particularly useful for pointer parameters. In the C language, a parameter is passed by value, which makes it impossible to tell from the function prototype whether the pointer is intended as input to the function, output from the function, or both. Use the &lt;B&gt;__in&lt;/B&gt;, &lt;B&gt;__out&lt;/B&gt;, and &lt;B&gt;__inout&lt;/B&gt; annotations to direct the static analysis tools to check parameters that have these annotations and report any errors if it finds that uninitialized values are used incorrectly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H3 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=3&gt;Annotations to indicate buffer parameters&lt;/FONT&gt;&lt;/H3&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;Functions that read or write to buffers are a potential source of bugs and can represent a real security concern. When you add annotations for buffer parameters, you can enable the static tools to find buffer overflow and buffer underflow conditions. In the&lt;I style="mso-bidi-font-style: normal"&gt; &lt;/I&gt;&lt;/SPAN&gt;&lt;I style="mso-bidi-font-style: normal"&gt;ToasterQueryWmiDataBlock &lt;/I&gt;example&lt;SPAN style="mso-bidi-font-weight: bold"&gt;, the &lt;B&gt;__out_bcount(BufferAvail)&lt;/B&gt; annotation indicates that the parameter is a buffer that is initialized after the function call and that the size of the buffer is specified by the &lt;I style="mso-bidi-font-style: normal"&gt;BufferAvail&lt;/I&gt; parameter.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The byte-count and element -count buffer annotations &lt;B&gt;__bcount(&lt;/B&gt;&lt;I style="mso-bidi-font-style: normal"&gt;size&lt;/I&gt;&lt;B&gt;)&lt;/B&gt;, and &lt;B&gt;__ecount(&lt;/B&gt;&lt;I style="mso-bidi-font-style: normal"&gt;size&lt;/I&gt;&lt;B&gt;)&lt;/B&gt; provide information that ensures that neither the calling function nor the called function can access data outside the bounds of the buffer (the &lt;I style="mso-bidi-font-style: normal"&gt;size &lt;/I&gt;of the buffer). The annotations can also express the difference between available memory and initialized memory, so that access to uninitialized memory can be detected. For an excellent discussion about how annotations can help catch buffer problems, see Michael Howard's blog &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;A href="http://blogs.msdn.com/michael_howard/archive/2006/05/19/602077.aspx" mce_href="http://blogs.msdn.com/michael_howard/archive/2006/05/19/602077.aspx"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT face="Times New Roman" size=3&gt;A Brief Introduction to the Standard Annotation Language&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=4&gt;Example of an annotated system-supplied function &lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="mso-bidi-font-weight: bold"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;You can benefit from annotations simply by using the static analysis tools on your driver code. To save you trouble and to catch problems in Windows code, some system-supplied functions are annotated. These annotations include driver-specific annotations (using the prefix &lt;B&gt;__drv&lt;/B&gt;) that ensure proper usage of the DDI.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For example, there are driver annotations that specify the proper IRQL at which a function can be called, and annotations that describe the correct use of memory, spin locks, and other resources . &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN style="FONT-SIZE: 11pt; LINE-HEIGHT: 115%; FONT-FAMILY: Calibri; mso-bidi-font-weight: bold"&gt;For example, &lt;B&gt;WdfSpinLockAcquire&lt;/B&gt; method is a KMDF system-supplied function that is declared in &lt;I&gt;Wdfsync.h. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/I&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;o:p&gt;&lt;FONT face=Consolas&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;_&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;_drv_maxIRQL(DISPATCH_LEVEL)&lt;/SPAN&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;VOID&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;FORCEINLINE&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;WdfSpinLockAcquire(&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__in&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;__drv_savesIRQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;__drv_neverHold(SpinLock)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="COLOR: red"&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;__drv_acquiresResource(SpinLock)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WDFSPINLOCK SpinLock&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;)&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;{&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;((PFN_WDFSPINLOCKACQUIRE) WdfFunctions[WdfSpinLockAcquireTableIndex])(WdfDriverGlobals, SpinLock);&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;FONT face=Consolas&gt;}&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;FONT face=Calibri size=3&gt;There is a lot going on here. But to be brief, the annotation &lt;B style="mso-bidi-font-weight: normal"&gt;__drv_maxIRQL(DISPATCH_LEVEL) &lt;/B&gt;applies to the whole function and specifies that the &lt;B style="mso-bidi-font-weight: normal"&gt;WdfSpinLockAcquire&lt;/B&gt; method must be called only when IRQL &amp;lt;= DISPATCH_LEVEL.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The annotations &lt;B style="mso-bidi-font-weight: normal"&gt;__drv_neverHold(SpinLock)&lt;/B&gt; and &lt;B style="mso-bidi-font-weight: normal"&gt;__drv_acquiresResource(SpinLock) &lt;/B&gt;prevent a &lt;I style="mso-bidi-font-style: normal"&gt;double-taking&lt;/I&gt; of the spinlock (that is, the &lt;B style="mso-bidi-font-weight: normal"&gt;WdfSpinLockAcquire&lt;/B&gt; method must not be called again while the method is holding the spinlock). For more information about the driver specific annotations, see &lt;/FONT&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkID=116388&amp;amp;clcid=0x409" mce_href="http://go.microsoft.com/fwlink/?LinkID=116388&amp;amp;clcid=0x409"&gt;&lt;FONT face="Times New Roman" size=3&gt;Driver Annotations&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; in the WDK and take a look at the KMDF sample code and KMDF header files in the WDK. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=4&gt;Call to action!&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=ListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo4"&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 face=Calibri size=3&gt;Use the static analysis tools. Use them early and use them often!&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=ListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo4"&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 face=Calibri size=3&gt;Learn more about annotations, and add them to your function prototypes. &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;o:p&gt;&lt;FONT face=Calibri size=3&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT face=Cambria color=#17365d size=4&gt;Resources&lt;/FONT&gt;&lt;/H2&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo3; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkID=116387&amp;amp;clcid=0x409" mce_href="http://go.microsoft.com/fwlink/?LinkID=116387&amp;amp;clcid=0x409"&gt;&lt;FONT face="Times New Roman" size=3&gt;PREfast for Drivers&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; in the WDK&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo3; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkID=116389&amp;amp;clcid=0x409" mce_href="http://go.microsoft.com/fwlink/?LinkID=116389&amp;amp;clcid=0x409"&gt;&lt;FONT face="Times New Roman" size=3&gt;PREfast for Drivers Annotations&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; in the WDK&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo3; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;Michael Howard's blog &lt;/FONT&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkId=116396&amp;amp;clcid=0x409" mce_href="http://go.microsoft.com/fwlink/?LinkId=116396&amp;amp;clcid=0x409"&gt;&lt;FONT face="Times New Roman" size=3&gt;A Brief Introduction to the Standard Annotation Language&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo3; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;A href="http://go.microsoft.com/fwlink/?LinkID=92826&amp;amp;clcid=0x409" mce_href="http://go.microsoft.com/fwlink/?LinkID=92826&amp;amp;clcid=0x409"&gt;&lt;FONT face="Times New Roman" size=3&gt;Header Annotations&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Calibri size=3&gt; in the SDK&lt;/FONT&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l2 level1 lfo3; tab-stops: list .5in"&gt;&lt;SPAN style="FONT-FAMILY: 'Wingdings 3'; mso-fareast-font-family: 'Wingdings 3'; mso-bidi-font-family: 'Wingdings 3'"&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; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri size=3&gt;The driver sample and header files in the WDK&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dave Hagen [MSFT], WDK Technical Writer&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/wdkdocs" mce_href="http://blogs.msdn.com/wdkdocs"&gt;&lt;U&gt;&lt;FONT color=#0000ff&gt;http://blogs.msdn.com/wdkdocs&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;This posting is provided "AS IS" with no warranties, and confers no rights.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8399604" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/wdkdocs/archive/tags/code+annotation/default.aspx">code annotation</category></item></channel></rss>