ReactOS 0.4.15-dev-8428-g6910fa6
fxtelemetry.hpp File Reference
#include <strsafe.h>
#include "fxtelemetrycommon.hpp"
#include "fxtelemetrykm.hpp"
Include dependency graph for fxtelemetry.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FX_TELEMETRY_ENABLED(TraceHandle, Globals)    (TraceHandle && IsDriverTelemetryContextInitialized(Globals)) \
 
#define WDF_CENSUS_EVT_DATA_COMMON(FxGlobals)
 
#define WDF_CENSUS_EVT_WRITE_DRIVER_LOAD(TraceHandle, Globals, DrvImage, WdfVersion)
 
#define MIN_HOURS_BEFORE_NEXT_LOG   24
 
#define BASE_10   (10)
 
#define WDF_LAST_TELEMETRY_LOG_TIME_VALUE   L"TimeOfLastTelemetryLog"
 
#define WDF_DRIVER_IMAGE_NAME_VALUE   L"ImagePath"
 
#define WDF_VERSION_STRING_SIZE_INCLUDING_SEPARATOR_CCH   10
 

Typedefs

typedef enum _FX_TELEMETRY_DO_ONCE_BITS FX_TELEMETRY_DO_ONCE_BITS
 

Enumerations

enum  _FX_TELEMETRY_DO_ONCE_BITS { DeviceStartEventBit = 0 }
 
enum  FxDeviceInfoFlags : USHORT {
  DeviceInfoLineBasedLevelTriggeredInterrupt = 0x1 , DeviceInfoLineBasedEdgeTriggeredInterrupt = 0x2 , DeviceInfoMsiXOrSingleMsi22Interrupt = 0x4 , DeviceInfoMsi22MultiMessageInterrupt = 0x8 ,
  DeviceInfoPassiveLevelInterrupt = 0x10 , DeviceInfoDmaBusMaster = 0x20 , DeviceInfoDmaSystem = 0x40 , DeviceInfoDmaSystemDuplex = 0x80 ,
  DeviceInfoHasStaticChildren = 0x100 , DeviceInfoHasDynamicChildren = 0x200 , DeviceInfoIsUsingDriverWppRecorder = 0x400
}
 

Functions

BOOLEAN __inline IsDeviceInfoFlagSet (_In_ USHORT DeviceInfo, _In_ FxDeviceInfoFlags Flag)
 
VOID AllocAndInitializeTelemetryContext (_In_ PFX_TELEMETRY_CONTEXT *TelemetryContext)
 
__inline BOOLEAN IsDriverTelemetryContextInitialized (_In_ PFX_DRIVER_GLOBALS FxDrvGlobals)
 
VOID RegisterTelemetryProvider (VOID)
 
VOID UnregisterTelemetryProvider (VOID)
 
VOID LogDeviceStartTelemetryEvent (_In_ PFX_DRIVER_GLOBALS Globals, _In_opt_ FxDevice *Fdo)
 
VOID LogDriverInfoStream (_In_ PFX_DRIVER_GLOBALS Globals, _In_opt_ FxDevice *Fdo)
 
_Must_inspect_result_ NTSTATUS GetImageName (_In_ PFX_DRIVER_GLOBALS DriverGlobals, _Out_ PUNICODE_STRING ImageName)
 
VOID __inline BuildStringFromPartialInfo (_In_ PKEY_VALUE_PARTIAL_INFORMATION Info, _Out_ PUNICODE_STRING String)
 
VOID GetNameFromPath (_In_ PCUNICODE_STRING Path, _Out_ PUNICODE_STRING Name)
 

Macro Definition Documentation

◆ BASE_10

#define BASE_10   (10)

Definition at line 90 of file fxtelemetry.hpp.

◆ FX_TELEMETRY_ENABLED

#define FX_TELEMETRY_ENABLED (   TraceHandle,
  Globals 
)     (TraceHandle && IsDriverTelemetryContextInitialized(Globals)) \

Definition at line 45 of file fxtelemetry.hpp.

◆ MIN_HOURS_BEFORE_NEXT_LOG

#define MIN_HOURS_BEFORE_NEXT_LOG   24

Definition at line 89 of file fxtelemetry.hpp.

◆ WDF_CENSUS_EVT_DATA_COMMON

#define WDF_CENSUS_EVT_DATA_COMMON (   FxGlobals)
Value:
TraceLoggingStruct(1, "CensusCommonV1"), \
TraceLoggingGuid((FxGlobals)->TelemetryContext->DriverSessionGUID, "SessionGUID")

