Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1992-2001 Microsoft Corporation
  3. Module Name:
  4. kdlock.c
  5. Abstract:
  6. This module contains code to synchronize the usage of the port
  7. used by the kernel debugger.
  8. Author:
  9. Bryan M. Willman (bryanwi) 24-Sep-90
  10. Revision History:
  11. --*/
  12. #include "kdp.h"
  13. VOID
  14. KdpPortLock(
  15. VOID
  16. )
  17. /*++
  18. Routine Description:
  19. Acquire the spinlock for the debug port.
  20. Note that user must call this explicitly, the get/put routines
  21. do NOT make any use of the lock.
  22. CALLER MUST HAVE SET PROPER IRQL BEFORE CALLING US.
  23. We use KiAcquireSpinLock and NOT Ke... because our IRQL may
  24. be above DISPATCH_LEVEL.
  25. Arguments:
  26. None.
  27. Return value:
  28. None.
  29. --*/
  30. {
  31. KiAcquireSpinLock(&KdpDebuggerLock);
  32. }
  33. VOID
  34. KdpPortUnlock(
  35. VOID
  36. )
  37. /*++
  38. Routine Description:
  39. Release the spinlock for the debug port.
  40. Note that user must call this explicitly, the get/put routines
  41. do NOT make any use of the lock.
  42. CALLER MUST HAVE SET PROPER IRQL BEFORE CALLING US.
  43. We use KiReleaseSpinLock and NOT Ke... because our IRQL may
  44. be above DISPATCH_LEVEL.
  45. Arguments:
  46. None.
  47. Return value:
  48. None.
  49. --*/
  50. {
  51. KiReleaseSpinLock(&KdpDebuggerLock);
  52. }
  53. BOOLEAN
  54. KdPollBreakIn(
  55. VOID
  56. )
  57. /*++
  58. Routine Description:
  59. This procedure raises IRQL to high_level, seizes the Debug port
  60. spinlock, and checks to see if a breakin packet is pending.
  61. If a packet is present, return TRUE, else FALSE.
  62. A packet is present if:
  63. There is a valid character which matches BREAK_CHAR.
  64. N.B. Interrupts must be OFF around this call
  65. Return Value:
  66. TRUE if breakin sequence present, caller should execute int-3.
  67. FALSE if no breakin seen.
  68. --*/
  69. {
  70. BOOLEAN BreakIn;
  71. BOOLEAN Enable;
  72. ULONG Status;
  73. #if defined(_IA64_)
  74. KIRQL OldIrql;
  75. #endif
  76. //
  77. // If the debugger is enabled, see if a breakin by the kernel
  78. // debugger is pending.
  79. //
  80. BreakIn = FALSE;
  81. if (KdDebuggerEnabled != FALSE) {
  82. Enable = KeDisableInterrupts();
  83. #if defined(_IA64_)
  84. KeRaiseIrql(HIGH_LEVEL, &OldIrql);
  85. #endif
  86. if (KdpContext.KdpControlCPending != FALSE) {
  87. KdpControlCPressed = TRUE;
  88. BreakIn = TRUE;
  89. KdpContext.KdpControlCPending = FALSE;
  90. } else {
  91. if (KeTryToAcquireSpinLockAtDpcLevel(&KdpDebuggerLock) != FALSE) {
  92. Status = KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
  93. NULL,
  94. NULL,
  95. NULL,
  96. NULL);
  97. if (Status == KDP_PACKET_RECEIVED) {
  98. BreakIn = TRUE;
  99. KdpControlCPressed = TRUE;
  100. }
  101. KdpPortUnlock();
  102. }
  103. }
  104. #if defined(_IA64_)
  105. KeLowerIrql(OldIrql);
  106. #endif
  107. KeEnableInterrupts(Enable);
  108. }
  109. return BreakIn;
  110. }
  111. BOOLEAN
  112. KdpPollBreakInWithPortLock(
  113. VOID
  114. )
  115. /*++
  116. Routine Description:
  117. This procedure same as KdPollBreakIn, but assumes the caller
  118. already holds the port lock. Returns TRUE if a breakin packet
  119. is pending.
  120. A packet is present if:
  121. There is a valid character which matches BREAK_CHAR.
  122. N.B. Interrupts must be OFF around this call
  123. Return Value:
  124. TRUE if breakin sequence present, caller should execute int-3.
  125. FALSE if no breakin seen.
  126. --*/
  127. {
  128. BOOLEAN BreakIn;
  129. ULONG Status;
  130. //
  131. // If the debugger is enabled, see if a breakin by the kernel
  132. // debugger is pending.
  133. //
  134. BreakIn = FALSE;
  135. if (KdDebuggerEnabled != FALSE) {
  136. if (KdpContext.KdpControlCPending != FALSE) {
  137. BreakIn = TRUE;
  138. KdpContext.KdpControlCPending = FALSE;
  139. } else {
  140. Status = KdReceivePacket(PACKET_TYPE_KD_POLL_BREAKIN,
  141. NULL,
  142. NULL,
  143. NULL,
  144. NULL);
  145. if (Status == KDP_PACKET_RECEIVED) {
  146. BreakIn = TRUE;
  147. }
  148. }
  149. }
  150. return BreakIn;
  151. }