ReactOS 0.4.15-dev-7842-g558ab78
tracing.cpp File Reference
#include "fxcorepch.hpp"
#include <initguid.h>
#include "fxifr.h"
#include "fxifrkm.h"
Include dependency graph for tracing.cpp:

Go to the source code of this file.

Functions

_Must_inspect_result_ NTSTATUS FxTraceInitialize (VOID)
 
VOID TraceUninitialize (VOID)
 
_Must_inspect_result_ NTSTATUS FxWmiTraceMessage (__in TRACEHANDLE LoggerHandle, __in ULONG MessageFlags, __in LPGUID MessageGuid, __in USHORT MessageNumber, __in ...)
 
ULONG FxIFRGetSize (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING RegistryPath)
 
VOID FxIFRStart (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING RegistryPath, __in MdDriverObject DriverObject)
 
VOID FxIFRStop (__in PFX_DRIVER_GLOBALS FxDriverGlobals)
 
_Must_inspect_result_ NTSTATUS FxIFR (__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in UCHAR MessageLevel, __in ULONG MessageFlags, __in LPGUID MessageGuid, __in USHORT MessageNumber, __in ...)
 

Function Documentation

◆ FxIFR()

_Must_inspect_result_ NTSTATUS FxIFR ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in UCHAR  MessageLevel,
__in ULONG  MessageFlags,
__in LPGUID  MessageGuid,
__in USHORT  MessageNumber,
__in ...   
)

Definition at line 332 of file tracing.cpp.

