ReactOS  0.4.15-dev-1619-g69dffed
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 13 of file kdapi.c.

Function Documentation

◆ DumpTraceData()

VOID NTAPI DumpTraceData ( IN PSTRING  TraceData)

Definition at line 366 of file kdapi.c.

367 {
368  /* Update the buffer */
370 
371  /* Setup the trace data */
372  TraceData->Length = (USHORT)(TraceDataBufferPosition * sizeof(ULONG));
373  TraceData->Buffer = (PCHAR)TraceDataBuffer;
374 
375  /* Reset the buffer location */
377 }
#define PCHAR
Definition: match.c:90
ULONG TraceDataBufferPosition
Definition: kddata.c:111
unsigned short USHORT
Definition: pedump.c:61
ULONG TraceDataBuffer[40]
Definition: kddata.c:110
unsigned int ULONG
Definition: retypes.h:1

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

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

◆ KdDisableDebugger()

NTSTATUS NTAPI KdDisableDebugger ( VOID  )

Definition at line 2141 of file kdapi.c.

2142 {
2143  /* Use the internal routine */
2145 }
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI KdDisableDebuggerWithLock(IN BOOLEAN NeedLock)
Definition: kdapi.c:2035

Referenced by PcipGetFunctionLimits().

◆ KdDisableDebuggerWithLock()

NTSTATUS NTAPI KdDisableDebuggerWithLock ( IN BOOLEAN  NeedLock)

Definition at line 2035 of file kdapi.c.

2036 {
2037  KIRQL OldIrql;
2038  NTSTATUS Status;
2039 
2040 #if defined(__GNUC__)
2041  /* Make gcc happy */
2043 #endif
2044 
2045  /*
2046  * If enabling the debugger is blocked
2047  * then there is nothing to disable (duh)
2048  */
2049  if (KdBlockEnable)
2050  {
2051  /* Fail */
2052  return STATUS_ACCESS_DENIED;
2053  }
2054 
2055  /* Check if we need to acquire the lock */
2056  if (NeedLock)
2057  {
2058  /* Lock the port */
2060  KdpPortLock();
2061  }
2062 
2063  /* Check if we're not disabled */
2064  if (!KdDisableCount)
2065  {
2066  /* Check if the debugger was never actually initialized */
2067  if (!(KdDebuggerEnabled) && !(KdPitchDebugger))
2068  {
2069  /* It wasn't, so don't re-enable it later */
2071  }
2072  else
2073  {
2074  /* It was, so we will re-enable it later */
2076  }
2077 
2078  /* Check if we were called from the exported API and are enabled */
2079  if ((NeedLock) && (KdPreviouslyEnabled))
2080  {
2081  /* Check if it is safe to disable the debugger */
2082  Status = KdpAllowDisable();
2083  if (!NT_SUCCESS(Status))
2084  {
2085  /* Release the lock and fail */
2087  KdpPortUnlock();
2088  return Status;
2089  }
2090  }
2091 
2092  /* Only disable the debugger if it is enabled */
2093  if (KdDebuggerEnabled)
2094  {
2095  /*
2096  * Disable the debugger; suspend breakpoints
2097  * and reset the debug stub
2098  */
2101 
2102  /* We are disabled now */
2104  SharedUserData->KdDebuggerEnabled = FALSE;
2105  }
2106  }
2107 
2108  /* Increment the disable count */
2109  KdDisableCount++;
2110 
2111  /* Check if we had locked the port before */
2112  if (NeedLock)
2113  {
2114  /* Yes, now unlock it */
2116  KdpPortUnlock();
2117  }
2118 
2119  /* We're done */
2120  return STATUS_SUCCESS;
2121 }
BOOLEAN KdDebuggerEnabled
Definition: kddata.c:83
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
PKDEBUG_ROUTINE KiDebugRoutine
Definition: kddata.c:74
#define TRUE
Definition: types.h:120
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
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN KdPreviouslyEnabled
Definition: kddata.c:87
BOOLEAN KdPitchDebugger
Definition: kddata.c:81
BOOLEAN KdBlockEnable
Definition: kddata.c:85
NTSTATUS NTAPI KdpAllowDisable(VOID)
Definition: kdx64.c:364
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
VOID NTAPI KdpPortUnlock(VOID)
Definition: kdlock.c:27
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID NTAPI KdpSuspendAllBreakPoints(VOID)
Definition: kdbreak.c:407
#define SharedUserData
ULONG KdDisableCount
Definition: kddata.c:90
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI KdpPortLock(VOID)
Definition: kdlock.c:19
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by KdDisableDebugger(), and KdInitSystem().

◆ KdEnableDebugger()

NTSTATUS NTAPI KdEnableDebugger ( VOID  )

Definition at line 2130 of file kdapi.c.

2131 {
2132  /* Use the internal routine */
2134 }
NTSTATUS NTAPI KdEnableDebuggerWithLock(IN BOOLEAN NeedLock)
Definition: kdapi.c:1959
#define TRUE
Definition: types.h:120

Referenced by KdpStub(), and PcipGetFunctionLimits().

◆ KdEnableDebuggerWithLock()

NTSTATUS NTAPI KdEnableDebuggerWithLock ( IN BOOLEAN  NeedLock)

Definition at line 1959 of file kdapi.c.

1960 {
1961  KIRQL OldIrql;
1962 
1963 #if defined(__GNUC__)
1964  /* Make gcc happy */
1966 #endif
1967 
1968  /* Check if enabling the debugger is blocked */
1969  if (KdBlockEnable)
1970  {
1971  /* It is, fail the enable */
1972  return STATUS_ACCESS_DENIED;
1973  }
1974 
1975  /* Check if we need to acquire the lock */
1976  if (NeedLock)
1977  {
1978  /* Lock the port */
1980  KdpPortLock();
1981  }
1982 
1983  /* Check if we're not disabled */
1984  if (!KdDisableCount)
1985  {
1986  /* Check if we had locked the port before */
1987  if (NeedLock)
1988  {
1989  /* Do the unlock */
1991  KdpPortUnlock();
1992 
1993  /* Fail: We're already enabled */
1994  return STATUS_INVALID_PARAMETER;
1995  }
1996  else
1997  {
1998  /*
1999  * This can only happen if we are called from a bugcheck
2000  * and were never initialized, so initialize the debugger now.
2001  */
2002  KdInitSystem(0, NULL);
2003 
2004  /* Return success since we initialized */
2005  return STATUS_SUCCESS;
2006  }
2007  }
2008 
2009  /* Decrease the disable count */
2010  if (!(--KdDisableCount))
2011  {
2012  /* We're now enabled again! Were we enabled before, too? */
2013  if (KdPreviouslyEnabled)
2014  {
2015  /* Reinitialize the Debugger */
2016  KdInitSystem(0, NULL);
2018  }
2019  }
2020 
2021  /* Check if we had locked the port before */
2022  if (NeedLock)
2023  {
2024  /* Yes, now unlock it */
2026  KdpPortUnlock();
2027  }
2028 
2029  /* We're done */
2030  return STATUS_SUCCESS;
2031 }
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN KdPreviouslyEnabled
Definition: kddata.c:87
BOOLEAN KdBlockEnable
Definition: kddata.c:85
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID NTAPI KdpPortUnlock(VOID)
Definition: kdlock.c:27
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
ULONG KdDisableCount
Definition: kddata.c:90
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
BOOLEAN NTAPI KdInitSystem(ULONG Reserved, PLOADER_PARAMETER_BLOCK LoaderBlock)
#define NULL
Definition: types.h:112
VOID NTAPI KdpPortLock(VOID)
Definition: kdlock.c:19
#define STATUS_SUCCESS
Definition: shellext.h:65
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 1871 of file kdapi.c.

