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.

214 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 2001-2001 Microsoft Corporation
  3. Module Name:
  4. ownerref.h
  5. Abstract:
  6. This module contains public declarations and definitions for tracing
  7. and debugging reference count problems - by owner. It's an enhanced
  8. version of the reftracing in reftrace.h.
  9. Reference counting implies ownership. We associate a REF_OWNER structure
  10. with every object that holds a reference on the refcounted object and
  11. keep track of its relative refcount. Currently, this is used to keep
  12. track of which UL_CONNECTIONs have an active reference to their
  13. UL_ENDPOINT. Because UL_CONNECTIONs are recycled, we use the MonotonicId
  14. to keep track of each generation.
  15. Author:
  16. George V. Reilly Jan-2001
  17. Revision History:
  18. --*/
  19. #ifndef _OWNERREF_H_
  20. #define _OWNERREF_H_
  21. #if defined(__cplusplus)
  22. extern "C" {
  23. #endif // __cplusplus
  24. // Owned Reference stuff
  25. typedef struct _OWNER_REF_TRACELOG *POWNER_REF_TRACELOG; // fwd decl
  26. typedef struct _OWNED_REFERENCE
  27. {
  28. LONGLONG RefIndex; // index of corresponding OWNER_REF_TRACE_LOG_ENTRY
  29. // in the master OwnerRefTraceLog
  30. LONG MonotonicId;// "generation" of this owner
  31. USHORT Action; // what happened
  32. } OWNED_REFERENCE;
  33. #define OWNED_REF_NUM_ENTRIES 16
  34. #define OWNER_REF_SIGNATURE ((ULONG) 'wOfR')
  35. // Each owner has one of these associated with it. Note: it is not
  36. // stored inline within the owner, as it must survive past the lifetime
  37. // of the owner
  38. typedef struct _REF_OWNER
  39. {
  40. ULONG Signature; // OWNER_REF_SIGNATURE
  41. ULONG OwnerSignature; // e.g., UL_CONNECTION_SIGNATURE
  42. PVOID pOwner; // owning object
  43. POWNER_REF_TRACELOG pOwnerRefTraceLog; // back pointer
  44. LIST_ENTRY ListEntry; // within list of REF_OWNERs
  45. LONG RelativeRefCount;// held by this owner
  46. LONG OwnedNextEntry; // index within RecentEntries
  47. OWNED_REFERENCE RecentEntries[OWNED_REF_NUM_ENTRIES]; // circular buff
  48. } REF_OWNER, *PREF_OWNER, **PPREF_OWNER;
  49. // Additional data stored at the end of the TRACELOG header.
  50. typedef struct _OWNER_REF_TRACELOG_HEADER
  51. {
  52. UL_SPIN_LOCK SpinLock;
  53. LONG OwnersCount; // length of list of REF_OWNERs
  54. LONG MonotonicId;
  55. LIST_ENTRY ListHead; // list of REF_OWNERs
  56. LIST_ENTRY GlobalListEntry;// entry within global list of ORTLs
  57. } OWNER_REF_TRACELOG_HEADER, *POWNER_REF_TRACELOG_HEADER;
  58. #define OWNER_REF_TRACELOG_SIGNATURE ((ULONG) 'gLRO')
  59. typedef struct _OWNER_REF_TRACELOG
  60. {
  61. TRACE_LOG TraceLog;
  62. OWNER_REF_TRACELOG_HEADER OwnerHeader;
  63. } OWNER_REF_TRACELOG, *POWNER_REF_TRACELOG;
  64. typedef struct _OWNER_REF_TRACE_LOG_ENTRY
  65. {
  66. PVOID pOwner; // an object that has an assoc'd REF_OWNER
  67. PVOID pFileName; // source file
  68. LONG NewRefCount; // new absolute refcount. -1 => non ref action
  69. USHORT LineNumber; // line within source file
  70. USHORT Action : REF_TRACE_ACTION_BITS;
  71. USHORT Pad : REF_TRACE_PROCESSOR_BITS;
  72. } OWNER_REF_TRACE_LOG_ENTRY, *POWNER_REF_TRACE_LOG_ENTRY;
  73. //
  74. // Manipulators.
  75. //
  76. VOID
  77. UlInitializeOwnerRefTraceLog(
  78. VOID);
  79. VOID
  80. UlTerminateOwnerRefTraceLog(
  81. VOID);
  82. POWNER_REF_TRACELOG
  83. CreateOwnerRefTraceLog(
  84. IN ULONG LogSize,
  85. IN ULONG ExtraBytesInHeader
  86. );
  87. LONGLONG
  88. WriteOwnerRefTraceLog(
  89. IN POWNER_REF_TRACELOG pOwnerRefTraceLog,
  90. IN PVOID pOwner,
  91. IN PPREF_OWNER ppRefOwner,
  92. IN ULONG OwnerSignature,
  93. IN USHORT Action,
  94. IN LONG NewRefCount,
  95. IN LONG MonotonicId,
  96. IN LONG IncrementValue,
  97. IN PVOID pFileName,
  98. IN USHORT LineNumber
  99. );
  100. VOID
  101. DestroyOwnerRefTraceLog(
  102. IN POWNER_REF_TRACELOG pOwnerRefTraceLog
  103. );
  104. VOID
  105. ResetOwnerRefTraceLog(
  106. IN POWNER_REF_TRACELOG pOwnerRefTraceLog
  107. );
  108. #if ENABLE_OWNER_REF_TRACE
  109. // Owner RefTrace stuff
  110. #define CREATE_OWNER_REF_TRACE_LOG( ptr, size, extra ) \
  111. (ptr) = CreateOwnerRefTraceLog( (size), (extra) )
  112. #define DESTROY_OWNER_REF_TRACE_LOG( ptr ) \
  113. do \
  114. { \
  115. DestroyOwnerRefTraceLog( ptr ); \
  116. (ptr) = NULL; \
  117. } while (FALSE)
  118. #define WRITE_OWNER_REF_TRACE_LOG( \
  119. plog, powner, pprefowner, sig, act, newrefct, monoid, incrval, pfile, line )\
  120. WriteOwnerRefTraceLog( \
  121. (plog), \
  122. (powner), \
  123. (pprefowner), \
  124. (sig), \
  125. (act), \
  126. (newrefct), \
  127. (monoid), \
  128. (incrval), \
  129. (pfile), \
  130. (line) \
  131. )
  132. #define SET_OWNER_REF_TRACE_LOG_MONOTONIC_ID( var, plog ) \
  133. (var) = (((plog) == NULL) \
  134. ? -1 : InterlockedIncrement(&(plog)->OwnerHeader.MonotonicId))
  135. #define OWNER_REFERENCE_DEBUG_FORMAL_PARAMS \
  136. , PVOID pOwner \
  137. , PPREF_OWNER ppRefOwner \
  138. , ULONG OwnerSignature \
  139. , USHORT Action \
  140. , LONG MonotonicId \
  141. , PSTR pFileName \
  142. , USHORT LineNumber
  143. #define OWNER_REFERENCE_DEBUG_ACTUAL_PARAMS \
  144. , act, powner, pprefowner, monoid \
  145. , (PSTR)__FILE__,(USHORT)__LINE__
  146. #else // !ENABLE_OWNER_REF_TRACE
  147. #define CREATE_OWNER_REF_TRACE_LOG( ptr, size, extra ) \
  148. (ptr) = NULL
  149. #define DESTROY_OWNER_REF_TRACE_LOG( ptr )
  150. #define WRITE_OWNER_REF_TRACE_LOG( \
  151. plog, powner, pprefowner, sig, act, newrefct, monoid, incrval, pfile, line )
  152. #define SET_OWNER_REF_TRACE_LOG_MONOTONIC_ID( var, plog )
  153. #define OWNER_REFERENCE_DEBUG_FORMAL_PARAMS
  154. #define OWNER_REFERENCE_DEBUG_ACTUAL_PARAMS
  155. #endif // !ENABLE_OWNER_REF_TRACE
  156. #if defined(__cplusplus)
  157. } // extern "C"
  158. #endif // __cplusplus
  159. #endif // _OWNERREF_H_