| 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 macro that expand control model specified |
| 10 |
// with WPP_CONTROL_GUIDS (example shown below) |
| 11 |
// into an enum of trace levels and required structures that |
| 12 |
// contain the mask of levels, logger handle and some information |
| 13 |
// required for registration. |
| 14 |
// |
| 15 |
|
| 16 |
#ifndef WPP_ALREADY_INCLUDED |
| 17 |
|
| 18 |
#define WPP_EVAL(x) x |
| 19 |
#define WPP_STR(x) #x |
| 20 |
#define WPP_STRINGIZE(x) WPP_STR(x) |
| 21 |
#define WPP_GLUE(a, b) a ## b |
| 22 |
#define WPP_GLUE3(a, b, c) a ## b ## c |
| 23 |
#define WPP_GLUE4(a, b, c, d) a ## b ## c ## d |
| 24 |
#define WPP_XGLUE(a, b) WPP_GLUE(a, b) |
| 25 |
#define WPP_XGLUE3(a, b, c) WPP_GLUE3(a, b, c) |
| 26 |
#define WPP_XGLUE4(a, b, c, d) WPP_GLUE4(a, b, c, d) |
| 27 |
|
| 28 |
/////////////////////////////////////////////////////////////////////////////////// |
| 29 |
// |
| 30 |
// #define WPP_CONTROL_GUIDS \ |
| 31 |
// WPP_DEFINE_CONTROL_GUID(Regular,(81b20fea,73a8,4b62,95bc,354477c97a6f), \ |
| 32 |
// WPP_DEFINE_BIT(Error) \ |
| 33 |
// WPP_DEFINE_BIT(Unusual) \ |
| 34 |
// WPP_DEFINE_BIT(Noise) \ |
| 35 |
// ) \ |
| 36 |
// WPP_DEFINE_CONTROL_GUID(HiFreq,(91b20fea,73a8,4b62,95bc,354477c97a6f), \ |
| 37 |
// WPP_DEFINE_BIT(Entry) \ |
| 38 |
// WPP_DEFINE_BIT(Exit) \ |
| 39 |
// WPP_DEFINE_BIT(ApiCalls) \ |
| 40 |
// WPP_DEFINE_BIT(RandomJunk) \ |
| 41 |
// WPP_DEFINE_BIT(LovePoem) \ |
| 42 |
// ) |
| 43 |
|
| 44 |
#ifdef __cplusplus |
| 45 |
extern "C" { |
| 46 |
#endif |
| 47 |
|
| 48 |
#ifndef WPP_NO_CONTROL_GUIDS |
| 49 |
|
| 50 |
#ifdef WPP_DEFAULT_CONTROL_GUID |
| 51 |
# ifdef WPP_CONTROL_GUIDS |
| 52 |
# error WPP_DEFAULT_CONTROL_GUID cannot be used together with WPP_CONTROL_GUIDS. |
| 53 |
# else // WPP_CONTROL_GUIDS |
| 54 |
# define WPP_CONTROL_GUIDS \ |
| 55 |
WPP_DEFINE_CONTROL_GUID(Default,(WPP_DEFAULT_CONTROL_GUID), \ |
| 56 |
WPP_DEFINE_BIT(Error) \ |
| 57 |
WPP_DEFINE_BIT(Unusual) \ |
| 58 |
WPP_DEFINE_BIT(Noise) \ |
| 59 |
) |
| 60 |
# endif // WPP_CONTROL_GUIDS |
| 61 |
#endif // WPP_DEFAULT_CONTROL_GUID |
| 62 |
|
| 63 |
#ifndef WPP_CONTROL_GUIDS |
| 64 |
# pragma message(__FILE__ " : error : Please define control model via WPP_CONTROL_GUIDS or WPP_DEFAULT_CONTROL_GUID macros") |
| 65 |
# pragma message(__FILE__ " : error : don't forget to call WPP_INIT_TRACING and WPP_CLEANUP in your main, DriverEntry or DllInit") |
| 66 |
# pragma message(__FILE__ " : error : see tracewpp.doc for further information") |
| 67 |
# error WPP_CONTROL_GUIDS not defined. |
| 68 |
#endif // WPP_CONTROL_GUIDS |
| 69 |
// a set of macro to convert a guid in a form x(81b20fea,73a8,4b62,95bc,354477c97a6f) |
| 70 |
// into either a a struct or text string |
| 71 |
|
| 72 |
#define _WPPW(x) WPP_GLUE(L, x) |
| 73 |
|
| 74 |
#define WPP_GUID_NORM(l,w1,w2,w3,ll) l ## w1 ## w2 ## w3 ## ll |
| 75 |
#define WPP_GUID_TEXT(l,w1,w2,w3,ll) #l "-" #w1 "-" #w2 "-" #w3 "-" #ll |
| 76 |
#define WPP_GUID_WTEXT(l,w1,w2,w3,ll) _WPPW(#l) L"-" _WPPW(#w1) L"-" _WPPW(#w2) L"-" _WPPW(#w3) L"-" _WPPW(#ll) |
| 77 |
#define WPP_EXTRACT_BYTE(val,n) (((ULONGLONG)(0x ## val) >> (8 * n)) & 0xFF) |
| 78 |
#define WPP_GUID_STRUCT(l,w1,w2,w3,ll) {0x ## l, 0x ## w1, 0x ## w2,\ |
| 79 |
{WPP_EXTRACT_BYTE(w3, 1), WPP_EXTRACT_BYTE(w3, 0),\ |
| 80 |
WPP_EXTRACT_BYTE(ll, 5), WPP_EXTRACT_BYTE(ll, 4),\ |
| 81 |
WPP_EXTRACT_BYTE(ll, 3), WPP_EXTRACT_BYTE(ll, 2),\ |
| 82 |
WPP_EXTRACT_BYTE(ll, 1), WPP_EXTRACT_BYTE(ll, 0)} } |
| 83 |
|
| 84 |
#ifndef WPP_FORCEINLINE |
| 85 |
#define WPP_FORCEINLINE __forceinline |
| 86 |
#endif |
| 87 |
|
| 88 |
// define an enum of control block names |
| 89 |
////// |
| 90 |
#define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) WPP_XGLUE(WPP_CTL_, WPP_EVAL(Name)), |
| 91 |
enum WPP_CTL_NAMES { WPP_CONTROL_GUIDS WPP_LAST_CTL}; |
| 92 |
#undef WPP_DEFINE_CONTROL_GUID |
| 93 |
|
| 94 |
// define control guids |
| 95 |
////// |
| 96 |
#define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \ |
| 97 |
extern __declspec(selectany) const GUID WPP_XGLUE4(WPP_, ThisDir, _CTLGUID_, WPP_EVAL(Name)) = WPP_GUID_STRUCT Guid; |
| 98 |
WPP_CONTROL_GUIDS |
| 99 |
#undef WPP_DEFINE_CONTROL_GUID |
| 100 |
|
| 101 |
// define enums of individual bits |
| 102 |
///// |
| 103 |
#define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \ |
| 104 |
WPP_XGLUE(WPP_BLOCK_START_, WPP_EVAL(Name)) = WPP_XGLUE(WPP_CTL_, WPP_EVAL(Name)) * 0x10000, Bits WPP_XGLUE(WPP_BLOCK_END_, WPP_EVAL(Name)), |
| 105 |
# define WPP_DEFINE_BIT(Name) WPP_BIT_ ## Name, |
| 106 |
enum WPP_DEFINE_BIT_NAMES { WPP_CONTROL_GUIDS }; |
| 107 |
# undef WPP_DEFINE_BIT |
| 108 |
#undef WPP_DEFINE_CONTROL_GUID |
| 109 |
|
| 110 |
#define WPP_MASK(CTL) (1 << ( ((CTL)-1) & 31 )) |
| 111 |
#define WPP_FLAG_NO(CTL) ( (0xFFFF & ((CTL)-1) ) / 32) |
| 112 |
#define WPP_CTRL_NO(CTL) ((CTL) >> 16) |
| 113 |
|
| 114 |
// calculate how many DWORDs we need to get the required number of bits |
| 115 |
// upper estimate. Sometimes will be off by one |
| 116 |
#define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) | WPP_XGLUE(WPP_BLOCK_END_, WPP_EVAL(Name)) |
| 117 |
enum _WPP_FLAG_LEN_ENUM { WPP_FLAG_LEN = 1 | ((0 WPP_CONTROL_GUIDS) & 0xFFFF) / 32 }; |
| 118 |
#undef WPP_DEFINE_CONTROL_GUID |
| 119 |
|
| 120 |
// |
| 121 |
// Check that maximum number of flags does not exceed 32 |
| 122 |
// |
| 123 |
#ifndef C_ASSERT |
| 124 |
#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1] |
| 125 |
#endif |
| 126 |
|
| 127 |
#define MAX_NUMBER_OF_ETW_FLAGS 34 // 32 flags plus 2 separators |
| 128 |
#define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) && ((WPP_XGLUE(WPP_BLOCK_END_, WPP_EVAL(Name) & 0xFFFF)) < MAX_NUMBER_OF_ETW_FLAGS) |
| 129 |
enum _WPP_FLAG_LEN_ENUM_MAX { WPP_MAX_FLAG_LEN_CHECK = (1 WPP_CONTROL_GUIDS) }; |
| 130 |
#undef WPP_DEFINE_CONTROL_GUID |
| 131 |
|
| 132 |
#ifndef WPP_CB |
| 133 |
#define WPP_CB WPP_GLOBAL_Control |
| 134 |
#endif |
| 135 |
#ifndef WPP_CB_TYPE |
| 136 |
#define WPP_CB_TYPE WPP_PROJECT_CONTROL_BLOCK |
| 137 |
#endif |
| 138 |
|
| 139 |
#ifndef WPP_CHECK_INIT |
| 140 |
#define WPP_CHECK_INIT (WPP_CB != (WPP_CB_TYPE*)&WPP_CB) && |
| 141 |
#endif |
| 142 |
|
| 143 |
typedef union { |
| 144 |
WPP_TRACE_CONTROL_BLOCK Control; |
| 145 |
UCHAR ReserveSpace[ sizeof(WPP_TRACE_CONTROL_BLOCK) + sizeof(ULONG) * (WPP_FLAG_LEN - 1) ]; |
| 146 |
} WPP_CB_TYPE ; |
| 147 |
|
| 148 |
|
| 149 |
extern __declspec(selectany) WPP_CB_TYPE *WPP_CB = (WPP_CB_TYPE*)&WPP_CB; |
| 150 |
|
| 151 |
#if ENABLE_WPP_RECORDER |
| 152 |
#ifndef WPP_RECORDER_CHECK_INIT |
| 153 |
#define WPP_RECORDER_CHECK_INIT (WPP_RECORDER_INITIALIZED != (WPP_CB_TYPE*)&WPP_RECORDER_INITIALIZED) && |
| 154 |
#endif |
| 155 |
// Global varaible used to track if WPP_RECORDER was initialized. |
| 156 |
// It will be initialized on calling WPP_INIT_TRACING macro. |
| 157 |
extern __declspec(selectany) WPP_CB_TYPE *WPP_RECORDER_INITIALIZED = (WPP_CB_TYPE*)&WPP_RECORDER_INITIALIZED; |
| 158 |
#endif |
| 159 |
|
| 160 |
#define WPP_CONTROL(CTL) (WPP_CB[WPP_CTRL_NO(CTL)].Control) |
| 161 |
|
| 162 |
// Define the default WPP_LEVEL_LOGGER/WPP_LEVEL_ENABLED macros for the |
| 163 |
// predefined DoTraceMessage(LEVEL) function. |
| 164 |
#ifdef WPP_USE_TRACE_LEVELS |
| 165 |
|
| 166 |
#ifndef WPP_LEVEL_LOGGER |
| 167 |
#define WPP_LEVEL_LOGGER(lvl) (WPP_CONTROL(WPP_BIT_ ## DUMMY).Logger), |
| 168 |
#endif |
| 169 |
#ifndef WPP_LEVEL_ENABLED |
| 170 |
#define WPP_LEVEL_ENABLED(lvl) (WPP_CONTROL(WPP_BIT_ ## DUMMY).Level >= lvl) |
| 171 |
#endif |
| 172 |
|
| 173 |
#else // WPP_USE_TRACE_LEVELS |
| 174 |
|
| 175 |
// For historical reasons, the use of LEVEL means flags by default. |
| 176 |
// This was a bad choice but very difficult to undo. |
| 177 |
#ifndef WPP_LEVEL_LOGGER |
| 178 |
# define WPP_LEVEL_LOGGER(CTL) (WPP_CONTROL(WPP_BIT_ ## CTL).Logger), |
| 179 |
#endif |
| 180 |
#ifndef WPP_LEVEL_ENABLED |
| 181 |
# define WPP_LEVEL_ENABLED(CTL) (WPP_CONTROL(WPP_BIT_ ## CTL).Flags[WPP_FLAG_NO(WPP_BIT_ ## CTL)] & WPP_MASK(WPP_BIT_ ## CTL)) |
| 182 |
#endif |
| 183 |
|
| 184 |
#endif // WPP_USE_TRACE_LEVELS |
| 185 |
|
| 186 |
// Define default WPP_FLAG_LOGGER/WPP_FLAG_ENABLED macros for convenience in |
| 187 |
// defining a function that takes a FLAG parameter e.g. DoTrace(FLAG). |
| 188 |
#ifndef WPP_FLAG_LOGGER |
| 189 |
# define WPP_FLAG_LOGGER(CTL) (WPP_CONTROL(WPP_BIT_ ## CTL).Logger), |
| 190 |
#endif |
| 191 |
#ifndef WPP_FLAG_ENABLED |
| 192 |
# define WPP_FLAG_ENABLED(CTL) (WPP_CONTROL(WPP_BIT_ ## CTL).Flags[WPP_FLAG_NO(WPP_BIT_ ## CTL)] & WPP_MASK(WPP_BIT_ ## CTL)) |
| 193 |
#endif |
| 194 |
|
| 195 |
#ifndef WPP_ENABLED |
| 196 |
# define WPP_ENABLED() 1 |
| 197 |
#endif |
| 198 |
#ifndef WPP_LOGGER |
| 199 |
# define WPP_LOGGER() (WPP_CB[0].Control.Logger), |
| 200 |
#endif |
| 201 |
|
| 202 |
#endif // WPP_NO_CONTROL_GUIDS |
| 203 |
|
| 204 |
#ifndef WPP_GET_LOGGER |
| 205 |
# define WPP_GET_LOGGER Logger |
| 206 |
#endif |
| 207 |
|
| 208 |
#ifndef WPP_LOGGER_ARG |
| 209 |
# define WPP_LOGGER_ARG TRACEHANDLE Logger, |
| 210 |
#endif |
| 211 |
|
| 212 |
#ifdef __cplusplus |
| 213 |
} // extern "C" |
| 214 |
#endif |
| 215 |
|
| 216 |
#endif // WPP_ALREADY_INCLUDED |