- Synchronize debug messages output to the serial port. Now each line of a debug log is printed synchronously, as it is NT. In future, this should be converted to a generic spinlock for all registered KD handlers.

svn path=/trunk/; revision=40285
This commit is contained in:
Aleksey Bragin 2009-03-29 13:15:03 +00:00
parent fea868eebc
commit df5b7d2582

View file

@ -21,6 +21,7 @@ BOOLEAN KdpLogInitialized;
CHAR DebugBuffer[BufferSize];
ULONG CurrentPosition;
WORK_QUEUE_ITEM KdpDebugLogQueue;
KSPIN_LOCK KdpSerialSpinLock;
BOOLEAN ItemQueued;
KD_PORT_INFORMATION SerialPortInfo = {DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_BAUD_RATE, 0};
@ -150,8 +151,27 @@ NTAPI
KdpSerialDebugPrint(LPSTR Message,
ULONG Length)
{
KIRQL OldIrql;
PCHAR pch = (PCHAR) Message;
/* Acquire the printing spinlock without waiting at raised IRQL */
while (TRUE)
{
/* Wait when the spinlock becomes available */
while (!KeTestSpinLock(&KdpSerialSpinLock));
/* Spinlock was free, raise irql */
KeRaiseIrql(HIGH_LEVEL, &OldIrql);
/* Try to get the spinlock */
if (KeTryToAcquireSpinLockAtDpcLevel(&KdpSerialSpinLock))
break;
/* Someone else got the spinlock, lower IRQL back */
KeLowerIrql(OldIrql);
}
/* Output the message */
while (*pch != 0)
{
if (*pch == '\n')
@ -161,6 +181,12 @@ KdpSerialDebugPrint(LPSTR Message,
KdPortPutByteEx(&SerialPortInfo, *pch);
pch++;
}
/* Release spinlock */
KiReleaseSpinLock(&KdpSerialSpinLock);
/* Lower IRQL */
KeLowerIrql(OldIrql);
}
VOID
@ -184,6 +210,9 @@ KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
}
KdComPortInUse = (PUCHAR)(ULONG_PTR)SerialPortInfo.BaseAddress;
/* Initialize spinlock */
KeInitializeSpinLock(&KdpSerialSpinLock);
/* Register as a Provider */
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);