共用方式為


Specifying the Analysis Mode

The first step to annotate your driver is to determine the analysis mode, so that PREfast for Drivers (PFD) can better understand the type of code that is to be examined. To specify the analysis mode, use the __drv_unit(analysisMode) annotation. This annotation informs PFD whether a particular body of code is user-mode code or kernel-mode code and whether the code is actually a driver. This annotation applies to an entire source code file.

Usage

__drv_unit(analysisMode)

Where analysisMode can be one of the following.

analysisMode Description

kernel_driver

For kernel-mode driver code. This is the default analysis mode.

kernel_code

For non-driver, kernel-mode code.

user_driver

For user-mode driver code.

user_code

For non-driver, user-mode code.

 

Use the __drv_unit(analysisMode) annotation if the default analysis mode (kernel_driver) is incorrect for a particular driver. The annotation should appear almost immediately following the relevant header file and before any function bodies. Insert this macro in the source file or appropriate header file anywhere after Driverspecs.h is included. Ntddk.h and Wdm.h include Driverspecs.h, so this annotation can appear anywhere after Ntddk.h or Wdm.h is included.

For example, the following code example indicates that the code is a kernel-mode driver (which is also the default).

#include <wdm.h>
__drv_unit(kernel_driver)

Note  Driverspecs.h defines the following individual macros for analysis mode control: __kernel_driver (the default), __kernel_code, __user_driver, and __user_code. The __drv_unit(analysisMode) annotation is functionally equivalent to these macros. See Selecting the Analysis Mode for more information.

When you run PREfast under Windows Auto Code Review (OACR), kernel analysis mode is inferred from the presence of Wdm.h, Ntddk.h (because it includes Wdm.h) or Ntosp.h. Other files are defaulted to user mode. You can override the OACR default settings by using the annotations listed previously.

 

 

Send comments about this topic to Microsoft

Build date: 5/3/2011