ReactOS 0.4.15-dev-8417-gb6b82fe
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)
 
static KCONTINUE_STATUS KdpSwitchProcessor (_In_ USHORT ProcessorIndex)
 
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)
 
KCONTINUE_STATUS NTAPI KdReportProcessorChange (VOID)
 
VOID NTAPI KdpTimeSlipDpcRoutine (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID NTAPI KdpTimeSlipWork (IN PVOID Context)
 
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:110
ULONG TraceDataBuffer[40]
Definition: kddata.c:109
#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 2265 of file kdapi.c.

2271{
2272 /* Fail if there is no debugger */
2273 if (KdPitchDebugger)
2274 {
2275 /* No debugger, no options */
2277 }
2278
2279 /* Do we recognize this option? */
2280 if (Option != KD_OPTION_SET_BLOCK_ENABLE)
2281 {
2282 /* We don't, clear the output length and fail */
2283 if (OutBufferNeeded) *OutBufferNeeded = 0;
2285 }
2286
2287 /* Verify parameters */
2288 if ((InBufferBytes != sizeof(BOOLEAN)) ||
2289 (OutBufferBytes != 0) ||
2290 (OutBuffer != NULL))
2291 {
2292 /* Invalid parameters for this option, fail */
2294 }
2295
2296 /*
2297 * Check if the high bit is set, meaning we don't
2298 * allow the debugger to be enabled
2299 */
2300 if (KdBlockEnable & 0x80)
2301 {
2302 /* Fail regardless of what state the caller tried to set */
2304 }
2305
2306 /* Set the new block enable state */
2307 KdBlockEnable = *(PBOOLEAN)InBuffer;
2308
2309 /* No output buffer required for this option */
2310 if (OutBufferNeeded) *OutBufferNeeded = 0;
2311
2312 /* We are done */
2313 return STATUS_SUCCESS;
2314}
unsigned char BOOLEAN
#define NULL
Definition: types.h:112
BOOLEAN KdPitchDebugger
Definition: kddata.c:80
BOOLEAN KdBlockEnable
Definition: kddata.c:84
#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 2172 of file kdapi.c.

2173{
2174 /* Use the internal routine */
2176}
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI KdDisableDebuggerWithLock(IN BOOLEAN NeedLock)
Definition: kdapi.c:2066

Referenced by PcipGetFunctionLimits().

◆ KdDisableDebuggerWithLock()

NTSTATUS NTAPI KdDisableDebuggerWithLock ( IN BOOLEAN  NeedLock)

Definition at line 2066 of file kdapi.c.

2067{
2068 KIRQL OldIrql;
2070
2071#if defined(__GNUC__)
2072 /* Make gcc happy */
2074#endif
2075
2076 /*
2077 * If enabling the debugger is blocked
2078 * then there is nothing to disable (duh)
2079 */
2080 if (KdBlockEnable)
2081 {
2082 /* Fail */
2083 return STATUS_ACCESS_DENIED;
2084 }
2085
2086 /* Check if we need to acquire the lock */
2087 if (NeedLock)
2088 {
2089 /* Lock the port */
2091 KdpPortLock();
2092 }
2093
2094 /* Check if we're not disabled */
2095 if (!KdDisableCount)
2096 {
2097 /* Check if the debugger was never actually initialized */
2099 {
2100 /* It wasn't, so don't re-enable it later */
2102 }
2103 else
2104 {
2105 /* It was, so we will re-enable it later */
2107 }
2108
2109 /* Check if we were called from the exported API and are enabled */
2110 if ((NeedLock) && (KdPreviouslyEnabled))
2111 {
2112 /* Check if it is safe to disable the debugger */
2114 if (!NT_SUCCESS(Status))
2115 {
2116 /* Release the lock and fail */
2117 KdpPortUnlock();
2119 return Status;
2120 }
2121 }
2122
2123 /* Only disable the debugger if it is enabled */
2125 {
2126 /*
2127 * Disable the debugger; suspend breakpoints
2128 * and reset the debug stub
2129 */
2132
2133 /* We are disabled now */
2135 SharedUserData->KdDebuggerEnabled = FALSE;
2136 }
2137 }
2138
2139 /* Increment the disable count */
2141
2142 /* Check if we had locked the port before */
2143 if (NeedLock)
2144 {
2145 /* Yes, now unlock it */
2146 KdpPortUnlock();
2148 }
2149
2150 /* We're done */
2151 return STATUS_SUCCESS;
2152}
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#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:86
VOID NTAPI KdpPortLock(VOID)
Definition: kdlock.c:19
ULONG KdDisableCount
Definition: kddata.c:89
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:82
#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 2161 of file kdapi.c.

2162{
2163 /* Use the internal routine */
2165}
NTSTATUS NTAPI KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
Definition: kdapi.c:1990

Referenced by KdpStub(), and PcipGetFunctionLimits().

◆ KdEnableDebuggerWithLock()

NTSTATUS NTAPI KdEnableDebuggerWithLock ( IN BOOLEAN  NeedLock)

Definition at line 1990 of file kdapi.c.

1991{
1992 KIRQL OldIrql;
1993
1994#if defined(__GNUC__)
1995 /* Make gcc happy */
1997#endif
1998
1999 /* Check if enabling the debugger is blocked */
2000 if (KdBlockEnable)
2001 {
2002 /* It is, fail the enable */
2003 return STATUS_ACCESS_DENIED;
2004 }
2005
2006 /* Check if we need to acquire the lock */
2007 if (NeedLock)
2008 {
2009 /* Lock the port */
2011 KdpPortLock();
2012 }
2013
2014 /* Check if we're not disabled */
2015 if (!KdDisableCount)
2016 {
2017 /* Check if we had locked the port before */
2018 if (NeedLock)
2019 {
2020 /* Do the unlock */
2021 KdpPortUnlock();
2023
2024 /* Fail: We're already enabled */
2026 }
2027 else
2028 {
2029 /*
2030 * This can only happen if we are called from a bugcheck
2031 * and were never initialized, so initialize the debugger now.
2032 */
2033 KdInitSystem(0, NULL);
2034
2035 /* Return success since we initialized */
2036 return STATUS_SUCCESS;
2037 }
2038 }
2039
2040 /* Decrease the disable count */
2041 if (!(--KdDisableCount))
2042 {
2043 /* We're now enabled again! Were we enabled before, too? */
2045 {
2046 /* Reinitialize the Debugger */
2047 KdInitSystem(0, NULL);
2049 }
2050 }
2051
2052 /* Check if we had locked the port before */
2053 if (NeedLock)
2054 {
2055 /* Yes, now unlock it */
2056 KdpPortUnlock();
2058 }
2059
2060 /* We're done */
2061 return STATUS_SUCCESS;
2062}
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 1902 of file kdapi.c.

1904{
1906
1907 /* Check if we have a trap frame */
1908 if (TrapFrame)
1909 {
1910 /* Calculate the time difference for the enter */
1914 }
1915 else
1916 {
1917 /* No trap frame, so can't calculate */
1919 }
1920
1921 /* Save the current IRQL */
1922 KeGetCurrentPrcb()->DebuggerSavedIRQL = KeGetCurrentIrql();
1923
1924 /* Freeze all CPUs, raising also the IRQL to HIGH_LEVEL */
1925 Enable = KeFreezeExecution(TrapFrame, ExceptionFrame);
1926
1927 /* Lock the port, save the state and set debugger entered */
1929 KdSave(FALSE);
1931
1932 /* Check freeze flag */
1933 if (KiFreezeFlag & 1)
1934 {
1935 /* Print out errror */
1936 KdpDprintf("FreezeLock was jammed! Backup SpinLock was used!\n");
1937 }
1938
1939 /* Check processor state */
1940 if (KiFreezeFlag & 2)
1941 {
1942 /* Print out errror */
1943 KdpDprintf("Some processors not frozen in debugger!\n");
1944 }
1945
1946 /* Make sure we acquired the port */
1947 if (!KdpPortLocked) KdpDprintf("Port lock was not acquired!\n");
1948
1949 /* Return if interrupts needs to be re-enabled */
1950 return Enable;
1951}
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
LARGE_INTEGER KdTimerStop
Definition: kddata.c:121
BOOLEAN KdEnteredDebugger
Definition: kddata.c:88
LARGE_INTEGER KdTimerStart
Definition: kd64.h:550
KSPIN_LOCK KdpDebuggerLock
Definition: kddata.c:67
BOOLEAN KdpPortLocked
Definition: kddata.c:66
LARGE_INTEGER KdTimerDifference
Definition: kd64.h:550
LARGE_INTEGER NTAPI KdpQueryPerformanceCounter(IN PKTRAP_FRAME TrapFrame)
Definition: kdapi.c:1885
NTSTATUS NTAPI KdSave(IN BOOLEAN SleepTransition)
Definition: kdcom.c:113
#define KdpDprintf(...)
Definition: mmdbg.c:19
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
_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 1955 of file kdapi.c.

1956{
1957 ULONG TimeSlip;
1958
1959 /* Restore the state and unlock the port */
1962
1963 /* Unfreeze the CPUs, restoring also the IRQL */
1965
1966 /* Compare time with the one from KdEnterDebugger */
1967 if (!KdTimerStop.QuadPart)
1968 {
1969 /* We didn't get a trap frame earlier in so never got the time */
1971 }
1972 else
1973 {
1974 /* Query the timer */
1976 }
1977
1978 /* Check if a Time Slip was on queue */
1980 if (TimeSlip == 1)
1981 {
1982 /* Queue a DPC for the time slip */
1984 KeInsertQueueDpc(&KdpTimeSlipDpc, NULL, NULL); // FIXME: this can trigger context switches!
1985 }
1986}
#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:118
KDPC KdpTimeSlipDpc
Definition: kddata.c:115
NTSTATUS NTAPI KdRestore(IN BOOLEAN SleepTransition)
Definition: kdcom.c:121
VOID NTAPI KeThawExecution(IN BOOLEAN Enable)
Definition: freeze.c:65

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:1430

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:3016
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 2321 of file kdapi.c.

2322{
2323 /* Check what power state this is */
2324 if (NewState == PowerDeviceD0)
2325 {
2326 /* Wake up the debug port */
2328 return STATUS_SUCCESS;
2329 }
2330 else if ((NewState == PowerDeviceD1) ||
2331 (NewState == PowerDeviceD2) ||
2332 (NewState == PowerDeviceD3))
2333 {
2334 /* Power down the debug port */
2336 return STATUS_SUCCESS;
2337 }
2338 else
2339 {
2340 /* Invalid state! */
2342 }
2343}
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 1885 of file kdapi.c.

1886{
1887 LARGE_INTEGER Null = {{0}};
1888
1889 /* Check if interrupts were disabled */
1890 if (!KeGetTrapFrameInterruptState(TrapFrame))
1891 {
1892 /* Nothing to return */
1893 return Null;
1894 }
1895
1896 /* Otherwise, do the call */
1898}
#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 1678 of file kdapi.c.

1681{
1683 DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1684 ULONG Length, ActualLength, TotalLength;
1686
1687 /* Start wait loop */
1688 do
1689 {
1690 /* Build the architecture common parts of the message */
1692 Context,
1693 &WaitStateChange);
1694
1695 /* Set the context */
1696 KdpSetContextState(&WaitStateChange, Context);
1697
1698 /* Clear the command string structure */
1699 KdpZeroMemory(&WaitStateChange.u.CommandString,
1700 sizeof(DBGKD_COMMAND_STRING));
1701
1702 /* Normalize name string to max */
1703 Length = min(128 - 1, NameString->Length);
1704
1705 /* Copy it to the message buffer */
1706 KdpCopyMemoryChunks((ULONG_PTR)NameString->Buffer,
1708 Length,
1709 0,
1711 &ActualLength);
1712
1713 /* Null terminate and calculate the total length */
1714 TotalLength = ActualLength;
1716
1717 /* Check if the command string is too long */
1718 Length = CommandString->Length;
1719 if (Length > (PACKET_MAX_SIZE -
1721 {
1722 /* Use maximum possible size */
1725 }
1726
1727 /* Copy it to the message buffer */
1728 KdpCopyMemoryChunks((ULONG_PTR)CommandString->Buffer,
1730 Length,
1731 0,
1733 &ActualLength);
1734
1735 /* Null terminate and calculate the total length */
1736 TotalLength += ActualLength;
1738
1739 /* Now set up the header and the data */
1740 Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1741 Header.Buffer = (PCHAR)&WaitStateChange;
1742 Data.Length = (USHORT)TotalLength;
1743 Data.Buffer = KdpMessageBuffer;
1744
1745 /* Send State Change packet and wait for a reply */
1747 &Header,
1748 &Data,
1749 Context);
1751}
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:126
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:1287
#define min(a, b)
Definition: monoChain.cc:55
enum _KCONTINUE_STATUS KCONTINUE_STATUS
@ ContinueProcessorReselected
Definition: ketypes.h:451
#define ANSI_NULL
DBGKD_COMMAND_STRING CommandString
Definition: windbgkd.h:510
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3547 u
_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 1755 of file kdapi.c.

1758{
1760 DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1762
1763 /* Start report loop */
1764 do
1765 {
1766 /* Build the architecture common parts of the message */
1768
1769#if !defined(_WIN64)
1770
1771 /* Convert it and copy it over */
1773 &WaitStateChange.u.Exception.ExceptionRecord);
1774
1775#else
1776
1777 /* Just copy it directly, no need to convert */
1778 KdpMoveMemory(&WaitStateChange.u.Exception.ExceptionRecord,
1779 ExceptionRecord,
1780 sizeof(EXCEPTION_RECORD));
1781
1782#endif
1783
1784 /* Set the First Chance flag */
1785 WaitStateChange.u.Exception.FirstChance = !SecondChanceException;
1786
1787 /* Now finish creating the structure */
1788 KdpSetContextState(&WaitStateChange, Context);
1789
1790 /* Setup the actual header to send to KD */
1791 Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1792 Header.Buffer = (PCHAR)&WaitStateChange;
1793
1794 /* Setup the trace data */
1796
1797 /* Send State Change packet and wait for a reply */
1799 &Header,
1800 &Data,
1801 Context);
1803
1804 /* Return */
1805 return Status;
1806}
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 KdReportProcessorChange().

◆ KdpReportLoadSymbolsStateChange()

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

Definition at line 1606 of file kdapi.c.

1610{
1611 PSTRING ExtraData;
1613 DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1614 ULONG PathNameLength;
1616
1617 /* Start wait loop */
1618 do
1619 {
1620 /* Build the architecture common parts of the message */
1622 Context,
1623 &WaitStateChange);
1624
1625 /* Now finish creating the structure */
1626 KdpSetContextState(&WaitStateChange, Context);
1627
1628 /* Fill out load data */
1629 WaitStateChange.u.LoadSymbols.UnloadSymbols = Unload;
1630 WaitStateChange.u.LoadSymbols.BaseOfDll = (ULONG64)(LONG_PTR)SymbolInfo->BaseOfDll;
1631 WaitStateChange.u.LoadSymbols.ProcessId = SymbolInfo->ProcessId;
1632 WaitStateChange.u.LoadSymbols.CheckSum = SymbolInfo->CheckSum;
1633 WaitStateChange.u.LoadSymbols.SizeOfImage = SymbolInfo->SizeOfImage;
1634
1635 /* Check if we have a path name */
1636 if (PathName)
1637 {
1638 /* Copy it to the path buffer */
1639 KdpCopyMemoryChunks((ULONG_PTR)PathName->Buffer,
1641 PathName->Length,
1642 0,
1644 &PathNameLength);
1645
1646 /* Null terminate */
1647 KdpPathBuffer[PathNameLength++] = ANSI_NULL;
1648
1649 /* Set the path length */
1650 WaitStateChange.u.LoadSymbols.PathNameLength = PathNameLength;
1651
1652 /* Set up the data */
1653 Data.Buffer = KdpPathBuffer;
1654 Data.Length = (USHORT)PathNameLength;
1655 ExtraData = &Data;
1656 }
1657 else
1658 {
1659 /* No name */
1660 WaitStateChange.u.LoadSymbols.PathNameLength = 0;
1661 ExtraData = NULL;
1662 }
1663
1664 /* Setup the header */
1665 Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1666 Header.Buffer = (PCHAR)&WaitStateChange;
1667
1668 /* Send the packet */
1670 &Header,
1671 ExtraData,
1672 Context);
1674}
static VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
Definition: floppy.c:377
CHAR KdpPathBuffer[KDP_MSG_BUFFER_SIZE]
Definition: kddata.c:127
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 1287 of file kdapi.c.

