mirror of
https://github.com/reactos/reactos.git
synced 2025-08-07 06:02:56 +00:00
[WDF] Add Windows Driver Framework files
Takern from Microsoft GitHub repo:
d9c6040fe9
Licensed under MIT
This commit is contained in:
parent
545df81502
commit
8a978a179f
475 changed files with 285099 additions and 0 deletions
357
sdk/lib/drivers/wdf/shared/enhancedverif/km/vfprivkm.hpp
Normal file
357
sdk/lib/drivers/wdf/shared/enhancedverif/km/vfprivkm.hpp
Normal file
|
@ -0,0 +1,357 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
vfpriv.hpp
|
||||
|
||||
Abstract:
|
||||
|
||||
common header file for verifier
|
||||
|
||||
Author:
|
||||
|
||||
|
||||
|
||||
Environment:
|
||||
|
||||
kernel mode only
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
extern "C" {
|
||||
#include <ntddk.h>
|
||||
}
|
||||
|
||||
#include "fx.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyIrqlEntry(
|
||||
__out KIRQL *Irql
|
||||
)
|
||||
{
|
||||
*Irql = KeGetCurrentIrql();
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyIrqlExit(
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in KIRQL PrevIrql
|
||||
)
|
||||
{
|
||||
KIRQL currIrql;
|
||||
|
||||
currIrql = KeGetCurrentIrql();
|
||||
if (PrevIrql != currIrql) {
|
||||
KdPrint(("WDF VERIFIER: Irql at entry of event is not same as at exit.\n"));
|
||||
FxVerifierBugCheck(GetFxDriverGlobals(DriverGlobals),
|
||||
WDF_VERIFIER_IRQL_MISMATCH,
|
||||
PrevIrql,
|
||||
currIrql
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyCriticalRegionEntry(
|
||||
__out BOOLEAN *CritRegion
|
||||
)
|
||||
{
|
||||
if (KeGetCurrentIrql() <= APC_LEVEL) {
|
||||
*CritRegion = KeAreApcsDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyCriticalRegionExit(
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in BOOLEAN OldCritRegion,
|
||||
__in PVOID Pfn
|
||||
)
|
||||
{
|
||||
if (KeGetCurrentIrql() <= APC_LEVEL) {
|
||||
if (OldCritRegion != KeAreApcsDisabled()) {
|
||||
KdPrint(("WDF VERIFIER: Critical section entry and exit around event callback incorrect\n"));
|
||||
FxVerifierBugCheck(GetFxDriverGlobals(DriverGlobals),
|
||||
WDF_VERIFIER_CRITICAL_REGION_MISMATCH,
|
||||
(ULONG_PTR)Pfn,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
PerformanceAnalysisIOProcess(
|
||||
__in PFX_DRIVER_GLOBALS pFxDriverGlobals,
|
||||
__in WDFREQUEST Handle,
|
||||
__out FxRequest** ppReq,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
|
||||
FxObjectHandleGetPtr(pFxDriverGlobals,
|
||||
Handle,
|
||||
FX_TYPE_REQUEST,
|
||||
(PVOID *) ppReq);
|
||||
|
||||
if (IoGetActivityIdIrp((*ppReq)->GetFxIrp()->GetIrp(), pActivityId) == STATUS_NOT_FOUND)
|
||||
{
|
||||
EtwActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
IoSetActivityIdIrp((*ppReq)->GetFxIrp()->GetIrp(), pActivityId);
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
PerfIoStart(
|
||||
__in WDFREQUEST Handle
|
||||
)
|
||||
{
|
||||
FxRequest* pReq;
|
||||
GUID activityId = { 0 };
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status)
|
||||
{
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
PerformanceAnalysisIOProcess(pFxDriverGlobals, Handle, &pReq,
|
||||
&activityId);
|
||||
|
||||
EventWriteFX_REQUEST_START(&activityId, pReq->GetFxIrp()->GetMajorFunction(),
|
||||
pDriverDeviceAdd, pReq->GetCurrentQueue()->GetDevice()->GetHandle());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
PerfIoComplete(
|
||||
__in WDFREQUEST Handle
|
||||
)
|
||||
{
|
||||
FxRequest* pReq;
|
||||
GUID activityId = { 0 };
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status)
|
||||
{
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
PerformanceAnalysisIOProcess(pFxDriverGlobals, Handle, &pReq,
|
||||
&activityId);
|
||||
|
||||
EventWriteFX_REQUEST_COMPLETE(&activityId, pReq->GetFxIrp()->GetMajorFunction(),
|
||||
pDriverDeviceAdd, pReq->GetCurrentQueue()->GetDevice()->GetHandle());
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
PFN_WDF_DRIVER_DEVICE_ADD
|
||||
PerformanceGetDriverDeviceAdd(
|
||||
__in WDFOBJECT Handle
|
||||
)
|
||||
{
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
|
||||
return pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDeviceD0EntryStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
EtwActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
EventWriteFX_POWER_D0_ENTRY_START(pActivityId, pDriverDeviceAdd, Handle);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDeviceD0EntryStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventWriteFX_POWER_D0_ENTRY_STOP(pActivityId, PerformanceGetDriverDeviceAdd(Handle), Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDeviceD0ExitStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
EtwActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
EventWriteFX_POWER_D0_EXIT_START(pActivityId, pDriverDeviceAdd, Handle);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDeviceD0ExitStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventWriteFX_POWER_D0_EXIT_STOP(pActivityId, PerformanceGetDriverDeviceAdd(Handle), Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDevicePrepareHardwareStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
EtwActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
EventWriteFX_POWER_HW_PREPARE_START(pActivityId, pDriverDeviceAdd, Handle);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDevicePrepareHardwareStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventWriteFX_POWER_HW_PREPARE_STOP(pActivityId, PerformanceGetDriverDeviceAdd(Handle), Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDeviceReleaseHardwareStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
EtwActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
EventWriteFX_POWER_HW_RELEASE_START(pActivityId, pDriverDeviceAdd, Handle);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDeviceReleaseHardwareStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventWriteFX_POWER_HW_RELEASE_STOP(pActivityId, PerformanceGetDriverDeviceAdd(Handle), Handle);
|
||||
}
|
||||
|
||||
// EvtIoStop callback started.
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtIoStopStart(
|
||||
__in WDFQUEUE Queue,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
WDFDEVICE device;
|
||||
FxIoQueue* pQueue;
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Queue, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
FxObjectHandleGetPtr(pFxDriverGlobals,
|
||||
Queue,
|
||||
FX_TYPE_QUEUE,
|
||||
(PVOID*) &pQueue);
|
||||
device = (WDFDEVICE) pQueue->GetDevice()->GetHandle();
|
||||
pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
EtwActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
EventWriteFX_EVTIOSTOP_START(pActivityId, pDriverDeviceAdd, device);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// EvtIoStop callback returned.
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtIoStopStop(
|
||||
__in WDFQUEUE Queue,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
WDFDEVICE device;
|
||||
FxIoQueue* pQueue;
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Queue, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
FxObjectHandleGetPtr(pFxDriverGlobals,
|
||||
Queue,
|
||||
FX_TYPE_QUEUE,
|
||||
(PVOID*) &pQueue);
|
||||
device = (WDFDEVICE) pQueue->GetDevice()->GetHandle();
|
||||
pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
|
||||
EventWriteFX_EVTIOSTOP_STOP(pActivityId, pDriverDeviceAdd, device);
|
||||
}
|
8313
sdk/lib/drivers/wdf/shared/enhancedverif/km/vfwdfdynamics.cpp
Normal file
8313
sdk/lib/drivers/wdf/shared/enhancedverif/km/vfwdfdynamics.cpp
Normal file
File diff suppressed because it is too large
Load diff
325
sdk/lib/drivers/wdf/shared/enhancedverif/um/vfprivum.hpp
Normal file
325
sdk/lib/drivers/wdf/shared/enhancedverif/um/vfprivum.hpp
Normal file
|
@ -0,0 +1,325 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
vfpriv.hpp
|
||||
|
||||
Abstract:
|
||||
|
||||
common header file for verifier
|
||||
|
||||
Author:
|
||||
|
||||
|
||||
Environment:
|
||||
|
||||
User mode only
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fxmin.hpp"
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
PerformanceAnalysisIOProcess(
|
||||
__in PFX_DRIVER_GLOBALS pFxDriverGlobals,
|
||||
__in WDFREQUEST Handle,
|
||||
__inout FxRequest** ppReq,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
FxObjectHandleGetPtr(pFxDriverGlobals,
|
||||
Handle,
|
||||
FX_TYPE_REQUEST,
|
||||
(PVOID *) ppReq);
|
||||
|
||||
if ((*ppReq)->GetFxIrp()->GetIoIrp()->IsActivityIdSet() == FALSE) {
|
||||
EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
(*ppReq)->GetFxIrp()->GetIoIrp()->SetActivityId(pActivityId);
|
||||
}
|
||||
else {
|
||||
*pActivityId = *(*ppReq)->GetFxIrp()->GetIoIrp()->GetActivityId();
|
||||
}
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
PerfIoStart(
|
||||
__in WDFREQUEST Handle
|
||||
)
|
||||
{
|
||||
FxRequest* pReq;
|
||||
GUID activityId = { 0 };
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
PerformanceAnalysisIOProcess(pFxDriverGlobals, Handle, &pReq,
|
||||
&activityId);
|
||||
|
||||
UCHAR Type = pReq->GetFxIrp()->GetMajorFunction();
|
||||
WDFDEVICE Device = pReq->GetCurrentQueue()->GetDevice()->GetHandle();
|
||||
EVENT_DATA_DESCRIPTOR EventData[3];
|
||||
EventDataDescCreate(&EventData[0], &Type, sizeof(const UCHAR));
|
||||
EventDataDescCreate(&EventData[1], &pDriverDeviceAdd, sizeof(PVOID));
|
||||
EventDataDescCreate(&EventData[2], &Device, sizeof(PVOID));
|
||||
|
||||
EventWriteTransfer(Microsoft_Windows_DriverFrameworks_UserMode_PerformanceHandle,
|
||||
&FX_REQUEST_START,
|
||||
&activityId,
|
||||
NULL,
|
||||
3,
|
||||
&EventData[0]);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
PerfIoComplete(
|
||||
__in WDFREQUEST Handle
|
||||
)
|
||||
{
|
||||
FxRequest* pReq;
|
||||
GUID activityId = { 0 };
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
PerformanceAnalysisIOProcess(pFxDriverGlobals, Handle, &pReq,
|
||||
&activityId);
|
||||
|
||||
UCHAR Type = pReq->GetFxIrp()->GetMajorFunction();
|
||||
WDFDEVICE Device = pReq->GetCurrentQueue()->GetDevice()->GetHandle();
|
||||
EVENT_DATA_DESCRIPTOR EventData[3];
|
||||
EventDataDescCreate(&EventData[0], &Type, sizeof(const UCHAR));
|
||||
EventDataDescCreate(&EventData[1], &pDriverDeviceAdd, sizeof(PVOID));
|
||||
EventDataDescCreate(&EventData[2], &Device, sizeof(PVOID));
|
||||
|
||||
EventWriteTransfer(Microsoft_Windows_DriverFrameworks_UserMode_PerformanceHandle,
|
||||
&FX_REQUEST_COMPLETE,
|
||||
&activityId,
|
||||
NULL,
|
||||
3,
|
||||
&EventData[0]);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerformanceAnalysisPowerProcess(
|
||||
__in PCEVENT_DESCRIPTOR EventDescriptor,
|
||||
__in GUID* pActivityId,
|
||||
__in WDFDEVICE Handle
|
||||
)
|
||||
{
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
BOOLEAN status = IsFxPerformanceAnalysis(pFxDriverGlobals);
|
||||
|
||||
if(status) {
|
||||
PFN_WDF_DRIVER_DEVICE_ADD pDriverDeviceAdd = pFxDriverGlobals->Driver->GetDriverDeviceAddMethod();
|
||||
|
||||
EVENT_DATA_DESCRIPTOR EventData[2];
|
||||
EventDataDescCreate(&EventData[0], &pDriverDeviceAdd, sizeof(PVOID));
|
||||
EventDataDescCreate(&EventData[1], &Handle, sizeof(PVOID));
|
||||
|
||||
EventWriteTransfer(Microsoft_Windows_DriverFrameworks_UserMode_PerformanceHandle,
|
||||
EventDescriptor,
|
||||
pActivityId,
|
||||
NULL,
|
||||
2,
|
||||
&EventData[0]);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDeviceD0EntryStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
return PerformanceAnalysisPowerProcess(&FX_POWER_D0_ENTRY_START, pActivityId, Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDeviceD0EntryStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
PerformanceAnalysisPowerProcess(&FX_POWER_D0_ENTRY_STOP, pActivityId, Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDeviceD0ExitStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
return PerformanceAnalysisPowerProcess(&FX_POWER_D0_EXIT_START, pActivityId, Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDeviceD0ExitStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
PerformanceAnalysisPowerProcess(&FX_POWER_D0_EXIT_STOP, pActivityId, Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDevicePrepareHardwareStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
return PerformanceAnalysisPowerProcess(&FX_POWER_HW_PREPARE_START, pActivityId, Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDevicePrepareHardwareStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
PerformanceAnalysisPowerProcess(&FX_POWER_HW_PREPARE_STOP, pActivityId, Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtDeviceReleaseHardwareStart(
|
||||
__in WDFDEVICE Handle,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
return PerformanceAnalysisPowerProcess(&FX_POWER_HW_RELEASE_START, pActivityId, Handle);
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtDeviceReleaseHardwareStop(
|
||||
__in WDFDEVICE Handle,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
PerformanceAnalysisPowerProcess(&FX_POWER_HW_RELEASE_STOP, pActivityId, Handle);
|
||||
}
|
||||
|
||||
// EvtIoStop callback started.
|
||||
__inline
|
||||
BOOLEAN
|
||||
PerfEvtIoStopStart(
|
||||
__in WDFQUEUE Queue,
|
||||
__inout GUID* pActivityId
|
||||
)
|
||||
{
|
||||
FxIoQueue* pQueue;
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
WDFDEVICE device;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Queue, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
|
||||
FxObjectHandleGetPtr(pFxDriverGlobals,
|
||||
Queue,
|
||||
FX_TYPE_QUEUE,
|
||||
(PVOID*) &pQueue);
|
||||
device = (WDFDEVICE) pQueue->GetDevice()->GetHandle();
|
||||
|
||||
EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_ID, pActivityId);
|
||||
return PerformanceAnalysisPowerProcess(&FX_EVTIOSTOP_START, pActivityId, device);
|
||||
}
|
||||
|
||||
// EvtIoStop callback returned.
|
||||
__inline
|
||||
VOID
|
||||
PerfEvtIoStopStop(
|
||||
__in WDFQUEUE Queue,
|
||||
__in GUID* pActivityId
|
||||
)
|
||||
{
|
||||
FxIoQueue* pQueue;
|
||||
WDFOBJECT_OFFSET offset = 0;
|
||||
WDFDEVICE device;
|
||||
|
||||
FxObject *pObject = FxObject::_GetObjectFromHandle(Queue, &offset);
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
|
||||
FxObjectHandleGetPtr(pFxDriverGlobals,
|
||||
Queue,
|
||||
FX_TYPE_QUEUE,
|
||||
(PVOID*) &pQueue);
|
||||
device = (WDFDEVICE) pQueue->GetDevice()->GetHandle();
|
||||
|
||||
PerformanceAnalysisPowerProcess(&FX_EVTIOSTOP_STOP, pActivityId, device);
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyIrqlEntry(
|
||||
__out KIRQL *Irql
|
||||
)
|
||||
{
|
||||
DO_NOTHING();
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyIrqlExit(
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in KIRQL PrevIrql
|
||||
)
|
||||
{
|
||||
DO_NOTHING();
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyCriticalRegionEntry(
|
||||
__out BOOLEAN *CritRegion
|
||||
)
|
||||
{
|
||||
DO_NOTHING();
|
||||
}
|
||||
|
||||
__inline
|
||||
VOID
|
||||
VerifyCriticalRegionExit(
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in BOOLEAN OldCritRegion,
|
||||
__in PVOID Pfn
|
||||
)
|
||||
{
|
||||
DO_NOTHING();
|
||||
}
|
||||
|
5002
sdk/lib/drivers/wdf/shared/enhancedverif/um/vfwdfdynamics.cpp
Normal file
5002
sdk/lib/drivers/wdf/shared/enhancedverif/um/vfwdfdynamics.cpp
Normal file
File diff suppressed because it is too large
Load diff
650
sdk/lib/drivers/wdf/shared/enhancedverif/verifier.cpp
Normal file
650
sdk/lib/drivers/wdf/shared/enhancedverif/verifier.cpp
Normal file
|
@ -0,0 +1,650 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
Verifier.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
This file has implementation of verifier support routines
|
||||
|
||||
Author:
|
||||
|
||||
|
||||
|
||||
Environment:
|
||||
|
||||
Shared (Kernel and user)
|
||||
|
||||
Revision History:
|
||||
|
||||
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#include "vfpriv.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
extern WDFVERSION WdfVersion;
|
||||
|
||||
// Tracing support
|
||||
#if defined(EVENT_TRACING)
|
||||
#include "verifier.tmh"
|
||||
#endif
|
||||
|
||||
#ifdef ALLOC_PRAGMA
|
||||
#pragma alloc_text(FX_ENHANCED_VERIFIER_SECTION_NAME, \
|
||||
AddEventHooksWdfDeviceCreate, \
|
||||
AddEventHooksWdfIoQueueCreate, \
|
||||
VfAddContextToHandle, \
|
||||
VfAllocateContext, \
|
||||
VfWdfObjectGetTypedContext \
|
||||
)
|
||||
#endif
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
AddEventHooksWdfDeviceCreate(
|
||||
__inout PVF_HOOK_PROCESS_INFO HookProcessInfo,
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in PWDFDEVICE_INIT* DeviceInit,
|
||||
__in PWDF_OBJECT_ATTRIBUTES DeviceAttributes,
|
||||
__out WDFDEVICE* Device
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This routine is called by main hook for WdfDeviceCreate.
|
||||
The routine swaps the event callbacks provided by client.
|
||||
|
||||
Arguments:
|
||||
|
||||
Return value:
|
||||
|
||||
--*/
|
||||
{
|
||||
NTSTATUS status;
|
||||
PWDFDEVICE_INIT deviceInit = *DeviceInit;
|
||||
WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerEvtsOriginal;
|
||||
WDF_PNPPOWER_EVENT_CALLBACKS *pnpPowerEvts;
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
||||
PVOID contextHeader = NULL;
|
||||
WDF_OBJECT_ATTRIBUTES attributes;
|
||||
|
||||
PAGED_CODE_LOCKED();
|
||||
|
||||
pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
|
||||
|
||||
FxPointerNotNull(pFxDriverGlobals, DeviceInit);
|
||||
FxPointerNotNull(pFxDriverGlobals, *DeviceInit);
|
||||
FxPointerNotNull(pFxDriverGlobals, Device);
|
||||
|
||||
//
|
||||
// Check if there are any callbacks set by the client driver. If not, we
|
||||
// don't need any callback hooking.
|
||||
//
|
||||
if (deviceInit->PnpPower.PnpPowerEventCallbacks.Size !=
|
||||
sizeof(WDF_PNPPOWER_EVENT_CALLBACKS)) {
|
||||
//
|
||||
// no hooking required.
|
||||
//
|
||||
status = STATUS_SUCCESS;
|
||||
HookProcessInfo->DonotCallKmdfLib = FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// Hooking can be done only if we are able to allocate context memory.
|
||||
// Try to allocate a context
|
||||
//
|
||||
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(
|
||||
&attributes,
|
||||
VF_WDFDEVICECREATE_CONTEXT
|
||||
);
|
||||
|
||||
status = VfAllocateContext(DriverGlobals, &attributes, &contextHeader);
|
||||
|
||||
if (!NT_SUCCESS(status)) {
|
||||
//
|
||||
// couldn't allocate context. hooking not possible
|
||||
//
|
||||
HookProcessInfo->DonotCallKmdfLib = FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// store original driver callbacks to local variable
|
||||
//
|
||||
RtlCopyMemory(&pnpPowerEvtsOriginal,
|
||||
&deviceInit->PnpPower.PnpPowerEventCallbacks,
|
||||
sizeof(WDF_PNPPOWER_EVENT_CALLBACKS)
|
||||
);
|
||||
|
||||
//
|
||||
// Set callback hooks
|
||||
//
|
||||
// Normally override the hooks on local copy of stucture (not the original
|
||||
// structure itself) and then pass the local struture to DDI call and
|
||||
// copy back the original poniter when returning back to caller. In this case
|
||||
// device_init is null'ed out by fx when returning to caller so we can
|
||||
// directly override the original
|
||||
//
|
||||
pnpPowerEvts = &deviceInit->PnpPower.PnpPowerEventCallbacks;
|
||||
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceD0Entry);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceD0EntryPostInterruptsEnabled);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceD0Exit);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceD0ExitPreInterruptsDisabled);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDevicePrepareHardware);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceReleaseHardware);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceSelfManagedIoCleanup);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceSelfManagedIoFlush);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceSelfManagedIoInit);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceSelfManagedIoSuspend);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceSelfManagedIoRestart);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceSurpriseRemoval);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceQueryRemove);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceQueryStop);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceUsageNotification);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceUsageNotificationEx);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(pnpPowerEvts, pnpPowerEvts, EvtDeviceRelationsQuery);
|
||||
|
||||
//
|
||||
// Call the DDI on behalf of driver.
|
||||
//
|
||||
status = ((PFN_WDFDEVICECREATE)WdfVersion.Functions.pfnWdfDeviceCreate)(
|
||||
DriverGlobals,
|
||||
DeviceInit,
|
||||
DeviceAttributes,
|
||||
Device
|
||||
);
|
||||
//
|
||||
// Tell main hook routine not to call the DDI in kmdf lib since we
|
||||
// already called it
|
||||
//
|
||||
HookProcessInfo->DonotCallKmdfLib = TRUE;
|
||||
HookProcessInfo->DdiCallStatus = status;
|
||||
|
||||
//
|
||||
// if DDI Succeeds, add context
|
||||
//
|
||||
if (NT_SUCCESS(status)) {
|
||||
PVF_WDFDEVICECREATE_CONTEXT context = NULL;
|
||||
|
||||
//
|
||||
// add the already allocated context to the object.
|
||||
//
|
||||
status = VfAddContextToHandle(contextHeader,
|
||||
&attributes,
|
||||
*Device,
|
||||
(PVOID *)&context);
|
||||
|
||||
if (NT_SUCCESS(status)) {
|
||||
//
|
||||
// store the DriverGlobals pointer used to associate the driver
|
||||
// with its client driver callback later in the callback hooks
|
||||
//
|
||||
context->CommonHeader.DriverGlobals = DriverGlobals;
|
||||
|
||||
//
|
||||
// store original client driver callbacks in context
|
||||
//
|
||||
RtlCopyMemory(
|
||||
&context->PnpPowerEventCallbacksOriginal,
|
||||
&pnpPowerEvtsOriginal,
|
||||
sizeof(WDF_PNPPOWER_EVENT_CALLBACKS)
|
||||
);
|
||||
}
|
||||
else {
|
||||
//
|
||||
// For some reason adding context to handle failed. This should be
|
||||
// rare failure, because context allocation was already successful,
|
||||
// only adding to handle failed.
|
||||
//
|
||||
// Hooking failed if adding context is unsuccessful. This means
|
||||
// kmdf has callbacks hooks but verifier cannot assiociate client
|
||||
// driver callbacks with callback hooks. This would be a fatal error.
|
||||
//
|
||||
ASSERTMSG("KMDF Enhanced Verifier failed to add context to object "
|
||||
"handle\n", FALSE);
|
||||
|
||||
if (contextHeader != NULL) {
|
||||
FxPoolFree(contextHeader);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//
|
||||
// KMDF DDI call failed. In case of failure, DeviceInit is not NULL'ed
|
||||
// so the driver could potentially call WdfDeviceCreate again with this
|
||||
// DeviceInit that contains callback hooks, and result in infinite
|
||||
// callback loop. So put original callbacks back
|
||||
//
|
||||
if ((*DeviceInit) != NULL) {
|
||||
//
|
||||
// we overwrote only the pnppower callbacks. Put the original back.
|
||||
//
|
||||
deviceInit = *DeviceInit;
|
||||
RtlCopyMemory(&deviceInit->PnpPower.PnpPowerEventCallbacks,
|
||||
&pnpPowerEvtsOriginal,
|
||||
sizeof(WDF_PNPPOWER_EVENT_CALLBACKS)
|
||||
);
|
||||
}
|
||||
|
||||
if (contextHeader != NULL) {
|
||||
FxPoolFree(contextHeader);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
AddEventHooksWdfIoQueueCreate(
|
||||
__inout PVF_HOOK_PROCESS_INFO HookProcessInfo,
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in WDFDEVICE Device,
|
||||
__in PWDF_IO_QUEUE_CONFIG Config,
|
||||
__in PWDF_OBJECT_ATTRIBUTES QueueAttributes,
|
||||
__out WDFQUEUE* Queue
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Arguments:
|
||||
|
||||
Return value:
|
||||
|
||||
--*/
|
||||
{
|
||||
NTSTATUS status;
|
||||
WDF_IO_QUEUE_CONFIG configNew;
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
||||
WDFQUEUE *pQueue;
|
||||
WDFQUEUE queue;
|
||||
PVOID contextHeader = NULL;
|
||||
WDF_OBJECT_ATTRIBUTES attributes;
|
||||
|
||||
PAGED_CODE_LOCKED();
|
||||
|
||||
pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
|
||||
|
||||
FxPointerNotNull(pFxDriverGlobals, Config);
|
||||
|
||||
//
|
||||
// Check if there are any callbacks set by the client driver. If not, we
|
||||
// don't need any callback hooking.
|
||||
//
|
||||
if (Config->Size != sizeof(WDF_IO_QUEUE_CONFIG)) {
|
||||
//
|
||||
// no hooking required.
|
||||
//
|
||||
status = STATUS_SUCCESS;
|
||||
HookProcessInfo->DonotCallKmdfLib = FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// Hooking can be done only if we are able to allocate context memory.
|
||||
// Try to allocate a context
|
||||
//
|
||||
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes,
|
||||
VF_WDFIOQUEUECREATE_CONTEXT);
|
||||
|
||||
status = VfAllocateContext(DriverGlobals, &attributes, &contextHeader);
|
||||
|
||||
if (!NT_SUCCESS(status)) {
|
||||
//
|
||||
// couldn't allocate context. hooking not possible
|
||||
//
|
||||
HookProcessInfo->DonotCallKmdfLib = FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// create a local copy of config
|
||||
//
|
||||
RtlCopyMemory(&configNew,
|
||||
Config,
|
||||
sizeof(configNew)
|
||||
);
|
||||
|
||||
//
|
||||
// Override local copy with event callback hooks.
|
||||
//
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoDefault);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoRead);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoWrite);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoDeviceControl);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoInternalDeviceControl);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoStop);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoResume);
|
||||
SET_HOOK_IF_CALLBACK_PRESENT(Config, &configNew, EvtIoCanceledOnQueue);
|
||||
|
||||
//
|
||||
// Queue handle is an optional parameter
|
||||
//
|
||||
if (Queue == NULL) {
|
||||
pQueue = &queue;
|
||||
}
|
||||
else {
|
||||
pQueue = Queue;
|
||||
}
|
||||
|
||||
//
|
||||
// call the DDI
|
||||
//
|
||||
status = WdfVersion.Functions.pfnWdfIoQueueCreate(
|
||||
DriverGlobals,
|
||||
Device,
|
||||
&configNew,
|
||||
QueueAttributes,
|
||||
pQueue
|
||||
);
|
||||
|
||||
//
|
||||
// Tell main hook routine not to call the DDI in kmdf lib since we
|
||||
// already called it
|
||||
//
|
||||
HookProcessInfo->DonotCallKmdfLib = TRUE;
|
||||
HookProcessInfo->DdiCallStatus = status;
|
||||
|
||||
//
|
||||
// if DDI Succeeds, add context
|
||||
//
|
||||
if (NT_SUCCESS(status)) {
|
||||
PVF_WDFIOQUEUECREATE_CONTEXT context = NULL;
|
||||
|
||||
//
|
||||
// add the already allocated context to the object.
|
||||
//
|
||||
status = VfAddContextToHandle(contextHeader,
|
||||
&attributes,
|
||||
*pQueue,
|
||||
(PVOID *)&context);
|
||||
|
||||
if (NT_SUCCESS(status)) {
|
||||
//
|
||||
// store the DriverGlobals pointer used to associate the driver
|
||||
// with its client driver callback later in the callback hooks
|
||||
//
|
||||
context->CommonHeader.DriverGlobals = DriverGlobals;
|
||||
|
||||
//
|
||||
// add stored original callbacks to context
|
||||
//
|
||||
RtlCopyMemory(
|
||||
&context->IoQueueConfigOriginal,
|
||||
Config,
|
||||
sizeof(WDF_IO_QUEUE_CONFIG)
|
||||
);
|
||||
}
|
||||
else {
|
||||
//
|
||||
// For some reason adding context to handle failed. This should be
|
||||
// rare failure, because context allocation was already successful,
|
||||
// only adding to handle failed.
|
||||
//
|
||||
// Hooking failed if adding context is unsuccessful. This means
|
||||
// kmdf has callbacks hooks but verifier cannot assiociate client
|
||||
// driver callbacks with callback hooks. This would be a fatal error.
|
||||
//
|
||||
ASSERTMSG("KMDF Enhanced Verifier failed to add context to object "
|
||||
"handle\n", FALSE);
|
||||
|
||||
if (contextHeader != NULL) {
|
||||
FxPoolFree(contextHeader);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//
|
||||
// DDI call to KMDF failed. Nothing to do by verifier. Just return
|
||||
// kmdf's status after freeing context header memory.
|
||||
//
|
||||
if (contextHeader != NULL) {
|
||||
FxPoolFree(contextHeader);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
_Must_inspect_result_
|
||||
PVOID
|
||||
FASTCALL
|
||||
VfWdfObjectGetTypedContext(
|
||||
__in
|
||||
WDFOBJECT Handle,
|
||||
__in
|
||||
PCWDF_OBJECT_CONTEXT_TYPE_INFO TypeInfo
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Retrieves the requested type from a handle
|
||||
|
||||
Arguments:
|
||||
Handle - the handle to retrieve the context from
|
||||
TypeInfo - global constant pointer which describes the type. Since the pointer
|
||||
value is unique in all of kernel space, we will perform a pointer compare
|
||||
instead of a deep structure compare
|
||||
|
||||
Return Value:
|
||||
A valid context pointere or NULL. NULL is not a failure, querying for a type
|
||||
not associated with the handle is a legitimate operation.
|
||||
|
||||
--*/
|
||||
{
|
||||
FxContextHeader* pHeader;
|
||||
FxObject* pObject;
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
||||
WDFOBJECT_OFFSET offset;
|
||||
|
||||
PAGED_CODE_LOCKED();
|
||||
|
||||
//
|
||||
// Do not call FxObjectHandleGetPtr( , , FX_TYPE_OBJECT) because this is a
|
||||
// hot spot / workhorse function that should be as efficient as possible.
|
||||
//
|
||||
// A call to FxObjectHandleGetPtr would :
|
||||
// 1) invoke a virtual call to QueryInterface
|
||||
//
|
||||
// 2) ASSERT that the ref count of the object is > zero. Since this is one
|
||||
// of the few functions that can be called in EvtObjectDestroy where the
|
||||
// ref count is zero, that is not a good side affect.
|
||||
//
|
||||
offset = 0;
|
||||
pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
|
||||
//
|
||||
// Use the object's globals, not the caller's
|
||||
//
|
||||
pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
|
||||
FxPointerNotNull(pFxDriverGlobals, Handle);
|
||||
FxPointerNotNull(pFxDriverGlobals, TypeInfo);
|
||||
|
||||
pHeader = pObject->GetContextHeader();
|
||||
|
||||
for ( ; pHeader != NULL; pHeader = pHeader->NextHeader) {
|
||||
if (pHeader->ContextTypeInfo == TypeInfo) {
|
||||
return &pHeader->Context[0];
|
||||
}
|
||||
}
|
||||
|
||||
PCHAR pGivenName;
|
||||
|
||||
if (TypeInfo->ContextName != NULL) {
|
||||
pGivenName = TypeInfo->ContextName;
|
||||
}
|
||||
else {
|
||||
pGivenName = "<no typename given>";
|
||||
}
|
||||
|
||||
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_WARNING, TRACINGDEVICE,
|
||||
"Attempting to get context type %s from WDFOBJECT 0x%p",
|
||||
pGivenName, Handle);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
VfAllocateContext(
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in PWDF_OBJECT_ATTRIBUTES Attributes,
|
||||
__out PVOID* ContextHeader
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
Allocates an additional context on the handle if the object is in the
|
||||
correct state
|
||||
|
||||
Arguments:
|
||||
Handle - handle on which to add a context
|
||||
Attributes - attributes which describe the type and size of the new context
|
||||
Context - optional pointer which will recieve the new context
|
||||
|
||||
Return Value:
|
||||
STATUS_SUCCESS upon success, STATUS_OBJECT_NAME_EXISTS if the context type
|
||||
is already attached to the handle, and !NT_SUCCESS on failure
|
||||
|
||||
--*/
|
||||
{
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
||||
NTSTATUS status;
|
||||
FxContextHeader *pHeader;
|
||||
size_t size;
|
||||
|
||||
PAGED_CODE_LOCKED();
|
||||
|
||||
pFxDriverGlobals = GetFxDriverGlobals(DriverGlobals);
|
||||
|
||||
status = FxValidateObjectAttributes(
|
||||
pFxDriverGlobals, Attributes, FX_VALIDATE_OPTION_ATTRIBUTES_REQUIRED);
|
||||
if (!NT_SUCCESS(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// Must have a context type!
|
||||
//
|
||||
if (Attributes->ContextTypeInfo == NULL) {
|
||||
status = STATUS_OBJECT_NAME_INVALID;
|
||||
DoTraceLevelMessage(
|
||||
pFxDriverGlobals, TRACE_LEVEL_WARNING, TRACINGHANDLE,
|
||||
"Attributes %p ContextTypeInfo is NULL, %!STATUS!",
|
||||
Attributes, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
//
|
||||
// By passing 0's for raw object size and extra size, we can compute the
|
||||
// size of only the header and its contents.
|
||||
//
|
||||
status = FxCalculateObjectTotalSize(pFxDriverGlobals, 0, 0, Attributes, &size);
|
||||
if (!NT_SUCCESS(status)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
pHeader = (FxContextHeader*)
|
||||
FxPoolAllocate(pFxDriverGlobals, NonPagedPool, size);
|
||||
|
||||
if (pHeader != NULL) {
|
||||
*ContextHeader = pHeader;
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
else {
|
||||
status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
VfAddContextToHandle(
|
||||
__in PVOID ContextHeader,
|
||||
__in PWDF_OBJECT_ATTRIBUTES Attributes,
|
||||
__in WDFOBJECT Handle,
|
||||
__out_opt PVOID* Context
|
||||
)
|
||||
{
|
||||
PFX_DRIVER_GLOBALS pFxDriverGlobals;
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
FxObject* pObject;
|
||||
FxContextHeader *pHeader;
|
||||
WDFOBJECT_OFFSET offset;
|
||||
|
||||
PAGED_CODE_LOCKED();
|
||||
|
||||
pHeader = (FxContextHeader *)ContextHeader;
|
||||
|
||||
if (pHeader == NULL) {
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
//
|
||||
// No need to call FxObjectHandleGetPtr( , , FX_TYPE_OBJECT) because
|
||||
// we assume that the object handle will point back to an FxObject. (The
|
||||
// call to FxObjectHandleGetPtr will just make needless virtual call into
|
||||
// FxObject anyways).
|
||||
//
|
||||
offset = 0;
|
||||
pObject = FxObject::_GetObjectFromHandle(Handle, &offset);
|
||||
|
||||
pFxDriverGlobals = pObject->GetDriverGlobals();
|
||||
|
||||
if (offset != 0) {
|
||||
//
|
||||
// for lack of a better error code
|
||||
//
|
||||
status = STATUS_OBJECT_PATH_INVALID;
|
||||
|
||||
DoTraceLevelMessage(
|
||||
pFxDriverGlobals, TRACE_LEVEL_WARNING, TRACINGHANDLE,
|
||||
"WDFHANDLE %p cannot have contexts added to it, %!STATUS!",
|
||||
Handle, status);
|
||||
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
pObject->ADDREF(&status);
|
||||
|
||||
FxContextHeaderInit(pHeader, pObject, Attributes);
|
||||
|
||||
status = pObject->AddContext(pHeader, Context, Attributes);
|
||||
|
||||
//
|
||||
// STATUS_OBJECT_NAME_EXISTS will not fail NT_SUCCESS, so check
|
||||
// explicitly for STATUS_SUCCESS.
|
||||
//
|
||||
if (status != STATUS_SUCCESS) {
|
||||
DoTraceLevelMessage(
|
||||
pFxDriverGlobals, TRACE_LEVEL_WARNING, TRACINGHANDLE,
|
||||
"WDFHANDLE %p failed to add context, %!STATUS!",
|
||||
Handle, status);
|
||||
}
|
||||
|
||||
pObject->RELEASE(&status);
|
||||
|
||||
cleanup:
|
||||
|
||||
if (status != STATUS_SUCCESS && pHeader != NULL) {
|
||||
FxPoolFree(pHeader);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
} // extern "C"
|
1020
sdk/lib/drivers/wdf/shared/enhancedverif/vfeventhooks.cpp
Normal file
1020
sdk/lib/drivers/wdf/shared/enhancedverif/vfeventhooks.cpp
Normal file
File diff suppressed because it is too large
Load diff
50
sdk/lib/drivers/wdf/shared/enhancedverif/vfeventhooks.hpp
Normal file
50
sdk/lib/drivers/wdf/shared/enhancedverif/vfeventhooks.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
VfEventHooks.hpp
|
||||
|
||||
Abstract:
|
||||
Generated header of verifier event callback hooks
|
||||
|
||||
Environment:
|
||||
kernel mode only
|
||||
|
||||
** Warning ** : manual changes to this file will be lost.
|
||||
|
||||
--*/
|
||||
|
||||
#pragma once
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
EVT_WDF_DEVICE_D0_ENTRY VfEvtDeviceD0Entry;
|
||||
EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED VfEvtDeviceD0EntryPostInterruptsEnabled;
|
||||
EVT_WDF_DEVICE_D0_EXIT VfEvtDeviceD0Exit;
|
||||
EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED VfEvtDeviceD0ExitPreInterruptsDisabled;
|
||||
EVT_WDF_DEVICE_PREPARE_HARDWARE VfEvtDevicePrepareHardware;
|
||||
EVT_WDF_DEVICE_RELEASE_HARDWARE VfEvtDeviceReleaseHardware;
|
||||
EVT_WDF_DEVICE_SELF_MANAGED_IO_CLEANUP VfEvtDeviceSelfManagedIoCleanup;
|
||||
EVT_WDF_DEVICE_SELF_MANAGED_IO_FLUSH VfEvtDeviceSelfManagedIoFlush;
|
||||
EVT_WDF_DEVICE_SELF_MANAGED_IO_INIT VfEvtDeviceSelfManagedIoInit;
|
||||
EVT_WDF_DEVICE_SELF_MANAGED_IO_SUSPEND VfEvtDeviceSelfManagedIoSuspend;
|
||||
EVT_WDF_DEVICE_SELF_MANAGED_IO_RESTART VfEvtDeviceSelfManagedIoRestart;
|
||||
EVT_WDF_DEVICE_QUERY_STOP VfEvtDeviceQueryStop;
|
||||
EVT_WDF_DEVICE_QUERY_REMOVE VfEvtDeviceQueryRemove;
|
||||
EVT_WDF_DEVICE_SURPRISE_REMOVAL VfEvtDeviceSurpriseRemoval;
|
||||
EVT_WDF_DEVICE_USAGE_NOTIFICATION VfEvtDeviceUsageNotification;
|
||||
EVT_WDF_DEVICE_USAGE_NOTIFICATION_EX VfEvtDeviceUsageNotificationEx;
|
||||
EVT_WDF_DEVICE_RELATIONS_QUERY VfEvtDeviceRelationsQuery;
|
||||
EVT_WDF_IO_QUEUE_IO_DEFAULT VfEvtIoDefault;
|
||||
EVT_WDF_IO_QUEUE_IO_STOP VfEvtIoStop;
|
||||
EVT_WDF_IO_QUEUE_IO_RESUME VfEvtIoResume;
|
||||
EVT_WDF_IO_QUEUE_IO_READ VfEvtIoRead;
|
||||
EVT_WDF_IO_QUEUE_IO_WRITE VfEvtIoWrite;
|
||||
EVT_WDF_IO_QUEUE_IO_DEVICE_CONTROL VfEvtIoDeviceControl;
|
||||
EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL VfEvtIoInternalDeviceControl;
|
||||
EVT_WDF_IO_QUEUE_IO_CANCELED_ON_QUEUE VfEvtIoCanceledOnQueue;
|
||||
|
||||
} // extern "C"
|
138
sdk/lib/drivers/wdf/shared/enhancedverif/vfpriv.hpp
Normal file
138
sdk/lib/drivers/wdf/shared/enhancedverif/vfpriv.hpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
vfpriv.hpp
|
||||
|
||||
Abstract:
|
||||
|
||||
common header file for verifier
|
||||
|
||||
Author:
|
||||
|
||||
|
||||
|
||||
Environment:
|
||||
|
||||
user/kernel mode
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
|
||||
#if FX_CORE_MODE==FX_CORE_KERNEL_MODE
|
||||
#include "VfPrivKm.hpp"
|
||||
#else if ((FX_CORE_MODE)==(FX_CORE_USER_MODE))
|
||||
#include "VfPrivUm.hpp"
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "FxDynamics.h"
|
||||
}
|
||||
#include "vfeventhooks.hpp"
|
||||
|
||||
|
||||
#define FX_ENHANCED_VERIFIER_SECTION_NAME WDF_FX_VF_SECTION_NAME
|
||||
|
||||
#define GET_CONTEXT(_objectHandle, _type) \
|
||||
(_type *)VfWdfObjectGetTypedContext(_objectHandle, WDF_GET_CONTEXT_TYPE_INFO(_type));
|
||||
|
||||
#define SET_HOOK_IF_CALLBACK_PRESENT(Source, Target, Name) \
|
||||
if ((Source)-> ## Name != NULL) { \
|
||||
(Target)-> ## Name = Vf ## Name; \
|
||||
}
|
||||
|
||||
typedef struct _VF_HOOK_PROCESS_INFO {
|
||||
//
|
||||
// Return status of the DDI of called by hook routine.
|
||||
// this will be returned by stub if it does not call the DDI (since
|
||||
// hook already called.
|
||||
//
|
||||
ULONG DdiCallStatus;
|
||||
|
||||
//
|
||||
// Whether kmdf lib needs to be called after hook functin returns
|
||||
//
|
||||
BOOLEAN DonotCallKmdfLib;
|
||||
|
||||
} VF_HOOK_PROCESS_INFO, *PVF_HOOK_PROCESS_INFO;
|
||||
|
||||
typedef struct _VF_COMMON_CONTEXT_HEADER {
|
||||
|
||||
PWDF_DRIVER_GLOBALS DriverGlobals;
|
||||
|
||||
} VF_COMMON_CONTEXT_HEADER, *PVF_COMMON_CONTEXT_HEADER;
|
||||
|
||||
typedef struct _VF_WDFDEVICECREATE_CONTEXT {
|
||||
|
||||
VF_COMMON_CONTEXT_HEADER CommonHeader;
|
||||
|
||||
WDF_PNPPOWER_EVENT_CALLBACKS PnpPowerEventCallbacksOriginal;
|
||||
|
||||
} VF_WDFDEVICECREATE_CONTEXT, *PVF_WDFDEVICECREATE_CONTEXT;
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE(VF_WDFDEVICECREATE_CONTEXT);
|
||||
|
||||
typedef struct _VF_WDFIOQUEUECREATE_CONTEXT {
|
||||
|
||||
VF_COMMON_CONTEXT_HEADER CommonHeader;
|
||||
|
||||
WDF_IO_QUEUE_CONFIG IoQueueConfigOriginal;
|
||||
|
||||
} VF_WDFIOQUEUECREATE_CONTEXT, *PVF_WDFIOQUEUECREATE_CONTEXT;
|
||||
|
||||
WDF_DECLARE_CONTEXT_TYPE(VF_WDFIOQUEUECREATE_CONTEXT);
|
||||
|
||||
extern "C" {
|
||||
|
||||
_Must_inspect_result_
|
||||
PVOID
|
||||
FASTCALL
|
||||
VfWdfObjectGetTypedContext(
|
||||
__in
|
||||
WDFOBJECT Handle,
|
||||
__in
|
||||
PCWDF_OBJECT_CONTEXT_TYPE_INFO TypeInfo
|
||||
);
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
VfAllocateContext(
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in PWDF_OBJECT_ATTRIBUTES Attributes,
|
||||
__out PVOID* ContextHeader
|
||||
);
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
VfAddContextToHandle(
|
||||
__in PVOID ContextHeader,
|
||||
__in PWDF_OBJECT_ATTRIBUTES Attributes,
|
||||
__in WDFOBJECT Handle,
|
||||
__out_opt PVOID* Context
|
||||
);
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
AddEventHooksWdfDeviceCreate(
|
||||
__inout PVF_HOOK_PROCESS_INFO HookProcessInfo,
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in PWDFDEVICE_INIT* DeviceInit,
|
||||
__in PWDF_OBJECT_ATTRIBUTES DeviceAttributes,
|
||||
__out WDFDEVICE* Device
|
||||
);
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
AddEventHooksWdfIoQueueCreate(
|
||||
__inout PVF_HOOK_PROCESS_INFO HookProcessInfo,
|
||||
__in PWDF_DRIVER_GLOBALS DriverGlobals,
|
||||
__in WDFDEVICE Device,
|
||||
__in PWDF_IO_QUEUE_CONFIG Config,
|
||||
__in PWDF_OBJECT_ATTRIBUTES QueueAttributes,
|
||||
__out WDFQUEUE* Queue
|
||||
);
|
||||
|
||||
} // extern "C"
|
Loading…
Add table
Add a link
Reference in a new issue