1873 {
1874  BOOLEAN Enable;
1875 
1876  /* Check if we have a trap frame */
1877  if (TrapFrame)
1878  {
1879  /* Calculate the time difference for the enter */
1883  }
1884  else
1885  {
1886  /* No trap frame, so can't calculate */
1887  KdTimerStop.QuadPart = 0;
1888  }
1889 
1890  /* Save the current IRQL */
1891  KeGetCurrentPrcb()->DebuggerSavedIRQL = KeGetCurrentIrql();
1892 
1893  /* Freeze all CPUs */
1894  Enable = KeFreezeExecution(TrapFrame, ExceptionFrame);
1895 
1896  /* Lock the port, save the state and set debugger entered */
1898  KdSave(FALSE);
1900 
1901  /* Check freeze flag */
1902  if (KiFreezeFlag & 1)
1903  {
1904  /* Print out errror */
1905  KdpDprintf("FreezeLock was jammed! Backup SpinLock was used!\n");
1906  }
1907 
1908  /* Check processor state */
1909  if (KiFreezeFlag & 2)
1910  {
1911  /* Print out errror */
1912  KdpDprintf("Some processors not frozen in debugger!\n");
1913  }
1914 
1915  /* Make sure we acquired the port */
1916  if (!KdpPortLocked) KdpDprintf("Port lock was not acquired!\n");
1917 
1918  /* Return if interrupts needs to be re-enabled */
1919  return Enable;
1920 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define TRUE
Definition: types.h:120
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
KSPIN_LOCK KdpDebuggerLock
Definition: kddata.c:67
LARGE_INTEGER KdTimerDifference
Definition: kddata.c:122
LARGE_INTEGER KdTimerStart
Definition: kd64.h:548
LARGE_INTEGER NTAPI KdpQueryPerformanceCounter(IN PKTRAP_FRAME TrapFrame)
Definition: kdapi.c:1854
#define FALSE
Definition: types.h:117
BOOLEAN KdEnteredDebugger
Definition: kddata.c:89
BOOLEAN NTAPI KeFreezeExecution(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: freeze.c:26
unsigned char BOOLEAN
ULONG KiFreezeFlag
Definition: cpu.c:38
LARGE_INTEGER KdTimerStop
Definition: kddata.c:122
BOOLEAN KdpPortLocked
Definition: kddata.c:66
NTSTATUS NTAPI KdSave(IN BOOLEAN SleepTransition)
Definition: kdcom.c:113
BOOLEAN FASTCALL KeTryToAcquireSpinLockAtDpcLevel(IN OUT PKSPIN_LOCK SpinLock)
Definition: spinlock.c:303
#define KdpDprintf(...)
Definition: mmdbg.c:19
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 1924 of file kdapi.c.

1925 {
1926  ULONG TimeSlip;
1927 
1928  /* Restore the state and unlock the port */
1929  KdRestore(FALSE);
1931 
1932  /* Unfreeze the CPUs */
1934 
1935  /* Compare time with the one from KdEnterDebugger */
1936  if (!KdTimerStop.QuadPart)
1937  {
1938  /* We didn't get a trap frame earlier in so never got the time */
1940  }
1941  else
1942  {
1943  /* Query the timer */
1945  }
1946 
1947  /* Check if a Time Slip was on queue */
1949  if (TimeSlip == 1)
1950  {
1951  /* Queue a DPC for the time slip */
1953  KeInsertQueueDpc(&KdpTimeSlipDpc, NULL, NULL); // FIXME: this can trigger context switches!
1954  }
1955 }
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
VOID NTAPI KeThawExecution(IN BOOLEAN Enable)
Definition: freeze.c:46
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:724
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
NTSTATUS NTAPI KdRestore(IN BOOLEAN SleepTransition)
Definition: kdcom.c:121
LONG KdpTimeSlipPending
Definition: kddata.c:119
LARGE_INTEGER KdTimerStart
Definition: kd64.h:548
#define FALSE
Definition: types.h:117
VOID NTAPI KdpPortUnlock(VOID)
Definition: kdlock.c:27
LARGE_INTEGER KdTimerStop
Definition: kddata.c:122
KDPC KdpTimeSlipDpc
Definition: kddata.c:116
#define InterlockedIncrement
Definition: armddk.h:53
#define NULL
Definition: types.h:112
BOOLEAN KdpPortLocked
Definition: kddata.c:66
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:114

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

◆ KdpCauseBugCheck()

VOID NTAPI KdpCauseBugCheck ( IN PDBGKD_MANIPULATE_STATE64  State)

Definition at line 944 of file kdapi.c.

945 {
946  /* Crash with the special code */
947  KeBugCheck(MANUALLY_INITIATED_CRASH);
948 }
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427

Referenced by KdpSendWaitContinue().

◆ KdpCheckLowMemory()

VOID NTAPI KdpCheckLowMemory ( IN PDBGKD_MANIPULATE_STATE64  State)

Definition at line 1220 of file kdapi.c.

1221 {
1222  STRING Header;
1223 
1224  /* Setup the header */
1225  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1226  Header.Buffer = (PCHAR)State;
1227 
1228  /* Call the internal routine */
1229  State->ReturnStatus = KdpSysCheckLowMemory(MMDBG_COPY_UNSAFE);
1230 
1231  /* Send the reply */
1233  &Header,
1234  NULL,
1235  &KdpContext);
1236 }
NTSTATUS NTAPI KdpSysCheckLowMemory(IN ULONG Flags)
Definition: kdx64.c:356
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
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 50 of file kdapi.c.

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

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

212 {
213  //PDBGKD_FILL_MEMORY FillMemory = &State->u.FillMemory;
214  STRING Header;
215 
216  /* TODO */
217  KdpDprintf("Memory Fill support is unimplemented!\n");
218 
219  /* Send a failure packet */
220  State->ReturnStatus = STATUS_UNSUCCESSFUL;
221  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
222  Header.Buffer = (PCHAR)State;
224  &Header,
225  NULL,
226  &KdpContext);
227 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
#define KdpDprintf(...)
Definition: mmdbg.c:19
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpGetBusData()

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

Definition at line 1010 of file kdapi.c.

1013 {
1014  STRING Header;
1015  PDBGKD_GET_SET_BUS_DATA GetBusData = &State->u.GetSetBusData;
1016  ULONG Length;
1017 
1018  /* Setup the header */
1019  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1020  Header.Buffer = (PCHAR)State;
1021  ASSERT(Data->Length == 0);
1022 
1023  /* Check the length requested */
1024  Length = GetBusData->Length;
1026  {
1027  /* Use maximum allowed */
1029  }
1030 
1031  /* Call the internal routine */
1032  State->ReturnStatus = KdpSysReadBusData(GetBusData->BusDataType,
1033  GetBusData->BusNumber,
1034  GetBusData->SlotNumber,
1035  GetBusData->Offset,
1036  Data->Buffer,
1037  Length,
1038  &Length);
1039 
1040  /* Return the actual length read */
1041  GetBusData->Length = Length;
1042  Data->Length = (USHORT)Length;
1043 
1044  /* Send the reply */
1046  &Header,
1047  Data,
1048  &KdpContext);
1049 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
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
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpGetContext()

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

Definition at line 713 of file kdapi.c.

716 {
717  STRING Header;
719 
720  /* Setup the header */
721  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
722  Header.Buffer = (PCHAR)State;
723  ASSERT(Data->Length == 0);
724 
725  /* Make sure that this is a valid request */
726  if (State->Processor < KeNumberProcessors)
727  {
728  /* Check if the request is for this CPU */
729  if (State->Processor == KeGetCurrentPrcb()->Number)
730  {
731  /* We're just copying our own context */
733  }
734  else
735  {
736  /* Get the context from the PRCB array */
737  TargetContext = &KiProcessorBlock[State->Processor]->
738  ProcessorState.ContextFrame;
739  }
740 
741  /* Copy it over to the debugger */
742  KdpMoveMemory(Data->Buffer,
744  sizeof(CONTEXT));
745  Data->Length = sizeof(CONTEXT);
746 
747  /* Let the debugger set the context now */
749 
750  /* Finish up */
751  State->ReturnStatus = STATUS_SUCCESS;
752  }
753  else
754  {
755  /* Invalid request */
756  State->ReturnStatus = STATUS_UNSUCCESSFUL;
757  }
758 
759  /* Send the reply */
761  &Header,
762  Data,
763  &KdpContext);
764 }
BOOLEAN KdpContextSent
Definition: kddata.c:69
#define TRUE
Definition: types.h:120
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
struct _CONTEXT CONTEXT
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG _In_opt_ PVOID TargetContext
Definition: fsrtlfuncs.h:738
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpGetContextEx()

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

Definition at line 820 of file kdapi.c.

823 {
824  STRING Header;
825  PDBGKD_CONTEXT_EX ContextEx;
827  ASSERT(Data->Length == 0);
828 
829  /* Get our struct */
830  ContextEx = &State->u.ContextEx;
831 
832  /* Set up the header */
833  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
834  Header.Buffer = (PCHAR)State;
835 
836  /* Make sure that this is a valid request */
837  if ((State->Processor < KeNumberProcessors) &&
838  (ContextEx->Offset + ContextEx->ByteCount) <= sizeof(CONTEXT))
839  {
840  /* Check if the request is for this CPU */
841  if (State->Processor == KeGetCurrentPrcb()->Number)
842  {
843  /* We're just copying our own context */
845  }
846  else
847  {
848  /* Get the context from the PRCB array */
849  TargetContext = &KiProcessorBlock[State->Processor]->
850  ProcessorState.ContextFrame;
851  }
852 
853  /* Copy what is requested */
854  KdpMoveMemory(Data->Buffer,
855  (PVOID)((ULONG_PTR)TargetContext + ContextEx->Offset),
856  ContextEx->ByteCount);
857 
858  /* KD copies all */
859  Data->Length = ContextEx->BytesCopied = ContextEx->ByteCount;
860 
861  /* Let the debugger set the context now */
863 
864  /* Finish up */
865  State->ReturnStatus = STATUS_SUCCESS;
866  }
867  else
868  {
869  /* Invalid request */
870  ContextEx->BytesCopied = 0;
871  State->ReturnStatus = STATUS_UNSUCCESSFUL;
872  }
873 
874  /* Send the reply */
876  &Header,
877  Data,
878  &KdpContext);
879 }
BOOLEAN KdpContextSent
Definition: kddata.c:69
#define TRUE
Definition: types.h:120
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
uint32_t ULONG_PTR
Definition: typedefs.h:65
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG _In_opt_ PVOID TargetContext
Definition: fsrtlfuncs.h:738
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpGetVersion()

VOID NTAPI KdpGetVersion ( IN PDBGKD_MANIPULATE_STATE64  State)

Definition at line 438 of file kdapi.c.

439 {
440  STRING Header;
441 
442  /* Fill out the header */
443  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
444  Header.Buffer = (PCHAR)State;
445 
446  /* Get the version block */
447  KdpSysGetVersion(&State->u.GetVersion64);
448 
449  /* Fill out the state */
450  State->ApiNumber = DbgKdGetVersionApi;
451  State->ReturnStatus = STATUS_SUCCESS;
452 
453  /* Send the packet */
455  &Header,
456  NULL,
457  &KdpContext);
458 }
#define DbgKdGetVersionApi
Definition: windbgkd.h:96
VOID NTAPI KdpSysGetVersion(IN PDBGKD_GET_VERSION64 Version)
Definition: kdapi.c:428
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpMoveMemory()

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

Definition at line 22 of file kdapi.c.

26 {
27  PCHAR DestinationBytes, SourceBytes;
28 
29  /* Copy the buffers 1 byte at a time */
30  DestinationBytes = Destination;
31  SourceBytes = Source;
32  while (Length--) *DestinationBytes++ = *SourceBytes++;
33 }
signed char * PCHAR
Definition: retypes.h:7
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2937
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by 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 1240 of file kdapi.c.

1241 {
1242  STRING Header;
1243 
1244  /* Set failure */
1245  State->ReturnStatus = STATUS_UNSUCCESSFUL;
1246 
1247  /* Setup the packet */
1248  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1249  Header.Buffer = (PCHAR)State;
1250 
1251  /* Send it */
1253  &Header,
1254  NULL,
1255  &KdpContext);
1256 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdPowerTransition()

NTSTATUS NTAPI KdPowerTransition ( IN DEVICE_POWER_STATE  NewState)

Definition at line 2290 of file kdapi.c.

2291 {
2292  /* Check what power state this is */
2293  if (NewState == PowerDeviceD0)
2294  {
2295  /* Wake up the debug port */
2296  KdD0Transition();
2297  return STATUS_SUCCESS;
2298  }
2299  else if ((NewState == PowerDeviceD1) ||
2300  (NewState == PowerDeviceD2) ||
2301  (NewState == PowerDeviceD3))
2302  {
2303  /* Power down the debug port */
2304  KdD3Transition();
2305  return STATUS_SUCCESS;
2306  }
2307  else
2308  {
2309  /* Invalid state! */
2311  }
2312 }
NTSTATUS NTAPI KdD0Transition(VOID)
Definition: kdcom.c:99
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
NTSTATUS NTAPI KdD3Transition(VOID)
Definition: kdcom.c:106
#define STATUS_SUCCESS
Definition: shellext.h:65

◆ KdpQueryMemory()

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

Definition at line 128 of file kdapi.c.