1291{
1293 DBGKD_MANIPULATE_STATE64 ManipulateState;
1294 ULONG Length;
1295 KDSTATUS RecvCode;
1296
1297 /* Setup the Manipulate State structure */
1298 Header.MaximumLength = sizeof(DBGKD_MANIPULATE_STATE64);
1299 Header.Buffer = (PCHAR)&ManipulateState;
1300 Data.MaximumLength = sizeof(KdpMessageBuffer);
1301 Data.Buffer = KdpMessageBuffer;
1302
1303 /*
1304 * Reset the context state to ensure the debugger has received
1305 * the current context before it sets it.
1306 */
1308
1310 /* Send the Packet */
1311 KdSendPacket(PacketType, SendHeader, SendData, &KdpContext);
1312
1313 /* If the debugger isn't present anymore, just return success */
1315
1316 /* Main processing Loop */
1317 for (;;)
1318 {
1319 /* Receive Loop */
1320 do
1321 {
1322 /* Wait to get a reply to our packet */
1324 &Header,
1325 &Data,
1326 &Length,
1327 &KdpContext);
1328
1329 /* If we got a resend request, do it */
1330 if (RecvCode == KdPacketNeedsResend) goto SendPacket;
1331 } while (RecvCode == KdPacketTimedOut);
1332
1333 /* Now check what API we got */
1334 switch (ManipulateState.ApiNumber)
1335 {
1337
1338 /* Read virtual memory */
1339 KdpReadVirtualMemory(&ManipulateState, &Data, Context);
1340 break;
1341
1343
1344 /* Write virtual memory */
1345 KdpWriteVirtualMemory(&ManipulateState, &Data, Context);
1346 break;
1347
1348 case DbgKdGetContextApi:
1349
1350 /* Get the current context */
1351 KdpGetContext(&ManipulateState, &Data, Context);
1352 break;
1353
1354 case DbgKdSetContextApi:
1355
1356 /* Set a new context */
1357 KdpSetContext(&ManipulateState, &Data, Context);
1358 break;
1359
1361
1362 /* Write the breakpoint */
1363 KdpWriteBreakpoint(&ManipulateState, &Data, Context);
1364 break;
1365
1367
1368 /* Restore the breakpoint */
1369 KdpRestoreBreakpoint(&ManipulateState, &Data, Context);
1370 break;
1371
1372 case DbgKdContinueApi:
1373
1374 /* Simply continue */
1375 return NT_SUCCESS(ManipulateState.u.Continue.ContinueStatus);
1376
1378
1379 /* Read control space */
1380 KdpReadControlSpace(&ManipulateState, &Data, Context);
1381 break;
1382
1384
1385 /* Write control space */
1386 KdpWriteControlSpace(&ManipulateState, &Data, Context);
1387 break;
1388
1390
1391 /* Read I/O Space */
1392 KdpReadIoSpace(&ManipulateState, &Data, Context);
1393 break;
1394
1396
1397 /* Write I/O Space */
1398 KdpWriteIoSpace(&ManipulateState, &Data, Context);
1399 break;
1400
1401 case DbgKdRebootApi:
1402
1403 /* Reboot the system */
1405 break;
1406
1407 case DbgKdContinueApi2:
1408
1409 /* Check if caller reports success */
1410 if (NT_SUCCESS(ManipulateState.u.Continue2.ContinueStatus))
1411 {
1412 /* Update the state */
1413 KdpGetStateChange(&ManipulateState, Context);
1414 return ContinueSuccess;
1415 }
1416 else
1417 {
1418 /* Return an error */
1419 return ContinueError;
1420 }
1421
1423
1424 /* Read physical memory */
1425 KdpReadPhysicalMemory(&ManipulateState, &Data, Context);
1426 break;
1427
1429
1430 /* Write physical memory */
1431 KdpWritePhysicalMemory(&ManipulateState, &Data, Context);
1432 break;
1433
1437
1438 /* TODO */
1439 KdpDprintf("Special Call support is unimplemented!\n");
1440 KdpNotSupported(&ManipulateState);
1441 break;
1442
1445
1446 /* TODO */
1447 KdpDprintf("Internal Breakpoint support is unimplemented!\n");
1448 KdpNotSupported(&ManipulateState);
1449 break;
1450
1452
1453 /* Read I/O Space */
1454 KdpReadIoSpaceExtended(&ManipulateState, &Data, Context);
1455 break;
1456
1458
1459 /* Write I/O Space */
1460 KdpWriteIoSpaceExtended(&ManipulateState, &Data, Context);
1461 break;
1462
1463 case DbgKdGetVersionApi:
1464
1465 /* Get version data */
1466 KdpGetVersion(&ManipulateState);
1467 break;
1468
1470
1471 /* Write the breakpoint and check if it failed */
1472 if (!NT_SUCCESS(KdpWriteBreakPointEx(&ManipulateState,
1473 &Data,
1474 Context)))
1475 {
1476 /* Return an error */
1477 return ContinueError;
1478 }
1479 break;
1480
1482
1483 /* Restore the breakpoint */
1484 KdpRestoreBreakPointEx(&ManipulateState, &Data, Context);
1485 break;
1486
1488
1489 /* Crash the system */
1490 KdpCauseBugCheck(&ManipulateState);
1491 break;
1492
1494
1495 /* Switch the processor and return */
1496 return KdpSwitchProcessor(ManipulateState.Processor);
1497
1498 case DbgKdPageInApi:
1499
1500 /* TODO */
1501 KdpDprintf("Page-In support is unimplemented!\n");
1502 KdpNotSupported(&ManipulateState);
1503 break;
1504
1506
1507 /* Read from the specified MSR */
1508 KdpReadMachineSpecificRegister(&ManipulateState, &Data, Context);
1509 break;
1510
1512
1513 /* Write to the specified MSR */
1514 KdpWriteMachineSpecificRegister(&ManipulateState, &Data, Context);
1515 break;
1516
1518
1519 /* Search memory */
1520 KdpSearchMemory(&ManipulateState, &Data, Context);
1521 break;
1522
1523 case DbgKdGetBusDataApi:
1524
1525 /* Read from the bus */
1526 KdpGetBusData(&ManipulateState, &Data, Context);
1527 break;
1528
1529 case DbgKdSetBusDataApi:
1530
1531 /* Write to the bus */
1532 KdpSetBusData(&ManipulateState, &Data, Context);
1533 break;
1534
1536
1537 /* Check for memory corruption in the lower 4 GB */
1538 KdpCheckLowMemory(&ManipulateState);
1539 break;
1540
1542
1543 /* Just clear the counter */
1545 break;
1546
1547 case DbgKdFillMemoryApi:
1548
1549 /* Fill memory */
1550 KdpFillMemory(&ManipulateState, &Data, Context);
1551 break;
1552
1554
1555 /* Query memory */
1556 KdpQueryMemory(&ManipulateState, Context);
1557 break;
1558
1560
1561 /* TODO */
1562 KdpDprintf("Partition Switch support is unimplemented!\n");
1563 KdpNotSupported(&ManipulateState);
1564 break;
1565
1567
1568 /* Write the customized breakpoint */
1569 KdpWriteCustomBreakpoint(&ManipulateState, &Data, Context);
1570 break;
1571
1573
1574 /* Extended Context Get */
1575 KdpGetContextEx(&ManipulateState, &Data, Context);
1576 break;
1577
1579
1580 /* Extended Context Set */
1581 KdpSetContextEx(&ManipulateState, &Data, Context);
1582 break;
1583
1584 /* Unsupported Messages */
1585 default:
1586
1587 /* Send warning */
1588 KdpDprintf("Received Unrecognized API 0x%lx\n", ManipulateState.ApiNumber);
1589
1590 /* Setup an empty message, with failure */
1591 Data.Length = 0;
1592 ManipulateState.ReturnStatus = STATUS_UNSUCCESSFUL;
1593
1594 /* Send it */
1596 &Header,
1597 &Data,
1598 &KdpContext);
1599 break;
1600 }
1601 }
1602}
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:99
static KCONTINUE_STATUS KdpSwitchProcessor(_In_ USHORT ProcessorIndex)
Definition: kdapi.c:1265
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:81
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
union _DBGKD_MANIPULATE_STATE64::@3555 u
DBGKD_CONTINUE2 Continue2
Definition: windbgkd.h:800
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()

