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.

321 lines
12 KiB

  1. /*++
  2. Copyright (c) 1995-1999 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. debug defines shared between the KD extensions and the driver
  7. Author:
  8. Charlie Wickham (charlwi) 11-May-1995
  9. Revision History:
  10. --*/
  11. #ifndef _DEBUG_
  12. #define _DEBUG_
  13. //
  14. //
  15. // Debug Level and Mask definitions.
  16. //
  17. #define DBG_DEATH 1
  18. #define DBG_CRITICAL_ERROR 2
  19. #define DBG_FAILURE 4
  20. #define DBG_INFO 6
  21. #define DBG_TRACE 8
  22. #define DBG_VERBOSE 10
  23. #define DBG_INIT 0x00000001
  24. #define DBG_MINIPORT 0x00000002
  25. #define DBG_PROTOCOL 0x00000004
  26. #define DBG_SEND 0x00000008
  27. #define DBG_RECEIVE 0x00000010
  28. #define DBG_IO 0x00000020
  29. #define DBG_MEMORY 0x00000040
  30. #define DBG_CM 0x00000080
  31. #define DBG_REFCNTS 0x00000100
  32. #define DBG_VC 0x00000200
  33. #define DBG_GPC_QOS 0x00000400
  34. #define DBG_WAN 0x00000800
  35. #define DBG_STATE 0x00001000
  36. #define DBG_ROUTINEOIDS 0x00002000
  37. #define DBG_SCHED_TBC 0x00004000
  38. #define DBG_SCHED_SHAPER 0x00008000
  39. #define DBG_SCHED_DRR 0x00010000
  40. #define DBG_WMI 0x00020000
  41. #define DBG_ZAW 0x00040000
  42. #define DBG_ALL 0xFFFFFFFF
  43. //
  44. // these tags are used in Lookaside lists therefore need to be
  45. // available regardless of the type of build
  46. //
  47. extern ULONG NdisRequestTag;
  48. extern ULONG GpcClientVcTag;
  49. extern ULONG WanLinkTag;
  50. extern ULONG PsMiscTag;
  51. extern ULONG WMITag;
  52. #define NDIS_PACKET_POOL_TAG_FOR_PSCHED 'pPDN'
  53. // We mark all memory allocated via PsAllocateXXX with a signature
  54. // immediately following allocation, and with another signature
  55. // immediately preceeding freeing.
  56. #define ALLOCATED_MARK (UCHAR) 0xDD
  57. #define FREED_MARK (UCHAR) 0xBB
  58. //
  59. // NT Debugging routines
  60. //
  61. //
  62. // signatures for data structures
  63. //
  64. extern ULONG AdapterTag;
  65. extern ULONG CmParamsTag;
  66. extern ULONG PipeContextTag;
  67. extern ULONG FlowContextTag;
  68. extern ULONG ClassMapContextTag;
  69. extern ULONG ProfileTag;
  70. extern ULONG ComponentTag;
  71. extern ULONG WanTableTag;
  72. #if DBG
  73. extern CHAR VersionNumber[];
  74. extern CHAR VersionHerald[];
  75. extern CHAR VersionTimestamp[];
  76. #define DEBUGCHK DbgBreakPoint()
  77. #define STATIC
  78. //
  79. // these correspond to DebugLevel and DebugMask in Psched\Parameters
  80. //
  81. extern ULONG DbgTraceLevel;
  82. extern ULONG DbgTraceMask;
  83. extern ULONG LogTraceLevel;
  84. extern ULONG LogTraceMask;
  85. extern ULONG LogId;
  86. extern ULONG DbgTraceControl;
  87. extern ULONG ClassificationType;
  88. #define PsDbgSched(_DebugLevel, _DebugMask, _r, _s, _t, _u, _v, _w, _x1, _x2, _y, _z){\
  89. if ((LogTraceLevel >= _DebugLevel) && \
  90. ((_DebugMask) & LogTraceMask)){ \
  91. DbugSched(_r, _s, _t, _u, _v, _w, (_x1), (_x2), _y, _z);\
  92. }\
  93. }
  94. #define PsDbgRecv(_DebugLevel, _DebugMask, _event, _action, _a, _p1, _p2) {\
  95. if ((LogTraceLevel >= _DebugLevel) && \
  96. ((_DebugMask) & LogTraceMask)){ \
  97. DbugRecv(_event, _action, _a, _p1, _p2); \
  98. } \
  99. }
  100. #define PsDbgSend(_DebugLevel, _DebugMask, _event, _action, _a, _v, _p1, _p2) {\
  101. if ((LogTraceLevel >= _DebugLevel) && \
  102. ((_DebugMask) & LogTraceMask)){ \
  103. DbugSend(_event, _action, _a, _v, _p1, _p2); \
  104. } \
  105. }
  106. #define PsDbgOid(_DebugLevel, _DebugMask, Action, Local, PTState, MPState, Adapter, Oid, Status) {\
  107. if ((LogTraceLevel >= _DebugLevel) && \
  108. ((_DebugMask) & LogTraceMask)){ \
  109. DbugOid(Action, Local, PTState, MPState, Adapter, Oid, Status); \
  110. } \
  111. }
  112. #define PsDbgOut(_DebugLevel, _DebugMask, _Out){ \
  113. if ((DbgTraceLevel >= _DebugLevel) && \
  114. ((_DebugMask) & DbgTraceMask)){ \
  115. DbgPrint("PSched: "); \
  116. DbgPrint _Out; \
  117. } \
  118. if ((LogTraceLevel >= _DebugLevel) && \
  119. ((_DebugMask) & LogTraceMask)){ \
  120. DbugSchedString _Out; \
  121. } \
  122. }
  123. #define PsDbgOutNoID(_DebugLevel, _DebugMask, _Out) { \
  124. if ((DbgTraceLevel >= _DebugLevel) && \
  125. ((_DebugMask) & DbgTraceMask)){ \
  126. DbgPrint _Out; \
  127. } \
  128. if ((LogTraceLevel >= _DebugLevel) && \
  129. ((_DebugMask) & LogTraceMask)){ \
  130. DbugSchedString _Out; \
  131. } \
  132. }
  133. #define PS_LOCK(_s) { \
  134. NdisAcquireSpinLock(&((_s)->Lock)); \
  135. PsAssert((_s)->LockAcquired == FALSE); \
  136. (_s)->LockAcquired = TRUE; \
  137. (_s)->LastAcquiredLine = __LINE__; \
  138. strncpy((_s)->LastAcquiredFile, strrchr(__FILE__, '\\')+1, 7); \
  139. }
  140. #define PS_UNLOCK(_s) \
  141. { \
  142. PsAssert((_s)->LockAcquired == TRUE); \
  143. (_s)->LockAcquired = FALSE; \
  144. (_s)->LastReleasedLine = __LINE__; \
  145. strncpy((_s)->LastReleasedFile, strrchr(__FILE__, '\\')+1, 7); \
  146. NdisReleaseSpinLock(&((_s)->Lock)); \
  147. }
  148. #define PS_LOCK_DPC(_s) { \
  149. PsAssert(KeGetCurrentIrql() == DISPATCH_LEVEL); \
  150. NdisDprAcquireSpinLock(&((_s)->Lock)); \
  151. PsAssert((_s)->LockAcquired == FALSE); \
  152. (_s)->LockAcquired = TRUE; \
  153. (_s)->LastAcquiredLine = __LINE__; \
  154. strncpy((_s)->LastAcquiredFile, strrchr(__FILE__, '\\')+1, 7); \
  155. }
  156. #define PS_UNLOCK_DPC(_s) \
  157. { \
  158. PsAssert(KeGetCurrentIrql() == DISPATCH_LEVEL); \
  159. PsAssert((_s)->LockAcquired == TRUE); \
  160. (_s)->LockAcquired = FALSE; \
  161. (_s)->LastReleasedLine = __LINE__; \
  162. strncpy((_s)->LastReleasedFile, strrchr(__FILE__, '\\')+1, 7); \
  163. NdisDprReleaseSpinLock(&((_s)->Lock)); \
  164. }
  165. #define PS_INIT_SPIN_LOCK(_s) { \
  166. (_s)->LockAcquired = FALSE; \
  167. (_s)->LastAcquiredLine = __LINE__; \
  168. strncpy((_s)->LastAcquiredFile, strrchr(__FILE__, '\\')+1, 7); \
  169. NdisAllocateSpinLock(&((_s)->Lock)); \
  170. }
  171. #define KdPrint( x ) DbgPrint x
  172. #define STRUCT_LLTAG ULONG LLTag
  173. #define PsStructAssert(_tag) if ((_tag) != NULL && *(PULONG)((PUCHAR)_tag - sizeof(ULONG)) != _tag##Tag) {\
  174. DbgPrint( "PSched: structure assertion failure for type " #_tag " in file " __FILE__ " line %d\n", __LINE__ );\
  175. DEBUGCHK;\
  176. }
  177. #define PsAssert(c) if (!(c)) {\
  178. DbgPrint( "PSched: assertion @ line %d in file " __FILE__ " \n", __LINE__ );\
  179. DEBUGCHK;\
  180. }
  181. //
  182. // allocate memory from nonpaged pool and set the tag in the checked
  183. // version of the structure
  184. //
  185. #define PsAllocatePool( _addr, _size, _tag ) \
  186. { \
  187. PCHAR _Temp; \
  188. ULONG _Size = (_size) + 2 * sizeof(ULONG); \
  189. _Temp = ExAllocatePoolWithTag( NonPagedPool, (_Size), (_tag)); \
  190. if ( _Temp ) { \
  191. NdisFillMemory( _Temp, _Size, ALLOCATED_MARK); \
  192. *(PULONG)_Temp = _Size; \
  193. *(PULONG)(_Temp + sizeof(ULONG)) = _tag; \
  194. (PCHAR)(_addr) = _Temp + 2 * sizeof(ULONG); \
  195. } \
  196. else{ \
  197. (PCHAR)(_addr) = _Temp; \
  198. } \
  199. }
  200. #define PsFreePool(_addr) \
  201. { \
  202. PCHAR _Temp = (PCHAR)(_addr) - 2 * sizeof(ULONG); \
  203. ULONG _Size = *(PULONG)_Temp; \
  204. NdisFillMemory( _Temp, _Size, FREED_MARK); \
  205. ExFreePool(_Temp); \
  206. }
  207. //
  208. // structures allocated from lookaside lists don't go through PsAllocateXXX.
  209. // so - if we wanna tag these, we'll have to macro the LL routines.
  210. //
  211. #define PsAllocFromLL(_ptr, _list, _tag) \
  212. *_ptr = NdisAllocateFromNPagedLookasideList(_list); \
  213. if(*_ptr != 0) {\
  214. *_ptr->LLTag = _tag##Tag; \
  215. }
  216. #define PsFreeToLL(_ptr, _list, _tag) \
  217. PsAssert(_ptr->LLTag == _tag##Tag); \
  218. _ptr->LLTag = (ULONG)0; \
  219. NdisFreeToNPagedLookasideList(_list, _ptr); \
  220. #define CheckLLTag(_ptr, _tag) \
  221. PsAssert(_ptr->LLTag == _tag##Tag);
  222. #define SetLLTag(_ptr, _tag) (_ptr)->LLTag = _tag##Tag;
  223. #else // DBG
  224. #define DEBUGCHK
  225. #define PsDbgSched(_DebugLevel, _DebugMask, _r, _s, _t, _u, _v, _w, _x1, _x2, _y, _z)
  226. #define PsDbgRecv(_DebugLevel, _DebugMask, _event, _action, _a, _p1, _p2)
  227. #define PsDbgSend(_DebugLevel, _DebugMask, _event, _action, _a, _v, _p1, _p2)
  228. #define PsDbgOut(s,t,u)
  229. #define PsDbgOid(p,q,s,t,u,v,w,x,y)
  230. #define PsDbgOutNoID(s,t,u)
  231. #define PsDbg(r, s, t, u)
  232. #define KdPrint( x )
  233. #define STRUCT_LLTAG /##/
  234. #define PsStructAssert( t )
  235. #define PsAssert(c)
  236. #define PS_LOCK(_s) NdisAcquireSpinLock(&((_s)->Lock))
  237. #define PS_UNLOCK(_s) NdisReleaseSpinLock(&((_s)->Lock))
  238. #define PS_LOCK_DPC(_s) NdisDprAcquireSpinLock(&((_s)->Lock))
  239. #define PS_UNLOCK_DPC(_s) NdisDprReleaseSpinLock(&((_s)->Lock))
  240. #define PS_INIT_SPIN_LOCK(_s) NdisAllocateSpinLock(&((_s)->Lock))
  241. #define PsAllocatePool( _addr, _size, _tag ) \
  242. _addr = ExAllocatePoolWithTag( NonPagedPool, (_size), (_tag)); \
  243. if ( _addr ) { \
  244. NdisZeroMemory( _addr, _size ); \
  245. }
  246. #define PsFreePool(_addr) ExFreePool(_addr)
  247. //
  248. // structures allocated from lookaside lists don't go through PsAllocateXXX.
  249. // so - if we wanna tag these, we'll have to macro the LL routines.
  250. //
  251. #define PsAllocFromLL(_ptr, _list, _tag) \
  252. *_ptr = (PVOID)NdisAllocateFromNPagedLookasideList(_list); \
  253. #define PsFreeToLL(_ptr, _list, _tag) \
  254. NdisFreeToNPagedLookasideList(_list, _ptr);
  255. #define CheckLLTag(_ptr, _tag)
  256. #define SetLLTag(_ptr, _tag)
  257. #define STATIC static
  258. #endif // DBG
  259. #endif /* _DEBUG_ */
  260. /* end debug.h */