ReactOS 0.4.15-dev-7934-g1dc8d80
fxtelemetrykm.cpp File Reference
#include "fxsupportpch.hpp"
#include "fxldr.h"
#include <ntstrsafe.h>
#include <winmeta.h>
#include <telemetry\microsofttelemetry.h>
Include dependency graph for fxtelemetrykm.cpp:

Go to the source code of this file.

Functions

 TRACELOGGING_DEFINE_PROVIDER (g_TelemetryProvider, KMDF_FX_TRACE_LOGGING_PROVIDER_NAME,(0xec044b58, 0x3d13, 0x4880, 0x93, 0x6f, 0x7b, 0x67, 0xdf, 0xb3, 0xe0, 0x56), TraceLoggingOptionMicrosoftTelemetry())
 
VOID AllocAndInitializeTelemetryContext (_In_ PFX_TELEMETRY_CONTEXT *TelemetryContext)
 
VOID RegisterTelemetryProvider (VOID)
 
VOID UnregisterTelemetryProvider (VOID)
 
VOID LogDeviceStartTelemetryEvent (_In_ PFX_DRIVER_GLOBALS DriverGlobals, _In_opt_ FxDevice *Fdo)
 
BOOLEAN IsLoggingEnabledAndNeeded (_In_ PFX_DRIVER_GLOBALS DriverGlobals)
 
VOID LogDriverInfoStream (_In_ PFX_DRIVER_GLOBALS DriverGlobals, _In_opt_ FxDevice *Fdo)
 
VOID GetFirstHardwareId (_Inout_ PUNICODE_STRING HardwareIds)
 
VOID GetDriverInfo (_In_ PFX_DRIVER_GLOBALS Globals, _In_opt_ FxDevice *Fdo, _Out_ FxTelemetryDriverInfo *DriverInfo)
 
VOID RegistryReadLastLoggedTime (_In_ PFX_DRIVER_GLOBALS DriverGlobals, _Out_ PLARGE_INTEGER LastLoggedTime)
 
VOID RegistryWriteCurrentTime (_In_ PFX_DRIVER_GLOBALS DriverGlobals)
 
VOID FxGetDevicePropertyString (_In_ FxDevice *Fdo, _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty, _Out_ PUNICODE_STRING PropertyString)
 
_Must_inspect_result_ NTSTATUS GetImageName (_In_ PFX_DRIVER_GLOBALS DriverGlobals, _Out_ PUNICODE_STRING ImageName)
 