Definition at line 48 of file fxtelemetry.hpp.

◆ WDF_CENSUS_EVT_WRITE_DRIVER_LOAD

#define WDF_CENSUS_EVT_WRITE_DRIVER_LOAD (   TraceHandle,
  Globals,
  DrvImage,
  WdfVersion 
)
Value:
TraceLoggingWrite(TraceHandle, \
"WdfCensusEvtDrvLoad", \
TraceLoggingStruct(9, "DriverInfo" ), \
TraceLoggingString((Globals)->Public.DriverName, "DriverService" ), \
TraceLoggingWideString(DrvImage, "DriverImage" ), \
TraceLoggingWideString(WdfVersion, "WdfVersion" ), \
TraceLoggingUInt32((Globals)->WdfBindInfo->Version.Major, "DriverVersionMajor" ), \
TraceLoggingUInt32((Globals)->WdfBindInfo->Version.Minor, "DriverVersionMinor" ), \
TraceLoggingBoolean((Globals)->FxVerifierOn, "FxVerifierOn" ), \
TraceLoggingBoolean(!!((Globals)->Public.DriverFlags & WdfDriverInitNonPnpDriver), "DriverNonPnP" ), \
TraceLoggingBoolean(!!((Globals)->Public.DriverFlags & WdfDriverInitNoDispatchOverride), "DriverNoDispatchOverride" ), \
TraceLoggingUInt32((Globals)->FxEnhancedVerifierOptions, "FxEnhancedVeriferOptions" ) \
);
CLIPBOARD_GLOBALS Globals
Definition: clipbrd.c:13
#define WDF_CENSUS_EVT_DATA_COMMON(FxGlobals)
Definition: fxtelemetry.hpp:48
#define WDF_TELEMETRY_EVT_KEYWORDS
WDFVERSION WdfVersion
WDF_BIND_INFO WdfBindInfo
WDF_VERSION Version
Definition: fxldr.h:133
WDF_MAJOR_VERSION Major
Definition: fxldr.h:122
WDF_MINOR_VERSION Minor
Definition: fxldr.h:123
@ WdfDriverInitNonPnpDriver
Definition: wdfdriver.h:51
@ WdfDriverInitNoDispatchOverride
Definition: wdfdriver.h:52

Definition at line 72 of file fxtelemetry.hpp.

◆ WDF_DRIVER_IMAGE_NAME_VALUE

#define WDF_DRIVER_IMAGE_NAME_VALUE   L"ImagePath"

Definition at line 93 of file fxtelemetry.hpp.

◆ WDF_LAST_TELEMETRY_LOG_TIME_VALUE

#define WDF_LAST_TELEMETRY_LOG_TIME_VALUE   L"TimeOfLastTelemetryLog"

Definition at line 92 of file fxtelemetry.hpp.

◆ WDF_VERSION_STRING_SIZE_INCLUDING_SEPARATOR_CCH

#define WDF_VERSION_STRING_SIZE_INCLUDING_SEPARATOR_CCH   10

Definition at line 115 of file fxtelemetry.hpp.

Typedef Documentation

◆ FX_TELEMETRY_DO_ONCE_BITS

Enumeration Type Documentation

◆ _FX_TELEMETRY_DO_ONCE_BITS

Enumerator
DeviceStartEventBit 

Definition at line 56 of file fxtelemetry.hpp.