static KCONTINUE_STATUS KdpSwitchProcessor ( _In_ USHORT  ProcessorIndex)
static

Definition at line 1265 of file kdapi.c.

1267{
1268 /* Make sure that the processor index is valid */
1269 if (ProcessorIndex >= KeNumberProcessors)
1270 {
1271 KdpDprintf("%u is not a valid processor number\n", ProcessorIndex);
1273 }
1274
1275 /* If the new processor is the current one, there is nothing to do */
1276 if (ProcessorIndex == KeGetCurrentProcessorNumber())
1277 {
1279 }
1280
1281 /* Call the architecture specific Ke routine */
1282 return KxSwitchKdProcessor(ProcessorIndex);
1283}
KCONTINUE_STATUS NTAPI KxSwitchKdProcessor(_In_ ULONG ProcessorIndex)
Definition: freeze.c:184
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:341

Referenced by KdpSendWaitContinue().

◆ 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:495
_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 1837 of file kdapi.c.

1841{
1842 LONG OldSlip, NewSlip, PendingSlip;
1843
1844 /* Get the current pending slip */
1845 PendingSlip = KdpTimeSlipPending;
1846 do
1847 {
1848 /* Save the old value and either disable or enable it now. */
1849 OldSlip = PendingSlip;
1850 NewSlip = OldSlip > 1 ? 1 : 0;
1851
1852 /* Try to change the value */
1854 NewSlip,
1855 OldSlip) != OldSlip);
1856
1857 /* If the New Slip value is 1, then do the Time Slipping */
1859}
#define InterlockedCompareExchange
Definition: interlocked.h:104
WORK_QUEUE_ITEM KdpTimeSlipWorkItem
Definition: kddata.c:117
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 1863 of file kdapi.c.