_Must_inspect_result_ __drv_maxIRQL (PASSIVE_LEVEL) NTSTATUS QueryAndAllocString(_In_ HANDLE Key
 
 ASSERT (Info !=NULL)
 
 if (!NT_SUCCESS(status) &&status !=STATUS_BUFFER_TOO_SMALL)
 
 if (!NT_SUCCESS(status))
 
 if (info==NULL)
 
 RtlZeroMemory (info, length)
 
 if (NT_SUCCESS(status))
 

Variables

_Must_inspect_result_ _In_ PFX_DRIVER_GLOBALS Globals
 
_Must_inspect_result_ _In_ PFX_DRIVER_GLOBALS _In_ PCUNICODE_STRING ValueName
 
_Must_inspect_result_ _In_ PFX_DRIVER_GLOBALS _In_ PCUNICODE_STRING _Out_ PKEY_VALUE_PARTIAL_INFORMATIONInfo
 
NTSTATUS status = STATUS_UNSUCCESSFUL
 
ULONG length
 
 info = NULL
 
cleanup __pad0__
 

Function Documentation

◆ __drv_maxIRQL()

_Must_inspect_result_ __drv_maxIRQL ( PASSIVE_LEVEL  )

◆ 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:32
#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

◆ ASSERT()

ASSERT ( Info = NULL)

◆ FxGetDevicePropertyString()

VOID FxGetDevicePropertyString ( _In_ FxDevice Fdo,
_In_ DEVICE_REGISTRY_PROPERTY  DeviceProperty,
_Out_ PUNICODE_STRING  PropertyString 
)

Definition at line 458 of file fxtelemetrykm.cpp.

463{
464 MdDeviceObject pdo;
466 PFX_DRIVER_GLOBALS pFxDriverGlobals = Fdo->GetDriverGlobals();
467 ULONG length = 0;
468 PVOID buffer = NULL;
469
470 ASSERT(PropertyString != NULL);
471 RtlZeroMemory(PropertyString, sizeof(UNICODE_STRING));
472
473 pdo = Fdo->GetSafePhysicalDevice();
474 if (pdo == NULL) {
477 "Could not get PDO from FDO WDFDEVICE 0x%p, %!STATUS!",
478 Fdo->GetHandle(), status);
479 return;
480 }
481
485 "Could not retrieve property %d length %d, %!STATUS!",
487 return;
488 }
489
490 buffer = FxPoolAllocate(pFxDriverGlobals, PagedPool, length);
491 if (buffer == NULL) {
494 "Could not allocate memory for property %d length %d, %!STATUS!",
496 return;
497 }
498
500 if (!NT_SUCCESS(status)) {
502 "Could not query for full buffer, size %d, for "
503 "property %d, %!STATUS!",
506 return;
507 }
508
509 PropertyString->Buffer = (PWCH)buffer;
510 PropertyString->Length = (USHORT) length - sizeof(UNICODE_NULL);
511 PropertyString->MaximumLength = (USHORT) length;
512
513 //
514 // ensure it's null terminated
515 //
516 PropertyString->Buffer[PropertyString->Length/sizeof(WCHAR)] = UNICODE_NULL;
517}
static __inline NTSTATUS _GetDeviceProperty(_In_ MdDeviceObject DeviceObject, _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty, _In_ ULONG BufferLength, _Out_opt_ PVOID PropertyBuffer, _Out_ PULONG ResultLength)
#define TRACINGDEVICE
Definition: dbgtrace.h:58
#define PagedPool
Definition: env_spec_w32.h:308
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
PFX_DRIVER_GLOBALS pFxDriverGlobals
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
GLuint buffer
Definition: glext.h:5915
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define ASSERT(a)
Definition: mode.c:44
WCHAR * PWCH
Definition: ntbasedef.h:410
#define UNICODE_NULL
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3769
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by LogDriverInfoStream().

◆ GetDriverInfo()

VOID GetDriverInfo ( _In_ PFX_DRIVER_GLOBALS  Globals,
_In_opt_ FxDevice Fdo,
_Out_ FxTelemetryDriverInfo DriverInfo 
)

Definition at line 287 of file fxtelemetrykm.cpp.

