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.

1022 lines
31 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. pudebug.h
  5. Abstract:
  6. This module declares the DEBUG_PRINTS object helpful in
  7. testing the programs
  8. Author:
  9. Murali R. Krishnan ( MuraliK ) 14-Dec-1994
  10. Modified to include a and other functions ( 22-Dec-1994)
  11. Revision History:
  12. MuraliK 16-May-1995 Added function to read debug flags.
  13. MuraliK 12-Sept-1996 Added functions to dump the output.
  14. JasAndre Dec-1998 Replaced tracing mechanism with WMI Eventing
  15. --*/
  16. # ifndef _PUDEBUG_H_
  17. # define _PUDEBUG_H_
  18. /************************************************************
  19. * Include Headers
  20. ************************************************************/
  21. # include <windows.h>
  22. # ifdef __cplusplus
  23. extern "C" {
  24. # endif // __cplusplus
  25. #ifndef _NO_TRACING_
  26. #include <wmistr.h>
  27. #include <evntrace.h>
  28. #endif
  29. # ifndef dllexp
  30. # define dllexp __declspec( dllexport)
  31. # endif // dllexp
  32. /***********************************************************
  33. * Macros
  34. ************************************************************/
  35. #ifdef _NO_TRACING_
  36. enum PRINT_REASONS {
  37. PrintNone = 0x0, // Nothing to be printed
  38. PrintError = 0x1, // An error message
  39. PrintWarning = 0x2, // A warning message
  40. PrintLog = 0x3, // Just logging. Indicates a trace of where ...
  41. PrintMsg = 0x4, // Echo input message
  42. PrintCritical = 0x5, // Print and Exit
  43. PrintAssertion= 0x6 // Printing for an assertion failure
  44. };
  45. enum DEBUG_OUTPUT_FLAGS {
  46. DbgOutputNone = 0x0, // None
  47. DbgOutputKdb = 0x1, // Output to Kernel Debugger
  48. DbgOutputLogFile = 0x2, // Output to LogFile
  49. DbgOutputTruncate = 0x4, // Truncate Log File if necessary
  50. DbgOutputStderr = 0x8, // Send output to std error
  51. DbgOutputBackup = 0x10, // Make backup of debug file ?
  52. DbgOutputAll = 0xFFFFFFFF // All the bits set.
  53. };
  54. #endif // _NO_TRACING_
  55. # define MAX_LABEL_LENGTH ( 100)
  56. // The WINNT defined tests are required so that the ui\setup\osrc project still
  57. // compiles
  58. #if !defined(_NO_TRACING_) && (defined(_WINNT_) || defined(WINNT))
  59. #define REG_TRACE_IIS TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Tracing\\IIS")
  60. #define REG_TRACE_IIS_ENABLED TEXT("EnableTracing")
  61. #define REG_TRACE_IIS_ODS TEXT("AlwaysODS")
  62. #define REG_TRACE_IIS_LOG_FILE_NAME TEXT("LogFileName")
  63. #define REG_TRACE_IIS_LOG_SESSION_NAME TEXT("LogSessionName")
  64. #define REG_TRACE_IIS_LOG_BUFFER_SIZE TEXT("BufferSize")
  65. #define REG_TRACE_IIS_LOG_MIN_BUFFERS TEXT("MinBuffers")
  66. #define REG_TRACE_IIS_LOG_MAX_BUFFERS TEXT("MaxBuffers")
  67. #define REG_TRACE_IIS_LOG_MAX_FILESIZE TEXT("MaxFileSize")
  68. #define REG_TRACE_IIS_LOG_REAL_TIME TEXT("EnableRealTimeMode")
  69. #define REG_TRACE_IIS_LOG_IN_MEMORY TEXT("EnableInMemoryMode")
  70. #define REG_TRACE_IIS_LOG_USER_MODE TEXT("EnableUserMode")
  71. #define REG_TRACE_IIS_ACTIVE TEXT("Active")
  72. #define REG_TRACE_IIS_CONTROL TEXT("ControlFlags")
  73. #define REG_TRACE_IIS_LEVEL TEXT("Level")
  74. #define REG_TRACE_IIS_GUID L"Guid"
  75. // Structure used to send trace information to the WMI eventing mechanism
  76. typedef struct _TRACE_INFO
  77. {
  78. EVENT_TRACE_HEADER TraceHeader; // WMI Event header required at start of trace info
  79. MOF_FIELD MofFields[5]; // Trace info. A MOF_FIELD is a {pointer, size} pair
  80. } TRACE_INFO, *PTRACE_INFO;
  81. /*++
  82. class DEBUG_PRINTS
  83. This class is responsible for printing messages to log file / kernel debugger
  84. Currently the class supports only member functions for <ANSI> char.
  85. ( not unicode-strings).
  86. --*/
  87. typedef struct _DEBUG_PRINTS {
  88. CHAR m_rgchLabel[MAX_LABEL_LENGTH]; // Name of the module
  89. BOOL m_bBreakOnAssert; // Control flag for DBG_ASSERT
  90. GUID m_guidControl; // Identifying GUID for the module
  91. int m_iControlFlag; // Control flag used for IF_DEBUG macros
  92. int *m_piErrorFlags; // Bit mapped error flag used for DBGINFO etc macros
  93. TRACEHANDLE m_hRegistration; // WMI identifying handle for the module
  94. TRACEHANDLE m_hLogger; // WMI logfile handle for the module
  95. } DEBUG_PRINTS, *LPDEBUG_PRINTS;
  96. // Structure used by IISRTL to maintain the list of GUID's that can be
  97. // registered with the WMI eventing system
  98. typedef struct _SGuidList {
  99. enum {
  100. TRACESIG = (('T') | ('R' << 8) | ('C' << 16) | ('$' << 24)),
  101. } dwSig;
  102. LIST_ENTRY m_leEntry;
  103. DEBUG_PRINTS m_dpData;
  104. int m_iDefaultErrorLevel;
  105. int m_iInitializeFlags;
  106. } SGuidList, *PSGuidList;
  107. #else // _NO_TRACING_
  108. typedef struct _DEBUG_PRINTS {
  109. CHAR m_rgchLabel[MAX_LABEL_LENGTH];
  110. CHAR m_rgchLogFilePath[MAX_PATH];
  111. CHAR m_rgchLogFileName[MAX_PATH];
  112. HANDLE m_LogFileHandle;
  113. HANDLE m_StdErrHandle;
  114. BOOL m_fInitialized;
  115. DWORD m_dwOutputFlags;
  116. BOOL m_fBreakOnAssert;
  117. } DEBUG_PRINTS, FAR * LPDEBUG_PRINTS;
  118. #endif // _NO_TRACING_
  119. // The WINNT defined tests are required so that the ui\setup\osrc project still
  120. // compiles
  121. #if !defined(_NO_TRACING_) && (defined(_WINNT_) || defined(WINNT))
  122. dllexp VOID
  123. PuInitiateDebug(VOID);
  124. dllexp VOID
  125. PuUninitiateDebug(VOID);
  126. LPDEBUG_PRINTS
  127. PuCreateDebugPrintsObject(
  128. IN const char * pszPrintLabel,
  129. IN GUID * ControlGuid,
  130. IN int * ErrorFlags,
  131. IN int DefaultControlFlags);
  132. //
  133. // frees the debug prints object and closes any file if necessary.
  134. // Returns NULL on success or returns pDebugPrints on failure.
  135. //
  136. VOID
  137. PuDeleteDebugPrintsObject(
  138. IN OUT LPDEBUG_PRINTS pDebugPrints
  139. );
  140. VOID
  141. PuDbgPrint(
  142. IN OUT LPDEBUG_PRINTS pDebugPrints,
  143. IN const char * pszFilePath,
  144. IN int nLineNum,
  145. IN const char * pszFormat,
  146. ...); // arglist
  147. dllexp VOID
  148. PuDbgPrintW(
  149. IN OUT LPDEBUG_PRINTS pDebugPrints,
  150. IN const char * pszFilePath,
  151. IN int nLineNum,
  152. IN const WCHAR * pszFormat,
  153. ...); // arglist
  154. /*++
  155. PuDbgDump() does not do any formatting of output.
  156. It just dumps the given message onto the debug destinations.
  157. --*/
  158. VOID
  159. PuDbgDump(
  160. IN OUT LPDEBUG_PRINTS pDebugPrints,
  161. IN const char * pszFilePath,
  162. IN int nLineNum,
  163. IN const char * pszDump
  164. );
  165. dllexp VOID
  166. PuDbgDumpW(
  167. IN OUT LPDEBUG_PRINTS pDebugPrints,
  168. IN const char * pszFilePath,
  169. IN int nLineNum,
  170. IN const WCHAR * pszDump
  171. );
  172. //
  173. // PuDbgAssertFailed() *must* be __cdecl to properly capture the
  174. // thread context at the time of the failure.
  175. //
  176. VOID
  177. __cdecl
  178. PuDbgAssertFailed(
  179. IN OUT LPDEBUG_PRINTS pDebugPrints,
  180. IN const char * pszFilePath,
  181. IN int nLineNum,
  182. IN const char * pszExpression);
  183. VOID
  184. PuDbgCaptureContext (
  185. OUT PCONTEXT ContextRecord
  186. );
  187. #else // _NO_TRACING_
  188. LPDEBUG_PRINTS
  189. PuCreateDebugPrintsObject(
  190. IN const char * pszPrintLabel,
  191. IN DWORD dwOutputFlags);
  192. //
  193. // frees the debug prints object and closes any file if necessary.
  194. // Returns NULL on success or returns pDebugPrints on failure.
  195. //
  196. LPDEBUG_PRINTS
  197. PuDeleteDebugPrintsObject(
  198. IN OUT LPDEBUG_PRINTS pDebugPrints);
  199. VOID
  200. PuDbgPrint(
  201. IN OUT LPDEBUG_PRINTS pDebugPrints,
  202. IN const char * pszFilePath,
  203. IN int nLineNum,
  204. IN const char * pszFormat,
  205. ...); // arglist
  206. /*++
  207. PuDbgDump() does not do any formatting of output.
  208. It just dumps the given message onto the debug destinations.
  209. --*/
  210. VOID
  211. PuDbgDump(
  212. IN OUT LPDEBUG_PRINTS pDebugPrints,
  213. IN const char * pszFilePath,
  214. IN int nLineNum,
  215. IN const char * pszDump
  216. );
  217. //
  218. // PuDbgAssertFailed() *must* be __cdecl to properly capture the
  219. // thread context at the time of the failure.
  220. //
  221. VOID
  222. __cdecl
  223. PuDbgAssertFailed(
  224. IN OUT LPDEBUG_PRINTS pDebugPrints,
  225. IN const char * pszFilePath,
  226. IN int nLineNum,
  227. IN const char * pszExpression,
  228. IN const char * pszMessage);
  229. VOID
  230. PuDbgCaptureContext (
  231. OUT PCONTEXT ContextRecord
  232. );
  233. dllexp
  234. VOID
  235. PuDbgPrintCurrentTime(
  236. IN OUT LPDEBUG_PRINTS pDebugPrints,
  237. IN const char * pszFilePath,
  238. IN int nLineNum
  239. );
  240. dllexp
  241. VOID
  242. PuSetDbgOutputFlags(
  243. IN OUT LPDEBUG_PRINTS pDebugPrints,
  244. IN DWORD dwFlags);
  245. dllexp
  246. DWORD
  247. PuGetDbgOutputFlags(
  248. IN const LPDEBUG_PRINTS pDebugPrints);
  249. //
  250. // Following functions return Win32 error codes.
  251. // NO_ERROR if success
  252. //
  253. dllexp
  254. DWORD
  255. PuOpenDbgPrintFile(
  256. IN OUT LPDEBUG_PRINTS pDebugPrints,
  257. IN const char * pszFileName,
  258. IN const char * pszPathForFile);
  259. dllexp
  260. DWORD
  261. PuReOpenDbgPrintFile(
  262. IN OUT LPDEBUG_PRINTS pDebugPrints);
  263. dllexp
  264. DWORD
  265. PuCloseDbgPrintFile(
  266. IN OUT LPDEBUG_PRINTS pDebugPrints);
  267. dllexp
  268. DWORD
  269. PuLoadDebugFlagsFromReg(IN HKEY hkey, IN DWORD dwDefault, IN LPDEBUG_PRINTS pDebugPrints);
  270. dllexp
  271. DWORD
  272. PuLoadDebugFlagsFromRegStr(IN LPCSTR pszRegKey, IN DWORD dwDefault, IN LPDEBUG_PRINTS pDebugPrints);
  273. dllexp
  274. DWORD
  275. PuSaveDebugFlagsInReg(IN HKEY hkey, IN DWORD dwDbg);
  276. # define PuPrintToKdb( pszOutput) \
  277. if ( pszOutput != NULL) { \
  278. OutputDebugString( pszOutput); \
  279. } else {}
  280. #endif // _NO_TRACING_
  281. # ifdef __cplusplus
  282. };
  283. # endif // __cplusplus
  284. // begin_user_unmodifiable
  285. // The WINNT defined tests are required so that the ui\setup\osrc project still
  286. // compiles
  287. #if !defined(_NO_TRACING_) && (defined(_WINNT_) || defined(WINNT))
  288. // The following enumerations are the values supplied by the user to select
  289. // a particular logging level
  290. #define DEBUG_LEVEL_INFO 3
  291. #define DEBUG_LEVEL_WARN 2
  292. #define DEBUG_LEVEL_ERROR 1
  293. // The following flags are used internally to track what level of tracing we
  294. // are currently using. Bitmapped for extensibility.
  295. #define DEBUG_FLAG_ODS 0x00000001
  296. #define DEBUG_FLAG_INFO 0x00000002
  297. #define DEBUG_FLAG_WARN 0x00000004
  298. #define DEBUG_FLAG_ERROR 0x00000008
  299. // The top 8 bits are reserved for control fields, sometimes we need to mask
  300. // these out
  301. #define DEBUG_FLAG_LEVEL_MASK (DEBUG_FLAG_ODS | DEBUG_FLAG_INFO | DEBUG_FLAG_WARN | DEBUG_FLAG_ERROR)
  302. // Deferred means that we have initialized with WMI but not actually loaded the
  303. // module yet, so save the state for later
  304. #define DEBUG_FLAG_DEFERRED_START 0x4000000
  305. // Initialize means that we want to register this with WMI when we start up
  306. #define DEBUG_FLAG_INITIALIZE 0x8000000
  307. // The following are used internally to determine whether to log or not based
  308. // on what the current state is
  309. #define DEBUG_FLAGS_INFO (DEBUG_FLAG_ODS | DEBUG_FLAG_INFO)
  310. #define DEBUG_FLAGS_WARN (DEBUG_FLAG_ODS | DEBUG_FLAG_INFO | DEBUG_FLAG_WARN)
  311. #define DEBUG_FLAGS_ERROR (DEBUG_FLAG_ODS | DEBUG_FLAG_INFO | DEBUG_FLAG_WARN | DEBUG_FLAG_ERROR)
  312. #define DEBUG_FLAGS_ANY (DEBUG_FLAG_INFO | DEBUG_FLAG_WARN | DEBUG_FLAG_ERROR)
  313. extern
  314. #ifdef __cplusplus
  315. "C"
  316. # endif // _cplusplus
  317. DEBUG_PRINTS *g_pDebug; // define a global debug variable
  318. extern
  319. #ifdef __cplusplus
  320. "C"
  321. # endif // _cplusplus
  322. int g_fErrorFlags; // define a global error level variable
  323. # if DBG
  324. // For the CHK build we want ODS enabled. For an explanation of these flags see
  325. // the comment just after the definition of DBG_CONTEXT
  326. # define DECLARE_DEBUG_PRINTS_OBJECT() \
  327. DEBUG_PRINTS * g_pDebug = NULL; \
  328. int g_fErrorFlags = DEBUG_FLAG_ODS;
  329. #else // !DBG
  330. # define DECLARE_DEBUG_PRINTS_OBJECT() \
  331. DEBUG_PRINTS * g_pDebug = NULL; \
  332. int g_fErrorFlags = 0;
  333. #endif // !DBG
  334. // The DEFAULT_TRACE_FLAGS is used in the CREATE_DEBUG macros to set the start
  335. // up state for the control flags, m_iControlFlag, used in the IF_DEBUG macros.
  336. // This define is added for the cases where there are no default flags.
  337. # ifndef DEFAULT_TRACE_FLAGS
  338. # define DEFAULT_TRACE_FLAGS 0
  339. # endif
  340. //
  341. // Call the following macro only from the main of you executable, or COM object.
  342. // The aim is to have this called only once per process so at the moment that
  343. // means in Inetinfo, WAM and a few EXE files
  344. //
  345. # define CREATE_INITIALIZE_DEBUG() \
  346. PuInitiateDebug();
  347. //
  348. // Call the following macro only from the main of you executable, or COM object.
  349. // This must called only once per process so at the last possible moment that
  350. // means in Inetinfo, WAM and a few EXE files. Its job is to test to see if a
  351. // trace file was created in the initiate and if so shut it down now
  352. //
  353. # define DELETE_INITIALIZE_DEBUG() \
  354. PuUninitiateDebug();
  355. //
  356. // Call the following macro as a normal part of your initialization for programs
  357. // planning to use the debugging class. This should be done inside the
  358. // PROCESS_ATTTACH for most DLL's and COM objects
  359. //
  360. # define CREATE_DEBUG_PRINT_OBJECT( pszLabel, ControlGuid) \
  361. { \
  362. g_pDebug = PuCreateDebugPrintsObject(pszLabel, (LPGUID) &ControlGuid, &g_fErrorFlags, DEFAULT_TRACE_FLAGS);\
  363. }
  364. //
  365. // Call the following macro once as part of the termination of programs
  366. // which uses the debugging class.
  367. //
  368. # define DELETE_DEBUG_PRINT_OBJECT( ) \
  369. { \
  370. PuDeleteDebugPrintsObject(g_pDebug); \
  371. g_pDebug = NULL; \
  372. }
  373. # define VALID_DEBUG_PRINT_OBJECT() \
  374. (NULL != g_pDebug)
  375. //
  376. // Use the DBG_CONTEXT without any surrounding braces.
  377. // This is used to pass the values for global DebugPrintObject
  378. // and File/Line information
  379. //
  380. # define DBG_CONTEXT g_pDebug, __FILE__, __LINE__
  381. // The 3 main tracing macros, each one corresponds to a different level of
  382. // tracing
  383. # define DBGINFO(args) {if (g_fErrorFlags & DEBUG_FLAGS_INFO) { PuDbgPrint args; }}
  384. # define DBGWARN(args) {if (g_fErrorFlags & DEBUG_FLAGS_WARN) { PuDbgPrint args; }}
  385. # define DBGERROR(args) {if (g_fErrorFlags & DEBUG_FLAGS_ERROR) { PuDbgPrint args; }}
  386. # define DBGINFOW(args) {if (g_fErrorFlags & DEBUG_FLAGS_INFO) { PuDbgPrintW args; }}
  387. # define DBGWARNW(args) {if (g_fErrorFlags & DEBUG_FLAGS_WARN) { PuDbgPrintW args; }}
  388. # define DBGERRORW(args) {if (g_fErrorFlags & DEBUG_FLAGS_ERROR) { PuDbgPrintW args; }}
  389. # if DBG
  390. # define DBG_CODE(s) s /* echoes code in debugging mode */
  391. // The same 3 main tracing macros however in this case the macros are only compiled
  392. // into the CHK build. This is necessary because some tracing info used functions or
  393. // variables which are not compiled into the FRE build.
  394. # define CHKINFO(args) {if (g_fErrorFlags & DEBUG_FLAGS_INFO) { PuDbgPrint args; }}
  395. # define CHKWARN(args) {if (g_fErrorFlags & DEBUG_FLAGS_WARN) { PuDbgPrint args; }}
  396. # define CHKERROR(args) {if (g_fErrorFlags & DEBUG_FLAGS_ERROR) { PuDbgPrint args; }}
  397. # define CHKINFOW(args) {if (g_fErrorFlags & DEBUG_FLAGS_INFO) { PuDbgPrintW args; }}
  398. # define CHKWARNW(args) {if (g_fErrorFlags & DEBUG_FLAGS_WARN) { PuDbgPrintW args; }}
  399. # define CHKERRORW(args) {if (g_fErrorFlags & DEBUG_FLAGS_ERROR) { PuDbgPrintW args; }}
  400. # define DBG_ASSERT( exp) if ( !(exp)) { \
  401. PuDbgAssertFailed( DBG_CONTEXT, #exp); \
  402. } else {}
  403. # define DBG_REQUIRE( exp) DBG_ASSERT( exp)
  404. # else // !DBG
  405. # define DBG_CODE(s) ((void)0) /* Do Nothing */
  406. # define CHKINFO(args) ((void)0) /* Do Nothing */
  407. # define CHKWARN(args) ((void)0) /* Do Nothing */
  408. # define CHKERROR(args) ((void)0) /* Do Nothing */
  409. # define CHKINFOW(args) ((void)0) /* Do Nothing */
  410. # define CHKWARNW(args) ((void)0) /* Do Nothing */
  411. # define CHKERRORW(args) ((void)0) /* Do Nothing */
  412. # define DBG_ASSERT(exp) ((void)0) /* Do Nothing */
  413. # define DBG_REQUIRE( exp) ((void) (exp))
  414. # endif // !DBG
  415. //
  416. // DBGPRINTF() is printing function ( much like printf) but always called
  417. // with the DBG_CONTEXT as follows
  418. // DBGPRINTF( ( DBG_CONTEXT, format-string, arguments for format list);
  419. //
  420. # define DBGPRINTF DBGINFO
  421. # define DBGDUMP(args) PuDbgDump args
  422. # define DBGDUMPW(args) PuDbgDumpW args
  423. #else // _NO_TRACING_
  424. // Map the new debugging macros to DBGPRINTF so that we can make modifications
  425. // to the code which still compile in both the tracing and no-tracing versions.
  426. // Unfortunately there is no equivalent of the unicode versions so map them to
  427. // nothing
  428. # define DBGINFO DBGPRINTF
  429. # define DBGWARN DBGPRINTF
  430. # define DBGERROR DBGPRINTF
  431. # define DBGINFOW(args) ((void)0) /* Do Nothing */
  432. # define DBGWARNW(args) ((void)0) /* Do Nothing */
  433. # define DBGERRORW(args) ((void)0) /* Do Nothing */
  434. # define DBGDUMPW(args) ((void)0) /* Do Nothing */
  435. # if DBG
  436. /***********************************************************
  437. * Macros
  438. ************************************************************/
  439. extern
  440. #ifdef __cplusplus
  441. "C"
  442. # endif // _cplusplus
  443. DEBUG_PRINTS * g_pDebug; // define a global debug variable
  444. # define DECLARE_DEBUG_PRINTS_OBJECT() \
  445. DEBUG_PRINTS * g_pDebug = NULL; \
  446. int g_fErrorFlags = 0;
  447. //
  448. // Call the following macro as part of your initialization for program
  449. // planning to use the debugging class.
  450. //
  451. # define CREATE_DEBUG_PRINT_OBJECT( pszLabel) \
  452. g_pDebug = PuCreateDebugPrintsObject( pszLabel, DEFAULT_OUTPUT_FLAGS);\
  453. if ( g_pDebug == NULL) { \
  454. OutputDebugStringA( "Unable to Create Debug Print Object \n"); \
  455. }
  456. //
  457. // Call the following macro once as part of the termination of program
  458. // which uses the debugging class.
  459. //
  460. # define DELETE_DEBUG_PRINT_OBJECT( ) \
  461. g_pDebug = PuDeleteDebugPrintsObject( g_pDebug);
  462. # define VALID_DEBUG_PRINT_OBJECT() \
  463. ( ( g_pDebug != NULL) && g_pDebug->m_fInitialized)
  464. //
  465. // Use the DBG_CONTEXT without any surrounding braces.
  466. // This is used to pass the values for global DebugPrintObject
  467. // and File/Line information
  468. //
  469. # define DBG_CONTEXT g_pDebug, __FILE__, __LINE__
  470. # define DBG_CODE(s) s /* echoes code in debugging mode */
  471. # define DBG_ASSERT( exp) if ( !(exp)) { \
  472. PuDbgAssertFailed( DBG_CONTEXT, #exp, NULL); \
  473. } else {}
  474. # define DBG_ASSERT_MSG( exp, pszMsg) \
  475. if ( !(exp)) { \
  476. PuDbgAssertFailed( DBG_CONTEXT, #exp, pszMsg); \
  477. } else {}
  478. # define DBG_REQUIRE( exp) DBG_ASSERT( exp)
  479. # define DBG_LOG() PuDbgPrint( DBG_CONTEXT, "\n")
  480. # define DBG_OPEN_LOG_FILE( pszFile, pszPath) \
  481. PuOpenDbgPrintFile( g_pDebug, (pszFile), (pszPath))
  482. # define DBG_CLOSE_LOG_FILE( ) \
  483. PuCloseDbgPrintFile( g_pDebug)
  484. //
  485. // DBGPRINTF() is printing function ( much like printf) but always called
  486. // with the DBG_CONTEXT as follows
  487. // DBGPRINTF( ( DBG_CONTEXT, format-string, arguments for format list);
  488. //
  489. # define DBGPRINTF( args) PuDbgPrint args
  490. # define DBGDUMP( args) PuDbgDump args
  491. # define DBGPRINT_CURRENT_TIME() PuDbgPrintCurrentTime( DBG_CONTEXT)
  492. # else // !DBG
  493. # define DECLARE_DEBUG_PRINTS_OBJECT() /* Do Nothing */
  494. # define CREATE_DEBUG_PRINT_OBJECT( pszLabel) ((void)0) /* Do Nothing */
  495. # define DELETE_DEBUG_PRINT_OBJECT( ) ((void)0) /* Do Nothing */
  496. # define VALID_DEBUG_PRINT_OBJECT() ( TRUE)
  497. # define DBG_CODE(s) ((void)0) /* Do Nothing */
  498. # define DBG_ASSERT(exp) ((void)0) /* Do Nothing */
  499. # define DBG_ASSERT_MSG(exp, pszMsg) ((void)0) /* Do Nothing */
  500. # define DBG_REQUIRE( exp) ( (void) (exp))
  501. # define DBGPRINTF( args) ((void)0) /* Do Nothing */
  502. # define DBGDUMP( args) ((void)0) /* Do nothing */
  503. # define DBG_LOG() ((void)0) /* Do Nothing */
  504. # define DBG_OPEN_LOG_FILE( pszFile, pszPath) ((void)0) /* Do Nothing */
  505. # define DBG_CLOSE_LOG_FILE() ((void)0) /* Do Nothing */
  506. # define DBGPRINT_CURRENT_TIME() ((void)0) /* Do Nothing */
  507. # endif // !DBG
  508. # endif // _NO_TRACING_
  509. // end_user_unmodifiable
  510. // begin_user_unmodifiable
  511. #ifdef ASSERT
  512. # undef ASSERT
  513. #endif
  514. # define ASSERT( exp) DBG_ASSERT( exp)
  515. // The WINNT defined tests are required so that the ui\setup\osrc project still
  516. // compiles
  517. #if !defined(_NO_TRACING_) && (defined(_WINNT_) || defined(WINNT))
  518. # define GET_DEBUG_FLAGS() ( g_pDebug ? g_pDebug->m_iControlFlag : 0)
  519. # define DEBUG_IF( arg, s) if ( DEBUG_ ## arg & GET_DEBUG_FLAGS()) { \
  520. s \
  521. } else {}
  522. # define IF_DEBUG( arg) if ( DEBUG_## arg & GET_DEBUG_FLAGS())
  523. # if DBG
  524. # define CHKDEBUG_IF( arg, s) if ( DEBUG_ ## arg & GET_DEBUG_FLAGS()) { \
  525. s \
  526. } else {}
  527. # define IF_CHKDEBUG( arg) if ( DEBUG_## arg & GET_DEBUG_FLAGS())
  528. # else // !DBG
  529. # define CHKDEBUG_IF( arg, s) /* Do Nothing */
  530. # define IF_CHKDEBUG( arg) if ( 0)
  531. # endif // !DBG
  532. # else // !_NO_TRACING_
  533. # if DBG
  534. extern
  535. #ifdef __cplusplus
  536. "C"
  537. # endif // _cplusplus
  538. DWORD g_dwDebugFlags; // Debugging Flags
  539. # define DECLARE_DEBUG_VARIABLE() \
  540. DWORD g_dwDebugFlags;
  541. # define SET_DEBUG_FLAGS( dwFlags) g_dwDebugFlags = dwFlags
  542. # define GET_DEBUG_FLAGS() ( g_dwDebugFlags)
  543. # define LOAD_DEBUG_FLAGS_FROM_REG(hkey, dwDefault) \
  544. g_dwDebugFlags = PuLoadDebugFlagsFromReg((hkey), (dwDefault), g_pDebug)
  545. # define LOAD_DEBUG_FLAGS_FROM_REG_STR(pszRegKey, dwDefault) \
  546. g_dwDebugFlags = PuLoadDebugFlagsFromRegStr((pszRegKey), (dwDefault), g_pDebug)
  547. # define SAVE_DEBUG_FLAGS_IN_REG(hkey, dwDbg) \
  548. PuSaveDebugFlagsInReg((hkey), (dwDbg))
  549. # define DEBUG_IF( arg, s) if ( DEBUG_ ## arg & GET_DEBUG_FLAGS()) { \
  550. s \
  551. } else {}
  552. # define IF_DEBUG( arg) if ( DEBUG_## arg & GET_DEBUG_FLAGS())
  553. # else // !DBG
  554. # define DECLARE_DEBUG_VARIABLE() /* Do Nothing */
  555. # define SET_DEBUG_FLAGS( dwFlags) /* Do Nothing */
  556. # define GET_DEBUG_FLAGS() ( 0)
  557. # define LOAD_DEBUG_FLAGS_FROM_REG(hkey, dwDefault) /* Do Nothing */
  558. # define LOAD_DEBUG_FLAGS_FROM_REG_STR(pszRegKey, dwDefault) /* Do Nothing */
  559. # define SAVE_DEBUG_FLAGS_IN_REG(hkey, dwDbg) /* Do Nothing */
  560. # define DEBUG_IF( arg, s) /* Do Nothing */
  561. # define IF_DEBUG( arg) if ( 0)
  562. # endif // !DBG
  563. # endif // !_NO_TRACING_
  564. // end_user_unmodifiable
  565. // begin_user_modifiable
  566. //
  567. // Debugging constants consist of two pieces.
  568. // All constants in the range 0x0 to 0x8000 are reserved
  569. // User extensions may include additional constants (bit flags)
  570. //
  571. # define DEBUG_API_ENTRY 0x00000001L
  572. # define DEBUG_API_EXIT 0x00000002L
  573. # define DEBUG_INIT_CLEAN 0x00000004L
  574. # define DEBUG_ERROR 0x00000008L
  575. // End of Reserved Range
  576. # define DEBUG_RESERVED 0x00000FFFL
  577. // end_user_modifiable
  578. /***********************************************************
  579. * Platform Type related variables and macros
  580. ************************************************************/
  581. //
  582. // Enum for product types
  583. //
  584. typedef enum _PLATFORM_TYPE {
  585. PtInvalid = 0, // Invalid
  586. PtNtWorkstation = 1, // NT Workstation
  587. PtNtServer = 2, // NT Server
  588. PtWindows95 = 3, // Windows 95
  589. PtWindows9x = 4 // Windows 9x - not implemented
  590. } PLATFORM_TYPE;
  591. //
  592. // IISGetPlatformType is the function used to the platform type
  593. //
  594. extern
  595. #ifdef __cplusplus
  596. "C"
  597. # endif // _cplusplus
  598. PLATFORM_TYPE
  599. IISGetPlatformType(
  600. VOID
  601. );
  602. //
  603. // External Macros
  604. //
  605. #define InetIsNtServer( _pt ) ((_pt) == PtNtServer)
  606. #define InetIsNtWksta( _pt ) ((_pt) == PtNtWorkstation)
  607. #define InetIsWindows95( _pt ) ((_pt) == PtWindows95)
  608. #define InetIsValidPT(_pt) ((_pt) != PtInvalid)
  609. extern
  610. #ifdef __cplusplus
  611. "C"
  612. # endif // _cplusplus
  613. PLATFORM_TYPE g_PlatformType;
  614. // Use the DECLARE_PLATFORM_TYPE macro to declare the platform type
  615. #define DECLARE_PLATFORM_TYPE() \
  616. PLATFORM_TYPE g_PlatformType = PtInvalid;
  617. // Use the INITIALIZE_PLATFORM_TYPE to init the platform type
  618. // This should typically go inside the DLLInit or equivalent place.
  619. #define INITIALIZE_PLATFORM_TYPE() \
  620. g_PlatformType = IISGetPlatformType();
  621. //
  622. // Additional Macros to use the Platform Type
  623. //
  624. #define TsIsNtServer( ) InetIsNtServer(g_PlatformType)
  625. #define TsIsNtWksta( ) InetIsNtWksta(g_PlatformType)
  626. #define TsIsWindows95() InetIsWindows95(g_PlatformType)
  627. #define IISIsValidPlatform() InetIsValidPT(g_PlatformType)
  628. #define IISPlatformType() (g_PlatformType)
  629. /***********************************************************
  630. * Some utility functions for Critical Sections
  631. ************************************************************/
  632. //
  633. // IISSetCriticalSectionSpinCount() provides a thunk for the
  634. // original NT4.0sp3 API SetCriticalSectionSpinCount() for CS with Spin counts
  635. // Users of this function should definitely dynlink with kernel32.dll,
  636. // Otherwise errors will surface to a large extent
  637. //
  638. extern
  639. # ifdef __cplusplus
  640. "C"
  641. # endif // _cplusplus
  642. DWORD
  643. IISSetCriticalSectionSpinCount(
  644. LPCRITICAL_SECTION lpCriticalSection,
  645. DWORD dwSpinCount
  646. );
  647. //
  648. // Macro for the calls to SetCriticalSectionSpinCount()
  649. //
  650. # define SET_CRITICAL_SECTION_SPIN_COUNT( lpCS, dwSpins) \
  651. IISSetCriticalSectionSpinCount( (lpCS), (dwSpins))
  652. //
  653. // IIS_DEFAULT_CS_SPIN_COUNT is the default value of spins used by
  654. // Critical sections defined within IIS.
  655. // NYI: We should have to switch the individual values based on experiments!
  656. // Current value is an arbitrary choice
  657. //
  658. # define IIS_DEFAULT_CS_SPIN_COUNT (1000)
  659. //
  660. // Initializes a critical section and sets its spin count
  661. // to IIS_DEFAULT_CS_SPIN_COUNT. Equivalent to
  662. // InitializeCriticalSectionAndSpinCount(lpCS, IIS_DEFAULT_CS_SPIN_COUNT),
  663. // but provides a safe thunking layer for older systems that don't provide
  664. // this API.
  665. //
  666. extern
  667. # ifdef __cplusplus
  668. "C"
  669. # endif // _cplusplus
  670. VOID
  671. IISInitializeCriticalSection(
  672. LPCRITICAL_SECTION lpCriticalSection
  673. );
  674. //
  675. // Macro for the calls to InitializeCriticalSection()
  676. //
  677. # define INITIALIZE_CRITICAL_SECTION(lpCS) IISInitializeCriticalSection(lpCS)
  678. # endif /* _DEBUG_HXX_ */
  679. //
  680. // The following macros allow the automatic naming of certain Win32 objects.
  681. // See IIS\SVCS\IISRTL\WIN32OBJ.C for details on the naming convention.
  682. //
  683. // Set IIS_NAMED_WIN32_OBJECTS to a non-zero value to enable named events,
  684. // semaphores, and mutexes.
  685. //
  686. #if DBG
  687. #define IIS_NAMED_WIN32_OBJECTS 1
  688. #else
  689. #define IIS_NAMED_WIN32_OBJECTS 0
  690. #endif
  691. #ifdef __cplusplus
  692. extern "C" {
  693. #endif
  694. HANDLE
  695. PuDbgCreateEvent(
  696. IN LPSTR FileName,
  697. IN ULONG LineNumber,
  698. IN LPSTR MemberName,
  699. IN PVOID Address,
  700. IN BOOL ManualReset,
  701. IN BOOL InitialState
  702. );
  703. HANDLE
  704. PuDbgCreateSemaphore(
  705. IN LPSTR FileName,
  706. IN ULONG LineNumber,
  707. IN LPSTR MemberName,
  708. IN PVOID Address,
  709. IN LONG InitialCount,
  710. IN LONG MaximumCount
  711. );
  712. HANDLE
  713. PuDbgCreateMutex(
  714. IN LPSTR FileName,
  715. IN ULONG LineNumber,
  716. IN LPSTR MemberName,
  717. IN PVOID Address,
  718. IN BOOL InitialOwner
  719. );
  720. #ifdef __cplusplus
  721. } // extern "C"
  722. #endif
  723. #if IIS_NAMED_WIN32_OBJECTS
  724. #define IIS_CREATE_EVENT( membername, address, manual, state ) \
  725. PuDbgCreateEvent( \
  726. (LPSTR)__FILE__, \
  727. (ULONG)__LINE__, \
  728. (membername), \
  729. (PVOID)(address), \
  730. (manual), \
  731. (state) \
  732. )
  733. #define IIS_CREATE_SEMAPHORE( membername, address, initial, maximum ) \
  734. PuDbgCreateSemaphore( \
  735. (LPSTR)__FILE__, \
  736. (ULONG)__LINE__, \
  737. (membername), \
  738. (PVOID)(address), \
  739. (initial), \
  740. (maximum) \
  741. )
  742. #define IIS_CREATE_MUTEX( membername, address, initial ) \
  743. PuDbgCreateMutex( \
  744. (LPSTR)__FILE__, \
  745. (ULONG)__LINE__, \
  746. (membername), \
  747. (PVOID)(address), \
  748. (initial) \
  749. )
  750. #else // !IIS_NAMED_WIN32_OBJECTS
  751. #define IIS_CREATE_EVENT( membername, address, manual, state ) \
  752. CreateEventA( \
  753. NULL, \
  754. (manual), \
  755. (state), \
  756. NULL \
  757. )
  758. #define IIS_CREATE_SEMAPHORE( membername, address, initial, maximum ) \
  759. CreateSemaphoreA( \
  760. NULL, \
  761. (initial), \
  762. (maximum), \
  763. NULL \
  764. )
  765. #define IIS_CREATE_MUTEX( membername, address, initial ) \
  766. CreateMutexA( \
  767. NULL, \
  768. (initial), \
  769. NULL \
  770. )
  771. #endif // IIS_NAMED_WIN32_OBJECTS
  772. /************************ End of File ***********************/