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.

328 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. Debug macros for the ARP module
  7. Revision History:
  8. Notes:
  9. --*/
  10. #ifndef __RT_DEBUG_H__
  11. #define __RT_DEBUG_H__
  12. VOID
  13. RtInitializeDebug();
  14. //
  15. // Tags for Pools
  16. //
  17. #define GROUP_TAG 'gmPI'
  18. #define SOURCE_TAG 'smPI'
  19. #define OIF_TAG 'omPI'
  20. #define MSG_TAG 'mmPI'
  21. #define FREE_TAG 'fmPI'
  22. //
  23. // File signatures for everyone
  24. //
  25. #define DEBUG_SIG 'gbed'
  26. #define INI_SIG 'tini'
  27. #define IOCT_SIG 'tcoi'
  28. #define MFE_SIG 'efmm'
  29. #define FWD_SIG 'dwfm'
  30. #define TMR_SIG 'rmit'
  31. //
  32. // We use the RT_XXX_DEBUG flags so that we can force to
  33. // different debug modes on free builds by changing sources.
  34. // On a checked build, all debugging is on
  35. //
  36. #if DBG
  37. #ifndef RT_TRACE_DEBUG
  38. #define RT_TRACE_DEBUG 1
  39. #endif
  40. #ifndef RT_LOCK_DEBUG
  41. #define RT_LOCK_DEBUG 1
  42. #endif
  43. #ifndef RT_ASSERT_ON
  44. #define RT_ASSERT_ON 1
  45. #endif
  46. #ifndef RT_MEM_DEBUG
  47. #define RT_MEM_DEBUG 1
  48. #endif
  49. #else // DBG
  50. #ifndef RT_TRACE_DEBUG
  51. #define RT_TRACE_DEBUG 0
  52. #endif
  53. #ifndef RT_LOCK_DEBUG
  54. #define RT_LOCK_DEBUG 0
  55. #endif
  56. #ifndef RT_ASSERT_ON
  57. #define RT_ASSERT_ON 0
  58. #endif
  59. #ifndef RT_MEM_DEBUG
  60. #define RT_MEM_DEBUG 0
  61. #endif
  62. #endif // DBG
  63. #if RT_ASSERT_ON
  64. #define RtAssert(X) \
  65. { \
  66. if(!(X)) \
  67. { \
  68. DbgPrint("[IPMCAST] Assertion failed in %s at line %d\n",\
  69. __FILE__,__LINE__); \
  70. DbgPrint("IPMCAST: Assertion " #X "\n"); \
  71. DbgBreakPoint(); \
  72. } \
  73. }
  74. #else // RT_ASSERT_ON
  75. #define RtAssert(X)
  76. #endif
  77. #if RT_TRACE_DEBUG
  78. BYTE g_byDebugLevel;
  79. DWORD g_fDebugComp;
  80. #define MCAST_STREAM_GLOBAL 0x00000001
  81. #define MCAST_STREAM_SEND 0x00000002
  82. #define MCAST_STREAM_RCV 0x00000004
  83. #define MCAST_STREAM_MFE 0x00000008
  84. #define MCAST_STREAM_MEMORY 0x00000010
  85. #define MCAST_STREAM_IF 0x00000020
  86. #define MCAST_STREAM_FWD 0x00000040
  87. #define MCAST_STREAM_TMR 0x00000080
  88. #define RT_DBG_LEVEL_NONE 0xFF
  89. #define RT_DBG_LEVEL_ERROR 0xE0
  90. #define RT_DBG_LEVEL_WARN 0xD0
  91. #define RT_DBG_LEVEL_INFO 0xC0
  92. #define RT_DBG_LEVEL_TRACE 0xB0
  93. #define Trace(Stream, Level, Str) \
  94. { \
  95. if ( ((RT_DBG_LEVEL_##Level >= g_byDebugLevel) && \
  96. ((g_fDebugComp & MCAST_STREAM_##Stream) == MCAST_STREAM_##Stream)))\
  97. { \
  98. DbgPrint("[IPMCAST] "); \
  99. DbgPrint Str; \
  100. } \
  101. }
  102. #define TraceEnter(Stream, Str) Trace(Stream, TRACE, ("Entering "Str"\n"))
  103. #define TraceLeave(Stream, Str) Trace(Stream, TRACE, ("Leaving "Str"\n"))
  104. #else // RT_TRACE_DEBUG
  105. #define Trace(Stream, Level, Str)
  106. #define TraceEnter(Stream, Str)
  107. #define TraceLeave(Stream, Str)
  108. #endif // !RT_TRACE_DEBUG
  109. #if RT_LOCK_DEBUG
  110. extern KSPIN_LOCK g_ksLockLock;
  111. #ifndef __FILE_SIG__
  112. #error File signature not defined
  113. #endif
  114. typedef struct _RT_LOCK
  115. {
  116. ULONG ulLockSig;
  117. BOOLEAN bAcquired;
  118. PKTHREAD pktLastThread;
  119. ULONG ulFileSig;
  120. ULONG ulLineNumber;
  121. KSPIN_LOCK kslLock;
  122. }RT_LOCK, *PRT_LOCK;
  123. VOID
  124. RtpInitializeSpinLock(
  125. IN PRT_LOCK pLock,
  126. IN ULONG ulFileSig,
  127. IN ULONG ulLineNumber
  128. );
  129. VOID
  130. RtpAcquireSpinLock(
  131. IN PRT_LOCK pLock,
  132. OUT PKIRQL pkiIrql,
  133. IN ULONG ulFileSig,
  134. IN ULONG ulLineNumber,
  135. IN BOOLEAN bAtDpc
  136. );
  137. VOID
  138. RtpReleaseSpinLock(
  139. IN PRT_LOCK pLock,
  140. IN KIRQL kiIrql,
  141. IN ULONG ulFileSig,
  142. IN ULONG ulLineNumber,
  143. IN BOOLEAN bFromDpc
  144. );
  145. #define RT_LOCK_SIG 'KCOL'
  146. #define RtInitializeSpinLock(X) RtpInitializeSpinLock((X), __FILE_SIG__, __LINE__)
  147. #define RtAcquireSpinLock(X, Y) RtpAcquireSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  148. #define RtAcquireSpinLockAtDpcLevel(X) RtpAcquireSpinLock((X), NULL, __FILE_SIG__, __LINE__, TRUE)
  149. #define RtReleaseSpinLock(X, Y) RtpReleaseSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  150. #define RtReleaseSpinLockFromDpcLevel(X) RtpReleaseSpinLock((X), 0, __FILE_SIG__, __LINE__, TRUE)
  151. #else // RT_LOCK_DEBUG
  152. typedef KSPIN_LOCK RT_LOCK, *PRT_LOCK;
  153. #define RtInitializeSpinLock KeInitializeSpinLock
  154. #define RtAcquireSpinLock KeAcquireSpinLock
  155. #define RtAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
  156. #define RtReleaseSpinLock KeReleaseSpinLock
  157. #define RtReleaseSpinLockFromDpcLevel KeReleaseSpinLockFromDpcLevel
  158. #endif // RT_LOCK_DEBUG
  159. #if RT_MEM_DEBUG
  160. #ifndef __FILE_SIG__
  161. #error File signature not defined
  162. #endif
  163. //
  164. // Memory Allocation/Freeing Audit:
  165. //
  166. //
  167. // The RT_ALLOCATION structure stores all info about one allocation
  168. //
  169. typedef struct _RT_ALLOCATION
  170. {
  171. LIST_ENTRY leLink;
  172. ULONG ulMemSig;
  173. ULONG ulFileSig;
  174. ULONG ulLineNumber;
  175. ULONG ulSize;
  176. UCHAR pucData[1];
  177. }RT_ALLOCATION, *PRT_ALLOCATION;
  178. //
  179. // The RT_FREE structure stores info about an allocation
  180. // that was freed. Later if the memory is touched, the
  181. // free list can be scanned to see where the allocation was
  182. // freed
  183. //
  184. typedef struct _RT_FREE
  185. {
  186. LIST_ENTRY leLink;
  187. ULONG_PTR ulStartAddr;
  188. ULONG ulSize;
  189. ULONG ulMemSig;
  190. ULONG ulAllocFileSig;
  191. ULONG ulAllocLineNumber;
  192. ULONG ulFreeFileSig;
  193. ULONG ulFreeLineNumber;
  194. }RT_FREE, *PRT_FREE;
  195. #define RT_MEMORY_SIG 'YRMM'
  196. #define RT_FREE_SIG 'EERF'
  197. PVOID
  198. RtpAllocate(
  199. IN POOL_TYPE ptPool,
  200. IN ULONG ulSize,
  201. IN ULONG ulTag,
  202. IN ULONG ulFileSig,
  203. IN ULONG ulLineNumber
  204. );
  205. VOID
  206. RtpFree(
  207. PVOID pvPointer,
  208. IN ULONG ulFileSig,
  209. IN ULONG ulLineNumber
  210. );
  211. VOID
  212. RtAuditMemory();
  213. #define RtAllocate(X, Y, Z) RtpAllocate((X), (Y), (Z), __FILE_SIG__, __LINE__)
  214. #define RtFree(X) RtpFree((X), __FILE_SIG__, __LINE__)
  215. #else // RT_MEM_DEBUG
  216. #define RtAllocate ExAllocatePoolWithTag
  217. #define RtFree ExFreePool
  218. #define RtAuditMemory()
  219. #endif // RT_MEM_DEBUG
  220. #endif // __RT_DEBUG_H__