Leaked source code of windows server 2003
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.

451 lines
20 KiB

  1. /****************************************************************************/
  2. // atrcapi.h
  3. //
  4. // Kernel mode trace header
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #ifndef _H_ATRCAPI
  9. #define _H_ATRCAPI
  10. #define TRC_BUFFER_SIZE 255
  11. #ifdef DLL_DISP
  12. /****************************************************************************/
  13. // In RDPDD, TT_APIx are not defined - define them here
  14. /****************************************************************************/
  15. #define TT_API1 0x00000001 /* API level 1 */
  16. #define TT_API2 0x00000002 /* API level 2 */
  17. #define TT_API3 0x00000004 /* API level 3 */
  18. #define TT_API4 0x00000008 /* API level 4 */
  19. #define TT_ERROR 0xffffffff /* error condition */
  20. /****************************************************************************/
  21. // No profile tracing in RDPDD
  22. /****************************************************************************/
  23. #ifdef TRC_COMPILE_PRF
  24. #undef TRC_COMPILE_PRF
  25. #endif
  26. #endif /* DLL_DISP */
  27. /****************************************************************************/
  28. /* Before including this file the TRC_FILE macro should be defined. This */
  29. /* is much more efficient than relying on __FILE__ to give the correct */
  30. /* filename since it includes unnecessary path info (and extension info). */
  31. /* In addition each use of __FILE__ causes a new constant string to be */
  32. /* placed in the data segment. */
  33. /****************************************************************************/
  34. #ifdef TRC_FILE
  35. #define _file_name_ (char *)__filename
  36. static const char __filename[] = TRC_FILE;
  37. #endif /* TRC_FILE */
  38. /****************************************************************************/
  39. /* Define the trace level. */
  40. /* */
  41. /* TRC_LEVEL_DBG : All tracing is enabled */
  42. /* TRC_LEVEL_NRM : Debug level tracing is disabled */
  43. /* TRC_LEVEL_ALT : Normal and debug level tracing is disabled */
  44. /* TRC_LEVEL_ERR : Alert, normal and debug level tracing is */
  45. /* disabled */
  46. /* TRC_LEVEL_ASSERT : Error, alert, normal and debug level tracing */
  47. /* is disabled */
  48. /* TRC_LEVEL_DIS : All tracing is disabled. */
  49. /****************************************************************************/
  50. #define TRC_LEVEL_DBG 0
  51. #define TRC_LEVEL_NRM 1
  52. #define TRC_LEVEL_ALT 2
  53. #define TRC_LEVEL_ERR 3
  54. #define TRC_LEVEL_ASSERT 4
  55. #define TRC_LEVEL_DIS 5
  56. /****************************************************************************/
  57. /* Tracing can be switched off at compile time to allow for 'debug' and */
  58. /* 'retail' versions of the product. The following macros disable specific */
  59. /* trace processing. */
  60. /* */
  61. /* TRC_ENABLE_DBG - Enable debug tracing */
  62. /* TRC_ENABLE_NRM - Enable normal tracing */
  63. /* TRC_ENABLE_ALT - Enable alert tracing */
  64. /* TRC_ENABLE_ERR - Enable error tracing */
  65. /* TRC_ENABLE_ASSERT - Enable assert tracing */
  66. /* TRC_ENABLE_PRF - Enable function profile tracing */
  67. /****************************************************************************/
  68. #if (TRC_COMPILE_LEVEL == TRC_LEVEL_DBG)
  69. #define TRC_ENABLE_DBG
  70. #define TRC_ENABLE_NRM
  71. #define TRC_ENABLE_ALT
  72. #define TRC_ENABLE_ERR
  73. #define TRC_ENABLE_ASSERT
  74. #endif
  75. #if (TRC_COMPILE_LEVEL == TRC_LEVEL_NRM)
  76. #define TRC_ENABLE_NRM
  77. #define TRC_ENABLE_ALT
  78. #define TRC_ENABLE_ERR
  79. #define TRC_ENABLE_ASSERT
  80. #endif
  81. #if (TRC_COMPILE_LEVEL == TRC_LEVEL_ALT)
  82. #define TRC_ENABLE_ALT
  83. #define TRC_ENABLE_ERR
  84. #define TRC_ENABLE_ASSERT
  85. #endif
  86. #if (TRC_COMPILE_LEVEL == TRC_LEVEL_ERR)
  87. #define TRC_ENABLE_ERR
  88. #define TRC_ENABLE_ASSERT
  89. #endif
  90. #if (TRC_COMPILE_LEVEL == TRC_LEVEL_ASSERT)
  91. #define TRC_ENABLE_ASSERT
  92. #endif
  93. #ifdef TRC_COMPILE_PRF
  94. #define TRC_ENABLE_PRF
  95. #endif
  96. /****************************************************************************/
  97. /* Prefix constants */
  98. /* */
  99. /* TRC_MAX_PREFIX : number of prefixes supported */
  100. /* TRC_PREFIX_NAME_LEN : length of a prefix name */
  101. /****************************************************************************/
  102. #define TRC_MAX_PREFIX 20
  103. #define TRC_PREFIX_NAME_LEN 8
  104. /****************************************************************************/
  105. /* Structure: TRC_PREFIX_DATA */
  106. /* */
  107. /* Description: Trace prefixes */
  108. /****************************************************************************/
  109. typedef struct tagTRC_PREFIX_DATA
  110. {
  111. char name[TRC_PREFIX_NAME_LEN];
  112. UINT32 start;
  113. UINT32 end;
  114. } TRC_PREFIX_DATA, *PTRC_PREFIX_DATA;
  115. /****************************************************************************/
  116. // TRC_SHARED_DATA
  117. //
  118. // TS stack trace info for the DD shared memory.
  119. /****************************************************************************/
  120. typedef struct tagTRC_SHARED_DATA
  121. {
  122. BOOL init;
  123. UINT32 TraceClass;
  124. UINT32 TraceEnable;
  125. TRC_PREFIX_DATA prefix[TRC_MAX_PREFIX];
  126. } TRC_SHARED_DATA, *PTRC_SHARED_DATA;
  127. /****************************************************************************/
  128. /* Various trace helper definitions */
  129. /****************************************************************************/
  130. #ifdef DLL_DISP
  131. #define TB ddTraceString, sizeof(ddTraceString)
  132. #else
  133. #define TB pTRCWd->traceString, sizeof(pTRCWd->traceString)
  134. #endif
  135. #ifdef DLL_DISP
  136. #define TraceBuffer ddTraceString
  137. #else
  138. #define TraceBuffer pTRCWd->traceString
  139. #endif
  140. #define TRC_FUNC_FMT "%-*.*s"
  141. #define TRC_LINE_FMT "%04d"
  142. #define TRC_FUNCNAME_LEN 12
  143. #define TRC_SEP_DBG ' '
  144. #define TRC_SEP_NRM ' '
  145. #define TRC_SEP_ALT '+'
  146. #define TRC_SEP_ERR '*'
  147. #define TRC_SEP_ASSERT '!'
  148. #define TRC_SEP_PROF ' '
  149. #if (TRC_COMPILE_LEVEL < TRC_LEVEL_DIS)
  150. #define TRC_FN(A) static const char __fnname[] = A; \
  151. char *trc_fn = (char *)__fnname; \
  152. char *trc_file = _file_name_;
  153. #else
  154. #define TRC_FN(A)
  155. #endif
  156. /****************************************************************************/
  157. /* Standard trace macros */
  158. /****************************************************************************/
  159. #ifdef TRC_ENABLE_DBG
  160. #define TRC_DBG(string) TRCX(TT_API1, TRC_SEP_DBG, string)
  161. #else
  162. #define TRC_DBG(string)
  163. #endif
  164. #ifdef TRC_ENABLE_NRM
  165. #define TRC_NRM(string) TRCX(TT_API2, TRC_SEP_NRM, string)
  166. #else
  167. #define TRC_NRM(string)
  168. #endif
  169. #ifdef TRC_ENABLE_ALT
  170. #define TRC_ALT(string) TRCX(TT_API3, TRC_SEP_ALT, string)
  171. #else
  172. #define TRC_ALT(string)
  173. #endif
  174. #ifdef TRC_ENABLE_ERR
  175. #define TRC_ERR(string) TRCX(TT_API4, TRC_SEP_ERR, string)
  176. #else
  177. #define TRC_ERR(string)
  178. #endif
  179. #ifdef TRC_ENABLE_ASSERT
  180. #ifdef DLL_DISP
  181. /****************************************************************************/
  182. // TRC_ASSERT & TRC_ABORT for RDPDD
  183. /****************************************************************************/
  184. #define TRC_ASSERT(condition, string) \
  185. { \
  186. if (!(condition)) \
  187. { \
  188. TRCX(TT_ERROR, TRC_SEP_ASSERT, string); \
  189. EngDebugBreak(); \
  190. } \
  191. }
  192. #define TRC_ABORT(string) \
  193. { \
  194. TRCX(TT_ERROR, TRC_SEP_ASSERT, string); \
  195. EngDebugBreak(); \
  196. }
  197. #else /* DLL_DISP */
  198. /****************************************************************************/
  199. // TRC_ASSERT & TRC_ABORT for RDPWD
  200. /****************************************************************************/
  201. #define TRC_ASSERT(condition, string) \
  202. { \
  203. if (!(condition)) \
  204. { \
  205. TRCX(TT_ERROR, TRC_SEP_ASSERT, string); \
  206. DbgBreakPoint(); \
  207. } \
  208. }
  209. #define TRC_ABORT(string) \
  210. { \
  211. TRCX(TT_ERROR, TRC_SEP_ASSERT, string); \
  212. DbgBreakPoint(); \
  213. }
  214. #endif /* DLL_DISP */
  215. #else /* TRC_ENABLE_ASSERT */
  216. /****************************************************************************/
  217. // TRC_ASSERT & TRC_ABORT for retail builds (same for RDPWD & RDPDD)
  218. /****************************************************************************/
  219. #define TRC_ASSERT(condition, string)
  220. #define TRC_ABORT(string)
  221. #endif /* TRC_ENABLE_ASSERT */
  222. #ifdef TRC_ENABLE_TST
  223. #define TRC_TST TRC_DBG
  224. #else
  225. #define TRC_TST(x)
  226. #endif /* TRC_ENABLE_TST */
  227. #ifdef DLL_DISP
  228. /****************************************************************************/
  229. // TRCX for RDPDD
  230. /****************************************************************************/
  231. #define TRCX(type, separator, traceString) \
  232. { \
  233. if (TRC_WillTrace(type, TC_DISPLAY, trc_file, __LINE__)) \
  234. { \
  235. _snprintf traceString; \
  236. TRC_TraceLine(NULL, \
  237. TC_DISPLAY, \
  238. type, \
  239. TraceBuffer, \
  240. separator, \
  241. (int)__LINE__, \
  242. trc_fn, \
  243. trc_file); \
  244. } \
  245. }
  246. #else /* DLL_DISP */
  247. /****************************************************************************/
  248. // TRCX for RDPWD
  249. /****************************************************************************/
  250. #define TRCX(type, separator, traceString) \
  251. { \
  252. if (TRC_WillTrace(pTRCWd, type, TC_WD, trc_file, __LINE__)) \
  253. { \
  254. _snprintf traceString; \
  255. TRC_TraceLine(pTRCWd, \
  256. TC_WD, \
  257. type, \
  258. TraceBuffer, \
  259. separator, \
  260. (int)__LINE__, \
  261. trc_fn, \
  262. trc_file); \
  263. } \
  264. }
  265. #endif /* DLL_DISP */
  266. /****************************************************************************/
  267. /* Function profile trace macros */
  268. /****************************************************************************/
  269. #define TRC_ENTRY TRC_PRF((TB, "Enter {"));
  270. #define TRC_EXIT TRC_PRF((TB, "Exit }"));
  271. #ifdef TRC_ENABLE_PRF
  272. #define TRC_PRF(string) TRCP(string)
  273. #else
  274. #define TRC_PRF(string)
  275. #endif
  276. #define TRCP(traceString) \
  277. { \
  278. if (TRC_WillTrace(pTRCWd, type, TC_WD, trc_file, __LINE__)) \
  279. { \
  280. _snprintf traceString; \
  281. TRC_TraceLine(pTRCWd, \
  282. TC_WD, \
  283. TT_API1, \
  284. TraceBuffer, \
  285. TRC_SEP_PROF, \
  286. (int)__LINE__, \
  287. trc_fn, \
  288. trc_file); \
  289. } \
  290. }
  291. /****************************************************************************/
  292. /* Data dump trace macros */
  293. /****************************************************************************/
  294. #ifdef DLL_DISP
  295. /****************************************************************************/
  296. // @@@MF No data tracing in RDPDD (yet?)
  297. /****************************************************************************/
  298. #define TRC_DATA_DBG(a, b, c)
  299. #define TRC_DATA_NRM(a, b, c)
  300. #define TRC_DATA_ALT(a, b, c)
  301. #define TRC_DATA_ERR(a, b, c)
  302. #else /* DLL_DISP */
  303. /****************************************************************************/
  304. // TRC_DATA macros for RDPWD
  305. /****************************************************************************/
  306. #ifdef TRC_ENABLE_DBG
  307. #define TRC_DATA_DBG(string, buffer, length) \
  308. TRCX_DATA(TT_OUT1, TRC_SEP_DBG, string, buffer, length)
  309. #else
  310. #define TRC_DATA_DBG(string, buffer, length)
  311. #endif
  312. #ifdef TRC_ENABLE_NRM
  313. #define TRC_DATA_NRM(string, buffer, length) \
  314. TRCX_DATA(TT_OUT2, TRC_SEP_NRM, string, buffer, length)
  315. #else
  316. #define TRC_DATA_NRM(string, buffer, length)
  317. #endif
  318. #ifdef TRC_ENABLE_ALT
  319. #define TRC_DATA_ALT(string, buffer, length) \
  320. TRCX_DATA(TT_OUT3, TRC_SEP_ALT, string, buffer, length)
  321. #else
  322. #define TRC_DATA_ALT(string, buffer, length)
  323. #endif
  324. #ifdef TRC_ENABLE_ERR
  325. #define TRC_DATA_ERR(string, buffer, length) \
  326. TRCX_DATA(TT_OUT4, TRC_SEP_ERR, string, buffer, length)
  327. #else
  328. #define TRC_DATA_ERR(string, buffer, length)
  329. #endif
  330. #ifdef TRC_ENABLE_NRM
  331. #define TRC_DATA_NET(string, buffer, length) \
  332. TRCX_DATA(TT_OUT2, TRC_SEP_NRM, string, buffer, length)
  333. #else
  334. #define TRC_DATA_NET(string, buffer, length)
  335. #endif
  336. #define TRCX_DATA(type, separator, string, buffer, length) \
  337. { \
  338. if (TRC_WillTrace(pTRCWd, type, TC_WD, trc_file, __LINE__)) \
  339. { \
  340. TRC_TraceLine(pTRCWd, \
  341. TC_WD, \
  342. type, \
  343. string, \
  344. separator, \
  345. (int)__LINE__, \
  346. trc_fn, \
  347. trc_file); \
  348. \
  349. /*************************************************************/ \
  350. /* Use direct function call here, since macro TRACESTACKBUF */ \
  351. /* is #defined to _IcaStackTraceBuffer, which takes the */ \
  352. /* wrong sort of first param. */ \
  353. /*************************************************************/ \
  354. IcaStackTraceBuffer(pTRCWd->pContext, \
  355. TC_WD, \
  356. type, \
  357. buffer, \
  358. length); \
  359. } \
  360. }
  361. #endif /* DLL_DISP */
  362. /****************************************************************************/
  363. // TRC_TraceLine - function used by RDPDD and RDPWD
  364. /****************************************************************************/
  365. void TRC_TraceLine(PVOID, UINT32, UINT32, char *, char, unsigned, char *,
  366. char *);
  367. /****************************************************************************/
  368. // Functions used by RDPWD only
  369. /****************************************************************************/
  370. #ifndef DLL_DISP
  371. void TRC_UpdateConfig(PVOID, PSD_IOCTL);
  372. void TRC_MaybeCopyConfig(PVOID, PTRC_SHARED_DATA);
  373. #endif
  374. /****************************************************************************/
  375. /* TRC_WillTrace */
  376. /****************************************************************************/
  377. #ifdef DLL_DISP
  378. BOOL TRC_WillTrace(UINT32, UINT32, char *, UINT32);
  379. #else
  380. BOOL TRC_WillTrace(PVOID, UINT32, UINT32, char *, UINT32);
  381. #endif
  382. #endif /* _H_ATRCAPI */