| 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 |
// user mode registration for tracing |
| 11 |
// |
| 12 |
|
| 13 |
#ifdef __cplusplus |
| 14 |
extern "C" { |
| 15 |
#endif |
| 16 |
|
| 17 |
#ifndef WPPINIT_EXPORT |
| 18 |
#define WPPINIT_EXPORT |
| 19 |
#endif |
| 20 |
|
| 21 |
#ifndef WppDebug |
| 22 |
#define WppDebug(a,b) |
| 23 |
#endif |
| 24 |
|
| 25 |
#define __WARNING_BANNED_LEGACY_INSTRUMENTATION_API_USAGE 28735 |
| 26 |
|
| 27 |
#if ENABLE_WPP_RECORDER |
| 28 |
#ifdef WPP_MACRO_USE_KM_VERSION_FOR_UM |
| 29 |
WPPINIT_EXPORT |
| 30 |
VOID |
| 31 |
__cdecl |
| 32 |
WppAutoLogStart( |
| 33 |
_In_ WPP_CB_TYPE * WppCb, |
| 34 |
_In_ PDRIVER_OBJECT DrvObj, |
| 35 |
_In_ PCUNICODE_STRING RegPath |
| 36 |
); |
| 37 |
#else |
| 38 |
WPPINIT_EXPORT |
| 39 |
VOID |
| 40 |
__cdecl |
| 41 |
WppAutoLogStart( |
| 42 |
_In_ WPP_CB_TYPE * WppCb, |
| 43 |
_In_ PVOID DrvObj, |
| 44 |
_In_ PCUNICODE_STRING RegPath |
| 45 |
); |
| 46 |
#endif // WPP_MACRO_USE_KM_VERSION_FOR_UM |
| 47 |
|
| 48 |
WPPINIT_EXPORT |
| 49 |
VOID |
| 50 |
__cdecl |
| 51 |
WppAutoLogStop( |
| 52 |
_In_ WPP_CB_TYPE * WppCb |
| 53 |
); |
| 54 |
|
| 55 |
#endif // ENABLE_WPP_RECORDER |
| 56 |
|
| 57 |
// define annotation record that will carry control information to pdb (in case somebody needs it) |
| 58 |
WPP_FORCEINLINE void WPP_CONTROL_ANNOTATION() { |
| 59 |
#if !defined(WPP_NO_ANNOTATIONS) |
| 60 |
|
| 61 |
#ifndef WPP_TMC_ANNOT_SUFIX |
| 62 |
#ifdef WPP_PUBLIC_TMC |
| 63 |
#define WPP_TMC_ANNOT_SUFIX ,L"PUBLIC_TMF:" |
| 64 |
#else |
| 65 |
#define WPP_TMC_ANNOT_SUFIX |
| 66 |
#endif |
| 67 |
#endif |
| 68 |
|
| 69 |
# define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) __annotation(L"TMC:", WPP_GUID_WTEXT Guid, _WPPW(WPP_STRINGIZE(Name)) Bits WPP_TMC_ANNOT_SUFIX); |
| 70 |
# define WPP_DEFINE_BIT(Name) , _WPPW(#Name) |
| 71 |
|
| 72 |
WPP_CONTROL_GUIDS |
| 73 |
# undef WPP_DEFINE_BIT |
| 74 |
# undef WPP_DEFINE_CONTROL_GUID |
| 75 |
#endif |
| 76 |
} |
| 77 |
|
| 78 |
LPCGUID WPP_REGISTRATION_GUIDS[WPP_LAST_CTL]; |
| 79 |
|
| 80 |
WPP_CB_TYPE WPP_MAIN_CB[WPP_LAST_CTL]; |
| 81 |
|
| 82 |
#define WPP_NEXT(Name) ((WPP_TRACE_CONTROL_BLOCK*) \ |
| 83 |
(WPP_XGLUE(WPP_CTL_, WPP_EVAL(Name)) + 1 == WPP_LAST_CTL ? 0:WPP_MAIN_CB + WPP_XGLUE(WPP_CTL_, WPP_EVAL(Name)) + 1)) |
| 84 |
|
| 85 |
#if ENABLE_WPP_RECORDER |
| 86 |
#define INIT_WPP_RECORDER(Arr) \ |
| 87 |
Arr->Control.AutoLogContext = NULL; \ |
| 88 |
Arr->Control.AutoLogVerboseEnabled = 0x0; \ |
| 89 |
Arr->Control.AutoLogAttachToMiniDump = 0x0; |
| 90 |
#else |
| 91 |
#define INIT_WPP_RECORDER(Arr) |
| 92 |
#endif |
| 93 |
|
| 94 |
__inline void WPP_INIT_CONTROL_ARRAY(WPP_CB_TYPE* Arr) { |
| 95 |
#define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \ |
| 96 |
Arr->Control.Ptr = NULL; \ |
| 97 |
Arr->Control.Next = WPP_NEXT(WPP_EVAL(Name)); \ |
| 98 |
Arr->Control.FlagsLen = WPP_FLAG_LEN; \ |
| 99 |
Arr->Control.Level = 0; \ |
| 100 |
Arr->Control.Options = 0; \ |
| 101 |
Arr->Control.Flags[0] = 0; \ |
| 102 |
INIT_WPP_RECORDER(Arr) \ |
| 103 |
++Arr; |
| 104 |
#define WPP_DEFINE_BIT(BitName) L" " L ## #BitName |
| 105 |
WPP_CONTROL_GUIDS |
| 106 |
#undef WPP_DEFINE_BIT |
| 107 |
#undef WPP_DEFINE_CONTROL_GUID |
| 108 |
} |
| 109 |
|
| 110 |
#undef WPP_INIT_STATIC_DATA |
| 111 |
#define WPP_INIT_STATIC_DATA WPP_INIT_CONTROL_ARRAY(WPP_MAIN_CB) |
| 112 |
|
| 113 |
__inline void WPP_INIT_GUID_ARRAY(LPCGUID* Arr) { |
| 114 |
#define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \ |
| 115 |
WPP_XGLUE4(*Arr = &WPP_, ThisDir, _CTLGUID_, WPP_EVAL(Name)); \ |
| 116 |
++Arr; |
| 117 |
WPP_CONTROL_GUIDS |
| 118 |
#undef WPP_DEFINE_CONTROL_GUID |
| 119 |
} |
| 120 |
|
| 121 |
VOID WppInitUm(_In_opt_ LPCWSTR AppName); |
| 122 |
// |
| 123 |
// WPP_INIT_TRACING and WPP_CLEANUP macros are defined differently for kernel |
| 124 |
// mode and user mode. In order to support mode-agnostic WDF drivers, |
| 125 |
// WPP_INIT_TRACING and WPP_CLEANUP macros for UMDF 2.x user-mode drivers are |
| 126 |
// being updated to be same as kernel mode macros. This difference is based |
| 127 |
// upon the macro WPP_MACRO_USE_KM_VERSION_FOR_UM. |
| 128 |
// |
| 129 |
|
| 130 |
#ifdef WPP_MACRO_USE_KM_VERSION_FOR_UM |
| 131 |
VOID WppInitUmDriver( |
| 132 |
_In_ PDRIVER_OBJECT DrvObject, |
| 133 |
_In_ PCUNICODE_STRING RegPath |
| 134 |
); |
| 135 |
|
| 136 |
VOID WppInitUm(_In_opt_ LPCWSTR AppName); |
| 137 |
|
| 138 |
#ifndef WPP_MACRO_USE_KM_VERSION_FOR_UM_IGNORE_VALIDATION |
| 139 |
|
| 140 |
// |
| 141 |
// To reduce confusion due to this breaking change, we have overloaded |
| 142 |
// WPP_INIT_TRACING with some macro wizardry to notify the developer |
| 143 |
// if (s)he is using the deprecated single argument version. |
| 144 |
// |
| 145 |
// Example of how this works: |
| 146 |
// |
| 147 |
// 1) WPP_INIT_TRACING is called with two parameters, X and Y. |
| 148 |
// 2) FX_WPP_COUNT_ARGUMENTS is called, but due to a bug with VC++ __VA_ARGS__ remains as a single token. |
| 149 |
// 3) FX_WPP_EXPAND_ARGUMENTS expands the argument list to (X, Y, 2, 1, 0) |
| 150 |
// 4) FX_WPP_DETERMINE_MACRO_NAME puts X into _1_, Y into _2_, 2 into Count (the value we want), |
| 151 |
// and the rest into "..." which are discarded. Count is then combined with WPP_INIT_TRACING. |
| 152 |
// 5) WPP_GLUE combines "WPP_INIT_TRACING2" with "(X, Y)" giving us our function call: WPP_INIT_TRACING2(X,Y) |
| 153 |
// |
| 154 |
#define FX_WPP_DETERMINE_MACRO_NAME(_1_, _2_, Count, ...) WPP_INIT_TRACING##Count |
| 155 |
#define FX_WPP_EXPAND_ARGUMENTS(Args) FX_WPP_DETERMINE_MACRO_NAME Args |
| 156 |
#define FX_WPP_COUNT_ARGUMENTS(...) FX_WPP_EXPAND_ARGUMENTS((__VA_ARGS__, 2, 1, 0)) |
| 157 |
|
| 158 |
#define WPP_INIT_TRACING(...) WPP_GLUE(FX_WPP_COUNT_ARGUMENTS(__VA_ARGS__),(__VA_ARGS__)) |
| 159 |
|
| 160 |
// |
| 161 |
// _pragma(message("...")) doesn't work with newline characters. "ERROR..." is an |
| 162 |
// undocumented keyword in visual studio that causes an error, but this is ignored by razzle. |
| 163 |
// Instead we use an undeclared identifier. |
| 164 |
// |
| 165 |
#define WPP_INIT_TRACING1(AppName) \ |
| 166 |
__pragma(message("ERROR: This version of WPP_INIT_TRACING has been deprecated from UMDF 2.15 onwards")) \ |
| 167 |
__pragma(message("WPP_INIT_TRACING( ")) \ |
| 168 |
__pragma(message(" _In_ PDRIVER_OBJECT DriverObject, ")) \ |
| 169 |
__pragma(message(" _In_ PUNICODE_STRING RegistryPath ")) \ |
| 170 |
__pragma(message("); ")) \ |
| 171 |
__pragma(message("WPP_CLEANUP( ")) \ |
| 172 |
__pragma(message(" _In_ PDRIVER_OBJECT DriverObject ")) \ |
| 173 |
__pragma(message(");" )) \ |
| 174 |
__pragma(message("Please refer to the MSDN documentation on WPP tracing for more information.")) \ |
| 175 |
WPP_INIT_TRACING_FUNCTION_IS_DEPRECATED_PLEASE_REFER_TO_BUILD_LOG_FOR_MORE_INFORMATION; |
| 176 |
|
| 177 |
#define WPP_INIT_TRACING2(DrvObj, RegPath) \ |
| 178 |
WppLoadTracingSupport; \ |
| 179 |
(WPP_CONTROL_ANNOTATION(),WPP_INIT_STATIC_DATA, \ |
| 180 |
WPP_INIT_GUID_ARRAY((LPCGUID*)&WPP_REGISTRATION_GUIDS), \ |
| 181 |
WPP_CB= WPP_MAIN_CB, \ |
| 182 |
WppInitUmDriver(DrvObj, RegPath)) |
| 183 |
|
| 184 |
#else |
| 185 |
#define WPP_INIT_TRACING(DrvObj, RegPath) \ |
| 186 |
WppLoadTracingSupport; \ |
| 187 |
(WPP_CONTROL_ANNOTATION(),WPP_INIT_STATIC_DATA, \ |
| 188 |
WPP_INIT_GUID_ARRAY((LPCGUID*)&WPP_REGISTRATION_GUIDS), \ |
| 189 |
WPP_CB= WPP_MAIN_CB, \ |
| 190 |
WppInitUmDriver(DrvObj, RegPath)) |
| 191 |
|
| 192 |
#endif // WPP_MACRO_USE_KM_VERSION_FOR_UM_IGNORE_VALIDATION |
| 193 |
#else |
| 194 |
#define WPP_INIT_TRACING(AppName) \ |
| 195 |
WppLoadTracingSupport; \ |
| 196 |
(WPP_CONTROL_ANNOTATION(),WPP_INIT_STATIC_DATA, \ |
| 197 |
WPP_INIT_GUID_ARRAY((LPCGUID*)&WPP_REGISTRATION_GUIDS), \ |
| 198 |
WPP_CB= WPP_MAIN_CB, \ |
| 199 |
WppInitUm(AppName)) |
| 200 |
|
| 201 |
#endif // WPP_MACRO_USE_KM_VERSION_FOR_UM |
| 202 |
void WPP_Set_Dll_CB( |
| 203 |
PWPP_TRACE_CONTROL_BLOCK Control, |
| 204 |
VOID * DllControlBlock, |
| 205 |
USHORT Flags) |
| 206 |
{ |
| 207 |
|
| 208 |
if (*(PVOID*)DllControlBlock != DllControlBlock){ |
| 209 |
Control->Ptr = DllControlBlock; |
| 210 |
} else { |
| 211 |
if (Flags == WPP_VER_WHISTLER_CB_FORWARD_PTR ){ |
| 212 |
memset(Control, 0, sizeof(WPP_TRACE_CONTROL_BLOCK)); |
| 213 |
*(PWPP_TRACE_CONTROL_BLOCK*)DllControlBlock = Control; |
| 214 |
Control->Options = WPP_VER_LH_CB_FORWARD_PTR; |
| 215 |
|
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
#define WPP_SET_FORWARD_PTR(CTL, FLAGS, PTR) (\ |
| 223 |
(WPP_MAIN_CB[WPP_CTRL_NO(WPP_BIT_ ## CTL )].Control.Options = (FLAGS)));\ |
| 224 |
WPP_Set_Dll_CB(&WPP_MAIN_CB[WPP_CTRL_NO(WPP_BIT_ ## CTL )].Control,(PTR),(USHORT)FLAGS) |
| 225 |
|
| 226 |
|
| 227 |
#define DEFAULT_LOGGER_NAME L"stdout" |
| 228 |
|
| 229 |
#if !defined(WPPINIT_STATIC) |
| 230 |
# define WPPINIT_STATIC |
| 231 |
#endif |
| 232 |
|
| 233 |
#define WPP_GUID_FORMAT "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x" |
| 234 |
#define WPP_GUID_ELEMENTS(p) \ |
| 235 |
p->Data1, p->Data2, p->Data3,\ |
| 236 |
p->Data4[0], p->Data4[1], p->Data4[2], p->Data4[3],\ |
| 237 |
p->Data4[4], p->Data4[5], p->Data4[6], p->Data4[7] |
| 238 |
|
| 239 |
#define WPP_MAX_LEVEL 255 |
| 240 |
#define WPP_MAX_FLAGS 0xFFFFFFFF |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
#if defined (WPP_GLOBALLOGGER) |
| 245 |
|
| 246 |
__inline |
| 247 |
TRACEHANDLE |
| 248 |
WppQueryLogger( |
| 249 |
_In_opt_ PCWSTR LoggerName |
| 250 |
) |
| 251 |
{ |
| 252 |
ULONG Status; |
| 253 |
EVENT_TRACE_PROPERTIES LoggerInfo; |
| 254 |
|
| 255 |
ZeroMemory(&LoggerInfo, sizeof(LoggerInfo)); |
| 256 |
LoggerInfo.Wnode.BufferSize = sizeof(LoggerInfo); |
| 257 |
LoggerInfo.Wnode.Flags = WNODE_FLAG_TRACED_GUID; |
| 258 |
|
| 259 |
Status = ControlTraceW(0, LoggerName ? LoggerName : L"stdout", &LoggerInfo, EVENT_TRACE_CONTROL_QUERY); |
| 260 |
if (Status == ERROR_SUCCESS || Status == ERROR_MORE_DATA) { |
| 261 |
return (TRACEHANDLE) LoggerInfo.Wnode.HistoricalContext; |
| 262 |
} |
| 263 |
return 0; |
| 264 |
} |
| 265 |
|
| 266 |
#define WPP_REG_GLOBALLOGGER_FLAGS L"Flags" |
| 267 |
#define WPP_REG_GLOBALLOGGER_LEVEL L"Level" |
| 268 |
#define WPP_REG_GLOBALLOGGER_START L"Start" |
| 269 |
|
| 270 |
#define WPP_TEXTGUID_LEN 38 |
| 271 |
#define WPP_REG_GLOBALLOGGER_KEY L"SYSTEM\\CurrentControlSet\\Control\\Wmi\\GlobalLogger" |
| 272 |
|
| 273 |
WPPINIT_STATIC |
| 274 |
void WppIntToHex( |
| 275 |
_Out_writes_(digits) PWCHAR Buf, |
| 276 |
unsigned int value, |
| 277 |
int digits |
| 278 |
) |
| 279 |
{ |
| 280 |
static LPCWSTR hexDigit = L"0123456789abcdef"; |
| 281 |
while (--digits >= 0) { |
| 282 |
Buf[digits] = hexDigit[ value & 15 ]; |
| 283 |
value /= 16; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
WPPINIT_EXPORT |
| 288 |
void WppInitGlobalLogger( |
| 289 |
IN LPCGUID ControlGuid, |
| 290 |
IN PTRACEHANDLE LoggerHandle, |
| 291 |
OUT PULONG Flags, |
| 292 |
_Out_writes_(sizeof(UCHAR)) PUCHAR Level ) |
| 293 |
{ |
| 294 |
WCHAR GuidBuf[WPP_TEXTGUID_LEN]; |
| 295 |
ULONG CurrentFlags = 0; |
| 296 |
ULONG CurrentLevel = 0; |
| 297 |
DWORD Start = 0; |
| 298 |
DWORD DataSize ; |
| 299 |
ULONG Status ; |
| 300 |
HKEY GloblaLoggerHandleKey; |
| 301 |
HKEY ValueHandleKey ; |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
WppDebug(0,("WPP checking Global Logger %S",WPP_REG_GLOBALLOGGER_KEY)); |
| 306 |
|
| 307 |
if ((Status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, |
| 308 |
(LPWSTR)WPP_REG_GLOBALLOGGER_KEY, |
| 309 |
0, |
| 310 |
KEY_READ, |
| 311 |
&GloblaLoggerHandleKey |
| 312 |
)) != ERROR_SUCCESS) { |
| 313 |
WppDebug(0,("GlobalLogger key does not exist (0x%08X)",Status)); |
| 314 |
return ; |
| 315 |
} |
| 316 |
|
| 317 |
DataSize = sizeof(DWORD); |
| 318 |
Status = RegQueryValueExW(GloblaLoggerHandleKey, |
| 319 |
(LPWSTR)WPP_REG_GLOBALLOGGER_START, |
| 320 |
0, |
| 321 |
NULL, |
| 322 |
(LPBYTE)&Start, |
| 323 |
&DataSize); |
| 324 |
if (Status != ERROR_SUCCESS || Start == 0 ) { |
| 325 |
WppDebug(0,("Global Logger not started (0x%08X)",Status)); |
| 326 |
goto Cleanup; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
WppDebug(0,("Global Logger exists and is set to be started")); |
| 331 |
|
| 332 |
{ |
| 333 |
static LPCWSTR hexDigit = L"0123456789abcdef"; |
| 334 |
int i; |
| 335 |
|
| 336 |
WppIntToHex(GuidBuf, ControlGuid->Data1, 8); |
| 337 |
GuidBuf[8] = '-'; |
| 338 |
|
| 339 |
WppIntToHex(&GuidBuf[9], ControlGuid->Data2, 4); |
| 340 |
GuidBuf[13] = '-'; |
| 341 |
|
| 342 |
WppIntToHex(&GuidBuf[14], ControlGuid->Data3, 4); |
| 343 |
GuidBuf[18] = '-'; |
| 344 |
|
| 345 |
GuidBuf[19] = hexDigit[(ControlGuid->Data4[0] & 0xF0) >> 4]; |
| 346 |
GuidBuf[20] = hexDigit[ControlGuid->Data4[0] & 0x0F ]; |
| 347 |
GuidBuf[21] = hexDigit[(ControlGuid->Data4[1] & 0xF0) >> 4]; |
| 348 |
GuidBuf[22] = hexDigit[ControlGuid->Data4[1] & 0x0F ]; |
| 349 |
GuidBuf[23] = '-'; |
| 350 |
|
| 351 |
for( i=2; i < 8 ; i++ ){ |
| 352 |
GuidBuf[i*2+20] = hexDigit[(ControlGuid->Data4[i] & 0xF0) >> 4]; |
| 353 |
GuidBuf[i*2+21] = hexDigit[ControlGuid->Data4[i] & 0x0F ]; |
| 354 |
} |
| 355 |
GuidBuf[36] = 0; |
| 356 |
|
| 357 |
} |
| 358 |
|
| 359 |
// |
| 360 |
// Perform the query |
| 361 |
// |
| 362 |
|
| 363 |
if ((Status = RegOpenKeyExW(GloblaLoggerHandleKey, |
| 364 |
(LPWSTR)GuidBuf, |
| 365 |
0, |
| 366 |
KEY_READ, |
| 367 |
&ValueHandleKey |
| 368 |
)) != ERROR_SUCCESS) { |
| 369 |
WppDebug(0,("Global Logger Key not set for this Control Guid %S (0x%08X)",GuidBuf,Status)); |
| 370 |
goto Cleanup; |
| 371 |
} |
| 372 |
// Get the Flags Parameter |
| 373 |
DataSize = sizeof(DWORD); |
| 374 |
Status = RegQueryValueExW(ValueHandleKey, |
| 375 |
(LPWSTR)WPP_REG_GLOBALLOGGER_FLAGS, |
| 376 |
0, |
| 377 |
NULL, |
| 378 |
(LPBYTE)&CurrentFlags, |
| 379 |
&DataSize); |
| 380 |
if (Status != ERROR_SUCCESS || CurrentFlags == 0 ) { |
| 381 |
WppDebug(0,("GlobalLogger for %S Flags not set (0x%08X)",GuidBuf,Status)); |
| 382 |
} |
| 383 |
// Get the levels Parameter |
| 384 |
DataSize = sizeof(DWORD); |
| 385 |
Status = RegQueryValueExW(ValueHandleKey, |
| 386 |
(LPWSTR)WPP_REG_GLOBALLOGGER_LEVEL, |
| 387 |
0, |
| 388 |
NULL, |
| 389 |
(LPBYTE)&CurrentLevel, |
| 390 |
&DataSize); |
| 391 |
if (Status != ERROR_SUCCESS || CurrentLevel == 0 ) { |
| 392 |
WppDebug(0,("GlobalLogger for %S Level not set (0x%08X)",GuidBuf,Status)); |
| 393 |
} |
| 394 |
|
| 395 |
if (Start==1) { |
| 396 |
|
| 397 |
if ((*LoggerHandle= WppQueryLogger( L"GlobalLogger")) != (TRACEHANDLE)NULL) { |
| 398 |
*Flags = CurrentFlags & 0x7FFFFFFF ; |
| 399 |
*Level = (UCHAR)(CurrentLevel & 0xFF) ; |
| 400 |
WppDebug(0,("WPP Enabled via Global Logger Flags=0x%08X Level=0x%02X",CurrentFlags,CurrentLevel)); |
| 401 |
} else { |
| 402 |
WppDebug(0,("GlobalLogger set for start but not running (Flags=0x%08X Level=0x%02X)",CurrentFlags,CurrentLevel)); |
| 403 |
} |
| 404 |
|
| 405 |
} |
| 406 |
|
| 407 |
RegCloseKey(ValueHandleKey); |
| 408 |
Cleanup: |
| 409 |
RegCloseKey(GloblaLoggerHandleKey); |
| 410 |
} |
| 411 |
#endif //#ifdef WPP_GLOBALLOGGER |
| 412 |
|
| 413 |
#ifdef WPP_MANAGED_CPP |
| 414 |
#pragma managed(push, off) |
| 415 |
#endif |
| 416 |
|
| 417 |
ULONG |
| 418 |
__stdcall |
| 419 |
WppControlCallback( |
| 420 |
IN WMIDPREQUESTCODE RequestCode, |
| 421 |
IN PVOID Context, |
| 422 |
_Inout_ ULONG *InOutBufferSize, |
| 423 |
_Inout_ PVOID Buffer |
| 424 |
) |
| 425 |
{ |
| 426 |
PWPP_TRACE_CONTROL_BLOCK Ctx = (PWPP_TRACE_CONTROL_BLOCK)Context; |
| 427 |
TRACEHANDLE Logger; |
| 428 |
UCHAR Level; |
| 429 |
DWORD Flags; |
| 430 |
|
| 431 |
*InOutBufferSize = 0; |
| 432 |
|
| 433 |
switch (RequestCode) |
| 434 |
{ |
| 435 |
case WMI_ENABLE_EVENTS: |
| 436 |
{ |
| 437 |
Logger = WPP_GET_TRACE_LOGGER_HANDLE( Buffer ); |
| 438 |
Level = WPP_GET_TRACE_ENABLE_LEVEL(Logger); |
| 439 |
Flags = WPP_GET_TRACE_ENABLE_FLAGS(Logger); |
| 440 |
|
| 441 |
WppDebug(1, ("[WppInit] WMI_ENABLE_EVENTS Ctx %p Flags %x" |
| 442 |
" Lev %d Logger %I64x\n", |
| 443 |
Ctx, Flags, Level, Logger) ); |
| 444 |
break; |
| 445 |
} |
| 446 |
|
| 447 |
case WMI_DISABLE_EVENTS: |
| 448 |
{ |
| 449 |
Logger = 0; |
| 450 |
Flags = 0; |
| 451 |
Level = 0; |
| 452 |
WppDebug(1, ("[WppInit] WMI_DISABLE_EVENTS Ctx 0x%08p\n", Ctx)); |
| 453 |
break; |
| 454 |
} |
| 455 |
|
| 456 |
#ifdef WPP_CAPTURE_STATE_CALLBACK |
| 457 |
|
| 458 |
case WMI_CAPTURE_STATE: |
| 459 |
{ |
| 460 |
Logger = WPP_GET_TRACE_LOGGER_HANDLE(Buffer); |
| 461 |
Level = WPP_GET_TRACE_ENABLE_LEVEL(Logger); |
| 462 |
Flags = WPP_GET_TRACE_ENABLE_FLAGS(Logger); |
| 463 |
WPP_CAPTURE_STATE_CALLBACK(Ctx->ControlGuid, |
| 464 |
Logger, |
| 465 |
Flags, |
| 466 |
Level); |
| 467 |
|
| 468 |
return ERROR_SUCCESS; |
| 469 |
} |
| 470 |
|
| 471 |
#endif |
| 472 |
|
| 473 |
default: |
| 474 |
{ |
| 475 |
return ERROR_INVALID_PARAMETER; |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
if (Ctx->Options & WPP_VER_WHISTLER_CB_FORWARD_PTR && Ctx->Cb) { |
| 480 |
Ctx = Ctx->Cb; // use forwarding address |
| 481 |
} |
| 482 |
|
| 483 |
Ctx->Logger = Logger; |
| 484 |
Ctx->Level = Level; |
| 485 |
Ctx->Flags[0] = Flags; |
| 486 |
|
| 487 |
#ifdef WPP_PRIVATE_ENABLE_CALLBACK |
| 488 |
WPP_PRIVATE_ENABLE_CALLBACK(Ctx->ControlGuid, |
| 489 |
Logger, |
| 490 |
(RequestCode != WMI_DISABLE_EVENTS) ? TRUE : FALSE, |
| 491 |
Flags, |
| 492 |
Level); |
| 493 |
#endif |
| 494 |
|
| 495 |
return(ERROR_SUCCESS); |
| 496 |
} |
| 497 |
|
| 498 |
#ifdef WPP_MANAGED_CPP |
| 499 |
#pragma managed(pop) |
| 500 |
#endif |
| 501 |
|
| 502 |
#pragma warning(push) |
| 503 |
#pragma warning(disable:4068) |
| 504 |
|
| 505 |
|
| 506 |
#ifdef WPP_MACRO_USE_KM_VERSION_FOR_UM |
| 507 |
WPPINIT_EXPORT |
| 508 |
VOID WppInitUmDriver( |
| 509 |
_In_ PDRIVER_OBJECT DrvObject, |
| 510 |
_In_ PCUNICODE_STRING RegPath |
| 511 |
) |
| 512 |
{ |
| 513 |
WppInitUm(L"UMDF Driver"); |
| 514 |
|
| 515 |
#if ENABLE_WPP_RECORDER |
| 516 |
WppAutoLogStart(&WPP_CB[0], DrvObject, RegPath); |
| 517 |
#else |
| 518 |
UNREFERENCED_PARAMETER(DrvObject); |
| 519 |
UNREFERENCED_PARAMETER(RegPath); |
| 520 |
#endif // ENABLE_WPP_RECORDER |
| 521 |
} |
| 522 |
|
| 523 |
#endif // WPP_MACRO_USE_KM_VERSION_FOR_UM |
| 524 |
|
| 525 |
WPPINIT_EXPORT |
| 526 |
VOID WppInitUm(_In_opt_ LPCWSTR AppName) |
| 527 |
{ |
| 528 |
C_ASSERT(WPP_MAX_FLAG_LEN_CHECK); |
| 529 |
|
| 530 |
PWPP_TRACE_CONTROL_BLOCK Control = &WPP_CB[0].Control; |
| 531 |
TRACE_GUID_REGISTRATION TraceRegistration; |
| 532 |
LPCGUID * RegistrationGuids = (LPCGUID *)&WPP_REGISTRATION_GUIDS; |
| 533 |
LPCGUID ControlGuid; |
| 534 |
|
| 535 |
ULONG Status; |
| 536 |
|
| 537 |
#ifdef WPP_MOF_RESOURCENAME |
| 538 |
#ifdef WPP_DLL |
| 539 |
HMODULE hModule = NULL; |
| 540 |
#endif |
| 541 |
WCHAR ImagePath[MAX_PATH] = {UNICODE_NULL} ; |
| 542 |
WCHAR WppMofResourceName[] = WPP_MOF_RESOURCENAME ; |
| 543 |
#else |
| 544 |
UNREFERENCED_PARAMETER(AppName); |
| 545 |
#endif //#ifdef WPP_MOF_RESOURCENAME |
| 546 |
|
| 547 |
WppDebug(1, ("Registering %ws\n", AppName) ); |
| 548 |
|
| 549 |
for(; Control; Control = Control->Next) { |
| 550 |
|
| 551 |
ControlGuid = *RegistrationGuids++; |
| 552 |
TraceRegistration.Guid = ControlGuid; |
| 553 |
TraceRegistration.RegHandle = 0; |
| 554 |
Control->ControlGuid = ControlGuid; |
| 555 |
|
| 556 |
WppDebug(1,(WPP_GUID_FORMAT " %ws : %d\n", |
| 557 |
WPP_GUID_ELEMENTS(ControlGuid), |
| 558 |
AppName, |
| 559 |
Control->FlagsLen)); |
| 560 |
|
| 561 |
|
| 562 |
#ifdef WPP_MOF_RESOURCENAME |
| 563 |
if (AppName != NULL) { |
| 564 |
|
| 565 |
#ifdef WPP_DLL |
| 566 |
if ((hModule = GetModuleHandleW(AppName)) != NULL) { |
| 567 |
Status = GetModuleFileNameW(hModule, ImagePath, MAX_PATH) ; |
| 568 |
ImagePath[MAX_PATH-1] = '\0'; |
| 569 |
if (Status == 0) { |
| 570 |
WppDebug(1,("RegisterTraceGuids => GetModuleFileName(DLL) Failed 0x%08X\n",GetLastError())); |
| 571 |
} |
| 572 |
} else { |
| 573 |
WppDebug(1,("RegisterTraceGuids => GetModuleHandleW failed for %ws (0x%08X)\n",AppName,GetLastError())); |
| 574 |
} |
| 575 |
#else // #ifdef WPP_DLL |
| 576 |
Status = GetModuleFileNameW(NULL,ImagePath,MAX_PATH); |
| 577 |
if (Status == 0) { |
| 578 |
WppDebug(1,("GetModuleFileName(EXE) Failed 0x%08X\n",GetLastError())); |
| 579 |
} |
| 580 |
#endif // #ifdef WPP_DLL |
| 581 |
} |
| 582 |
WppDebug(1,("registerTraceGuids => registering with WMI, App=%ws, Mof=%ws, ImagePath=%ws\n",AppName,WppMofResourceName,ImagePath)); |
| 583 |
|
| 584 |
#pragma prefast(suppress:__WARNING_BANNED_LEGACY_INSTRUMENTATION_API_USAGE, "WPP generated, requires legacy providers"); |
| 585 |
Status = RegisterTraceGuidsW( // Always use Unicode |
| 586 |
#else // ifndef WPP_MOF_RESOURCENAME |
| 587 |
|
| 588 |
#pragma prefast(suppress:__WARNING_BANNED_LEGACY_INSTRUMENTATION_API_USAGE, "WPP generated, requires legacy providers"); |
| 589 |
Status = WPP_REGISTER_TRACE_GUIDS( |
| 590 |
#endif // ifndef WPP_MOF_RESOURCENAME |
| 591 |
|
| 592 |
WppControlCallback, |
| 593 |
Control, // Context for the callback |
| 594 |
ControlGuid, |
| 595 |
1, |
| 596 |
&TraceRegistration, |
| 597 |
#ifndef WPP_MOF_RESOURCENAME |
| 598 |
0, //ImagePath, |
| 599 |
0, //ResourceName, |
| 600 |
#else // #ifndef WPP_MOF_RESOURCENAME |
| 601 |
ImagePath, |
| 602 |
WppMofResourceName, |
| 603 |
#endif // #ifndef WPP_MOF_RESOURCENAME |
| 604 |
&Control->UmRegistrationHandle |
| 605 |
); |
| 606 |
|
| 607 |
|
| 608 |
if (Status != ERROR_SUCCESS) { |
| 609 |
|
| 610 |
WppDebug(1, ("RegisterTraceGuid failed %d\n", Status) ); |
| 611 |
|
| 612 |
} |
| 613 |
|
| 614 |
#if defined (WPP_GLOBALLOGGER) |
| 615 |
|
| 616 |
// |
| 617 |
// Check if Global logger is active if we have not been immediately activated |
| 618 |
// |
| 619 |
if (Control->Logger == (TRACEHANDLE)NULL) { |
| 620 |
WppInitGlobalLogger( ControlGuid, (PTRACEHANDLE)&Control->Logger, &Control->Flags[0], &Control->Level); |
| 621 |
} |
| 622 |
|
| 623 |
#endif //#if defined (WPP_GLOBALLOGGER) |
| 624 |
|
| 625 |
} |
| 626 |
|
| 627 |
#if ENABLE_WPP_RECORDER |
| 628 |
#ifndef WPP_MACRO_USE_KM_VERSION_FOR_UM |
| 629 |
UNICODE_STRING AppNameStr; |
| 630 |
if (NULL != AppName) { |
| 631 |
RtlInitUnicodeString( &AppNameStr, AppName); |
| 632 |
} |
| 633 |
WppAutoLogStart(&WPP_CB[0], NULL, AppName ? &AppNameStr : NULL); |
| 634 |
#endif |
| 635 |
WPP_RECORDER_INITIALIZED = WPP_MAIN_CB; |
| 636 |
#endif |
| 637 |
} |
| 638 |
|
| 639 |
WPPINIT_EXPORT |
| 640 |
VOID WppCleanupUm( VOID ) |
| 641 |
{ |
| 642 |
PWPP_TRACE_CONTROL_BLOCK Control; |
| 643 |
|
| 644 |
if (WPP_CB == (WPP_CB_TYPE*)&WPP_CB){ |
| 645 |
// |
| 646 |
// WPP_INIT_TRACING macro has not been called |
| 647 |
// |
| 648 |
return; |
| 649 |
} |
| 650 |
WppDebug(1, ("Cleanup\n") ); |
| 651 |
Control = &WPP_CB[0].Control; |
| 652 |
for(; Control; Control = Control->Next) { |
| 653 |
WppDebug(1,("UnRegistering %I64x\n", Control->UmRegistrationHandle) ); |
| 654 |
if (Control->UmRegistrationHandle) { |
| 655 |
|
| 656 |
#pragma prefast(suppress:__WARNING_BANNED_LEGACY_INSTRUMENTATION_API_USAGE, "WPP generated, requires legacy providers"); |
| 657 |
WPP_UNREGISTER_TRACE_GUIDS(Control->UmRegistrationHandle); |
| 658 |
|
| 659 |
Control->UmRegistrationHandle = (TRACEHANDLE)NULL ; |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
#if ENABLE_WPP_RECORDER |
| 664 |
WppAutoLogStop(&WPP_CB[0]); |
| 665 |
|
| 666 |
WPP_RECORDER_INITIALIZED = (WPP_CB_TYPE*) &WPP_RECORDER_INITIALIZED; |
| 667 |
#endif |
| 668 |
|
| 669 |
WPP_CB = (WPP_CB_TYPE*)&WPP_CB; |
| 670 |
} |
| 671 |
|
| 672 |
#pragma warning(pop) |
| 673 |
|
| 674 |
|
| 675 |
#ifdef __cplusplus |
| 676 |
} // extern "C" |
| 677 |
#endif |