[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 typedef
VOID VOID
(NTAPI *PKDP_PRINT_ROUTINE)( (NTAPI *PKDP_PRINT_ROUTINE)(
PCHAR String, _In_ PCCH String,
ULONG Length _In_ ULONG Length);
);
VOID
KdIoPuts(
_In_ PCSTR String);
VOID
__cdecl
KdIoPrintf(
_In_ PCSTR Format,
...);
/* INIT ROUTINES *************************************************************/ /* INIT ROUTINES *************************************************************/

View file

@ -151,8 +151,9 @@ KdpLoggerThread(PVOID Context)
static VOID static VOID
NTAPI NTAPI
KdpPrintToLogFile(PCHAR String, KdpPrintToLogFile(
ULONG Length) _In_ PCCH String,
_In_ ULONG Length)
{ {
KIRQL OldIrql; KIRQL OldIrql;
ULONG beg, end, num; ULONG beg, end, num;
@ -359,10 +360,11 @@ Failure:
static VOID static VOID
NTAPI NTAPI
KdpSerialPrint(PCHAR String, KdpSerialPrint(
ULONG Length) _In_ PCCH String,
_In_ ULONG Length)
{ {
PCHAR pch = String; PCCH pch = String;
KIRQL OldIrql; KIRQL OldIrql;
/* Acquire the printing spinlock without waiting at raised IRQL */ /* Acquire the printing spinlock without waiting at raised IRQL */
@ -376,7 +378,7 @@ KdpSerialPrint(PCHAR String,
KdPortPutByteEx(&SerialPortInfo, '\r'); KdPortPutByteEx(&SerialPortInfo, '\r');
} }
KdPortPutByteEx(&SerialPortInfo, *pch); KdPortPutByteEx(&SerialPortInfo, *pch);
pch++; ++pch;
} }
/* Release the spinlock */ /* Release the spinlock */
@ -456,10 +458,11 @@ KdpScreenRelease(VOID)
static VOID static VOID
NTAPI NTAPI
KdpScreenPrint(PCHAR String, KdpScreenPrint(
ULONG Length) _In_ PCCH String,
_In_ ULONG Length)
{ {
PCHAR pch = String; PCCH pch = String;
while (pch < String + Length && *pch) while (pch < String + Length && *pch)
{ {
@ -538,6 +541,57 @@ KdpScreenInit(
/* GENERAL FUNCTIONS *********************************************************/ /* 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; extern STRING KdbPromptString;
VOID VOID
@ -551,8 +605,6 @@ KdSendPacket(
if (PacketType == PACKET_TYPE_KD_DEBUG_IO) if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
{ {
ULONG ApiNumber = ((PDBGKD_DEBUG_IO)MessageHeader->Buffer)->ApiNumber; ULONG ApiNumber = ((PDBGKD_DEBUG_IO)MessageHeader->Buffer)->ApiNumber;
PLIST_ENTRY CurrentEntry;
PKD_DISPATCH_TABLE CurrentTable;
/* Validate API call */ /* Validate API call */
if (MessageHeader->Length != sizeof(DBGKD_DEBUG_IO)) if (MessageHeader->Length != sizeof(DBGKD_DEBUG_IO))
@ -572,17 +624,8 @@ KdSendPacket(
if (!KdpDebugMode.Value) if (!KdpDebugMode.Value)
return; return;
/* Call the registered providers */ /* Print the string proper */
for (CurrentEntry = KdProviders.Flink; KdIoPrintString(MessageData->Buffer, MessageData->Length);
CurrentEntry != &KdProviders;
CurrentEntry = CurrentEntry->Flink)
{
CurrentTable = CONTAINING_RECORD(CurrentEntry,
KD_DISPATCH_TABLE,
KdProvidersList);
CurrentTable->KdpPrintRoutine(MessageData->Buffer, MessageData->Length);
}
return; return;
} }
else if (PacketType == PACKET_TYPE_KD_STATE_CHANGE64) else if (PacketType == PACKET_TYPE_KD_STATE_CHANGE64)

View file

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