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.

244 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1995,1996 Microsoft Corporation
  3. :ts=4
  4. Module Name:
  5. log.c
  6. Abstract:
  7. Debug log Code for serial.
  8. Environment:
  9. kernel mode only
  10. Notes:
  11. Revision History:
  12. 10-08-95 : created
  13. --*/
  14. #include "precomp.h"
  15. #include <stdio.h>
  16. #if DBG
  17. extern ULONG CyyDebugLevel;
  18. KSPIN_LOCK LogSpinLock;
  19. struct SERIAL_LOG_ENTRY {
  20. ULONG le_sig; // Identifying string
  21. ULONG_PTR le_info1; // entry specific info
  22. ULONG_PTR le_info2; // entry specific info
  23. ULONG_PTR le_info3; // entry specific info
  24. }; // SERIAL_LOG_ENTRY
  25. struct SERIAL_LOG_ENTRY *SerialLStart = 0; // No log yet
  26. struct SERIAL_LOG_ENTRY *SerialLPtr;
  27. struct SERIAL_LOG_ENTRY *SerialLEnd;
  28. // LogMask changed to LOG_MISC for debug
  29. ULONG LogMask = 0x0;
  30. //ULONG LogMask = LOG_MISC;
  31. VOID
  32. SerialDebugLogEntry(IN ULONG Mask, IN ULONG Sig, IN ULONG_PTR Info1,
  33. IN ULONG_PTR Info2, IN ULONG_PTR Info3)
  34. /*++
  35. Routine Description:
  36. Adds an Entry to serial log.
  37. Arguments:
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. KIRQL irql;
  43. typedef union _SIG {
  44. struct {
  45. UCHAR Byte0;
  46. UCHAR Byte1;
  47. UCHAR Byte2;
  48. UCHAR Byte3;
  49. } b;
  50. ULONG l;
  51. } SIG, *PSIG;
  52. SIG sig, rsig;
  53. if (SerialLStart == 0) {
  54. return;
  55. }
  56. if ((Mask & LogMask) == 0) {
  57. return;
  58. }
  59. irql = KeGetCurrentIrql();
  60. if (irql < DISPATCH_LEVEL) {
  61. KeAcquireSpinLock(&LogSpinLock, &irql);
  62. } else {
  63. KeAcquireSpinLockAtDpcLevel(&LogSpinLock);
  64. }
  65. if (SerialLPtr > SerialLStart) {
  66. SerialLPtr -= 1; // Decrement to next entry
  67. } else {
  68. SerialLPtr = SerialLEnd;
  69. }
  70. sig.l = Sig;
  71. rsig.b.Byte0 = sig.b.Byte3;
  72. rsig.b.Byte1 = sig.b.Byte2;
  73. rsig.b.Byte2 = sig.b.Byte1;
  74. rsig.b.Byte3 = sig.b.Byte0;
  75. SerialLPtr->le_sig = rsig.l;
  76. SerialLPtr->le_info1 = Info1;
  77. SerialLPtr->le_info2 = Info2;
  78. SerialLPtr->le_info3 = Info3;
  79. ASSERT(SerialLPtr >= SerialLStart);
  80. if (irql < DISPATCH_LEVEL) {
  81. KeReleaseSpinLock(&LogSpinLock, irql);
  82. } else {
  83. KeReleaseSpinLockFromDpcLevel(&LogSpinLock);
  84. }
  85. return;
  86. }
  87. VOID
  88. SerialLogInit()
  89. /*++
  90. Routine Description:
  91. Init the debug log - remember interesting information in a circular buffer
  92. Arguments:
  93. Return Value:
  94. None.
  95. --*/
  96. {
  97. #ifdef MAX_DEBUG
  98. ULONG logSize = 4096*6;
  99. #else
  100. ULONG logSize = 4096*3;
  101. #endif
  102. KeInitializeSpinLock(&LogSpinLock);
  103. SerialLStart = ExAllocatePoolWithTag(NonPagedPool, logSize, 'PyyC');
  104. if (SerialLStart) {
  105. SerialLPtr = SerialLStart;
  106. // Point the end (and first entry) 1 entry from the end of the segment
  107. SerialLEnd = SerialLStart + (logSize / sizeof(struct SERIAL_LOG_ENTRY))
  108. - 1;
  109. } else {
  110. #if DBG
  111. /* DO NOTHING */;
  112. //
  113. // we used to break here, but that messed up low resource simulation
  114. // testing on checked builds.
  115. //
  116. // DbgBreakPoint ();
  117. #endif
  118. }
  119. return;
  120. }
  121. VOID
  122. SerialLogFree(
  123. )
  124. /*++
  125. Routine Description:
  126. Arguments:
  127. Return Value:
  128. None.
  129. --*/
  130. {
  131. if (SerialLStart) {
  132. ExFreePool(SerialLStart);
  133. }
  134. return;
  135. }
  136. #define SERIAL_DBGPRINT_BUFSIZE 512
  137. ULONG
  138. CyyDbgPrintEx(IN ULONG Level, PCHAR Format, ...)
  139. {
  140. va_list arglist;
  141. ULONG rval;
  142. ULONG Mask;
  143. ULONG cb;
  144. UCHAR buffer[SERIAL_DBGPRINT_BUFSIZE];
  145. if (Level > 31) {
  146. Mask = Level;
  147. } else {
  148. Mask = 1 << Level;
  149. }
  150. if ((Mask & CyyDebugLevel) == 0) {
  151. return STATUS_SUCCESS;
  152. }
  153. va_start(arglist, Format);
  154. DbgPrint("Cyyport: ");
  155. cb = _vsnprintf(buffer, sizeof(buffer), Format, arglist);
  156. if (cb == -1) {
  157. buffer[sizeof(buffer) - 2] = '\n';
  158. }
  159. DbgPrint("%s", buffer);
  160. // rval = vDbgPrintEx(DPFLTR_SERIAL_ID, Level, Format, arglist);
  161. va_end(arglist);
  162. rval = STATUS_SUCCESS;
  163. return rval;
  164. }
  165. #endif // DBG