56 {
enum _FX_TELEMETRY_DO_ONCE_BITS FX_TELEMETRY_DO_ONCE_BITS
@ DeviceStartEventBit
Definition: fxtelemetry.hpp:57

◆ FxDeviceInfoFlags

Enumerator
DeviceInfoLineBasedLevelTriggeredInterrupt 
DeviceInfoLineBasedEdgeTriggeredInterrupt 
DeviceInfoMsiXOrSingleMsi22Interrupt 
DeviceInfoMsi22MultiMessageInterrupt 
DeviceInfoPassiveLevelInterrupt 
DeviceInfoDmaBusMaster 
DeviceInfoDmaSystem 
DeviceInfoDmaSystemDuplex 
DeviceInfoHasStaticChildren 
DeviceInfoHasDynamicChildren 
DeviceInfoIsUsingDriverWppRecorder 

Definition at line 98 of file fxtelemetry.hpp.

98 : USHORT {
105 DeviceInfoDmaSystem = 0x40,
110};
@ DeviceInfoHasStaticChildren
@ DeviceInfoLineBasedEdgeTriggeredInterrupt
@ DeviceInfoMsi22MultiMessageInterrupt
@ DeviceInfoMsiXOrSingleMsi22Interrupt
@ DeviceInfoDmaBusMaster
@ DeviceInfoIsUsingDriverWppRecorder
@ DeviceInfoDmaSystem
@ DeviceInfoLineBasedLevelTriggeredInterrupt
Definition: fxtelemetry.hpp:99
@ DeviceInfoDmaSystemDuplex
@ DeviceInfoHasDynamicChildren
@ DeviceInfoPassiveLevelInterrupt
unsigned short USHORT
Definition: pedump.c:61

Function Documentation

◆ AllocAndInitializeTelemetryContext()

VOID AllocAndInitializeTelemetryContext ( _In_ PFX_TELEMETRY_CONTEXT TelemetryContext)

Definition at line 46 of file fxtelemetrykm.cpp.

49{
52
56 FX_TAG);
57 if (NULL == context) {
58 goto exit;
59 }
60
61 status = ExUuidCreate(&(context->DriverSessionGUID));
62 if (!NT_SUCCESS(status)) {
64 context = NULL;
65 goto exit;
66 }
67
68 context->DoOnceFlagsBitmap = 0;
69
70exit:
71 *TelemetryContext = context;
72}
LONG NTSTATUS
Definition: precomp.h:26
static __inline VOID MxFreePool(__in PVOID Ptr)
Definition: mxmemorykm.h:41
static __inline PVOID MxAllocatePoolWithTag(__in POOL_TYPE PoolType, __in SIZE_T NumberOfBytes, __in ULONG Tag)
Definition: mxmemorykm.h:30
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define NonPagedPool
Definition: env_spec_w32.h:307
struct _FX_TELEMETRY_CONTEXT * PFX_TELEMETRY_CONTEXT
#define FX_TAG
Definition: fxmacros.hpp:155
NTSTATUS status
NTKERNELAPI NTSTATUS ExUuidCreate(OUT UUID *Uuid)
Definition: uuid.c:380
#define exit(n)
Definition: config.h:202
Definition: http.c:7252
Definition: ps.c:97

Referenced by FxAllocateDriverGlobals().

◆ BuildStringFromPartialInfo()

VOID __inline BuildStringFromPartialInfo ( _In_ PKEY_VALUE_PARTIAL_INFORMATION  Info,
_Out_ PUNICODE_STRING  String 
)

Definition at line 173 of file fxtelemetry.hpp.

177{
178 String->Buffer = (PWCHAR) &Info->Data[0];
179 String->MaximumLength = (USHORT) Info->DataLength;
180 String->Length = String->MaximumLength - sizeof(UNICODE_NULL);
181
182 //
183 // ensure string is null terminated
184 //
185 String->Buffer[String->Length/sizeof(WCHAR)] = UNICODE_NULL;
186}
#define UNICODE_NULL
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by GetImageName().

◆ GetImageName()

_Must_inspect_result_ NTSTATUS GetImageName ( _In_ PFX_DRIVER_GLOBALS  DriverGlobals,
_Out_ PUNICODE_STRING  ImageName 
)

Definition at line 521 of file fxtelemetrykm.cpp.