292{
293 FxPkgPnp* pnpPkg;
294 USHORT devInfo = 0;
295
296 DriverInfo->bitmap.IsVerifierOn = Globals->FxVerifierOn;
298
299 if (Fdo == NULL) {
300 //
301 // this is for non-pnp or noDispatchOverride.
302 //
303 DriverInfo->bitmap.IsNonPnpDriver = FLAG_TO_BOOL(Globals->Public.DriverFlags, WdfDriverInitNonPnpDriver);
304 DriverInfo->bitmap.IsNoDispatchOverride = FLAG_TO_BOOL(Globals->Public.DriverFlags, WdfDriverInitNoDispatchOverride);
305 }
306 else {
307 pnpPkg = Fdo->m_PkgPnp;
308 devInfo = Fdo->GetDeviceTelemetryInfoFlags();
309
310 DriverInfo->bitmap.IsFilter = Fdo->GetFdoPkg()->IsFilter();
311 DriverInfo->bitmap.IsUsingRemoveLockOption = Fdo->IsRemoveLockEnabledForIo();
312 DriverInfo->bitmap.IsUsingNonDefaultHardwareReleaseOrder = pnpPkg->IsDefaultReleaseHardwareOrder();
313 DriverInfo->bitmap.IsPowerPolicyOwner = pnpPkg->IsPowerPolicyOwner();
314 DriverInfo->bitmap.IsS0IdleWakeFromS0Enabled = pnpPkg->IsS0IdleWakeFromS0Enabled();
315 DriverInfo->bitmap.IsS0IdleUsbSSEnabled = pnpPkg->IsS0IdleUsbSSEnabled();
316 DriverInfo->bitmap.IsS0IdleSystemManaged = pnpPkg->IsS0IdleSystemManaged();
317 DriverInfo->bitmap.IsSxWakeEnabled = pnpPkg->IsSxWakeEnabled();
318 DriverInfo->bitmap.IsUsingLevelTriggeredLineInterrupt = IsDeviceInfoFlagSet(devInfo, DeviceInfoLineBasedLevelTriggeredInterrupt);
319 DriverInfo->bitmap.IsUsingEdgeTriggeredLineInterrupt = IsDeviceInfoFlagSet(devInfo, DeviceInfoLineBasedEdgeTriggeredInterrupt);
320 DriverInfo->bitmap.IsUsingMsiXOrSingleMsi22Interrupt = IsDeviceInfoFlagSet(devInfo, DeviceInfoMsiXOrSingleMsi22Interrupt);
321 DriverInfo->bitmap.IsUsingMsi22MultiMessageInterrupt = IsDeviceInfoFlagSet(devInfo, DeviceInfoMsi22MultiMessageInterrupt);
322 DriverInfo->bitmap.IsUsingMultipleInterrupt = pnpPkg->HasMultipleInterrupts();
323 DriverInfo->bitmap.IsUsingPassiveLevelInterrupt = IsDeviceInfoFlagSet(devInfo, DeviceInfoPassiveLevelInterrupt);
324 DriverInfo->bitmap.IsUsingBusMasterDma = IsDeviceInfoFlagSet(devInfo, DeviceInfoDmaBusMaster);
325 DriverInfo->bitmap.IsUsingSystemDma = IsDeviceInfoFlagSet(devInfo, DeviceInfoDmaSystem);
326 DriverInfo->bitmap.IsUsingSystemDmaDuplex = IsDeviceInfoFlagSet(devInfo, DeviceInfoDmaSystemDuplex);
327 DriverInfo->bitmap.IsUsingStaticBusEnumration = IsDeviceInfoFlagSet(devInfo, DeviceInfoHasStaticChildren);
328 DriverInfo->bitmap.IsUsingDynamicBusEnumeration = IsDeviceInfoFlagSet(devInfo, DeviceInfoHasDynamicChildren);
329 }
330}
BOOLEAN IsSxWakeEnabled(VOID)
Definition: fxpkgpnp.hpp:3672
BOOLEAN HasMultipleInterrupts(VOID)
Definition: fxpkgpnp.hpp:4066
BOOLEAN IsS0IdleSystemManaged(VOID)
Definition: fxpkgpnp.hpp:3645
BOOLEAN IsPowerPolicyOwner(VOID)
Definition: fxpkgpnp.hpp:3612
BOOLEAN IsDefaultReleaseHardwareOrder(VOID)
Definition: fxpkgpnp.hpp:4054
BOOLEAN IsS0IdleUsbSSEnabled(VOID)
Definition: fxpkgpnp.hpp:3658
BOOLEAN IsS0IdleWakeFromS0Enabled(VOID)
Definition: fxpkgpnp.hpp:3632
#define FLAG_TO_BOOL(_Flags, _FlagMask)
Definition: fxobject.hpp:125
BOOLEAN __inline IsDeviceInfoFlagSet(_In_ USHORT DeviceInfo, _In_ FxDeviceInfoFlags Flag)
@ DeviceInfoHasStaticChildren
@ DeviceInfoLineBasedEdgeTriggeredInterrupt
@ DeviceInfoMsi22MultiMessageInterrupt
@ DeviceInfoMsiXOrSingleMsi22Interrupt
@ DeviceInfoDmaBusMaster
@ DeviceInfoDmaSystem
@ DeviceInfoLineBasedLevelTriggeredInterrupt
Definition: fxtelemetry.hpp:99
@ DeviceInfoDmaSystemDuplex
@ DeviceInfoHasDynamicChildren
@ DeviceInfoPassiveLevelInterrupt
_Must_inspect_result_ _In_ PFX_DRIVER_GLOBALS Globals
@ FxEnhancedVerifierFunctionTableHookMask
Definition: fxverifier.h:48
DRIVER_INFORMATION DriverInfo
Definition: main.c:59
BOOLEAN FxVerifierOn
Definition: fxglobals.h:420
ULONG FxEnhancedVerifierOptions
Definition: fxglobals.h:518
@ WdfDriverInitNonPnpDriver
Definition: wdfdriver.h:51
@ WdfDriverInitNoDispatchOverride
Definition: wdfdriver.h:52

