静态驱动程序验证程序命令 (MSBuild)

可以通过安装 Windows 驱动程序工具包(WDK)或运行企业 Windows 驱动程序工具包(EWDK)在 Visual Studio 命令提示符 窗口中运行静态驱动程序验证程序(SDV)。 导航到存储驱动程序的项目文件或库的项目文件的目录。 参数可以按命令行的任何顺序显示。

Important

不再支持 SDV,并且 Windows 24H2 WDK 或 EWDK 版本中不提供 SDV。 它在版本 26017 之前的 WDK 中不可用,并且不包括在 Windows 24H2 RTM WDK 中。 通过从 下载 Windows 驱动程序工具包(WDK)下载 Windows 11 版本 22H2 EWDK(2023 年 10 月 24 日发布)和 Visual Studio 生成工具 17.1.5,仍可使用 SDV。 建议仅使用企业 WDK 运行 SDV。 不建议将旧版标准 WDK 与 Visual Studio 的最新版本结合使用,因为这可能会导致分析失败。
今后,CodeQL 将成为驱动程序的主要静态分析工具。 CodeQL 提供了一种功能强大的查询语言,可将代码视为要查询的数据库,使编写特定行为、模式等查询变得简单。 有关使用 CodeQL 的详细信息,请参阅 CodeQL 和静态工具徽标测试

msbuild /t:sdv /p:Inputs="Parameters" ProjectFile /p:Configuration=configuration /p:Platform=platform

必须选择发布配置(例如 /p:Configuration=“Windows 7 版本”)。 有关支持的发布配置列表,请参阅 生成驱动程序。 The Platform can be Win32 (for x86) or x64 (for example, /p:Platform=Win32).

Note

请务必检查计算机的电源管理计划,以确保计算机在分析期间不会进入睡眠状态。

Parameters

/ scan

扫描驱动程序的源代码以获取函数角色类型声明。 有关如何声明驱动程序提供的回调函数和调度例程的信息,请参阅 “使用函数角色类型声明”。 在此扫描期间,SDV 会尝试检测驱动程序需要验证驱动程序的驱动程序入口点。 It records the results of the scan in Sdv-map.h, a file that it creates in the driver's project directory.

有关详细信息,请参阅 准备源代码

/check:Rule | Rule,...

使用指定的规则启动验证。 可以通过用逗号分隔每个规则来指定多个规则。 Run the /check: command and specify the driver's Visual Studio project file (*.vcxproj).

Rule is the name of one rule or a rule name pattern that includes wildcard characters (*) to represent one or more characters. 单独使用时,通配符 \ 表示所有规则。

/check:RuleList.sdv

使用指定规则列表文件中的规则启动验证。 只能列出具有此参数的一个文件。 在规则列表文件中,每行可以是一个规则的名称,也可以是一个通配符 {,表示所有 SDV 规则。 Run /check:RuleList.sdv command and specify the driver's Visual Studio project file (*.vcxproj).

RuleList.sdv is the fully qualified path and file name of a rule list file. The file must have the .sdv file name extension. 除非文件位于本地目录中,否则路径是必需的。 If the path or file name includes spaces, you must enclose RuleList.sdv in quotation marks.

If you specify the /check: option without specifying a rule, SDV runs with the default rule set for the driver model.

/lib

处理当前目录中的库。 SDV 调用 MSBuild.exe 来编译和生成库以供外部使用,并生成需要将库包含在驱动程序验证中的文件。

在验证需要库的驱动程序之前,请使用此参数。 运行 msbuild /t:sdv /p:Inputs=“/lib” 命令,并为库指定 Visual Studio 项目文件(*.vcxproj)。

For more information about the use and effect of the /lib parameter, see Library Processing in Static Driver Verifier.

/view

打开静态驱动程序验证程序。 Run /view commands and specify the driver's Visual Studio project file (*.vcxproj).

The results are available as soon as a verification is complete, and remain available until you use a /clean command to delete the SDV files from the driver's project directory.

/clean

从目录中删除 SDV 文件。 Because these files are used to generate the Static Driver Verifier Report display, the /clean command also deletes the report of the verification.

Run a /clean command and specify the Visual Studio project file (*.vcxproj) for the driver or library. 该命令仅删除指定的项目的 SDV 文件。

Run a /clean command for a driver project before each verification.

Run a /clean command for a library when the library files are outdated, such as when the library code changes.

A /clean command does not remove the Sdv-map.h file, if the approved flag is set to true in the Sdv-map.h file (Approved=true). 然后,SDV 可以使用此文件进行将来的验证。

/?

显示 SDV 命令的用法。 使用此参数的命令不必在生成环境窗口中运行。

Comments

运行 msbuild /t:/sdv p:/Inputs= /? 而不显示 SDV 命令的用法。

A /clean command deletes the files that SDV uses to create the Static Driver Verifier Report display for a verification. 运行此命令后,为验证显示的静态驱动程序验证程序报告不再可用。

Examples

若要使用 mydriver 项目的本地目录中驱动程序文件的所有规则运行 SDV:

msbuild /t:sdv /p:Inputs="/check:*" mydriver.VcxProj /p:Configuration="Windows 7 Release"/p:Platform=Win32

To run SDV using the CancelSpinLock rule on the driver files in the local directory:

msbuild /t:sdv /p:Inputs="/check:CancelSpinLock" mydriver.VcxProj /p:Configuration="Windows 7 Release" /p:Platform=Win32

若要使用在 D:\SDV 目录中的 Rules1.sdv 规则列表文件中指定的规则运行 SDV:

msbuild /t:sdv /p:Inputs="/check:D:\SDV\Rules1.sdv" mydriver.VcxProj /p:Configuration="Windows 7 Release" /p:Platform=Win32

若要再次运行 SDV,这次使用 /clean 选项:

msbuild /t:sdv /p:Inputs="/clean" mydriver.VcxProj /p:Configuration="Windows 7 Release"/p:Platform=Win32

若要显示静态驱动程序验证程序,以便可以在本地目录中查看驱动程序的最新验证结果:

msbuild /t:sdv /p:Inputs="/view" mydriver.VcxProj /p:Configuration="Windows 7 Release" /p:Platform=Win32

使用静态驱动程序验证程序查找 Windows 驱动程序中的缺陷