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.

142 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. logger.c
  5. Abstract:
  6. This file contains the code for the debug logging facility.
  7. Author:
  8. Steve Wood (stevewo) 20-Jun-1992
  9. Environment:
  10. kernel mode callable only.
  11. Revision History:
  12. 20-Jun-1992 Steve Wood (stevewo) Created.
  13. --*/
  14. #include "exp.h"
  15. PEX_DEBUG_LOG
  16. ExCreateDebugLog(
  17. IN UCHAR MaximumNumberOfTags,
  18. IN ULONG MaximumNumberOfEvents
  19. )
  20. {
  21. PEX_DEBUG_LOG Log;
  22. ULONG Size;
  23. Size = sizeof( EX_DEBUG_LOG ) +
  24. (MaximumNumberOfTags *
  25. sizeof( EX_DEBUG_LOG_TAG )
  26. ) +
  27. (MaximumNumberOfEvents *
  28. sizeof( EX_DEBUG_LOG_EVENT )
  29. );
  30. Log = ExAllocatePoolWithTag( NonPagedPool, Size, 'oLbD' );
  31. if (Log != NULL) {
  32. RtlZeroMemory( Log, Size );
  33. KeInitializeSpinLock( &Log->Lock );
  34. Log->MaximumNumberOfTags = MaximumNumberOfTags;
  35. Log->Tags = (PEX_DEBUG_LOG_TAG)(Log + 1);
  36. Log->First = (PEX_DEBUG_LOG_EVENT)(Log->Tags + MaximumNumberOfTags);
  37. Log->Last = Log->First + MaximumNumberOfEvents;
  38. Log->Next = Log->First;
  39. }
  40. return Log;
  41. }
  42. UCHAR
  43. ExCreateDebugLogTag(
  44. IN PEX_DEBUG_LOG Log,
  45. IN PCHAR Name,
  46. IN UCHAR Format1,
  47. IN UCHAR Format2,
  48. IN UCHAR Format3,
  49. IN UCHAR Format4
  50. )
  51. {
  52. KIRQL OldIrql;
  53. ULONG Size;
  54. PEX_DEBUG_LOG_TAG Tag;
  55. UCHAR TagIndex;
  56. PCHAR CapturedName;
  57. Size = strlen( Name );
  58. CapturedName = ExAllocatePoolWithTag( NonPagedPool, Size, 'oLbD' );
  59. RtlCopyMemory( CapturedName, Name, Size + 1 );
  60. ExAcquireSpinLock( &Log->Lock, &OldIrql );
  61. if (Log->NumberOfTags < Log->MaximumNumberOfTags) {
  62. TagIndex = (UCHAR)(Log->NumberOfTags++);
  63. Tag = &Log->Tags[ TagIndex ];
  64. Tag->Name = CapturedName;
  65. Tag->Format[ 0 ] = Format1;
  66. Tag->Format[ 1 ] = Format2;
  67. Tag->Format[ 2 ] = Format3;
  68. Tag->Format[ 3 ] = Format4;
  69. CapturedName = NULL;
  70. }
  71. else {
  72. TagIndex = (UCHAR)0xFF;
  73. }
  74. ExReleaseSpinLock( &Log->Lock, OldIrql );
  75. if (CapturedName != NULL) {
  76. ExFreePool( CapturedName );
  77. }
  78. return TagIndex;
  79. }
  80. VOID
  81. ExDebugLogEvent(
  82. IN PEX_DEBUG_LOG Log,
  83. IN UCHAR Tag,
  84. IN ULONG Data1,
  85. IN ULONG Data2,
  86. IN ULONG Data3,
  87. IN ULONG Data4
  88. )
  89. {
  90. KIRQL OldIrql;
  91. PEX_DEBUG_LOG_EVENT p;
  92. PETHREAD Thread = PsGetCurrentThread();
  93. LARGE_INTEGER CurrentTime;
  94. KeQuerySystemTime( &CurrentTime );
  95. ExAcquireSpinLock( &Log->Lock, &OldIrql );
  96. p = Log->Next;
  97. if (p == Log->Last) {
  98. p = Log->First;
  99. }
  100. Log->Next = p + 1;
  101. p->ThreadId = Thread->Cid.UniqueThread;
  102. p->ProcessId = Thread->Cid.UniqueProcess;
  103. p->Time = CurrentTime.LowPart;
  104. p->Tag = Tag;
  105. p->Data[ 0 ] = Data1;
  106. p->Data[ 1 ] = Data2;
  107. p->Data[ 2 ] = Data3;
  108. p->Data[ 3 ] = Data4;
  109. ExReleaseSpinLock( &Log->Lock, OldIrql );
  110. return;
  111. }