Referenced by LogDriverInfoStream().

◆ GetFirstHardwareId()

VOID GetFirstHardwareId ( _Inout_ PUNICODE_STRING  HardwareIds)

Definition at line 229 of file fxtelemetrykm.cpp.

246{
247 PWCHAR curr;
248 USHORT lengthCch;
249
250 ASSERT(HardwareIds != NULL);
251
252 curr = (PWCHAR) HardwareIds->Buffer;
253 lengthCch = (HardwareIds->Length)/sizeof(WCHAR);
254
255 //
256 // if the caller supplied NULL buffer, then nothing to do.
257 //
258 if (curr == NULL) {
259 RtlInitUnicodeString(HardwareIds, NULL);
260 return;
261 }
262
263 //
264 // if the first element is NULL then update the length
265 //
266 if (*curr == UNICODE_NULL) {
267 HardwareIds->Length = 0;
268 HardwareIds->MaximumLength = HardwareIds->Length + sizeof(UNICODE_NULL);
269 return;
270 }
271
272 for (int i = 0; i < lengthCch; i++, curr++) {
273
274 if (*curr == UNICODE_NULL) {
275 //
276 // We found the first string. Update size. We only want to keep the
277 // first string.
278 //
279 HardwareIds->Length = (USHORT)(i * sizeof(WCHAR));
280 HardwareIds->MaximumLength = HardwareIds->Length + sizeof(UNICODE_NULL);
281 return;
282 }
283 }
284}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by LogDriverInfoStream().

◆ 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
DriverGlobals
FxAutoRegKey hKey
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
static const char * ImageName
Definition: image.c:34
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Definition: pdh_main.c:94
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161

◆ if() [1/4]

Definition at line 668 of file fxtelemetrykm.cpp.

668 {
669 goto cleanup;
670 }
static void cleanup(void)
Definition: main.c:1335

◆ if() [2/4]

if ( NT_SUCCESSstatus)

Definition at line 680 of file fxtelemetrykm.cpp.

680 {
681 goto cleanup;
682 }

◆ if() [3/4]

if ( info  = NULL)

Definition at line 688 of file fxtelemetrykm.cpp.

688 {
690 goto cleanup;
691 }

◆ if() [4/4]

