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.

545 lines
14 KiB

  1. //============================================================================
  2. // Copyright (c) 1995, Microsoft Corporation
  3. //
  4. // File: trace.h
  5. //
  6. // History:
  7. // Abolade Gbadegesin July-24-1995 Created
  8. //
  9. // Private declarations for tracing API functions
  10. //
  11. // Support for both ANSI and Unicode is achieved by having separate
  12. // versions of all code-page dependent functions for each.
  13. // All source files containing code-page dependent functions contain only
  14. // code-page dependent functions, and the build instructions copy the
  15. // source files containing code-page dependent functions to two separate
  16. // files, one of which is compiled with UNICODE defined, the other without.
  17. //
  18. // At this time the macros in this header file are resolved either to
  19. // ANSI declarations or Unicode declarations for types and functions.
  20. // Thus there is only one set of sources to maintain but compilation produces
  21. // separate execution paths for clients using ANSI and Unicode.
  22. // For example the file api.c which contains TraceRegisterEx will be copied
  23. // to both api_a.c and api_w.c, and api_w.c will be compiled with -DUNICODE
  24. // causing TraceRegisterEx in the file to resolve to TraceRegisterExW,
  25. // and causing TCHAR and LPTSTR and LPCTSTR to resolve to WCHAR, LPWSTR, and
  26. // LPCWSTR respectively; api_a.c will be compiled with UNICODE undefined,
  27. // causing TraceRegisterEx to resolve to TraceRegisterExA, and causing TCHAR,
  28. // LPTSTR and LPCTSTR to resolve to CHAR, LPSTR and LPCSTR respectively.
  29. // The final DLL will then contain both TraceRegisterExA and TraceRegisterExW
  30. // and clients which define UNICODE will end up invoking TraceRegisterExW
  31. // and the other Unicode variants, while clients which do not will invoke
  32. // TraceRegisterExA and the other ANSI variants.
  33. //
  34. // The server thread and the functions it invokes include explicit
  35. // calls to the correct code-page dependent function based on whether the
  36. // flag TRACEFLAGS_UNICODE is set in the client structure being operated on.
  37. // Thus, the server is the only part of the system aware that more than one
  38. // code page is in use, and the file server.c is compiled as is so the
  39. // single set of its functions deals with both ANSI and Unicode clients.
  40. // The alternative would be to have two server threads when both
  41. // ANSI and Unicode clients register in a single process, but this alternative
  42. // is too costly in terms of resources and additional synchronization.
  43. //============================================================================
  44. #ifndef _TRACE_H_
  45. #define _TRACE_H_
  46. #define TRACEFLAGS_DISABLED 0x00000001
  47. #define TRACEFLAGS_USEFILE 0x00000002
  48. #define TRACEFLAGS_USECONSOLE 0x00000004
  49. #define TRACEFLAGS_REGCONFIG 0x00000008
  50. #define TRACEFLAGS_SERVERTHREAD 0x00000010
  51. #define MAX_CLIENT_COUNT 60
  52. #define MAX_CLIENTNAME_LENGTH 64
  53. //
  54. // strings associated with client registry configuration
  55. //
  56. #define REGKEY_TRACING TEXT("Software\\Microsoft\\Tracing")
  57. #define REGVAL_ENABLEFILETRACING TEXT("EnableFileTracing")
  58. #define REGVAL_ENABLECONSOLETRACING TEXT("EnableConsoleTracing")
  59. #define REGVAL_FILETRACINGMASK TEXT("FileTracingMask")
  60. #define REGVAL_CONSOLETRACINGMASK TEXT("ConsoleTracingMask")
  61. #define REGVAL_MAXFILESIZE TEXT("MaxFileSize")
  62. #define REGVAL_FILEDIRECTORY TEXT("FileDirectory")
  63. #define DEF_ENABLEFILETRACING 0
  64. #define DEF_ENABLECONSOLETRACING 0
  65. #define DEF_FILETRACINGMASK 0xffff0000
  66. #define DEF_CONSOLETRACINGMASK 0xffff0000
  67. #define DEF_MAXFILESIZE 0x100000
  68. #define DEF_FILEDIRECTORY TEXT("%windir%\\tracing")
  69. #define DEF_SCREENBUF_WIDTH 128
  70. #define DEF_SCREENBUF_HEIGHT 5000
  71. //max line length:349
  72. #define DEF_PRINT_BUFSIZE 10000
  73. #define BYTES_PER_DUMPLINE 16
  74. #define STR_DIRSEP TEXT("\\")
  75. #define STR_LOGEXT TEXT(".LOG")
  76. #define STR_OLDEXT TEXT(".OLD")
  77. //
  78. // structure describing each client.
  79. // a client struct should be locked for writing when
  80. // enabling or disabling it, and when loading its configuration
  81. // a client struct should be locked for reading on all other accesses
  82. //
  83. typedef struct _TRACE_CLIENT {
  84. RTL_RESOURCE ReadWriteLock;
  85. DWORD TC_Flags;
  86. DWORD TC_ClientID;
  87. CHAR TC_ClientNameA[MAX_CLIENTNAME_LENGTH];
  88. WCHAR TC_ClientNameW[MAX_CLIENTNAME_LENGTH];
  89. #ifdef UNICODE
  90. #define TC_ClientName TC_ClientNameW
  91. #else
  92. #define TC_ClientName TC_ClientNameA
  93. #endif
  94. HANDLE TC_File;
  95. HANDLE TC_Console;
  96. DWORD TC_FileMask;
  97. DWORD TC_ConsoleMask;
  98. DWORD TC_MaxFileSize;
  99. CHAR TC_FileDirA[MAX_PATH];
  100. WCHAR TC_FileDirW[MAX_PATH];
  101. #ifdef UNICODE
  102. #define TC_FileDir TC_FileDirW
  103. #else
  104. #define TC_FileDir TC_FileDirA
  105. #endif
  106. HKEY TC_ConfigKey;
  107. HANDLE TC_ConfigEvent;
  108. } TRACE_CLIENT, *LPTRACE_CLIENT;
  109. //
  110. // structure describing each server.
  111. // a server struct must be locked for writing when adding
  112. // or removing a client to the client table, and when changing
  113. // the owner of the console
  114. // a server should be locked for reading on all other accesses
  115. //
  116. typedef struct _TRACE_SERVER {
  117. RTL_RESOURCE ReadWriteLock;
  118. DWORD TS_Flags;
  119. DWORD TS_ClientCount;
  120. DWORD TS_ConsoleOwner;
  121. HANDLE TS_Console;
  122. HANDLE TS_StopEvent;
  123. HANDLE TS_TableEvent;
  124. DWORD TS_FlagsCache[MAX_CLIENT_COUNT];
  125. LPTRACE_CLIENT TS_ClientTable[MAX_CLIENT_COUNT];
  126. } TRACE_SERVER, *LPTRACE_SERVER;
  127. #define GET_TRACE_SERVER() ( \
  128. (g_server!=NULL) ? g_server : TraceCreateServer(&g_server) \
  129. )
  130. #define GET_TRACE_SERVER_NO_INIT() (g_server)
  131. //
  132. // macros used to lock client and server structures
  133. //
  134. #define TRACE_STARTUP_LOCKING(ob) \
  135. RtlInitializeResource(&(ob)->ReadWriteLock)
  136. #define TRACE_CLEANUP_LOCKING(ob) \
  137. RtlDeleteResource(&(ob)->ReadWriteLock)
  138. #define TRACE_ACQUIRE_READLOCK(ob) \
  139. RtlAcquireResourceShared(&(ob)->ReadWriteLock, TRUE)
  140. #define TRACE_RELEASE_READLOCK(ob) \
  141. RtlReleaseResource(&(ob)->ReadWriteLock)
  142. #define TRACE_ACQUIRE_WRITELOCK(ob) \
  143. RtlAcquireResourceExclusive(&(ob)->ReadWriteLock, TRUE)
  144. #define TRACE_RELEASE_WRITELOCK(ob) \
  145. RtlReleaseResource(&(ob)->ReadWriteLock)
  146. #define TRACE_READ_TO_WRITELOCK(ob) \
  147. RtlConvertSharedToExclusive(&(ob)->ReadWriteLock)
  148. #define TRACE_WRITE_TO_READLOCK(ob) \
  149. RtlConvertExclusiveToShared(&(ob)->ReadWriteLock)
  150. //
  151. // macros used to interpret client flags
  152. //
  153. #define TRACE_CLIENT_IS_DISABLED(c) \
  154. ((c)->TC_Flags & TRACEFLAGS_DISABLED)
  155. #define TRACE_CLIENT_USES_FILE(c) \
  156. ((c)->TC_Flags & TRACEFLAGS_USEFILE)
  157. #define TRACE_CLIENT_USES_CONSOLE(c) \
  158. ((c)->TC_Flags & TRACEFLAGS_USECONSOLE)
  159. #define TRACE_CLIENT_USES_REGISTRY(c) \
  160. ((c)->TC_Flags & TRACEFLAGS_REGCONFIG)
  161. #define TRACE_CLIENT_USES_UNICODE(c) \
  162. ((c)->TC_Flags & TRACEFLAGS_UNICODE)
  163. // macro used to create server thread if required
  164. DWORD
  165. TraceCreateServerThread (
  166. DWORD Flags,
  167. BOOL bHaveLock,
  168. BOOL bTraceRegister
  169. );
  170. #define CREATE_SERVER_THREAD_IF_REQUIRED() {\
  171. if (!g_serverThread) TraceCreateServerThread(0, FALSE,FALSE);}
  172. //
  173. // code-page independent function declarations
  174. //
  175. LPTRACE_SERVER
  176. TraceCreateServer(
  177. LPTRACE_SERVER *lpserver
  178. );
  179. BOOL
  180. TraceShutdownServer(
  181. LPTRACE_SERVER lpserver
  182. );
  183. DWORD
  184. TraceCleanUpServer(
  185. LPTRACE_SERVER lpserver
  186. );
  187. DWORD
  188. TraceServerThread(
  189. LPVOID lpvParam
  190. );
  191. DWORD
  192. TraceCreateServerComplete(
  193. LPTRACE_SERVER lpserver
  194. );
  195. DWORD
  196. TraceProcessConsoleInput(
  197. LPTRACE_SERVER lpserver
  198. );
  199. DWORD
  200. TraceShiftConsoleWindow(
  201. LPTRACE_CLIENT lpclient,
  202. INT iXShift,
  203. INT iYShift,
  204. PCONSOLE_SCREEN_BUFFER_INFO pcsbi
  205. );
  206. DWORD
  207. TraceUpdateConsoleOwner(
  208. LPTRACE_SERVER lpserver,
  209. INT dir
  210. );
  211. VOID
  212. SetWaitArray(
  213. LPTRACE_SERVER lpserver
  214. );
  215. //
  216. // code-page dependent function declarations
  217. //
  218. // ANSI declarations
  219. //
  220. LPTRACE_CLIENT
  221. TraceFindClientA(
  222. LPTRACE_SERVER lpserver,
  223. LPCSTR lpszClient
  224. );
  225. DWORD
  226. TraceCreateClientA(
  227. LPTRACE_CLIENT *lplpentry
  228. );
  229. DWORD
  230. TraceDeleteClientA(
  231. LPTRACE_SERVER lpserver,
  232. LPTRACE_CLIENT *lplpentry
  233. );
  234. DWORD
  235. TraceEnableClientA(
  236. LPTRACE_SERVER lpserver,
  237. LPTRACE_CLIENT lpclient,
  238. BOOL bFirstTime
  239. );
  240. DWORD
  241. TraceDisableClientA(
  242. LPTRACE_SERVER lpserver,
  243. LPTRACE_CLIENT lpclient
  244. );
  245. DWORD
  246. TraceRegConfigClientA(
  247. LPTRACE_CLIENT lpclient,
  248. BOOL bFirstTime
  249. );
  250. DWORD
  251. TraceRegCreateDefaultsA(
  252. LPCSTR lpszTracing,
  253. PHKEY phkeyTracing
  254. );
  255. DWORD
  256. TraceOpenClientConsoleA(
  257. LPTRACE_SERVER lpserver,
  258. LPTRACE_CLIENT lpclient
  259. );
  260. DWORD
  261. TraceCloseClientConsoleA(
  262. LPTRACE_SERVER lpserver,
  263. LPTRACE_CLIENT lpclient
  264. );
  265. DWORD
  266. TraceCreateClientFileA(
  267. LPTRACE_CLIENT lpclient
  268. );
  269. DWORD
  270. TraceMoveClientFileA(
  271. LPTRACE_CLIENT lpclient
  272. );
  273. DWORD
  274. TraceCloseClientFileA(
  275. LPTRACE_CLIENT lpclient
  276. );
  277. DWORD
  278. TraceWriteOutputA(
  279. LPTRACE_SERVER lpserver,
  280. LPTRACE_CLIENT lpclient,
  281. DWORD dwFlags,
  282. LPCSTR lpszOutput
  283. );
  284. DWORD
  285. TraceUpdateConsoleTitleA(
  286. LPTRACE_CLIENT lpclient
  287. );
  288. DWORD
  289. TraceDumpLineA(
  290. LPTRACE_SERVER lpserver,
  291. LPTRACE_CLIENT lpclient,
  292. DWORD dwFlags,
  293. LPBYTE lpbBytes,
  294. DWORD dwLine,
  295. DWORD dwGroup,
  296. BOOL bPrefixAddr,
  297. LPBYTE lpbPrefix,
  298. LPCSTR lpszPrefix
  299. );
  300. DWORD
  301. TraceVprintfInternalA(
  302. DWORD dwTraceID,
  303. DWORD dwFlags,
  304. LPCSTR lpszFormat,
  305. va_list arglist
  306. );
  307. //
  308. // Unicode declarations
  309. //
  310. LPTRACE_CLIENT
  311. TraceFindClientW(
  312. LPTRACE_SERVER lpserver,
  313. LPCWSTR lpszClient
  314. );
  315. DWORD
  316. TraceCreateClientW(
  317. LPTRACE_CLIENT *lplpentry
  318. );
  319. DWORD
  320. TraceDeleteClientW(
  321. LPTRACE_SERVER lpserver,
  322. LPTRACE_CLIENT *lplpentry
  323. );
  324. DWORD
  325. TraceEnableClientW(
  326. LPTRACE_SERVER lpserver,
  327. LPTRACE_CLIENT lpclient,
  328. BOOL bFirstTime
  329. );
  330. DWORD
  331. TraceDisableClientW(
  332. LPTRACE_SERVER lpserver,
  333. LPTRACE_CLIENT lpclient
  334. );
  335. DWORD
  336. TraceRegConfigClientW(
  337. LPTRACE_CLIENT lpclient,
  338. BOOL bFirstTime
  339. );
  340. DWORD
  341. TraceRegCreateDefaultsW(
  342. LPCWSTR lpszTracing,
  343. PHKEY phkeyTracing
  344. );
  345. DWORD
  346. TraceOpenClientConsoleW(
  347. LPTRACE_SERVER lpserver,
  348. LPTRACE_CLIENT lpclient
  349. );
  350. DWORD
  351. TraceCloseClientConsoleW(
  352. LPTRACE_SERVER lpserver,
  353. LPTRACE_CLIENT lpclient
  354. );
  355. DWORD
  356. TraceCreateClientFileW(
  357. LPTRACE_CLIENT lpclient
  358. );
  359. DWORD
  360. TraceMoveClientFileW(
  361. LPTRACE_CLIENT lpclient
  362. );
  363. DWORD
  364. TraceCloseClientFileW(
  365. LPTRACE_CLIENT lpclient
  366. );
  367. DWORD
  368. TraceWriteOutputW(
  369. LPTRACE_SERVER lpserver,
  370. LPTRACE_CLIENT lpclient,
  371. DWORD dwFlags,
  372. LPCWSTR lpszOutput
  373. );
  374. DWORD
  375. TraceUpdateConsoleTitleW(
  376. LPTRACE_CLIENT lpclient
  377. );
  378. DWORD
  379. TraceDumpLineW(
  380. LPTRACE_SERVER lpserver,
  381. LPTRACE_CLIENT lpclient,
  382. DWORD dwFlags,
  383. LPBYTE lpbBytes,
  384. DWORD dwLine,
  385. DWORD dwGroup,
  386. BOOL bPrefixAddr,
  387. LPBYTE lpbPrefix,
  388. LPCWSTR lpszPrefix
  389. );
  390. DWORD
  391. TraceVprintfInternalW(
  392. DWORD dwTraceID,
  393. DWORD dwFlags,
  394. LPCWSTR lpszFormat,
  395. va_list arglist
  396. );
  397. //
  398. // code-page independent macro definitions
  399. //
  400. #ifdef UNICODE
  401. #define TraceFindClient TraceFindClientW
  402. #define TraceCreateClient TraceCreateClientW
  403. #define TraceDeleteClient TraceDeleteClientW
  404. #define TraceEnableClient TraceEnableClientW
  405. #define TraceDisableClient TraceDisableClientW
  406. #define TraceRegConfigClient TraceRegConfigClientW
  407. #define TraceRegCreateDefaults TraceRegCreateDefaultsW
  408. #define TraceOpenClientConsole TraceOpenClientConsoleW
  409. #define TraceCloseClientConsole TraceCloseClientConsoleW
  410. #define TraceCreateClientFile TraceCreateClientFileW
  411. #define TraceMoveClientFile TraceMoveClientFileW
  412. #define TraceCloseClientFile TraceCloseClientFileW
  413. #define TraceWriteOutput TraceWriteOutputW
  414. #define TraceUpdateConsoleTitle TraceUpdateConsoleTitleW
  415. #define TraceDumpLine TraceDumpLineW
  416. #define TraceVprintfInternal TraceVprintfInternalW
  417. #else
  418. #define TraceFindClient TraceFindClientA
  419. #define TraceCreateClient TraceCreateClientA
  420. #define TraceDeleteClient TraceDeleteClientA
  421. #define TraceEnableClient TraceEnableClientA
  422. #define TraceDisableClient TraceDisableClientA
  423. #define TraceRegConfigClient TraceRegConfigClientA
  424. #define TraceRegCreateDefaults TraceRegCreateDefaultsA
  425. #define TraceOpenClientConsole TraceOpenClientConsoleA
  426. #define TraceCloseClientConsole TraceCloseClientConsoleA
  427. #define TraceCreateClientFile TraceCreateClientFileA
  428. #define TraceMoveClientFile TraceMoveClientFileA
  429. #define TraceCloseClientFile TraceCloseClientFileA
  430. #define TraceWriteOutput TraceWriteOutputA
  431. #define TraceUpdateConsoleTitle TraceUpdateConsoleTitleA
  432. #define TraceDumpLine TraceDumpLineA
  433. #define TraceVprintfInternal TraceVprintfInternalA
  434. #endif
  435. // global data declarations
  436. //
  437. extern LPTRACE_SERVER g_server;
  438. extern HANDLE g_serverThread;
  439. #endif // _TRACE_H_