ReactOS  0.4.15-dev-3163-gf17c2c0
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 __pad2__
 

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 
55  sizeof(FX_TELEMETRY_CONTEXT),
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 
70 exit:
71  *TelemetryContext = context;
72 }
NTKERNELAPI NTSTATUS ExUuidCreate(OUT UUID *Uuid)
Definition: uuid.c:380
Definition: http.c:7251
LONG NTSTATUS
Definition: precomp.h:26
struct _FX_TELEMETRY_CONTEXT * PFX_TELEMETRY_CONTEXT
static __inline VOID MxFreePool(__in PVOID Ptr)
Definition: mxmemorykm.h:41
NTSTATUS status
static __inline PVOID MxAllocatePoolWithTag(__in POOL_TYPE PoolType, __in SIZE_T NumberOfBytes, __in ULONG Tag)
Definition: mxmemorykm.h:30
#define FX_TAG
Definition: fxmacros.hpp:155
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ PVOID _In_ ULONG _In_ PVOID context
Definition: wdfdriver.h:113
#define NULL
Definition: types.h:112
void exit(int exitcode)
Definition: _exit.c:33
Definition: ps.c:97

◆ ASSERT()

◆ 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 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3767
LONG NTSTATUS
Definition: precomp.h:26
RtlZeroMemory(info, length)
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
GLuint buffer
Definition: glext.h:5915
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
NTSTATUS status
#define UNICODE_NULL
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define TRACINGDEVICE
Definition: dbgtrace.h:58
PFX_DRIVER_GLOBALS pFxDriverGlobals
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
WCHAR * PWCH
Definition: ntbasedef.h:410
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
ASSERT(Info !=NULL)
unsigned short USHORT
Definition: pedump.c:61
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
static __inline NTSTATUS _GetDeviceProperty(_In_ MdDeviceObject DeviceObject, _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty, _In_ ULONG BufferLength, _Out_opt_ PVOID PropertyBuffer, _Out_ PULONG ResultLength)
unsigned int ULONG
Definition: retypes.h:1
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
Definition: ps.c:97

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 }
#define FLAG_TO_BOOL(_Flags, _FlagMask)
Definition: fxobject.hpp:125
BOOLEAN FxVerifierOn
Definition: fxglobals.h:420
BOOLEAN IsS0IdleSystemManaged(VOID)
Definition: fxpkgpnp.hpp:3645
ULONG FxEnhancedVerifierOptions
Definition: fxglobals.h:518
_Must_inspect_result_ _In_ PFX_DRIVER_GLOBALS Globals
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
BOOLEAN IsPowerPolicyOwner(VOID)
Definition: fxpkgpnp.hpp:3612
BOOLEAN HasMultipleInterrupts(VOID)
Definition: fxpkgpnp.hpp:4066
DRIVER_INFORMATION DriverInfo
Definition: main.c:59
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
BOOLEAN __inline IsDeviceInfoFlagSet(_In_ USHORT DeviceInfo, _In_ FxDeviceInfoFlags Flag)
BOOLEAN IsDefaultReleaseHardwareOrder(VOID)
Definition: fxpkgpnp.hpp:4054
BOOLEAN IsS0IdleWakeFromS0Enabled(VOID)
Definition: fxpkgpnp.hpp:3632
BOOLEAN IsS0IdleUsbSSEnabled(VOID)
Definition: fxpkgpnp.hpp:3658
BOOLEAN IsSxWakeEnabled(VOID)
Definition: fxpkgpnp.hpp:3672

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 }
uint16_t * PWCHAR
Definition: typedefs.h:56
#define UNICODE_NULL
__wchar_t WCHAR
Definition: xmlstorage.h:180
ASSERT(Info !=NULL)
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
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

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 
551  ASSERT(ImageName != NULL);
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 
578  BuildStringFromPartialInfo(value, &imagePath);
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 
631 cleanUp:
632 
633  if (value != NULL) {
634  FxPoolFree(value);
635  }
636 
637  return status;
638 }
Definition: pdh_main.c:93
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
GLint x0
Definition: linetemp.h:95
#define KEY_READ
Definition: nt_native.h:1023
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
RtlZeroMemory(info, length)
#define TRACINGDRIVER
Definition: dbgtrace.h:68
DriverGlobals
NTSTATUS status
#define UNICODE_NULL
GLsizeiptr size
Definition: glext.h:5919
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
WCHAR * PWCH
Definition: ntbasedef.h:410
static const char * ImageName
Definition: image.c:34
static const WCHAR L[]
Definition: oid.c:1250
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
ASSERT(Info !=NULL)
unsigned short USHORT
Definition: pedump.c:61
FxAutoRegKey hKey
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
VOID __inline BuildStringFromPartialInfo(_In_ PKEY_VALUE_PARTIAL_INFORMATION Info, _Out_ PUNICODE_STRING String)
void FxPoolFree(__in_xcount(ptr is at an offset from AllocationStart) PVOID ptr)
Definition: wdfpool.cpp:361
void cleanUp()
Definition: main.cpp:472
VOID GetNameFromPath(_In_ PCUNICODE_STRING Path, _Out_ PUNICODE_STRING Name)
Definition: fxtelemetry.cpp:54
Definition: ps.c:97

