/* FUNCTIONS *****************************************************************/
+#ifdef _WINKD_
+
BOOLEAN
NTAPI
-KdpPrintString(IN PSTRING Output)
+KdpPrintString(
+ _In_ PSTRING Output)
{
STRING Data, Header;
DBGKD_DEBUG_IO DebugIo;
BOOLEAN
NTAPI
-KdpPromptString(IN PSTRING PromptString,
- IN PSTRING ResponseString)
+KdpPromptString(
+ _In_ PSTRING PromptString,
+ _In_ PSTRING ResponseString)
{
STRING Data, Header;
DBGKD_DEBUG_IO DebugIo;
KdExitDebugger(Enable);
}
+#else
+
+extern
+BOOLEAN
+NTAPI
+KdpPrintString(
+ _In_ PSTRING Output);
+
+extern
+BOOLEAN
+NTAPI
+KdpPromptString(
+ _In_ PSTRING PromptString,
+ _In_ PSTRING ResponseString);
+
+#endif // _WINKD_
+
USHORT
NTAPI
-KdpPrompt(IN LPSTR PromptString,
- IN USHORT PromptLength,
- OUT PCHAR ResponseString,
- IN USHORT MaximumResponseLength,
- IN KPROCESSOR_MODE PreviousMode,
- IN PKTRAP_FRAME TrapFrame,
- IN PKEXCEPTION_FRAME ExceptionFrame)
+KdpPrompt(
+ _In_reads_bytes_(PromptLength) PCHAR PromptString,
+ _In_ USHORT PromptLength,
+ _Out_writes_bytes_(MaximumResponseLength) PCHAR ResponseString,
+ _In_ USHORT MaximumResponseLength,
+ _In_ KPROCESSOR_MODE PreviousMode,
+ _In_ PKTRAP_FRAME TrapFrame,
+ _In_ PKEXCEPTION_FRAME ExceptionFrame)
{
STRING PromptBuffer, ResponseBuffer;
BOOLEAN Enable, Resend;
+ PCHAR SafeResponseString;
CHAR CapturedPrompt[512];
CHAR SafeResponseBuffer[512];
- PCHAR SafeResponseString;
/* Normalize the lengths */
PromptLength = min(PromptLength,
/* Handle user-mode buffers safely */
_SEH2_TRY
{
- /* Probe the prompt */
- ProbeForRead(PromptString,
- PromptLength,
- 1);
-
- /* Capture prompt */
- KdpMoveMemory(CapturedPrompt,
- PromptString,
- PromptLength);
+ /* Probe and capture the prompt */
+ ProbeForRead(PromptString, PromptLength, 1);
+ KdpMoveMemory(CapturedPrompt, PromptString, PromptLength);
PromptString = CapturedPrompt;
- /* Probe and make room for response */
- ProbeForWrite(ResponseString,
- MaximumResponseLength,
- 1);
+ /* Probe and make room for the response */
+ ProbeForWrite(ResponseString, MaximumResponseLength, 1);
SafeResponseString = SafeResponseBuffer;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Bad string pointer, bail out */
+ /* Bad string pointer, bail out */
_SEH2_YIELD(return 0);
}
_SEH2_END;
SafeResponseString = ResponseString;
}
- /* Setup the prompt and response buffers */
+ /* Setup the prompt and response buffers */
PromptBuffer.Buffer = PromptString;
- PromptBuffer.Length = PromptLength;
+ PromptBuffer.Length = PromptBuffer.MaximumLength = PromptLength;
ResponseBuffer.Buffer = SafeResponseString;
ResponseBuffer.Length = 0;
ResponseBuffer.MaximumLength = MaximumResponseLength;
/* Exit the debugger */
KdExitDebugger(Enable);
- /* Copy back response if required */
+ /* Copy back the response if required */
if (PreviousMode != KernelMode)
{
_SEH2_TRY
{
- /* Safely copy back response to user mode */
+ /* Safely copy back the response to user mode */
KdpMoveMemory(ResponseString,
ResponseBuffer.Buffer,
ResponseBuffer.Length);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* String became invalid after we exited, fail */
+ /* String became invalid after we exited, fail */
_SEH2_YIELD(return 0);
}
_SEH2_END;
NTSTATUS
NTAPI
-KdpPrint(IN ULONG ComponentId,
- IN ULONG Level,
- IN LPSTR String,
- IN USHORT Length,
- IN KPROCESSOR_MODE PreviousMode,
- IN PKTRAP_FRAME TrapFrame,
- IN PKEXCEPTION_FRAME ExceptionFrame,
- OUT PBOOLEAN Handled)
+KdpPrint(
+ _In_ ULONG ComponentId,
+ _In_ ULONG Level,
+ _In_reads_bytes_(Length) PCHAR String,
+ _In_ USHORT Length,
+ _In_ KPROCESSOR_MODE PreviousMode,
+ _In_ PKTRAP_FRAME TrapFrame,
+ _In_ PKEXCEPTION_FRAME ExceptionFrame,
+ _Out_ PBOOLEAN Handled)
{
- NTSTATUS ReturnStatus;
+ NTSTATUS Status;
BOOLEAN Enable;
STRING OutputString;
- PVOID CapturedString;
+ CHAR CapturedString[512];
- /* Assume failure */
- *Handled = FALSE;
-
-#if (NTDDI_VERSION >= NTDDI_VISTA)
- if ((ComponentId >= KdComponentTableSize) && (ComponentId < MAXULONG))
- {
- /* Use the default component ID */
- Mask = &Kd_DEFAULT_Mask;
- // Level = DPFLTR_INFO_LEVEL; // Override the Level.
- }
-#endif
- /* Convert Level to bit field if required */
- if (Level < 32) Level = 1 << Level;
- Level &= ~DPFLTR_MASK;
-
- /* Validate the mask */
- if (!(Kd_WIN2000_Mask & Level) ||
- ((ComponentId < KdComponentTableSize) &&
- !(*KdComponentTable[ComponentId] & Level)))
+ if (NtQueryDebugFilterState(ComponentId, Level) == (NTSTATUS)FALSE)
{
/* Mask validation failed */
*Handled = TRUE;
return STATUS_SUCCESS;
}
+ /* Assume failure */
+ *Handled = FALSE;
+
/* Normalize the length */
- Length = min(Length, 512);
+ Length = min(Length, sizeof(CapturedString));
- /* Check if we need to verify the buffer */
+ /* Check if we need to verify the string */
if (PreviousMode != KernelMode)
{
/* Capture user-mode buffers */
_SEH2_TRY
{
- /* Probe the string */
- ProbeForRead(String,
- Length,
- 1);
-
- /* Capture it */
- CapturedString = alloca(Length);
- KdpMoveMemory(CapturedString,
- String,
- Length);
+ /* Probe and capture the string */
+ ProbeForRead(String, Length, 1);
+ KdpMoveMemory(CapturedString, String, Length);
String = CapturedString;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- /* Bad pointer, fail the print */
+ /* Bad string pointer, bail out */
_SEH2_YIELD(return STATUS_ACCESS_VIOLATION);
}
_SEH2_END;
/* Setup the output string */
OutputString.Buffer = String;
- OutputString.Length = Length;
+ OutputString.Length = OutputString.MaximumLength = Length;
/* Log the print */
//KdLogDbgPrint(&OutputString);
if (KdpPrintString(&OutputString))
{
/* User pressed CTRL-C, breakpoint on return */
- ReturnStatus = STATUS_BREAKPOINT;
+ Status = STATUS_BREAKPOINT;
}
else
{
/* String was printed */
- ReturnStatus = STATUS_SUCCESS;
+ Status = STATUS_SUCCESS;
}
/* Exit the debugger and return */
KdExitDebugger(Enable);
*Handled = TRUE;
- return ReturnStatus;
+ return Status;
}
VOID
__cdecl
-KdpDprintf(IN PCHAR Format,
- ...)
+KdpDprintf(
+ _In_ PCHAR Format,
+ ...)
{
STRING String;
- CHAR Buffer[100];
USHORT Length;
va_list ap;
+ CHAR Buffer[100];
/* Format the string */
va_start(ap, Format);
sizeof(Buffer),
Format,
ap);
+ va_end(ap);
/* Set it up */
String.Buffer = Buffer;
- String.Length = Length + 1;
+ String.Length = String.MaximumLength = Length;
/* Send it to the debugger directly */
KdpPrintString(&String);
- va_end(ap);
}