364{
365 size_t size;
368
369 UNREFERENCED_PARAMETER( MessageLevel );
370 UNREFERENCED_PARAMETER( MessageFlags );
371
372 //
373 // Return early if IFR is disabled.
374 //
376 ASSERT(FxDriverGlobals->WdfLogHeader == NULL);
377 return STATUS_SUCCESS;
378 }
379
380 if ( FxDriverGlobals->WdfLogHeader == NULL) {
381 return STATUS_UNSUCCESSFUL;
382 }
383
384 //
385 // Determine the number bytes to follow header
386 //
387 size = 0; // For Count of Bytes
388
389 //
390 // Determine how much log space is needed for this
391 // trace record's data.
392 //
393 {
394 va_list ap;
395 size_t argLen;
396
398#pragma prefast(suppress: __WARNING_BUFFER_OVERFLOW, "Recommneded by EndClean");
399 while ((va_arg(ap, PVOID)) != NULL) {
400
401 argLen = va_arg(ap, size_t);
402
403 if (argLen > 0) {
404
405 if (argLen > FxIFRMaxMessageSize) {
406 goto drop_message;
407 }
408 size += (USHORT) argLen;
409 }
410 }
411
412 va_end(ap);
413
414 //
415 // NOTE: The final size must be 32-bit (ULONG) aligned.
416 // This is necessary for IA64 to prevent Alignment Faults.
417 //
418 size += (size % sizeof(ULONG)) ? sizeof(ULONG) - (size % sizeof(ULONG)) : 0;
419
421 goto drop_message;
422 }
423 }
424
425 size += sizeof(WDF_IFR_RECORD);
426
427 //
428 // Allocate log space of the calculated size
429 //
430 {
431 WDF_IFR_OFFSET offsetRet;
432 WDF_IFR_OFFSET offsetCur;
433 WDF_IFR_OFFSET offsetNew;
434 USHORT usSize = (USHORT) size; // for a prefast artifact.
435
436 header = (PWDF_IFR_HEADER) FxDriverGlobals->WdfLogHeader;
437
438 FxVerifyLogHeader(FxDriverGlobals, header);
439
440 offsetRet.u.AsLONG = header->Offset.u.AsLONG;
441 offsetNew.u.AsLONG = offsetRet.u.s.Current;
442
443 do {
444 offsetCur.u.AsLONG = offsetRet.u.AsLONG;
445
446 if (&header->Base[header->Size] < &header->Base[offsetCur.u.s.Current+size]) {
447
448 offsetNew.u.s.Current = 0;
449 offsetNew.u.s.Previous = offsetRet.u.s.Previous;
450
451 offsetRet.u.AsLONG =
452 InterlockedCompareExchange( &header->Offset.u.AsLONG,
453 offsetNew.u.AsLONG,
454 offsetCur.u.AsLONG );
455
456 if (offsetCur.u.AsLONG != offsetRet.u.AsLONG) {
457 continue;
458 } else {
459 offsetNew.u.s.Current = offsetCur.u.s.Current + usSize;
460 offsetNew.u.s.Previous = offsetRet.u.s.Current;
461 }
462 } else {
463
464 offsetNew.u.s.Current = offsetCur.u.s.Current + usSize;
465 offsetNew.u.s.Previous = offsetCur.u.s.Current;
466 }
467
468 offsetRet.u.AsLONG =
469 InterlockedCompareExchange( &header->Offset.u.AsLONG,
470 offsetNew.u.AsLONG,
471 offsetCur.u.AsLONG );
472
473 } while (offsetCur.u.AsLONG != offsetRet.u.AsLONG);
474
475 record = (PWDF_IFR_RECORD) &header->Base[offsetRet.u.s.Current];
476
477 // RtlZeroMemory( record, sizeof(WDF_IFR_RECORD) );
478
479 //
480 // Build record (fill all fields!)
481 //
482 record->Signature = FxIFRRecordSignature;
483 record->Length = (USHORT) size;
484 record->PrevOffset = (USHORT) offsetRet.u.s.Previous;
485 record->MessageNumber = MessageNumber;
486 record->Sequence = InterlockedIncrement( &header->Sequence );
487 record->MessageGuid = *MessageGuid;
488 }
489
490 //
491 // Move variable part of data into log.
492 //
493 {
494 va_list ap;
495 size_t argLen;
497 PUCHAR argsData;
498
499 argsData = (UCHAR*) &record[1];
500
502
503 while ((source = va_arg(ap, PVOID)) != NULL) {
504
505 argLen = va_arg(ap, size_t);
506
507 if (argLen > 0) {
508
509 RtlCopyMemory( argsData, source, argLen );
510 argsData += argLen;
511 }
512 }
513
514 va_end(ap);
515 }
516
517 FxVerifyLogHeader(FxDriverGlobals, header);
518
519 return STATUS_SUCCESS;
520
521 {
522 //
523 // Increment sequence number to indicate dropped message
524 //
525drop_message:
526 header = (PWDF_IFR_HEADER) FxDriverGlobals->WdfLogHeader;
527 InterlockedIncrement( &header->Sequence );
528 return STATUS_UNSUCCESSFUL;
529 }
530}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define va_arg(ap, T)
Definition: acmsvcex.h:89
#define InterlockedIncrement
Definition: armddk.h:53
#define NULL
Definition: types.h:112
struct _WDF_IFR_HEADER * PWDF_IFR_HEADER
struct _WDF_IFR_RECORD WDF_IFR_RECORD
struct _WDF_IFR_RECORD * PWDF_IFR_RECORD
@ FxIFRMaxMessageSize
Definition: fxifrkm.h:27
@ FxIFRRecordSignature
Definition: fxifrkm.h:29
__inline VOID FxVerifyLogHeader(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PWDF_IFR_HEADER Header)
Definition: fxifrkm.h:49
GLsizeiptr size
Definition: glext.h:5919
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define ASSERT(a)
Definition: mode.c:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
unsigned short USHORT
Definition: pedump.c:61
FxLibraryGlobalsType FxLibraryGlobals
Definition: globals.cpp:95
#define STATUS_SUCCESS
Definition: shellext.h:65
union _WDF_IFR_OFFSET::@4758 u
LONG AsLONG
Definition: fxifr.h:83
struct _WDF_IFR_OFFSET::@4758::@4759 s
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
_Must_inspect_result_ typedef _In_ ULONG _In_ ULONG MessageNumber
Definition: iotypes.h:4304
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ FxIFRGetSize()