542{
545 DECLARE_CONST_UNICODE_STRING(valueName, L"ImagePath");
546 UNICODE_STRING imagePath = {0};
547 UNICODE_STRING imageName = {0};
549 USHORT size;
550
553
554 //
555 // Open driver's Service base key
556 //
557 status = FxRegKey::_OpenKey(NULL,
558 DriverGlobals->Driver->GetRegistryPathUnicodeString(),
559 &hKey.m_Key,
560 KEY_READ);
561 if (!NT_SUCCESS(status)) {
563 "Unable to open driver's service key, status %!STATUS!", status);
564 return status;
565 }
566
567 status = QueryAndAllocString(hKey.m_Key,
569 &valueName,
570 &value);
571 if (!NT_SUCCESS(status)) {
573 "Failed to get Image name from service key, status %!STATUS!",
574 status);
575 return status;
576 }
577
579
580 //
581 // Now read the "ImagePath" and extract just the driver filename as a new
582 // unicode string.
583 //
584 GetNameFromPath(&imagePath, &imageName);
585
586 if (imageName.Length == 0x0) {
589 "ERROR: GetNameFromPath could not find a name, status 0x%x\n",
590 status);
591 goto cleanUp;
592 }
593
594 //
595 // Check for interger overflow for length before we allocate memory
596 // size = path->Length + sizeof(UNICODE_NULL);
597 // len is used below to compute the string size including the NULL, so
598 // compute len to include the terminating NULL.
599 //
600 status = RtlUShortAdd(imageName.Length, sizeof(UNICODE_NULL), &size);
601 if (!NT_SUCCESS(status)) {
603 "ERROR: size computation failed with Status 0x%x\n", status);
604 goto cleanUp;
605 }
606
607 //
608 // allocate a buffer to hold Unicode string + null char.
609 //
610 ImageName->Buffer = (PWCH) FxPoolAllocate(DriverGlobals, PagedPool, size);
611
612 if (ImageName->Buffer == NULL) {
615 "ERROR: ExAllocatePoolWithTag failed with Status 0x%x\n", status);
616 goto cleanUp;
617 }
618
619 RtlZeroMemory(ImageName->Buffer, size);
620 ImageName->Length = 0x0;
621 ImageName->MaximumLength = size;
622
623 status = RtlUnicodeStringCopy(ImageName, &imageName);
624
625 //
626 // The copy cannot fail since we setup the buffer to hold enough space for
627 // the contents of the ImagePath value.
628 //
630
631cleanUp:
632
633 if (value != NULL) {
635 }
636
637 return status;
638}
#define TRACINGDRIVER
Definition: dbgtrace.h:68
void cleanUp()
Definition: main.cpp:469
#define PagedPool
Definition: env_spec_w32.h:308
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
DriverGlobals
FxAutoRegKey hKey
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
VOID GetNameFromPath(_In_ PCUNICODE_STRING Path, _Out_ PUNICODE_STRING Name)
Definition: fxtelemetry.cpp:54
VOID __inline BuildStringFromPartialInfo(_In_ PKEY_VALUE_PARTIAL_INFORMATION Info, _Out_ PUNICODE_STRING String)
GLsizeiptr size
Definition: glext.h:5919
#define ASSERT(a)
Definition: mode.c:44
static const char * ImageName
Definition: image.c:34
#define KEY_READ
Definition: nt_native.h:1023
WCHAR * PWCH
Definition: ntbasedef.h:410
#define L(x)
Definition: ntvdm.h:50
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: pdh_main.c:94
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161

Referenced by if().

◆ GetNameFromPath()

VOID GetNameFromPath ( _In_ PCUNICODE_STRING  Path,
_Out_ PUNICODE_STRING  Name 
)

Definition at line 54 of file fxtelemetry.cpp.

78{
79 BOOLEAN foundSlash;
80
81 ASSERT(Path != NULL);
82
83 //
84 // Ideally a check of Path->Length == 0 would be sufficient except that
85 // PreFAST thinks that Length can be odd, so it thinks Length == 1 is possible.
86 // Comparing Length < sizeof(WCHAR) satisfies PreFAST and keeps the logic
87 // at runtime correct.
88 //
89 if (Path->Length < sizeof(WCHAR)) {
91 return;
92 }
93
94 //
95 // Initialize Name to point to the last WCHAR of the buffer and we will work
96 // our way backwards to the beginning of the string or a \
97 //
98
99 Name->Buffer = WDF_PTR_ADD_OFFSET_TYPE(Path->Buffer,
100 Path->Length - sizeof(WCHAR),
101 PWCH);
102 Name->Length = sizeof(WCHAR);
103 foundSlash = FALSE;
104
105 while (Name->Buffer >= Path->Buffer) {
106 if (*Name->Buffer == L'\\') {
107 //
108 // Skip the \ in the buffer moving forward a character and adjusting
109 // the length
110 //
111 foundSlash = TRUE;
112 Name->Buffer++;
113 Name->Length -= sizeof(WCHAR);
114 break;
115 }
116
117 //
118 // Move backwards in the string
119 //
120 Name->Buffer--;
121 Name->Length += sizeof(WCHAR);
122 }
123
124 if (foundSlash && Name->Length == 0) {
125 //
126 // Handle the case where a slash was found and it is the only character
127 //
128 Name->Buffer = NULL;
129 }
130 else if (foundSlash == FALSE) {
131 //
132 // Handle the case where no slash was found. In this case, Name->Buffer
133 // points to one WCHAR before the beginning of the string.
134 //
135 Name->Length -= sizeof(WCHAR);
136 Name->Buffer++;
137 }
138
139 //
140 // Need to set MaximumLength to the same value as Length so that the struct
141 // format is valid.
142 //
143 Name->MaximumLength = Name->Length;
144}
unsigned char BOOLEAN
PRTL_UNICODE_STRING_BUFFER Path
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, _type)
Definition: wdfcore.h:141

Referenced by FxLibraryCommonRegisterClient(), and GetImageName().

◆ IsDeviceInfoFlagSet()

