#ifndef _WINDBGKD_
#define _WINDBGKG_
//
// Dependencies
//
#include "wdbgexts.h"
//
// Conversion Macros
//
#define COPYSE(p64, p32, f) \
p64->f = (ULONG64)(LONG64)(LONG)p32->f
//
// Packet Size and Control Stream Size
//
#define PACKET_MAX_SIZE 4000
#define DBGKD_MAXSTREAM 16
//
// Magic Packet IDs
//
#define INITIAL_PACKET_ID 0x80800000
#define SYNC_PACKET_ID 0x00000800
//
// Magic Packet bytes
//
#define BREAKIN_PACKET 0x62626262
#define BREAKIN_PACKET_BYTE 0x62
#define PACKET_LEADER 0x30303030
#define PACKET_LEADER_BYTE 0x30
#define CONTROL_PACKET_LEADER 0x69696969
#define CONTROL_PACKET_LEADER_BYTE 0x69
#define PACKET_TRAILING_BYTE 0xAA
//
// Packet Types
//
#define PACKET_TYPE_UNUSED 0
#define PACKET_TYPE_KD_STATE_CHANGE32 1
#define PACKET_TYPE_KD_STATE_MANIPULATE 2
#define PACKET_TYPE_KD_DEBUG_IO 3
#define PACKET_TYPE_KD_ACKNOWLEDGE 4
#define PACKET_TYPE_KD_RESEND 5
#define PACKET_TYPE_KD_RESET 6
#define PACKET_TYPE_KD_STATE_CHANGE64 7
#define PACKET_TYPE_KD_POLL_BREAKIN 8
#define PACKET_TYPE_KD_TRACE_IO 9
#define PACKET_TYPE_KD_CONTROL_REQUEST 10
#define PACKET_TYPE_KD_FILE_IO 11
#define PACKET_TYPE_MAX 12
//
// Wait State Change Types
//
#define DbgKdMinimumStateChange 0x00003030
#define DbgKdExceptionStateChange 0x00003030
#define DbgKdLoadSymbolsStateChange 0x00003031
#define DbgKdCommandStringStateChange 0x00003032
#define DbgKdMaximumStateChange 0x00003033
//
// Manipulate Types
//
#define DbgKdMinimumManipulate 0x00003130
#define DbgKdReadVirtualMemoryApi 0x00003130
#define DbgKdWriteVirtualMemoryApi 0x00003131
#define DbgKdGetContextApi 0x00003132
#define DbgKdSetContextApi 0x00003133
#define DbgKdWriteBreakPointApi 0x00003134
#define DbgKdRestoreBreakPointApi 0x00003135
#define DbgKdContinueApi 0x00003136
#define DbgKdReadControlSpaceApi 0x00003137
#define DbgKdWriteControlSpaceApi 0x00003138
#define DbgKdReadIoSpaceApi 0x00003139
#define DbgKdWriteIoSpaceApi 0x0000313A
#define DbgKdRebootApi 0x0000313B
#define DbgKdContinueApi2 0x0000313C
#define DbgKdReadPhysicalMemoryApi 0x0000313D
#define DbgKdWritePhysicalMemoryApi 0x0000313E
#define DbgKdQuerySpecialCallsApi 0x0000313F
#define DbgKdSetSpecialCallApi 0x00003140
#define DbgKdClearSpecialCallsApi 0x00003141
#define DbgKdSetInternalBreakPointApi 0x00003142
#define DbgKdGetInternalBreakPointApi 0x00003143
#define DbgKdReadIoSpaceExtendedApi 0x00003144
#define DbgKdWriteIoSpaceExtendedApi 0x00003145
#define DbgKdGetVersionApi 0x00003146
#define DbgKdWriteBreakPointExApi 0x00003147
#define DbgKdRestoreBreakPointExApi 0x00003148
#define DbgKdCauseBugCheckApi 0x00003149
#define DbgKdSwitchProcessor 0x00003150
#define DbgKdPageInApi 0x00003151
#define DbgKdReadMachineSpecificRegister 0x00003152
#define DbgKdWriteMachineSpecificRegister 0x00003153
#define OldVlm1 0x00003154
#define OldVlm2 0x00003155
#define DbgKdSearchMemoryApi 0x00003156
#define DbgKdGetBusDataApi 0x00003157
#define DbgKdSetBusDataApi 0x00003158
#define DbgKdCheckLowMemoryApi 0x00003159
#define DbgKdClearAllInternalBreakpointsApi 0x0000315A
#define DbgKdFillMemoryApi 0x0000315B
#define DbgKdQueryMemoryApi 0x0000315C
#define DbgKdSwitchPartition 0x0000315D
#define DbgKdMaximumManipulate 0x0000315E
//
// Debug I/O Types
//
#define DbgKdPrintStringApi 0x00003230
#define DbgKdGetStringApi 0x00003231
//
// Control Report Flags
//
#define REPORT_INCLUDES_SEGS 0x0001
#define REPORT_INCLUDES_CS 0x0002
//
// Protocol Versions
//
#define DBGKD_64BIT_PROTOCOL_VERSION1 5
#define DBGKD_64BIT_PROTOCOL_VERSION2 6
//
// Query Memory Address Spaces
//
#define DBGKD_QUERY_MEMORY_VIRTUAL 0
#define DBGKD_QUERY_MEMORY_PROCESS 0
#define DBGKD_QUERY_MEMORY_SESSION 1
#define DBGKD_QUERY_MEMORY_KERNEL 2
//
// Query Memory Flags
//
#define DBGKD_QUERY_MEMORY_READ 0x01
#define DBGKD_QUERY_MEMORY_WRITE 0x02
#define DBGKD_QUERY_MEMORY_EXECUTE 0x04
#define DBGKD_QUERY_MEMORY_FIXED 0x08
//
// KD Packet Structure
//
typedef struct _KD_PACKET
{
ULONG PacketLeader;
USHORT PacketType;
USHORT ByteCount;
ULONG PacketId;
ULONG Checksum;
} KD_PACKET, *PKD_PACKET;
//
// KD Context
//
typedef struct _KD_CONTEXT
{
ULONG KdpDefaultRetries;
BOOLEAN KdpControlCPending;
} KD_CONTEXT, *PKD_CONTEXT;
//
// Control Sets for Supported Architectures
//
#include <pshpack4.h>
typedef struct _X86_DBGKD_CONTROL_SET
{
ULONG TraceFlag;
ULONG Dr7;
ULONG CurrentSymbolStart;
ULONG CurrentSymbolEnd;
} X86_DBGKD_CONTROL_SET, *PX86_DBGKD_CONTROL_SET;
typedef struct _IA64_DBGKD_CONTROL_SET
{
ULONG Continue;
ULONG64 CurrentSymbolStart;
ULONG64 CurrentSymbolEnd;
} IA64_DBGKD_CONTROL_SET, *PIA64_DBGKD_CONTROL_SET;
typedef struct _AMD64_DBGKD_CONTROL_SET
{
ULONG TraceFlag;
ULONG64 Dr7;
ULONG64 CurrentSymbolStart;
ULONG64 CurrentSymbolEnd;
} AMD64_DBGKD_CONTROL_SET, *PAMD64_DBGKD_CONTROL_SET;
typedef struct _DBGKD_ANY_CONTROL_SET
{
union
{
X86_DBGKD_CONTROL_SET X86ControlSet;
IA64_DBGKD_CONTROL_SET IA64ControlSet;
AMD64_DBGKD_CONTROL_SET Amd64ControlSet;
};
} DBGKD_ANY_CONTROL_SET, *PDBGKD_ANY_CONTROL_SET;
#include <poppack.h>
typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET;
//
// DBGKM Structure for Exceptions
//
typedef struct _DBGKM_EXCEPTION64
{
EXCEPTION_RECORD64 ExceptionRecord;
ULONG FirstChance;
} DBGKM_EXCEPTION64, *PDBGKM_EXCEPTION64;
//
// DBGKD Structure for State Change
//
typedef struct _DBGKD_CONTROL_REPORT
{
ULONG Dr6;
ULONG Dr7;
USHORT InstructionCount;
USHORT ReportFlags;
UCHAR InstructionStream[DBGKD_MAXSTREAM];
USHORT SegCs;
USHORT SegDs;
USHORT SegEs;
USHORT SegFs;
ULONG EFlags;
} DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
//
// DBGKD Structure for Debug I/O Type Print String
//
typedef struct _DBGKD_PRINT_STRING
{
ULONG LengthOfString;
} DBGKD_PRINT_STRING, *PDBGKD_PRINT_STRING;
//
// DBGKD Structure for Debug I/O Type Get String
//
typedef struct _DBGKD_GET_STRING
{
ULONG LengthOfPromptString;
ULONG LengthOfStringRead;
} DBGKD_GET_STRING, *PDBGKD_GET_STRING;
//
// DBGKD Structure for Debug I/O
//
typedef struct _DBGKD_DEBUG_IO
{
ULONG ApiNumber;
USHORT ProcessorLevel;
USHORT Processor;
union
{
DBGKD_PRINT_STRING PrintString;
DBGKD_GET_STRING GetString;
} u;
} DBGKD_DEBUG_IO, *PDBGKD_DEBUG_IO;
//
// DBGKD Structure for Load Symbols
//
typedef struct _DBGKD_LOAD_SYMBOLS64
{
ULONG PathNameLength;
ULONG64 BaseOfDll;
ULONG64 ProcessId;
ULONG CheckSum;
ULONG SizeOfImage;
BOOLEAN UnloadSymbols;
} DBGKD_LOAD_SYMBOLS64, *PDBGKD_LOAD_SYMBOLS64;
//
// DBGKD Structure for Wait State Change
//
typedef struct _DBGKD_WAIT_STATE_CHANGE64
{
ULONG NewState;
USHORT ProcessorLevel;
USHORT Processor;
ULONG NumberProcessors;
ULONG64 Thread;
ULONG64 ProgramCounter;
union
{
DBGKM_EXCEPTION64 Exception;
DBGKD_LOAD_SYMBOLS64 LoadSymbols;
} u;
DBGKD_CONTROL_REPORT ControlReport;
CONTEXT Context;
} DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
//
// DBGKD Manipulate Structures
//
typedef struct _DBGKD_READ_MEMORY64
{
ULONG64 TargetBaseAddress;
ULONG TransferCount;
ULONG ActualBytesRead;
} DBGKD_READ_MEMORY64, *PDBGKD_READ_MEMORY64;
typedef struct _DBGKD_WRITE_MEMORY64
{
ULONG64 TargetBaseAddress;
ULONG TransferCount;
ULONG ActualBytesWritten;
} DBGKD_WRITE_MEMORY64, *PDBGKD_WRITE_MEMORY64;
typedef struct _DBGKD_GET_CONTEXT
{
ULONG Unused;
} DBGKD_GET_CONTEXT, *PDBGKD_GET_CONTEXT;
typedef struct _DBGKD_SET_CONTEXT
{
ULONG ContextFlags;
} DBGKD_SET_CONTEXT, *PDBGKD_SET_CONTEXT;
typedef struct _DBGKD_WRITE_BREAKPOINT64
{
ULONG64 BreakPointAddress;
ULONG BreakPointHandle;
} DBGKD_WRITE_BREAKPOINT64, *PDBGKD_WRITE_BREAKPOINT64;
typedef struct _DBGKD_RESTORE_BREAKPOINT
{
ULONG BreakPointHandle;
} DBGKD_RESTORE_BREAKPOINT, *PDBGKD_RESTORE_BREAKPOINT;
typedef struct _DBGKD_CONTINUE
{
NTSTATUS ContinueStatus;
} DBGKD_CONTINUE, *PDBGKD_CONTINUE;
#include <pshpack4.h>
typedef struct _DBGKD_CONTINUE2
{
NTSTATUS ContinueStatus;
union
{
DBGKD_CONTROL_SET ControlSet;
DBGKD_ANY_CONTROL_SET AnyControlSet;
};
} DBGKD_CONTINUE2, *PDBGKD_CONTINUE2;
#include <poppack.h>
typedef struct _DBGKD_READ_WRITE_IO64
{
ULONG64 IoAddress;
ULONG DataSize;
ULONG DataValue;
} DBGKD_READ_WRITE_IO64, *PDBGKD_READ_WRITE_IO64;
typedef struct _DBGKD_READ_WRITE_IO_EXTENDED64
{
ULONG DataSize;
ULONG InterfaceType;
ULONG BusNumber;
ULONG AddressSpace;
ULONG64 IoAddress;
ULONG DataValue;
} DBGKD_READ_WRITE_IO_EXTENDED64, *PDBGKD_READ_WRITE_IO_EXTENDED64;
typedef struct _DBGKD_READ_WRITE_MSR
{
ULONG Msr;
ULONG DataValueLow;
ULONG DataValueHigh;
} DBGKD_READ_WRITE_MSR, *PDBGKD_READ_WRITE_MSR;
typedef struct _DBGKD_QUERY_SPECIAL_CALLS
{
ULONG NumberOfSpecialCalls;
} DBGKD_QUERY_SPECIAL_CALLS, *PDBGKD_QUERY_SPECIAL_CALLS;
typedef struct _DBGKD_SET_SPECIAL_CALL64
{
ULONG64 SpecialCall;
} DBGKD_SET_SPECIAL_CALL64, *PDBGKD_SET_SPECIAL_CALL64;
typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT64
{
ULONG64 BreakpointAddress;
ULONG Flags;
} DBGKD_SET_INTERNAL_BREAKPOINT64, *PDBGKD_SET_INTERNAL_BREAKPOINT64;
typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT64
{
ULONG64 BreakpointAddress;
ULONG Flags;
ULONG Calls;
ULONG MaxCallsPerPeriod;
ULONG MinInstructions;
ULONG MaxInstructions;
ULONG TotalInstructions;
} DBGKD_GET_INTERNAL_BREAKPOINT64, *PDBGKD_GET_INTERNAL_BREAKPOINT64;
typedef struct _DBGKD_BREAKPOINTEX
{
ULONG BreakPointCount;
NTSTATUS ContinueStatus;
} DBGKD_BREAKPOINTEX, *PDBGKD_BREAKPOINTEX;
typedef struct _DBGKD_SEARCH_MEMORY
{
union
{
ULONG64 SearchAddress;
ULONG64 FoundAddress;
};
ULONG64 SearchLength;
ULONG PatternLength;
} DBGKD_SEARCH_MEMORY, *PDBGKD_SEARCH_MEMORY;
typedef struct _DBGKD_GET_SET_BUS_DATA
{
ULONG BusDataType;
ULONG BusNumber;
ULONG SlotNumber;
ULONG Offset;
ULONG Length;
} DBGKD_GET_SET_BUS_DATA, *PDBGKD_GET_SET_BUS_DATA;
typedef struct _DBGKD_FILL_MEMORY
{
ULONG64 Address;
ULONG Length;
USHORT Flags;
USHORT PatternLength;
} DBGKD_FILL_MEMORY, *PDBGKD_FILL_MEMORY;
typedef struct _DBGKD_QUERY_MEMORY
{
ULONG64 Address;
ULONG64 Reserved;
ULONG AddressSpace;
ULONG Flags;
} DBGKD_QUERY_MEMORY, *PDBGKD_QUERY_MEMORY;
typedef struct _DBGKD_SWITCH_PARTITION
{
ULONG Partition;
} DBGKD_SWITCH_PARTITION;
//
// DBGKD Structure for Manipulate
//
typedef struct _DBGKD_MANIPULATE_STATE64
{
ULONG ApiNumber;
USHORT ProcessorLevel;
USHORT Processor;
NTSTATUS ReturnStatus;
union
{
DBGKD_READ_MEMORY64 ReadMemory;
DBGKD_WRITE_MEMORY64 WriteMemory;
DBGKD_GET_CONTEXT GetContext;
DBGKD_SET_CONTEXT SetContext;
DBGKD_WRITE_BREAKPOINT64 WriteBreakPoint;
DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint;
DBGKD_CONTINUE Continue;
DBGKD_CONTINUE2 Continue2;
DBGKD_READ_WRITE_IO64 ReadWriteIo;
DBGKD_READ_WRITE_IO_EXTENDED64 ReadWriteIoExtended;
DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls;
DBGKD_SET_SPECIAL_CALL64 SetSpecialCall;
DBGKD_SET_INTERNAL_BREAKPOINT64 SetInternalBreakpoint;
DBGKD_GET_INTERNAL_BREAKPOINT64 GetInternalBreakpoint;
DBGKD_GET_VERSION64 GetVersion64;
DBGKD_BREAKPOINTEX BreakPointEx;
DBGKD_READ_WRITE_MSR ReadWriteMsr;
DBGKD_SEARCH_MEMORY SearchMemory;
DBGKD_GET_SET_BUS_DATA GetSetBusData;
DBGKD_FILL_MEMORY FillMemory;
DBGKD_QUERY_MEMORY QueryMemory;
DBGKD_SWITCH_PARTITION SwitchPartition;
} u;
} DBGKD_MANIPULATE_STATE64, *PDBGKD_MANIPULATE_STATE64;
FORCEINLINE
VOID
ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
OUT PEXCEPTION_RECORD64 Ex64)
{
ULONG i;
Ex64->ExceptionCode = Ex32->ExceptionCode;
Ex64->ExceptionFlags = Ex32->ExceptionFlags;
Ex64->ExceptionRecord = Ex32->ExceptionRecord;
COPYSE(Ex64,Ex32,ExceptionAddress);
Ex64->NumberParameters = Ex32->NumberParameters;
for (i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
{
COPYSE(Ex64,Ex32,ExceptionInformation[i]);
}
}
#endif