ReactOS 0.4.16-dev-1946-g52006dd
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 334 of file tracing.cpp.

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

◆ FxIFRGetSize()

ULONG FxIFRGetSize ( __in PFX_DRIVER_GLOBALS  FxDriverGlobals,
__in PCUNICODE_STRING  RegistryPath 
)

Definition at line 136 of file tracing.cpp.

153{
154 FxAutoRegKey service, parameters;
157 ULONG numPages;
158
159 //
160 // This is the value used in case of any error while retrieving 'LogPages'
161 // from the registry.
162 //
163 numPages = FxIFRMinLogPages;
164
165 //
166 // External representation of the IFR is the "LogPages", so use that term when
167 // overriding the size via the registry.
168 //
169 DECLARE_CONST_UNICODE_STRING(parametersPath, L"Parameters\\Wdf");
170 DECLARE_CONST_UNICODE_STRING(valueName, L"LogPages");
171
175 NULL,
176 NULL);
177
178 status = ZwOpenKey(&service.m_Key, KEY_READ, &oa);
179 if (!NT_SUCCESS(status)) {
180 goto defaultValues;
181 }
182
184 (PUNICODE_STRING)&parametersPath,
186 service.m_Key,
187 NULL);
188
189 status = ZwOpenKey(&parameters.m_Key, KEY_READ, &oa);
190
191 if (!NT_SUCCESS(status)) {
192 goto defaultValues;
193 }
194
195 status = FxRegKey::_QueryULong(parameters.m_Key, &valueName, &numPages);
196 if (!NT_SUCCESS(status)) {
197 goto defaultValues;
198 }
199
200 if (numPages == 0) {
201 numPages = FxIFRMinLogPages;
202 }
203
204defaultValues:
205 //
206 // Use FxIFRAvgLogPages if user specifies greater than FxIFRMaxLogPages and if
207 // Verifier flag is on and so is Verbose flag.
208 //
209 if (numPages > FxIFRMaxLogPages) {
210 if (FxDriverGlobals->FxVerifierOn && FxDriverGlobals->FxVerboseOn) {
211 numPages = FxIFRAvgLogPages;
212 }
213 else {
214 numPages = FxIFRMinLogPages;
215 }
216 }
217
218 return numPages * PAGE_SIZE;
219}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
#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:1026
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 222 of file tracing.cpp.

239{
241 ULONG size;
242
244
246
247 //
248 // Return early if IFR is disabled.
249 //
251 ASSERT(FxDriverGlobals->WdfLogHeader == NULL);
252 return;
253 }
254
255 if (FxDriverGlobals == NULL || FxDriverGlobals->WdfLogHeader != NULL) {
256 return;
257 }
258
259 size = FxIFRGetSize(FxDriverGlobals, RegistryPath);
260
262 size,
264 if (pHeader == NULL) {
265 return;
266 }
267
269
270 //
271 // Initialize the header.
272 // Base will be where the IFR records are placed.
273 // WPP_ThisDir_CTLGUID_FrameworksTraceGuid
274 //
275 RtlCopyMemory(&pHeader->Guid, (PVOID) &WdfTraceGuid, sizeof(GUID));
276
277 pHeader->Base = (PUCHAR) &pHeader[1];
278 pHeader->Size = size - sizeof(WDF_IFR_HEADER);
279
280 pHeader->Offset.u.s.Current = 0;
281 pHeader->Offset.u.s.Previous = 0;
282 RtlStringCchCopyA(pHeader->DriverName, WDF_IFR_HEADER_NAME_LEN, FxDriverGlobals->Public.DriverName);
283
284 FxDriverGlobals->WdfLogHeader = pHeader;
285
287 "FxIFR logging started" );
288
289 if (size > FxIFRMinLogSize) {
291 FxDriverGlobals, TRACE_LEVEL_INFORMATION, TRACINGDRIVER,
292 "FxIFR has been started with a size override: size 0x%x bytes, "
293 "# Pages %d. An extended IFR size may not be written to a minidump!",
295 }
296}
#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:136
#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 299 of file tracing.cpp.

312{
313 //
314 // Return early if IFR is disabled.
315 //
317 ASSERT(FxDriverGlobals->WdfLogHeader == NULL);
318 return;
319 }
320
321 if (FxDriverGlobals == NULL || FxDriverGlobals->WdfLogHeader == NULL) {
322 return;
323 }
324
325 //
326 // Free the Log buffer.
327 //
328 ExFreePoolWithTag( FxDriverGlobals->WdfLogHeader, WDF_IFR_LOG_TAG );
329 FxDriverGlobals->WdfLogHeader = NULL;
330}
#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#ifndef __REACTOS__
119 status = WmiTraceMessageVa(LoggerHandle,
120 MessageFlags,
121 MessageGuid,
123 va);
124#endif
125 va_end(va);
126
127 return status;
128}
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().