1 /*++
2 
3 Copyright (c) Microsoft Corporation.  All rights reserved.
4 
5 Module Name:
6 
7     vfpriv.hpp
8 
9 Abstract:
10 
11     common header file for verifier
12 
13 Author:
14 
15 
16 Environment:
17 
18     User mode only
19 
20 Revision History:
21 
22 --*/
23 
24 #pragma once
25 
26 #include "fxmin.hpp"
27 
28 FORCEINLINE
29 VOID
30 PerformanceAnalysisIOProcess(
31     __in PFX_DRIVER_GLOBALS pFxDriverGlobals,
32     __in WDFREQUEST Handle,
33     __inout FxRequest** ppReq,
34     __inout GUID* pActivityId
35     )
36 {
37     FxObjectHandleGetPtr(pFxDriverGlobals,
38                          Handle,
39                          FX_TYPE_REQUEST,
40                          (PVOID *) ppReq);
41 
42     if ((*ppReq)->GetFxIrp()->GetIoIrp()->IsActivityIdSet() == FALSE) {
43         EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
44         (*ppReq)->GetFxIrp()->GetIoIrp()->SetActivityId(pActivityId);
45     }
46     else {
47         *pActivityId = *(*ppReq)->GetFxIrp()->GetIoIrp()->GetActivityId();
48     }
49 }
50 
51 FORCEINLINE
52 BOOLEAN
53 PerfIoStart(
54     __in WDFREQUEST Handle
55 )
56 {
57     FxRequest* pReq;
58     GUID activityId = { 0 };
59     WDFOBJECT_OFFSET offset = 0;
60 
61     FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
62     PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
63     BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
64 
65     if(status) {
66         PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
67         PerformanceAnalysisIOProcess(pFxDriverGlobals, Handle, &pReq,
68                 &activityId);
69 
70         UCHAR Type = pReq->GetFxIrp()->GetMajorFunction();
71         WDFDEVICE Device = pReq->GetCurrentQueue()->GetDevice()->GetHandle();
72         EVENT_DATA_DESCRIPTOR EventData[3];
73         EventDataDescCreate(&EventData[0], &Type, sizeof(const UCHAR));
74         EventDataDescCreate(&EventData[1], &pDriverDeviceAdd, sizeof(PVOID));
75         EventDataDescCreate(&EventData[2], &Device, sizeof(PVOID));
76 
77         EventWriteTransfer(Microsoft_Windows_DriverFrameworks_UserMode_PerformanceHandle,
78                  &FX_REQUEST_START,
79                  &activityId,
80                  NULL,
81                  3,
82                  &EventData[0]);
83     }
84     return status;
85 }
86 
87 FORCEINLINE
88 BOOLEAN
89 PerfIoComplete(
90     __in WDFREQUEST Handle
91 )
92 {
93     FxRequest* pReq;
94     GUID activityId = { 0 };
95     WDFOBJECT_OFFSET offset = 0;
96 
97     FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
98     PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
99     BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
100 
101     if(status) {
102         PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
103         PerformanceAnalysisIOProcess(pFxDriverGlobals, Handle, &pReq,
104                 &activityId);
105 
106         UCHAR Type = pReq->GetFxIrp()->GetMajorFunction();
107         WDFDEVICE Device = pReq->GetCurrentQueue()->GetDevice()->GetHandle();
108         EVENT_DATA_DESCRIPTOR EventData[3];
109         EventDataDescCreate(&EventData[0], &Type, sizeof(const UCHAR));
110         EventDataDescCreate(&EventData[1], &pDriverDeviceAdd, sizeof(PVOID));
111         EventDataDescCreate(&EventData[2], &Device, sizeof(PVOID));
112 
113         EventWriteTransfer(Microsoft_Windows_DriverFrameworks_UserMode_PerformanceHandle,
114                  &FX_REQUEST_COMPLETE,
115                  &activityId,
116                  NULL,
117                  3,
118                  &EventData[0]);
119     }
120     return status;
121 }
122 
123 __inline
124 BOOLEAN
125 PerformanceAnalysisPowerProcess(
126    __in PCEVENT_DESCRIPTOR EventDescriptor,
127    __in GUID* pActivityId,
128    __in WDFDEVICE Handle
129 )
130 {
131     WDFOBJECT_OFFSET offset = 0;
132     FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
133     PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
134     BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
135 
136     if(status) {
137         PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
138 
139         EVENT_DATA_DESCRIPTOR EventData[2];
140         EventDataDescCreate(&EventData[0], &pDriverDeviceAdd, sizeof(PVOID));
141         EventDataDescCreate(&EventData[1], &Handle, sizeof(PVOID));
142 
143         EventWriteTransfer(Microsoft_Windows_DriverFrameworks_UserMode_PerformanceHandle,
144                  EventDescriptor,
145                  pActivityId,
146                  NULL,
147                  2,
148                  &EventData[0]);
149     }
150 
151     return status;
152 }
153 
154 __inline
155 BOOLEAN
156 PerfEvtDeviceD0EntryStart(
157     __in WDFDEVICE Handle,
158     __inout GUID* pActivityId
159 )
160 {
161     EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
162     return PerformanceAnalysisPowerProcess(&FX_POWER_D0_ENTRY_START, pActivityId, Handle);
163 }
164 
165 __inline
166 VOID
167 PerfEvtDeviceD0EntryStop(
168     __in WDFDEVICE Handle,
169     __in GUID* pActivityId
170 )
171 {
172     PerformanceAnalysisPowerProcess(&FX_POWER_D0_ENTRY_STOP, pActivityId, Handle);
173 }
174 
175 __inline
176 BOOLEAN
177 PerfEvtDeviceD0ExitStart(
178     __in WDFDEVICE Handle,
179     __inout GUID* pActivityId
180 )
181 {
182     EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
183     return PerformanceAnalysisPowerProcess(&FX_POWER_D0_EXIT_START, pActivityId, Handle);
184 }
185 
186 __inline
187 VOID
188 PerfEvtDeviceD0ExitStop(
189     __in WDFDEVICE Handle,
190     __in GUID* pActivityId
191 )
192 {
193     PerformanceAnalysisPowerProcess(&FX_POWER_D0_EXIT_STOP, pActivityId, Handle);
194 }
195 
196 __inline
197 BOOLEAN
198 PerfEvtDevicePrepareHardwareStart(
199     __in WDFDEVICE Handle,
200     __inout GUID* pActivityId
201 )
202 {
203     EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
204     return PerformanceAnalysisPowerProcess(&FX_POWER_HW_PREPARE_START, pActivityId, Handle);
205 }
206 
207 __inline
208 VOID
209 PerfEvtDevicePrepareHardwareStop(
210     __in WDFDEVICE Handle,
211     __in GUID* pActivityId
212 )
213 {
214     PerformanceAnalysisPowerProcess(&FX_POWER_HW_PREPARE_STOP, pActivityId, Handle);
215 }
216 
217 __inline
218 BOOLEAN
219 PerfEvtDeviceReleaseHardwareStart(
220     __in WDFDEVICE Handle,
221     __inout GUID* pActivityId
222 )
223 {
224     EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
225     return PerformanceAnalysisPowerProcess(&FX_POWER_HW_RELEASE_START, pActivityId, Handle);
226 }
227 
228 __inline
229 VOID
230 PerfEvtDeviceReleaseHardwareStop(
231     __in WDFDEVICE Handle,
232     __in GUID* pActivityId
233 )
234 {
235     PerformanceAnalysisPowerProcess(&FX_POWER_HW_RELEASE_STOP, pActivityId, Handle);
236 }
237 
238 // EvtIoStop callback started.
239 __inline
240 BOOLEAN
241 PerfEvtIoStopStart(
242     __in WDFQUEUE Queue,
243     __inout GUID* pActivityId
244 )
245 {
246     FxIoQueue* pQueue;
247     WDFOBJECT_OFFSET offset = 0;
248     WDFDEVICE device;
249 
250     FxObject *pObject = FxObject::_GetObjectFromHandle(Queue, &offset);
251     PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
252 
253     FxObjectHandleGetPtr(pFxDriverGlobals,
254                           Queue,
255                           FX_TYPE_QUEUE,
256                           (PVOID*) &pQueue);
257     device = (WDFDEVICE) pQueue->GetDevice()->GetHandle();
258 
259     EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
260     return PerformanceAnalysisPowerProcess(&FX_EVTIOSTOP_START, pActivityId, device);
261 }
262 
263 // EvtIoStop callback returned.
264 __inline
265 VOID
266 PerfEvtIoStopStop(
267     __in WDFQUEUE Queue,
268     __in GUID* pActivityId
269 )
270 {
271     FxIoQueue* pQueue;
272     WDFOBJECT_OFFSET offset = 0;
273     WDFDEVICE device;
274 
275     FxObject *pObject = FxObject::_GetObjectFromHandle(Queue, &offset);
276     PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
277 
278     FxObjectHandleGetPtr(pFxDriverGlobals,
279                           Queue,
280                           FX_TYPE_QUEUE,
281                           (PVOID*) &pQueue);
282     device = (WDFDEVICE) pQueue->GetDevice()->GetHandle();
283 
284     PerformanceAnalysisPowerProcess(&FX_EVTIOSTOP_STOP, pActivityId, device);
285 }
286 
287 __inline
288 VOID
289 VerifyIrqlEntry(
290     __out KIRQL *Irql
291     )
292 {
293     DO_NOTHING();
294 }
295 
296 __inline
297 VOID
298 VerifyIrqlExit(
299     __in PWDF_DRIVER_GLOBALS DriverGlobals,
300     __in KIRQL PrevIrql
301     )
302 {
303     DO_NOTHING();
304 }
305 
306 __inline
307 VOID
308 VerifyCriticalRegionEntry(
309     __out BOOLEAN *CritRegion
310     )
311 {
312     DO_NOTHING();
313 }
314 
315 __inline
316 VOID
317 VerifyCriticalRegionExit(
318     __in PWDF_DRIVER_GLOBALS DriverGlobals,
319     __in BOOLEAN OldCritRegion,
320     __in PVOID Pfn
321     )
322 {
323     DO_NOTHING();
324 }
325 
326