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.

207 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. Debug macros for NDISUIO
  7. Revision History:
  8. arvindm 04/11/2000 created based on rawwan.
  9. Notes:
  10. --*/
  11. #ifndef _TUN_DEBUG__H
  12. #define _TUN_DEBUG__H
  13. //
  14. // Message verbosity: lower values indicate higher urgency
  15. //
  16. #define DL_EXTRA_LOUD 20
  17. #define DL_VERY_LOUD 10
  18. #define DL_LOUD 8
  19. #define DL_INFO 6
  20. #define DL_WARN 4
  21. #define DL_ERROR 2
  22. #define DL_FATAL 0
  23. #if DBG_SPIN_LOCK
  24. typedef struct _TUN_LOCK
  25. {
  26. ULONG Signature;
  27. ULONG IsAcquired;
  28. PKTHREAD OwnerThread;
  29. ULONG TouchedByFileNumber;
  30. ULONG TouchedInLineNumber;
  31. NDIS_SPIN_LOCK NdisLock;
  32. } TUN_LOCK, *PTUN_LOCK;
  33. #define TUNL_SIG 'KCOL'
  34. extern NDIS_SPIN_LOCK TunDbgLogLock;
  35. extern
  36. VOID
  37. TunAllocateSpinLock(
  38. IN PTUN_LOCK pLock,
  39. IN ULONG FileNumber,
  40. IN ULONG LineNumber
  41. );
  42. extern
  43. VOID
  44. TunAcquireSpinLock(
  45. IN PTUN_LOCK pLock,
  46. IN ULONG FileNumber,
  47. IN ULONG LineNumber
  48. );
  49. extern
  50. VOID
  51. TunReleaseSpinLock(
  52. IN PTUN_LOCK pLock,
  53. IN ULONG FileNumber,
  54. IN ULONG LineNumber
  55. );
  56. #define CHECK_LOCK_COUNT(Count) \
  57. { \
  58. if ((INT)(Count) < 0) \
  59. { \
  60. DbgPrint("Lock Count %d is < 0! File %s, Line %d\n",\
  61. Count, __FILE__, __LINE__); \
  62. DbgBreakPoint(); \
  63. } \
  64. }
  65. #else
  66. #define CHECK_LOCK_COUNT(Count)
  67. typedef NDIS_SPIN_LOCK TUN_LOCK;
  68. typedef PNDIS_SPIN_LOCK PTUN_LOCK;
  69. #endif // DBG_SPIN_LOCK
  70. #if DBG
  71. extern INT TunDebugLevel;
  72. #define DEBUGP(lev, stmt) \
  73. { \
  74. if ((lev) <= TunDebugLevel) \
  75. { \
  76. DbgPrint("TunMp: "); DbgPrint stmt; \
  77. } \
  78. }
  79. #define DEBUGPDUMP(lev, pBuf, Len) \
  80. { \
  81. if ((lev) <= TunDebugLevel) \
  82. { \
  83. DbgPrintHexDump((PUCHAR)(pBuf), (ULONG)(Len)); \
  84. } \
  85. }
  86. #define TUN_ASSERT(exp) \
  87. { \
  88. if (!(exp)) \
  89. { \
  90. DbgPrint("TunMp: assert " #exp " failed in" \
  91. " file %s, line %d\n", __FILE__, __LINE__); \
  92. DbgBreakPoint(); \
  93. } \
  94. }
  95. #define TUN_SET_SIGNATURE(s, t)\
  96. (ULONG)(s)->t##_sig = (ULONG)t##_signature;
  97. #define TUN_STRUCT_ASSERT(s, t) \
  98. if ((ULONG)(s)->t##_sig != (ULONG)t##_signature) \
  99. { \
  100. DbgPrint("Tun: assertion failure" \
  101. " for type " #t " at 0x%p in file %s, line %d\n", \
  102. (PUCHAR)s, __FILE__, __LINE__); \
  103. DbgBreakPoint(); \
  104. }
  105. //
  106. // Memory Allocation/Freeing Audit:
  107. //
  108. //
  109. // The TUND_ALLOCATION structure stores all info about one allocation
  110. //
  111. typedef struct _TUND_ALLOCATION {
  112. ULONG Signature;
  113. struct _TUND_ALLOCATION *Next;
  114. struct _TUND_ALLOCATION *Prev;
  115. ULONG FileNumber;
  116. ULONG LineNumber;
  117. ULONG Size;
  118. ULONG_PTR Location; // where the returned ptr was stored
  119. union
  120. {
  121. ULONGLONG Alignment;
  122. UCHAR UserData;
  123. };
  124. } TUND_ALLOCATION, *PTUND_ALLOCATION;
  125. #define TUND_MEMORY_SIGNATURE (ULONG)'CSII'
  126. extern
  127. PVOID
  128. TunAuditAllocMem (
  129. PVOID pPointer,
  130. ULONG Size,
  131. ULONG FileNumber,
  132. ULONG LineNumber
  133. );
  134. extern
  135. VOID
  136. TunAuditFreeMem(
  137. PVOID Pointer
  138. );
  139. extern
  140. VOID
  141. TunAuditShutdown(
  142. VOID
  143. );
  144. extern
  145. VOID
  146. DbgPrintHexDump(
  147. PUCHAR pBuffer,
  148. ULONG Length
  149. );
  150. #else
  151. //
  152. // No debug
  153. //
  154. #define DEBUGP(lev, stmt)
  155. #define DEBUGPDUMP(lev, pBuf, Len)
  156. #define TUN_ASSERT(exp)
  157. #define TUN_SET_SIGNATURE(s, t)
  158. #define TUN_STRUCT_ASSERT(s, t)
  159. #endif // DBG
  160. #endif // _TUN_DEBUG__H