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.

170 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1998-2001 Microsoft Corporation
  3. Module Name:
  4. reftrace.h
  5. Abstract:
  6. This module contains public declarations and definitions for tracing
  7. and debugging reference count problems. This module uses the generic
  8. TRACE_LOG facility in tracelog.h.
  9. The REF_ACTION_* codes are declared separately in refaction.h
  10. Author:
  11. Keith Moore (keithmo) 10-Jun-1998
  12. Revision History:
  13. --*/
  14. #ifndef _REFTRACE_H_
  15. #define _REFTRACE_H_
  16. #if defined(__cplusplus)
  17. extern "C" {
  18. #endif // __cplusplus
  19. //
  20. // Pull in the action codes
  21. //
  22. #include "refaction.h"
  23. #define REF_TRACE_PROCESSOR_BITS 6 // MAXIMUM_PROCESSORS == 64 on Win64
  24. #define REF_TRACE_ACTION_BITS (16 - REF_TRACE_PROCESSOR_BITS)
  25. C_ASSERT((1 << REF_TRACE_PROCESSOR_BITS) >= MAXIMUM_PROCESSORS);
  26. C_ASSERT((1 << REF_TRACE_ACTION_BITS) >= REF_ACTION_MAX);
  27. //
  28. // This defines the entry written to the trace log.
  29. //
  30. typedef struct _REF_TRACE_LOG_ENTRY
  31. {
  32. PVOID pContext;
  33. PVOID pFileName;
  34. PEPROCESS pProcess;
  35. PETHREAD pThread;
  36. PVOID pCaller;
  37. PVOID pCallersCaller;
  38. LONG NewRefCount;
  39. USHORT LineNumber;
  40. USHORT Action : REF_TRACE_ACTION_BITS;
  41. USHORT Processor : REF_TRACE_PROCESSOR_BITS;
  42. } REF_TRACE_LOG_ENTRY, *PREF_TRACE_LOG_ENTRY;
  43. #define REF_TRACELOG_SIGNATURE ((ULONG) 'gLfR')
  44. //
  45. // Subtract REF_TRACE_OVERHEAD from a power of 2 when calculating the
  46. // number of entries in a reftrace log, to ensure that overall size is
  47. // a nice power of 2 and doesn't spill onto another page. This accounts
  48. // for the size of the TRACE_LOG struct itself and the overhead
  49. // imposed by the pool and the verifier. On x86, a REF_TRACE_LOG_ENTRY
  50. // is currently 32 bytes. If you modify the struct, please recalculate
  51. // REF_TRACE_OVERHEAD and *change the per-object* reftrace logs (in
  52. // UL_CONNECTION, UL_HTTP_CONNECTION, and UL_INTERNAL_REQUEST) accordingly.
  53. //
  54. #define REF_TRACE_OVERHEAD 2 // entries
  55. //
  56. // Manipulators.
  57. //
  58. PTRACE_LOG
  59. CreateRefTraceLog(
  60. IN ULONG LogSize,
  61. IN ULONG ExtraBytesInHeader
  62. );
  63. VOID
  64. DestroyRefTraceLog(
  65. IN PTRACE_LOG pLog
  66. );
  67. VOID
  68. ResetRefTraceLog(
  69. IN PTRACE_LOG pLog
  70. );
  71. LONGLONG
  72. WriteRefTraceLog(
  73. IN PTRACE_LOG pLog,
  74. IN PTRACE_LOG pLog2,
  75. IN USHORT Action,
  76. IN LONG NewRefCount,
  77. IN PVOID pContext,
  78. IN PVOID pFileName,
  79. IN USHORT LineNumber
  80. );
  81. #if REFERENCE_DEBUG
  82. #define CREATE_REF_TRACE_LOG( ptr, size, extra ) \
  83. (ptr) = CreateRefTraceLog( (size), (extra) )
  84. #define DESTROY_REF_TRACE_LOG( ptr ) \
  85. do \
  86. { \
  87. DestroyRefTraceLog( ptr ); \
  88. (ptr) = NULL; \
  89. } while (FALSE)
  90. #define RESET_REF_TRACE_LOG( ptr ) \
  91. ResetRefTraceLog( ptr )
  92. #define WRITE_REF_TRACE_LOG( plog, act, ref, pctx, pfile, line ) \
  93. WriteRefTraceLog( \
  94. (plog), \
  95. NULL, \
  96. (act), \
  97. (ref), \
  98. (pctx), \
  99. (pfile), \
  100. (line) \
  101. )
  102. #define WRITE_REF_TRACE_LOG2( plog1, plog2, act, ref, pctx, pfile, line ) \
  103. WriteRefTraceLog( \
  104. (plog1), \
  105. (plog2), \
  106. (act), \
  107. (ref), \
  108. (pctx), \
  109. (pfile), \
  110. (line) \
  111. )
  112. #else // !REFERENCE_DEBUG
  113. #define CREATE_REF_TRACE_LOG( ptr, size, extra )
  114. #define DESTROY_REF_TRACE_LOG( ptr )
  115. #define RESET_REF_TRACE_LOG( ptr )
  116. #define WRITE_REF_TRACE_LOG( plog, act, ref, pctx, pfile, line )
  117. #define WRITE_REF_TRACE_LOG2( plog1, plog2 , act, ref, pctx, pfile, line )
  118. #endif // !REFERENCE_DEBUG
  119. #if defined(__cplusplus)
  120. } // extern "C"
  121. #endif // __cplusplus
  122. #endif // _REFTRACE_H_