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.

189 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. reftrace.c
  5. Abstract:
  6. This module implements a reference count tracing facility.
  7. Author:
  8. Keith Moore (keithmo) 10-Jun-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #if !REFERENCE_DEBUG
  13. static int g_RefTraceDummyDeclarationToKeepW4WarningsQuiet;
  14. #else
  15. /***************************************************************************++
  16. Routine Description:
  17. Creates a new (empty) ref count trace log buffer.
  18. Arguments:
  19. LogSize - Supplies the number of entries in the log.
  20. ExtraBytesInHeader - Supplies the number of extra bytes to include
  21. in the log header. This is useful for adding application-
  22. specific data to the log.
  23. Return Value:
  24. PTRACE_LOG - Pointer to the newly created log if successful,
  25. NULL otherwise.
  26. --***************************************************************************/
  27. PTRACE_LOG
  28. CreateRefTraceLog(
  29. IN ULONG LogSize,
  30. IN ULONG ExtraBytesInHeader,
  31. IN TRACELOG_PRIORITY AllocationPriority,
  32. IN ULONG PoolTag
  33. )
  34. {
  35. return CreateTraceLog(
  36. REF_TRACELOG_SIGNATURE,
  37. LogSize,
  38. ExtraBytesInHeader,
  39. sizeof(REF_TRACE_LOG_ENTRY),
  40. AllocationPriority,
  41. PoolTag
  42. );
  43. } // CreateRefTraceLog
  44. /***************************************************************************++
  45. Routine Description:
  46. Destroys a ref count trace log buffer created with CreateRefTraceLog().
  47. Arguments:
  48. pLog - Supplies the ref count trace log buffer to destroy.
  49. --***************************************************************************/
  50. VOID
  51. DestroyRefTraceLog(
  52. IN PTRACE_LOG pLog,
  53. IN ULONG PoolTag
  54. )
  55. {
  56. DestroyTraceLog( pLog, PoolTag );
  57. } // DestroyRefTraceLog
  58. /***************************************************************************++
  59. Routine Description:
  60. W/O destroying the ref trace this function simply does reset and cleanup.
  61. Arguments:
  62. pLog - Supplies the ref count trace log buffer to destroy.
  63. --***************************************************************************/
  64. VOID
  65. ResetRefTraceLog(
  66. IN PTRACE_LOG pLog
  67. )
  68. {
  69. ResetTraceLog( pLog );
  70. } // ResetTraceLog
  71. /***************************************************************************++
  72. Routine Description:
  73. Writes a new entry to the specified ref count trace log.
  74. Arguments:
  75. pLog - Supplies the log to write to.
  76. pLog2 - Supplies a secondary log to write to.
  77. Action - Supplies an action code for the new log entry.
  78. NewRefCount - Supplies the updated reference count.
  79. pContext - Supplies an uninterpreted context to associate with
  80. the log entry.
  81. pFileName - Supplies the filename of the routine writing the log entry.
  82. LineNumber - Supplies he line number of the routine writing the log
  83. entry.
  84. --***************************************************************************/
  85. LONGLONG
  86. WriteRefTraceLog(
  87. IN PTRACE_LOG pLog,
  88. IN PTRACE_LOG pLog2,
  89. IN USHORT Action,
  90. IN LONG NewRefCount,
  91. IN PVOID pContext,
  92. IN PCSTR pFileName,
  93. IN USHORT LineNumber
  94. )
  95. {
  96. REF_TRACE_LOG_ENTRY entry;
  97. LONGLONG index;
  98. ULONG hash;
  99. ASSERT(Action < (1 << REF_TRACE_ACTION_BITS));
  100. //
  101. // Initialize the entry.
  102. //
  103. RtlCaptureStackBackTrace(
  104. 2,
  105. REF_TRACE_CALL_STACK_DEPTH,
  106. entry.CallStack,
  107. &hash
  108. );
  109. entry.NewRefCount = NewRefCount;
  110. entry.pContext = pContext;
  111. entry.pFileName = pFileName;
  112. entry.LineNumber = LineNumber;
  113. entry.Action = Action;
  114. entry.Processor = (UCHAR)KeGetCurrentProcessorNumber();
  115. entry.pThread = PsGetCurrentThread();
  116. //
  117. // Write it to the logs.
  118. //
  119. WriteTraceLog( g_pMondoGlobalTraceLog, &entry );
  120. index = WriteTraceLog( pLog, &entry );
  121. if (pLog2 != NULL)
  122. index = WriteTraceLog( pLog2, &entry );
  123. return index;
  124. } // WriteRefTraceLog
  125. #endif // REFERENCE_DEBUG