if ( NT_SUCCESS(status )

Definition at line 706 of file fxtelemetrykm.cpp.

706 {
707 if (info->Type != REG_SZ && info->Type != REG_EXPAND_SZ) {
709 goto cleanup;
710 }
711
712 if (info->DataLength == 0 ||
713 (info->DataLength % 2) != 0 ||
714 (info->DataLength >
717 goto cleanup;
718 }
719
720 *Info = info;
721 }
#define REG_SZ
Definition: layer.c:22
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

◆ IsLoggingEnabledAndNeeded()

BOOLEAN IsLoggingEnabledAndNeeded ( _In_ PFX_DRIVER_GLOBALS  DriverGlobals)

Definition at line 109 of file fxtelemetrykm.cpp.

112{
113 LARGE_INTEGER lastLoggedTime;
114 LARGE_INTEGER currentTime;
115 LONGLONG delta;
116
117 // If provider is not enabled exit.
118 if (FALSE == FX_TELEMETRY_ENABLED(g_TelemetryProvider, DriverGlobals)) {
119 return FALSE;
120 }
121
122 ASSERT(DriverGlobals->TelemetryContext);
123
124 //
125 // If we already fired an event during PnP start we are done. This avoids
126 // repeatedly firing events during PnP rebalance.
127 //
129 &DriverGlobals->TelemetryContext->DoOnceFlagsBitmap,
130 DeviceStartEventBit) != 0) {
131 return FALSE;
132 }
133
134 //
135 // log only if it has been MIN_HOURS_BEFORE_NEXT_LOG time since last log.
136 // We don't log every time driver loads to avoid sending too much data
137 // too many times in case of a buggy driver going through load/unload cycle
138 // or when a device is plugged in two many times.
139 //
140 lastLoggedTime.QuadPart = 0;
142
143 if (lastLoggedTime.QuadPart == 0) {
144 //
145 // driver is loading for first time ater install so need to log
146 // event
147 //
148 return TRUE;
149 }
150
151 Mx::MxQuerySystemTime(&currentTime);
152
153 delta = (currentTime.QuadPart - lastLoggedTime.QuadPart);
154
156 "lastlogged %I64x, current %I64x, delta %I64x",
157 lastLoggedTime.QuadPart, currentTime.QuadPart, delta);
158
159 //
160 // KeQuerySystemTime returns time in 100-ns. We convert MIN_HOURS_BEFORE_NEXT_LOG
161 // to 100-nano sec unit and then compare.
162 //
163 if (delta < WDF_ABS_TIMEOUT_IN_SEC(MIN_HOURS_BEFORE_NEXT_LOG * 60 * 60)) {
164 return FALSE;
165 }
166
167 return TRUE;
168}
static __inline VOID MxQuerySystemTime(_Out_ PLARGE_INTEGER CurrentTime)
Definition: mxgeneralkm.h:679
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MIN_HOURS_BEFORE_NEXT_LOG
Definition: fxtelemetry.hpp:89
#define FX_TELEMETRY_ENABLED(TraceHandle, Globals)
Definition: fxtelemetry.hpp:45
@ DeviceStartEventBit
Definition: fxtelemetry.hpp:57
VOID RegistryReadLastLoggedTime(_In_ PFX_DRIVER_GLOBALS DriverGlobals, _Out_ PLARGE_INTEGER LastLoggedTime)
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
int64_t LONGLONG
Definition: typedefs.h:68
LONGLONG QuadPart
Definition: typedefs.h:114
FORCEINLINE LONGLONG WDF_ABS_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:71

Referenced by LogDeviceStartTelemetryEvent().

◆ LogDeviceStartTelemetryEvent()

VOID LogDeviceStartTelemetryEvent ( _In_ PFX_DRIVER_GLOBALS  DriverGlobals,
_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)

◆ LogDriverInfoStream()

VOID LogDriverInfoStream ( _In_ PFX_DRIVER_GLOBALS  DriverGlobals,
_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}

◆ RegistryReadLastLoggedTime()

VOID RegistryReadLastLoggedTime ( _In_ PFX_DRIVER_GLOBALS  DriverGlobals,
_Out_ PLARGE_INTEGER  LastLoggedTime 
)

Definition at line 333 of file fxtelemetrykm.cpp.

337{
338 FxAutoRegKey hKey, hWdf;
339 DECLARE_CONST_UNICODE_STRING(parametersPath, L"Parameters\\Wdf");
343
344 ASSERT(LastLoggedTime != NULL);
345 LastLoggedTime->QuadPart = 0;
346
347 status = FxRegKey::_OpenKey(NULL,
348 DriverGlobals->Driver->GetRegistryPathUnicodeString(),
349 &hWdf.m_Key,
350 KEY_READ);
351 if (!NT_SUCCESS(status)) {
353 "Unable to open driver's service key, status %!STATUS!", status);
354 return;
355 }
356
357 status = FxRegKey::_OpenKey(hWdf.m_Key,
358 &parametersPath,
359 &hKey.m_Key,
360 KEY_READ);
361 if (!NT_SUCCESS(status)) {
363 "Unable to open driver's service parameters key, status %!STATUS!",
364 status);
365 return;
366 }
367
368 value.QuadPart = 0;
369 status = FxRegKey::_QueryQuadWord(
370 hKey.m_Key, &valueName, &value);
371
372 //
373 // Set value only on success.
374 //
375 if (NT_SUCCESS(status)) {
376 LastLoggedTime->QuadPart = value.QuadPart;
377 }
378}
#define WDF_LAST_TELEMETRY_LOG_TIME_VALUE
Definition: fxtelemetry.hpp:92

Referenced by IsLoggingEnabledAndNeeded().

◆ RegistryWriteCurrentTime()

VOID RegistryWriteCurrentTime ( _In_ PFX_DRIVER_GLOBALS  DriverGlobals)

