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.

185 lines
3.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 "pch.h"
  15. #include <stdio.h>
  16. #if DBG
  17. KSPIN_LOCK LogSpinLock;
  18. struct SERENUM_LOG_ENTRY {
  19. ULONG le_sig; // Identifying string
  20. ULONG_PTR le_info1; // entry specific info
  21. ULONG_PTR le_info2; // entry specific info
  22. ULONG_PTR le_info3; // entry specific info
  23. }; // SERENUM_LOG_ENTRY
  24. struct SERENUM_LOG_ENTRY *SerenumLStart = 0; // No log yet
  25. struct SERENUM_LOG_ENTRY *SerenumLPtr;
  26. struct SERENUM_LOG_ENTRY *SerenumLEnd;
  27. ULONG LogMask = 0xffffffff;
  28. VOID
  29. SerenumDebugLogEntry(IN ULONG Mask, IN ULONG Sig, IN ULONG_PTR Info1,
  30. IN ULONG_PTR Info2, IN ULONG_PTR Info3)
  31. /*++
  32. Routine Description:
  33. Adds an Entry to serial log.
  34. Arguments:
  35. Return Value:
  36. None.
  37. --*/
  38. {
  39. KIRQL irql;
  40. typedef union _SIG {
  41. struct {
  42. UCHAR Byte0;
  43. UCHAR Byte1;
  44. UCHAR Byte2;
  45. UCHAR Byte3;
  46. } b;
  47. ULONG l;
  48. } SIG, *PSIG;
  49. SIG sig, rsig;
  50. if (SerenumLStart == 0) {
  51. return;
  52. }
  53. if ((Mask & LogMask) == 0) {
  54. return;
  55. }
  56. irql = KeGetCurrentIrql();
  57. if (irql < DISPATCH_LEVEL) {
  58. KeAcquireSpinLock(&LogSpinLock, &irql);
  59. } else {
  60. KeAcquireSpinLockAtDpcLevel(&LogSpinLock);
  61. }
  62. if (SerenumLPtr > SerenumLStart) {
  63. SerenumLPtr -= 1; // Decrement to next entry
  64. } else {
  65. SerenumLPtr = SerenumLEnd;
  66. }
  67. sig.l = Sig;
  68. rsig.b.Byte0 = sig.b.Byte3;
  69. rsig.b.Byte1 = sig.b.Byte2;
  70. rsig.b.Byte2 = sig.b.Byte1;
  71. rsig.b.Byte3 = sig.b.Byte0;
  72. SerenumLPtr->le_sig = rsig.l;
  73. SerenumLPtr->le_info1 = Info1;
  74. SerenumLPtr->le_info2 = Info2;
  75. SerenumLPtr->le_info3 = Info3;
  76. ASSERT(SerenumLPtr >= SerenumLStart);
  77. if (irql < DISPATCH_LEVEL) {
  78. KeReleaseSpinLock(&LogSpinLock, irql);
  79. } else {
  80. KeReleaseSpinLockFromDpcLevel(&LogSpinLock);
  81. }
  82. return;
  83. }
  84. VOID
  85. SerenumLogInit()
  86. /*++
  87. Routine Description:
  88. Init the debug log - remember interesting information in a circular buffer
  89. Arguments:
  90. Return Value:
  91. None.
  92. --*/
  93. {
  94. #ifdef MAX_DEBUG
  95. ULONG logSize = 4096*6;
  96. #else
  97. ULONG logSize = 4096*3;
  98. #endif
  99. KeInitializeSpinLock(&LogSpinLock);
  100. SerenumLStart = ExAllocatePoolWithTag(NonPagedPool, logSize, 'mneS');
  101. if (SerenumLStart) {
  102. SerenumLPtr = SerenumLStart;
  103. // Point the end (and first entry) 1 entry from the end of the segment
  104. SerenumLEnd = SerenumLStart + (logSize
  105. / sizeof(struct SERENUM_LOG_ENTRY))
  106. - 1;
  107. }
  108. return;
  109. }
  110. VOID
  111. SerenumLogFree(
  112. )
  113. /*++
  114. Routine Description:
  115. Arguments:
  116. Return Value:
  117. None.
  118. --*/
  119. {
  120. if (SerenumLStart) {
  121. ExFreePool(SerenumLStart);
  122. }
  123. return;
  124. }
  125. #endif // DBG