130 {
131  PDBGKD_QUERY_MEMORY Memory = &State->u.QueryMemory;
132  STRING Header;
134 
135  /* Validate the address space */
136  if (Memory->AddressSpace == DBGKD_QUERY_MEMORY_VIRTUAL)
137  {
138  /* Check if this is process memory */
139  if ((PVOID)(ULONG_PTR)Memory->Address < MmHighestUserAddress)
140  {
141  /* It is */
142  Memory->AddressSpace = DBGKD_QUERY_MEMORY_PROCESS;
143  }
144  else
145  {
146  /* Check if it's session space */
147  if (MmIsSessionAddress((PVOID)(ULONG_PTR)Memory->Address))
148  {
149  /* It is */
150  Memory->AddressSpace = DBGKD_QUERY_MEMORY_SESSION;
151  }
152  else
153  {
154  /* Not session space but some other kernel memory */
155  Memory->AddressSpace = DBGKD_QUERY_MEMORY_KERNEL;
156  }
157  }
158 
159  /* Set flags */
163  }
164  else
165  {
166  /* Invalid */
168  }
169 
170  /* Return structure */
171  State->ReturnStatus = Status;
172  Memory->Reserved = 0;
173 
174  /* Build header */
175  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
176  Header.Buffer = (PCHAR)State;
177 
178  /* Send the packet */
180  &Header,
181  NULL,
182  &KdpContext);
183 }
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define DBGKD_QUERY_MEMORY_VIRTUAL
Definition: windbgkd.h:159
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI MmIsSessionAddress(IN PVOID Address)
Definition: session.c:49
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define DBGKD_QUERY_MEMORY_KERNEL
Definition: windbgkd.h:162
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
_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
Status
Definition: gdiplustypes.h:24
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define DBGKD_QUERY_MEMORY_EXECUTE
Definition: windbgkd.h:169
#define DBGKD_QUERY_MEMORY_PROCESS
Definition: windbgkd.h:160
#define DBGKD_QUERY_MEMORY_SESSION
Definition: windbgkd.h:161
#define DBGKD_QUERY_MEMORY_READ
Definition: windbgkd.h:167
#define NULL
Definition: types.h:112
PVOID MmHighestUserAddress
Definition: rtlcompat.c:29
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64
#define DBGKD_QUERY_MEMORY_WRITE
Definition: windbgkd.h:168

Referenced by KdpSendWaitContinue().

◆ KdpQueryPerformanceCounter()

LARGE_INTEGER NTAPI KdpQueryPerformanceCounter ( IN PKTRAP_FRAME  TrapFrame)

Definition at line 1854 of file kdapi.c.

1855 {
1856  LARGE_INTEGER Null = {{0}};
1857 
1858  /* Check if interrupts were disabled */
1859  if (!KeGetTrapFrameInterruptState(TrapFrame))
1860  {
1861  /* Nothing to return */
1862  return Null;
1863  }
1864 
1865  /* Otherwise, do the call */
1867 }
LARGE_INTEGER NTAPI KeQueryPerformanceCounter(IN PLARGE_INTEGER PerformanceFreq)
Definition: timer.c:138
#define KeGetTrapFrameInterruptState(TrapFrame)
Definition: ke.h:170
#define NULL
Definition: types.h:112

Referenced by KdEnterDebugger().

◆ KdpReadControlSpace()

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

Definition at line 645 of file kdapi.c.

648 {
649  PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
650  STRING Header;
651  ULONG Length;
652 
653  /* Setup the header */
654  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
655  Header.Buffer = (PCHAR)State;
656  ASSERT(Data->Length == 0);
657 
658  /* Check the length requested */
659  Length = ReadMemory->TransferCount;
661  {
662  /* Use maximum allowed */
664  }
665 
666  /* Call the internal routine */
667  State->ReturnStatus = KdpSysReadControlSpace(State->Processor,
668  ReadMemory->TargetBaseAddress,
669  Data->Buffer,
670  Length,
671  &Length);
672 
673  /* Return the actual length read */
674  ReadMemory->ActualBytesRead = Length;
675  Data->Length = (USHORT)Length;
676 
677  /* Send the reply */
679  &Header,
680  Data,
681  &KdpContext);
682 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18
Definition: Header.h:8
NTSTATUS NTAPI KdpSysReadControlSpace(IN ULONG Processor, IN ULONG64 BaseAddress, IN PVOID Buffer, IN ULONG Length, OUT PULONG ActualLength)
Definition: kdx64.c:162
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY ReadMemory
Definition: wdfusb.h:1996
unsigned short USHORT
Definition: pedump.c:61
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpReadIoSpace()

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

Definition at line 1086 of file kdapi.c.

1089 {
1090  STRING Header;
1091  PDBGKD_READ_WRITE_IO64 ReadIo = &State->u.ReadWriteIo;
1092 
1093  /* Setup the header */
1094  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1095  Header.Buffer = (PCHAR)State;
1096  ASSERT(Data->Length == 0);
1097 
1098  /*
1099  * Clear the value so 1 or 2 byte reads
1100  * don't leave the higher bits unmodified
1101  */
1102  ReadIo->DataValue = 0;
1103 
1104  /* Call the internal routine */
1105  State->ReturnStatus = KdpSysReadIoSpace(Isa,
1106  0,
1107  1,
1108  ReadIo->IoAddress,
1109  &ReadIo->DataValue,
1110  ReadIo->DataSize,
1111  &ReadIo->DataSize);
1112 
1113  /* Send the reply */
1115  &Header,
1116  NULL,
1117  &KdpContext);
1118 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
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
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpReadIoSpaceExtended()

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

Definition at line 1152 of file kdapi.c.

1155 {
1156  STRING Header;
1157  PDBGKD_READ_WRITE_IO_EXTENDED64 ReadIoExtended = &State->u.
1158  ReadWriteIoExtended;
1159 
1160  /* Setup the header */
1161  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1162  Header.Buffer = (PCHAR)State;
1163  ASSERT(Data->Length == 0);
1164 
1165  /*
1166  * Clear the value so 1 or 2 byte reads
1167  * don't leave the higher bits unmodified
1168  */
1169  ReadIoExtended->DataValue = 0;
1170 
1171  /* Call the internal routine */
1172  State->ReturnStatus = KdpSysReadIoSpace(ReadIoExtended->InterfaceType,
1173  ReadIoExtended->BusNumber,
1174  ReadIoExtended->AddressSpace,
1175  ReadIoExtended->IoAddress,
1176  &ReadIoExtended->DataValue,
1177  ReadIoExtended->DataSize,
1178  &ReadIoExtended->DataSize);
1179 
1180  /* Send the reply */
1182  &Header,
1183  NULL,
1184  &KdpContext);
1185 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
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
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpReadMachineSpecificRegister()

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

Definition at line 952 of file kdapi.c.

955 {
956  STRING Header;
957  PDBGKD_READ_WRITE_MSR ReadMsr = &State->u.ReadWriteMsr;
958  LARGE_INTEGER MsrValue;
959 
960  /* Setup the header */
961  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
962  Header.Buffer = (PCHAR)State;
963  ASSERT(Data->Length == 0);
964 
965  /* Call the internal routine */
966  State->ReturnStatus = KdpSysReadMsr(ReadMsr->Msr,
967  &MsrValue);
968 
969  /* Return the data */
970  ReadMsr->DataValueLow = MsrValue.LowPart;
971  ReadMsr->DataValueHigh = MsrValue.HighPart;
972 
973  /* Send the reply */
975  &Header,
976  NULL,
977  &KdpContext);
978 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
ULONG LowPart
Definition: typedefs.h:106
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64
NTSTATUS NTAPI KdpSysReadMsr(IN ULONG Msr, OUT PLARGE_INTEGER MsrValue)
Definition: kdx64.c:96

Referenced by KdpSendWaitContinue().

◆ KdpReadPhysicalMemory()

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

Definition at line 532 of file kdapi.c.

535 {
536  PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
537  STRING Header;
538  ULONG Length = ReadMemory->TransferCount;
539  ULONG Flags, CacheFlags;
540 
541  /* Setup the header */
542  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
543  Header.Buffer = (PCHAR)State;
544  ASSERT(Data->Length == 0);
545 
546  /* Validate length */
548  {
549  /* Overflow, set it to maximum possible */
551  }
552 
553  /* Start with the default flags */
555 
556  /* Get the caching flags and check if a type is specified */
557  CacheFlags = ReadMemory->ActualBytesRead;
558  if (CacheFlags == DBGKD_CACHING_CACHED)
559  {
560  /* Cached */
562  }
563  else if (CacheFlags == DBGKD_CACHING_UNCACHED)
564  {
565  /* Uncached */
567  }
568  else if (CacheFlags == DBGKD_CACHING_WRITE_COMBINED)
569  {
570  /* Write Combined */
572  }
573 
574  /* Do the read */
575  State->ReturnStatus = KdpCopyMemoryChunks(ReadMemory->TargetBaseAddress,
576  Data->Buffer,
577  Length,
578  0,
579  Flags,
580  &Length);
581 
582  /* Return the actual length read */
583  ReadMemory->ActualBytesRead = Length;
584  Data->Length = (USHORT)Length;
585 
586  /* Send the packet */
588  &Header,
589  Data,
590  &KdpContext);
591 }
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:50
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18
#define DBGKD_CACHING_UNCACHED
Definition: windbgkd.h:191
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define DBGKD_CACHING_CACHED
Definition: windbgkd.h:190
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ASSERT(a)
Definition: mode.c:45
#define MMDBG_COPY_UNCACHED
Definition: mm.h:57
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY ReadMemory
Definition: wdfusb.h:1996
#define MMDBG_COPY_WRITE_COMBINED
Definition: mm.h:58
#define DBGKD_CACHING_WRITE_COMBINED
Definition: windbgkd.h:192
unsigned short USHORT
Definition: pedump.c:61
#define MMDBG_COPY_PHYSICAL
Definition: mm.h:54
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
#define MMDBG_COPY_CACHED
Definition: mm.h:56
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpReadVirtualMemory()

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

Definition at line 462 of file kdapi.c.

465 {
466  PDBGKD_READ_MEMORY64 ReadMemory = &State->u.ReadMemory;
467  STRING Header;
468  ULONG Length = ReadMemory->TransferCount;
469 
470  /* Setup the header */
471  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
472  Header.Buffer = (PCHAR)State;
473  ASSERT(Data->Length == 0);
474 
475  /* Validate length */
477  {
478  /* Overflow, set it to maximum possible */
480  }
481 
482  /* Do the read */
483  State->ReturnStatus = KdpCopyMemoryChunks(ReadMemory->TargetBaseAddress,
484  Data->Buffer,
485  Length,
486  0,
488  &Length);
489 
490  /* Return the actual length read */
491  ReadMemory->ActualBytesRead = Length;
492  Data->Length = (USHORT)Length;
493 
494  /* Send the packet */
496  &Header,
497  Data,
498  &KdpContext);
499 }
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:50
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY ReadMemory
Definition: wdfusb.h:1996
unsigned short USHORT
Definition: pedump.c:61
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpReportCommandStringStateChange()

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