◆ if() [1/4]

Definition at line 668 of file fxtelemetrykm.cpp.

668  {
669  goto cleanup;
670  }
char * cleanup(char *str)
Definition: wpickclick.c:99

◆ if() [2/4]

if ( NT_SUCCESSstatus)

Definition at line 680 of file fxtelemetrykm.cpp.

680  {
681  goto cleanup;
682  }
char * cleanup(char *str)
Definition: wpickclick.c:99

◆ if() [3/4]

if ( info  = NULL)

Definition at line 688 of file fxtelemetrykm.cpp.

688  {
690  goto cleanup;
691  }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
char * cleanup(char *str)
Definition: wpickclick.c:99
Definition: ps.c:97

◆ 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 STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:683
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
char * cleanup(char *str)
Definition: wpickclick.c:99
#define REG_SZ
Definition: layer.c:22
Definition: ps.c:97

◆ 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;
141  RegistryReadLastLoggedTime(DriverGlobals, &lastLoggedTime);
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 }
#define MIN_HOURS_BEFORE_NEXT_LOG
Definition: fxtelemetry.hpp:89
#define TRUE
Definition: types.h:120
static __inline VOID MxQuerySystemTime(_Out_ PLARGE_INTEGER CurrentTime)
Definition: mxgeneralkm.h:679
#define TRACINGDRIVER
Definition: dbgtrace.h:68
DriverGlobals
VOID RegistryReadLastLoggedTime(_In_ PFX_DRIVER_GLOBALS DriverGlobals, _Out_ PLARGE_INTEGER LastLoggedTime)
FORCEINLINE LONGLONG WDF_ABS_TIMEOUT_IN_SEC(_In_ ULONGLONG Time)
Definition: wdfcore.h:71
#define FALSE
Definition: types.h:117
#define TRACE_LEVEL_VERBOSE
Definition: storswtr.h:30
#define FX_TELEMETRY_ENABLED(TraceHandle, Globals)
Definition: fxtelemetry.hpp:45
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
int64_t LONGLONG
Definition: typedefs.h:68
ASSERT(Info !=NULL)
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
LONGLONG QuadPart
Definition: typedefs.h:114

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)
DriverGlobals
#define FALSE
Definition: types.h:117
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461

◆ 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 
204  GetFirstHardwareId(&hardwareIDs.m_UnicodeString);
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 GetFirstHardwareId(_Inout_ PUNICODE_STRING HardwareIds)
VOID GetDriverInfo(_In_ PFX_DRIVER_GLOBALS Globals, _In_opt_ FxDevice *Fdo, _Out_ FxTelemetryDriverInfo *DriverInfo)
DriverGlobals
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461
VOID RegistryWriteCurrentTime(_In_ PFX_DRIVER_GLOBALS DriverGlobals)
#define KMDF_CENSUS_EVT_WRITE_DEVICE_START(TraceHandle, Globals, DriverConfig, SetupClass, BusEnum, HwID, Manafacturer)
#define NULL
Definition: types.h:112
VOID FxGetDevicePropertyString(_In_ FxDevice *Fdo, _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty, _Out_ PUNICODE_STRING PropertyString)
UNICODE_STRING m_UnicodeString

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 }
Definition: pdh_main.c:93
#define KEY_READ
Definition: nt_native.h:1023
LONG NTSTATUS
Definition: precomp.h:26
#define TRACINGDRIVER
Definition: dbgtrace.h:68
DriverGlobals
#define WDF_LAST_TELEMETRY_LOG_TIME_VALUE
Definition: fxtelemetry.hpp:92
NTSTATUS status
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
static const WCHAR L[]
Definition: oid.c:1250
GLsizei const GLfloat * value
Definition: glext.h:6069
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
ASSERT(Info !=NULL)
FxAutoRegKey hKey
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
Definition: ps.c:97

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 }
#define KEY_READ
Definition: nt_native.h:1023
static __inline VOID MxQuerySystemTime(_Out_ PLARGE_INTEGER CurrentTime)
Definition: mxgeneralkm.h:679
LONG NTSTATUS
Definition: precomp.h:26
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
#define TRACINGDRIVER
Definition: dbgtrace.h:68
DriverGlobals
#define WDF_LAST_TELEMETRY_LOG_TIME_VALUE
Definition: fxtelemetry.hpp:92
NTSTATUS status
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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
static const WCHAR L[]
Definition: oid.c:1250
#define TRACE_LEVEL_ERROR
Definition: storswtr.h:27
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define NULL
Definition: types.h:112
#define REG_QWORD
Definition: sdbapi.c:597
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
LONGLONG QuadPart
Definition: typedefs.h:114
Definition: ps.c:97

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

◆ __pad2__

cleanup __pad2__

Definition at line 727 of file fxtelemetrykm.cpp.

◆ Globals

Definition at line 646 of file fxtelemetrykm.cpp.

Referenced by GetDriverInfo().

◆ Info

◆ info

Definition at line 656 of file fxtelemetrykm.cpp.

Referenced by if().

◆ length

Definition at line 653 of file fxtelemetrykm.cpp.

◆ status

◆ ValueName