Debian Codegraph @

src/gallium/frontends/mediafoundation/wppconfig/rev1/km-init.tpl

raw
1 `**********************************************************************`
2 `* This is an include template file for the tracewpp preprocessor. *`
3 `* *`
4 `* Copyright (c) Microsoft Corporation. All rights reserved. *`
5 `**********************************************************************`
6 // template `TemplateFile`
7
8 //
9 // Defines a set of functions that simplifies
10 // kernel mode registration for tracing
11 //
12
13 #pragma warning(disable: 4201)
14 #include <ntddk.h>
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #ifndef WPPINIT_EXPORT
21 #define WPPINIT_EXPORT
22 #endif
23
24 #ifndef WppDebug
25 #define WppDebug(a,b)
26 #endif
27
28 WPPINIT_EXPORT
29 VOID
30 WppInitGlobalLogger(
31 _In_ LPCGUID ControlGuid,
32 _Out_ PTRACEHANDLE LoggerHandle,
33 _Out_ PULONG Flags,
34 _Out_ PUCHAR Level
35 );
36
37 WPPINIT_EXPORT
38 VOID
39 WppInitKm(
40 _When_(_ENABLE_WPP_RECORDER, _In_) _When_(!_ENABLE_WPP_RECORDER, _In_opt_) PDRIVER_OBJECT DriverObject,
41 _When_(_ENABLE_WPP_RECORDER, _In_) _When_(!_ENABLE_WPP_RECORDER, _In_opt_) PCUNICODE_STRING RegPath
42 );
43
44 #if ENABLE_WPP_RECORDER
45 WPPINIT_EXPORT
46 VOID
47 WppAutoLogStart(
48 _In_ WPP_CB_TYPE * WppCb,
49 _In_ PDRIVER_OBJECT DrvObj,
50 _In_ PCUNICODE_STRING RegPath
51 );
52
53 VOID
54 WppAutoLogStop(
55 _In_ WPP_CB_TYPE * WppCb,
56 _In_ PDRIVER_OBJECT DrvObj
57 );
58
59 VOID
60 imp_WppRecorderReplay(
61 _In_ PVOID WppCb,
62 _In_ TRACEHANDLE WppTraceHandle,
63 _In_ ULONG EnableFlags,
64 _In_ UCHAR EnableLevel
65 );
66
67 #ifndef ENABLE_WPP_RECORDER_REPLAY
68 #define ENABLE_WPP_RECORDER_REPLAY 1
69 #endif
70 #endif
71
72 #ifdef ALLOC_PRAGMA
73 #pragma alloc_text( PAGE, WppLoadTracingSupport)
74 #pragma alloc_text( PAGE, WppInitGlobalLogger)
75 #pragma alloc_text( PAGE, WppTraceCallback)
76 #pragma alloc_text( PAGE, WppInitKm)
77 #pragma alloc_text( PAGE, WppCleanupKm)
78 #endif // ALLOC_PRAGMA
79
80 // define annotation record that will carry control information to pdb (in case somebody needs it)
81 WPP_FORCEINLINE void WPP_CONTROL_ANNOTATION() {
82 #if !defined(WPP_NO_ANNOTATIONS)
83
84 #ifndef WPP_TMC_ANNOT_SUFIX
85 #ifdef WPP_PUBLIC_TMC
86 #define WPP_TMC_ANNOT_SUFIX ,L"PUBLIC_TMF:"
87 #else
88 #define WPP_TMC_ANNOT_SUFIX
89 #endif
90 #endif
91
92 # define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) __annotation(L"TMC:", WPP_GUID_WTEXT Guid, _WPPW(WPP_STRINGIZE(Name)) Bits WPP_TMC_ANNOT_SUFIX);
93 # define WPP_DEFINE_BIT(Name) , _WPPW(#Name)
94 WPP_CONTROL_GUIDS
95 # undef WPP_DEFINE_BIT
96 # undef WPP_DEFINE_CONTROL_GUID
97 #endif
98 }
99
100 #define WPP_NEXT(Name) ((WPP_TRACE_CONTROL_BLOCK*) \
101 (WPP_XGLUE(WPP_CTL_, WPP_EVAL(Name)) + 1 == WPP_LAST_CTL ? 0:WPP_MAIN_CB + WPP_XGLUE(WPP_CTL_, WPP_EVAL(Name)) + 1))
102
103 #if ENABLE_WPP_RECORDER
104 #define INIT_WPP_RECORDER(Arr) \
105 Arr->Control.AutoLogContext = NULL; \
106 Arr->Control.AutoLogVerboseEnabled = 0x0; \
107 Arr->Control.AutoLogAttachToMiniDump = 0x0;
108 #else
109 #define INIT_WPP_RECORDER(Arr)
110 #endif
111
112 WPP_CB_TYPE WPP_MAIN_CB[WPP_LAST_CTL];
113
114 __inline void WPP_INIT_CONTROL_ARRAY(WPP_CB_TYPE* Arr) {
115 #define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \
116 Arr->Control.Callback = NULL; \
117 Arr->Control.ControlGuid = WPP_XGLUE4(&WPP_, ThisDir, _CTLGUID_, WPP_EVAL(Name)); \
118 Arr->Control.Next = WPP_NEXT(WPP_EVAL(Name)); \
119 Arr->Control.RegistryPath= NULL; \
120 Arr->Control.FlagsLen = WPP_FLAG_LEN; \
121 Arr->Control.Level = 0; \
122 Arr->Control.Reserved = 0; \
123 Arr->Control.Flags[0] = 0; \
124 INIT_WPP_RECORDER(Arr) \
125 ++Arr;
126 #define WPP_DEFINE_BIT(BitName) L" " L ## #BitName
127 WPP_CONTROL_GUIDS
128 #undef WPP_DEFINE_BIT
129 #undef WPP_DEFINE_CONTROL_GUID
130 }
131
132 #undef WPP_INIT_STATIC_DATA
133 #define WPP_INIT_STATIC_DATA WPP_INIT_CONTROL_ARRAY(WPP_MAIN_CB)
134
135 // define WPP_INIT_TRACING. For performance reasons turn off during
136 // static analysis compilation with Static Driver Verifier (SDV).
137 #ifndef _SDV_
138 #define WPP_INIT_TRACING(DriverObject, RegPath) \
139 { \
140 WppDebug(0,("WPP_INIT_TRACING: &WPP_CB[0] %p\n", &WPP_MAIN_CB[0])); \
141 WPP_INIT_STATIC_DATA; \
142 WppLoadTracingSupport(); \
143 ( WPP_CONTROL_ANNOTATION(), \
144 WPP_MAIN_CB[0].Control.RegistryPath = NULL, \
145 WppInitKm( (PDRIVER_OBJECT)DriverObject, RegPath ) \
146 ); \
147 }
148 #else
149 #define WPP_INIT_TRACING(DriverObject, RegPath)
150 #endif
151
152 #define WMIREG_FLAG_CALLBACK 0x80000000 // not exposed in DDK
153
154 #ifndef WMIREG_FLAG_TRACE_PROVIDER
155 #define WMIREG_FLAG_TRACE_PROVIDER 0x00010000
156 #endif
157
158 //
159 // Public routines to break down the Loggerhandle
160 //
161
162 #if !defined(KERNEL_LOGGER_ID)
163 #define KERNEL_LOGGER_ID 0xFFFF // USHORT only
164 #endif
165
166 typedef struct _WPP_TRACE_ENABLE_CONTEXT {
167 USHORT LoggerId; // Actual Id of the logger
168 UCHAR Level; // Enable level passed by control caller
169 UCHAR InternalFlag; // Reserved
170 ULONG EnableFlags; // Enable flags passed by control caller
171 } WPP_TRACE_ENABLE_CONTEXT, *PWPP_TRACE_ENABLE_CONTEXT;
172
173 #if !defined(WmiGetLoggerId)
174 #define WmiGetLoggerId(LoggerContext) \
175 (((PWPP_TRACE_ENABLE_CONTEXT) (&LoggerContext))->LoggerId == \
176 (USHORT)KERNEL_LOGGER_ID) ? \
177 KERNEL_LOGGER_ID : \
178 ((PWPP_TRACE_ENABLE_CONTEXT) (&LoggerContext))->LoggerId
179
180 #define WmiGetLoggerEnableFlags(LoggerContext) \
181 ((PWPP_TRACE_ENABLE_CONTEXT) (&LoggerContext))->EnableFlags
182 #define WmiGetLoggerEnableLevel(LoggerContext) \
183 ((PWPP_TRACE_ENABLE_CONTEXT) (&LoggerContext))->Level
184 #endif
185
186 __inline int WppIsEqualGuid(_In_ const GUID* g1, _In_ const GUID* g2)
187 {
188 const ULONG* p1 = (const ULONG*)g1;
189 const ULONG* p2 = (const ULONG*)g2;
190 return p1[0] == p2[0] && p1[1] == p2[1] && p1[2] == p2[2] && p1[3] == p2[3];
191 }
192
193 VOID
194 WppLoadTracingSupport(
195 VOID
196 )
197 /*++
198
199 Routine Description:
200
201 This function assigns at runtime the ETW API set to be use for tracing.
202
203 Arguments:
204
205 Remarks:
206
207 At runtime determine assing the funtions pointers for the trace APIs to be use.
208 XP and above will use TraceMessage, and Win2K is not supported.
209
210 --*/
211 {
212 ULONG MajorVersion = 0;
213 UNICODE_STRING name;
214
215 PAGED_CODE();
216
217 RtlInitUnicodeString(&name, L"PsGetVersion");
218 pfnWppGetVersion = (PFN_WPPGETVERSION) (INT_PTR)
219 MmGetSystemRoutineAddress(&name);
220
221 RtlInitUnicodeString(&name, L"WmiTraceMessage");
222 pfnWppTraceMessage = (PFN_WPPTRACEMESSAGE) (INT_PTR)
223 MmGetSystemRoutineAddress(&name);
224
225
226 //
227 // WinXp
228 //
229
230 RtlInitUnicodeString(&name, L"WmiQueryTraceInformation");
231 pfnWppQueryTraceInformation = (PFN_WPPQUERYTRACEINFORMATION) (INT_PTR)
232 MmGetSystemRoutineAddress(&name);
233 WPPTraceSuite = WppTraceWinXP;
234
235 //
236 // Server08
237 //
238
239 if (pfnWppGetVersion != NULL) {
240 pfnWppGetVersion(&MajorVersion,
241 NULL,
242 NULL,
243 NULL);
244 }
245
246 if (MajorVersion >= 6) {
247
248 RtlInitUnicodeString(&name, L"EtwRegisterClassicProvider");
249 pfnEtwRegisterClassicProvider = (PFN_ETWREGISTERCLASSICPROVIDER) (INT_PTR)
250 MmGetSystemRoutineAddress(&name);
251
252 if (pfnEtwRegisterClassicProvider != NULL) {
253 //
254 // For Vista SP1 and later
255 //
256 RtlInitUnicodeString(&name, L"EtwUnregister");
257 pfnEtwUnregister = (PFN_ETWUNREGISTER) (INT_PTR)
258 MmGetSystemRoutineAddress(&name);
259
260 WPPTraceSuite = WppTraceServer08;
261 }
262 }
263 }
264
265 #ifdef WPP_GLOBALLOGGER
266 #define DEFAULT_GLOBAL_LOGGER_KEY L"WMI\\GlobalLogger\\"
267 #define WPP_TEXTGUID_LEN 38
268 #define GREGVALUENAMELENGTH (18 + WPP_TEXTGUID_LEN) // wslen(L"WMI\\GlobalLogger\\") + GUIDLENGTH
269
270 WPPINIT_EXPORT
271 VOID
272 WppInitGlobalLogger(
273 _In_ LPCGUID ControlGuid,
274 _Out_ PTRACEHANDLE LoggerHandle,
275 _Out_ PULONG Flags,
276 _Out_ PUCHAR Level
277 )
278 {
279 WCHAR GRegValueName[GREGVALUENAMELENGTH];
280 RTL_QUERY_REGISTRY_TABLE Parms[3];
281 ULONG CurrentFlags = 0;
282 ULONG CurrentLevel = 0;
283 ULONG Start = 0;
284 NTSTATUS Status;
285 ULONG Zero = 0;
286 UNICODE_STRING GuidString;
287
288 PAGED_CODE();
289
290 WppDebug(0,("WPP checking Global Logger\n"));
291
292 //
293 // Fill in the query table to find out if the Global Logger is Started
294 //
295 // Trace Flags
296 Parms[0].QueryRoutine = NULL;
297 Parms[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
298 Parms[0].Name = L"Start";
299 Parms[0].EntryContext = &Start;
300 Parms[0].DefaultType = REG_DWORD;
301 Parms[0].DefaultData = &Zero;
302 Parms[0].DefaultLength = sizeof(ULONG);
303 // Termination
304 Parms[1].QueryRoutine = NULL;
305 Parms[1].Flags = 0;
306 //
307 // Perform the query
308 //
309
310 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL | RTL_REGISTRY_OPTIONAL,
311 DEFAULT_GLOBAL_LOGGER_KEY,
312 Parms,
313 NULL,
314 NULL);
315 if (!NT_SUCCESS(Status) || Start == 0 ) {
316 return;
317 }
318
319 // Fill in the query table to find out if we should use the Global logger
320 //
321 // Trace Flags
322 Parms[0].QueryRoutine = NULL;
323 Parms[0].Flags = RTL_QUERY_REGISTRY_DIRECT;
324 Parms[0].Name = L"Flags";
325 Parms[0].EntryContext = &CurrentFlags;
326 Parms[0].DefaultType = REG_DWORD;
327 Parms[0].DefaultData = &Zero;
328 Parms[0].DefaultLength = sizeof(ULONG);
329 // Trace level
330 Parms[1].QueryRoutine = NULL;
331 Parms[1].Flags = RTL_QUERY_REGISTRY_DIRECT;
332 Parms[1].Name = L"Level";
333 Parms[1].EntryContext = &CurrentLevel;
334 Parms[1].DefaultType = REG_DWORD;
335 Parms[1].DefaultData = &Zero;
336 Parms[1].DefaultLength = sizeof(UCHAR);
337 // Termination
338 Parms[2].QueryRoutine = NULL;
339 Parms[2].Flags = 0;
340
341 RtlCopyMemory(GRegValueName, DEFAULT_GLOBAL_LOGGER_KEY, (wcslen(DEFAULT_GLOBAL_LOGGER_KEY)+1) *sizeof(WCHAR));
342
343 #if defined(__cplusplus)
344 Status = RtlStringFromGUID(*ControlGuid, &GuidString);
345 #else
346 Status = RtlStringFromGUID(ControlGuid, &GuidString);
347 #endif
348
349 if( Status != STATUS_SUCCESS ) {
350 WppDebug(0,("WPP GlobalLogger failed RtlStringFromGUID \n"));
351 return;
352 }
353
354 if (GuidString.Length > (WPP_TEXTGUID_LEN * sizeof(WCHAR))){
355 WppDebug(0,("WPP GlobalLogger RtlStringFromGUID too large\n"));
356 RtlFreeUnicodeString(&GuidString);
357 return;
358 }
359
360 // got the GUID in form "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"
361 // need GUID in form "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
362 // copy the translated GUID string
363
364 RtlCopyMemory(&GRegValueName[(ULONG)wcslen(GRegValueName)], &GuidString.Buffer[1], GuidString.Length);
365 GRegValueName[(ULONG)wcslen(GRegValueName) - 1] = L'\0';
366 RtlFreeUnicodeString(&GuidString);
367
368 //
369 // Perform the query
370 //
371
372 Status = RtlQueryRegistryValues(RTL_REGISTRY_CONTROL | RTL_REGISTRY_OPTIONAL,
373 GRegValueName,
374 Parms,
375 NULL,
376 NULL);
377 if (NT_SUCCESS(Status)) {
378 if (Start==1) {
379 *LoggerHandle= WMI_GLOBAL_LOGGER_ID;
380 *Flags = CurrentFlags & 0x7FFFFFFF;
381 *Level = (UCHAR)(CurrentLevel & 0xFF);
382 WppDebug(0,("WPP Enabled via Global Logger Flags=0x%08X Level=0x%02X\n",CurrentFlags,CurrentLevel));
383
384 }
385 } else {
386 WppDebug(0,("WPP GlobalLogger has No Flags/Levels Status=%08X\n",Status));
387 }
388 }
389 #endif //#ifdef WPP_GLOBALLOGGER
390
391 #define WPP_MAX_COUNT_REGISTRATION_GUID 63
392
393 WPPINIT_EXPORT
394 NTSTATUS
395 WppTraceCallback(
396 _In_ UCHAR MinorFunction,
397 _In_opt_ PVOID DataPath,
398 _In_ ULONG BufferLength,
399 _Inout_updates_bytes_(BufferLength) PVOID Buffer,
400 _Inout_ PVOID Context,
401 _Out_ PULONG Size
402 )
403 /*++
404
405 Routine Description:
406
407 This function is the callback WMI calls when we register and when our
408 events are enabled or disabled.
409
410 Arguments:
411
412 MinorFunction - specifies the type of callback (register, event enable/disable)
413
414 DataPath - varies depending on the ActionCode
415
416 BufferLength - size of the Buffer parameter
417
418 Buffer - in/out buffer where we read from or write to depending on the type
419 of callback
420
421 Context - the pointer private struct WPP_TRACE_CONTROL_BLOCK
422
423 Size - output parameter to receive the amount of data written into Buffer
424
425 Return Value:
426
427 NTSTATUS code indicating success/failure
428
429 Comments:
430
431 if return value is STATUS_BUFFER_TOO_SMALL and BufferLength >= 4,
432 then first ulong of buffer contains required size
433
434
435 --*/
436
437 {
438 PWPP_TRACE_CONTROL_BLOCK cntl;
439 NTSTATUS Status = STATUS_SUCCESS;
440
441 UNREFERENCED_PARAMETER(DataPath);
442
443 PAGED_CODE();
444
445 WppDebug(0,("WppTraceCallBack 0x%08X %p\n", MinorFunction, Context));
446
447 *Size = 0;
448
449 switch(MinorFunction)
450 {
451 case IRP_MN_REGINFO:
452 {
453 PWMIREGINFOW WmiRegInfo;
454 PCUNICODE_STRING RegPath;
455 PWCHAR StringPtr;
456 ULONG RegistryPathOffset;
457 ULONG BufferNeeded;
458 ULONG GuidCount = 0;
459
460 //
461 // Initialize locals
462 //
463
464 cntl = (PWPP_TRACE_CONTROL_BLOCK)Context;
465 WmiRegInfo = (PWMIREGINFO)Buffer;
466
467 RegPath = cntl->RegistryPath;
468
469 //
470 // Count the number of guid to be identified.
471 //
472 while(cntl) { GuidCount++; cntl = cntl->Next; }
473
474 if (GuidCount > WPP_MAX_COUNT_REGISTRATION_GUID){
475 Status = STATUS_INVALID_PARAMETER;
476 break;
477 }
478
479 WppDebug(0,("WppTraceCallBack: GUID count %d\n", GuidCount));
480
481 //
482 // Calculate buffer size need to hold all info.
483 // Calculate offset to where RegistryPath parm will be copied.
484 //
485
486 if (RegPath == NULL)
487 {
488
489 RegistryPathOffset = 0;
490
491 BufferNeeded = FIELD_OFFSET(WMIREGINFOW, WmiRegGuid) +
492 GuidCount * sizeof(WMIREGGUIDW);
493
494 } else {
495
496 RegistryPathOffset = FIELD_OFFSET(WMIREGINFOW, WmiRegGuid) +
497 GuidCount * sizeof(WMIREGGUIDW);
498
499 BufferNeeded = RegistryPathOffset +
500 RegPath->Length + sizeof(USHORT);
501 }
502
503 //
504 // If the provided buffer is large enough, then fill with info.
505 //
506
507 if (BufferNeeded <= BufferLength)
508 {
509 ULONG i;
510
511 RtlZeroMemory(Buffer, BufferLength);
512
513 //
514 // Fill in the WMIREGINFO
515 //
516
517 WmiRegInfo->BufferSize = BufferNeeded;
518 WmiRegInfo->RegistryPath = RegistryPathOffset;
519 WmiRegInfo->GuidCount = GuidCount;
520
521 if (RegPath != NULL) {
522 StringPtr = (PWCHAR)((PUCHAR)Buffer + RegistryPathOffset);
523 *StringPtr++ = RegPath->Length;
524
525 RtlCopyMemory(StringPtr, RegPath->Buffer, RegPath->Length);
526 }
527
528 //
529 // Fill in the WMIREGGUID
530 //
531
532 cntl = (PWPP_TRACE_CONTROL_BLOCK) Context;
533
534 for (i=0; i<GuidCount; i++) {
535
536 WmiRegInfo->WmiRegGuid[i].Guid = *cntl->ControlGuid;
537 WmiRegInfo->WmiRegGuid[i].Flags = WMIREG_FLAG_TRACE_CONTROL_GUID |
538 WMIREG_FLAG_TRACED_GUID;
539 cntl->Level = 0;
540 cntl->Flags[0] = 0;
541 WppDebug(0,("Control GUID::%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
542 cntl->ControlGuid->Data1,
543 cntl->ControlGuid->Data2,
544 cntl->ControlGuid->Data3,
545 cntl->ControlGuid->Data4[0],
546 cntl->ControlGuid->Data4[1],
547 cntl->ControlGuid->Data4[2],
548 cntl->ControlGuid->Data4[3],
549 cntl->ControlGuid->Data4[4],
550 cntl->ControlGuid->Data4[5],
551 cntl->ControlGuid->Data4[6],
552 cntl->ControlGuid->Data4[7]
553 ));
554
555 cntl = cntl->Next;
556 }
557
558 Status = STATUS_SUCCESS;
559 *Size = BufferNeeded;
560
561 } else {
562 Status = STATUS_BUFFER_TOO_SMALL;
563
564 if (BufferLength >= sizeof(ULONG)) {
565 *((PULONG)Buffer) = BufferNeeded;
566 *Size = sizeof(ULONG);
567 }
568 }
569
570 #ifdef WPP_GLOBALLOGGER
571 // Check if Global logger is active
572
573 cntl = (PWPP_TRACE_CONTROL_BLOCK) Context;
574 while(cntl) {
575 WppInitGlobalLogger(
576 cntl->ControlGuid,
577 (PTRACEHANDLE)&cntl->Logger,
578 &cntl->Flags[0],
579 &cntl->Level);
580 cntl = cntl->Next;
581 }
582 #endif //#ifdef WPP_GLOBALLOGGER
583
584 break;
585 }
586
587 case IRP_MN_ENABLE_EVENTS:
588 case IRP_MN_DISABLE_EVENTS:
589 {
590 PWNODE_HEADER Wnode;
591 ULONG Level;
592 ULONG ReturnLength;
593 ULONG index;
594
595 if (Context == NULL ) {
596 Status = STATUS_WMI_GUID_NOT_FOUND;
597 break;
598 }
599
600 if (BufferLength < sizeof(WNODE_HEADER)) {
601 Status = STATUS_INVALID_PARAMETER;
602 break;
603 }
604
605 //
606 // Initialize locals
607 //
608 Wnode = (PWNODE_HEADER)Buffer;
609
610 //
611 // Traverse this ProjectControlBlock's ControlBlock list and
612 // find the "cntl" ControlBlock which matches the Wnode GUID.
613 //
614 cntl = (PWPP_TRACE_CONTROL_BLOCK) Context;
615 index = 0;
616 while(cntl) {
617 if (WppIsEqualGuid(cntl->ControlGuid, &Wnode->Guid )) {
618 break;
619 }
620 index++;
621 cntl = cntl->Next;
622 }
623
624 if (cntl == NULL) {
625 Status = STATUS_WMI_GUID_NOT_FOUND;
626 break;
627 }
628
629 //
630 // Do the requested event action
631 //
632 Status = STATUS_SUCCESS;
633
634 if (MinorFunction == IRP_MN_DISABLE_EVENTS) {
635
636 WppDebug(0,("WppTraceCallBack: DISABLE_EVENTS\n"));
637
638 cntl->Level = 0;
639 cntl->Flags[0] = 0;
640 cntl->Logger = 0;
641
642 } else {
643
644 TRACEHANDLE lh;
645
646 lh = (TRACEHANDLE)( Wnode->HistoricalContext );
647 cntl->Logger = lh;
648
649 if (WppTraceWinXP == WPPTraceSuite) {
650
651 Status = pfnWppQueryTraceInformation( TraceEnableLevelClass,
652 &Level,
653 sizeof(Level),
654 &ReturnLength,
655 (PVOID)Wnode);
656
657 if (Status == STATUS_SUCCESS) {
658 cntl->Level = (UCHAR)Level;
659 }
660
661 Status = pfnWppQueryTraceInformation( TraceEnableFlagsClass,
662 &cntl->Flags[0],
663 sizeof(cntl->Flags[0]),
664 &ReturnLength,
665 (PVOID) Wnode );
666
667 } else {
668 cntl->Flags[0] = ((PWPP_TRACE_ENABLE_CONTEXT) &lh)->EnableFlags;
669 cntl->Level = (UCHAR) ((PWPP_TRACE_ENABLE_CONTEXT) &lh)->Level;
670 }
671
672 WppDebug(0,("WppTraceCallBack: ENABLE_EVENTS "
673 "LoggerId %d, Flags 0x%08X, Level 0x%02X\n",
674 (USHORT) cntl->Logger,
675 cntl->Flags[0],
676 cntl->Level));
677
678 }
679
680 #ifdef WPP_PRIVATE_ENABLE_CALLBACK
681 //
682 // Notify changes to flags, level for GUID
683 //
684 WPP_PRIVATE_ENABLE_CALLBACK( cntl->ControlGuid,
685 cntl->Logger,
686 (MinorFunction != IRP_MN_DISABLE_EVENTS) ? TRUE:FALSE,
687 cntl->Flags[0],
688 cntl->Level );
689 #endif
690
691 break;
692 }
693
694 case IRP_MN_ENABLE_COLLECTION:
695 case IRP_MN_DISABLE_COLLECTION:
696 {
697 Status = STATUS_SUCCESS;
698 break;
699 }
700
701 case IRP_MN_QUERY_ALL_DATA:
702 case IRP_MN_QUERY_SINGLE_INSTANCE:
703 case IRP_MN_CHANGE_SINGLE_INSTANCE:
704 case IRP_MN_CHANGE_SINGLE_ITEM:
705 case IRP_MN_EXECUTE_METHOD:
706 {
707 Status = STATUS_INVALID_DEVICE_REQUEST;
708 break;
709 }
710
711 default:
712 {
713 Status = STATUS_INVALID_DEVICE_REQUEST;
714 break;
715 }
716
717 }
718 return(Status);
719 }
720
721 VOID
722 NTAPI
723 WppClassicProviderCallback(
724 _In_ LPCGUID Guid,
725 _In_ UCHAR ControlCode,
726 _In_ PVOID EnableContext,
727 _Inout_ PVOID CallbackContext
728 )
729
730 /*++
731
732 Routine Description:
733
734 Enable callback function when EtwRegisterClassicProvider was used.
735 It happens in Windows Vista SP1 and newer.
736
737 Arguments:
738
739 Guid - provider guid.
740
741 ControlCode - code indicating operations request.
742
743 EnableContext - context from the ETW infrastructure.
744
745 CallbackContext - context from the user.
746
747 Return Value:
748
749 None.
750
751 --*/
752
753 {
754 PWPP_TRACE_CONTROL_BLOCK TraceCb = (PWPP_TRACE_CONTROL_BLOCK)CallbackContext;
755 PWPP_TRACE_ENABLE_CONTEXT TraceContext = (PWPP_TRACE_ENABLE_CONTEXT)EnableContext;
756
757 UNREFERENCED_PARAMETER (Guid);
758
759 WppDebug(0,("WppClassicProviderCallback %d\n", (int)ControlCode));
760
761 //
762 // Only handle enable and disable operations.
763 //
764
765 if ((ControlCode != EVENT_CONTROL_CODE_ENABLE_PROVIDER) &&
766 (ControlCode != EVENT_CONTROL_CODE_DISABLE_PROVIDER)) {
767
768 return;
769 }
770
771 if (ControlCode != EVENT_CONTROL_CODE_DISABLE_PROVIDER) {
772 TraceCb->Flags[0] = TraceContext->EnableFlags;
773 TraceCb->Level = (UCHAR)TraceContext->Level;
774 TraceCb->Logger = *((TRACEHANDLE*)TraceContext);
775
776 #if ENABLE_WPP_RECORDER
777 #if ENABLE_WPP_RECORDER_REPLAY && (NTDDI_VERSION >= NTDDI_WIN10_RS1)
778 imp_WppRecorderReplay(&WPP_CB[0], TraceCb->Logger, TraceContext->EnableFlags, TraceContext->Level);
779 #endif
780 #endif //#if ENABLE_WPP_RECORDER
781
782 WppDebug(0,("ENABLE: LoggerId=%d Flags=%08x Level=%02d\n", (int)TraceContext->LoggerId, TraceCb->Flags[0], TraceCb->Level));
783 } else {
784 TraceCb->Level = 0;
785 TraceCb->Flags[0] = 0;
786 TraceCb->Logger = 0;
787 }
788
789 #ifdef WPP_PRIVATE_ENABLE_CALLBACK
790 //
791 // Notify changes to flags, level for GUID
792 //
793 WppDebug(0,("WppClassicProviderCallback: calling private callback.\n"));
794
795 WPP_PRIVATE_ENABLE_CALLBACK(TraceCb->ControlGuid,
796 TraceCb->Logger,
797 ControlCode,
798 TraceCb->Flags[0],
799 TraceCb->Level);
800 #endif
801
802 }
803
804
805 #pragma warning(push)
806 #pragma warning(disable:4068)
807 WPPINIT_EXPORT
808 VOID
809 WppInitKm(
810 _When_(_ENABLE_WPP_RECORDER, _In_) _When_(!_ENABLE_WPP_RECORDER, _In_opt_) PDRIVER_OBJECT DriverObject,
811 _When_(_ENABLE_WPP_RECORDER, _In_) _When_(!_ENABLE_WPP_RECORDER, _In_opt_) PCUNICODE_STRING RegPath
812 )
813
814 /*++
815
816 Routine Description:
817
818 This function registers a driver with ETW as a provider of trace
819 events from the defined GUIDs.
820
821 Arguments:
822
823 DriverObject - Pointer to a driver object. This is required for WppRecorder
824 and is optional otherwise (not used unless it's for
825 WppRecorder).
826
827 RegPath - Optional pointer to registry path, needed for wpp recorder.
828
829 Remarks:
830
831 This function is called by the WPP_INIT_TRACING(DriverObject, RegPath) macro.
832
833 --*/
834
835 {
836 C_ASSERT(WPP_MAX_FLAG_LEN_CHECK);
837
838 NTSTATUS Status;
839 PWPP_TRACE_CONTROL_BLOCK WppReg = NULL;
840
841 PAGED_CODE();
842
843 UNREFERENCED_PARAMETER(DriverObject);
844 UNREFERENCED_PARAMETER(RegPath);
845
846 if (WPP_CB != WPP_MAIN_CB) {
847
848 WPP_CB = WPP_MAIN_CB;
849
850 } else {
851 //
852 // WPP_INIT_TRACING already called
853 //
854 WppDebug(0,("Warning : WPP_INIT_TRACING already called, ignoring this one"));
855 return;
856 }
857
858 WppReg = &WPP_CB[0].Control;
859
860 WppDebug(0,("WPP Init.\n"));
861
862 if (WppTraceServer08 == WPPTraceSuite) {
863
864 //
865 // Windows version >= Vista SP1
866 //
867 while (WppReg) {
868
869 WppReg->RegHandle = 0;
870 Status = pfnEtwRegisterClassicProvider(
871 WppReg->ControlGuid,
872 0,
873 WppClassicProviderCallback,
874 (PVOID)WppReg,
875 &WppReg->RegHandle);
876
877 if (!NT_SUCCESS(Status)) {
878 WppDebug(0,("EtwRegisterClassicProvider Status = %d, ControlBlock = %p.\n", Status, WppReg));
879 }
880
881 WppReg = WppReg->Next;
882 }
883
884 } else if (WppTraceWinXP == WPPTraceSuite) {
885
886
887 WppReg -> Callback = WppTraceCallback;
888
889 #pragma prefast(suppress:__WARNING_BANNED_API_ARGUMENT_USAGE, "WPP generated, requires legacy providers");
890 Status = IoWMIRegistrationControl(
891 (PDEVICE_OBJECT)WppReg,
892 WMIREG_ACTION_REGISTER |
893 WMIREG_FLAG_CALLBACK |
894 WMIREG_FLAG_TRACE_PROVIDER
895 );
896
897 if (!NT_SUCCESS(Status)) {
898 WppDebug(0,("IoWMIRegistrationControl Status = %08X\n",Status));
899 }
900
901 }
902
903 #if ENABLE_WPP_RECORDER
904 WppAutoLogStart(&WPP_CB[0], DriverObject, RegPath);
905
906 WPP_RECORDER_INITIALIZED = WPP_MAIN_CB;
907 #endif
908
909 }
910
911 WPPINIT_EXPORT
912 VOID
913 WppCleanupKm(
914 _When_(_ENABLE_WPP_RECORDER, _In_) _When_(!_ENABLE_WPP_RECORDER, _In_opt_) PDRIVER_OBJECT DriverObject
915 )
916
917 /*++
918
919 Routine Description:
920
921 This function deregisters a driver from ETW as provider of trace
922 events.
923
924 Arguments:
925
926 DriverObject - Pointer to a driver object. This is required for WppRecorder
927 and is optional otherwise (not used unless it's for
928 WppRecorder).
929
930 Remarks:
931
932 This function is called by the WPP_CLEANUP(DriverObject) macro.
933
934 --*/
935
936 {
937 UNREFERENCED_PARAMETER(DriverObject);
938
939 PAGED_CODE();
940
941 if (WPP_CB == (WPP_CB_TYPE*)&WPP_CB){
942 //
943 // WPP_INIT_TRACING macro has not been called
944 //
945 WppDebug(0,("Warning : WPP_CLEANUP already called, or called with out WPP_INIT_TRACING first"));
946 return;
947 }
948
949 if (WppTraceServer08 == WPPTraceSuite) {
950
951 PWPP_TRACE_CONTROL_BLOCK WppReg = &WPP_CB[0].Control;
952
953 while (WppReg) {
954 if (WppReg->RegHandle) {
955 pfnEtwUnregister(WppReg->RegHandle);
956 WppDebug(0,("EtwUnregister RegHandle = %lld.\n",WppReg->RegHandle));
957 WppReg->RegHandle = 0;
958 } else {
959 WppDebug(0,("WppCleanupKm: invalid RegHandle.\n"));
960 }
961 WppReg = WppReg->Next;
962 }
963
964 } else if (WppTraceWinXP == WPPTraceSuite) {
965 PWPP_TRACE_CONTROL_BLOCK WppReg = &WPP_CB[0].Control;
966
967 IoWMIRegistrationControl( (PDEVICE_OBJECT)WppReg,
968 WMIREG_ACTION_DEREGISTER |
969 WMIREG_FLAG_CALLBACK );
970
971 }
972
973 #if ENABLE_WPP_RECORDER
974 WppAutoLogStop(&WPP_CB[0], DriverObject);
975
976 WPP_RECORDER_INITIALIZED = (WPP_CB_TYPE*) &WPP_RECORDER_INITIALIZED;
977 #endif
978
979 WPP_CB = (WPP_CB_TYPE*)&WPP_CB;
980 }
981
982 #pragma warning(pop)
983
984 #define WPP_SYSTEMCONTROL(PDO)
985 #define WPP_SYSTEMCONTROL2(PDO, offset)
986
987 #ifdef __cplusplus
988 } // extern "C"
989 #endif