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.

333 lines
6.9 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 FREE_TAG 'rfII'
  18. #define DATA_TAG 'tdII'
  19. #define TUNNEL_TAG 'nTII'
  20. #define HEADER_TAG 'dhII'
  21. #define PACKET_TAG 'kpII'
  22. #define SEND_CONTEXT_TAG 'csII'
  23. #define TRANSFER_CONTEXT_TAG 'ctII'
  24. #define QUEUE_NODE_TAG 'qwII'
  25. #define MESSAGE_TAG 'gmII'
  26. #define STRING_TAG 'rsII'
  27. //
  28. // File signatures for everyone
  29. //
  30. #define DEBUG_SIG 'gbed'
  31. #define DRIVER_SIG 'rvrd'
  32. #define BPOOL_SIG 'lopb'
  33. #define PPOOL_SIG 'lopp'
  34. #define ADAPTER_SIG 'tpdA'
  35. #define SEND_SIG 'dnes'
  36. #define TDIX_SIG 'xidt'
  37. #define IOCT_SIG 'tcoi'
  38. #define ICMP_SIG 'pmci'
  39. //
  40. // We use the RT_XXX_DEBUG flags so that we can force to
  41. // different debug modes on free builds by changing sources.
  42. // On a checked build, all debugging is on
  43. //
  44. #if DBG
  45. #ifndef RT_TRACE_DEBUG
  46. #define RT_TRACE_DEBUG 1
  47. #endif
  48. #ifndef RT_LOCK_DEBUG
  49. #define RT_LOCK_DEBUG 1
  50. #endif
  51. #ifndef RT_ASSERT_ON
  52. #define RT_ASSERT_ON 1
  53. #endif
  54. #ifndef RT_MEM_DEBUG
  55. #define RT_MEM_DEBUG 1
  56. #endif
  57. #else // DBG
  58. #ifndef RT_TRACE_DEBUG
  59. #define RT_TRACE_DEBUG 0
  60. #endif
  61. #ifndef RT_LOCK_DEBUG
  62. #define RT_LOCK_DEBUG 0
  63. #endif
  64. #ifndef RT_ASSERT_ON
  65. #define RT_ASSERT_ON 0
  66. #endif
  67. #ifndef RT_MEM_DEBUG
  68. #define RT_MEM_DEBUG 0
  69. #endif
  70. #endif // DBG
  71. #if RT_ASSERT_ON
  72. #define RtAssert(X) \
  73. { \
  74. if(!(X)) \
  75. { \
  76. DbgPrint("[IPINIP] Assertion failed in %s at line %d\n",\
  77. __FILE__,__LINE__); \
  78. DbgPrint("IPINIP: Assertion " #X "\n"); \
  79. DbgBreakPoint(); \
  80. } \
  81. }
  82. #else // RT_ASSERT_ON
  83. #define RtAssert(X)
  84. #endif
  85. #if RT_TRACE_DEBUG
  86. BYTE g_byDebugLevel;
  87. DWORD g_fDebugComp;
  88. #define IPINIP_STREAM_GLOBAL 0x00000001
  89. #define IPINIP_STREAM_SEND 0x00000002
  90. #define IPINIP_STREAM_RCV 0x00000004
  91. #define IPINIP_STREAM_UTIL 0x00000008
  92. #define IPINIP_STREAM_MEMORY 0x00000010
  93. #define IPINIP_STREAM_TUNN 0x00000020
  94. #define IPINIP_STREAM_TDI 0x00000040
  95. #define RT_DBG_LEVEL_NONE 0xFF
  96. #define RT_DBG_LEVEL_FATAL 0xF0
  97. #define RT_DBG_LEVEL_ERROR 0xE0
  98. #define RT_DBG_LEVEL_WARN 0xD0
  99. #define RT_DBG_LEVEL_INFO 0xC0
  100. #define RT_DBG_LEVEL_TRACE 0xB0
  101. #define Trace(Stream, Level, Str) \
  102. { \
  103. if ((RT_DBG_LEVEL_##Level >= RT_DBG_LEVEL_ERROR) || \
  104. ((RT_DBG_LEVEL_##Level >= g_byDebugLevel) && \
  105. ((g_fDebugComp & IPINIP_STREAM_##Stream) == IPINIP_STREAM_##Stream)))\
  106. { \
  107. DbgPrint("[IPINIP] "); \
  108. DbgPrint Str; \
  109. } \
  110. }
  111. #define TraceEnter(Stream, Str) Trace(Stream, TRACE, ("Entering "Str"\n"))
  112. #define TraceLeave(Stream, Str) Trace(Stream, TRACE, ("Leaving "Str"\n"))
  113. #else // RT_TRACE_DEBUG
  114. #define Trace(Stream, Level, Str)
  115. #define TraceEnter(Stream, Str)
  116. #define TraceLeave(Stream, Str)
  117. #endif // RT_TRACE_DEBUG
  118. #if RT_LOCK_DEBUG
  119. extern KSPIN_LOCK g_ksLockLock;
  120. #ifndef __FILE_SIG__
  121. #error File signature not defined
  122. #endif
  123. typedef struct _RT_LOCK
  124. {
  125. ULONG ulLockSig;
  126. BOOLEAN bAcquired;
  127. PKTHREAD pktLastThread;
  128. ULONG ulFileSig;
  129. ULONG ulLineNumber;
  130. KSPIN_LOCK kslLock;
  131. }RT_LOCK, *PRT_LOCK;
  132. VOID
  133. RtpInitializeSpinLock(
  134. IN PRT_LOCK pLock,
  135. IN ULONG ulFileSig,
  136. IN ULONG ulLineNumber
  137. );
  138. VOID
  139. RtpAcquireSpinLock(
  140. IN PRT_LOCK pLock,
  141. OUT PKIRQL pkiIrql,
  142. IN ULONG ulFileSig,
  143. IN ULONG ulLineNumber,
  144. IN BOOLEAN bAtDpc
  145. );
  146. VOID
  147. RtpReleaseSpinLock(
  148. IN PRT_LOCK pLock,
  149. IN KIRQL kiIrql,
  150. IN ULONG ulFileSig,
  151. IN ULONG ulLineNumber,
  152. IN BOOLEAN bFromDpc
  153. );
  154. #define RT_LOCK_SIG 'KCOL'
  155. #define RtInitializeSpinLock(X) RtpInitializeSpinLock((X), __FILE_SIG__, __LINE__)
  156. #define RtAcquireSpinLock(X, Y) RtpAcquireSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  157. #define RtAcquireSpinLockAtDpcLevel(X) RtpAcquireSpinLock((X), NULL, __FILE_SIG__, __LINE__, TRUE)
  158. #define RtReleaseSpinLock(X, Y) RtpReleaseSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  159. #define RtReleaseSpinLockFromDpcLevel(X) RtpReleaseSpinLock((X), 0, __FILE_SIG__, __LINE__, TRUE)
  160. #else // RT_LOCK_DEBUG
  161. typedef KSPIN_LOCK RT_LOCK, *PRT_LOCK;
  162. #define RtInitializeSpinLock KeInitializeSpinLock
  163. #define RtAcquireSpinLock KeAcquireSpinLock
  164. #define RtAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
  165. #define RtReleaseSpinLock KeReleaseSpinLock
  166. #define RtReleaseSpinLockFromDpcLevel KeReleaseSpinLockFromDpcLevel
  167. #endif // RT_LOCK_DEBUG
  168. #if RT_MEM_DEBUG
  169. #ifndef __FILE_SIG__
  170. #error File signature not defined
  171. #endif
  172. //
  173. // Memory Allocation/Freeing Audit:
  174. //
  175. //
  176. // The RT_ALLOCATION structure stores all info about one allocation
  177. //
  178. typedef struct _RT_ALLOCATION
  179. {
  180. LIST_ENTRY leLink;
  181. ULONG ulMemSig;
  182. ULONG ulFileSig;
  183. ULONG ulLineNumber;
  184. ULONG ulSize;
  185. UCHAR pucData[1];
  186. }RT_ALLOCATION, *PRT_ALLOCATION;
  187. //
  188. // The RT_FREE structure stores info about an allocation
  189. // that was freed. Later if the memory is touched, the
  190. // free list can be scanned to see where the allocation was
  191. // freed
  192. //
  193. typedef struct _RT_FREE
  194. {
  195. LIST_ENTRY leLink;
  196. UINT_PTR pStartAddr;
  197. ULONG ulSize;
  198. ULONG ulMemSig;
  199. ULONG ulAllocFileSig;
  200. ULONG ulAllocLineNumber;
  201. ULONG ulFreeFileSig;
  202. ULONG ulFreeLineNumber;
  203. }RT_FREE, *PRT_FREE;
  204. #define RT_MEMORY_SIG 'YRMM'
  205. #define RT_FREE_SIG 'EERF'
  206. PVOID
  207. RtpAllocate(
  208. IN POOL_TYPE ptPool,
  209. IN ULONG ulSize,
  210. IN ULONG ulTag,
  211. IN ULONG ulFileSig,
  212. IN ULONG ulLineNumber
  213. );
  214. VOID
  215. RtpFree(
  216. PVOID pvPointer,
  217. IN ULONG ulFileSig,
  218. IN ULONG ulLineNumber
  219. );
  220. VOID
  221. RtAuditMemory();
  222. #define RtAllocate(X, Y, Z) RtpAllocate((X), (Y), (Z), __FILE_SIG__, __LINE__)
  223. #define RtFree(X) RtpFree((X), __FILE_SIG__, __LINE__)
  224. #else // RT_MEM_DEBUG
  225. #define RtAllocate ExAllocatePoolWithTag
  226. #define RtFree ExFreePool
  227. #define RtAuditMemory()
  228. #endif // RT_MEM_DEBUG
  229. #endif // __RT_DEBUG_H__