https://git.reactos.org/?p=reactos.git;a=commitdiff;h=430d7ebb93b75df103d4ebe2ab8ee3e6eac3ffe8

commit 430d7ebb93b75df103d4ebe2ab8ee3e6eac3ffe8
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Tue Mar 28 14:13:48 2023 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Tue Mar 28 16:14:39 2023 +0200

    [NTOS:KDBG] Use KdbpSendCommandSerial() to send specific ANSI escape 
sequences.
    
    Use this function instead of KdpDprintf(), otherwise, we send them to
    **ALL** the display providers, including for example dmesg. Replaying
    the listing with dmesg would then cause the terminal to misbehave later.
    For example, it would send the answer of a "Query Device Attributes"
    command, as the response to a query for terminal size...
---
 ntoskrnl/kd/kdserial.c  | 11 ++++++++++-
 ntoskrnl/kdbg/kdb.h     |  9 +++++++--
 ntoskrnl/kdbg/kdb_cli.c | 14 +++++---------
 3 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/ntoskrnl/kd/kdserial.c b/ntoskrnl/kd/kdserial.c
index bedfcde159c..d36b7abe559 100644
--- a/ntoskrnl/kd/kdserial.c
+++ b/ntoskrnl/kd/kdserial.c
@@ -13,8 +13,17 @@
 
 /* FUNCTIONS *****************************************************************/
 
+VOID
+KdbpSendCommandSerial(
+    _In_ PCSTR Command)
+{
+    while (*Command)
+        KdPortPutByteEx(&SerialPortInfo, *Command++);
+}
+
 CHAR
-KdbpTryGetCharSerial(ULONG Retry)
+KdbpTryGetCharSerial(
+    _In_ ULONG Retry)
 {
     CHAR Result = -1;
 
diff --git a/ntoskrnl/kdbg/kdb.h b/ntoskrnl/kdbg/kdb.h
index ac3f8b13004..bf8a47e5ec1 100644
--- a/ntoskrnl/kdbg/kdb.h
+++ b/ntoskrnl/kdbg/kdb.h
@@ -294,13 +294,18 @@ KdbpSafeWriteMemory(OUT PVOID Dest,
                     IN PVOID Src,
                     IN ULONG Bytes);
 
-#define KdbpGetCharKeyboard(ScanCode) KdbpTryGetCharKeyboard(ScanCode, 0)
+#define KdbpGetCharKeyboard(ScanCode) KdbpTryGetCharKeyboard((ScanCode), 0)
 CHAR
 KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry);
 
 #define KdbpGetCharSerial()  KdbpTryGetCharSerial(0)
 CHAR
-KdbpTryGetCharSerial(ULONG Retry);
+KdbpTryGetCharSerial(
+    _In_ ULONG Retry);
+
+VOID
+KdbpSendCommandSerial(
+    _In_ PCSTR Command);
 
 VOID
 KbdDisableMouse(VOID);
diff --git a/ntoskrnl/kdbg/kdb_cli.c b/ntoskrnl/kdbg/kdb_cli.c
index bbfca348fe2..ad28412fd91 100644
--- a/ntoskrnl/kdbg/kdb_cli.c
+++ b/ntoskrnl/kdbg/kdb_cli.c
@@ -2919,7 +2919,7 @@ KdbpPagerInternal(
         TerminalInitialized = TRUE;
 
         /* Enable line-wrap */
-        KdpDprintf("\x1b[?7h");
+        KdbpSendCommandSerial("\x1b[?7h");
 
         /*
          * Query terminal type.
@@ -2928,7 +2928,7 @@ KdbpPagerInternal(
          * string. Instead, use the VT52-compatible 'ESC Z' sequence or the
          * VT100-compatible 'ESC[c' one.
          */
-        KdpDprintf("\x1b[c");
+        KdbpSendCommandSerial("\x1b[c");
         KeStallExecutionProcessor(100000);
 
         Length = 0;
@@ -2967,7 +2967,7 @@ KdbpPagerInternal(
         {
             /* Try to query number of rows from terminal. A reply looks like 
"\x1b[8;24;80t" */
             TerminalReportsSize = FALSE;
-            KdpDprintf("\x1b[18t");
+            KdbpSendCommandSerial("\x1b[18t");
             KeStallExecutionProcessor(100000);
 
             c = KdbpTryGetCharSerial(5000);
@@ -3122,7 +3122,8 @@ KdbpPagerInternal(
                     p = CountOnePageUp(Buffer, BufLength, pBufEnd);
                     i = strcspn(p, "\n");
                 }
-                else if (ScanCode == KEYSC_PAGEUP || c == 'u')
+                else if (ScanCode == KEYSC_PAGEUP  ||
+                         ScanCode == KEYSC_ARROWUP || c == 'u')
                 {
                     p = CountOnePageUp(Buffer, BufLength, p);
                     i = strcspn(p, "\n");
@@ -3132,11 +3133,6 @@ KdbpPagerInternal(
                     p = Buffer;
                     i = strcspn(p, "\n");
                 }
-                else if (ScanCode == KEYSC_ARROWUP)
-                {
-                    p = CountOnePageUp(Buffer, BufLength, p);
-                    i = strcspn(p, "\n");
-                }
             }
 
             KdbNumberOfRowsPrinted = 0;

Reply via email to