ULONG FxIFRGetSize ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PCUNICODE_STRING  RegistryPath 
)

Definition at line 134 of file tracing.cpp.

151{
152 FxAutoRegKey service, parameters;
155 ULONG numPages;
156
157 //
158 // This is the value used in case of any error while retrieving 'LogPages'
159 // from the registry.
160 //
161 numPages = FxIFRMinLogPages;
162
163 //
164 // External representation of the IFR is the "LogPages", so use that term when
165 // overriding the size via the registry.
166 //
167 DECLARE_CONST_UNICODE_STRING(parametersPath, L"Parameters\\Wdf");
168 DECLARE_CONST_UNICODE_STRING(valueName, L"LogPages");
169
173 NULL,
174 NULL);
175
176 status = ZwOpenKey(&service.m_Key, KEY_READ, &oa);
177 if (!NT_SUCCESS(status)) {
178 goto defaultValues;
179 }
180
182 (PUNICODE_STRING)&parametersPath,
184 service.m_Key,
185 NULL);
186
187 status = ZwOpenKey(&parameters.m_Key, KEY_READ, &oa);
188
189 if (!NT_SUCCESS(status)) {
190 goto defaultValues;
191 }
192
193 status = FxRegKey::_QueryULong(parameters.m_Key, &valueName, &numPages);
194 if (!NT_SUCCESS(status)) {
195 goto defaultValues;
196 }
197
198 if (numPages == 0) {
199 numPages = FxIFRMinLogPages;
200 }
201
202defaultValues:
203 //
204 // Use FxIFRAvgLogPages if user specifies greater than FxIFRMaxLogPages and if
205 // Verifier flag is on and so is Verbose flag.
206 //
207 if (numPages > FxIFRMaxLogPages) {
208 if (FxDriverGlobals->FxVerifierOn && FxDriverGlobals->FxVerboseOn) {
209 numPages = FxIFRAvgLogPages;
210 }
211 else {
212 numPages = FxIFRMinLogPages;
213 }
214 }
215
216 return numPages * PAGE_SIZE;
217}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PAGE_SIZE
Definition: env_spec_w32.h:49
@ FxIFRMaxLogPages
Definition: fxifrkm.h:20
@ FxIFRMinLogPages
Definition: fxifrkm.h:19
@ FxIFRAvgLogPages
Definition: fxifrkm.h:21
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
Definition: ps.c:97
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215

Referenced by FxIFRStart().

◆ FxIFRStart()

VOID FxIFRStart ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PCUNICODE_STRING  RegistryPath,
__in MdDriverObject  DriverObject 
)

Definition at line 220 of file tracing.cpp.

