[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.
This commit is contained in:
Hermès Bélusca-Maïto 2023-03-28 01:33:55 +02:00
parent 5d1ae45b83
commit 412037a2e2
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 79 additions and 26 deletions

View file

@ -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 *************************************************************/

View file

@ -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)

View file

@ -3781,7 +3781,7 @@ KdbpCliInit(VOID)
static VOID
NTAPI
KdbDebugPrint(
_In_ PCHAR String,
_In_ PCCH String,
_In_ ULONG Length)
{
KIRQL OldIrql;