-/* $Id: dlog.c,v 1.6 2002/09/07 15:12:53 chorns 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
#include <ntoskrnl.h>
-#define NDEBUG
-#include <internal/debug.h>
-
-
/* GLOBALS *******************************************************************/
#define DEBUGLOG_SIZE (32*1024)
-#ifdef DBGPRINT_FILE_LOG
-
static CHAR DebugLog[DEBUGLOG_SIZE];
static ULONG DebugLogStart;
static ULONG DebugLogEnd;
static HANDLE DebugLogThreadHandle;
static CLIENT_ID DebugLogThreadCid;
static HANDLE DebugLogFile;
-static KSEMAPHORE DebugLogSem;
-
-#endif /* DBGPRINT_FILE_LOG */
+static KEVENT DebugLogEvent;
/* FUNCTIONS *****************************************************************/
-#ifdef DBGPRINT_FILE_LOG
-
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)
{
KeInitializeSpinLock(&DebugLogLock);
DebugLogEnd = 0;
DebugLogOverflow = 0;
DebugLogCount = 0;
- KeInitializeSemaphore(&DebugLogSem, 0, 255);
+ KeInitializeEvent(&DebugLogEvent, NotificationEvent, FALSE);
}
-NTSTATUS
+VOID STDCALL
DebugLogThreadMain(PVOID Context)
{
KIRQL oldIrql;
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)
{
{
WLen = min(256, DEBUGLOG_SIZE - DebugLogStart);
memcpy(Buffer, &DebugLog[DebugLogStart], WLen);
+ Buffer[WLen + 1] = '\n';
DebugLogStart =
(DebugLogStart + WLen) % DEBUGLOG_SIZE;
DebugLogCount = DebugLogCount - WLen;
NULL,
&Iosb,
Buffer,
- WLen,
+ WLen + 1,
NULL,
NULL);
}
else
{
- WLen = min(256, DebugLogEnd - DebugLogStart);
+ WLen = min(255, DebugLogEnd - DebugLogStart);
memcpy(Buffer, &DebugLog[DebugLogStart], WLen);
DebugLogStart =
(DebugLogStart + WLen) % DEBUGLOG_SIZE;
}
KeAcquireSpinLock(&DebugLogLock, &oldIrql);
}
+ KeResetEvent(&DebugLogEvent);
KeReleaseSpinLock(&DebugLogLock, oldIrql);
}
}
-VOID
+VOID INIT_FUNCTION
DebugLogInit2(VOID)
{
NTSTATUS Status;
UNICODE_STRING FileName;
IO_STATUS_BLOCK Iosb;
- RtlInitUnicodeStringFromLiteral(&FileName, L"\\SystemRoot\\debug.log");
+ RtlInitUnicodeString(&FileName, L"\\SystemRoot\\debug.log");
InitializeObjectAttributes(&ObjectAttributes,
&FileName,
0,
&Iosb,
NULL,
FILE_ATTRIBUTE_NORMAL,
- 0,
+ FILE_SHARE_READ,
FILE_SUPERSEDE,
FILE_WRITE_THROUGH | FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
NULL);
}
- VOID
- DebugLogWrite(PCH String)
- {
- KIRQL oldIrql;
+VOID
+DebugLogWrite(PCH String)
+{
+ KIRQL oldIrql;
if (KeGetCurrentIrql() > DISPATCH_LEVEL)
- {
- DebugLogOverflow++;
- return;
- }
+ {
+ DebugLogOverflow++;
+ return;
+ }
KeAcquireSpinLock(&DebugLogLock, &oldIrql);
if (DebugLogCount == DEBUGLOG_SIZE)
- {
- DebugLogOverflow++;
- KeReleaseSpinLock(&DebugLogLock, oldIrql);
- if (oldIrql < DISPATCH_LEVEL)
- {
- KeReleaseSemaphore(&DebugLogSem, IO_NO_INCREMENT, 1, FALSE);
- }
- return;
- }
+ {
+ DebugLogOverflow++;
+ KeReleaseSpinLock(&DebugLogLock, oldIrql);
+ if (oldIrql < DISPATCH_LEVEL)
+ {
+ KeSetEvent(&DebugLogEvent, IO_NO_INCREMENT, FALSE);
+ }
+ return;
+ }
while ((*String) != 0)
- {
- DebugLog[DebugLogEnd] = *String;
- String++;
- DebugLogCount++;
- if (DebugLogCount == DEBUGLOG_SIZE)
- {
- DebugLogOverflow++;
- KeReleaseSpinLock(&DebugLogLock, oldIrql);
- if (oldIrql < DISPATCH_LEVEL)
- {
- KeReleaseSemaphore(&DebugLogSem, IO_NO_INCREMENT, 1, FALSE);
- }
- return;
- }
- DebugLogEnd = (DebugLogEnd + 1) % DEBUGLOG_SIZE;
- }
-
- KeReleaseSpinLock(&DebugLogLock, oldIrql);
- if (oldIrql < DISPATCH_LEVEL)
- {
- KeReleaseSemaphore(&DebugLogSem, IO_NO_INCREMENT, 1, FALSE);
- }
- }
-
- #else /* not DBGPRINT_FILE_LOG */
-
- VOID
- DebugLogInit(VOID)
- {
- }
+ {
+ DebugLog[DebugLogEnd] = *String;
+ String++;
+ DebugLogCount++;
+
+ if (DebugLogCount == DEBUGLOG_SIZE)
+ {
+ DebugLogOverflow++;
+ KeReleaseSpinLock(&DebugLogLock, oldIrql);
+ if (oldIrql < DISPATCH_LEVEL)
+ {
+ KeSetEvent(&DebugLogEvent, IO_NO_INCREMENT, FALSE);
+ }
+ return;
+ }
+ DebugLogEnd = (DebugLogEnd + 1) % DEBUGLOG_SIZE;
+ }
-VOID
-DebugLogInit2(VOID)
-{
-}
+ KeReleaseSpinLock(&DebugLogLock, oldIrql);
-VOID
-DebugLogWrite(PCH String)
-{
+ if (oldIrql < DISPATCH_LEVEL)
+ {
+ KeSetEvent(&DebugLogEvent, IO_NO_INCREMENT, FALSE);
+ }
}
-#endif /* DBGPRINT_FILE_LOG */
-