ReactOS 0.4.16-dev-297-gc569aee
kdio.c File Reference
#include <ntoskrnl.h>
#include <reactos/buildno.h>
#include "kd.h"
#include "kdterminal.h"
#include <debug.h>
Include dependency graph for kdio.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define KdpBufferSize   (1024 * 512)
 
#define KdpScreenLineLengthDefault   80
 

Functions

KIRQL NTAPI KdbpAcquireLock (_In_ PKSPIN_LOCK SpinLock)
 
VOID NTAPI KdbpReleaseLock (_In_ PKSPIN_LOCK SpinLock, _In_ KIRQL OldIrql)
 
static VOID NTAPI KdpLoggerThread (PVOID Context)
 
static VOID NTAPI KdpPrintToLogFile (_In_ PCCH String, _In_ ULONG Length)
 
NTSTATUS NTAPI KdpDebugLogInit (_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
 
static VOID NTAPI KdpSerialPrint (_In_ PCCH String, _In_ ULONG Length)
 
NTSTATUS NTAPI KdpSerialInit (_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
 
VOID KdpScreenAcquire (VOID)
 
VOID KdpScreenRelease (VOID)
 
static VOID NTAPI KdpScreenPrint (_In_ PCCH String, _In_ ULONG Length)
 
NTSTATUS NTAPI KdpScreenInit (_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
 
static VOID KdIoPrintString (_In_ PCCH String, _In_ ULONG Length)
 
VOID KdIoPuts (_In_ PCSTR String)
 
VOID __cdecl KdIoPrintf (_In_ PCSTR Format,...)
 
VOID NTAPI KdSendPacket (_In_ ULONG PacketType, _In_ PSTRING MessageHeader, _In_opt_ PSTRING MessageData, _Inout_ PKD_CONTEXT Context)
 
KDSTATUS NTAPI KdReceivePacket (_In_ ULONG PacketType, _Out_ PSTRING MessageHeader, _Out_ PSTRING MessageData, _Out_ PULONG DataLength, _Inout_ PKD_CONTEXT Context)
 

Variables

static BOOLEAN KdpLoggingEnabled = FALSE
 
static PCHAR KdpDebugBuffer = NULL
 
static volatile ULONG KdpCurrentPosition = 0
 
static volatile ULONG KdpFreeBytes = 0
 
static KSPIN_LOCK KdpDebugLogSpinLock
 
static KEVENT KdpLoggerThreadEvent
 
static HANDLE KdpLogFileHandle
 
ANSI_STRING KdpLogFileName = RTL_CONSTANT_STRING("\\SystemRoot\\debug.log")
 
static KSPIN_LOCK KdpSerialSpinLock
 
ULONG SerialPortNumber = DEFAULT_DEBUG_PORT
 
CPPORT SerialPortInfo = {0, DEFAULT_DEBUG_BAUD_RATE, 0}
 
static CHAR KdpScreenLineBuffer [KdpScreenLineLengthDefault+1] = ""
 
static ULONG KdpScreenLineBufferPos = 0
 
static ULONG KdpScreenLineLength = 0
 
KDP_DEBUG_MODE KdpDebugMode
 
LIST_ENTRY KdProviders = {&KdProviders, &KdProviders}
 
KD_DISPATCH_TABLE DispatchTable [KdMax] = {0}
 
PKDP_INIT_ROUTINE InitRoutines [KdMax]
 

Macro Definition Documentation

◆ KdpBufferSize

#define KdpBufferSize   (1024 * 512)

Definition at line 28 of file kdio.c.

◆ KdpScreenLineLengthDefault

#define KdpScreenLineLengthDefault   80

Definition at line 42 of file kdio.c.

◆ NDEBUG

#define NDEBUG

Definition at line 20 of file kdio.c.

Function Documentation

◆ KdbpAcquireLock()

KIRQL NTAPI KdbpAcquireLock ( _In_ PKSPIN_LOCK  SpinLock)

Definition at line 64 of file kdio.c.

66{
68
69 /* Acquire the spinlock without waiting at raised IRQL */
70 while (TRUE)
71 {
72 /* Loop until the spinlock becomes available */
73 while (!KeTestSpinLock(SpinLock));
74
75 /* Spinlock is free, raise IRQL to high level */
77
78 /* Try to get the spinlock */
80 break;
81
82 /* Someone else got the spinlock, lower IRQL back */
84 }
85
86 return OldIrql;
87}
#define TRUE
Definition: types.h:120
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define HIGH_LEVEL
Definition: env_spec_w32.h:703
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
BOOLEAN FASTCALL KeTestSpinLock(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:475
BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK SpinLock)
Definition: spinlock.c:309
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by KdbDebugPrint(), KdpPrintToLogFile(), and KdpSerialPrint().

◆ KdbpReleaseLock()

VOID NTAPI KdbpReleaseLock ( _In_ PKSPIN_LOCK  SpinLock,
_In_ KIRQL  OldIrql 
)

Definition at line 91 of file kdio.c.

94{
95 /* Release the spinlock */
97 // KeReleaseSpinLockFromDpcLevel(SpinLock);
98
99 /* Restore the old IRQL */
101}
VOID FASTCALL KiReleaseSpinLock(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:298

Referenced by KdbDebugPrint(), KdpPrintToLogFile(), and KdpSerialPrint().

◆ KdIoPrintf()

VOID __cdecl KdIoPrintf ( _In_ PCSTR  Format,
  ... 
)

Definition at line 576 of file kdio.c.

579{
580 va_list ap;
582 CHAR Buffer[512];
583
584 /* Format the string */
587 sizeof(Buffer),
588 Format,
589 ap);
590 va_end(ap);
591
592 /* Send it to the display providers */
594}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
Definition: bufpool.h:45
static VOID KdIoPrintString(_In_ PCCH String, _In_ ULONG Length)
Definition: kdio.c:547
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
uint32_t ULONG
Definition: typedefs.h:59
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
#define _vsnprintf
Definition: xmlstorage.h:202
char CHAR
Definition: xmlstorage.h:175

Referenced by KdIoReadLine(), KdReceivePacket(), and KdSendPacket().

◆ KdIoPrintString()

static VOID KdIoPrintString ( _In_ PCCH  String,
_In_ ULONG  Length 
)
static

Definition at line 547 of file kdio.c.

550{
551 PLIST_ENTRY CurrentEntry;
552 PKD_DISPATCH_TABLE CurrentTable;
553
554 /* Call the registered providers */
555 for (CurrentEntry = KdProviders.Flink;
556 CurrentEntry != &KdProviders;
557 CurrentEntry = CurrentEntry->Flink)
558 {
559 CurrentTable = CONTAINING_RECORD(CurrentEntry,
561 KdProvidersList);
562
563 CurrentTable->KdpPrintRoutine(String, Length);
564 }
565}
LIST_ENTRY KdProviders
Definition: kdio.c:47
PKDP_PRINT_ROUTINE KdpPrintRoutine
Definition: kd.h:115
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

Referenced by KdIoPrintf(), KdIoPuts(), KdReceivePacket(), and KdSendPacket().

◆ KdIoPuts()

VOID KdIoPuts ( _In_ PCSTR  String)

Definition at line 568 of file kdio.c.

570{
572}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269

Referenced by KdIoReadLine(), and KdReceivePacket().

◆ KdpDebugLogInit()

NTSTATUS NTAPI KdpDebugLogInit ( _In_ PKD_DISPATCH_TABLE  DispatchTable,
_In_ ULONG  BootPhase 
)

HACK for FILE_APPEND_DATA ** Remove once CORE-18789 is fixed. ** Enforce to go to the end of file

END OF HACK

Definition at line 197 of file kdio.c.

200{
202
203 if (!KdpDebugMode.File)
205
206 if (BootPhase == 0)
207 {
208 /* Write out the functions that we support for now */
209 DispatchTable->KdpPrintRoutine = KdpPrintToLogFile;
210
211 /* Register for BootPhase 1 initialization and as a Provider */
212 DispatchTable->KdpInitRoutine = KdpDebugLogInit;
213 InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
214 }
215 else if (BootPhase == 1)
216 {
217 /* Allocate a buffer for debug log */
220 TAG_KDBG);
221 if (!KdpDebugBuffer)
222 {
224 RemoveEntryList(&DispatchTable->KdProvidersList);
225 return STATUS_NO_MEMORY;
226 }
228
229 /* Initialize spinlock */
231
232 /* Register for later BootPhase 2 reinitialization */
233 DispatchTable->KdpInitRoutine = KdpDebugLogInit;
234
235 /* Announce ourselves */
236 HalDisplayString(" File log debugging enabled\r\n");
237 }
238 else if (BootPhase >= 2)
239 {
243 HANDLE ThreadHandle;
245
246 /* If we have already successfully opened the log file, bail out */
247 if (KdpLogFileHandle != NULL)
248 return STATUS_SUCCESS;
249
250 /* Setup the log name */
252 if (!NT_SUCCESS(Status))
253 goto Failure;
254
256 &FileName,
258 NULL,
259 NULL);
260
261 /* Create the log file */
262 Status = ZwCreateFile(&KdpLogFileHandle,
265 &Iosb,
266 NULL,
272 NULL,
273 0);
274
276
277 if (!NT_SUCCESS(Status))
278 {
279 DPRINT1("Failed to open log file: 0x%08lx\n", Status);
280
281 /* Schedule an I/O reinitialization if needed */
284 {
285 DispatchTable->KdpInitRoutine = KdpDebugLogInit;
286 return Status;
287 }
288 goto Failure;
289 }
290
294 {
296 FILE_POSITION_INFORMATION FilePosInfo;
297
298 Status = ZwQueryInformationFile(KdpLogFileHandle,
299 &Iosb,
300 &FileInfo,
301 sizeof(FileInfo),
303 DPRINT("Status: 0x%08lx - EOF offset: %I64d\n",
304 Status, FileInfo.EndOfFile.QuadPart);
305
306 Status = ZwQueryInformationFile(KdpLogFileHandle,
307 &Iosb,
308 &FilePosInfo,
309 sizeof(FilePosInfo),
311 DPRINT("Status: 0x%08lx - Position: %I64d\n",
312 Status, FilePosInfo.CurrentByteOffset.QuadPart);
313
314 FilePosInfo.CurrentByteOffset.QuadPart = FileInfo.EndOfFile.QuadPart;
315 Status = ZwSetInformationFile(KdpLogFileHandle,
316 &Iosb,
317 &FilePosInfo,
318 sizeof(FilePosInfo),
320 DPRINT("ZwSetInformationFile(FilePositionInfo) returned: 0x%08lx\n", Status);
321 }
325
326 /* Create the logger thread */
327 Status = PsCreateSystemThread(&ThreadHandle,
329 NULL,
330 NULL,
331 NULL,
333 NULL);
334 if (!NT_SUCCESS(Status))
335 {
336 DPRINT1("Failed to create log file thread: 0x%08lx\n", Status);
338 goto Failure;
339 }
340
342 ZwSetInformationThread(ThreadHandle,
344 &Priority,
345 sizeof(Priority));
346
347 ZwClose(ThreadHandle);
348 return Status;
349
350Failure:
351 KdpFreeBytes = 0;
355 RemoveEntryList(&DispatchTable->KdProvidersList);
356 }
357
358 return Status;
359}
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define DPRINT1
Definition: precomp.h:8
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
@ ThreadPriority
Definition: compat.h:937
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
LONG KPRIORITY
Definition: compat.h:803
#define FILE_SHARE_READ
Definition: compat.h:136
return Iosb
Definition: create.c:4402
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NonPagedPool
Definition: env_spec_w32.h:307
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
struct _FileName FileName
Definition: fatprocs.h:897
@ FilePositionInformation
Definition: from_kernel.h:75
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_WRITE_THROUGH
Definition: from_kernel.h:26
#define FILE_OPEN_IF
Definition: from_kernel.h:56
#define FILE_SEQUENTIAL_ONLY
Definition: from_kernel.h:27
Status
Definition: gdiplustypes.h:25
NTHALAPI VOID NTAPI HalDisplayString(PUCHAR String)
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define HIGH_PRIORITY
static VOID NTAPI KdpLoggerThread(PVOID Context)
Definition: kdio.c:107
static volatile ULONG KdpFreeBytes
Definition: kdio.c:32
static HANDLE KdpLogFileHandle
Definition: kdio.c:35
KDP_DEBUG_MODE KdpDebugMode
Definition: kdio.c:46
#define KdpBufferSize
Definition: kdio.c:28
static PCHAR KdpDebugBuffer
Definition: kdio.c:30
NTSTATUS NTAPI KdpDebugLogInit(_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
Definition: kdio.c:197
static KSPIN_LOCK KdpDebugLogSpinLock
Definition: kdio.c:33
static KEVENT KdpLoggerThreadEvent
Definition: kdio.c:34
ANSI_STRING KdpLogFileName
Definition: kdio.c:36
static VOID NTAPI KdpPrintToLogFile(_In_ PCCH String, _In_ ULONG Length)
Definition: kdio.c:156
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
FORCEINLINE PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define FILE_APPEND_DATA
Definition: nt_native.h:634
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
@ SynchronizationEvent
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define STATUS_PORT_DISCONNECTED
Definition: ntstatus.h:291
#define FileStandardInformation
Definition: propsheet.cpp:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
LARGE_INTEGER CurrentByteOffset
Definition: nt_native.h:955
UCHAR File
Definition: kd.h:102
#define TAG_KDBG
Definition: tag.h:38
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:655
_In_ PWDFDEVICE_INIT _In_ PWDF_PDO_EVENT_CALLBACKS DispatchTable
Definition: wdfpdo.h:248

Referenced by KdpDebugLogInit().

◆ KdpLoggerThread()

static VOID NTAPI KdpLoggerThread ( PVOID  Context)
static

Definition at line 107 of file kdio.c.

108{
109 ULONG beg, end, num;
111
113
115
116 while (TRUE)
117 {
119
120 /* Bug */
121 /* Keep KdpCurrentPosition and KdpFreeBytes values in local
122 * variables to avoid their possible change from Producer part,
123 * KdpPrintToLogFile function
124 */
127
128 /* Now securely calculate values, based on local variables */
129 beg = (end + num) % KdpBufferSize;
131
132 /* Nothing to do? */
133 if (num == 0)
134 continue;
135
136 if (end > beg)
137 {
139 KdpDebugBuffer + beg, num, NULL, NULL);
140 }
141 else
142 {
144 KdpDebugBuffer + beg, KdpBufferSize - beg, NULL, NULL);
145
148 }
149
151 }
152}
#define VOID
Definition: acefi.h:82
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define ExGetPreviousMode
Definition: ex.h:140
#define InterlockedExchangeAddUL(Addend, Value)
Definition: ex.h:1533
GLuint GLuint end
Definition: gl.h:1545
GLuint GLuint num
Definition: glext.h:9618
static BOOLEAN KdpLoggingEnabled
Definition: kdio.c:29
static volatile ULONG KdpCurrentPosition
Definition: kdio.c:31
#define ASSERT(a)
Definition: mode.c:44
#define KernelMode
Definition: asm.h:34
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
@ Executive
Definition: ketypes.h:415

Referenced by KdpDebugLogInit().

◆ KdpPrintToLogFile()

static VOID NTAPI KdpPrintToLogFile ( _In_ PCCH  String,
_In_ ULONG  Length 
)
static

Definition at line 156 of file kdio.c.

159{
161 ULONG beg, end, num;
162
163 if (KdpDebugBuffer == NULL) return;
164
165 /* Acquire the printing spinlock without waiting at raised IRQL */
167
168 beg = KdpCurrentPosition;
170 if (num != 0)
171 {
172 end = (beg + num) % KdpBufferSize;
174 KdpFreeBytes -= num;
175
176 if (end > beg)
177 {
179 }
180 else
181 {
184 }
185 }
186
187 /* Release the spinlock */
189
190 /* Signal the logger thread */
193}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI KdbpReleaseLock(_In_ PKSPIN_LOCK SpinLock, _In_ KIRQL OldIrql)
Definition: kdio.c:91
KIRQL NTAPI KdbpAcquireLock(_In_ PKSPIN_LOCK SpinLock)
Definition: kdio.c:64
#define min(a, b)
Definition: monoChain.cc:55
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by KdpDebugLogInit().

◆ KdpScreenAcquire()

VOID KdpScreenAcquire ( VOID  )

Definition at line 431 of file kdio.c.

432{
433 if (InbvIsBootDriverInstalled() /* &&
434 !InbvCheckDisplayOwnership() */)
435 {
436 /* Acquire ownership and reset the display */
444 }
445}
VOID NTAPI InbvAcquireDisplayOwnership(VOID)
Definition: inbv.c:290
VOID NTAPI InbvInstallDisplayStringFilter(_In_ INBV_DISPLAY_STRING_FILTER DisplayFilter)
Definition: inbv.c:387
VOID NTAPI InbvSetTextColor(_In_ ULONG Color)
Definition: inbv.c:460
BOOLEAN NTAPI InbvEnableDisplayString(_In_ BOOLEAN Enable)
Definition: inbv.c:370
BOOLEAN NTAPI InbvResetDisplay(VOID)
Definition: inbv.c:431
VOID NTAPI InbvSetScrollRegion(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom)
Definition: inbv.c:448
VOID NTAPI InbvSolidColorFill(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Right, _In_ ULONG Bottom, _In_ ULONG Color)
Definition: inbv.c:485
BOOLEAN NTAPI InbvIsBootDriverInstalled(VOID)
Definition: inbv.c:396
#define SCREEN_WIDTH
Definition: pc98video.c:27
#define SCREEN_HEIGHT
Definition: pc98video.c:28
#define BV_COLOR_WHITE
Definition: display.h:30
#define BV_COLOR_BLACK
Definition: display.h:15

Referenced by KdbpInternalEnter(), and KdpScreenInit().

◆ KdpScreenInit()

NTSTATUS NTAPI KdpScreenInit ( _In_ PKD_DISPATCH_TABLE  DispatchTable,
_In_ ULONG  BootPhase 
)

Definition at line 515 of file kdio.c.

518{
519 if (!KdpDebugMode.Screen)
521
522 if (BootPhase == 0)
523 {
524 /* Write out the functions that we support for now */
525 DispatchTable->KdpPrintRoutine = KdpScreenPrint;
526
527 /* Register for BootPhase 1 initialization and as a Provider */
528 DispatchTable->KdpInitRoutine = KdpScreenInit;
529 InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
530 }
531 else if (BootPhase == 1)
532 {
533 /* Take control of the display */
535
536 /* Announce ourselves */
537 HalDisplayString(" Screen debugging enabled\r\n");
538 }
539
540 return STATUS_SUCCESS;
541}
NTSTATUS NTAPI KdpScreenInit(_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
Definition: kdio.c:515
VOID KdpScreenAcquire(VOID)
Definition: kdio.c:431
static VOID NTAPI KdpScreenPrint(_In_ PCCH String, _In_ ULONG Length)
Definition: kdio.c:463
UCHAR Screen
Definition: kd.h:100

Referenced by KdpScreenInit().

◆ KdpScreenPrint()

static VOID NTAPI KdpScreenPrint ( _In_ PCCH  String,
_In_ ULONG  Length 
)
static

Definition at line 463 of file kdio.c.

466{
467 PCCH pch = String;
468
469 while (pch < String + Length && *pch)
470 {
471 if (*pch == '\b')
472 {
473 /* HalDisplayString does not support '\b'. Workaround it and use '\r' */
474 if (KdpScreenLineLength > 0)
475 {
476 /* Remove last character from buffer */
479
480 /* Clear row and print line again */
481 HalDisplayString("\r");
483 }
484 }
485 else
486 {
489 }
490
492 {
493 /* Print buffered characters */
496
497 /* Clear line buffer */
498 KdpScreenLineBuffer[0] = '\0';
500 }
501
502 ++pch;
503 }
504
505 /* Print buffered characters */
507 {
510 }
511}
static ULONG KdpScreenLineBufferPos
Definition: kdio.c:44
static CHAR KdpScreenLineBuffer[KdpScreenLineLengthDefault+1]
Definition: kdio.c:43
static ULONG KdpScreenLineLength
Definition: kdio.c:44
#define KdpScreenLineLengthDefault
Definition: kdio.c:42
#define pch(ap)
Definition: match.c:418
CONST CHAR * PCCH
Definition: ntbasedef.h:400

Referenced by KdpScreenInit().

◆ KdpScreenRelease()

VOID KdpScreenRelease ( VOID  )

Definition at line 450 of file kdio.c.

451{
454 {
455 /* Release the display */
456 // InbvSetDisplayOwnership(FALSE);
458 }
459}
VOID NTAPI InbvNotifyDisplayOwnershipLost(_In_ INBV_RESET_DISPLAY_PARAMETERS Callback)
Definition: inbv.c:404
BOOLEAN NTAPI InbvCheckDisplayOwnership(VOID)
Definition: inbv.c:316

Referenced by KdbpInternalEnter().

◆ KdpSerialInit()

NTSTATUS NTAPI KdpSerialInit ( _In_ PKD_DISPATCH_TABLE  DispatchTable,
_In_ ULONG  BootPhase 
)

Definition at line 392 of file kdio.c.

395{
396 if (!KdpDebugMode.Serial)
398
399 if (BootPhase == 0)
400 {
401 /* Write out the functions that we support for now */
402 DispatchTable->KdpPrintRoutine = KdpSerialPrint;
403
404 /* Initialize the Port */
406 {
409 }
411
412 /* Initialize spinlock */
414
415 /* Register for BootPhase 1 initialization and as a Provider */
416 DispatchTable->KdpInitRoutine = KdpSerialInit;
417 InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
418 }
419 else if (BootPhase == 1)
420 {
421 /* Announce ourselves */
422 HalDisplayString(" Serial debugging enabled\r\n");
423 }
424
425 return STATUS_SUCCESS;
426}
PUCHAR KdComPortInUse
Definition: usage.c:17
BOOLEAN NTAPI KdPortInitializeEx(PCPPORT PortInformation, ULONG ComPortNumber)
ULONG SerialPortNumber
Definition: kdio.c:39
NTSTATUS NTAPI KdpSerialInit(_In_ PKD_DISPATCH_TABLE DispatchTable, _In_ ULONG BootPhase)
Definition: kdio.c:392
static KSPIN_LOCK KdpSerialSpinLock
Definition: kdio.c:38
CPPORT SerialPortInfo
Definition: kdio.c:40
static VOID NTAPI KdpSerialPrint(_In_ PCCH String, _In_ ULONG Length)
Definition: kdio.c:365
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
PUCHAR Address
Definition: cportlib.h:29
UCHAR Serial
Definition: kd.h:101

Referenced by KdpSerialInit().

◆ KdpSerialPrint()

static VOID NTAPI KdpSerialPrint ( _In_ PCCH  String,
_In_ ULONG  Length 
)
static

Definition at line 365 of file kdio.c.

368{
369 PCCH pch = String;
371
372 /* Acquire the printing spinlock without waiting at raised IRQL */
374
375 /* Output the string */
376 while (pch < String + Length && *pch)
377 {
378 if (*pch == '\n')
379 {
381 }
383 ++pch;
384 }
385
386 /* Release the spinlock */
388}
VOID NTAPI KdPortPutByteEx(PCPPORT PortInformation, UCHAR ByteToSend)

Referenced by KdpSerialInit().

◆ KdReceivePacket()

KDSTATUS NTAPI KdReceivePacket ( _In_ ULONG  PacketType,
_Out_ PSTRING  MessageHeader,
_Out_ PSTRING  MessageData,
_Out_ PULONG  DataLength,
_Inout_ PKD_CONTEXT  Context 
)

Definition at line 642 of file kdio.c.

648{
649#ifdef KDBG
650 PDBGKD_DEBUG_IO DebugIo;
651 STRING ResponseString;
652 CHAR MessageBuffer[512];
653#endif
654
655 if (PacketType != PACKET_TYPE_KD_DEBUG_IO)
656 {
657 KdIoPrintf("%s: PacketType %d is UNIMPLEMENTED\n", __FUNCTION__, PacketType);
658 return KdPacketTimedOut;
659 }
660
661#ifdef KDBG
662 DebugIo = (PDBGKD_DEBUG_IO)MessageHeader->Buffer;
663
664 /* Validate API call */
665 if (MessageHeader->MaximumLength != sizeof(DBGKD_DEBUG_IO))
666 return KdPacketNeedsResend;
667 if (DebugIo->ApiNumber != DbgKdGetStringApi)
668 return KdPacketNeedsResend;
669
670 /* NOTE: We cannot use directly MessageData->Buffer here as it points
671 * to the temporary KdpMessageBuffer scratch buffer that is being
672 * shared with all the possible I/O KD operations that may happen. */
673 ResponseString.Buffer = MessageBuffer;
674 ResponseString.Length = 0;
675 ResponseString.MaximumLength = min(sizeof(MessageBuffer),
676 MessageData->MaximumLength);
677 ResponseString.MaximumLength = min(ResponseString.MaximumLength,
679
680 /* The prompt string has been printed by KdSendPacket; go to
681 * new line and print the kdb prompt -- for SYSREG2 support. */
682 KdIoPrintString("\n", 1);
683 KdIoPuts(KdbPromptStr.Buffer); // Alternatively, use "Input> "
684
687
688 /*
689 * Read a NULL-terminated line of user input and retrieve its length.
690 * Official documentation states that DbgPrompt() includes a terminating
691 * newline character but does not NULL-terminate. However, experiments
692 * show that this behaviour is left at the discretion of WinDbg itself.
693 * WinDbg NULL-terminates the string unless its buffer is too short,
694 * in which case the string is simply truncated without NULL-termination.
695 */
696 ResponseString.Length =
697 (USHORT)KdIoReadLine(ResponseString.Buffer,
698 ResponseString.MaximumLength);
699
702
703 /* Adjust and return the string length */
704 *DataLength = min(ResponseString.Length + sizeof(ANSI_NULL),
706 MessageData->Length = DebugIo->u.GetString.LengthOfStringRead = *DataLength;
707
708 /* Only now we can copy back the data into MessageData->Buffer */
709 RtlCopyMemory(MessageData->Buffer, ResponseString.Buffer, *DataLength);
710#endif
711
712 return KdPacketReceived;
713}
_In_ ULONG _In_opt_ WDFREQUEST _In_opt_ PVOID _In_ size_t _In_ PVOID _In_ size_t _Out_ size_t * DataLength
Definition: cdrom.h:1444
#define __FUNCTION__
Definition: types.h:116
std::wstring STRING
Definition: fontsub.cpp:33
SIZE_T KdIoReadLine(_Out_ PCHAR Buffer, _In_ SIZE_T Size)
Reads a line of user input from the terminal.
Definition: kdprompt.c:51
const CSTRING KdbPromptStr
Definition: kdb_cli.c:149
VOID __cdecl KdIoPrintf(_In_ PCSTR Format,...)
Definition: kdio.c:576
VOID KdIoPuts(_In_ PCSTR String)
Definition: kdio.c:568
VOID KbdDisableMouse(VOID)
Definition: kdps2kbd.c:98
VOID KbdEnableMouse(VOID)
Definition: kdps2kbd.c:93
ULONG KdbDebugState
Definition: kdterminal.c:32
@ KD_DEBUG_KDSERIAL
Definition: kdterminal.h:36
if(dx< 0)
Definition: linetemp.h:194
#define ANSI_NULL
unsigned short USHORT
Definition: pedump.c:61
#define KdPacketReceived
Definition: kddll.h:5
#define KdPacketNeedsResend
Definition: kddll.h:7
#define KdPacketTimedOut
Definition: kddll.h:6
CONST CHAR * Buffer
Definition: umtypes.h:159
union _DBGKD_DEBUG_IO::@3545 u
DBGKD_GET_STRING GetString
Definition: windbgkd.h:427
ULONG ApiNumber
Definition: windbgkd.h:421
ULONG LengthOfStringRead
Definition: windbgkd.h:413
#define DbgKdGetStringApi
Definition: windbgkd.h:123
struct _DBGKD_DEBUG_IO * PDBGKD_DEBUG_IO
#define PACKET_TYPE_KD_DEBUG_IO
Definition: windbgkd.h:44

◆ KdSendPacket()

VOID NTAPI KdSendPacket ( _In_ ULONG  PacketType,
_In_ PSTRING  MessageHeader,
_In_opt_ PSTRING  MessageData,
_Inout_ PKD_CONTEXT  Context 
)

Definition at line 602 of file kdio.c.

607{
608 PDBGKD_DEBUG_IO DebugIo;
609
610 if (PacketType != PACKET_TYPE_KD_DEBUG_IO)
611 {
612 KdIoPrintf("%s: PacketType %d is UNIMPLEMENTED\n", __FUNCTION__, PacketType);
613 return;
614 }
615
616 DebugIo = (PDBGKD_DEBUG_IO)MessageHeader->Buffer;
617
618 /* Validate API call */
619 if (MessageHeader->Length != sizeof(DBGKD_DEBUG_IO))
620 return;
621 if ((DebugIo->ApiNumber != DbgKdPrintStringApi) &&
622 (DebugIo->ApiNumber != DbgKdGetStringApi))
623 {
624 return;
625 }
626 if (!MessageData)
627 return;
628
629 /* NOTE: MessageData->Length should be equal to
630 * DebugIo.u.PrintString.LengthOfString, or to
631 * DebugIo.u.GetString.LengthOfPromptString */
632
633 if (!KdpDebugMode.Value)
634 return;
635
636 /* Print the string proper */
637 KdIoPrintString(MessageData->Buffer, MessageData->Length);
638}
ULONG Value
Definition: kd.h:106
#define DbgKdPrintStringApi
Definition: windbgkd.h:122

Variable Documentation

◆ DispatchTable

Definition at line 48 of file kdio.c.

◆ InitRoutines

PKDP_INIT_ROUTINE InitRoutines[KdMax]
Initial value:

Definition at line 50 of file kdio.c.

Referenced by KdDebuggerInitialize0().

◆ KdpCurrentPosition

volatile ULONG KdpCurrentPosition = 0
static

Definition at line 31 of file kdio.c.

Referenced by KdpLoggerThread(), and KdpPrintToLogFile().

◆ KdpDebugBuffer

PCHAR KdpDebugBuffer = NULL
static

Definition at line 30 of file kdio.c.

Referenced by KdpDebugLogInit(), KdpLoggerThread(), and KdpPrintToLogFile().

◆ KdpDebugLogSpinLock

KSPIN_LOCK KdpDebugLogSpinLock
static

Definition at line 33 of file kdio.c.

Referenced by KdpDebugLogInit(), and KdpPrintToLogFile().

◆ KdpDebugMode

◆ KdpFreeBytes

volatile ULONG KdpFreeBytes = 0
static

Definition at line 32 of file kdio.c.

Referenced by KdpDebugLogInit(), KdpLoggerThread(), and KdpPrintToLogFile().

◆ KdpLogFileHandle

HANDLE KdpLogFileHandle
static

Definition at line 35 of file kdio.c.

Referenced by KdpDebugLogInit(), and KdpLoggerThread().

◆ KdpLogFileName

ANSI_STRING KdpLogFileName = RTL_CONSTANT_STRING("\\SystemRoot\\debug.log")

Definition at line 36 of file kdio.c.

Referenced by KdpDebugLogInit(), and KdpGetDebugMode().

◆ KdpLoggerThreadEvent

KEVENT KdpLoggerThreadEvent
static

Definition at line 34 of file kdio.c.

Referenced by KdpDebugLogInit(), KdpLoggerThread(), and KdpPrintToLogFile().

◆ KdpLoggingEnabled

BOOLEAN KdpLoggingEnabled = FALSE
static

Definition at line 29 of file kdio.c.

Referenced by KdpLoggerThread(), and KdpPrintToLogFile().

◆ KdProviders

LIST_ENTRY KdProviders = {&KdProviders, &KdProviders}

◆ KdpScreenLineBuffer

CHAR KdpScreenLineBuffer[KdpScreenLineLengthDefault+1] = ""
static

Definition at line 43 of file kdio.c.

Referenced by KdpScreenPrint().

◆ KdpScreenLineBufferPos

ULONG KdpScreenLineBufferPos = 0
static

Definition at line 44 of file kdio.c.

Referenced by KdpScreenPrint().

◆ KdpScreenLineLength

ULONG KdpScreenLineLength = 0
static

Definition at line 44 of file kdio.c.

Referenced by KdpScreenPrint().

◆ KdpSerialSpinLock

KSPIN_LOCK KdpSerialSpinLock
static

Definition at line 38 of file kdio.c.

Referenced by KdpSerialInit(), and KdpSerialPrint().

◆ SerialPortInfo

◆ SerialPortNumber

ULONG SerialPortNumber = DEFAULT_DEBUG_PORT

Definition at line 39 of file kdio.c.

Referenced by KdpGetDebugMode(), and KdpSerialInit().