Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
8.2 KiB

  1. `**********************************************************************`
  2. `* This is an include template file for tracewpp preprocessor. *`
  3. `* *`
  4. `* Copyright 1999-2000 Microsoft Corporation. All Rights Reserved. *`
  5. `**********************************************************************`
  6. // template `TemplateFile`
  7. //
  8. // Defines a set of macro that expand control model specified
  9. // with WPP_CONTROL_GUIDS (example shown below)
  10. // into an enum of trace levels and required structures that
  11. // contain the mask of levels, logger handle and some information
  12. // required for registration.
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////////
  15. //
  16. // #define WPP_CONTROL_GUIDS \
  17. // WPP_DEFINE_CONTROL_GUID(Regular,(81b20fea,73a8,4b62,95bc,354477c97a6f), \
  18. // WPP_DEFINE_BIT(Error) \
  19. // WPP_DEFINE_BIT(Unusual) \
  20. // WPP_DEFINE_BIT(Noise) \
  21. // ) \
  22. // WPP_DEFINE_CONTROL_GUID(HiFreq,(91b20fea,73a8,4b62,95bc,354477c97a6f), \
  23. // WPP_DEFINE_BIT(Entry) \
  24. // WPP_DEFINE_BIT(Exit) \
  25. // WPP_DEFINE_BIT(ApiCalls) \
  26. // WPP_DEFINE_BIT(RandomJunk) \
  27. // WPP_DEFINE_BIT(LovePoem) \
  28. // )
  29. #if !defined(WPP_NO_CONTROL_GUIDS)
  30. #if defined(WPP_DEFAULT_CONTROL_GUID)
  31. # if defined(WPP_CONTROL_GUIDS)
  32. # pragma message(__FILE__ " : error : WPP_DEFAULT_CONTROL_GUID cannot be used together with WPP_CONTROL_GUIDS")
  33. # stop
  34. # else
  35. # define WPP_CONTROL_GUIDS \
  36. WPP_DEFINE_CONTROL_GUID(Default,(WPP_DEFAULT_CONTROL_GUID), \
  37. WPP_DEFINE_BIT(Error) \
  38. WPP_DEFINE_BIT(Unusual) \
  39. WPP_DEFINE_BIT(Noise) \
  40. )
  41. # endif
  42. #endif
  43. #if !defined(WPP_CONTROL_GUIDS)
  44. # pragma message(__FILE__ " : error : Please define control model via WPP_CONTROL_GUIDS or WPP_DEFAULT_CONTROL_GUID macros")
  45. # pragma message(__FILE__ " : error : don't forget to call WPP_INIT_TRACING and WPP_CLEANUP in your main, DriverEntry or DllInit")
  46. # pragma message(__FILE__ " : error : see tracewpp.doc for further information")
  47. stop.
  48. #endif
  49. // a set of macro to convert a guid in a form x(81b20fea,73a8,4b62,95bc,354477c97a6f)
  50. // into either a a struct or text string
  51. #define _WPPW(x) L ## x
  52. #define WPP_GUID_TEXT(l,w1,w2,w3,ll) #l "-" #w1 "-" #w2 "-" #w3 "-" #ll
  53. #define WPP_GUID_WTEXT(l,w1,w2,w3,ll) _WPPW(#l) L"-" _WPPW(#w1) L"-" _WPPW(#w2) L"-" _WPPW(#w3) L"-" _WPPW(#ll)
  54. #define WPP_EXTRACT_BYTE(val,n) ( ((0x ## val) >> (8 * n)) & 0xFF )
  55. #define WPP_GUID_STRUCT(l,w1,w2,w3,ll) {0x ## l, 0x ## w1, 0x ## w2,\
  56. {WPP_EXTRACT_BYTE(w3, 1), WPP_EXTRACT_BYTE(w3, 0), \
  57. WPP_EXTRACT_BYTE(ll, 5), WPP_EXTRACT_BYTE(ll, 4), \
  58. WPP_EXTRACT_BYTE(ll, 3), WPP_EXTRACT_BYTE(ll, 2), \
  59. WPP_EXTRACT_BYTE(ll, 1), WPP_EXTRACT_BYTE(ll, 0)} }
  60. // define annotation record that will carry control intormation to pdb (in case somebody needs it)
  61. __forceinline void WPP_CONTROL_ANNOTATION() {
  62. #if !defined(WPP_NO_ANNOTATIONS)
  63. #if !defined(WPP_ANSI_ANNOTATION)
  64. # define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) __annotation(L"TMC:", WPP_GUID_WTEXT Guid, _WPPW(#Name) Bits);
  65. # define WPP_DEFINE_BIT(Name) , _WPPW(#Name)
  66. #else
  67. # define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) __annotation("TMC:", WPP_GUID_TEXT Guid, #Name Bits);
  68. # define WPP_DEFINE_BIT(Name) , #Name
  69. #endif
  70. WPP_CONTROL_GUIDS
  71. # undef WPP_DEFINE_BIT
  72. # undef WPP_DEFINE_CONTROL_GUID
  73. #endif
  74. }
  75. // define an enum of control block names
  76. //////
  77. #define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) WPP_CTL_ ## Name,
  78. enum WPP_CTL_NAMES { WPP_CONTROL_GUIDS WPP_LAST_CTL};
  79. #undef WPP_DEFINE_CONTROL_GUID
  80. // define control guids
  81. //////
  82. #define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \
  83. extern __declspec(selectany) const GUID WPP_ ## ThisDir ## _CTLGUID_ ## Name = WPP_GUID_STRUCT Guid;
  84. WPP_CONTROL_GUIDS
  85. #undef WPP_DEFINE_CONTROL_GUID
  86. // define enums of individual bits
  87. /////
  88. #define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \
  89. WPP_BLOCK_START_ ## Name = WPP_CTL_ ## Name * 0x10000, Bits WPP_BLOCK_END_ ## Name,
  90. # define WPP_DEFINE_BIT(Name) WPP_BIT_ ## Name,
  91. enum WPP_DEFINE_BIT_NAMES { WPP_CONTROL_GUIDS };
  92. # undef WPP_DEFINE_BIT
  93. #undef WPP_DEFINE_CONTROL_GUID
  94. #define WPP_MASK(CTL) (1 << ( ((CTL)-1) & 31 ))
  95. #define WPP_FLAG_NO(CTL) ( (0xFFFF & ((CTL)-1) ) / 32)
  96. #define WPP_CTRL_NO(CTL) ((CTL) >> 16)
  97. // calculate how many DWORDs we need to get the required number of bits
  98. // upper estimate. Sometimes will be off by one
  99. #define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) | WPP_BLOCK_END_ ## Name
  100. enum _WPP_FLAG_LEN_ENUM { WPP_FLAG_LEN = 1 | ((0 WPP_CONTROL_GUIDS) & 0xFFFF) / 32 };
  101. #undef WPP_DEFINE_CONTROL_GUID
  102. #ifndef WPP_CB
  103. # define WPP_CB WPP_GLOBAL_Control
  104. #endif
  105. #ifndef WPP_CB_TYPE
  106. #define WPP_CB_TYPE WPP_PROJECT_CONTROL_BLOCK
  107. #endif
  108. typedef union {
  109. WPP_REGISTRATION_BLOCK Registration; // need this only to register
  110. WPP_TRACE_CONTROL_BLOCK Control;
  111. UCHAR ReserveSpace[ sizeof(WPP_TRACE_CONTROL_BLOCK) + sizeof(ULONG) * (WPP_FLAG_LEN - 1) ];
  112. } WPP_CB_TYPE ;
  113. #define WPP_NEXT(Name) ((WPP_REGISTRATION_BLOCK*) \
  114. (WPP_CTL_ ## Name + 1 == WPP_LAST_CTL ? 0:WPP_CB + WPP_CTL_ ## Name + 1))
  115. // WPP_CONTROL structure has two extra fields in the kernel
  116. // mode. We will use WPPKM_NULL to initalize them
  117. #if defined(WPP_KERNEL_MODE)
  118. # define WPPKM_NULL 0,
  119. #else
  120. # define WPPKM_NULL
  121. #endif
  122. #if defined(WPP_DLL)
  123. extern __declspec(selectany) WPP_CB_TYPE WPP_CB[WPP_LAST_CTL];
  124. __inline void WPP_INIT_CONTROL_ARRAY(WPP_CB_TYPE* Arr) {
  125. #define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) \
  126. Arr->Registration.Next = WPP_NEXT(Name); \
  127. Arr->Registration.ControlGuid = &WPP_ ## ThisDir ## _CTLGUID_ ## Name; \
  128. Arr->Registration.FriendlyName = L ## #Name; \
  129. Arr->Registration.BitNames = Bits; \
  130. Arr->Registration.FlagsLen = WPP_FLAG_LEN; \
  131. Arr->Registration.RegBlockLen = WPP_LAST_CTL; ++Arr;
  132. #define WPP_DEFINE_BIT(BitName) L" " L ## #BitName
  133. WPP_CONTROL_GUIDS
  134. #undef WPP_DEFINE_BIT
  135. #undef WPP_DEFINE_CONTROL_GUID
  136. }
  137. #define WPP_INIT_STATIC_DATA WPP_INIT_CONTROL_ARRAY(WPP_CB)
  138. #else
  139. extern __declspec(selectany) WPP_CB_TYPE WPP_CB[WPP_LAST_CTL] = {
  140. #define WPP_DEFINE_CONTROL_GUID(Name,Guid,Bits) {{WPPKM_NULL WPP_NEXT(Name), \
  141. &WPP_ ## ThisDir ## _CTLGUID_ ## Name, L ## #Name, Bits, WPPKM_NULL WPP_FLAG_LEN, WPP_LAST_CTL}},
  142. #define WPP_DEFINE_BIT(BitName) L" " L ## #BitName
  143. WPP_CONTROL_GUIDS
  144. #undef WPP_DEFINE_BIT
  145. #undef WPP_DEFINE_CONTROL_GUID
  146. };
  147. #define WPP_INIT_STATIC_DATA 0
  148. #endif
  149. #define WPP_CONTROL(CTL) (WPP_CB[WPP_CTRL_NO(CTL)].Control)
  150. #define WPP_REGISTRATION(CTL) (WPP_CB[WPP_CTRL_NO(CTL)].Registration)
  151. #define WPP_SET_FORWARD_PTR(CTL, FLAGS, PTR) (\
  152. (WPP_REGISTRATION(WPP_BIT_ ## CTL ).Options = (FLAGS)),\
  153. (WPP_REGISTRATION(WPP_BIT_ ## CTL ).Ptr = (PTR)) )
  154. #if !defined(WPP_LEVEL_LOGGER)
  155. # define WPP_LEVEL_LOGGER(CTL) (WPP_CONTROL(WPP_BIT_ ## CTL).Logger),
  156. #endif
  157. #if !defined(WPP_LEVEL_ENABLED)
  158. # define WPP_LEVEL_ENABLED(CTL) (WPP_CONTROL(WPP_BIT_ ## CTL).Flags[WPP_FLAG_NO(WPP_BIT_ ## CTL)] & WPP_MASK(WPP_BIT_ ## CTL))
  159. #endif
  160. #if !defined(WPP_LOGGER_ARG)
  161. # define WPP_LOGGER_ARG TRACEHANDLE Logger,
  162. #endif
  163. #if !defined(WPP_GET_LOGGER)
  164. # define WPP_GET_LOGGER Logger
  165. #endif
  166. #ifndef WPP_ENABLED
  167. # define WPP_ENABLED() 1
  168. #endif
  169. #ifndef WPP_LOGGER
  170. # define WPP_LOGGER() (WPP_CB[0].Control.Logger),
  171. #endif
  172. #endif // WPP_NO_CONTROL_GUIDS
  173. #if !defined(WPP_KERNEL_MODE)
  174. #if defined(__cplusplus)
  175. extern "C" {
  176. #endif
  177. VOID WppInitUm(LPCWSTR AppName, PWPP_REGISTRATION_BLOCK Registration);
  178. VOID WppCleanupUm(PWPP_REGISTRATION_BLOCK Registration);
  179. #if defined(__cplusplus)
  180. };
  181. #endif
  182. # define WPP_INIT_TRACING(AppName) (WPP_CONTROL_ANNOTATION(),WPP_INIT_STATIC_DATA,\
  183. WppInitUm(AppName, &WPP_CB[0].Registration))
  184. # define WPP_CLEANUP() WppCleanupUm(&WPP_CB[0].Registration)
  185. #else
  186. #if defined(__cplusplus)
  187. extern "C" {
  188. #endif
  189. VOID WppInitKm(PUNICODE_STRING RegistryPath, PWPP_REGISTRATION_BLOCK Registration);
  190. VOID WppCleanupKm(PWPP_REGISTRATION_BLOCK Registration);
  191. #if defined(__cplusplus)
  192. };
  193. #endif
  194. # define WPP_INIT_TRACING(DrvObj, RegPath) (WPP_CONTROL_ANNOTATION(),WPP_INIT_STATIC_DATA,\
  195. WppInitKm(RegPath, &WPP_CB[0].Registration))
  196. # define WPP_CLEANUP(DrvObj) WppCleanupKm(&WPP_CB[0].Registration)
  197. #endif