Definition at line 1653 of file kdapi.c.

1656 {
1657  STRING Header, Data;
1658  DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1659  ULONG Length, ActualLength, TotalLength;
1661 
1662  /* Start wait loop */
1663  do
1664  {
1665  /* Build the architecture common parts of the message */
1667  Context,
1668  &WaitStateChange);
1669 
1670  /* Set the context */
1671  KdpSetContextState(&WaitStateChange, Context);
1672 
1673  /* Clear the command string structure */
1674  KdpZeroMemory(&WaitStateChange.u.CommandString,
1675  sizeof(DBGKD_COMMAND_STRING));
1676 
1677  /* Normalize name string to max */
1678  Length = min(128 - 1, NameString->Length);
1679 
1680  /* Copy it to the message buffer */
1681  KdpCopyMemoryChunks((ULONG_PTR)NameString->Buffer,
1683  Length,
1684  0,
1686  &ActualLength);
1687 
1688  /* Null terminate and calculate the total length */
1689  TotalLength = ActualLength;
1691 
1692  /* Check if the command string is too long */
1693  Length = CommandString->Length;
1694  if (Length > (PACKET_MAX_SIZE -
1696  {
1697  /* Use maximum possible size */
1698  Length = (PACKET_MAX_SIZE -
1700  }
1701 
1702  /* Copy it to the message buffer */
1703  KdpCopyMemoryChunks((ULONG_PTR)CommandString->Buffer,
1705  Length,
1706  0,
1708  &ActualLength);
1709 
1710  /* Null terminate and calculate the total length */
1711  TotalLength += ActualLength;
1713 
1714  /* Now set up the header and the data */
1715  Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1716  Header.Buffer = (PCHAR)&WaitStateChange;
1717  Data.Length = (USHORT)TotalLength;
1718  Data.Buffer = KdpMessageBuffer;
1719 
1720  /* Send State Change packet and wait for a reply */
1722  &Header,
1723  &Data,
1724  Context);
1725  } while (Status == ContinueProcessorReselected);
1726 }
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:50
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3514 u
enum _KCONTINUE_STATUS KCONTINUE_STATUS
_In_ ULONG TotalLength
Definition: usbdlib.h:158
#define PACKET_MAX_SIZE
Definition: windbgkd.h:18
KCONTINUE_STATUS NTAPI KdpSendWaitContinue(IN ULONG PacketType, IN PSTRING SendHeader, IN PSTRING SendData OPTIONAL, IN OUT PCONTEXT Context)
Definition: kdapi.c:1260
CHAR KdpMessageBuffer[0x1000]
Definition: kddata.c:127
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ANSI_NULL
Definition: Header.h:8
#define PCHAR
Definition: match.c:90
Status
Definition: gdiplustypes.h:24
#define DbgKdCommandStringStateChange
Definition: windbgkd.h:61
DBGKD_COMMAND_STRING CommandString
Definition: windbgkd.h:490
VOID NTAPI KdpSetCommonState(IN ULONG NewState, IN PCONTEXT Context, IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange)
Definition: kdapi.c:381
struct _DBGKD_ANY_WAIT_STATE_CHANGE DBGKD_ANY_WAIT_STATE_CHANGE
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_CHANGE64
Definition: windbgkd.h:48
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, IN PCONTEXT Context)
Definition: kdx64.c:66
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
#define min(a, b)
Definition: monoChain.cc:55
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdpZeroMemory(_In_ PVOID Destination, _In_ SIZE_T Length)
Definition: kdapi.c:37

Referenced by KdpCommandString().

◆ KdpReportExceptionStateChange()

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

Definition at line 1730 of file kdapi.c.

1733 {
1734  STRING Header, Data;
1735  DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1737 
1738  /* Start report loop */
1739  do
1740  {
1741  /* Build the architecture common parts of the message */
1743 
1744 #if !defined(_WIN64)
1745 
1746  /* Convert it and copy it over */
1747  ExceptionRecord32To64((PEXCEPTION_RECORD32)ExceptionRecord,
1748  &WaitStateChange.u.Exception.ExceptionRecord);
1749 
1750 #else
1751 
1752  /* Just copy it directly, no need to convert */
1753  KdpMoveMemory(&WaitStateChange.u.Exception.ExceptionRecord,
1754  ExceptionRecord,
1755  sizeof(EXCEPTION_RECORD));
1756 
1757 #endif
1758 
1759  /* Set the First Chance flag */
1760  WaitStateChange.u.Exception.FirstChance = !SecondChanceException;
1761 
1762  /* Now finish creating the structure */
1763  KdpSetContextState(&WaitStateChange, Context);
1764 
1765  /* Setup the actual header to send to KD */
1766  Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1767  Header.Buffer = (PCHAR)&WaitStateChange;
1768 
1769  /* Setup the trace data */
1770  DumpTraceData(&Data);
1771 
1772  /* Send State Change packet and wait for a reply */
1774  &Header,
1775  &Data,
1776  Context);
1777  } while (Status == ContinueProcessorReselected);
1778 
1779  /* Return */
1780  return Status;
1781 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3514 u
enum _KCONTINUE_STATUS KCONTINUE_STATUS
VOID NTAPI DumpTraceData(IN PSTRING TraceData)
Definition: kdapi.c:366
#define DbgKdExceptionStateChange
Definition: windbgkd.h:59
KCONTINUE_STATUS NTAPI KdpSendWaitContinue(IN ULONG PacketType, IN PSTRING SendHeader, IN PSTRING SendData OPTIONAL, IN OUT PCONTEXT Context)
Definition: kdapi.c:1260
Definition: Header.h:8
static __inline VOID NTAPI ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32, OUT PEXCEPTION_RECORD64 Ex64)
Definition: windbgkd.h:897
#define PCHAR
Definition: match.c:90
Status
Definition: gdiplustypes.h:24
VOID NTAPI KdpSetCommonState(IN ULONG NewState, IN PCONTEXT Context, IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange)
Definition: kdapi.c:381
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
struct _DBGKD_ANY_WAIT_STATE_CHANGE DBGKD_ANY_WAIT_STATE_CHANGE
std::wstring STRING
Definition: fontsub.cpp:33
EXCEPTION_RECORD64 ExceptionRecord
Definition: windbgkd.h:303
#define PACKET_TYPE_KD_STATE_CHANGE64
Definition: windbgkd.h:48
VOID NTAPI KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, IN PCONTEXT Context)
Definition: kdx64.c:66
DBGKM_EXCEPTION64 Exception
Definition: windbgkd.h:488

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

1585 {
1586  PSTRING ExtraData;
1587  STRING Data, Header;
1588  DBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange;
1589  ULONG PathNameLength;
1591 
1592  /* Start wait loop */
1593  do
1594  {
1595  /* Build the architecture common parts of the message */
1597  Context,
1598  &WaitStateChange);
1599 
1600  /* Now finish creating the structure */
1601  KdpSetContextState(&WaitStateChange, Context);
1602 
1603  /* Fill out load data */
1604  WaitStateChange.u.LoadSymbols.UnloadSymbols = Unload;
1605  WaitStateChange.u.LoadSymbols.BaseOfDll = (ULONG64)(LONG_PTR)SymbolInfo->BaseOfDll;
1606  WaitStateChange.u.LoadSymbols.ProcessId = SymbolInfo->ProcessId;
1607  WaitStateChange.u.LoadSymbols.CheckSum = SymbolInfo->CheckSum;
1608  WaitStateChange.u.LoadSymbols.SizeOfImage = SymbolInfo->SizeOfImage;
1609 
1610  /* Check if we have a path name */
1611  if (PathName)
1612  {
1613  /* Copy it to the path buffer */
1614  KdpCopyMemoryChunks((ULONG_PTR)PathName->Buffer,
1615  KdpPathBuffer,
1616  PathName->Length,
1617  0,
1619  &PathNameLength);
1620 
1621  /* Null terminate */
1622  KdpPathBuffer[PathNameLength++] = ANSI_NULL;
1623 
1624  /* Set the path length */
1625  WaitStateChange.u.LoadSymbols.PathNameLength = PathNameLength;
1626 
1627  /* Set up the data */
1628  Data.Buffer = KdpPathBuffer;
1629  Data.Length = (USHORT)PathNameLength;
1630  ExtraData = &Data;
1631  }
1632  else
1633  {
1634  /* No name */
1635  WaitStateChange.u.LoadSymbols.PathNameLength = 0;
1636  ExtraData = NULL;
1637  }
1638 
1639  /* Setup the header */
1640  Header.Length = sizeof(DBGKD_ANY_WAIT_STATE_CHANGE);
1641  Header.Buffer = (PCHAR)&WaitStateChange;
1642 
1643  /* Send the packet */
1645  &Header,
1646  ExtraData,
1647  Context);
1648  } while (Status == ContinueProcessorReselected);
1649 }
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:50
VOID NTAPI Unload(PDRIVER_OBJECT DriverObject)
Definition: csqtest.c:160
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3514 u
enum _KCONTINUE_STATUS KCONTINUE_STATUS
KCONTINUE_STATUS NTAPI KdpSendWaitContinue(IN ULONG PacketType, IN PSTRING SendHeader, IN PSTRING SendData OPTIONAL, IN OUT PCONTEXT Context)
Definition: kdapi.c:1260
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ANSI_NULL
CHAR KdpPathBuffer[0x1000]
Definition: kddata.c:128
Definition: Header.h:8
DBGKD_LOAD_SYMBOLS64 LoadSymbols
Definition: windbgkd.h:489
#define PCHAR
Definition: match.c:90
Status
Definition: gdiplustypes.h:24
VOID NTAPI KdpSetCommonState(IN ULONG NewState, IN PCONTEXT Context, IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange)
Definition: kdapi.c:381
#define DbgKdLoadSymbolsStateChange
Definition: windbgkd.h:60
struct _DBGKD_ANY_WAIT_STATE_CHANGE DBGKD_ANY_WAIT_STATE_CHANGE
std::wstring STRING
Definition: fontsub.cpp:33
unsigned __int64 ULONG64
Definition: imports.h:198
#define PACKET_TYPE_KD_STATE_CHANGE64
Definition: windbgkd.h:48
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, IN PCONTEXT Context)
Definition: kdx64.c:66
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1

Referenced by KdpSymbol().

◆ KdpRestoreBreakpoint()

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

Definition at line 266 of file kdapi.c.