1864{
1865 KIRQL OldIrql;
1867
1868 /* Update the System time from the CMOS */
1872
1873 /* Check if we have a registered Time Slip Event and signal it */
1877
1878 /* Delay the DPC until it runs next time */
1879 DueTime.QuadPart = -1800000000;
1881}
#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:119
KSPIN_LOCK KdpTimeSlipEventLock
Definition: kddata.c:120
KTIMER KdpTimeSlipTimer
Definition: kddata.c:116
VOID NTAPI ExUpdateSystemTimeFromCmos(IN BOOLEAN UpdateInterruptTime, IN ULONG MaxSepInSeconds)
Definition: time.c:311
VOID NTAPI ExReleaseTimeRefreshLock(VOID)
Definition: time.c:177
BOOLEAN NTAPI ExAcquireTimeRefreshLock(IN BOOLEAN Wait)
Definition: time.c:145
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 2350 of file kdapi.c.

2351{
2352 BOOLEAN Enable, DebuggerNotPresent;
2353
2354 /* Check if the debugger is completely disabled */
2355 if (KdPitchDebugger)
2356 {
2357 /* Don't try to refresh then, fail early */
2358 return TRUE;
2359 }
2360
2361 /* Enter the debugger */
2363
2364 /*
2365 * Attempt to send a string to the debugger
2366 * to refresh the connection state.
2367 */
2368 KdpDprintf("KDTARGET: Refreshing KD connection\n");
2369
2370 /* Save the state while we are holding the lock */
2371 DebuggerNotPresent = KdDebuggerNotPresent;
2372
2373 /* Exit the debugger and return the state */
2375 return DebuggerNotPresent;
2376}
BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: kdapi.c:1902
VOID NTAPI KdExitDebugger(IN BOOLEAN Enable)
Definition: kdapi.c:1955