Definition at line 381 of file fxtelemetrykm.cpp.

384{
385 FxAutoRegKey hDriver, hParameters, hWdf;
386 DECLARE_CONST_UNICODE_STRING(parametersPart, L"Parameters");
387 DECLARE_CONST_UNICODE_STRING(wdfPart, L"Wdf");
388 LARGE_INTEGER currentTime;
389
390 //
391 // Not defined with the macro because ZwSetValue doesn't use
392 // PCUNICODE_STRING
393 //
394 UNICODE_STRING wdfTimeOfLastTelemetryLog;
396
397 RtlInitUnicodeString(&wdfTimeOfLastTelemetryLog, WDF_LAST_TELEMETRY_LOG_TIME_VALUE);
398
399 status = FxRegKey::_OpenKey(NULL,
400 DriverGlobals->Driver->GetRegistryPathUnicodeString(),
401 &hDriver.m_Key,
403 );
404 if (!NT_SUCCESS(status)) {
406 "Unable to open driver's service key, status %!STATUS!", status);
407 return;
408 }
409 //
410 // Key creation, unlike user mode, must happen one level at a time, since
411 // create will also open take both steps instead of trying open first
412 //
413 status = FxRegKey::_Create(hDriver.m_Key,
414 &parametersPart,
415 &hParameters.m_Key,
417 );
418 if (!NT_SUCCESS(status)) {
420 "Unable to write Parameters key, status %!STATUS!", status);
421 return;
422 }
423
424 status = FxRegKey::_Create(hParameters.m_Key,
425 &wdfPart,
426 &hWdf.m_Key,
428 );
429 if (!NT_SUCCESS(status)) {
431 "Unable to write Parameters key, status %!STATUS!", status);
432 return;
433 }
434
435 //
436 // Using ZwSetValueKey here to avoid having to change the implementation
437 // in FxRegKey of SetValue to a static / thiscall pair
438 //
439 currentTime.QuadPart = 0;
440 Mx::MxQuerySystemTime(&currentTime);
441
443 &wdfTimeOfLastTelemetryLog,
444 0,
445 REG_QWORD,
446 &currentTime.QuadPart,
447 sizeof(currentTime)
448 );
449
450 if (!NT_SUCCESS(status)) {
452 "Failed to record current time for Telemetry log, status %!STATUS!",
453 status);
454 }
455}
static __inline NTSTATUS MxSetValueKey(_In_ HANDLE KeyHandle, _In_ PUNICODE_STRING ValueName, _In_opt_ ULONG TitleIndex, _In_ ULONG Type, _In_opt_ PVOID Data, _In_ ULONG DataSize)
Definition: mxgeneralkm.h:688
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_QWORD
Definition: sdbapi.c:597
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3557

Referenced by LogDriverInfoStream().

◆ RtlZeroMemory()

RtlZeroMemory ( info  ,
length   
)

◆ TRACELOGGING_DEFINE_PROVIDER()

TRACELOGGING_DEFINE_PROVIDER ( g_TelemetryProvider  ,
KMDF_FX_TRACE_LOGGING_PROVIDER_NAME  ,
(0xec044b58, 0x3d13, 0x4880, 0x93, 0x6f, 0x7b, 0x67, 0xdf, 0xb3, 0xe0, 0x56)  ,
TraceLoggingOptionMicrosoftTelemetry()   
)

◆ UnregisterTelemetryProvider()

VOID UnregisterTelemetryProvider ( VOID  )

Definition at line 83 of file fxtelemetrykm.cpp.

86{
87 TraceLoggingUnregister(g_TelemetryProvider);
88}

Variable Documentation

◆ __pad0__

cleanup __pad0__

Definition at line 723 of file fxtelemetrykm.cpp.

◆ Globals

Definition at line 646 of file fxtelemetrykm.cpp.

Referenced by GetDriverInfo().

◆ Info

* Info
Initial value:

Definition at line 648 of file fxtelemetrykm.cpp.

◆ info

Definition at line 656 of file fxtelemetrykm.cpp.

Referenced by if().

◆ length

Definition at line 653 of file fxtelemetrykm.cpp.

◆ status

◆ ValueName