| 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 |
#ifdef WPP_THIS_FILE |
| 9 |
// included twice |
| 10 |
# define WPP_ALREADY_INCLUDED |
| 11 |
# undef WPP_THIS_FILE |
| 12 |
#endif // #ifdef WPP_THIS_FILE |
| 13 |
|
| 14 |
#define WPP_THIS_FILE `SourceFile.CanonicalName` |
| 15 |
|
| 16 |
#ifndef WPP_ALREADY_INCLUDED |
| 17 |
|
| 18 |
`* Dump the definitions specified via -D on the command line to WPP *` |
| 19 |
`FORALL def IN MacroDefinitions` |
| 20 |
#define `def.Name` `def.Alias` |
| 21 |
`ENDFOR` |
| 22 |
|
| 23 |
#include <evntrace.h> |
| 24 |
#include <stddef.h> |
| 25 |
#include <stdarg.h> |
| 26 |
#include <wmistr.h> |
| 27 |
|
| 28 |
#ifdef __cplusplus |
| 29 |
extern "C" { |
| 30 |
#endif |
| 31 |
|
| 32 |
typedef |
| 33 |
LONG |
| 34 |
(*PFN_WPPQUERYTRACEINFORMATION) ( |
| 35 |
IN TRACE_INFORMATION_CLASS TraceInformationClass, |
| 36 |
OUT PVOID TraceInformation, |
| 37 |
IN ULONG TraceInformationLength, |
| 38 |
OUT PULONG RequiredLength OPTIONAL, |
| 39 |
IN PVOID Buffer OPTIONAL |
| 40 |
); |
| 41 |
|
| 42 |
typedef |
| 43 |
LONG |
| 44 |
(*PFN_WPPTRACEMESSAGE)( |
| 45 |
IN ULONG64 LoggerHandle, |
| 46 |
IN ULONG MessageFlags, |
| 47 |
IN LPCGUID MessageGuid, |
| 48 |
IN USHORT MessageNumber, |
| 49 |
IN ... |
| 50 |
); |
| 51 |
|
| 52 |
typedef enum _WPP_TRACE_API_SUITE { |
| 53 |
WppTraceDisabledSuite, |
| 54 |
WppTraceWin2K, |
| 55 |
WppTraceWinXP, |
| 56 |
WppTraceTraceLH, |
| 57 |
WppTraceServer08, |
| 58 |
WppTraceMaxSuite |
| 59 |
} WPP_TRACE_API_SUITE; |
| 60 |
|
| 61 |
_IRQL_requires_same_ |
| 62 |
typedef |
| 63 |
VOID |
| 64 |
(NTAPI *PETW_CLASSIC_CALLBACK)( |
| 65 |
_In_ LPCGUID Guid, |
| 66 |
_In_ UCHAR ControlCode, |
| 67 |
_In_ PVOID EnableContext, |
| 68 |
_In_opt_ PVOID CallbackContext |
| 69 |
); |
| 70 |
|
| 71 |
_IRQL_requires_same_ |
| 72 |
typedef |
| 73 |
NTSTATUS |
| 74 |
NTKERNELAPI |
| 75 |
(FN_ETWREGISTERCLASSICPROVIDER)( |
| 76 |
_In_ LPCGUID ProviderGuid, |
| 77 |
_In_ ULONG Type, |
| 78 |
_In_ PETW_CLASSIC_CALLBACK EnableCallback, |
| 79 |
_In_opt_ PVOID CallbackContext, |
| 80 |
_Out_ PREGHANDLE RegHandle |
| 81 |
); |
| 82 |
|
| 83 |
typedef FN_ETWREGISTERCLASSICPROVIDER *PFN_ETWREGISTERCLASSICPROVIDER; |
| 84 |
|
| 85 |
typedef |
| 86 |
BOOLEAN |
| 87 |
NTKERNELAPI |
| 88 |
(FN_WPPGETVERSION)( |
| 89 |
_Out_opt_ PULONG MajorVersion, |
| 90 |
_Out_opt_ PULONG MinorVersion, |
| 91 |
_Out_opt_ PULONG BuildNumber, |
| 92 |
_Out_opt_ PUNICODE_STRING CSDVersion |
| 93 |
); |
| 94 |
|
| 95 |
typedef FN_WPPGETVERSION *PFN_WPPGETVERSION; |
| 96 |
|
| 97 |
typedef |
| 98 |
NTSTATUS |
| 99 |
NTKERNELAPI |
| 100 |
(FN_ETWUNREGISTER)( |
| 101 |
_In_ REGHANDLE RegHandle |
| 102 |
); |
| 103 |
|
| 104 |
typedef FN_ETWUNREGISTER *PFN_ETWUNREGISTER; |
| 105 |
|
| 106 |
#pragma prefast(suppress:__WARNING_ENCODE_GLOBAL_FUNCTION_POINTER, "this pointer can not be encoded"); |
| 107 |
__declspec(selectany) PFN_WPPQUERYTRACEINFORMATION pfnWppQueryTraceInformation = NULL; |
| 108 |
|
| 109 |
#pragma prefast(suppress:__WARNING_ENCODE_GLOBAL_FUNCTION_POINTER, "this pointer can not be encoded"); |
| 110 |
__declspec(selectany) PFN_WPPTRACEMESSAGE pfnWppTraceMessage = NULL; |
| 111 |
|
| 112 |
#pragma prefast(suppress:__WARNING_ENCODE_GLOBAL_FUNCTION_POINTER, "this pointer can not be encoded"); |
| 113 |
__declspec(selectany) PFN_ETWUNREGISTER pfnEtwUnregister = NULL; |
| 114 |
|
| 115 |
#pragma prefast(suppress:__WARNING_ENCODE_GLOBAL_FUNCTION_POINTER, "this pointer can not be encoded"); |
| 116 |
__declspec(selectany) PFN_ETWREGISTERCLASSICPROVIDER pfnEtwRegisterClassicProvider = NULL; |
| 117 |
|
| 118 |
#pragma prefast(suppress:__WARNING_ENCODE_GLOBAL_FUNCTION_POINTER, "this pointer can not be encoded"); |
| 119 |
__declspec(selectany) PFN_WPPGETVERSION pfnWppGetVersion = NULL; |
| 120 |
|
| 121 |
|
| 122 |
__declspec(selectany) WPP_TRACE_API_SUITE WPPTraceSuite = WppTraceDisabledSuite; |
| 123 |
|
| 124 |
#if !defined(_NTRTL_) |
| 125 |
#if !defined(_NTHAL_) |
| 126 |
// fake RTL_TIME_ZONE_INFORMATION // |
| 127 |
typedef int RTL_TIME_ZONE_INFORMATION; |
| 128 |
#endif |
| 129 |
#define _WMIKM_ |
| 130 |
#endif |
| 131 |
|
| 132 |
#ifndef WPP_TRACE |
| 133 |
#define WPP_TRACE pfnWppTraceMessage |
| 134 |
#endif |
| 135 |
|
| 136 |
#if ENABLE_WPP_RECORDER |
| 137 |
|
| 138 |
#define _ENABLE_WPP_RECORDER TRUE |
| 139 |
|
| 140 |
#ifndef WPP_RECORDER |
| 141 |
#define WPP_RECORDER WppAutoLogTrace |
| 142 |
#endif |
| 143 |
|
| 144 |
// |
| 145 |
// This setting is only applicable when IFR is enabled. |
| 146 |
// Setting this to 1 will allow a WPP trace session to |
| 147 |
// capture trace messages as usual i.e it will require the |
| 148 |
// user to provide WPP trace ENABLED and LOGGER macro. If |
| 149 |
// this is set to 0 by default the IFR trace filter also |
| 150 |
// affects which trace messages land in the WPP trace session. |
| 151 |
// |
| 152 |
#if !defined(ENABLE_WPP_TRACE_FILTERING_WITH_WPP_RECORDER) |
| 153 |
#define ENABLE_WPP_TRACE_FILTERING_WITH_WPP_RECORDER 0 |
| 154 |
#endif |
| 155 |
|
| 156 |
#if !defined(WPP_RECORDER_LEVEL_FLAGS_ARGS) |
| 157 |
#define WPP_RECORDER_LEVEL_FLAGS_ARGS(lvl, flags) WPP_CONTROL(WPP_BIT_ ## flags).AutoLogContext, lvl, WPP_BIT_ ## flags |
| 158 |
#define WPP_RECORDER_LEVEL_FLAGS_FILTER(lvl,flags) (lvl < TRACE_LEVEL_VERBOSE || WPP_CONTROL(WPP_BIT_ ## flags).AutoLogVerboseEnabled) |
| 159 |
#endif |
| 160 |
|
| 161 |
|
| 162 |
#if !defined(WPP_RECORDER_LEVEL_ARGS) |
| 163 |
#define WPP_RECORDER_LEVEL_ARGS(lvl) WPP_CONTROL(WPP_BIT_ ## lvl).AutoLogContext, 0, WPP_BIT_ ## lvl |
| 164 |
#define WPP_RECORDER_LEVEL_FILTER(lvl) (WPP_CONTROL(WPP_BIT_ ## lvl).AutoLogVerboseEnabled) |
| 165 |
#endif |
| 166 |
|
| 167 |
NTSTATUS |
| 168 |
WppAutoLogTrace( |
| 169 |
IN PVOID AutoLogContext, |
| 170 |
IN UCHAR MessageLevel, |
| 171 |
IN ULONG MessageFlags, |
| 172 |
IN LPGUID MessageGuid, |
| 173 |
IN USHORT MessageNumber, |
| 174 |
IN ... |
| 175 |
); |
| 176 |
|
| 177 |
#else |
| 178 |
#define _ENABLE_WPP_RECORDER FALSE |
| 179 |
#endif |
| 180 |
|
| 181 |
VOID |
| 182 |
WppLoadTracingSupport( |
| 183 |
VOID |
| 184 |
); |
| 185 |
|
| 186 |
NTSTATUS |
| 187 |
WppTraceCallback( |
| 188 |
_In_ UCHAR MinorFunction, |
| 189 |
_In_opt_ PVOID DataPath, |
| 190 |
_In_ ULONG BufferLength, |
| 191 |
_Inout_updates_bytes_(BufferLength) PVOID Buffer, |
| 192 |
_Inout_ PVOID Context, |
| 193 |
_Out_ PULONG Size |
| 194 |
); |
| 195 |
|
| 196 |
#if !defined(WPP_TRACE_CONTROL_NULL_GUID) |
| 197 |
DEFINE_GUID(WPP_TRACE_CONTROL_NULL_GUID, 0x00000000L, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); |
| 198 |
#endif |
| 199 |
|
| 200 |
#define WPP_TRACE_CONTROL(Function,Buffer,BufferSize,ReturnSize) WppTraceCallback(Function,NULL,BufferSize,Buffer,&WPP_CB[0],&ReturnSize); |
| 201 |
|
| 202 |
__inline ULONG64 WppQueryLogger(_In_opt_ PCWSTR LoggerName) |
| 203 |
{ |
| 204 |
if (WppTraceWinXP != WPPTraceSuite) { |
| 205 |
return (ULONG64)0; |
| 206 |
} |
| 207 |
|
| 208 |
ULONG ReturnLength; |
| 209 |
LONG Status; |
| 210 |
ULONG64 TraceHandle; |
| 211 |
UNICODE_STRING Buffer; |
| 212 |
|
| 213 |
RtlInitUnicodeString(&Buffer, LoggerName ? LoggerName : L"stdout"); |
| 214 |
|
| 215 |
Status = pfnWppQueryTraceInformation(TraceHandleByNameClass, |
| 216 |
(PVOID)&TraceHandle, |
| 217 |
sizeof(TraceHandle), |
| 218 |
&ReturnLength, |
| 219 |
(PVOID)&Buffer |
| 220 |
); |
| 221 |
if (Status != STATUS_SUCCESS) { |
| 222 |
return (ULONG64)0; |
| 223 |
} |
| 224 |
|
| 225 |
return TraceHandle; |
| 226 |
} |
| 227 |
|
| 228 |
typedef LONG (*WMIENTRY_NEW)( |
| 229 |
_In_ UCHAR MinorFunction, |
| 230 |
_In_opt_ PVOID DataPath, |
| 231 |
_In_ ULONG BufferLength, |
| 232 |
_Inout_updates_bytes_(BufferLength) PVOID Buffer, |
| 233 |
_In_ PVOID Context, |
| 234 |
_Out_ PULONG Size |
| 235 |
); |
| 236 |
|
| 237 |
typedef struct _WPP_TRACE_CONTROL_BLOCK |
| 238 |
{ |
| 239 |
WMIENTRY_NEW Callback; |
| 240 |
LPCGUID ControlGuid; |
| 241 |
struct _WPP_TRACE_CONTROL_BLOCK *Next; |
| 242 |
__int64 Logger; |
| 243 |
PUNICODE_STRING RegistryPath; |
| 244 |
UCHAR FlagsLen; |
| 245 |
UCHAR Level; |
| 246 |
USHORT Reserved; |
| 247 |
ULONG Flags[1]; |
| 248 |
ULONG ReservedFlags; |
| 249 |
REGHANDLE RegHandle; |
| 250 |
#if ENABLE_WPP_RECORDER |
| 251 |
PVOID AutoLogContext; |
| 252 |
USHORT AutoLogVerboseEnabled; |
| 253 |
USHORT AutoLogAttachToMiniDump; |
| 254 |
#endif |
| 255 |
} WPP_TRACE_CONTROL_BLOCK, *PWPP_TRACE_CONTROL_BLOCK; |
| 256 |
|
| 257 |
VOID WppCleanupKm(_When_(_ENABLE_WPP_RECORDER, _In_) _When_(!_ENABLE_WPP_RECORDER, _In_opt_) PDRIVER_OBJECT DriverObject); |
| 258 |
|
| 259 |
#define WPP_CLEANUP(DriverObject) WppCleanupKm((PDRIVER_OBJECT)DriverObject) |
| 260 |
|
| 261 |
#define WPP_IsValidSid RtlValidSid |
| 262 |
#define WPP_GetLengthSid RtlLengthSid |
| 263 |
|
| 264 |
// |
| 265 |
// Callback routine to be defined by the driver, which will be called from WPP callback |
| 266 |
// WPP will pass current valued of : GUID, Logger, Enable, Flags, and Level |
| 267 |
// |
| 268 |
// To activate driver must define WPP_PRIVATE_ENABLE_CALLBACK in their code, sample below |
| 269 |
// #define WPP_PRIVATE_ENABLE_CALLBACK MyPrivateCallback; |
| 270 |
// |
| 271 |
typedef |
| 272 |
VOID |
| 273 |
(*PFN_WPP_PRIVATE_ENABLE_CALLBACK)( |
| 274 |
_In_ LPCGUID Guid, |
| 275 |
_In_ __int64 Logger, |
| 276 |
_In_ BOOLEAN Enable, |
| 277 |
_In_ ULONG Flags, |
| 278 |
_In_ UCHAR Level); |
| 279 |
|
| 280 |
#ifdef __cplusplus |
| 281 |
} // extern "C" |
| 282 |
#endif |
| 283 |
|
| 284 |
#endif // #ifndef WPP_ALREADY_INCLUDED |