The real, definitive, Visual C++ support branch. Accept no substitutes
[reactos.git] / ntoskrnl / kd64 / kdlock.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/kd64/kdlock.c
5 * PURPOSE: KD64 Port Lock and Breakin Support
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 /* PRIVATE FUNCTIONS *********************************************************/
16
17 VOID
18 NTAPI
19 KdpPortLock(VOID)
20 {
21 /* Acquire the lock */
22 KiAcquireSpinLock(&KdpDebuggerLock);
23 }
24
25 VOID
26 NTAPI
27 KdpPortUnlock(VOID)
28 {
29 /* Release the lock */
30 KiReleaseSpinLock(&KdpDebuggerLock);
31 }
32
33 BOOLEAN
34 NTAPI
35 KdpPollBreakInWithPortLock(VOID)
36 {
37 BOOLEAN DoBreak = FALSE;
38
39 /* First make sure that KD is enabled */
40 if (KdDebuggerEnabled)
41 {
42 /* Check if a CTRL-C is in the queue */
43 if (KdpContext.KdpControlCPending)
44 {
45 /* Set it and prepare for break */
46 DoBreak = TRUE;
47 KdpContext.KdpControlCPending = FALSE;
48 }
49 else
50 {
51 /* Now get a packet */
52 if (!KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
53 NULL,
54 NULL,
55 NULL,
56 NULL))
57 {
58 /* Successful breakin */
59 DoBreak = TRUE;
60 }
61 }
62 }
63
64 /* Tell the caller to do a break */
65 return DoBreak;
66 }
67
68 /* PUBLIC FUNCTIONS **********************************************************/
69
70 /*
71 * @implemented
72 */
73 BOOLEAN
74 NTAPI
75 KdPollBreakIn(VOID)
76 {
77 BOOLEAN DoBreak = FALSE;
78 ULONG Flags = 0;
79
80 /* First make sure that KD is enabled */
81 if (KdDebuggerEnabled)
82 {
83 /* Disable interrupts */
84 Ke386SaveFlags(Flags);
85 //Flags = __getcallerseflags();
86 _disable();
87
88 /* Check if a CTRL-C is in the queue */
89 if (KdpContext.KdpControlCPending)
90 {
91 /* Set it and prepare for break */
92 KdpControlCPressed = TRUE;
93 DoBreak = TRUE;
94 KdpContext.KdpControlCPending = FALSE;
95 }
96 else
97 {
98 /* Try to acquire the lock */
99 if (KeTryToAcquireSpinLockAtDpcLevel(&KdpDebuggerLock))
100 {
101 /* Now get a packet */
102 if (!KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
103 NULL,
104 NULL,
105 NULL,
106 NULL))
107 {
108 /* Successful breakin */
109 DoBreak = TRUE;
110 KdpControlCPressed = TRUE;
111 }
112
113 /* Let go of the port */
114 KdpPortUnlock();
115 }
116 }
117
118 /* Re-enable interrupts if they were disabled */
119 if (Flags & EFLAGS_INTERRUPT_MASK) _enable();
120 }
121
122 /* Tell the caller to do a break */
123 return DoBreak;
124 }
125