269 {
270  PDBGKD_RESTORE_BREAKPOINT RestoreBp = &State->u.RestoreBreakPoint;
271  STRING Header;
272 
273  /* Fill out the header */
274  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
275  Header.Buffer = (PCHAR)State;
276  ASSERT(Data->Length == 0);
277 
278  /* Get the version block */
279  if (KdpDeleteBreakpoint(RestoreBp->BreakPointHandle))
280  {
281  /* We're all good */
282  State->ReturnStatus = STATUS_SUCCESS;
283  }
284  else
285  {
286  /* We failed */
287  State->ReturnStatus = STATUS_UNSUCCESSFUL;
288  }
289 
290  /* Send the packet */
292  &Header,
293  NULL,
294  &KdpContext);
295 }
Definition: Header.h:8
BOOLEAN NTAPI KdpDeleteBreakpoint(IN ULONG BpEntry)
Definition: kdbreak.c:311
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpRestoreBreakPointEx()

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

Definition at line 322 of file kdapi.c.

325 {
326  //PDBGKD_BREAKPOINTEX = &State->u.BreakPointEx;
327  STRING Header;
328 
329  /* TODO */
330  KdpDprintf("Extended Breakpoint Restore support is unimplemented!\n");
331 
332  /* Send a failure packet */
333  State->ReturnStatus = STATUS_UNSUCCESSFUL;
334  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
335  Header.Buffer = (PCHAR)State;
337  &Header,
338  Data,
339  &KdpContext);
340 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
#define KdpDprintf(...)
Definition: mmdbg.c:19
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpSearchMemory()

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

Definition at line 187 of file kdapi.c.

190 {
191  //PDBGKD_SEARCH_MEMORY SearchMemory = &State->u.SearchMemory;
192  STRING Header;
193 
194  /* TODO */
195  KdpDprintf("Memory Search support is unimplemented!\n");
196 
197  /* Send a failure packet */
198  State->ReturnStatus = STATUS_UNSUCCESSFUL;
199  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
200  Header.Buffer = (PCHAR)State;
202  &Header,
203  NULL,
204  &KdpContext);
205 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
#define KdpDprintf(...)
Definition: mmdbg.c:19
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

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