Referenced by _FX_DRIVER_GLOBALS::IsDebuggerAttached().

◆ KdReportProcessorChange()

KCONTINUE_STATUS NTAPI KdReportProcessorChange ( VOID  )

Definition at line 1810 of file kdapi.c.

1812{
1813 PKPRCB CurrentPrcb = KeGetCurrentPrcb();
1815 EXCEPTION_RECORD ExceptionRecord = {0};
1817
1818 /* Save the port data */
1819 KdSave(FALSE);
1820
1823
1824 /* Report the new state */
1825 Status = KdpReportExceptionStateChange(&ExceptionRecord,
1827 FALSE);
1828
1829 /* Restore the port data */
1831
1832 return Status;
1833}
BOOLEAN NTAPI KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord, IN OUT PCONTEXT Context, IN BOOLEAN SecondChanceException)
Definition: kdapi.c:1755
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:654
#define STATUS_WAKE_SYSTEM_DEBUGGER
Definition: ntstatus.h:188
DWORD ExceptionCode
Definition: compat.h:208
PVOID ExceptionAddress
Definition: compat.h:211
KPROCESSOR_STATE ProcessorState
Definition: ketypes.h:663
CONTEXT ContextFrame
Definition: ketypes.h:616

Referenced by KiProcessorFreezeHandler().

