https://git.reactos.org/?p=reactos.git;a=commitdiff;h=412037a2e286585f36db223ed6523d8035cca2d3

commit 412037a2e286585f36db223ed6523d8035cca2d3
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Tue Mar 28 01:33:55 2023 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Tue Mar 28 02:42:53 2023 +0200

    [NTOS:KD] Use local print-like functions for output, instead of the 
kernel-internal KdpDprintf.
    
    Indeed, the latter won't be accessible once those KD IO functions
    get moved out into a separate KDTERM.DLL.
---
 ntoskrnl/kd/kd.h        | 16 +++++++--
 ntoskrnl/kd/kdio.c      | 87 ++++++++++++++++++++++++++++++++++++-------------
 ntoskrnl/kdbg/kdb_cli.c |  2 +-
 3 files changed, 79 insertions(+), 26 deletions(-)

diff --git a/ntoskrnl/kd/kd.h b/ntoskrnl/kd/kd.h
index 5672408d4c6..4440b183626 100644
--- a/ntoskrnl/kd/kd.h
+++ b/ntoskrnl/kd/kd.h
@@ -13,9 +13,19 @@ NTSTATUS
 typedef
 VOID
 (NTAPI *PKDP_PRINT_ROUTINE)(
-    PCHAR String,
-    ULONG Length
-);
+    _In_ PCCH String,
+    _In_ ULONG Length);
+
+VOID
+KdIoPuts(
+    _In_ PCSTR String);
+
+VOID
+__cdecl
+KdIoPrintf(
+    _In_ PCSTR Format,
+    ...);
+
 
 /* INIT ROUTINES *************************************************************/
 
diff --git a/ntoskrnl/kd/kdio.c b/ntoskrnl/kd/kdio.c
index f74106049a7..c8087e991ae 100644
--- a/ntoskrnl/kd/kdio.c
+++ b/ntoskrnl/kd/kdio.c
@@ -151,8 +151,9 @@ KdpLoggerThread(PVOID Context)
 
 static VOID
 NTAPI
-KdpPrintToLogFile(PCHAR String,
-                  ULONG Length)
+KdpPrintToLogFile(
+    _In_ PCCH String,
+    _In_ ULONG Length)
 {
     KIRQL OldIrql;
     ULONG beg, end, num;
@@ -359,10 +360,11 @@ Failure:
 
 static VOID
 NTAPI
-KdpSerialPrint(PCHAR String,
-               ULONG Length)
+KdpSerialPrint(
+    _In_ PCCH String,
+    _In_ ULONG Length)
 {
-    PCHAR pch = String;
+    PCCH pch = String;
     KIRQL OldIrql;
 
     /* Acquire the printing spinlock without waiting at raised IRQL */
@@ -376,7 +378,7 @@ KdpSerialPrint(PCHAR String,
             KdPortPutByteEx(&SerialPortInfo, '\r');
         }
         KdPortPutByteEx(&SerialPortInfo, *pch);
-        pch++;
+        ++pch;
     }
 
     /* Release the spinlock */
@@ -456,10 +458,11 @@ KdpScreenRelease(VOID)
 
 static VOID
 NTAPI
-KdpScreenPrint(PCHAR String,
-               ULONG Length)
+KdpScreenPrint(
+    _In_ PCCH String,
+    _In_ ULONG Length)
 {
-    PCHAR pch = String;
+    PCCH pch = String;
 
     while (pch < String + Length && *pch)
     {
@@ -538,6 +541,57 @@ KdpScreenInit(
 
 /* GENERAL FUNCTIONS *********************************************************/
 
+static VOID
+KdIoPrintString(
+    _In_ PCCH String,
+    _In_ ULONG Length)
+{
+    PLIST_ENTRY CurrentEntry;
+    PKD_DISPATCH_TABLE CurrentTable;
+
+    /* Call the registered providers */
+    for (CurrentEntry = KdProviders.Flink;
+         CurrentEntry != &KdProviders;
+         CurrentEntry = CurrentEntry->Flink)
+    {
+        CurrentTable = CONTAINING_RECORD(CurrentEntry,
+                                         KD_DISPATCH_TABLE,
+                                         KdProvidersList);
+
+        CurrentTable->KdpPrintRoutine(String, Length);
+    }
+}
+
+VOID
+KdIoPuts(
+    _In_ PCSTR String)
+{
+    KdIoPrintString(String, (ULONG)strlen(String));
+}
+
+VOID
+__cdecl
+KdIoPrintf(
+    _In_ PCSTR Format,
+    ...)
+{
+    va_list ap;
+    ULONG Length;
+    CHAR Buffer[512];
+
+    /* Format the string */
+    va_start(ap, Format);
+    Length = (ULONG)_vsnprintf(Buffer,
+                               sizeof(Buffer),
+                               Format,
+                               ap);
+    va_end(ap);
+
+    /* Send it to the display providers */
+    KdIoPrintString(Buffer, Length);
+}
+
+
 extern STRING KdbPromptString;
 
 VOID
@@ -551,8 +605,6 @@ KdSendPacket(
     if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
     {
         ULONG ApiNumber = ((PDBGKD_DEBUG_IO)MessageHeader->Buffer)->ApiNumber;
-        PLIST_ENTRY CurrentEntry;
-        PKD_DISPATCH_TABLE CurrentTable;
 
         /* Validate API call */
         if (MessageHeader->Length != sizeof(DBGKD_DEBUG_IO))
@@ -572,17 +624,8 @@ KdSendPacket(
         if (!KdpDebugMode.Value)
             return;
 
-        /* Call the registered providers */
-        for (CurrentEntry = KdProviders.Flink;
-             CurrentEntry != &KdProviders;
-             CurrentEntry = CurrentEntry->Flink)
-        {
-            CurrentTable = CONTAINING_RECORD(CurrentEntry,
-                                             KD_DISPATCH_TABLE,
-                                             KdProvidersList);
-
-            CurrentTable->KdpPrintRoutine(MessageData->Buffer, 
MessageData->Length);
-        }
+        /* Print the string proper */
+        KdIoPrintString(MessageData->Buffer, MessageData->Length);
         return;
     }
     else if (PacketType == PACKET_TYPE_KD_STATE_CHANGE64)
diff --git a/ntoskrnl/kdbg/kdb_cli.c b/ntoskrnl/kdbg/kdb_cli.c
index b50d18b692f..bbfca348fe2 100644
--- a/ntoskrnl/kdbg/kdb_cli.c
+++ b/ntoskrnl/kdbg/kdb_cli.c
@@ -3781,7 +3781,7 @@ KdbpCliInit(VOID)
 static VOID
 NTAPI
 KdbDebugPrint(
-    _In_ PCHAR String,
+    _In_ PCCH String,
     _In_ ULONG Length)
 {
     KIRQL OldIrql;

Reply via email to