- Allow shared read access to the debug.log file.
[reactos.git] / reactos / ntoskrnl / kd / dlog.c
index a0c4ec9..2bd3c10 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: dlog.c,v 1.10 2004/01/02 17:43:50 sedwards Exp $
+/* $Id: dlog.c,v 1.16 2004/09/01 00:15:08 navaraf Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
 
 /* INCLUDES ******************************************************************/
 
-#include <ddk/ntddk.h>
-#include <internal/ntoskrnl.h>
-#include <roscfg.h>
-#include <internal/kd.h>
-#include <ntos/minmax.h>
-#include <rosrtl/string.h>
+#include <ntoskrnl.h>
 
 /* GLOBALS *******************************************************************/
 
@@ -31,10 +26,42 @@ static ULONG DebugLogOverflow;
 static HANDLE DebugLogThreadHandle;
 static CLIENT_ID DebugLogThreadCid;
 static HANDLE DebugLogFile;
-static KSEMAPHORE DebugLogSem;
+static KEVENT DebugLogEvent;
 
 /* FUNCTIONS *****************************************************************/
 
+VOID
+DebugLogDumpMessages(VOID)
+{
+  static CHAR Buffer[256];
+  ULONG Offset;
+  ULONG Length;
+
+  if (!(KdDebugState & KD_DEBUG_BOOTLOG))
+    {
+      return;
+    }
+  KdDebugState &= ~KD_DEBUG_BOOTLOG;
+  Offset = (DebugLogEnd + 1) % DEBUGLOG_SIZE;
+  do
+    {
+      if (Offset <= DebugLogEnd)
+       {
+         Length = min(255, DebugLogEnd - Offset);
+       }
+      else
+       {
+         Length = min(255, DEBUGLOG_SIZE - Offset);
+       }
+      memcpy(Buffer, DebugLog + Offset, Length);
+      Buffer[Length] = 0;
+      DbgPrint(Buffer);
+      Offset = (Offset + Length) % DEBUGLOG_SIZE;
+    }
+  while (Length > 0);
+}
+
 VOID INIT_FUNCTION
 DebugLogInit(VOID)
 {
@@ -43,10 +70,10 @@ DebugLogInit(VOID)
   DebugLogEnd = 0;
   DebugLogOverflow = 0;
   DebugLogCount = 0;
-  KeInitializeSemaphore(&DebugLogSem, 0, 255);
+  KeInitializeEvent(&DebugLogEvent, NotificationEvent, FALSE);
 }
 
-VOID STDCALL_FUNC
+VOID STDCALL
 DebugLogThreadMain(PVOID Context)
 {
   KIRQL oldIrql;
@@ -56,11 +83,13 @@ DebugLogThreadMain(PVOID Context)
 
   for (;;)
     {
-      KeWaitForSingleObject(&DebugLogSem,
+      LARGE_INTEGER TimeOut;
+      TimeOut.QuadPart = -5000000; /* Half a second. */
+      KeWaitForSingleObject(&DebugLogEvent,
                            0,
                            KernelMode,
                            FALSE,
-                           NULL);
+                           &TimeOut);
       KeAcquireSpinLock(&DebugLogLock, &oldIrql);
       while (DebugLogCount > 0)
        {
@@ -103,6 +132,7 @@ DebugLogThreadMain(PVOID Context)
            }
          KeAcquireSpinLock(&DebugLogLock, &oldIrql);
        }
+      KeResetEvent(&DebugLogEvent);
       KeReleaseSpinLock(&DebugLogLock, oldIrql);
     }
 }
@@ -128,7 +158,7 @@ DebugLogInit2(VOID)
                        &Iosb,
                        NULL,
                        FILE_ATTRIBUTE_NORMAL,
-                       0,
+                       FILE_SHARE_READ,
                        FILE_SUPERSEDE,
                        FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT,
                        NULL,
@@ -167,7 +197,7 @@ DebugLogWrite(PCH String)
       KeReleaseSpinLock(&DebugLogLock, oldIrql);
       if (oldIrql < DISPATCH_LEVEL)
        {
-       KeReleaseSemaphore(&DebugLogSem, IO_NO_INCREMENT, 1, FALSE);
+         KeSetEvent(&DebugLogEvent, IO_NO_INCREMENT, FALSE);
        }
        return;
     }
@@ -184,7 +214,7 @@ DebugLogWrite(PCH String)
          KeReleaseSpinLock(&DebugLogLock, oldIrql);
          if (oldIrql < DISPATCH_LEVEL)
            {
-             KeReleaseSemaphore(&DebugLogSem, IO_NO_INCREMENT, 1, FALSE);
+             KeSetEvent(&DebugLogEvent, IO_NO_INCREMENT, FALSE);
            }
          return;
        }
@@ -195,7 +225,7 @@ DebugLogWrite(PCH String)
 
     if (oldIrql < DISPATCH_LEVEL)
     {
-      KeReleaseSemaphore(&DebugLogSem, IO_NO_INCREMENT, 1, FALSE);
+      KeSetEvent(&DebugLogEvent, IO_NO_INCREMENT, FALSE);
     }
 }