https://git.reactos.org/?p=reactos.git;a=commitdiff;h=660948ce6ff39c89aca57…
commit 660948ce6ff39c89aca576f1b65dcd7e8e13c543
Author: Hervé Poussineau <hpoussin(a)reactos.org>
AuthorDate: Sat Mar 7 19:14:09 2020 +0100
Commit: Hervé Poussineau <hpoussin(a)reactos.org>
CommitDate: Mon Nov 16 08:55:03 2020 +0100
[NTOS:KD] Merge some more functions with kd64
Functions are KdIsThisAKdTrap, KdUpdateDataBlock, KdEnterDebugger,
KdExitDebugger, KdRefreshDebuggerNotPresent, KdDisableDebugger,
KdEnableDebuggerWithLock, KdEnableDebugger, KdSystemDebugControl
---
ntoskrnl/kd/kdmain.c | 226 +------------------------------------------------
ntoskrnl/kd64/kdapi.c | 99 ++++++++++++++++++++--
ntoskrnl/kd64/kdinit.c | 4 +-
ntoskrnl/kd64/kdtrap.c | 8 +-
4 files changed, 100 insertions(+), 237 deletions(-)
diff --git a/ntoskrnl/kd/kdmain.c b/ntoskrnl/kd/kdmain.c
index d411c83d53c..01827ee07fb 100644
--- a/ntoskrnl/kd/kdmain.c
+++ b/ntoskrnl/kd/kdmain.c
@@ -45,117 +45,13 @@
/* VARIABLES ***************************************************************/
-BOOLEAN KdDebuggerEnabled = FALSE;
-BOOLEAN KdEnteredDebugger = FALSE;
-BOOLEAN KdDebuggerNotPresent = TRUE;
-BOOLEAN KdBreakAfterSymbolLoad = FALSE;
-BOOLEAN KdPitchDebugger = TRUE;
-BOOLEAN KdIgnoreUmExceptions = FALSE;
-
VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads);
-#if 0
-ULONG Kd_DEFAULT_MASK = 1 << DPFLTR_ERROR_LEVEL;
-#endif
-
extern CPPORT PortInfo;
extern ANSI_STRING KdpLogFileName;
/* PRIVATE FUNCTIONS *********************************************************/
-ULONG
-NTAPI
-KdpServiceDispatcher(ULONG Service,
- PVOID Buffer1,
- ULONG Buffer1Length,
- KPROCESSOR_MODE PreviousMode)
-{
- ULONG Result = 0;
-
- switch (Service)
- {
- case BREAKPOINT_PRINT: /* DbgPrint */
- {
- /* Call KDBG */
- BOOLEAN Handled;
- Result = KdpPrint(MAXULONG,
- DPFLTR_INFO_LEVEL,
- (PCHAR)Buffer1,
- (USHORT)Buffer1Length,
- PreviousMode,
- NULL, // TrapFrame,
- NULL, // ExceptionFrame,
- &Handled);
- break;
- }
-
-#if DBG
- case ' soR': /* ROS-INTERNAL */
- {
- switch ((ULONG_PTR)Buffer1)
- {
- case DumpAllThreads:
- PspDumpThreads(TRUE);
- break;
-
- case DumpUserThreads:
- PspDumpThreads(FALSE);
- break;
-
- case KdSpare3:
- MmDumpArmPfnDatabase(FALSE);
- break;
-
- default:
- break;
- }
- break;
- }
-
-#if defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c
- /* Register a debug callback */
- case 'CsoR':
- {
- switch (Buffer1Length)
- {
- case ID_Win32PreServiceHook:
- KeWin32PreServiceHook = Buffer1;
- break;
-
- case ID_Win32PostServiceHook:
- KeWin32PostServiceHook = Buffer1;
- break;
-
- }
- break;
- }
-#endif
-
- /* Special case for stack frame dumps */
- case 'DsoR':
- {
- KeRosDumpStackFrames((PULONG_PTR)Buffer1, Buffer1Length);
- break;
- }
-
-#if defined(KDBG)
- /* Register KDBG CLI callback */
- case 'RbdK':
- {
- Result = KdbRegisterCliCallback(Buffer1, Buffer1Length);
- break;
- }
-#endif /* KDBG */
-#endif /* DBG */
- default:
- DPRINT1("Invalid debug service call!\n");
- HalDisplayString("Invalid debug service call!\r\n");
- break;
- }
-
- return Result;
-}
-
BOOLEAN
NTAPI
KdpTrap(IN PKTRAP_FRAME TrapFrame,
@@ -309,129 +205,9 @@ KdpStub(IN PKTRAP_FRAME TrapFrame,
SecondChanceException);
}
-BOOLEAN
-NTAPI
-KdIsThisAKdTrap(IN PEXCEPTION_RECORD ExceptionRecord,
- IN PCONTEXT Context,
- IN KPROCESSOR_MODE PreviousMode)
-{
- /* KDBG has its own mechanism for ignoring user mode exceptions */
- return FALSE;
-}
-
/* PUBLIC FUNCTIONS *********************************************************/
-VOID
-NTAPI
-KdUpdateDataBlock(VOID)
-{
-}
-
-BOOLEAN
-NTAPI
-KdEnterDebugger(IN PKTRAP_FRAME TrapFrame,
- IN PKEXCEPTION_FRAME ExceptionFrame)
-{
- return FALSE;
-}
-
-VOID
-NTAPI
-KdExitDebugger(IN BOOLEAN Enable)
-{
-}
-
-/*
- * @implemented
- */
-BOOLEAN
-NTAPI
-KdRefreshDebuggerNotPresent(VOID)
-{
- UNIMPLEMENTED;
-
- /* Just return whatever was set previously -- FIXME! */
- return KdDebuggerNotPresent;
-}
-
-/*
- * @implemented
- */
-NTSTATUS
-NTAPI
-KdDisableDebugger(VOID)
-{
- KIRQL OldIrql;
-
- /* Raise IRQL */
- KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
-
- /* TODO: Disable any breakpoints */
-
- /* Disable the Debugger */
- KdDebuggerEnabled = FALSE;
- SharedUserData->KdDebuggerEnabled = FALSE;
-
- /* Lower the IRQL */
- KeLowerIrql(OldIrql);
-
- /* Return success */
- return STATUS_SUCCESS;
-}
-
-NTSTATUS
-NTAPI
-KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
-{
- return STATUS_ACCESS_DENIED;
-}
-
-/*
- * @implemented
- */
-NTSTATUS
-NTAPI
-KdEnableDebugger(VOID)
-{
- KIRQL OldIrql;
-
- /* Raise IRQL */
- KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
-
- /* TODO: Re-enable any breakpoints */
-
- /* Enable the Debugger */
- KdDebuggerEnabled = TRUE;
- SharedUserData->KdDebuggerEnabled = TRUE;
-
- /* Lower the IRQL */
- KeLowerIrql(OldIrql);
-
- /* Return success */
- return STATUS_SUCCESS;
-}
-
-/*
- * @unimplemented
- */
-NTSTATUS
-NTAPI
-KdSystemDebugControl(IN SYSDBG_COMMAND Command,
- IN PVOID InputBuffer,
- IN ULONG InputBufferLength,
- OUT PVOID OutputBuffer,
- IN ULONG OutputBufferLength,
- IN OUT PULONG ReturnLength,
- IN KPROCESSOR_MODE PreviousMode)
-{
- /* HACK */
- return KdpServiceDispatcher(Command,
- InputBuffer,
- InputBufferLength,
- PreviousMode);
-}
-
-PCHAR
+static PCHAR
NTAPI
KdpGetDebugMode(PCHAR Currentp2)
{
diff --git a/ntoskrnl/kd64/kdapi.c b/ntoskrnl/kd64/kdapi.c
index 69fae2c450c..7e5b908a1e4 100644
--- a/ntoskrnl/kd64/kdapi.c
+++ b/ntoskrnl/kd64/kdapi.c
@@ -1874,12 +1874,14 @@ KdpQueryPerformanceCounter(IN PKTRAP_FRAME TrapFrame)
/* Otherwise, do the call */
return KeQueryPerformanceCounter(NULL);
}
+#endif
BOOLEAN
NTAPI
KdEnterDebugger(IN PKTRAP_FRAME TrapFrame,
IN PKEXCEPTION_FRAME ExceptionFrame)
{
+#ifdef _WINKD_
BOOLEAN Enable;
/* Check if we have a trap frame */
@@ -1926,12 +1928,16 @@ KdEnterDebugger(IN PKTRAP_FRAME TrapFrame,
/* Return if interrupts needs to be re-enabled */
return Enable;
+#else
+ return FALSE;
+#endif
}
VOID
NTAPI
KdExitDebugger(IN BOOLEAN Enable)
{
+#ifdef _WINKD_
ULONG TimeSlip;
/* Restore the state and unlock the port */
@@ -1961,12 +1967,14 @@ KdExitDebugger(IN BOOLEAN Enable)
InterlockedIncrement(&KdpTimeSlipPending);
KeInsertQueueDpc(&KdpTimeSlipDpc, NULL, NULL); // FIXME: this can trigger
context switches!
}
+#endif
}
NTSTATUS
NTAPI
KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
{
+#ifdef _WINKD_
KIRQL OldIrql;
#if defined(__GNUC__)
@@ -2037,12 +2045,31 @@ KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
/* We're done */
return STATUS_SUCCESS;
+#else
+ KIRQL OldIrql;
+
+ /* Raise IRQL */
+ KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+
+ /* TODO: Re-enable any breakpoints */
+
+ /* Enable the Debugger */
+ KdDebuggerEnabled = TRUE;
+ SharedUserData->KdDebuggerEnabled = TRUE;
+
+ /* Lower the IRQL */
+ KeLowerIrql(OldIrql);
+
+ /* Return success */
+ return STATUS_SUCCESS;
+#endif
}
NTSTATUS
NTAPI
KdDisableDebuggerWithLock(IN BOOLEAN NeedLock)
{
+#ifdef _WINKD_
KIRQL OldIrql;
NTSTATUS Status;
@@ -2127,13 +2154,32 @@ KdDisableDebuggerWithLock(IN BOOLEAN NeedLock)
/* We're done */
return STATUS_SUCCESS;
-}
+#else
+ KIRQL OldIrql;
-#endif // _WINKD_
+ if (!NeedLock)
+ {
+ return STATUS_ACCESS_DENIED;
+ }
-/* PUBLIC FUNCTIONS **********************************************************/
+ /* Raise IRQL */
+ KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
-#ifdef _WINKD_
+ /* TODO: Disable any breakpoints */
+
+ /* Disable the Debugger */
+ KdDebuggerEnabled = FALSE;
+ SharedUserData->KdDebuggerEnabled = FALSE;
+
+ /* Lower the IRQL */
+ KeLowerIrql(OldIrql);
+
+ /* Return success */
+ return STATUS_SUCCESS;
+#endif
+}
+
+/* PUBLIC FUNCTIONS **********************************************************/
/*
* @implemented
@@ -2174,6 +2220,21 @@ KdSystemDebugControl(
/* Handle some internal commands */
switch ((ULONG)Command)
{
+#ifndef _WINKD_
+ case BREAKPOINT_PRINT: /* DbgPrint */
+ {
+ /* Call KDBG */
+ BOOLEAN Handled;
+ return KdpPrint(MAXULONG,
+ DPFLTR_INFO_LEVEL,
+ (PCHAR)InputBuffer,
+ (USHORT)InputBufferLength,
+ PreviousMode,
+ NULL, // TrapFrame,
+ NULL, // ExceptionFrame,
+ &Handled);
+ }
+#endif
#if DBG
case ' soR': /* ROS-INTERNAL */
{
@@ -2197,12 +2258,38 @@ KdSystemDebugControl(
return STATUS_SUCCESS;
}
+#if defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c
+ /* Register a debug callback */
+ case 'CsoR':
+ {
+ switch (InputBufferLength)
+ {
+ case ID_Win32PreServiceHook:
+ KeWin32PreServiceHook = InputBuffer;
+ break;
+
+ case ID_Win32PostServiceHook:
+ KeWin32PostServiceHook = InputBuffer;
+ break;
+
+ }
+ break;
+ }
+#endif
+
/* Special case for stack frame dumps */
case 'DsoR':
{
KeRosDumpStackFrames((PULONG_PTR)InputBuffer, InputBufferLength);
break;
}
+#if defined(KDBG)
+ /* Register KDBG CLI callback */
+ case 'RbdK':
+ {
+ return KdbRegisterCliCallback(InputBuffer, InputBufferLength);
+ }
+#endif /* KDBG */
#endif
default:
break;
@@ -2212,7 +2299,6 @@ KdSystemDebugControl(
DbgPrint("KdSystemDebugControl is unimplemented!\n");
return STATUS_NOT_IMPLEMENTED;
}
-#endif
/*
* @implemented
@@ -2299,7 +2385,6 @@ KdPowerTransition(IN DEVICE_POWER_STATE NewState)
}
}
-#ifdef _WINKD_
/*
* @implemented
*/
@@ -2333,8 +2418,6 @@ KdRefreshDebuggerNotPresent(VOID)
return DebuggerNotPresent;
}
-#endif // _WINKD_
-
/*
* @implemented
*/
diff --git a/ntoskrnl/kd64/kdinit.c b/ntoskrnl/kd64/kdinit.c
index 55f96609759..e3767d4f49f 100644
--- a/ntoskrnl/kd64/kdinit.c
+++ b/ntoskrnl/kd64/kdinit.c
@@ -84,16 +84,16 @@ KdpPrintBanner(IN SIZE_T MemSizeMBs)
/* FUNCTIONS *****************************************************************/
-#ifdef _WINKD_
VOID
NTAPI
KdUpdateDataBlock(VOID)
{
+#ifdef _WINKD_
/* Update the KeUserCallbackDispatcher pointer */
KdDebuggerDataBlock.KeUserCallbackDispatcher =
(ULONG_PTR)KeUserCallbackDispatcher;
-}
#endif
+}
BOOLEAN
NTAPI
diff --git a/ntoskrnl/kd64/kdtrap.c b/ntoskrnl/kd64/kdtrap.c
index 7b7dd551223..c8cf539967f 100644
--- a/ntoskrnl/kd64/kdtrap.c
+++ b/ntoskrnl/kd64/kdtrap.c
@@ -312,6 +312,7 @@ KdpStub(IN PKTRAP_FRAME TrapFrame,
return FALSE;
}
}
+#endif
BOOLEAN
NTAPI
@@ -319,6 +320,7 @@ KdIsThisAKdTrap(IN PEXCEPTION_RECORD ExceptionRecord,
IN PCONTEXT Context,
IN KPROCESSOR_MODE PreviousMode)
{
+#ifdef _WINKD_
/*
* Determine if this is a valid debug service call and make sure that
* it isn't a software breakpoint
@@ -335,6 +337,8 @@ KdIsThisAKdTrap(IN PEXCEPTION_RECORD ExceptionRecord,
/* We don't have to handle it */
return FALSE;
}
-}
-
+#else
+ /* KDBG has its own mechanism for ignoring user mode exceptions */
+ return FALSE;
#endif
+}