BOOLEAN __inline IsDeviceInfoFlagSet ( _In_ USHORT  DeviceInfo,
_In_ FxDeviceInfoFlags  Flag 
)

Definition at line 119 of file fxtelemetry.hpp.

123{
125}
#define FLAG_TO_BOOL(_Flags, _FlagMask)
Definition: fxobject.hpp:125
Definition: xml2sdb.h:80

Referenced by GetDriverInfo().

◆ IsDriverTelemetryContextInitialized()

__inline BOOLEAN IsDriverTelemetryContextInitialized ( _In_ PFX_DRIVER_GLOBALS  FxDrvGlobals)

Definition at line 134 of file fxtelemetry.hpp.

137{
138 ASSERT(FxDrvGlobals);
139 return (NULL != FxDrvGlobals->TelemetryContext);
140}

◆ LogDeviceStartTelemetryEvent()

VOID LogDeviceStartTelemetryEvent ( _In_ PFX_DRIVER_GLOBALS  Globals,
_In_opt_ FxDevice Fdo 
)

Definition at line 91 of file fxtelemetrykm.cpp.

95{
96 //
97 // See if telemetry registered and all the criteria to log is met.
99 return;
100 }
101
102 //
103 // Log driver info stream
104 //
106}
VOID LogDriverInfoStream(_In_ PFX_DRIVER_GLOBALS DriverGlobals, _In_opt_ FxDevice *Fdo)
BOOLEAN IsLoggingEnabledAndNeeded(_In_ PFX_DRIVER_GLOBALS DriverGlobals)
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461

◆ LogDriverInfoStream()

VOID LogDriverInfoStream ( _In_ PFX_DRIVER_GLOBALS  Globals,
_In_opt_ FxDevice Fdo 
)

Definition at line 171 of file fxtelemetrykm.cpp.

175{
176 FxTelemetryDriverInfo driverInfo = {0};
177 FxAutoString hardwareIDs, setupClass, busEnum, manufacturer;
178
179 //
180 // Log driver and device info
181 //
182 GetDriverInfo(DriverGlobals, Fdo, &driverInfo);
183
184 if (Fdo != NULL) {
185 //
186 // Get Setup class
187 //
190 &setupClass.m_UnicodeString);
191 //
192 // Get Bus enumerator
193 //
196 &busEnum.m_UnicodeString);
197 //
198 // Get hardware id multi-string
199 //
202 &hardwareIDs.m_UnicodeString);
203
205
206 //
207 // Get manufacturer
208 //
211 &manufacturer.m_UnicodeString);
212 }
213
214 KMDF_CENSUS_EVT_WRITE_DEVICE_START(g_TelemetryProvider,
216 driverInfo,
217 setupClass,
218 busEnum,
219 hardwareIDs,
220 manufacturer);
221
222 //
223 // write current time to registry
224 //
226}
VOID GetDriverInfo(_In_ PFX_DRIVER_GLOBALS Globals, _In_opt_ FxDevice *Fdo, _Out_ FxTelemetryDriverInfo *DriverInfo)
VOID FxGetDevicePropertyString(_In_ FxDevice *Fdo, _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty, _Out_ PUNICODE_STRING PropertyString)
VOID RegistryWriteCurrentTime(_In_ PFX_DRIVER_GLOBALS DriverGlobals)
VOID GetFirstHardwareId(_Inout_ PUNICODE_STRING HardwareIds)
#define KMDF_CENSUS_EVT_WRITE_DEVICE_START(TraceHandle, Globals, DriverConfig, SetupClass, BusEnum, HwID, Manafacturer)
UNICODE_STRING m_UnicodeString
@ DevicePropertyEnumeratorName
Definition: iotypes.h:1210
@ DevicePropertyManufacturer
Definition: iotypes.h:1203
@ DevicePropertyClassName
Definition: iotypes.h:1200
@ DevicePropertyHardwareID
Definition: iotypes.h:1196

Referenced by LogDeviceStartTelemetryEvent().

◆ RegisterTelemetryProvider()

VOID RegisterTelemetryProvider ( VOID  )

Definition at line 75 of file fxtelemetrykm.cpp.

78{
79 TraceLoggingRegister(g_TelemetryProvider);
80}

Referenced by FxLibraryCommonCommission().

◆ UnregisterTelemetryProvider()

VOID UnregisterTelemetryProvider ( VOID  )

Definition at line 83 of file fxtelemetrykm.cpp.

86{
87 TraceLoggingUnregister(g_TelemetryProvider);
88}

Referenced by FxLibraryCommonDecommission().