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.

163 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1998-2002 Microsoft Corporation
  3. Module Name:
  4. tracelog.h
  5. Abstract:
  6. This module contains public declarations and definitions for creating
  7. trace logs.
  8. A trace log is a fast, in-memory, threadsafe, circular activity log useful
  9. for debugging certain classes of problems. They are especially useful
  10. when debugging reference count bugs.
  11. Note that the creator of the log has the option of adding "extra"
  12. bytes to the log header. This can be useful if the creator wants to
  13. create a set of global logs, each on a linked list.
  14. Author:
  15. Keith Moore (keithmo) 10-Jun-1998
  16. Revision History:
  17. --*/
  18. #ifndef _TRACELOG_H_
  19. #define _TRACELOG_H_
  20. //
  21. // Look at memory consumption when allocating tracelog. Return NULL if
  22. // memory is low and priority is not high enough.
  23. //
  24. typedef enum _TRACELOG_PRIORITY {
  25. TRACELOG_LOW_PRIORITY = 1,
  26. TRACELOG_NORMAL_PRIORITY,
  27. TRACELOG_HIGH_PRIORITY
  28. } TRACELOG_PRIORITY;
  29. typedef struct _TRACE_LOG
  30. {
  31. //
  32. // Signature: TRACE_LOG_SIGNATURE;
  33. //
  34. ULONG Signature;
  35. //
  36. // TypeSignature: Ref, FiltQ, Irp, etc
  37. //
  38. ULONG TypeSignature;
  39. //
  40. // The total number of entries available in the log.
  41. //
  42. ULONG LogSize;
  43. //
  44. // The byte size of each entry.
  45. //
  46. ULONG EntrySize;
  47. //
  48. // The index of the next entry to use. For long runs in a busy
  49. // tracelog, a 32-bit index will overflow in a few days. Consider
  50. // what would happen if we jumped from OxFFFFFFFF (4,294,967,295) to
  51. // 0 when LogSize = 10,000: the index would jump from 7295 to 0,
  52. // leaving a large gap of stale records at the end, and !ulkd.ref
  53. // would not be able to find the preceding ones with high indices.
  54. //
  55. LONGLONG NextEntry;
  56. //
  57. // Priority this was created with
  58. //
  59. TRACELOG_PRIORITY AllocationPriority;
  60. //
  61. // Pointer to the start of the circular buffer.
  62. //
  63. PUCHAR pLogBuffer;
  64. //
  65. // The extra header bytes and actual log entries go here.
  66. //
  67. // BYTE ExtraHeaderBytes[ExtraBytesInHeader];
  68. // BYTE Entries[LogSize][EntrySize];
  69. //
  70. #ifdef _WIN64
  71. ULONG_PTR Padding;
  72. #endif
  73. } TRACE_LOG, *PTRACE_LOG;
  74. // sizeof(TRACE_LOG) must be a multiple of MEMORY_ALLOCATION_ALIGNMENT
  75. C_ASSERT((sizeof(TRACE_LOG) & (MEMORY_ALLOCATION_ALIGNMENT - 1)) == 0);
  76. //
  77. // Log header signature.
  78. //
  79. #define TRACE_LOG_SIGNATURE MAKE_SIGNATURE('Tlog')
  80. #define TRACE_LOG_SIGNATURE_X MAKE_FREE_SIGNATURE(TRACE_LOG_SIGNATURE)
  81. //
  82. // This macro maps a TRACE_LOG pointer to a pointer to the 'extra'
  83. // data associated with the log.
  84. //
  85. #define TRACE_LOG_TO_EXTRA_DATA(log) (PVOID)( (log) + 1 )
  86. //
  87. // Manipulators.
  88. //
  89. // CODEWORK: think about adding alignment flags so that entries will always
  90. // be pointer-aligned on the hardware
  91. PTRACE_LOG
  92. CreateTraceLog(
  93. IN ULONG TypeSignature,
  94. IN ULONG LogSize,
  95. IN ULONG ExtraBytesInHeader,
  96. IN ULONG EntrySize,
  97. IN TRACELOG_PRIORITY AllocationPriority,
  98. IN ULONG PoolTag
  99. );
  100. VOID
  101. DestroyTraceLog(
  102. IN PTRACE_LOG pLog,
  103. IN ULONG PoolTag
  104. );
  105. LONGLONG
  106. WriteTraceLog(
  107. IN PTRACE_LOG pLog,
  108. IN PVOID pEntry
  109. );
  110. VOID
  111. ResetTraceLog(
  112. IN PTRACE_LOG pLog
  113. );
  114. #endif // _TRACELOG_H_