2009-10-12 03:35:35 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/kd64/kdlock.c
|
|
|
|
* PURPOSE: KD64 Port Lock and Breakin Support
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KdpPortLock(VOID)
|
|
|
|
{
|
|
|
|
/* Acquire the lock */
|
|
|
|
KiAcquireSpinLock(&KdpDebuggerLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
KdpPortUnlock(VOID)
|
|
|
|
{
|
|
|
|
/* Release the lock */
|
|
|
|
KiReleaseSpinLock(&KdpDebuggerLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KdpPollBreakInWithPortLock(VOID)
|
|
|
|
{
|
|
|
|
BOOLEAN DoBreak = FALSE;
|
|
|
|
|
|
|
|
/* First make sure that KD is enabled */
|
|
|
|
if (KdDebuggerEnabled)
|
|
|
|
{
|
|
|
|
/* Check if a CTRL-C is in the queue */
|
2009-10-22 15:25:37 +00:00
|
|
|
if (KdpContext.KdpControlCPending)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
/* Set it and prepare for break */
|
|
|
|
DoBreak = TRUE;
|
2009-10-22 15:25:37 +00:00
|
|
|
KdpContext.KdpControlCPending = FALSE;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Now get a packet */
|
|
|
|
if (KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
|
2009-11-02 17:45:51 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL) == KdPacketReceived)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
/* Successful breakin */
|
|
|
|
DoBreak = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tell the caller to do a break */
|
|
|
|
return DoBreak;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
KdPollBreakIn(VOID)
|
|
|
|
{
|
|
|
|
BOOLEAN DoBreak = FALSE, Enable;
|
|
|
|
|
|
|
|
/* First make sure that KD is enabled */
|
|
|
|
if (KdDebuggerEnabled)
|
|
|
|
{
|
|
|
|
/* Disable interrupts */
|
|
|
|
Enable = KeDisableInterrupts();
|
|
|
|
|
|
|
|
/* Check if a CTRL-C is in the queue */
|
2009-10-22 15:25:37 +00:00
|
|
|
if (KdpContext.KdpControlCPending)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
/* Set it and prepare for break */
|
|
|
|
KdpControlCPressed = TRUE;
|
|
|
|
DoBreak = TRUE;
|
2009-10-22 15:25:37 +00:00
|
|
|
KdpContext.KdpControlCPending = FALSE;
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-22 09:41:25 +00:00
|
|
|
KIRQL OldIrql;
|
2009-10-12 03:35:35 +00:00
|
|
|
/* Try to acquire the lock */
|
2021-06-22 09:41:25 +00:00
|
|
|
KeRaiseIrql(HIGH_LEVEL, &OldIrql);
|
2009-10-12 03:35:35 +00:00
|
|
|
if (KeTryToAcquireSpinLockAtDpcLevel(&KdpDebuggerLock))
|
|
|
|
{
|
|
|
|
/* Now get a packet */
|
|
|
|
if (KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
|
2009-11-02 17:45:51 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL) == KdPacketReceived)
|
2009-10-12 03:35:35 +00:00
|
|
|
{
|
|
|
|
/* Successful breakin */
|
|
|
|
DoBreak = TRUE;
|
|
|
|
KdpControlCPressed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Let go of the port */
|
|
|
|
KdpPortUnlock();
|
|
|
|
}
|
2021-06-22 09:41:25 +00:00
|
|
|
KeLowerIrql(OldIrql);
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-05 00:47:43 +00:00
|
|
|
/* Re-enable interrupts */
|
|
|
|
KeRestoreInterrupts(Enable);
|
2009-10-12 03:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tell the caller to do a break */
|
|
|
|
return DoBreak;
|
|
|
|
}
|