◆ 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 2183 of file kdapi.c.

2191{
2192 /* Handle some internal commands */
2193 switch ((ULONG)Command)
2194 {
2195#if DBG
2196 case ' soR': /* ROS-INTERNAL */
2197 {
2198 switch ((ULONG_PTR)InputBuffer)
2199 {
2200 case 0x21: // DumpAllThreads:
2202 break;
2203
2204 case 0x22: // DumpUserThreads:
2206 break;
2207
2208 case 0x24: // KdSpare3:
2210 break;
2211
2212 default:
2213 break;
2214 }
2215 return STATUS_SUCCESS;
2216 }
2217
2218#if defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c
2219 /* Register a debug callback */
2220 case 'CsoR':
2221 {
2222 switch (InputBufferLength)
2223 {
2224 case ID_Win32PreServiceHook:
2225 KeWin32PreServiceHook = InputBuffer;
2226 break;
2227
2228 case ID_Win32PostServiceHook:
2229 KeWin32PostServiceHook = InputBuffer;
2230 break;
2231
2232 }
2233 break;
2234 }
2235#endif
2236
2237 /* Special case for stack frame dumps */
2238 case 'DsoR':
2239 {
2241 break;
2242 }
2243#ifdef KDBG
2244 /* Register KDBG CLI callback */
2245 case 'RbdK':
2246 {
2248 }
2249#endif // KDBG
2250#endif
2251 default:
2252 break;
2253 }
2254
2255 /* Local kernel debugging is not yet supported */
2256 DbgPrint("KdSystemDebugControl is unimplemented!\n");
2258}
#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 2383 of file kdapi.c.

