ReactOS 0.4.15-dev-7659-ga55345b
kdapi.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for kdapi.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI PspDumpThreads (BOOLEAN SystemThreads)
 
VOID NTAPI KdpMoveMemory (_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
 
VOID NTAPI KdpZeroMemory (_In_ PVOID Destination, _In_ SIZE_T Length)
 
NTSTATUS NTAPI KdpCopyMemoryChunks (_In_ ULONG64 Address, _In_ PVOID Buffer, _In_ ULONG TotalSize, _In_ ULONG ChunkSize, _In_ ULONG Flags, _Out_opt_ PULONG ActualSize)
 
VOID NTAPI KdpQueryMemory (IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
 
VOID NTAPI KdpSearchMemory (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpFillMemory (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWriteBreakpoint (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpRestoreBreakpoint (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
NTSTATUS NTAPI KdpWriteBreakPointEx (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpRestoreBreakPointEx (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWriteCustomBreakpoint (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI DumpTraceData (IN PSTRING TraceData)
 
VOID NTAPI KdpSetCommonState (IN ULONG NewState, IN PCONTEXT Context, IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange)
 
VOID NTAPI KdpSysGetVersion (IN PDBGKD_GET_VERSION64 Version)
 
VOID NTAPI KdpGetVersion (IN PDBGKD_MANIPULATE_STATE64 State)
 
VOID NTAPI KdpReadVirtualMemory (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWriteVirtualMemory (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpReadPhysicalMemory (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWritePhysicalMemory (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpReadControlSpace (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWriteControlSpace (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpGetContext (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpSetContext (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpGetContextEx (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpSetContextEx (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpCauseBugCheck (IN PDBGKD_MANIPULATE_STATE64 State)
 
VOID NTAPI KdpReadMachineSpecificRegister (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWriteMachineSpecificRegister (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpGetBusData (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpSetBusData (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpReadIoSpace (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWriteIoSpace (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpReadIoSpaceExtended (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpWriteIoSpaceExtended (IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
 
VOID NTAPI KdpCheckLowMemory (IN PDBGKD_MANIPULATE_STATE64 State)
 
VOID NTAPI KdpNotSupported (IN PDBGKD_MANIPULATE_STATE64 State)
 
KCONTINUE_STATUS NTAPI KdpSendWaitContinue (IN ULONG PacketType, IN PSTRING SendHeader, IN PSTRING SendData OPTIONAL, IN OUT PCONTEXT Context)
 
VOID NTAPI KdpReportLoadSymbolsStateChange (IN PSTRING PathName, IN PKD_SYMBOLS_INFO SymbolInfo, IN BOOLEAN Unload, IN OUT PCONTEXT Context)
 
VOID NTAPI KdpReportCommandStringStateChange (IN PSTRING NameString, IN PSTRING CommandString, IN OUT PCONTEXT Context)
 
BOOLEAN NTAPI KdpReportExceptionStateChange (IN PEXCEPTION_RECORD ExceptionRecord, IN OUT PCONTEXT Context, IN BOOLEAN SecondChanceException)
 
VOID NTAPI KdpTimeSlipDpcRoutine (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID NTAPI KdpTimeSlipWork (IN PVOID Context)
 
BOOLEAN NTAPI KdpSwitchProcessor (IN PEXCEPTION_RECORD ExceptionRecord, IN OUT PCONTEXT ContextRecord, IN BOOLEAN SecondChanceException)
 
LARGE_INTEGER NTAPI KdpQueryPerformanceCounter (IN PKTRAP_FRAME TrapFrame)
 
BOOLEAN NTAPI KdEnterDebugger (IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
 
VOID NTAPI KdExitDebugger (IN BOOLEAN Enable)
 
NTSTATUS NTAPI KdEnableDebuggerWithLock (IN BOOLEAN NeedLock)
 
NTSTATUS NTAPI KdDisableDebuggerWithLock (IN BOOLEAN NeedLock)
 
NTSTATUS NTAPI KdEnableDebugger (VOID)
 
NTSTATUS NTAPI KdDisableDebugger (VOID)
 
NTSTATUS NTAPI KdSystemDebugControl (_In_ SYSDBG_COMMAND Command, _In_ PVOID InputBuffer, _In_ ULONG InputBufferLength, _Out_ PVOID OutputBuffer, _In_ ULONG OutputBufferLength, _Inout_ PULONG ReturnLength, _In_ KPROCESSOR_MODE PreviousMode)
 
NTSTATUS NTAPI KdChangeOption (IN KD_OPTION Option, IN ULONG InBufferBytes OPTIONAL, IN PVOID InBuffer, IN ULONG OutBufferBytes OPTIONAL, OUT PVOID OutBuffer, OUT PULONG OutBufferNeeded OPTIONAL)
 
NTSTATUS NTAPI KdPowerTransition (IN DEVICE_POWER_STATE NewState)
 
BOOLEAN NTAPI KdRefreshDebuggerNotPresent (VOID)
 
NTSTATUS NTAPI NtQueryDebugFilterState (_In_ ULONG ComponentId, _In_ ULONG Level)
 
NTSTATUS NTAPI NtSetDebugFilterState (_In_ ULONG ComponentId, _In_ ULONG Level, _In_ BOOLEAN State)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 18 of file kdapi.c.

Function Documentation

◆ DumpTraceData()

VOID NTAPI DumpTraceData ( IN PSTRING  TraceData)

Definition at line 371 of file kdapi.c.

372{
373 /* Update the buffer */
375
376 /* Setup the trace data */
377 TraceData->Length = (USHORT)(TraceDataBufferPosition * sizeof(ULONG));
378 TraceData->Buffer = (PCHAR)TraceDataBuffer;
379
380 /* Reset the buffer location */
382}
ULONG TraceDataBufferPosition
Definition: kddata.c:111
ULONG TraceDataBuffer[40]
Definition: kddata.c:110
#define PCHAR
Definition: match.c:90
unsigned short USHORT
Definition: pedump.c:61
uint32_t ULONG
Definition: typedefs.h:59

Referenced by KdpReportExceptionStateChange().

◆ KdChangeOption()

NTSTATUS NTAPI KdChangeOption ( IN KD_OPTION  Option,
IN ULONG InBufferBytes  OPTIONAL,
IN PVOID  InBuffer,
IN ULONG OutBufferBytes  OPTIONAL,
OUT PVOID  OutBuffer,
OUT PULONG OutBufferNeeded  OPTIONAL 
)

Definition at line 2239 of file kdapi.c.

2245{
2246 /* Fail if there is no debugger */
2247 if (KdPitchDebugger)
2248 {
2249 /* No debugger, no options */
2251 }
2252
2253 /* Do we recognize this option? */
2254 if (Option != KD_OPTION_SET_BLOCK_ENABLE)
2255 {
2256 /* We don't, clear the output length and fail */
2257 if (OutBufferNeeded) *OutBufferNeeded = 0;
2259 }
2260
2261 /* Verify parameters */
2262 if ((InBufferBytes != sizeof(BOOLEAN)) ||
2263 (OutBufferBytes != 0) ||
2264 (OutBuffer != NULL))
2265 {
2266 /* Invalid parameters for this option, fail */
2268 }
2269
2270 /*
2271 * Check if the high bit is set, meaning we don't
2272 * allow the debugger to be enabled
2273 */
2274 if (KdBlockEnable & 0x80)
2275 {
2276 /* Fail regardless of what state the caller tried to set */
2278 }
2279
2280 /* Set the new block enable state */
2281 KdBlockEnable = *(PBOOLEAN)InBuffer;
2282
2283 /* No output buffer required for this option */
2284 if (OutBufferNeeded) *OutBufferNeeded = 0;
2285
2286 /* We are done */
2287 return STATUS_SUCCESS;
2288}
unsigned char BOOLEAN
#define NULL
Definition: types.h:112
BOOLEAN KdPitchDebugger
Definition: kddata.c:81
BOOLEAN KdBlockEnable
Definition: kddata.c:85
#define STATUS_DEBUGGER_INACTIVE
Definition: debugger.c:30
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4071
#define STATUS_SUCCESS
Definition: shellext.h:65
unsigned char * PBOOLEAN
Definition: typedefs.h:53
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
@ KD_OPTION_SET_BLOCK_ENABLE
Definition: ketypes.h:524

◆ KdDisableDebugger()

NTSTATUS NTAPI KdDisableDebugger ( VOID  )

Definition at line 2146 of file kdapi.c.

2147{
2148 /* Use the internal routine */
2150}
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI KdDisableDebuggerWithLock(IN BOOLEAN NeedLock)
Definition: kdapi.c:2040

Referenced by PcipGetFunctionLimits().

◆ KdDisableDebuggerWithLock()

NTSTATUS NTAPI KdDisableDebuggerWithLock ( IN BOOLEAN  NeedLock)

Definition at line 2040 of file kdapi.c.

2041{
2042 KIRQL OldIrql;
2044
2045#if defined(__GNUC__)
2046 /* Make gcc happy */
2048#endif
2049
2050 /*
2051 * If enabling the debugger is blocked
2052 * then there is nothing to disable (duh)
2053 */
2054 if (KdBlockEnable)
2055 {
2056 /* Fail */
2057 return STATUS_ACCESS_DENIED;
2058 }
2059
2060 /* Check if we need to acquire the lock */
2061 if (NeedLock)
2062 {
2063 /* Lock the port */
2065 KdpPortLock();
2066 }
2067
2068 /* Check if we're not disabled */
2069 if (!KdDisableCount)
2070 {
2071 /* Check if the debugger was never actually initialized */
2073 {
2074 /* It wasn't, so don't re-enable it later */
2076 }
2077 else
2078 {
2079 /* It was, so we will re-enable it later */
2081 }
2082
2083 /* Check if we were called from the exported API and are enabled */
2084 if ((NeedLock) && (KdPreviouslyEnabled))
2085 {
2086 /* Check if it is safe to disable the debugger */
2088 if (!NT_SUCCESS(Status))
2089 {
2090 /* Release the lock and fail */
2091 KdpPortUnlock();
2093 return Status;
2094 }
2095 }
2096
2097 /* Only disable the debugger if it is enabled */
2099 {
2100 /*
2101 * Disable the debugger; suspend breakpoints
2102 * and reset the debug stub
2103 */
2106
2107 /* We are disabled now */
2109 SharedUserData->KdDebuggerEnabled = FALSE;
2110 }
2111 }
2112
2113 /* Increment the disable count */
2115
2116 /* Check if we had locked the port before */
2117 if (NeedLock)
2118 {
2119 /* Yes, now unlock it */
2120 KdpPortUnlock();
2122 }
2123
2124 /* We're done */
2125 return STATUS_SUCCESS;
2126}
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
Status
Definition: gdiplustypes.h:25
BOOLEAN KdPreviouslyEnabled
Definition: kddata.c:87
VOID NTAPI KdpPortLock(VOID)
Definition: kdlock.c:19
ULONG KdDisableCount
Definition: kddata.c:90
PKDEBUG_ROUTINE KiDebugRoutine
Definition: kddata.c:74
VOID NTAPI KdpPortUnlock(VOID)
Definition: kdlock.c:27
BOOLEAN NTAPI KdpStub(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN PEXCEPTION_RECORD ExceptionRecord, IN PCONTEXT ContextRecord, IN KPROCESSOR_MODE PreviousMode, IN BOOLEAN SecondChanceException)
Definition: kdtrap.c:266
NTSTATUS NTAPI KdpAllowDisable(VOID)
Definition: kdx64.c:364
VOID NTAPI KdpSuspendAllBreakPoints(VOID)
Definition: kdbreak.c:407
BOOLEAN KdDebuggerEnabled
Definition: kddata.c:83
#define SharedUserData
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by KdDisableDebugger(), and KdInitSystem().

◆ KdEnableDebugger()

NTSTATUS NTAPI KdEnableDebugger ( VOID  )

Definition at line 2135 of file kdapi.c.

2136{
2137 /* Use the internal routine */
2139}
NTSTATUS NTAPI KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
Definition: kdapi.c:1964

Referenced by KdpStub(), and PcipGetFunctionLimits().

◆ KdEnableDebuggerWithLock()

NTSTATUS NTAPI KdEnableDebuggerWithLock ( IN BOOLEAN  NeedLock)

Definition at line 1964 of file kdapi.c.

1965{
1966 KIRQL OldIrql;
1967
1968#if defined(__GNUC__)
1969 /* Make gcc happy */
1971#endif
1972
1973 /* Check if enabling the debugger is blocked */
1974 if (KdBlockEnable)
1975 {
1976 /* It is, fail the enable */
1977 return STATUS_ACCESS_DENIED;
1978 }
1979
1980 /* Check if we need to acquire the lock */
1981 if (NeedLock)
1982 {
1983 /* Lock the port */
1985 KdpPortLock();
1986 }
1987
1988 /* Check if we're not disabled */
1989 if (!KdDisableCount)
1990 {
1991 /* Check if we had locked the port before */
1992 if (NeedLock)
1993 {
1994 /* Do the unlock */
1995 KdpPortUnlock();
1997
1998 /* Fail: We're already enabled */
2000 }
2001 else
2002 {
2003 /*
2004 * This can only happen if we are called from a bugcheck
2005 * and were never initialized, so initialize the debugger now.
2006 */
2007 KdInitSystem(0, NULL);
2008
2009 /* Return success since we initialized */
2010 return STATUS_SUCCESS;
2011 }
2012 }
2013
2014 /* Decrease the disable count */
2015 if (!(--KdDisableCount))
2016 {
2017 /* We're now enabled again! Were we enabled before, too? */
2019 {
2020 /* Reinitialize the Debugger */
2021 KdInitSystem(0, NULL);
2023 }
2024 }
2025
2026 /* Check if we had locked the port before */
2027 if (NeedLock)
2028 {
2029 /* Yes, now unlock it */
2030 KdpPortUnlock();
2032 }
2033
2034 /* We're done */
2035 return STATUS_SUCCESS;
2036}
BOOLEAN NTAPI KdInitSystem(_In_ ULONG BootPhase, _In_opt_ PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: kdinit.c:142
VOID NTAPI KdpRestoreAllBreakpoints(VOID)
Definition: kdbreak.c:368

Referenced by KdEnableDebugger(), and KeBugCheckWithTf().

◆ KdEnterDebugger()

BOOLEAN NTAPI KdEnterDebugger ( IN PKTRAP_FRAME  TrapFrame,
IN PKEXCEPTION_FRAME  ExceptionFrame 
)

Definition at line 1876 of file kdapi.c.

1878{
1880
1881 /* Check if we have a trap frame */
1882 if (TrapFrame)
1883 {
1884 /* Calculate the time difference for the enter */
1888 }
1889 else
1890 {
1891 /* No trap frame, so can't calculate */
1893 }
1894
1895 /* Save the current IRQL */
1896 KeGetCurrentPrcb()->DebuggerSavedIRQL = KeGetCurrentIrql();
1897
1898 /* Freeze all CPUs, raising also the IRQL to HIGH_LEVEL */
1899 Enable = KeFreezeExecution(TrapFrame, ExceptionFrame);
1900
1901 /* Lock the port, save the state and set debugger entered */
1903 KdSave(FALSE);
1905
1906 /* Check freeze flag */
1907 if (KiFreezeFlag & 1)
1908 {
1909 /* Print out errror */
1910 KdpDprintf("FreezeLock was jammed! Backup SpinLock was used!\n");
1911 }
1912
1913 /* Check processor state */
1914 if (KiFreezeFlag & 2)
1915 {
1916 /* Print out errror */
1917 KdpDprintf("Some processors not frozen in debugger!\n");
1918 }
1919
1920 /* Make sure we acquired the port */
1921 if (!KdpPortLocked) KdpDprintf("Port lock was not acquired!\n");
1922
1923 /* Return if interrupts needs to be re-enabled */
1924 return Enable;
1925}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
LARGE_INTEGER KdTimerStop
Definition: kddata.c:122
BOOLEAN KdEnteredDebugger
Definition: kddata.c:89
LARGE_INTEGER KdTimerStart
Definition: kd64.h:562
KSPIN_LOCK KdpDebuggerLock
Definition: kddata.c:67
BOOLEAN KdpPortLocked
Definition: kddata.c:66
LARGE_INTEGER KdTimerDifference
Definition: kd64.h:562
LARGE_INTEGER NTAPI KdpQueryPerformanceCounter(IN PKTRAP_FRAME TrapFrame)
Definition: kdapi.c:1859
NTSTATUS NTAPI KdSave(IN BOOLEAN SleepTransition)
Definition: kdcom.c:113
#define KdpDprintf(...)
Definition: mmdbg.c:19
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1148
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
ULONG KiFreezeFlag
Definition: freeze.c:20
BOOLEAN NTAPI KeFreezeExecution(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: freeze.c:26
BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK SpinLock)
Definition: spinlock.c:309
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by KdpCommandString(), KdpPrint(), KdpPrompt(), KdpReport(), KdpSymbol(), KdRefreshDebuggerNotPresent(), and KdSetOwedBreakpoints().

◆ KdExitDebugger()

VOID NTAPI KdExitDebugger ( IN BOOLEAN  Enable)

Definition at line 1929 of file kdapi.c.

1930{
1931 ULONG TimeSlip;
1932
1933 /* Restore the state and unlock the port */
1936
1937 /* Unfreeze the CPUs, restoring also the IRQL */
1939
1940 /* Compare time with the one from KdEnterDebugger */
1941 if (!KdTimerStop.QuadPart)
1942 {
1943 /* We didn't get a trap frame earlier in so never got the time */
1945 }
1946 else
1947 {
1948 /* Query the timer */
1950 }
1951
1952 /* Check if a Time Slip was on queue */
1954 if (TimeSlip == 1)
1955 {
1956 /* Queue a DPC for the time slip */
1958 KeInsertQueueDpc(&KdpTimeSlipDpc, NULL, NULL); // FIXME: this can trigger context switches!
1959 }
1960}
#define InterlockedIncrement
Definition: armddk.h:53
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
LONG KdpTimeSlipPending
Definition: kddata.c:119
KDPC KdpTimeSlipDpc
Definition: kddata.c:116
NTSTATUS NTAPI KdRestore(IN BOOLEAN SleepTransition)
Definition: kdcom.c:121
VOID NTAPI KeThawExecution(IN BOOLEAN Enable)
Definition: freeze.c:64

Referenced by KdpCommandString(), KdpPrint(), KdpPrompt(), KdpReport(), KdpSymbol(), KdRefreshDebuggerNotPresent(), and KdSetOwedBreakpoints().

◆ KdpCauseBugCheck()

VOID NTAPI KdpCauseBugCheck ( IN PDBGKD_MANIPULATE_STATE64  State)

Definition at line 949 of file kdapi.c.

950{
951 /* Crash with the special code */
952 KeBugCheck(MANUALLY_INITIATED_CRASH);
953}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1431

Referenced by KdpSendWaitContinue().

◆ KdpCheckLowMemory()

VOID NTAPI KdpCheckLowMemory ( IN PDBGKD_MANIPULATE_STATE64  State)

Definition at line 1225 of file kdapi.c.

1226{
1227 STRING Header;
1228
1229 /* Setup the header */
1230 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1231 Header.Buffer = (PCHAR)State;
1232
1233 /* Call the internal routine */
1235
1236 /* Send the reply */
1238 &Header,
1239 NULL,
1240 &KdpContext);
1241}
Definition: Header.h:9
std::wstring STRING
Definition: fontsub.cpp:33
NTSTATUS NTAPI KdpSysCheckLowMemory(IN ULONG Flags)
Definition: kdx64.c:356
KD_CONTEXT KdpContext
Definition: kddata.c:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
#define MMDBG_COPY_UNSAFE
Definition: mm.h:77
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpCopyMemoryChunks()

NTSTATUS NTAPI KdpCopyMemoryChunks ( _In_ ULONG64  Address,
_In_ PVOID  Buffer,
_In_ ULONG  TotalSize,
_In_ ULONG  ChunkSize,
_In_ ULONG  Flags,
_Out_opt_ PULONG  ActualSize 
)

Definition at line 55 of file kdapi.c.

62{
64 ULONG RemainingLength, CopyChunk;
65
66 /* Check if we didn't get a chunk size or if it is too big */
67 if (ChunkSize == 0)
68 {
69 /* Default to 4 byte chunks */
70 ChunkSize = 4;
71 }
73 {
74 /* Normalize to maximum size */
76 }
77
78 /* Copy the whole range in aligned chunks */
79 RemainingLength = TotalSize;
80 CopyChunk = 1;
81 while (RemainingLength > 0)
82 {
83 /*
84 * Determine the best chunk size for this round.
85 * The ideal size is aligned, isn't larger than the
86 * the remaining length and respects the chunk limit.
87 */
88 while (((CopyChunk * 2) <= RemainingLength) &&
89 (CopyChunk < ChunkSize) &&
90 ((Address & ((CopyChunk * 2) - 1)) == 0))
91 {
92 /* Increase it */
93 CopyChunk *= 2;
94 }
95
96 /*
97 * The chunk size can be larger than the remaining size if this
98 * isn't the first round, so check if we need to shrink it back.
99 */
100 while (CopyChunk > RemainingLength)
101 {
102 /* Shrink it */
103 CopyChunk /= 2;
104 }
105
106 /* Do the copy */
107 Status = MmDbgCopyMemory(Address, Buffer, CopyChunk, Flags);
108 if (!NT_SUCCESS(Status))
109 {
110 /* Copy failed, break out */
111 break;
112 }
113
114 /* Update pointers and length for the next run */
115 Address = Address + CopyChunk;
116 Buffer = (PVOID)((ULONG_PTR)Buffer + CopyChunk);
117 RemainingLength = RemainingLength - CopyChunk;
118 }
119
120 /* We may have modified executable code, flush the instruction cache */
121 KeSweepICache((PVOID)(ULONG_PTR)Address, TotalSize);
122
123 /*
124 * Return the size we managed to copy and return
125 * success if we could copy the whole range.
126 */
127 if (ActualSize) *ActualSize = TotalSize - RemainingLength;
128 return RemainingLength == 0 ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
129}
Definition: bufpool.h:45
FORCEINLINE VOID KeSweepICache(IN PVOID BaseAddress, IN SIZE_T FlushSize)
Definition: ke.h:280
#define MMDBG_COPY_MAX_SIZE
Definition: mm.h:85
NTSTATUS NTAPI MmDbgCopyMemory(IN ULONG64 Address, IN PVOID Buffer, IN ULONG Size, IN ULONG Flags)
Definition: mmdbg.c:124
static WCHAR Address[46]
Definition: ping.c:68
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Inout_ PUCHAR _In_ PUCHAR _Out_ PUCHAR _Out_ PULONG ChunkSize
Definition: rtlfuncs.h:2277

Referenced by KdbpSafeReadMemory(), KdbpSafeWriteMemory(), KdpAddBreakpoint(), KdpLowRestoreBreakpoint(), KdpLowWriteContent(), KdpReadPhysicalMemory(), KdpReadVirtualMemory(), KdpReportCommandStringStateChange(), KdpReportLoadSymbolsStateChange(), KdpSetCommonState(), KdpSysReadControlSpace(), KdpSysWriteControlSpace(), KdpWritePhysicalMemory(), KdpWriteVirtualMemory(), and KdSetOwedBreakpoints().

◆ KdpFillMemory()

VOID NTAPI KdpFillMemory ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 214 of file kdapi.c.

217{
218 //PDBGKD_FILL_MEMORY FillMemory = &State->u.FillMemory;
220
221 /* TODO */
222 KdpDprintf("Memory Fill support is unimplemented!\n");
223
224 /* Send a failure packet */
225 State->ReturnStatus = STATUS_UNSUCCESSFUL;
226 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
227 Header.Buffer = (PCHAR)State;
229 &Header,
230 NULL,
231 &KdpContext);
232}

Referenced by KdpSendWaitContinue().

◆ KdpGetBusData()

VOID NTAPI KdpGetBusData ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 1015 of file kdapi.c.

1018{
1019 STRING Header;
1020 PDBGKD_GET_SET_BUS_DATA GetBusData = &State->u.GetSetBusData;
1021 ULONG Length;
1022
1023 /* Setup the header */
1024 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1025 Header.Buffer = (PCHAR)State;
1026 ASSERT(Data->Length == 0);
1027
1028 /* Check the length requested */
1029 Length = GetBusData->Length;
1031 {
1032 /* Use maximum allowed */
1034 }
1035
1036 /* Call the internal routine */
1037 State->ReturnStatus = KdpSysReadBusData(GetBusData->BusDataType,
1038 GetBusData->BusNumber,
1039 GetBusData->SlotNumber,
1040 GetBusData->Offset,
1041 Data->Buffer,
1042 Length,
1043 &Length);
1044
1045 /* Return the actual length read */
1046 GetBusData->Length = Length;
1047 Data->Length = (USHORT)Length;
1048
1049 /* Send the reply */
1051 &Header,
1052 Data,
1053 &KdpContext);
1054}
NTSTATUS NTAPI KdpSysReadBusData(IN ULONG BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:134
#define ASSERT(a)
Definition: mode.c:44
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18

Referenced by KdpSendWaitContinue().

◆ KdpGetContext()

VOID NTAPI KdpGetContext ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 718 of file kdapi.c.

721{
724
725 /* Setup the header */
726 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
727 Header.Buffer = (PCHAR)State;
728 ASSERT(Data->Length == 0);
729
730 /* Make sure that this is a valid request */
731 if (State->Processor < KeNumberProcessors)
732 {
733 /* Check if the request is for this CPU */
734 if (State->Processor == KeGetCurrentPrcb()->Number)
735 {
736 /* We're just copying our own context */
738 }
739 else
740 {
741 /* Get the context from the PRCB array */
742 TargetContext = &KiProcessorBlock[State->Processor]->
743 ProcessorState.ContextFrame;
744 }
745
746 /* Copy it over to the debugger */
747 KdpMoveMemory(Data->Buffer,
749 sizeof(CONTEXT));
750 Data->Length = sizeof(CONTEXT);
751
752 /* Let the debugger set the context now */
754
755 /* Finish up */
756 State->ReturnStatus = STATUS_SUCCESS;
757 }
758 else
759 {
760 /* Invalid request */
761 State->ReturnStatus = STATUS_UNSUCCESSFUL;
762 }
763
764 /* Send the reply */
766 &Header,
767 Data,
768 &KdpContext);
769}
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG _In_opt_ PVOID TargetContext
Definition: fsrtlfuncs.h:745
BOOLEAN KdpContextSent
Definition: kddata.c:69
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:27
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
struct _CONTEXT CONTEXT
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207

Referenced by KdpSendWaitContinue().

◆ KdpGetContextEx()

VOID NTAPI KdpGetContextEx ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 825 of file kdapi.c.

828{
830 PDBGKD_CONTEXT_EX ContextEx;
832 ASSERT(Data->Length == 0);
833
834 /* Get our struct */
835 ContextEx = &State->u.ContextEx;
836
837 /* Set up the header */
838 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
839 Header.Buffer = (PCHAR)State;
840
841 /* Make sure that this is a valid request */
842 if ((State->Processor < KeNumberProcessors) &&
843 (ContextEx->Offset + ContextEx->ByteCount) <= sizeof(CONTEXT))
844 {
845 /* Check if the request is for this CPU */
846 if (State->Processor == KeGetCurrentPrcb()->Number)
847 {
848 /* We're just copying our own context */
850 }
851 else
852 {
853 /* Get the context from the PRCB array */
854 TargetContext = &KiProcessorBlock[State->Processor]->
855 ProcessorState.ContextFrame;
856 }
857
858 /* Copy what is requested */
859 KdpMoveMemory(Data->Buffer,
860 (PVOID)((ULONG_PTR)TargetContext + ContextEx->Offset),
861 ContextEx->ByteCount);
862
863 /* KD copies all */
864 Data->Length = ContextEx->BytesCopied = ContextEx->ByteCount;
865
866 /* Let the debugger set the context now */
868
869 /* Finish up */
870 State->ReturnStatus = STATUS_SUCCESS;
871 }
872 else
873 {
874 /* Invalid request */
875 ContextEx->BytesCopied = 0;
876 State->ReturnStatus = STATUS_UNSUCCESSFUL;
877 }
878
879 /* Send the reply */
881 &Header,
882 Data,
883 &KdpContext);
884}

Referenced by KdpSendWaitContinue().

◆ KdpGetVersion()

VOID NTAPI KdpGetVersion ( IN PDBGKD_MANIPULATE_STATE64  State)

Definition at line 443 of file kdapi.c.

444{
446
447 /* Fill out the header */
448 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
449 Header.Buffer = (PCHAR)State;
450
451 /* Get the version block */
452 KdpSysGetVersion(&State->u.GetVersion64);
453
454 /* Fill out the state */
455 State->ApiNumber = DbgKdGetVersionApi;
456 State->ReturnStatus = STATUS_SUCCESS;
457
458 /* Send the packet */
460 &Header,
461 NULL,
462 &KdpContext);
463}
VOID NTAPI KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
Definition: kdapi.c:433
#define DbgKdGetVersionApi
Definition: windbgkd.h:96

Referenced by KdpSendWaitContinue().

◆ KdpMoveMemory()

VOID NTAPI KdpMoveMemory ( _In_ PVOID  Destination,
_In_ PVOID  Source,
_In_ SIZE_T  Length 
)

Definition at line 27 of file kdapi.c.

31{
32 PCHAR DestinationBytes, SourceBytes;
33
34 /* Copy the buffers 1 byte at a time */
35 DestinationBytes = Destination;
36 SourceBytes = Source;
37 while (Length--) *DestinationBytes++ = *SourceBytes++;
38}
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3004
char * PCHAR
Definition: typedefs.h:51

Referenced by KdLogDbgPrint(), KdpCommandString(), KdpGetContext(), KdpGetContextEx(), KdpPrintFromUser(), KdpPrintString(), KdpPrompt(), KdpPromptString(), KdpReport(), KdpReportExceptionStateChange(), KdpSetContext(), KdpSetContextEx(), KdpSymbol(), and KdpSysGetVersion().

◆ KdpNotSupported()

VOID NTAPI KdpNotSupported ( IN PDBGKD_MANIPULATE_STATE64  State)

Definition at line 1245 of file kdapi.c.

1246{
1247 STRING Header;
1248
1249 /* Set failure */
1250 State->ReturnStatus = STATUS_UNSUCCESSFUL;
1251
1252 /* Setup the packet */
1253 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1254 Header.Buffer = (PCHAR)State;
1255
1256 /* Send it */
1258 &Header,
1259 NULL,
1260 &KdpContext);
1261}

Referenced by KdpSendWaitContinue().

◆ KdPowerTransition()

NTSTATUS NTAPI KdPowerTransition ( IN DEVICE_POWER_STATE  NewState)

Definition at line 2295 of file kdapi.c.

2296{
2297 /* Check what power state this is */
2298 if (NewState == PowerDeviceD0)
2299 {
2300 /* Wake up the debug port */
2302 return STATUS_SUCCESS;
2303 }
2304 else if ((NewState == PowerDeviceD1) ||
2305 (NewState == PowerDeviceD2) ||
2306 (NewState == PowerDeviceD3))
2307 {
2308 /* Power down the debug port */
2310 return STATUS_SUCCESS;
2311 }
2312 else
2313 {
2314 /* Invalid state! */
2316 }
2317}
NTSTATUS NTAPI KdD0Transition(VOID)
Definition: kdcom.c:99
NTSTATUS NTAPI KdD3Transition(VOID)
Definition: kdcom.c:106
@ PowerDeviceD1
Definition: ntpoapi.h:50
@ PowerDeviceD0
Definition: ntpoapi.h:49
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475

◆ KdpQueryMemory()

VOID NTAPI KdpQueryMemory ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PCONTEXT  Context 
)

Definition at line 133 of file kdapi.c.

135{
136 PDBGKD_QUERY_MEMORY Memory = &State->u.QueryMemory;
139
140 /* Validate the address space */
141 if (Memory->AddressSpace == DBGKD_QUERY_MEMORY_VIRTUAL)
142 {
143 /* Check if this is process memory */
145 {
146 /* It is */
147 Memory->AddressSpace = DBGKD_QUERY_MEMORY_PROCESS;
148 }
149 else
150 {
151 /* Check if it's session space */
153 {
154 /* It is */
155 Memory->AddressSpace = DBGKD_QUERY_MEMORY_SESSION;
156 }
157 else
158 {
159 /* Not session space but some other kernel memory */
160 Memory->AddressSpace = DBGKD_QUERY_MEMORY_KERNEL;
161 }
162 }
163
164 /* Set flags */
168 }
169 else
170 {
171 /* Invalid */
173 }
174
175 /* Return structure */
176 State->ReturnStatus = Status;
177 Memory->Reserved = 0;
178
179 /* Build header */
180 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
181 Header.Buffer = (PCHAR)State;
182
183 /* Send the packet */
185 &Header,
186 NULL,
187 &KdpContext);
188}
BOOLEAN NTAPI MmIsSessionAddress(IN PVOID Address)
Definition: session.c:48
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ _Strict_type_match_ POOL_TYPE _In_opt_ ULONG _In_ _Out_ WDFMEMORY * Memory
Definition: wdfmemory.h:169
#define DBGKD_QUERY_MEMORY_PROCESS
Definition: windbgkd.h:160
#define DBGKD_QUERY_MEMORY_READ
Definition: windbgkd.h:167
#define DBGKD_QUERY_MEMORY_SESSION
Definition: windbgkd.h:161
#define DBGKD_QUERY_MEMORY_WRITE
Definition: windbgkd.h:168
#define DBGKD_QUERY_MEMORY_EXECUTE
Definition: windbgkd.h:169
#define DBGKD_QUERY_MEMORY_VIRTUAL
Definition: windbgkd.h:159
#define DBGKD_QUERY_MEMORY_KERNEL
Definition: windbgkd.h:162

Referenced by KdpSendWaitContinue().

◆ KdpQueryPerformanceCounter()

LARGE_INTEGER NTAPI KdpQueryPerformanceCounter ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 1859 of file kdapi.c.

1860{
1861 LARGE_INTEGER Null = {{0}};
1862
1863 /* Check if interrupts were disabled */
1864 if (!KeGetTrapFrameInterruptState(TrapFrame))
1865 {
1866 /* Nothing to return */
1867 return Null;
1868 }
1869
1870 /* Otherwise, do the call */
1872}
#define KeGetTrapFrameInterruptState(TrapFrame)
Definition: ke.h:233

Referenced by KdEnterDebugger().

◆ KdpReadControlSpace()

VOID NTAPI KdpReadControlSpace ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 650 of file kdapi.c.

653{
654 PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
657
658 /* Setup the header */
659 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
660 Header.Buffer = (PCHAR)State;
661 ASSERT(Data->Length == 0);
662
663 /* Check the length requested */
664 Length = ReadMemory->TransferCount;
666 {
667 /* Use maximum allowed */
669 }
670
671 /* Call the internal routine */
672 State->ReturnStatus = KdpSysReadControlSpace(State->Processor,
673 ReadMemory->TargetBaseAddress,
674 Data->Buffer,
675 Length,
676 &Length);
677
678 /* Return the actual length read */
679 ReadMemory->ActualBytesRead = Length;
680 Data->Length = (USHORT)Length;
681
682 /* Send the reply */
684 &Header,
685 Data,
686 &KdpContext);
687}
NTSTATUS NTAPI KdpSysReadControlSpace(IN ULONG Processor, IN ULONG64 BaseAddress, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:162
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY ReadMemory
Definition: wdfusb.h:2000

Referenced by KdpSendWaitContinue().

◆ KdpReadIoSpace()

VOID NTAPI KdpReadIoSpace ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 1091 of file kdapi.c.

1094{
1095 STRING Header;
1096 PDBGKD_READ_WRITE_IO64 ReadIo = &State->u.ReadWriteIo;
1097
1098 /* Setup the header */
1099 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1100 Header.Buffer = (PCHAR)State;
1101 ASSERT(Data->Length == 0);
1102
1103 /*
1104 * Clear the value so 1 or 2 byte reads
1105 * don't leave the higher bits unmodified
1106 */
1107 ReadIo->DataValue = 0;
1108
1109 /* Call the internal routine */
1110 State->ReturnStatus = KdpSysReadIoSpace(Isa,
1111 0,
1112 1,
1113 ReadIo->IoAddress,
1114 &ReadIo->DataValue,
1115 ReadIo->DataSize,
1116 &ReadIo->DataSize);
1117
1118 /* Send the reply */
1120 &Header,
1121 NULL,
1122 &KdpContext);
1123}
@ Isa
Definition: hwresource.cpp:138
NTSTATUS NTAPI KdpSysReadIoSpace(IN ULONG InterfaceType, IN ULONG BusNumber, IN ULONG AddressSpace, IN ULONG64 IoAddress, IN PVOID DataValue, IN ULONG DataSize, OUT PULONG ActualDataSize)
Definition: kdarm.c:108

Referenced by KdpSendWaitContinue().

◆ KdpReadIoSpaceExtended()

VOID NTAPI KdpReadIoSpaceExtended ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 1157 of file kdapi.c.

1160{
1161 STRING Header;
1162 PDBGKD_READ_WRITE_IO_EXTENDED64 ReadIoExtended = &State->u.
1163 ReadWriteIoExtended;
1164
1165 /* Setup the header */
1166 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1167 Header.Buffer = (PCHAR)State;
1168 ASSERT(Data->Length == 0);
1169
1170 /*
1171 * Clear the value so 1 or 2 byte reads
1172 * don't leave the higher bits unmodified
1173 */
1174 ReadIoExtended->DataValue = 0;
1175
1176 /* Call the internal routine */
1177 State->ReturnStatus = KdpSysReadIoSpace(ReadIoExtended->InterfaceType,
1178 ReadIoExtended->BusNumber,
1179 ReadIoExtended->AddressSpace,
1180 ReadIoExtended->IoAddress,
1181 &ReadIoExtended->DataValue,
1182 ReadIoExtended->DataSize,
1183 &ReadIoExtended->DataSize);
1184
1185 /* Send the reply */
1187 &Header,
1188 NULL,
1189 &KdpContext);
1190}

Referenced by KdpSendWaitContinue().

◆ KdpReadMachineSpecificRegister()

VOID NTAPI KdpReadMachineSpecificRegister ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 957 of file kdapi.c.

960{
962 PDBGKD_READ_WRITE_MSR ReadMsr = &State->u.ReadWriteMsr;
963 LARGE_INTEGER MsrValue;
964
965 /* Setup the header */
966 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
967 Header.Buffer = (PCHAR)State;
968 ASSERT(Data->Length == 0);
969
970 /* Call the internal routine */
971 State->ReturnStatus = KdpSysReadMsr(ReadMsr->Msr,
972 &MsrValue);
973
974 /* Return the data */
975 ReadMsr->DataValueLow = MsrValue.LowPart;
976 ReadMsr->DataValueHigh = MsrValue.HighPart;
977
978 /* Send the reply */
980 &Header,
981 NULL,
982 &KdpContext);
983}
NTSTATUS NTAPI KdpSysReadMsr(IN ULONG Msr, OUT PLARGE_INTEGER MsrValue)
Definition: kdx64.c:96
ULONG LowPart
Definition: typedefs.h:106

Referenced by KdpSendWaitContinue().

◆ KdpReadPhysicalMemory()

VOID NTAPI KdpReadPhysicalMemory ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 537 of file kdapi.c.

540{
541 PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
543 ULONG Length = ReadMemory->TransferCount;
544 ULONG Flags, CacheFlags;
545
546 /* Setup the header */
547 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
548 Header.Buffer = (PCHAR)State;
549 ASSERT(Data->Length == 0);
550
551 /* Validate length */
553 {
554 /* Overflow, set it to maximum possible */
556 }
557
558 /* Start with the default flags */
560
561 /* Get the caching flags and check if a type is specified */
562 CacheFlags = ReadMemory->ActualBytesRead;
563 if (CacheFlags == DBGKD_CACHING_CACHED)
564 {
565 /* Cached */
567 }
568 else if (CacheFlags == DBGKD_CACHING_UNCACHED)
569 {
570 /* Uncached */
572 }
573 else if (CacheFlags == DBGKD_CACHING_WRITE_COMBINED)
574 {
575 /* Write Combined */
577 }
578
579 /* Do the read */
580 State->ReturnStatus = KdpCopyMemoryChunks(ReadMemory->TargetBaseAddress,
581 Data->Buffer,
582 Length,
583 0,
584 Flags,
585 &Length);
586
587 /* Return the actual length read */
588 ReadMemory->ActualBytesRead = Length;
589 Data->Length = (USHORT)Length;
590
591 /* Send the packet */
593 &Header,
594 Data,
595 &KdpContext);
596}
NTSTATUS NTAPI KdpCopyMemoryChunks(_In_ ULONG64 Address, _In_ PVOID Buffer, _In_ ULONG TotalSize, _In_ ULONG ChunkSize, _In_ ULONG Flags, _Out_opt_ PULONG ActualSize)
Definition: kdapi.c:55
#define MMDBG_COPY_PHYSICAL
Definition: mm.h:76
#define MMDBG_COPY_WRITE_COMBINED
Definition: mm.h:80
#define MMDBG_COPY_CACHED
Definition: mm.h:78
#define MMDBG_COPY_UNCACHED
Definition: mm.h:79
#define DBGKD_CACHING_WRITE_COMBINED
Definition: windbgkd.h:192
#define DBGKD_CACHING_CACHED
Definition: windbgkd.h:190
#define DBGKD_CACHING_UNCACHED
Definition: windbgkd.h:191

Referenced by KdpSendWaitContinue().

◆ KdpReadVirtualMemory()

VOID NTAPI KdpReadVirtualMemory ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 467 of file kdapi.c.

470{
471 PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
473 ULONG Length = ReadMemory->TransferCount;
474
475 /* Setup the header */
476 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
477 Header.Buffer = (PCHAR)State;
478 ASSERT(Data->Length == 0);
479
480 /* Validate length */
482 {
483 /* Overflow, set it to maximum possible */
485 }
486
487 /* Do the read */
488 State->ReturnStatus = KdpCopyMemoryChunks(ReadMemory->TargetBaseAddress,
489 Data->Buffer,
490 Length,
491 0,
493 &Length);
494
495 /* Return the actual length read */
496 ReadMemory->ActualBytesRead = Length;
497 Data->Length = (USHORT)Length;
498
499 /* Send the packet */
501 &Header,
502 Data,
503 &KdpContext);
504}

Referenced by KdpSendWaitContinue().

◆ KdpReportCommandStringStateChange()

VOID NTAPI KdpReportCommandStringStateChange ( IN PSTRING  NameString,
IN PSTRING  CommandString,
IN OUT PCONTEXT  Context 
)

Definition at line 1658 of file kdapi.c.

1661{
1663 DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1664 ULONG Length, ActualLength, TotalLength;
1666
1667 /* Start wait loop */
1668 do
1669 {
1670 /* Build the architecture common parts of the message */
1672 Context,
1673 &WaitStateChange);
1674
1675 /* Set the context */
1676 KdpSetContextState(&WaitStateChange, Context);
1677
1678 /* Clear the command string structure */
1679 KdpZeroMemory(&WaitStateChange.u.CommandString,
1680 sizeof(DBGKD_COMMAND_STRING));
1681
1682 /* Normalize name string to max */
1683 Length = min(128 - 1, NameString->Length);
1684
1685 /* Copy it to the message buffer */
1686 KdpCopyMemoryChunks((ULONG_PTR)NameString->Buffer,
1688 Length,
1689 0,
1691 &ActualLength);
1692
1693 /* Null terminate and calculate the total length */
1694 TotalLength = ActualLength;
1696
1697 /* Check if the command string is too long */
1698 Length = CommandString->Length;
1699 if (Length > (PACKET_MAX_SIZE -
1701 {
1702 /* Use maximum possible size */
1705 }
1706
1707 /* Copy it to the message buffer */
1708 KdpCopyMemoryChunks((ULONG_PTR)CommandString->Buffer,
1710 Length,
1711 0,
1713 &ActualLength);
1714
1715 /* Null terminate and calculate the total length */
1716 TotalLength += ActualLength;
1718
1719 /* Now set up the header and the data */
1720 Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1721 Header.Buffer = (PCHAR)&WaitStateChange;
1722 Data.Length = (USHORT)TotalLength;
1723 Data.Buffer = KdpMessageBuffer;
1724
1725 /* Send State Change packet and wait for a reply */
1727 &Header,
1728 &Data,
1729 Context);
1731}
VOID NTAPI KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, IN PCONTEXT Context)
Definition: kdx64.c:66
CHAR KdpMessageBuffer[KDP_MSG_BUFFER_SIZE]
Definition: kddata.c:127
VOID NTAPI KdpSetCommonState(IN ULONG NewState, IN PCONTEXT Context, IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange)
Definition: kdapi.c:386
VOID NTAPI KdpZeroMemory(_In_ PVOID Destination, _In_ SIZE_T Length)
Definition: kdapi.c:42
KCONTINUE_STATUS NTAPI KdpSendWaitContinue(IN ULONG PacketType, IN PSTRING SendHeader, IN PSTRING SendData OPTIONAL, IN OUT PCONTEXT Context)
Definition: kdapi.c:1265
#define min(a, b)
Definition: monoChain.cc:55
enum _KCONTINUE_STATUS KCONTINUE_STATUS
@ ContinueProcessorReselected
Definition: ketypes.h:451
#define ANSI_NULL
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3545 u
DBGKD_COMMAND_STRING CommandString
Definition: windbgkd.h:510
_In_ ULONG TotalLength
Definition: usbdlib.h:158
struct _DBGKD_ANY_WAIT_STATE_CHANGE DBGKD_ANY_WAIT_STATE_CHANGE
#define DbgKdCommandStringStateChange
Definition: windbgkd.h:61
#define PACKET_TYPE_KD_STATE_CHANGE64
Definition: windbgkd.h:48

Referenced by KdpCommandString().

◆ KdpReportExceptionStateChange()

BOOLEAN NTAPI KdpReportExceptionStateChange ( IN PEXCEPTION_RECORD  ExceptionRecord,
IN OUT PCONTEXT  Context,
IN BOOLEAN  SecondChanceException 
)

Definition at line 1735 of file kdapi.c.

1738{
1740 DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1742
1743 /* Start report loop */
1744 do
1745 {
1746 /* Build the architecture common parts of the message */
1748
1749#if !defined(_WIN64)
1750
1751 /* Convert it and copy it over */
1753 &WaitStateChange.u.Exception.ExceptionRecord);
1754
1755#else
1756
1757 /* Just copy it directly, no need to convert */
1758 KdpMoveMemory(&WaitStateChange.u.Exception.ExceptionRecord,
1759 ExceptionRecord,
1760 sizeof(EXCEPTION_RECORD));
1761
1762#endif
1763
1764 /* Set the First Chance flag */
1765 WaitStateChange.u.Exception.FirstChance = !SecondChanceException;
1766
1767 /* Now finish creating the structure */
1768 KdpSetContextState(&WaitStateChange, Context);
1769
1770 /* Setup the actual header to send to KD */
1771 Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1772 Header.Buffer = (PCHAR)&WaitStateChange;
1773
1774 /* Setup the trace data */
1776
1777 /* Send State Change packet and wait for a reply */
1779 &Header,
1780 &Data,
1781 Context);
1783
1784 /* Return */
1785 return Status;
1786}
VOID NTAPI DumpTraceData(IN PSTRING TraceData)
Definition: kdapi.c:371
DBGKM_EXCEPTION64 Exception
Definition: windbgkd.h:508
EXCEPTION_RECORD64 ExceptionRecord
Definition: windbgkd.h:312
#define DbgKdExceptionStateChange
Definition: windbgkd.h:59
static __inline VOID NTAPI ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32, OUT PEXCEPTION_RECORD64 Ex64)
Definition: windbgkd.h:917

Referenced by KdpReport(), and KdpSwitchProcessor().

◆ KdpReportLoadSymbolsStateChange()

VOID NTAPI KdpReportLoadSymbolsStateChange ( IN PSTRING  PathName,
IN PKD_SYMBOLS_INFO  SymbolInfo,
IN BOOLEAN  Unload,
IN OUT PCONTEXT  Context 
)

Definition at line 1586 of file kdapi.c.

1590{
1591 PSTRING ExtraData;
1593 DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1594 ULONG PathNameLength;
1596
1597 /* Start wait loop */
1598 do
1599 {
1600 /* Build the architecture common parts of the message */
1602 Context,
1603 &WaitStateChange);
1604
1605 /* Now finish creating the structure */
1606 KdpSetContextState(&WaitStateChange, Context);
1607
1608 /* Fill out load data */
1609 WaitStateChange.u.LoadSymbols.UnloadSymbols = Unload;
1610 WaitStateChange.u.LoadSymbols.BaseOfDll = (ULONG64)(LONG_PTR)SymbolInfo->BaseOfDll;
1611 WaitStateChange.u.LoadSymbols.ProcessId = SymbolInfo->ProcessId;
1612 WaitStateChange.u.LoadSymbols.CheckSum = SymbolInfo->CheckSum;
1613 WaitStateChange.u.LoadSymbols.SizeOfImage = SymbolInfo->SizeOfImage;
1614
1615 /* Check if we have a path name */
1616 if (PathName)
1617 {
1618 /* Copy it to the path buffer */
1619 KdpCopyMemoryChunks((ULONG_PTR)PathName->Buffer,
1621 PathName->Length,
1622 0,
1624 &PathNameLength);
1625
1626 /* Null terminate */
1627 KdpPathBuffer[PathNameLength++] = ANSI_NULL;
1628
1629 /* Set the path length */
1630 WaitStateChange.u.LoadSymbols.PathNameLength = PathNameLength;
1631
1632 /* Set up the data */
1633 Data.Buffer = KdpPathBuffer;
1634 Data.Length = (USHORT)PathNameLength;
1635 ExtraData = &Data;
1636 }
1637 else
1638 {
1639 /* No name */
1640 WaitStateChange.u.LoadSymbols.PathNameLength = 0;
1641 ExtraData = NULL;
1642 }
1643
1644 /* Setup the header */
1645 Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1646 Header.Buffer = (PCHAR)&WaitStateChange;
1647
1648 /* Send the packet */
1650 &Header,
1651 ExtraData,
1652 Context);
1654}
static VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
Definition: floppy.c:377
CHAR KdpPathBuffer[KDP_MSG_BUFFER_SIZE]
Definition: kddata.c:128
unsigned __int64 ULONG64
Definition: imports.h:198
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
DBGKD_LOAD_SYMBOLS64 LoadSymbols
Definition: windbgkd.h:509
#define DbgKdLoadSymbolsStateChange
Definition: windbgkd.h:60

Referenced by KdpSymbol().

◆ KdpRestoreBreakpoint()

VOID NTAPI KdpRestoreBreakpoint ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 271 of file kdapi.c.

274{
275 PDBGKD_RESTORE_BREAKPOINT RestoreBp = &State->u.RestoreBreakPoint;
277
278 /* Fill out the header */
279 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
280 Header.Buffer = (PCHAR)State;
281 ASSERT(Data->Length == 0);
282
283 /* Get the version block */
285 {
286 /* We're all good */
287 State->ReturnStatus = STATUS_SUCCESS;
288 }
289 else
290 {
291 /* We failed */
292 State->ReturnStatus = STATUS_UNSUCCESSFUL;
293 }
294
295 /* Send the packet */
297 &Header,
298 NULL,
299 &KdpContext);
300}
BOOLEAN NTAPI KdpDeleteBreakpoint(IN ULONG BpEntry)
Definition: kdbreak.c:311

Referenced by KdpSendWaitContinue().

◆ KdpRestoreBreakPointEx()

VOID NTAPI KdpRestoreBreakPointEx ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 327 of file kdapi.c.

330{
331 //PDBGKD_BREAKPOINTEX = &State->u.BreakPointEx;
333
334 /* TODO */
335 KdpDprintf("Extended Breakpoint Restore support is unimplemented!\n");
336
337 /* Send a failure packet */
338 State->ReturnStatus = STATUS_UNSUCCESSFUL;
339 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
340 Header.Buffer = (PCHAR)State;
342 &Header,
343 Data,
344 &KdpContext);
345}

Referenced by KdpSendWaitContinue().

◆ KdpSearchMemory()

VOID NTAPI KdpSearchMemory ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 192 of file kdapi.c.

195{
196 //PDBGKD_SEARCH_MEMORY SearchMemory = &State->u.SearchMemory;
198
199 /* TODO */
200 KdpDprintf("Memory Search support is unimplemented!\n");
201
202 /* Send a failure packet */
203 State->ReturnStatus = STATUS_UNSUCCESSFUL;
204 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
205 Header.Buffer = (PCHAR)State;
207 &Header,
208 NULL,
209 &KdpContext);
210}

Referenced by KdpSendWaitContinue().

◆ KdpSendWaitContinue()

KCONTINUE_STATUS NTAPI KdpSendWaitContinue ( IN ULONG  PacketType,
IN PSTRING  SendHeader,
IN PSTRING SendData  OPTIONAL,
IN OUT PCONTEXT  Context 
)

Definition at line 1265 of file kdapi.c.

1269{
1271 DBGKD_MANIPULATE_STATE64 ManipulateState;
1272 ULONG Length;
1273 KDSTATUS RecvCode;
1274
1275 /* Setup the Manipulate State structure */
1276 Header.MaximumLength = sizeof(DBGKD_MANIPULATE_STATE64);
1277 Header.Buffer = (PCHAR)&ManipulateState;
1278 Data.MaximumLength = sizeof(KdpMessageBuffer);
1279 Data.Buffer = KdpMessageBuffer;
1280
1281 /*
1282 * Reset the context state to ensure the debugger has received
1283 * the current context before it sets it.
1284 */
1286
1288 /* Send the Packet */
1289 KdSendPacket(PacketType, SendHeader, SendData, &KdpContext);
1290
1291 /* If the debugger isn't present anymore, just return success */
1293
1294 /* Main processing Loop */
1295 for (;;)
1296 {
1297 /* Receive Loop */
1298 do
1299 {
1300 /* Wait to get a reply to our packet */
1302 &Header,
1303 &Data,
1304 &Length,
1305 &KdpContext);
1306
1307 /* If we got a resend request, do it */
1308 if (RecvCode == KdPacketNeedsResend) goto SendPacket;
1309 } while (RecvCode == KdPacketTimedOut);
1310
1311 /* Now check what API we got */
1312 switch (ManipulateState.ApiNumber)
1313 {
1315
1316 /* Read virtual memory */
1317 KdpReadVirtualMemory(&ManipulateState, &Data, Context);
1318 break;
1319
1321
1322 /* Write virtual memory */
1323 KdpWriteVirtualMemory(&ManipulateState, &Data, Context);
1324 break;
1325
1326 case DbgKdGetContextApi:
1327
1328 /* Get the current context */
1329 KdpGetContext(&ManipulateState, &Data, Context);
1330 break;
1331
1332 case DbgKdSetContextApi:
1333
1334 /* Set a new context */
1335 KdpSetContext(&ManipulateState, &Data, Context);
1336 break;
1337
1339
1340 /* Write the breakpoint */
1341 KdpWriteBreakpoint(&ManipulateState, &Data, Context);
1342 break;
1343
1345
1346 /* Restore the breakpoint */
1347 KdpRestoreBreakpoint(&ManipulateState, &Data, Context);
1348 break;
1349
1350 case DbgKdContinueApi:
1351
1352 /* Simply continue */
1353 return NT_SUCCESS(ManipulateState.u.Continue.ContinueStatus);
1354
1356
1357 /* Read control space */
1358 KdpReadControlSpace(&ManipulateState, &Data, Context);
1359 break;
1360
1362
1363 /* Write control space */
1364 KdpWriteControlSpace(&ManipulateState, &Data, Context);
1365 break;
1366
1368
1369 /* Read I/O Space */
1370 KdpReadIoSpace(&ManipulateState, &Data, Context);
1371 break;
1372
1374
1375 /* Write I/O Space */
1376 KdpWriteIoSpace(&ManipulateState, &Data, Context);
1377 break;
1378
1379 case DbgKdRebootApi:
1380
1381 /* Reboot the system */
1383 break;
1384
1385 case DbgKdContinueApi2:
1386
1387 /* Check if caller reports success */
1388 if (NT_SUCCESS(ManipulateState.u.Continue2.ContinueStatus))
1389 {
1390 /* Update the state */
1391 KdpGetStateChange(&ManipulateState, Context);
1392 return ContinueSuccess;
1393 }
1394 else
1395 {
1396 /* Return an error */
1397 return ContinueError;
1398 }
1399
1401
1402 /* Read physical memory */
1403 KdpReadPhysicalMemory(&ManipulateState, &Data, Context);
1404 break;
1405
1407
1408 /* Write physical memory */
1409 KdpWritePhysicalMemory(&ManipulateState, &Data, Context);
1410 break;
1411
1415
1416 /* TODO */
1417 KdpDprintf("Special Call support is unimplemented!\n");
1418 KdpNotSupported(&ManipulateState);
1419 break;
1420
1423
1424 /* TODO */
1425 KdpDprintf("Internal Breakpoint support is unimplemented!\n");
1426 KdpNotSupported(&ManipulateState);
1427 break;
1428
1430
1431 /* Read I/O Space */
1432 KdpReadIoSpaceExtended(&ManipulateState, &Data, Context);
1433 break;
1434
1436
1437 /* Write I/O Space */
1438 KdpWriteIoSpaceExtended(&ManipulateState, &Data, Context);
1439 break;
1440
1441 case DbgKdGetVersionApi:
1442
1443 /* Get version data */
1444 KdpGetVersion(&ManipulateState);
1445 break;
1446
1448
1449 /* Write the breakpoint and check if it failed */
1450 if (!NT_SUCCESS(KdpWriteBreakPointEx(&ManipulateState,
1451 &Data,
1452 Context)))
1453 {
1454 /* Return an error */
1455 return ContinueError;
1456 }
1457 break;
1458
1460
1461 /* Restore the breakpoint */
1462 KdpRestoreBreakPointEx(&ManipulateState, &Data, Context);
1463 break;
1464
1466
1467 /* Crash the system */
1468 KdpCauseBugCheck(&ManipulateState);
1469 break;
1470
1472
1473 /* TODO */
1474 KdpDprintf("Processor Switch support is unimplemented!\n");
1475 KdpNotSupported(&ManipulateState);
1476 break;
1477
1478 case DbgKdPageInApi:
1479
1480 /* TODO */
1481 KdpDprintf("Page-In support is unimplemented!\n");
1482 KdpNotSupported(&ManipulateState);
1483 break;
1484
1486
1487 /* Read from the specified MSR */
1488 KdpReadMachineSpecificRegister(&ManipulateState, &Data, Context);
1489 break;
1490
1492
1493 /* Write to the specified MSR */
1494 KdpWriteMachineSpecificRegister(&ManipulateState, &Data, Context);
1495 break;
1496
1498
1499 /* Search memory */
1500 KdpSearchMemory(&ManipulateState, &Data, Context);
1501 break;
1502
1503 case DbgKdGetBusDataApi:
1504
1505 /* Read from the bus */
1506 KdpGetBusData(&ManipulateState, &Data, Context);
1507 break;
1508
1509 case DbgKdSetBusDataApi:
1510
1511 /* Write to the bus */
1512 KdpSetBusData(&ManipulateState, &Data, Context);
1513 break;
1514
1516
1517 /* Check for memory corruption in the lower 4 GB */
1518 KdpCheckLowMemory(&ManipulateState);
1519 break;
1520
1522
1523 /* Just clear the counter */
1525 break;
1526
1527 case DbgKdFillMemoryApi:
1528
1529 /* Fill memory */
1530 KdpFillMemory(&ManipulateState, &Data, Context);
1531 break;
1532
1534
1535 /* Query memory */
1536 KdpQueryMemory(&ManipulateState, Context);
1537 break;
1538
1540
1541 /* TODO */
1542 KdpDprintf("Partition Switch support is unimplemented!\n");
1543 KdpNotSupported(&ManipulateState);
1544 break;
1545
1547
1548 /* Write the customized breakpoint */
1549 KdpWriteCustomBreakpoint(&ManipulateState, &Data, Context);
1550 break;
1551
1553
1554 /* Extended Context Get */
1555 KdpGetContextEx(&ManipulateState, &Data, Context);
1556 break;
1557
1559
1560 /* Extended Context Set */
1561 KdpSetContextEx(&ManipulateState, &Data, Context);
1562 break;
1563
1564 /* Unsupported Messages */
1565 default:
1566
1567 /* Send warning */
1568 KdpDprintf("Received Unrecognized API 0x%lx\n", ManipulateState.ApiNumber);
1569
1570 /* Setup an empty message, with failure */
1571 Data.Length = 0;
1572 ManipulateState.ReturnStatus = STATUS_UNSUCCESSFUL;
1573
1574 /* Send it */
1576 &Header,
1577 &Data,
1578 &KdpContext);
1579 break;
1580 }
1581 }
1582}
VOID NTAPI HalReturnToFirmware(_In_ FIRMWARE_REENTRY Action)
Definition: reboot.c:21
VOID SendPacket(PVOID Context, PNDIS_PACKET NdisPacket, UINT Offset, PVOID LinkAddress, USHORT Type)
Definition: iptest.cpp:247
VOID NTAPI KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
Definition: kdx64.c:22
ULONG KdpNumInternalBreakpoints
Definition: kddata.c:100
VOID NTAPI KdpRestoreBreakPointEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:327
VOID NTAPI KdpFillMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:214
VOID NTAPI KdpWriteMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:987
VOID NTAPI KdpRestoreBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:271
VOID NTAPI KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:443
VOID NTAPI KdpGetContext(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:718
VOID NTAPI KdpNotSupported(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:1245
VOID NTAPI KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:467
VOID NTAPI KdpGetContextEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:825
VOID NTAPI KdpQueryMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
Definition: kdapi.c:133
VOID NTAPI KdpSearchMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:192
VOID NTAPI KdpReadPhysicalMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:537
VOID NTAPI KdpReadControlSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:650
VOID NTAPI KdpWriteBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:236
VOID NTAPI KdpCauseBugCheck(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:949
VOID NTAPI KdpWriteVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:508
VOID NTAPI KdpReadIoSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1091
NTSTATUS NTAPI KdpWriteBreakPointEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:304
VOID NTAPI KdpWriteIoSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1127
VOID NTAPI KdpSetContext(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:773
VOID NTAPI KdpWritePhysicalMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:600
VOID NTAPI KdpSetContextEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:888
VOID NTAPI KdpSetBusData(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1058
VOID NTAPI KdpReadIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1157
VOID NTAPI KdpReadMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:957
VOID NTAPI KdpCheckLowMemory(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:1225
VOID NTAPI KdpWriteIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1194
VOID NTAPI KdpWriteCustomBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:349
VOID NTAPI KdpGetBusData(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1015
VOID NTAPI KdpWriteControlSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:691
BOOLEAN KdDebuggerNotPresent
Definition: kddata.c:82
KDP_STATUS NTAPI KdReceivePacket(IN ULONG PacketType, OUT PSTRING MessageHeader, OUT PSTRING MessageData, OUT PULONG DataLength, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:80
@ HalRebootRoutine
Definition: haltypes.h:37
@ ContinueError
Definition: ketypes.h:449
@ ContinueSuccess
Definition: ketypes.h:450
static BOOL SendData(PINFO pInfo)
Definition: ntpclient.c:76
#define KdPacketNeedsResend
Definition: kddll.h:7
ULONG KDSTATUS
Definition: kddll.h:4
#define KdPacketTimedOut
Definition: kddll.h:6
NTSTATUS ContinueStatus
Definition: windbgkd.h:585
NTSTATUS ContinueStatus
Definition: windbgkd.h:579
DBGKD_CONTINUE2 Continue2
Definition: windbgkd.h:800
union _DBGKD_MANIPULATE_STATE64::@3553 u
DBGKD_CONTINUE Continue
Definition: windbgkd.h:799
#define DbgKdClearAllInternalBreakpointsApi
Definition: windbgkd.h:110
#define DbgKdCheckLowMemoryApi
Definition: windbgkd.h:109
#define DbgKdWriteControlSpaceApi
Definition: windbgkd.h:82
#define DbgKdReadControlSpaceApi
Definition: windbgkd.h:81
#define DbgKdGetContextApi
Definition: windbgkd.h:76
#define DbgKdPageInApi
Definition: windbgkd.h:101
#define DbgKdSetContextExApi
Definition: windbgkd.h:116
#define DbgKdWriteVirtualMemoryApi
Definition: windbgkd.h:75
#define DbgKdGetContextExApi
Definition: windbgkd.h:115
#define DbgKdWriteCustomBreakpointApi
Definition: windbgkd.h:114
#define DbgKdSwitchPartition
Definition: windbgkd.h:113
#define DbgKdSetContextApi
Definition: windbgkd.h:77
#define DbgKdReadIoSpaceApi
Definition: windbgkd.h:83
#define DbgKdWriteBreakPointExApi
Definition: windbgkd.h:97
#define DbgKdSearchMemoryApi
Definition: windbgkd.h:106
#define DbgKdGetInternalBreakPointApi
Definition: windbgkd.h:93
#define DbgKdQuerySpecialCallsApi
Definition: windbgkd.h:89
#define DbgKdReadVirtualMemoryApi
Definition: windbgkd.h:74
#define DbgKdFillMemoryApi
Definition: windbgkd.h:111
#define DbgKdWriteMachineSpecificRegister
Definition: windbgkd.h:103
#define DbgKdCauseBugCheckApi
Definition: windbgkd.h:99
#define DbgKdContinueApi2
Definition: windbgkd.h:86
#define DbgKdWriteBreakPointApi
Definition: windbgkd.h:78
#define DbgKdWriteIoSpaceApi
Definition: windbgkd.h:84
#define DbgKdContinueApi
Definition: windbgkd.h:80
#define DbgKdSetInternalBreakPointApi
Definition: windbgkd.h:92
#define DbgKdGetBusDataApi
Definition: windbgkd.h:107
#define DbgKdClearSpecialCallsApi
Definition: windbgkd.h:91
#define DbgKdWriteIoSpaceExtendedApi
Definition: windbgkd.h:95
#define DbgKdSetBusDataApi
Definition: windbgkd.h:108
#define DbgKdSetSpecialCallApi
Definition: windbgkd.h:90
#define DbgKdWritePhysicalMemoryApi
Definition: windbgkd.h:88
#define DbgKdRestoreBreakPointExApi
Definition: windbgkd.h:98
#define DbgKdQueryMemoryApi
Definition: windbgkd.h:112
#define DbgKdRebootApi
Definition: windbgkd.h:85
#define DbgKdReadMachineSpecificRegister
Definition: windbgkd.h:102
#define DbgKdReadIoSpaceExtendedApi
Definition: windbgkd.h:94
#define DbgKdSwitchProcessor
Definition: windbgkd.h:100
#define DbgKdRestoreBreakPointApi
Definition: windbgkd.h:79
#define DbgKdReadPhysicalMemoryApi
Definition: windbgkd.h:87

Referenced by KdpReportCommandStringStateChange(), KdpReportExceptionStateChange(), and KdpReportLoadSymbolsStateChange().

◆ KdpSetBusData()

VOID NTAPI KdpSetBusData ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 1058 of file kdapi.c.

1061{
1062 STRING Header;
1063 PDBGKD_GET_SET_BUS_DATA SetBusData = &State->u.GetSetBusData;
1064 ULONG Length;
1065
1066 /* Setup the header */
1067 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1068 Header.Buffer = (PCHAR)State;
1069
1070 /* Call the internal routine */
1071 State->ReturnStatus = KdpSysWriteBusData(SetBusData->BusDataType,
1072 SetBusData->BusNumber,
1073 SetBusData->SlotNumber,
1074 SetBusData->Offset,
1075 Data->Buffer,
1076 SetBusData->Length,
1077 &Length);
1078
1079 /* Return the actual length written */
1080 SetBusData->Length = Length;
1081
1082 /* Send the reply */
1084 &Header,
1085 NULL,
1086 &KdpContext);
1087}
NTSTATUS NTAPI KdpSysWriteBusData(IN ULONG BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN ULONG Offset, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:148

Referenced by KdpSendWaitContinue().

◆ KdpSetCommonState()

VOID NTAPI KdpSetCommonState ( IN ULONG  NewState,
IN PCONTEXT  Context,
IN PDBGKD_ANY_WAIT_STATE_CHANGE  WaitStateChange 
)

Definition at line 386 of file kdapi.c.

389{
390 ULONG InstructionCount;
391 BOOLEAN HadBreakpoints;
392
393 /* Setup common stuff available for all CPU architectures */
394 WaitStateChange->NewState = NewState;
395 WaitStateChange->ProcessorLevel = KeProcessorLevel;
396 WaitStateChange->Processor = (USHORT)KeGetCurrentPrcb()->Number;
397 WaitStateChange->NumberProcessors = (ULONG)KeNumberProcessors;
398 WaitStateChange->Thread = (ULONG64)(LONG_PTR)KeGetCurrentThread();
399 WaitStateChange->ProgramCounter = (ULONG64)(LONG_PTR)KeGetContextPc(Context);
400
401 /* Zero out the entire Control Report */
402 KdpZeroMemory(&WaitStateChange->AnyControlReport,
404
405 /* Now copy the instruction stream and set the count */
406 KdpCopyMemoryChunks((ULONG_PTR)WaitStateChange->ProgramCounter,
407 &WaitStateChange->ControlReport.InstructionStream[0],
409 0,
411 &InstructionCount);
412 WaitStateChange->ControlReport.InstructionCount = (USHORT)InstructionCount;
413
414 /* Clear all the breakpoints in this region */
415 HadBreakpoints =
416 KdpDeleteBreakpointRange((PVOID)(ULONG_PTR)WaitStateChange->ProgramCounter,
417 (PVOID)((ULONG_PTR)WaitStateChange->ProgramCounter +
418 WaitStateChange->ControlReport.InstructionCount - 1));
419 if (HadBreakpoints)
420 {
421 /* Copy the instruction stream again, this time without breakpoints */
422 KdpCopyMemoryChunks((ULONG_PTR)WaitStateChange->ProgramCounter,
423 &WaitStateChange->ControlReport.InstructionStream[0],
424 InstructionCount,
425 0,
427 NULL);
428 }
429}
#define KeGetCurrentThread
Definition: hal.h:55
BOOLEAN NTAPI KdpDeleteBreakpointRange(IN PVOID Base, IN PVOID Limit)
Definition: kdbreak.c:340
#define KeGetContextPc(Context)
Definition: ke.h:31
USHORT KeProcessorLevel
Definition: krnlinit.c:20
#define DBGKD_MAXSTREAM
Definition: windbgkd.h:19

Referenced by KdpReportCommandStringStateChange(), KdpReportExceptionStateChange(), and KdpReportLoadSymbolsStateChange().

◆ KdpSetContext()

VOID NTAPI KdpSetContext ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 773 of file kdapi.c.

776{
779
780 /* Setup the header */
781 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
782 Header.Buffer = (PCHAR)State;
783 ASSERT(Data->Length == sizeof(CONTEXT));
784
785 /* Make sure that this is a valid request */
786 if ((State->Processor < KeNumberProcessors) &&
788 {
789 /* Check if the request is for this CPU */
790 if (State->Processor == KeGetCurrentPrcb()->Number)
791 {
792 /* We're just copying our own context */
794 }
795 else
796 {
797 /* Get the context from the PRCB array */
798 TargetContext = &KiProcessorBlock[State->Processor]->
799 ProcessorState.ContextFrame;
800 }
801
802 /* Copy the new context to it */
804 Data->Buffer,
805 sizeof(CONTEXT));
806
807 /* Finish up */
808 State->ReturnStatus = STATUS_SUCCESS;
809 }
810 else
811 {
812 /* Invalid request */
813 State->ReturnStatus = STATUS_UNSUCCESSFUL;
814 }
815
816 /* Send the reply */
818 &Header,
819 NULL,
820 &KdpContext);
821}

Referenced by KdpSendWaitContinue().

◆ KdpSetContextEx()

VOID NTAPI KdpSetContextEx ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 888 of file kdapi.c.

891{
893 PDBGKD_CONTEXT_EX ContextEx;
895
896 /* Get our struct */
897 ContextEx = &State->u.ContextEx;
898 ASSERT(Data->Length == ContextEx->ByteCount);
899
900 /* Set up the header */
901 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
902 Header.Buffer = (PCHAR)State;
903
904 /* Make sure that this is a valid request */
905 if ((State->Processor < KeNumberProcessors) &&
906 ((ContextEx->Offset + ContextEx->ByteCount) <= sizeof(CONTEXT)) &&
908 {
909 /* Check if the request is for this CPU */
910 if (State->Processor == KeGetCurrentPrcb()->Number)
911 {
912 /* We're just copying our own context */
914 }
915 else
916 {
917 /* Get the context from the PRCB array */
918 TargetContext = &KiProcessorBlock[State->Processor]->
919 ProcessorState.ContextFrame;
920 }
921
922 /* Copy what is requested */
924 Data->Buffer,
925 ContextEx->ByteCount);
926
927 /* KD copies all */
928 ContextEx->BytesCopied = ContextEx->ByteCount;
929
930 /* Finish up */
931 State->ReturnStatus = STATUS_SUCCESS;
932 }
933 else
934 {
935 /* Invalid request */
936 ContextEx->BytesCopied = 0;
937 State->ReturnStatus = STATUS_UNSUCCESSFUL;
938 }
939
940 /* Send the reply */
942 &Header,
943 NULL,
944 &KdpContext);
945}

Referenced by KdpSendWaitContinue().

◆ KdpSwitchProcessor()

BOOLEAN NTAPI KdpSwitchProcessor ( IN PEXCEPTION_RECORD  ExceptionRecord,
IN OUT PCONTEXT  ContextRecord,
IN BOOLEAN  SecondChanceException 
)

Definition at line 1838 of file kdapi.c.

1841{
1843
1844 /* Save the port data */
1845 KdSave(FALSE);
1846
1847 /* Report a state change */
1848 Status = KdpReportExceptionStateChange(ExceptionRecord,
1850 SecondChanceException);
1851
1852 /* Restore the port data and return */
1854 return Status;
1855}
BOOLEAN NTAPI KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord, IN OUT PCONTEXT Context, IN BOOLEAN SecondChanceException)
Definition: kdapi.c:1735
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:654

Referenced by KdInitSystem().

◆ KdpSysGetVersion()

VOID NTAPI KdpSysGetVersion ( IN PDBGKD_GET_VERSION64  Version)

Definition at line 433 of file kdapi.c.

434{
435 /* Copy the version block */
438 sizeof(DBGKD_GET_VERSION64));
439}
DBGKD_GET_VERSION64 KdVersionBlock
Definition: kddata.c:496
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469

Referenced by KdpGetVersion().

◆ KdpTimeSlipDpcRoutine()

VOID NTAPI KdpTimeSlipDpcRoutine ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 1790 of file kdapi.c.

1794{
1795 LONG OldSlip, NewSlip, PendingSlip;
1796
1797 /* Get the current pending slip */
1798 PendingSlip = KdpTimeSlipPending;
1799 do
1800 {
1801 /* Save the old value and either disable or enable it now. */
1802 OldSlip = PendingSlip;
1803 NewSlip = OldSlip > 1 ? 1 : 0;
1804
1805 /* Try to change the value */
1807 NewSlip,
1808 OldSlip) != OldSlip);
1809
1810 /* If the New Slip value is 1, then do the Time Slipping */
1812}
#define InterlockedCompareExchange
Definition: interlocked.h:104
WORK_QUEUE_ITEM KdpTimeSlipWorkItem
Definition: kddata.c:118
long LONG
Definition: pedump.c:60
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
@ DelayedWorkQueue
Definition: extypes.h:190

Referenced by KdInitSystem().

◆ KdpTimeSlipWork()

VOID NTAPI KdpTimeSlipWork ( IN PVOID  Context)

Definition at line 1816 of file kdapi.c.

1817{
1818 KIRQL OldIrql;
1820
1821 /* Update the System time from the CMOS */
1825
1826 /* Check if we have a registered Time Slip Event and signal it */
1830
1831 /* Delay the DPC until it runs next time */
1832 DueTime.QuadPart = -1800000000;
1834}
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
PKEVENT KdpTimeSlipEvent
Definition: kddata.c:120
KSPIN_LOCK KdpTimeSlipEventLock
Definition: kddata.c:121
KTIMER KdpTimeSlipTimer
Definition: kddata.c:117
VOID NTAPI ExUpdateSystemTimeFromCmos(IN BOOLEAN UpdateInterruptTime, IN ULONG MaxSepInSeconds)
Definition: time.c:217
VOID NTAPI ExReleaseTimeRefreshLock(VOID)
Definition: time.c:83
BOOLEAN NTAPI ExAcquireTimeRefreshLock(IN BOOLEAN Wait)
Definition: time.c:51
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190

Referenced by KdInitSystem().

◆ KdpWriteBreakpoint()

VOID NTAPI KdpWriteBreakpoint ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 236 of file kdapi.c.

239{
240 PDBGKD_WRITE_BREAKPOINT64 Breakpoint = &State->u.WriteBreakPoint;
242
243 /* Build header */
244 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
245 Header.Buffer = (PCHAR)State;
246 ASSERT(Data->Length == 0);
247
248 /* Create the breakpoint */
249 Breakpoint->BreakPointHandle =
251 if (!Breakpoint->BreakPointHandle)
252 {
253 /* We failed */
254 State->ReturnStatus = STATUS_UNSUCCESSFUL;
255 }
256 else
257 {
258 /* Success! */
259 State->ReturnStatus = STATUS_SUCCESS;
260 }
261
262 /* Send the packet */
264 &Header,
265 NULL,
266 &KdpContext);
267}
ULONG NTAPI KdpAddBreakpoint(IN PVOID Address)
Definition: kdbreak.c:20

Referenced by KdpSendWaitContinue().

◆ KdpWriteBreakPointEx()

NTSTATUS NTAPI KdpWriteBreakPointEx ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 304 of file kdapi.c.

307{
308 //PDBGKD_BREAKPOINTEX = &State->u.BreakPointEx;
310
311 /* TODO */
312 KdpDprintf("Extended Breakpoint Write support is unimplemented!\n");
313
314 /* Send a failure packet */
315 State->ReturnStatus = STATUS_UNSUCCESSFUL;
316 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
317 Header.Buffer = (PCHAR)State;
319 &Header,
320 Data,
321 &KdpContext);
322 return STATUS_UNSUCCESSFUL;
323}

Referenced by KdpSendWaitContinue().

◆ KdpWriteControlSpace()

VOID NTAPI KdpWriteControlSpace ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 691 of file kdapi.c.

694{
695 PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;
697
698 /* Setup the header */
699 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
700 Header.Buffer = (PCHAR)State;
701
702 /* Call the internal routine */
703 State->ReturnStatus = KdpSysWriteControlSpace(State->Processor,
704 WriteMemory->TargetBaseAddress,
705 Data->Buffer,
706 Data->Length,
707 &WriteMemory->ActualBytesWritten);
708
709 /* Send the reply */
711 &Header,
712 Data,
713 &KdpContext);
714}
NTSTATUS NTAPI KdpSysWriteControlSpace(IN ULONG Processor, IN ULONG64 BaseAddress, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:213
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY WriteMemory
Definition: wdfusb.h:1918

Referenced by KdpSendWaitContinue().

◆ KdpWriteCustomBreakpoint()

VOID NTAPI KdpWriteCustomBreakpoint ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 349 of file kdapi.c.

352{
353 //PDBGKD_WRITE_CUSTOM_BREAKPOINT = &State->u.WriteCustomBreakpoint;
355
356 /* Not supported */
357 KdpDprintf("Custom Breakpoint Write is unimplemented\n");
358
359 /* Send a failure packet */
360 State->ReturnStatus = STATUS_UNSUCCESSFUL;
361 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
362 Header.Buffer = (PCHAR)State;
364 &Header,
365 NULL,
366 &KdpContext);
367}

Referenced by KdpSendWaitContinue().

◆ KdpWriteIoSpace()

VOID NTAPI KdpWriteIoSpace ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 1127 of file kdapi.c.

1130{
1131 STRING Header;
1132 PDBGKD_READ_WRITE_IO64 WriteIo = &State->u.ReadWriteIo;
1133
1134 /* Setup the header */
1135 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1136 Header.Buffer = (PCHAR)State;
1137 ASSERT(Data->Length == 0);
1138
1139 /* Call the internal routine */
1140 State->ReturnStatus = KdpSysWriteIoSpace(Isa,
1141 0,
1142 1,
1143 WriteIo->IoAddress,
1144 &WriteIo->DataValue,
1145 WriteIo->DataSize,
1146 &WriteIo->DataSize);
1147
1148 /* Send the reply */
1150 &Header,
1151 NULL,
1152 &KdpContext);
1153}
NTSTATUS NTAPI KdpSysWriteIoSpace(IN ULONG InterfaceType, IN ULONG BusNumber, IN ULONG AddressSpace, IN ULONG64 IoAddress, IN PVOID DataValue, IN ULONG DataSize, OUT PULONG ActualDataSize)
Definition: kdx64.c:300

Referenced by KdpSendWaitContinue().

◆ KdpWriteIoSpaceExtended()

VOID NTAPI KdpWriteIoSpaceExtended ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 1194 of file kdapi.c.

1197{
1198 STRING Header;
1199 PDBGKD_READ_WRITE_IO_EXTENDED64 WriteIoExtended = &State->u.
1200 ReadWriteIoExtended;
1201
1202 /* Setup the header */
1203 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1204 Header.Buffer = (PCHAR)State;
1205 ASSERT(Data->Length == 0);
1206
1207 /* Call the internal routine */
1208 State->ReturnStatus = KdpSysWriteIoSpace(WriteIoExtended->InterfaceType,
1209 WriteIoExtended->BusNumber,
1210 WriteIoExtended->AddressSpace,
1211 WriteIoExtended->IoAddress,
1212 &WriteIoExtended->DataValue,
1213 WriteIoExtended->DataSize,
1214 &WriteIoExtended->DataSize);
1215
1216 /* Send the reply */
1218 &Header,
1219 NULL,
1220 &KdpContext);
1221}

Referenced by KdpSendWaitContinue().

◆ KdpWriteMachineSpecificRegister()

VOID NTAPI KdpWriteMachineSpecificRegister ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 987 of file kdapi.c.

990{
992 PDBGKD_READ_WRITE_MSR WriteMsr = &State->u.ReadWriteMsr;
993 LARGE_INTEGER MsrValue;
994
995 /* Setup the header */
996 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
997 Header.Buffer = (PCHAR)State;
998 ASSERT(Data->Length == 0);
999
1000 /* Call the internal routine */
1001 MsrValue.LowPart = WriteMsr->DataValueLow;
1002 MsrValue.HighPart = WriteMsr->DataValueHigh;
1003 State->ReturnStatus = KdpSysWriteMsr(WriteMsr->Msr,
1004 &MsrValue);
1005
1006 /* Send the reply */
1008 &Header,
1009 NULL,
1010 &KdpContext);
1011}
NTSTATUS NTAPI KdpSysWriteMsr(IN ULONG Msr, IN PLARGE_INTEGER MsrValue)
Definition: kdx64.c:115

Referenced by KdpSendWaitContinue().

◆ KdpWritePhysicalMemory()

VOID NTAPI KdpWritePhysicalMemory ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 600 of file kdapi.c.

603{
604 PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;
606 ULONG Flags, CacheFlags;
607
608 /* Setup the header */
609 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
610 Header.Buffer = (PCHAR)State;
611
612 /* Start with the default flags */
614
615 /* Get the caching flags and check if a type is specified */
616 CacheFlags = WriteMemory->ActualBytesWritten;
617 if (CacheFlags == DBGKD_CACHING_CACHED)
618 {
619 /* Cached */
621 }
622 else if (CacheFlags == DBGKD_CACHING_UNCACHED)
623 {
624 /* Uncached */
626 }
627 else if (CacheFlags == DBGKD_CACHING_WRITE_COMBINED)
628 {
629 /* Write Combined */
631 }
632
633 /* Do the write */
634 State->ReturnStatus = KdpCopyMemoryChunks(WriteMemory->TargetBaseAddress,
635 Data->Buffer,
636 Data->Length,
637 0,
638 Flags,
639 &WriteMemory->ActualBytesWritten);
640
641 /* Send the packet */
643 &Header,
644 NULL,
645 &KdpContext);
646}
#define MMDBG_COPY_WRITE
Definition: mm.h:75

Referenced by KdpSendWaitContinue().

◆ KdpWriteVirtualMemory()

VOID NTAPI KdpWriteVirtualMemory ( IN PDBGKD_MANIPULATE_STATE64  State,
IN PSTRING  Data,
IN PCONTEXT  Context 
)

Definition at line 508 of file kdapi.c.

511{
512 PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;
514
515 /* Setup the header */
516 Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
517 Header.Buffer = (PCHAR)State;
518
519 /* Do the write */
520 State->ReturnStatus = KdpCopyMemoryChunks(WriteMemory->TargetBaseAddress,
521 Data->Buffer,
522 Data->Length,
523 0,
526 &WriteMemory->ActualBytesWritten);
527
528 /* Send the packet */
530 &Header,
531 NULL,
532 &KdpContext);
533}

Referenced by KdpSendWaitContinue().

◆ KdpZeroMemory()

VOID NTAPI KdpZeroMemory ( _In_ PVOID  Destination,
_In_ SIZE_T  Length 
)

Definition at line 42 of file kdapi.c.

45{
46 PCHAR DestinationBytes;
47
48 /* Zero the buffer 1 byte at a time */
49 DestinationBytes = Destination;
50 while (Length--) *DestinationBytes++ = 0;
51}

Referenced by KdpReportCommandStringStateChange(), and KdpSetCommonState().

◆ KdRefreshDebuggerNotPresent()

BOOLEAN NTAPI KdRefreshDebuggerNotPresent ( VOID  )

Definition at line 2324 of file kdapi.c.

2325{
2326 BOOLEAN Enable, DebuggerNotPresent;
2327
2328 /* Check if the debugger is completely disabled */
2329 if (KdPitchDebugger)
2330 {
2331 /* Don't try to refresh then, fail early */
2332 return TRUE;
2333 }
2334
2335 /* Enter the debugger */
2337
2338 /*
2339 * Attempt to send a string to the debugger
2340 * to refresh the connection state.
2341 */
2342 KdpDprintf("KDTARGET: Refreshing KD connection\n");
2343
2344 /* Save the state while we are holding the lock */
2345 DebuggerNotPresent = KdDebuggerNotPresent;
2346
2347 /* Exit the debugger and return the state */
2349 return DebuggerNotPresent;
2350}
BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: kdapi.c:1876
VOID NTAPI KdExitDebugger(IN BOOLEAN Enable)
Definition: kdapi.c:1929

Referenced by _FX_DRIVER_GLOBALS::IsDebuggerAttached().

◆ KdSystemDebugControl()

NTSTATUS NTAPI KdSystemDebugControl ( _In_ SYSDBG_COMMAND  Command,
_In_ PVOID  InputBuffer,
_In_ ULONG  InputBufferLength,
_Out_ PVOID  OutputBuffer,
_In_ ULONG  OutputBufferLength,
_Inout_ PULONG  ReturnLength,
_In_ KPROCESSOR_MODE  PreviousMode 
)

Definition at line 2157 of file kdapi.c.

2165{
2166 /* Handle some internal commands */
2167 switch ((ULONG)Command)
2168 {
2169#if DBG
2170 case ' soR': /* ROS-INTERNAL */
2171 {
2172 switch ((ULONG_PTR)InputBuffer)
2173 {
2174 case 0x21: // DumpAllThreads:
2176 break;
2177
2178 case 0x22: // DumpUserThreads:
2180 break;
2181
2182 case 0x24: // KdSpare3:
2184 break;
2185
2186 default:
2187 break;
2188 }
2189 return STATUS_SUCCESS;
2190 }
2191
2192#if defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c
2193 /* Register a debug callback */
2194 case 'CsoR':
2195 {
2196 switch (InputBufferLength)
2197 {
2198 case ID_Win32PreServiceHook:
2199 KeWin32PreServiceHook = InputBuffer;
2200 break;
2201
2202 case ID_Win32PostServiceHook:
2203 KeWin32PostServiceHook = InputBuffer;
2204 break;
2205
2206 }
2207 break;
2208 }
2209#endif
2210
2211 /* Special case for stack frame dumps */
2212 case 'DsoR':
2213 {
2215 break;
2216 }
2217#ifdef KDBG
2218 /* Register KDBG CLI callback */
2219 case 'RbdK':
2220 {
2222 }
2223#endif // KDBG
2224#endif
2225 default:
2226 break;
2227 }
2228
2229 /* Local kernel debugging is not yet supported */
2230 DbgPrint("KdSystemDebugControl is unimplemented!\n");
2232}
#define KeRosDumpStackFrames(Frames, Count)
Definition: gdidebug.h:11
#define DbgPrint
Definition: hal.h:12
VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads)
BOOLEAN NTAPI KdbRegisterCliCallback(PVOID Callback, BOOLEAN Deregister)
Definition: kdb_cli.c:3125
VOID NTAPI MmDumpArmPfnDatabase(IN BOOLEAN StatusOnly)
Definition: mminit.c:1474
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
Definition: shell.h:41
uint32_t * PULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953

Referenced by DriverEntry(), i8042KbdInterruptService(), KdRosDumpStackFrames(), KdRosSetDebugCallback(), and NtSystemDebugControl().

◆ NtQueryDebugFilterState()

NTSTATUS NTAPI NtQueryDebugFilterState ( _In_ ULONG  ComponentId,
_In_ ULONG  Level 
)

Definition at line 2357 of file kdapi.c.

2360{
2361 PULONG Mask;
2362
2363 /* Check if the ID fits in the component table */
2365 {
2366 /* It does, so get the mask from there */
2368 }
2369 else if (ComponentId == MAXULONG)
2370 {
2371 /*
2372 * This is the internal ID used for DbgPrint messages without ID
2373 * and Level. Use the system-wide mask for those.
2374 */
2376 }
2377 else
2378 {
2379#if (NTDDI_VERSION >= NTDDI_VISTA)
2380 /* Use the default component ID */
2382 // Level = DPFLTR_INFO_LEVEL; // Override the Level.
2383#else
2384 /* Invalid ID, fail */
2386#endif
2387 }
2388
2389 /* Convert Level to bit field if required */
2390 if (Level < 32) Level = 1 << Level;
2391 Level &= ~DPFLTR_MASK;
2392
2393 /* Determine if this Level is filtered out */
2394 if ((Kd_WIN2000_Mask & Level) || (*Mask & Level))
2395 {
2396 /* This mask will get through to the debugger */
2397 return (NTSTATUS)TRUE;
2398 }
2399 else
2400 {
2401 /* This mask is filtered out */
2402 return (NTSTATUS)FALSE;
2403 }
2404}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char UINT32 ComponentId
Definition: acpixf.h:1281
unsigned int Mask
Definition: fpcontrol.c:82
ULONG Kd_WIN2000_Mask
Definition: kddata.c:144
ULONG KdComponentTableSize
Definition: kddata.c:485
ULONG Kd_DEFAULT_Mask
Definition: kddata.c:246
PULONG KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES]
Definition: kddata.c:315
#define MAXULONG
Definition: typedefs.h:251
uint32_t * PULONG
Definition: typedefs.h:59
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56

Referenced by DbgQueryDebugFilterState(), KdpPrint(), and vDbgPrintExWithPrefixInternal().

◆ NtSetDebugFilterState()

NTSTATUS NTAPI NtSetDebugFilterState ( _In_ ULONG  ComponentId,
_In_ ULONG  Level,
_In_ BOOLEAN  State 
)

Definition at line 2411 of file kdapi.c.

2415{
2416 PULONG Mask;
2417
2418 /* Modifying debug filters requires the debug privilege */
2420 {
2421 /* Fail */
2422 return STATUS_ACCESS_DENIED;
2423 }
2424
2425 /* Check if the ID fits in the component table */
2427 {
2428 /* It does, so get the mask from there */
2430 }
2431 else if (ComponentId == MAXULONG)
2432 {
2433 /*
2434 * This is the internal ID used for DbgPrint messages without ID
2435 * and Level. Use the system-wide mask for those.
2436 */
2438 }
2439 else
2440 {
2441#if (NTDDI_VERSION >= NTDDI_VISTA)
2442 /* Use the default component ID */
2444#else
2445 /* Invalid ID, fail */
2447#endif
2448 }
2449
2450 /* Convert Level to bit field if required */
2451 if (Level < 32) Level = 1 << Level;
2452 Level &= ~DPFLTR_MASK;
2453
2454 /* Set or remove the Level */
2455 if (State)
2456 *Mask |= Level;
2457 else
2458 *Mask &= ~Level;
2459
2460 return STATUS_SUCCESS;
2461}
#define ExGetPreviousMode
Definition: ex.h:140
const LUID SeDebugPrivilege
Definition: priv.c:39
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744

Referenced by DbgSetDebugFilterState(), and KdbpCmdFilter().

◆ PspDumpThreads()

VOID NTAPI PspDumpThreads ( BOOLEAN  SystemThreads)

Referenced by KdSystemDebugControl().