在啟用驅動程式驗證器時處理錯誤檢查

驅動程式驗證器 會在執行時間偵測驅動程式錯誤。 您可以使用驅動程式驗證器以及 !analyze 偵錯工具命令來偵測並顯示驅動程式中錯誤的相關資訊。

在Windows 8中,驅動程式驗證器已使用新功能增強,包括DDI 合規性檢查。 以下提供示範 DDI 合規性檢查的範例。

使用下列程式來設定。

  1. 建立主機電腦與目的電腦之間的核心模式偵錯會話。
  2. 在目的電腦上安裝驅動程式。
  3. 在目的電腦上,開啟 [命令提示字元] 視窗,然後輸入命令 驗證程式。 使用 驅動程式驗證器管理員 為您的驅動程式啟用驅動程式驗證器。
  4. 重新開機目的電腦。

當驅動程式驗證器偵測到錯誤時,會產生錯誤檢查。 然後 Windows 會中斷偵錯工具,並顯示錯誤的簡短描述。 以下是驅動程式驗證器產生錯誤檢查 DRIVER_VERIFIER_DETECTED_VIOLATION (C4) 的範例。

Driver Verifier: Extension abort with Error Code 0x20005
Error String ExAcquireFastMutex should only be called at IRQL <= APC_LEVEL.

*** Fatal System Error: 0x000000c4
                       (0x0000000000020005,0xFFFFF88000E16F50,0x0000000000000000,0x0000000000000000)

Break instruction exception - code 80000003 (first chance)

A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.

A fatal system error has occurred.

nt!DbgBreakPointWithStatus:
fffff802`a40ef930 cc              int     3

在偵錯工具中,輸入 !analyze -v 以取得錯誤的詳細描述。

0: kd> !analyze -v
Connected to Windows 8 9200 x64 target at (Thu Oct 11 13:48:31.270 2012 (UTC - 7:00)), ptr64 TRUE
Loading Kernel Symbols
...............................................................
................................................................
...................
Loading User Symbols
..................................................
Loading unloaded module list
............
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

DRIVER_VERIFIER_DETECTED_VIOLATION (c4)
A device driver attempting to corrupt the system has been caught.  This is
because the driver was specified in the registry as being suspect (by the
administrator) and the kernel has enabled substantial checking of this driver.
If the driver attempts to corrupt the system, bugchecks 0xC4, 0xC1 and 0xA will
be among the most commonly seen crashes.
Arguments:
Arg1: 0000000000020005, ID of the 'IrqlExApcLte1' rule that was violated.
Arg2: fffff88000e16f50, A pointer to the string describing the violated rule condition.
Arg3: 0000000000000000, An optional pointer to the rule state variable(s).
Arg4: 0000000000000000, Reserved (unused)

## Debugging Details:

...

DV_VIOLATED_CONDITION:  ExAcquireFastMutex should only be called at IRQL <= APC_LEVEL.

DV_MSDN_LINK: !url https://go.microsoft.com/fwlink/p/?linkid=216022

DV_RULE_INFO: !ruleinfo 0x20005

BUGCHECK_STR:  0xc4_IrqlExApcLte1_XDV

DEFAULT_BUCKET_ID:  WIN8_DRIVER_FAULT

PROCESS_NAME:  TiWorker.exe

CURRENT_IRQL:  9

在上述輸出中,您可以看到違反 的規則 IrqlExApcLte1名稱和描述,而且您可以選取描述 IrqlExApcLte1 規則的連結, (wdm) 。 您也可以選取偵錯工具命令連結 !ruleinfo 0x20005,以取得規則的相關資訊。 在此情況下,如果中斷要求層級 (IRQL) 大於 APC_LEVEL,規則會指出您無法呼叫 ExAcquireFastMutex 。 輸出會顯示目前的 IRQL 為 9,而且在 wdm.h 中,您可以看到APC_LEVEL值為 1。 如需 IRQL 的詳細資訊,請參閱 管理硬體優先順序

!analyze -v的輸出會繼續堆疊追蹤,以及造成錯誤之程式碼的相關資訊。 在下列輸出中,您可以看到 MyDriver.sys 中稱為ExAcquireFastMutexOnInterrupt常式。 OnInterrupt 是在 IRQL 大於APC_LEVEL執行的插斷服務常式,因此此常式會違反此常式來呼叫 ExAcquireFastMutex

LAST_CONTROL_TRANSFER:  from fffff802a41f00ea to fffff802a40ef930

STACK_TEXT:  
... : nt!DbgBreakPointWithStatus ...
... : nt!KiBugCheckDebugBreak+0x12 ...
... : nt!KeBugCheck2+0x79f ...
... : nt!KeBugCheckEx+0x104 ...
... : VerifierExt!SLIC_abort+0x47 ...
... : VerifierExt!SLIC_ExAcquireFastMutex_entry_irqlexapclte1+0x25 ...
... : VerifierExt!ExAcquireFastMutex_wrapper+0x1a ...
... : nt!ViExAcquireFastMutexCommon+0x1d ...
... : nt!VerifierExAcquireFastMutex+0x1a ...
... : MyDriver!OnInterrupt+0x69 ...
... : nt!KiScanInterruptObjectList+0x6f ...
... : nt!KiChainedDispatch+0x19a ...
...

STACK_COMMAND:  kb

FOLLOWUP_IP: 
MyDriver!OnInterrupt+69 ...
fffff880`16306649 4c8d0510040000  lea     r8,[MyDriver! ?? ::FNODOBFM::`string' (fffff880`16306a60)]

FAULTING_SOURCE_LINE:  c:\MyDriverwdm03\cpp\MyDriver\pnp.c

FAULTING_SOURCE_FILE:  c:\MyDriverwdm03\cpp\MyDriver\pnp.c

FAULTING_SOURCE_LINE_NUMBER:  26

FAULTING_SOURCE_CODE:  
    22:    if(1 == interruptStatus)
    23:    {
    24:       ...
    25:       ExAcquireFastMutex( &(fdoExt->fastMutex) );
>   26:       ...
    27:       ExReleaseFastMutex( &(fdoExt->fastMutex) );
    28:       ...
    29:       return TRUE;
    30:    }
    31:    else


SYMBOL_STACK_INDEX:  9

SYMBOL_NAME:  MyDriver!OnInterrupt+69

FOLLOWUP_NAME:  ...

MODULE_NAME: MyDriver

IMAGE_NAME:  MyDriver.sys

DEBUG_FLR_IMAGE_TIMESTAMP:  50772f37

BUCKET_ID_FUNC_OFFSET:  69

FAILURE_BUCKET_ID:  0xc4_IrqlExApcLte1_XDV_VRF_MyDriver!OnInterrupt

BUCKET_ID:  0xc4_IrqlExApcLte1_XDV_VRF_MyDriver!OnInterrupt

另請參閱

靜態驅動程式驗證器