2386{
2387 PULONG Mask;
2388
2389 /* Check if the ID fits in the component table */
2391 {
2392 /* It does, so get the mask from there */
2394 }
2395 else if (ComponentId == MAXULONG)
2396 {
2397 /*
2398 * This is the internal ID used for DbgPrint messages without ID
2399 * and Level. Use the system-wide mask for those.
2400 */
2402 }
2403 else
2404 {
2405#if (NTDDI_VERSION >= NTDDI_VISTA)
2406 /* Use the default component ID */
2408 // Level = DPFLTR_INFO_LEVEL; // Override the Level.
2409#else
2410 /* Invalid ID, fail */
2412#endif
2413 }
2414
2415 /* Convert Level to bit field if required */
2416 if (Level < 32) Level = 1 << Level;
2417 Level &= ~DPFLTR_MASK;
2418
2419 /* Determine if this Level is filtered out */
2420 if ((Kd_WIN2000_Mask & Level) || (*Mask & Level))
2421 {
2422 /* This mask will get through to the debugger */
2423 return (NTSTATUS)TRUE;
2424 }
2425 else
2426 {
2427 /* This mask is filtered out */
2428 return (NTSTATUS)FALSE;
2429 }
2430}
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:143
ULONG KdComponentTableSize
Definition: kddata.c:484
ULONG Kd_DEFAULT_Mask
Definition: kddata.c:245
PULONG KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES]
Definition: kddata.c:314
#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 2437 of file kdapi.c.

2441{
2442 PULONG Mask;
2443
2444 /* Modifying debug filters requires the debug privilege */
2446 {
2447 /* Fail */
2448 return STATUS_ACCESS_DENIED;
2449 }
2450
2451 /* Check if the ID fits in the component table */
2453 {
2454 /* It does, so get the mask from there */
2456 }
2457 else if (ComponentId == MAXULONG)
2458 {
2459 /*
2460 * This is the internal ID used for DbgPrint messages without ID
2461 * and Level. Use the system-wide mask for those.
2462 */
2464 }
2465 else
2466 {
2467#if (NTDDI_VERSION >= NTDDI_VISTA)
2468 /* Use the default component ID */
2470#else
2471 /* Invalid ID, fail */
2473#endif
2474 }
2475
2476 /* Convert Level to bit field if required */
2477 if (Level < 32) Level = 1 << Level;
2478 Level &= ~DPFLTR_MASK;
2479
2480 /* Set or remove the Level */
2481 if (State)
2482 *Mask |= Level;
2483 else
2484 *Mask &= ~Level;
2485
2486 return STATUS_SUCCESS;
2487}
#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().