237{
239 ULONG size;
240
242
244
245 //
246 // Return early if IFR is disabled.
247 //
249 ASSERT(FxDriverGlobals->WdfLogHeader == NULL);
250 return;
251 }
252
253 if (FxDriverGlobals == NULL || FxDriverGlobals->WdfLogHeader != NULL) {
254 return;
255 }
256
257 size = FxIFRGetSize(FxDriverGlobals, RegistryPath);
258
260 size,
262 if (pHeader == NULL) {
263 return;
264 }
265
267
268 //
269 // Initialize the header.
270 // Base will be where the IFR records are placed.
271 // WPP_ThisDir_CTLGUID_FrameworksTraceGuid
272 //
273 RtlCopyMemory(&pHeader->Guid, (PVOID) &WdfTraceGuid, sizeof(GUID));
274
275 pHeader->Base = (PUCHAR) &pHeader[1];
276 pHeader->Size = size - sizeof(WDF_IFR_HEADER);
277
278 pHeader->Offset.u.s.Current = 0;
279 pHeader->Offset.u.s.Previous = 0;
280 RtlStringCchCopyA(pHeader->DriverName, WDF_IFR_HEADER_NAME_LEN, FxDriverGlobals->Public.DriverName);
281
282 FxDriverGlobals->WdfLogHeader = pHeader;
283
285 "FxIFR logging started" );
286
287 if (size > FxIFRMinLogSize) {
289 FxDriverGlobals, TRACE_LEVEL_INFORMATION, TRACINGDRIVER,
290 "FxIFR has been started with a size override: size 0x%x bytes, "
291 "# Pages %d. An extended IFR size may not be written to a minidump!",
293 }
294}
#define TRACINGDRIVER
Definition: dbgtrace.h:68
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
DoTraceLevelMessage(pFxDriverGlobals, TRACE_LEVEL_VERBOSE, TRACINGPNP, "Enter, WDFDEVICE %p", Device)
#define WDF_IFR_LOG_TAG
Definition: fxifr.h:88
#define WDF_IFR_RECORD_SIGNATURE
Definition: fxifr.h:109
struct _WDF_IFR_HEADER WDF_IFR_HEADER
#define WDF_IFR_HEADER_NAME_LEN
Definition: fxifr.h:42
@ FxIFRMinLogSize
Definition: fxifrkm.h:23
FxContextHeader * pHeader
Definition: handleapi.cpp:604
NTSTRSAFEAPI RtlStringCchCopyA(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCSTR pszSrc)
Definition: ntstrsafe.h:110
#define TRACE_LEVEL_INFORMATION
Definition: storswtr.h:29
ULONG FxIFRGetSize(__in PFX_DRIVER_GLOBALS FxDriverGlobals, __in PCUNICODE_STRING RegistryPath)
Definition: tracing.cpp:134
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define WDFCASSERT(c)
Definition: wdfassert.h:93
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

◆ FxIFRStop()

VOID FxIFRStop ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals)

Definition at line 297 of file tracing.cpp.

310{
311 //
312 // Return early if IFR is disabled.
313 //
315 ASSERT(FxDriverGlobals->WdfLogHeader == NULL);
316 return;
317 }
318
319 if (FxDriverGlobals == NULL || FxDriverGlobals->WdfLogHeader == NULL) {
320 return;
321 }
322
323 //
324 // Free the Log buffer.
325 //
326 ExFreePoolWithTag( FxDriverGlobals->WdfLogHeader, WDF_IFR_LOG_TAG );
327 FxDriverGlobals->WdfLogHeader = NULL;
328}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109

Referenced by FxLibraryCommonUnregisterClient().

◆ FxTraceInitialize()

_Must_inspect_result_ NTSTATUS FxTraceInitialize ( VOID  )

Definition at line 47 of file tracing.cpp.

69{
70 //
71 // Initialize the tracing package: Vista or later
72 //
74
75 return STATUS_SUCCESS;
76}
#define WPP_INIT_TRACING(a, b)
Definition: kdebugprint.h:56

Referenced by FxLibraryCommonCommission().

◆ FxWmiTraceMessage()

_Must_inspect_result_ NTSTATUS FxWmiTraceMessage ( __in TRACEHANDLE  LoggerHandle,
__in ULONG  MessageFlags,
__in LPGUID  MessageGuid,
__in USHORT  MessageNumber,
__in ...   
)

Definition at line 104 of file tracing.cpp.

111{
113 va_list va;
114
116
117#pragma prefast(suppress:__WARNING_BUFFER_OVERFLOW, "Recommneded by EndClean");
118 status = WmiTraceMessageVa(LoggerHandle,
119 MessageFlags,
120 MessageGuid,
122 va);
123 va_end(va);
124
125 return status;
126}
NTSTATUS NTAPI WmiTraceMessageVa(IN TRACEHANDLE LoggerHandle, IN ULONG MessageFlags, IN LPGUID MessageGuid, IN USHORT MessageNumber, IN va_list MessageArgList)
Definition: wmi.c:368

◆ TraceUninitialize()

VOID TraceUninitialize ( VOID  )

Definition at line 79 of file tracing.cpp.

95{
96 //
97 // Vista and later
98 //
100}
#define WPP_CLEANUP(a)
Definition: kdebugprint.h:57

Referenced by FxLibraryCommonDecommission().