1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     VerifierApi.c
8 
9 Abstract:
10 
11     This module implements various global verifier worker routines
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19     Both kernel and user mode
20 
21 Revision History:
22 
23 
24 --*/
25 
26 #include "coreprivshared.hpp"
27 
28 //
29 // extern "C" all APIs
30 //
31 extern "C" {
32 
33 //
34 // Global triage Info for dbgeng and 0x9F work
35 //
36 extern WDF_TRIAGE_INFO g_WdfTriageInfo;
37 
38 
39 VOID
40 WDFEXPORT(WdfVerifierDbgBreakPoint)(
41     __in
42     PWDF_DRIVER_GLOBALS DriverGlobals
43     )
44 
45 /*++
46 
47 Routine Description:
48 
49     Common Driver Frameworks DbgBreakPoint() function.
50 
51     This will only break point if WdfVerifierDbgBreakOnError is defined, so
52     it's safe to call for production systems.
53 
54 Arguments:
55 
56     DriverGlobals -
57 
58 Return Value:
59 
60     None.
61 
62 --*/
63 
64 {
65     DDI_ENTRY_IMPERSONATION_OK();
66 
67     PFX_DRIVER_GLOBALS pFxDriverGlobals;
68 
69     pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
70 
71     if (pFxDriverGlobals->FxVerifierDbgBreakOnError) {
72         DbgBreakPoint();
73     }
74 }
75 
76 
77 VOID
78 WDFEXPORT(WdfVerifierKeBugCheck)(
79     __in
80     PWDF_DRIVER_GLOBALS DriverGlobals,
81     __in
82     ULONG BugCheckCode,
83     __in
84     ULONG_PTR BugCheckParameter1,
85     __in
86     ULONG_PTR BugCheckParameter2,
87     __in
88     ULONG_PTR BugCheckParameter3,
89     __in
90     ULONG_PTR BugCheckParameter4
91     )
92 
93 /*++
94 
95 Routine Description:
96 
97     Common Driver Frameworks KeBugCheckEx() function. Use this function rather
98     than the system one. This routine will indicate to the bugcheck callbacks
99     that the IFR data for this driver needs to be copied to the minidump file.
100 
101 Arguments:
102 
103     DriverGlobals -
104 
105     BugCheckCode - Specifies a value that indicates the reason for the bug check.
106 
107     BugCheckParameter1 - Supply additional information, such as the address and
108         data where a memory-corruption error occurred, depending on the value of
109         BugCheckCode.
110 
111     BugCheckParameter2 - Supply additional information, such as the address and
112         data where a memory-corruption error occurred, depending on the value of
113         BugCheckCode.
114 
115     BugCheckParameter3 - Supply additional information, such as the address and
116         data where a memory-corruption error occurred, depending on the value of
117         BugCheckCode.
118 
119     BugCheckParameter4 - Supply additional information, such as the address and
120         data where a memory-corruption error occurred, depending on the value of
121         BugCheckCode.
122 
123 Return Value:
124 
125     None.
126 
127 --*/
128 
129 {
130     DDI_ENTRY_IMPERSONATION_OK();
131 
132     //
133     // Indicate to the BugCheck callback filter which IFR to dump.
134     //
135     PFX_DRIVER_GLOBALS pFxDriverGlobals;
136 
137     pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
138     pFxDriverGlobals->FxForceLogsInMiniDump = TRUE;
139 
140 #pragma prefast(suppress:__WARNING_USE_OTHER_FUNCTION, "WDF wrapper to KeBugCheckEx.");
141     Mx::MxBugCheckEx(BugCheckCode,
142                  BugCheckParameter1,
143                  BugCheckParameter2,
144                  BugCheckParameter3,
145                  BugCheckParameter4);
146 }
147 
148 VOID
149 WDFEXPORT(WdfCxVerifierKeBugCheck)(
150     __in
151     PWDF_DRIVER_GLOBALS DriverGlobals,
152     __in_opt
153     WDFOBJECT Object,
154     __in
155     ULONG BugCheckCode,
156     __in
157     ULONG_PTR BugCheckParameter1,
158     __in
159     ULONG_PTR BugCheckParameter2,
160     __in
161     ULONG_PTR BugCheckParameter3,
162     __in
163     ULONG_PTR BugCheckParameter4
164     )
165 
166 /*++
167 
168 Routine Description:
169 
170     Common Driver Frameworks KeBugCheckEx() function. Cx should use this
171     function rather than the system one or WdfVerifierKeBugCheck. This routine
172     will indicate to the bugcheck callbacks that the IFR data for this driver or its
173     client driver needs to be copied to the minidump file.
174 
175 Arguments:
176 
177     DriverGlobals -
178 
179     Object - WDF uses this object to select which logs to write in the minidump.
180         Cx can pass an object from the client driver's hierarchy to force
181         the client driver's logs in the minidump.
182 
183     BugCheckCode - Specifies a value that indicates the reason for the bug check.
184 
185     BugCheckParameter1 - Supply additional information, such as the address and
186         data where a memory-corruption error occurred, depending on the value of
187         BugCheckCode.
188 
189     BugCheckParameter2 - Supply additional information, such as the address and
190         data where a memory-corruption error occurred, depending on the value of
191         BugCheckCode.
192 
193     BugCheckParameter3 - Supply additional information, such as the address and
194         data where a memory-corruption error occurred, depending on the value of
195         BugCheckCode.
196 
197     BugCheckParameter4 - Supply additional information, such as the address and
198         data where a memory-corruption error occurred, depending on the value of
199         BugCheckCode.
200 
201 Return Value:
202 
203     None.
204 
205 --*/
206 
207 {
208     DDI_ENTRY_IMPERSONATION_OK();
209 
210     FxObject* pObject;
211     PFX_DRIVER_GLOBALS pFxDriverGlobals;
212 
213     if (NULL == Object) {
214         pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
215     }
216     else {
217         FxObjectHandleGetPtrAndGlobals(GetFxDriverGlobals(DriverGlobals),
218                                        Object,
219                                        FX_TYPE_OBJECT,
220                                        (PVOID*)&pObject,
221                                        &pFxDriverGlobals);
222     }
223 
224     UNREFERENCED_PARAMETER(pObject);
225 
226     //
227     // Indicate to the BugCheck callback filter which IFR to dump.
228     //
229     pFxDriverGlobals->FxForceLogsInMiniDump = TRUE;
230 
231 #pragma prefast(suppress:__WARNING_USE_OTHER_FUNCTION, "WDF wrapper to KeBugCheckEx.");
232     Mx::MxBugCheckEx(BugCheckCode,
233                  BugCheckParameter1,
234                  BugCheckParameter2,
235                  BugCheckParameter3,
236                  BugCheckParameter4);
237 }
238 
239 
240 PVOID
241 WDFEXPORT(WdfGetTriageInfo)(
242     _In_
243     PWDF_DRIVER_GLOBALS DriverGlobals
244     )
245 
246 /*++
247 
248 Routine Description:
249 
250     Returns a pointer to the WDF triage info for dbgeng and 0x9F work.
251 
252 Arguments:
253 
254     DriverGlobals -
255 
256 Return Value:
257 
258     None.
259 
260 --*/
261 
262 {
263     DDI_ENTRY();
264 
265     UNREFERENCED_PARAMETER(DriverGlobals);
266     return &g_WdfTriageInfo;
267 }
268 
269 } // extern "C"
270