1264 {
1265  STRING Data, Header;
1266  DBGKD_MANIPULATE_STATE64 ManipulateState;
1267  ULONG Length;
1268  KDSTATUS RecvCode;
1269 
1270  /* Setup the Manipulate State structure */
1271  Header.MaximumLength = sizeof(DBGKD_MANIPULATE_STATE64);
1272  Header.Buffer = (PCHAR)&ManipulateState;
1273  Data.MaximumLength = sizeof(KdpMessageBuffer);
1274  Data.Buffer = KdpMessageBuffer;
1275 
1276  /*
1277  * Reset the context state to ensure the debugger has received
1278  * the current context before it sets it.
1279  */
1281 
1282 SendPacket:
1283  /* Send the Packet */
1284  KdSendPacket(PacketType, SendHeader, SendData, &KdpContext);
1285 
1286  /* If the debugger isn't present anymore, just return success */
1288 
1289  /* Main processing Loop */
1290  for (;;)
1291  {
1292  /* Receive Loop */
1293  do
1294  {
1295  /* Wait to get a reply to our packet */
1297  &Header,
1298  &Data,
1299  &Length,
1300  &KdpContext);
1301 
1302  /* If we got a resend request, do it */
1303  if (RecvCode == KdPacketNeedsResend) goto SendPacket;
1304  } while (RecvCode == KdPacketTimedOut);
1305 
1306  /* Now check what API we got */
1307  switch (ManipulateState.ApiNumber)
1308  {
1310 
1311  /* Read virtual memory */
1312  KdpReadVirtualMemory(&ManipulateState, &Data, Context);
1313  break;
1314 
1316 
1317  /* Write virtual memory */
1318  KdpWriteVirtualMemory(&ManipulateState, &Data, Context);
1319  break;
1320 
1321  case DbgKdGetContextApi:
1322 
1323  /* Get the current context */
1324  KdpGetContext(&ManipulateState, &Data, Context);
1325  break;
1326 
1327  case DbgKdSetContextApi:
1328 
1329  /* Set a new context */
1330  KdpSetContext(&ManipulateState, &Data, Context);
1331  break;
1332 
1334 
1335  /* Write the breakpoint */
1336  KdpWriteBreakpoint(&ManipulateState, &Data, Context);
1337  break;
1338 
1340 
1341  /* Restore the breakpoint */
1342  KdpRestoreBreakpoint(&ManipulateState, &Data, Context);
1343  break;
1344 
1345  case DbgKdContinueApi:
1346 
1347  /* Simply continue */
1348  return NT_SUCCESS(ManipulateState.u.Continue.ContinueStatus);
1349 
1351 
1352  /* Read control space */
1353  KdpReadControlSpace(&ManipulateState, &Data, Context);
1354  break;
1355 
1357 
1358  /* Write control space */
1359  KdpWriteControlSpace(&ManipulateState, &Data, Context);
1360  break;
1361 
1362  case DbgKdReadIoSpaceApi:
1363 
1364  /* Read I/O Space */
1365  KdpReadIoSpace(&ManipulateState, &Data, Context);
1366  break;
1367 
1368  case DbgKdWriteIoSpaceApi:
1369 
1370  /* Write I/O Space */
1371  KdpWriteIoSpace(&ManipulateState, &Data, Context);
1372  break;
1373 
1374  case DbgKdRebootApi:
1375 
1376  /* Reboot the system */
1378  break;
1379 
1380  case DbgKdContinueApi2:
1381 
1382  /* Check if caller reports success */
1383  if (NT_SUCCESS(ManipulateState.u.Continue2.ContinueStatus))
1384  {
1385  /* Update the state */
1386  KdpGetStateChange(&ManipulateState, Context);
1387  return ContinueSuccess;
1388  }
1389  else
1390  {
1391  /* Return an error */
1392  return ContinueError;
1393  }
1394 
1396 
1397  /* Read physical memory */
1398  KdpReadPhysicalMemory(&ManipulateState, &Data, Context);
1399  break;
1400 
1402 
1403  /* Write physical memory */
1404  KdpWritePhysicalMemory(&ManipulateState, &Data, Context);
1405  break;
1406 
1410 
1411  /* TODO */
1412  KdpDprintf("Special Call support is unimplemented!\n");
1413  KdpNotSupported(&ManipulateState);
1414  break;
1415 
1418 
1419  /* TODO */
1420  KdpDprintf("Internal Breakpoint support is unimplemented!\n");
1421  KdpNotSupported(&ManipulateState);
1422  break;
1423 
1425 
1426  /* Read I/O Space */
1427  KdpReadIoSpaceExtended(&ManipulateState, &Data, Context);
1428  break;
1429 
1431 
1432  /* Write I/O Space */
1433  KdpWriteIoSpaceExtended(&ManipulateState, &Data, Context);
1434  break;
1435 
1436  case DbgKdGetVersionApi:
1437 
1438  /* Get version data */
1439  KdpGetVersion(&ManipulateState);
1440  break;
1441 
1443 
1444  /* Write the breakpoint and check if it failed */
1445  if (!NT_SUCCESS(KdpWriteBreakPointEx(&ManipulateState,
1446  &Data,
1447  Context)))
1448  {
1449  /* Return an error */
1450  return ContinueError;
1451  }
1452  break;
1453 
1455 
1456  /* Restore the breakpoint */
1457  KdpRestoreBreakPointEx(&ManipulateState, &Data, Context);
1458  break;
1459 
1460  case DbgKdCauseBugCheckApi:
1461 
1462  /* Crash the system */
1463  KdpCauseBugCheck(&ManipulateState);
1464  break;
1465 
1466  case DbgKdSwitchProcessor:
1467 
1468  /* TODO */
1469  KdpDprintf("Processor Switch support is unimplemented!\n");
1470  KdpNotSupported(&ManipulateState);
1471  break;
1472 
1473  case DbgKdPageInApi:
1474 
1475  /* TODO */
1476  KdpDprintf("Page-In support is unimplemented!\n");
1477  KdpNotSupported(&ManipulateState);
1478  break;
1479 
1481 
1482  /* Read from the specified MSR */
1483  KdpReadMachineSpecificRegister(&ManipulateState, &Data, Context);
1484  break;
1485 
1487 
1488  /* Write to the specified MSR */
1489  KdpWriteMachineSpecificRegister(&ManipulateState, &Data, Context);
1490  break;
1491 
1492  case DbgKdSearchMemoryApi:
1493 
1494  /* Search memory */
1495  KdpSearchMemory(&ManipulateState, &Data, Context);
1496  break;
1497 
1498  case DbgKdGetBusDataApi:
1499 
1500  /* Read from the bus */
1501  KdpGetBusData(&ManipulateState, &Data, Context);
1502  break;
1503 
1504  case DbgKdSetBusDataApi:
1505 
1506  /* Write to the bus */
1507  KdpSetBusData(&ManipulateState, &Data, Context);
1508  break;
1509 
1511 
1512  /* Check for memory corruption in the lower 4 GB */
1513  KdpCheckLowMemory(&ManipulateState);
1514  break;
1515 
1517 
1518  /* Just clear the counter */
1520  break;
1521 
1522  case DbgKdFillMemoryApi:
1523 
1524  /* Fill memory */
1525  KdpFillMemory(&ManipulateState, &Data, Context);
1526  break;
1527 
1528  case DbgKdQueryMemoryApi:
1529 
1530  /* Query memory */
1531  KdpQueryMemory(&ManipulateState, Context);
1532  break;
1533 
1534  case DbgKdSwitchPartition:
1535 
1536  /* TODO */
1537  KdpDprintf("Partition Switch support is unimplemented!\n");
1538  KdpNotSupported(&ManipulateState);
1539  break;
1540 
1542 
1543  /* Write the customized breakpoint */
1544  KdpWriteCustomBreakpoint(&ManipulateState, &Data, Context);
1545  break;
1546 
1547  case DbgKdGetContextExApi:
1548 
1549  /* Extended Context Get */
1550  KdpGetContextEx(&ManipulateState, &Data, Context);
1551  break;
1552 
1553  case DbgKdSetContextExApi:
1554 
1555  /* Extended Context Set */
1556  KdpSetContextEx(&ManipulateState, &Data, Context);
1557  break;
1558 
1559  /* Unsupported Messages */
1560  default:
1561 
1562  /* Send warning */
1563  KdpDprintf("Received Unrecognized API 0x%lx\n", ManipulateState.ApiNumber);
1564 
1565  /* Setup an empty message, with failure */
1566  Data.Length = 0;
1567  ManipulateState.ReturnStatus = STATUS_UNSUCCESSFUL;
1568 
1569  /* Send it */
1571  &Header,
1572  &Data,
1573  &KdpContext);
1574  break;
1575  }
1576  }
1577 }
#define DbgKdSetBusDataApi
Definition: windbgkd.h:108
VOID NTAPI KdpNotSupported(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:1240
BOOLEAN KdpContextSent
Definition: kddata.c:69
VOID NTAPI KdpRestoreBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:266
#define DbgKdWriteVirtualMemoryApi
Definition: windbgkd.h:75
DBGKD_CONTINUE Continue
Definition: windbgkd.h:779
#define DbgKdWritePhysicalMemoryApi
Definition: windbgkd.h:88
#define DbgKdReadControlSpaceApi
Definition: windbgkd.h:81
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DbgKdGetVersionApi
Definition: windbgkd.h:96
VOID NTAPI KdpGetBusData(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1010
VOID NTAPI KdpWritePhysicalMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:595
#define DbgKdCauseBugCheckApi
Definition: windbgkd.h:99
#define DbgKdRebootApi
Definition: windbgkd.h:85
VOID NTAPI KdpReadIoSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1086
#define DbgKdReadVirtualMemoryApi
Definition: windbgkd.h:74
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG _In_opt_ PVOID Data
Definition: wdfdevice.h:4527
#define DbgKdSetContextExApi
Definition: windbgkd.h:116
#define DbgKdFillMemoryApi
Definition: windbgkd.h:111
#define DbgKdClearSpecialCallsApi
Definition: windbgkd.h:91
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
NTSTATUS NTAPI KdpWriteBreakPointEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:299
#define DbgKdWriteCustomBreakpointApi
Definition: windbgkd.h:114
union _DBGKD_MANIPULATE_STATE64::@3522 u
#define DbgKdWriteControlSpaceApi
Definition: windbgkd.h:82
VOID NTAPI KdpRestoreBreakPointEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:322
VOID NTAPI KdpReadControlSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:645
#define DbgKdContinueApi
Definition: windbgkd.h:80
VOID NTAPI KdpSetContext(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:768
CHAR KdpMessageBuffer[0x1000]
Definition: kddata.c:127
#define DbgKdWriteMachineSpecificRegister
Definition: windbgkd.h:103
#define DbgKdRestoreBreakPointApi
Definition: windbgkd.h:79
#define DbgKdWriteBreakPointExApi
Definition: windbgkd.h:97
BOOLEAN KdDebuggerNotPresent
Definition: kddata.c:82
VOID NTAPI KdpWriteBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:231
#define KdPacketNeedsResend
Definition: kddll.h:7
#define DbgKdSwitchProcessor
Definition: windbgkd.h:100
#define FALSE
Definition: types.h:117
#define DbgKdWriteIoSpaceApi
Definition: windbgkd.h:84
Definition: Header.h:8
#define DbgKdSwitchPartition
Definition: windbgkd.h:113
BOOLEAN SendPacket(PSERIAL_PACKET p)
Definition: serial.c:225
VOID NTAPI KdpGetContextEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:820
VOID NTAPI KdpWriteVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:503
VOID NTAPI KdpWriteCustomBreakpoint(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:344
VOID NTAPI KdpQueryMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
Definition: kdapi.c:128
#define DbgKdClearAllInternalBreakpointsApi
Definition: windbgkd.h:110
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define DbgKdReadPhysicalMemoryApi
Definition: windbgkd.h:87
#define DbgKdWriteIoSpaceExtendedApi
Definition: windbgkd.h:95
VOID NTAPI KdpReadMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:952
#define KdPacketTimedOut
Definition: kddll.h:6
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DbgKdQueryMemoryApi
Definition: windbgkd.h:112
#define DbgKdSearchMemoryApi
Definition: windbgkd.h:106
VOID NTAPI KdpWriteIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1189
#define DbgKdGetContextApi
Definition: windbgkd.h:76
VOID NTAPI HalReturnToFirmware(IN FIRMWARE_REENTRY Action)
Definition: reboot.c:22
VOID NTAPI KdpReadIoSpaceExtended(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1152
VOID NTAPI KdpCauseBugCheck(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:944
VOID NTAPI KdpSetContextEx(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:883
#define DbgKdGetContextExApi
Definition: windbgkd.h:115
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define DbgKdGetBusDataApi
Definition: windbgkd.h:107
#define DbgKdReadMachineSpecificRegister
Definition: windbgkd.h:102
VOID NTAPI KdpWriteMachineSpecificRegister(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:982
#define DbgKdContinueApi2
Definition: windbgkd.h:86
#define DbgKdSetContextApi
Definition: windbgkd.h:77
#define DbgKdCheckLowMemoryApi
Definition: windbgkd.h:109
VOID NTAPI KdpReadVirtualMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:462
VOID NTAPI KdpSearchMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:187
VOID NTAPI KdpWriteIoSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1122
#define DbgKdQuerySpecialCallsApi
Definition: windbgkd.h:89
#define DbgKdRestoreBreakPointExApi
Definition: windbgkd.h:98
#define DbgKdSetSpecialCallApi
Definition: windbgkd.h:90
#define DbgKdWriteBreakPointApi
Definition: windbgkd.h:78
VOID NTAPI KdpGetVersion(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:438
VOID NTAPI KdpFillMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:209
ULONG KDSTATUS
Definition: kddll.h:4
NTSTATUS ContinueStatus
Definition: windbgkd.h:559
#define DbgKdSetInternalBreakPointApi
Definition: windbgkd.h:92
static BOOL SendData(PINFO pInfo)
Definition: ntpclient.c:76
VOID NTAPI KdpWriteControlSpace(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:686
#define DbgKdReadIoSpaceExtendedApi
Definition: windbgkd.h:94
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdpSetBusData(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:1053
VOID NTAPI KdpReadPhysicalMemory(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:532
VOID NTAPI KdpGetContext(IN PDBGKD_MANIPULATE_STATE64 State, IN PSTRING Data, IN PCONTEXT Context)
Definition: kdapi.c:713
VOID NTAPI KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State, IN PCONTEXT Context)
Definition: kdx64.c:22
#define DbgKdReadIoSpaceApi
Definition: windbgkd.h:83
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
#define DbgKdPageInApi
Definition: windbgkd.h:101
#define DbgKdGetInternalBreakPointApi
Definition: windbgkd.h:93
VOID NTAPI KdpCheckLowMemory(IN PDBGKD_MANIPULATE_STATE64 State)
Definition: kdapi.c:1220
#define KdpDprintf(...)
Definition: mmdbg.c:19
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64
NTSTATUS ContinueStatus
Definition: windbgkd.h:565
ULONG KdpNumInternalBreakpoints
Definition: kddata.c:100
DBGKD_CONTINUE2 Continue2
Definition: windbgkd.h:780

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

◆ KdpSetBusData()

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

Definition at line 1053 of file kdapi.c.

1056 {
1057  STRING Header;
1058  PDBGKD_GET_SET_BUS_DATA SetBusData = &State->u.GetSetBusData;
1059  ULONG Length;
1060 
1061  /* Setup the header */
1062  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1063  Header.Buffer = (PCHAR)State;
1064 
1065  /* Call the internal routine */
1066  State->ReturnStatus = KdpSysWriteBusData(SetBusData->BusDataType,
1067  SetBusData->BusNumber,
1068  SetBusData->SlotNumber,
1069  SetBusData->Offset,
1070  Data->Buffer,
1071  SetBusData->Length,
1072  &Length);
1073 
1074  /* Return the actual length written */
1075  SetBusData->Length = Length;
1076 
1077  /* Send the reply */
1079  &Header,
1080  NULL,
1081  &KdpContext);
1082 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpSetCommonState()

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

Definition at line 381 of file kdapi.c.

384 {
385  ULONG InstructionCount;
386  BOOLEAN HadBreakpoints;
387 
388  /* Setup common stuff available for all CPU architectures */
389  WaitStateChange->NewState = NewState;
390  WaitStateChange->ProcessorLevel = KeProcessorLevel;
391  WaitStateChange->Processor = (USHORT)KeGetCurrentPrcb()->Number;
392  WaitStateChange->NumberProcessors = (ULONG)KeNumberProcessors;
393  WaitStateChange->Thread = (ULONG64)(LONG_PTR)KeGetCurrentThread();
394  WaitStateChange->ProgramCounter = (ULONG64)(LONG_PTR)KeGetContextPc(Context);
395 
396  /* Zero out the entire Control Report */
397  KdpZeroMemory(&WaitStateChange->AnyControlReport,
398  sizeof(DBGKD_ANY_CONTROL_REPORT));
399 
400  /* Now copy the instruction stream and set the count */
401  KdpCopyMemoryChunks((ULONG_PTR)WaitStateChange->ProgramCounter,
402  &WaitStateChange->ControlReport.InstructionStream[0],
404  0,
406  &InstructionCount);
407  WaitStateChange->ControlReport.InstructionCount = (USHORT)InstructionCount;
408 
409  /* Clear all the breakpoints in this region */
410  HadBreakpoints =
411  KdpDeleteBreakpointRange((PVOID)(ULONG_PTR)WaitStateChange->ProgramCounter,
412  (PVOID)((ULONG_PTR)WaitStateChange->ProgramCounter +
413  WaitStateChange->ControlReport.InstructionCount - 1));
414  if (HadBreakpoints)
415  {
416  /* Copy the instruction stream again, this time without breakpoints */
417  KdpCopyMemoryChunks((ULONG_PTR)WaitStateChange->ProgramCounter,
418  &WaitStateChange->ControlReport.InstructionStream[0],
419  InstructionCount,
420  0,
422  NULL);
423  }
424 }
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:50
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char BOOLEAN
#define KeGetContextPc(Context)
Definition: ke.h:124
unsigned __int64 ULONG64
Definition: imports.h:198
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
unsigned short USHORT
Definition: pedump.c:61
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define NULL
Definition: types.h:112
USHORT KeProcessorLevel
Definition: krnlinit.c:20
unsigned int ULONG
Definition: retypes.h:1
#define DBGKD_MAXSTREAM
Definition: windbgkd.h:19
VOID NTAPI KdpZeroMemory(_In_ PVOID Destination, _In_ SIZE_T Length)
Definition: kdapi.c:37
#define KeGetCurrentThread
Definition: hal.h:44
BOOLEAN NTAPI KdpDeleteBreakpointRange(IN PVOID Base, IN PVOID Limit)
Definition: kdbreak.c:340

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

◆ KdpSetContext()

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

Definition at line 768 of file kdapi.c.

771 {
772  STRING Header;
774 
775  /* Setup the header */
776  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
777  Header.Buffer = (PCHAR)State;
778  ASSERT(Data->Length == sizeof(CONTEXT));
779 
780  /* Make sure that this is a valid request */
781  if ((State->Processor < KeNumberProcessors) &&
782  (KdpContextSent))
783  {
784  /* Check if the request is for this CPU */
785  if (State->Processor == KeGetCurrentPrcb()->Number)
786  {
787  /* We're just copying our own context */
789  }
790  else
791  {
792  /* Get the context from the PRCB array */
793  TargetContext = &KiProcessorBlock[State->Processor]->
794  ProcessorState.ContextFrame;
795  }
796 
797  /* Copy the new context to it */
799  Data->Buffer,
800  sizeof(CONTEXT));
801 
802  /* Finish up */
803  State->ReturnStatus = STATUS_SUCCESS;
804  }
805  else
806  {
807  /* Invalid request */
808  State->ReturnStatus = STATUS_UNSUCCESSFUL;
809  }
810 
811  /* Send the reply */
813  &Header,
814  NULL,
815  &KdpContext);
816 }
BOOLEAN KdpContextSent
Definition: kddata.c:69
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG _In_opt_ PVOID TargetContext
Definition: fsrtlfuncs.h:738
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpSetContextEx()

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

Definition at line 883 of file kdapi.c.

886 {
887  STRING Header;
888  PDBGKD_CONTEXT_EX ContextEx;
890 
891  /* Get our struct */
892  ContextEx = &State->u.ContextEx;
893  ASSERT(Data->Length == ContextEx->ByteCount);
894 
895  /* Set up the header */
896  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
897  Header.Buffer = (PCHAR)State;
898 
899  /* Make sure that this is a valid request */
900  if ((State->Processor < KeNumberProcessors) &&
901  ((ContextEx->Offset + ContextEx->ByteCount) <= sizeof(CONTEXT)) &&
902  (KdpContextSent))
903  {
904  /* Check if the request is for this CPU */
905  if (State->Processor == KeGetCurrentPrcb()->Number)
906  {
907  /* We're just copying our own context */
909  }
910  else
911  {
912  /* Get the context from the PRCB array */
913  TargetContext = &KiProcessorBlock[State->Processor]->
914  ProcessorState.ContextFrame;
915  }
916 
917  /* Copy what is requested */
919  Data->Buffer,
920  ContextEx->ByteCount);
921 
922  /* KD copies all */
923  ContextEx->BytesCopied = ContextEx->ByteCount;
924 
925  /* Finish up */
926  State->ReturnStatus = STATUS_SUCCESS;
927  }
928  else
929  {
930  /* Invalid request */
931  ContextEx->BytesCopied = 0;
932  State->ReturnStatus = STATUS_UNSUCCESSFUL;
933  }
934 
935  /* Send the reply */
937  &Header,
938  NULL,
939  &KdpContext);
940 }
BOOLEAN KdpContextSent
Definition: kddata.c:69
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
uint32_t ULONG_PTR
Definition: typedefs.h:65
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG _In_opt_ PVOID TargetContext
Definition: fsrtlfuncs.h:738
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
#define NULL
Definition: types.h:112
struct tagContext Context
Definition: acpixf.h:1034
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpSwitchProcessor()

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

Definition at line 1833 of file kdapi.c.

1836 {
1837  BOOLEAN Status;
1838 
1839  /* Save the port data */
1840  KdSave(FALSE);
1841 
1842  /* Report a state change */
1843  Status = KdpReportExceptionStateChange(ExceptionRecord,
1844  ContextRecord,
1845  SecondChanceException);
1846 
1847  /* Restore the port data and return */
1848  KdRestore(FALSE);
1849  return Status;
1850 }
NTSTATUS NTAPI KdRestore(IN BOOLEAN SleepTransition)
Definition: kdcom.c:121
BOOLEAN NTAPI KdpReportExceptionStateChange(IN PEXCEPTION_RECORD ExceptionRecord, IN OUT PCONTEXT Context, IN BOOLEAN SecondChanceException)
Definition: kdapi.c:1730
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
Status
Definition: gdiplustypes.h:24
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:655
NTSTATUS NTAPI KdSave(IN BOOLEAN SleepTransition)
Definition: kdcom.c:113

Referenced by KdInitSystem().

◆ KdpSysGetVersion()

VOID NTAPI KdpSysGetVersion ( IN PDBGKD_GET_VERSION64  Version)

Definition at line 428 of file kdapi.c.

429 {
430  /* Copy the version block */
433  sizeof(DBGKD_GET_VERSION64));
434 }
DBGKD_GET_VERSION64 KdVersionBlock
Definition: kddata.c:495
VOID NTAPI KdpMoveMemory(_In_ PVOID Destination, _In_ PVOID Source, _In_ SIZE_T Length)
Definition: kdapi.c:22
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361

Referenced by KdpGetVersion().

◆ KdpTimeSlipDpcRoutine()

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

Definition at line 1785 of file kdapi.c.

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

Referenced by KdInitSystem().

◆ KdpTimeSlipWork()

VOID NTAPI KdpTimeSlipWork ( IN PVOID  Context)

Definition at line 1811 of file kdapi.c.

1812 {
1813  KIRQL OldIrql;
1815 
1816  /* Update the System time from the CMOS */
1820 
1821  /* Check if we have a registered Time Slip Event and signal it */
1825 
1826  /* Delay the DPC until it runs next time */
1827  DueTime.QuadPart = -1800000000;
1829 }
VOID NTAPI ExReleaseTimeRefreshLock(VOID)
Definition: time.c:83
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
BOOLEAN NTAPI ExAcquireTimeRefreshLock(IN BOOLEAN Wait)
Definition: time.c:51
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID NTAPI ExUpdateSystemTimeFromCmos(IN BOOLEAN UpdateInterruptTime, IN ULONG MaxSepInSeconds)
Definition: time.c:217
KDPC KdpTimeSlipDpc
Definition: kddata.c:116
PKEVENT KdpTimeSlipEvent
Definition: kddata.c:120
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
KSPIN_LOCK KdpTimeSlipEventLock
Definition: kddata.c:121
KTIMER KdpTimeSlipTimer
Definition: kddata.c:117

Referenced by KdInitSystem().

◆ KdpWriteBreakpoint()

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

Definition at line 231 of file kdapi.c.

234 {
235  PDBGKD_WRITE_BREAKPOINT64 Breakpoint = &State->u.WriteBreakPoint;
236  STRING Header;
237 
238  /* Build header */
239  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
240  Header.Buffer = (PCHAR)State;
241  ASSERT(Data->Length == 0);
242 
243  /* Create the breakpoint */
244  Breakpoint->BreakPointHandle =
246  if (!Breakpoint->BreakPointHandle)
247  {
248  /* We failed */
249  State->ReturnStatus = STATUS_UNSUCCESSFUL;
250  }
251  else
252  {
253  /* Success! */
254  State->ReturnStatus = STATUS_SUCCESS;
255  }
256 
257  /* Send the packet */
259  &Header,
260  NULL,
261  &KdpContext);
262 }
uint32_t ULONG_PTR
Definition: typedefs.h:65
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
ULONG NTAPI KdpAddBreakpoint(IN PVOID Address)
Definition: kdbreak.c:20
#define NULL
Definition: types.h:112
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWriteBreakPointEx()

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

Definition at line 299 of file kdapi.c.

302 {
303  //PDBGKD_BREAKPOINTEX = &State->u.BreakPointEx;
304  STRING Header;
305 
306  /* TODO */
307  KdpDprintf("Extended Breakpoint Write support is unimplemented!\n");
308 
309  /* Send a failure packet */
310  State->ReturnStatus = STATUS_UNSUCCESSFUL;
311  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
312  Header.Buffer = (PCHAR)State;
314  &Header,
315  Data,
316  &KdpContext);
317  return STATUS_UNSUCCESSFUL;
318 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
#define KdpDprintf(...)
Definition: mmdbg.c:19
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWriteControlSpace()

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

Definition at line 686 of file kdapi.c.

689 {
690  PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;
691  STRING Header;
692 
693  /* Setup the header */
694  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
695  Header.Buffer = (PCHAR)State;
696 
697  /* Call the internal routine */
698  State->ReturnStatus = KdpSysWriteControlSpace(State->Processor,
699  WriteMemory->TargetBaseAddress,
700  Data->Buffer,
701  Data->Length,
702  &WriteMemory->ActualBytesWritten);
703 
704  /* Send the reply */
706  &Header,
707  Data,
708  &KdpContext);
709 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
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:1914
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWriteCustomBreakpoint()

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

Definition at line 344 of file kdapi.c.

347 {
348  //PDBGKD_WRITE_CUSTOM_BREAKPOINT = &State->u.WriteCustomBreakpoint;
349  STRING Header;
350 
351  /* Not supported */
352  KdpDprintf("Custom Breakpoint Write is unimplemented\n");
353 
354  /* Send a failure packet */
355  State->ReturnStatus = STATUS_UNSUCCESSFUL;
356  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
357  Header.Buffer = (PCHAR)State;
359  &Header,
360  NULL,
361  &KdpContext);
362 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
#define KdpDprintf(...)
Definition: mmdbg.c:19
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWriteIoSpace()

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

Definition at line 1122 of file kdapi.c.

1125 {
1126  STRING Header;
1127  PDBGKD_READ_WRITE_IO64 WriteIo = &State->u.ReadWriteIo;
1128 
1129  /* Setup the header */
1130  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1131  Header.Buffer = (PCHAR)State;
1132  ASSERT(Data->Length == 0);
1133 
1134  /* Call the internal routine */
1135  State->ReturnStatus = KdpSysWriteIoSpace(Isa,
1136  0,
1137  1,
1138  WriteIo->IoAddress,
1139  &WriteIo->DataValue,
1140  WriteIo->DataSize,
1141  &WriteIo->DataSize);
1142 
1143  /* Send the reply */
1145  &Header,
1146  NULL,
1147  &KdpContext);
1148 }
Definition: Header.h:8
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
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWriteIoSpaceExtended()

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

Definition at line 1189 of file kdapi.c.

1192 {
1193  STRING Header;
1194  PDBGKD_READ_WRITE_IO_EXTENDED64 WriteIoExtended = &State->u.
1195  ReadWriteIoExtended;
1196 
1197  /* Setup the header */
1198  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
1199  Header.Buffer = (PCHAR)State;
1200  ASSERT(Data->Length == 0);
1201 
1202  /* Call the internal routine */
1203  State->ReturnStatus = KdpSysWriteIoSpace(WriteIoExtended->InterfaceType,
1204  WriteIoExtended->BusNumber,
1205  WriteIoExtended->AddressSpace,
1206  WriteIoExtended->IoAddress,
1207  &WriteIoExtended->DataValue,
1208  WriteIoExtended->DataSize,
1209  &WriteIoExtended->DataSize);
1210 
1211  /* Send the reply */
1213  &Header,
1214  NULL,
1215  &KdpContext);
1216 }
Definition: Header.h:8
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
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:45
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWriteMachineSpecificRegister()

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

Definition at line 982 of file kdapi.c.

985 {
986  STRING Header;
987  PDBGKD_READ_WRITE_MSR WriteMsr = &State->u.ReadWriteMsr;
988  LARGE_INTEGER MsrValue;
989 
990  /* Setup the header */
991  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
992  Header.Buffer = (PCHAR)State;
993  ASSERT(Data->Length == 0);
994 
995  /* Call the internal routine */
996  MsrValue.LowPart = WriteMsr->DataValueLow;
997  MsrValue.HighPart = WriteMsr->DataValueHigh;
998  State->ReturnStatus = KdpSysWriteMsr(WriteMsr->Msr,
999  &MsrValue);
1000 
1001  /* Send the reply */
1003  &Header,
1004  NULL,
1005  &KdpContext);
1006 }
Definition: Header.h:8
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
NTSTATUS NTAPI KdpSysWriteMsr(IN ULONG Msr, IN PLARGE_INTEGER MsrValue)
Definition: kdx64.c:115
#define ASSERT(a)
Definition: mode.c:45
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
ULONG LowPart
Definition: typedefs.h:106
#define NULL
Definition: types.h:112
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWritePhysicalMemory()

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

Definition at line 595 of file kdapi.c.

598 {
599  PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;
600  STRING Header;
601  ULONG Flags, CacheFlags;
602 
603  /* Setup the header */
604  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
605  Header.Buffer = (PCHAR)State;
606 
607  /* Start with the default flags */
609 
610  /* Get the caching flags and check if a type is specified */
611  CacheFlags = WriteMemory->ActualBytesWritten;
612  if (CacheFlags == DBGKD_CACHING_CACHED)
613  {
614  /* Cached */
616  }
617  else if (CacheFlags == DBGKD_CACHING_UNCACHED)
618  {
619  /* Uncached */
621  }
622  else if (CacheFlags == DBGKD_CACHING_WRITE_COMBINED)
623  {
624  /* Write Combined */
626  }
627 
628  /* Do the write */
629  State->ReturnStatus = KdpCopyMemoryChunks(WriteMemory->TargetBaseAddress,
630  Data->Buffer,
631  Data->Length,
632  0,
633  Flags,
634  &WriteMemory->ActualBytesWritten);
635 
636  /* Send the packet */
638  &Header,
639  NULL,
640  &KdpContext);
641 }
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:50
#define DBGKD_CACHING_UNCACHED
Definition: windbgkd.h:191
Definition: Header.h:8
#define MMDBG_COPY_WRITE
Definition: mm.h:53
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
#define DBGKD_CACHING_CACHED
Definition: windbgkd.h:190
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define MMDBG_COPY_UNCACHED
Definition: mm.h:57
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define MMDBG_COPY_WRITE_COMBINED
Definition: mm.h:58
#define DBGKD_CACHING_WRITE_COMBINED
Definition: windbgkd.h:192
#define MMDBG_COPY_PHYSICAL
Definition: mm.h:54
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY WriteMemory
Definition: wdfusb.h:1914
#define MMDBG_COPY_CACHED
Definition: mm.h:56
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpWriteVirtualMemory()

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

Definition at line 503 of file kdapi.c.

506 {
507  PDBGKD_WRITE_MEMORY64 WriteMemory = &State->u.WriteMemory;
508  STRING Header;
509 
510  /* Setup the header */
511  Header.Length = sizeof(DBGKD_MANIPULATE_STATE64);
512  Header.Buffer = (PCHAR)State;
513 
514  /* Do the write */
515  State->ReturnStatus = KdpCopyMemoryChunks(WriteMemory->TargetBaseAddress,
516  Data->Buffer,
517  Data->Length,
518  0,
521  &WriteMemory->ActualBytesWritten);
522 
523  /* Send the packet */
525  &Header,
526  NULL,
527  &KdpContext);
528 }
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:50
Definition: Header.h:8
#define MMDBG_COPY_WRITE
Definition: mm.h:53
KD_CONTEXT KdpContext
Definition: kddata.c:65
#define PCHAR
Definition: match.c:90
std::wstring STRING
Definition: fontsub.cpp:33
#define PACKET_TYPE_KD_STATE_MANIPULATE
Definition: windbgkd.h:43
#define MMDBG_COPY_UNSAFE
Definition: mm.h:55
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ WDFUSBPIPE _In_ WDFREQUEST _In_opt_ WDFMEMORY WriteMemory
Definition: wdfusb.h:1914
VOID NTAPI KdSendPacket(IN ULONG PacketType, IN PSTRING MessageHeader, IN PSTRING MessageData, IN OUT PKD_CONTEXT KdContext)
Definition: kddll.c:314
struct _DBGKD_MANIPULATE_STATE64 DBGKD_MANIPULATE_STATE64

