ReactOS 0.4.16-dev-306-g647d351
fxverifier.h
Go to the documentation of this file.
1/*++
2
3Copyright (c) Microsoft Corporation
4
5Module Name:
6
7 FxVerifier.cpp
8
9Abstract:
10
11 This is the main driver framework verifier
12
13Environment:
14
15 kernel/user mode
16
17Revision History:
18
19
20 Made it mode agnostic
21
22--*/
23
24#ifndef _FXVERIFIER_H_
25#define _FXVERIFIER_H_
26
27extern "C" {
28#if defined(EVENT_TRACING)
29#include "FxVerifier.h.tmh"
30#endif
31}
32
33
35 //
36 // low 2 bytes are used for function table Hooking
37 //
39 //
40 // Lower nibble of 3rd byte for forward progress
41 //
44
45 //
46 // bit masks
47 //
50
51 //
52 // higher nibble of 3rd byte for performance analysis
53 //
55};
56
57#if (FX_CORE_MODE == FX_CORE_USER_MODE)
58#define FxVerifierBugCheck(FxDriverGlobals, Error, ...) \
59 FX_VERIFY_WITH_NAME(DRIVER(BadAction, Error), \
60 TRAPMSG("WDF Violation: Please check" \
61 "tracelog for a description of this error"), \
62 FxDriverGlobals->Public.DriverName)
63#else
64#define FxVerifierBugCheck(FxDriverGlobals, ...) \
65 FxVerifierBugCheckWorker(FxDriverGlobals, __VA_ARGS__);
66#endif
67
68//
69// FxVerifierDbgBreakPoint and FxVerifierBreakOnDeviceStateError are mapped
70// to FX_VERIFY in UMDF and break regardless of any flags
71//
72__inline
73VOID
75 __in PFX_DRIVER_GLOBALS FxDriverGlobals
76 )
77{
78#if FX_CORE_MODE == FX_CORE_KERNEL_MODE
79 CHAR ext[] = "sys";
80#else
81 CHAR ext[] = "dll";
82#endif
83
84 Mx::MxDbgPrint("WDF detected potentially invalid operation by %s.%s "
85 "Dump the driver log (!wdflogdump %s.%s) for more information.\n",
86 FxDriverGlobals->Public.DriverName, ext,
87 FxDriverGlobals->Public.DriverName, ext
88 );
89
90 if (FxDriverGlobals->FxVerifierDbgBreakOnError) {
92 } else {
93 Mx::MxDbgPrint("Turn on framework verifier for %s.%s to automatically "
94 "break into the debugger next time it happens.\n",
95 FxDriverGlobals->Public.DriverName, ext);
96 }
97}
98
99__inline
100VOID
102 __in PFX_DRIVER_GLOBALS FxDriverGlobals
103 )
104{
105#if FX_CORE_MODE == FX_CORE_KERNEL_MODE
106 CHAR ext[] = "sys";
107#else
108 CHAR ext[] = "dll";
109#endif
110
111 Mx::MxDbgPrint("WDF detected potentially invalid device state in %s.%s. "
112 "Dump the driver log (!wdflogdump %s.$s) for more information.\n",
113 FxDriverGlobals->Public.DriverName, ext,
114 FxDriverGlobals->Public.DriverName, ext);
115
116 if (FxDriverGlobals->FxVerifierDbgBreakOnDeviceStateError) {
118 } else {
119 Mx::MxDbgPrint("Turn on framework verifier for %s.%s to automatically "
120 "break into the debugger next time it happens.\n",
121 FxDriverGlobals->Public.DriverName, ext);
122 }
123}
124
125__inline
128 __in PFX_DRIVER_GLOBALS FxDriverGlobals
129 )
130{
131 if (FxDriverGlobals->FxEnhancedVerifierOptions &
133 return TRUE;
134 }
135 else {
136 return FALSE;
137 }
138}
139
141VOID
143 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
144 __in WDF_BUGCHECK_CODES WdfBugCheckCode,
145 __in_opt ULONG_PTR BugCheckParameter2 = 0,
146 __in_opt ULONG_PTR BugCheckParameter3 = 0
147 );
148
150VOID
152 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
153 __in PVOID ReturnAddress
154 );
155
156__inline
159 __in PFX_DRIVER_GLOBALS FxDriverGlobals,
161 )
162/*++
163
164Routine Description:
165 Check that current IRQL matches expected IRQL.
166
167Arguments:
168 Irql - The expected IRQL
169
170Return Value:
171 STATUS_SUCCESS if expected IRQL matches current IRQL.
172 STATUS_INVALID_DEVICE_REQUEST if expected IRQL does not match current IRQL.
173
174 --*/
175{
176 //
177 // Full treatment only if VerifierOn is set.
178 //
179 if (FxDriverGlobals->FxVerifierOn) {
180
181 KIRQL currentIrql = Mx::MxGetCurrentIrql();
182
183 if (currentIrql <= Irql) {
184 return STATUS_SUCCESS;
185 }
186
188 "Called at wrong IRQL; at level %d, should be "
189 "at level %d", currentIrql, Irql);
190
191 FxVerifierDbgBreakPoint(FxDriverGlobals);
192
194 }
195
196 //
197 // If Verifier is turned off, always return success.
198 //
199 return STATUS_SUCCESS;
200}
201
202
203__inline
206 __in PFX_DRIVER_GLOBALS FxDriverGlobals
207 )
208{
209 if (FxDriverGlobals->FxEnhancedVerifierOptions &
211 return TRUE;
212 }
213 else {
214 return FALSE;
215 }
216}
217
218__inline
221 __in PFX_DRIVER_GLOBALS FxDriverGlobals
222 )
223{
224 if (FxDriverGlobals->FxEnhancedVerifierOptions &
226 return TRUE;
227 }
228 else {
229 return FALSE;
230 }
231}
232
233__inline
236 __in PFX_DRIVER_GLOBALS FxDriverGlobals
237 )
238{
239 if (FxDriverGlobals->FxEnhancedVerifierOptions &
241 return TRUE;
242 }
243 else {
244 return FALSE;
245 }
246}
247
248__inline
251 __in PFX_DRIVER_GLOBALS FxDriverGlobals
252 )
253{
254 if (FxDriverGlobals->FxEnhancedVerifierOptions &
256 return TRUE;
257 }
258 else {
259 return FALSE;
260 }
261}
262
263#endif // _FXVERIFIER_H_
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
static __inline VOID MxDbgBreakPoint()
Definition: mxgeneralkm.h:157
static __inline KIRQL MxGetCurrentIrql()
Definition: mxgeneralkm.h:86
static VOID MxDbgPrint(__drv_formatString(printf) __in PCSTR DebugMessage,...)
Definition: mxgeneralkm.cpp:7
_Out_ PKIRQL Irql
Definition: csq.h:179
#define __in
Definition: dbghelp.h:35
#define __in_opt
Definition: dbghelp.h:38
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR *const ext[]
Definition: module.c:53
UCHAR KIRQL
Definition: env_spec_w32.h:591
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
__inline BOOLEAN IsFxPerformanceAnalysis(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:250
DECLSPEC_NORETURN VOID FxVerifierBugCheckWorker(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in WDF_BUGCHECK_CODES WdfBugCheckCode, __in_opt ULONG_PTR BugCheckParameter2=0, __in_opt ULONG_PTR BugCheckParameter3=0)
__inline BOOLEAN IsFxVerifierTestForwardProgressFailRandom(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:220
__inline BOOLEAN IsFxVerifierFunctionTableHooking(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:127
__inline BOOLEAN IsFxVerifierTestForwardProgressFailAll(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:205
__inline NTSTATUS FxVerifierCheckIrqlLevel(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in KIRQL Irql)
Definition: fxverifier.h:158
DECLSPEC_NORETURN VOID FxVerifierNullBugCheck(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PVOID ReturnAddress)
__inline BOOLEAN IsFxVerifierTestForwardProgress(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:235
__inline VOID FxVerifierDbgBreakPoint(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:74
FxEnhancedVerifierBitFlags
Definition: fxverifier.h:34
@ FxEnhancedVerifierFunctionTableHookMask
Definition: fxverifier.h:48
@ FxEnhancedVerifierForwardProgressMask
Definition: fxverifier.h:49
@ FxEnhancedVerifierPerformanceAnalysisMask
Definition: fxverifier.h:54
@ FxEnhancedVerifierForwardProgressFailRandom
Definition: fxverifier.h:43
@ FxEnhancedVerifierCallbackIrqlAndCRCheck
Definition: fxverifier.h:38
@ FxEnhancedVerifierForwardProgressFailAll
Definition: fxverifier.h:42
__inline VOID FxVerifierBreakOnDeviceStateError(__in PFX_DRIVER_GLOBALS FxDriverGlobals)
Definition: fxverifier.h:101
#define DECLSPEC_NORETURN
Definition: ntbasedef.h:176
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
WDF_EXTERN_C_START enum _WDF_BUGCHECK_CODES WDF_BUGCHECK_CODES
char CHAR
Definition: xmlstorage.h:175