Author: fireball Date: Sun Mar 29 17:15:03 2009 New Revision: 40285
URL: http://svn.reactos.org/svn/reactos?rev=40285&view=rev Log: - 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.
Modified: trunk/reactos/ntoskrnl/kd/kdio.c
Modified: trunk/reactos/ntoskrnl/kd/kdio.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kd/kdio.c?rev=4028... ============================================================================== --- trunk/reactos/ntoskrnl/kd/kdio.c [iso-8859-1] (original) +++ trunk/reactos/ntoskrnl/kd/kdio.c [iso-8859-1] Sun Mar 29 17:15:03 2009 @@ -21,6 +21,7 @@ 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 @@ 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 @@ KdPortPutByteEx(&SerialPortInfo, *pch); pch++; } + + /* Release spinlock */ + KiReleaseSpinLock(&KdpSerialSpinLock); + + /* Lower IRQL */ + KeLowerIrql(OldIrql); }
VOID @@ -183,6 +209,9 @@ return; } KdComPortInUse = (PUCHAR)(ULONG_PTR)SerialPortInfo.BaseAddress; + + /* Initialize spinlock */ + KeInitializeSpinLock(&KdpSerialSpinLock);
/* Register as a Provider */ InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);