Referenced by KdpSendWaitContinue().

◆ KdpZeroMemory()

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

Definition at line 37 of file kdapi.c.

40 {
41  PCHAR DestinationBytes;
42 
43  /* Zero the buffer 1 byte at a time */
44  DestinationBytes = Destination;
45  while (Length--) *DestinationBytes++ = 0;
46 }
signed char * PCHAR
Definition: retypes.h:7
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2937

Referenced by KdpReportCommandStringStateChange(), and KdpSetCommonState().

◆ KdRefreshDebuggerNotPresent()

BOOLEAN NTAPI KdRefreshDebuggerNotPresent ( VOID  )

Definition at line 2319 of file kdapi.c.

2320 {
2321  BOOLEAN Enable, DebuggerNotPresent;
2322 
2323  /* Check if the debugger is completely disabled */
2324  if (KdPitchDebugger)
2325  {
2326  /* Don't try to refresh then, fail early */
2327  return TRUE;
2328  }
2329 
2330  /* Enter the debugger */
2332 
2333  /*
2334  * Attempt to send a string to the debugger
2335  * to refresh the connection state.
2336  */
2337  KdpDprintf("KDTARGET: Refreshing KD connection\n");
2338 
2339  /* Save the state while we are holding the lock */
2340  DebuggerNotPresent = KdDebuggerNotPresent;
2341 
2342  /* Exit the debugger and return the state */
2344  return DebuggerNotPresent;
2345 }
VOID NTAPI KdExitDebugger(IN BOOLEAN Enable)
Definition: kdapi.c:1924
BOOLEAN NTAPI KdEnterDebugger(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: kdapi.c:1871
#define TRUE
Definition: types.h:120
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:140
BOOLEAN KdPitchDebugger
Definition: kddata.c:81
BOOLEAN KdDebuggerNotPresent
Definition: kddata.c:82
unsigned char BOOLEAN
#define NULL
Definition: types.h:112
#define KdpDprintf(...)
Definition: mmdbg.c:19

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

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

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

◆ NtQueryDebugFilterState()

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

Definition at line 2352 of file kdapi.c.

2355 {
2356  PULONG Mask;
2357 
2358  /* Check if the ID fits in the component table */
2360  {
2361  /* It does, so get the mask from there */
2363  }
2364  else if (ComponentId == MAXULONG)
2365  {
2366  /*
2367  * This is the internal ID used for DbgPrint messages without ID
2368  * and Level. Use the system-wide mask for those.
2369  */
2370  Mask = &Kd_WIN2000_Mask;
2371  }
2372  else
2373  {
2374 #if (NTDDI_VERSION >= NTDDI_VISTA)
2375  /* Use the default component ID */
2376  Mask = &Kd_DEFAULT_Mask;
2377  // Level = DPFLTR_INFO_LEVEL; // Override the Level.
2378 #else
2379  /* Invalid ID, fail */
2381 #endif
2382  }
2383 
2384  /* Convert Level to bit field if required */
2385  if (Level < 32) Level = 1 << Level;
2386  Level &= ~DPFLTR_MASK;
2387 
2388  /* Determine if this Level is filtered out */
2389  if ((Kd_WIN2000_Mask & Level) || (*Mask & Level))
2390  {
2391  /* This mask will get through to the debugger */
2392  return (NTSTATUS)TRUE;
2393  }
2394  else
2395  {
2396  /* This mask is filtered out */
2397  return (NTSTATUS)FALSE;
2398  }
2399 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
ULONG KdComponentTableSize
Definition: kddata.c:484
#define DPFLTR_MASK
Definition: kdtypes.h:34
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
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:1274
#define FALSE
Definition: types.h:117
ULONG Kd_WIN2000_Mask
Definition: kddata.c:143
PULONG KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES]
Definition: kddata.c:314
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
processorSet Mask
#define MAXULONG
Definition: typedefs.h:251
ULONG Kd_DEFAULT_Mask
Definition: kddata.c:245
unsigned int * PULONG
Definition: retypes.h:1

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

◆ NtSetDebugFilterState()

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

Definition at line 2406 of file kdapi.c.

2410 {
2411  PULONG Mask;
2412 
2413  /* Modifying debug filters requires the debug privilege */
2415  {
2416  /* Fail */
2417  return STATUS_ACCESS_DENIED;
2418  }
2419 
2420  /* Check if the ID fits in the component table */
2422  {
2423  /* It does, so get the mask from there */
2425  }
2426  else if (ComponentId == MAXULONG)
2427  {
2428  /*
2429  * This is the internal ID used for DbgPrint messages without ID
2430  * and Level. Use the system-wide mask for those.
2431  */
2432  Mask = &Kd_WIN2000_Mask;
2433  }
2434  else
2435  {
2436 #if (NTDDI_VERSION >= NTDDI_VISTA)
2437  /* Use the default component ID */
2438  Mask = &Kd_DEFAULT_Mask;
2439 #else
2440  /* Invalid ID, fail */
2442 #endif
2443  }
2444 
2445  /* Convert Level to bit field if required */
2446  if (Level < 32) Level = 1 << Level;
2447  Level &= ~DPFLTR_MASK;
2448 
2449  /* Set or remove the Level */
2450  if (State)
2451  *Mask |= Level;
2452  else
2453  *Mask &= ~Level;
2454 
2455  return STATUS_SUCCESS;
2456 }
const LUID SeDebugPrivilege
Definition: priv.c:37
ULONG KdComponentTableSize
Definition: kddata.c:484
#define DPFLTR_MASK
Definition: kdtypes.h:34
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:520
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3070
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
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:1274
ULONG Kd_WIN2000_Mask
Definition: kddata.c:143
PULONG KdComponentTable[MAX_KD_COMPONENT_TABLE_ENTRIES]
Definition: kddata.c:314
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:475
processorSet Mask
#define MAXULONG
Definition: typedefs.h:251
ULONG Kd_DEFAULT_Mask
Definition: kddata.c:245
unsigned int * PULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by DbgSetDebugFilterState(), and KdbpCmdFilter().

◆ PspDumpThreads()

VOID NTAPI PspDumpThreads ( BOOLEAN  SystemThreads)

Referenced by KdSystemDebugControl().