- Implement KdpQueryMemory (KdQueryMemoryApi).
[reactos.git] / reactos / include / reactos / windbgkd.h
1 #ifndef _WINDBGKD_
2 #define _WINDBGKG_
3
4 //
5 // Dependencies
6 //
7 #include "wdbgexts.h"
8
9 //
10 // Conversion Macros
11 //
12 #define COPYSE(p64, p32, f) \
13 p64->f = (ULONG64)(LONG64)(LONG)p32->f
14
15 //
16 // Packet Size and Control Stream Size
17 //
18 #define PACKET_MAX_SIZE 4000
19 #define DBGKD_MAXSTREAM 16
20
21 //
22 // Magic Packet IDs
23 //
24 #define INITIAL_PACKET_ID 0x80800000
25 #define SYNC_PACKET_ID 0x00000800
26
27 //
28 // Magic Packet bytes
29 //
30 #define BREAKIN_PACKET 0x62626262
31 #define BREAKIN_PACKET_BYTE 0x62
32 #define PACKET_LEADER 0x30303030
33 #define PACKET_LEADER_BYTE 0x30
34 #define CONTROL_PACKET_LEADER 0x69696969
35 #define CONTROL_PACKET_LEADER_BYTE 0x69
36 #define PACKET_TRAILING_BYTE 0xAA
37
38 //
39 // Packet Types
40 //
41 #define PACKET_TYPE_UNUSED 0
42 #define PACKET_TYPE_KD_STATE_CHANGE32 1
43 #define PACKET_TYPE_KD_STATE_MANIPULATE 2
44 #define PACKET_TYPE_KD_DEBUG_IO 3
45 #define PACKET_TYPE_KD_ACKNOWLEDGE 4
46 #define PACKET_TYPE_KD_RESEND 5
47 #define PACKET_TYPE_KD_RESET 6
48 #define PACKET_TYPE_KD_STATE_CHANGE64 7
49 #define PACKET_TYPE_KD_POLL_BREAKIN 8
50 #define PACKET_TYPE_KD_TRACE_IO 9
51 #define PACKET_TYPE_KD_CONTROL_REQUEST 10
52 #define PACKET_TYPE_KD_FILE_IO 11
53 #define PACKET_TYPE_MAX 12
54
55 //
56 // Wait State Change Types
57 //
58 #define DbgKdMinimumStateChange 0x00003030
59 #define DbgKdExceptionStateChange 0x00003030
60 #define DbgKdLoadSymbolsStateChange 0x00003031
61 #define DbgKdCommandStringStateChange 0x00003032
62 #define DbgKdMaximumStateChange 0x00003033
63
64 //
65 // Manipulate Types
66 //
67 #define DbgKdMinimumManipulate 0x00003130
68 #define DbgKdReadVirtualMemoryApi 0x00003130
69 #define DbgKdWriteVirtualMemoryApi 0x00003131
70 #define DbgKdGetContextApi 0x00003132
71 #define DbgKdSetContextApi 0x00003133
72 #define DbgKdWriteBreakPointApi 0x00003134
73 #define DbgKdRestoreBreakPointApi 0x00003135
74 #define DbgKdContinueApi 0x00003136
75 #define DbgKdReadControlSpaceApi 0x00003137
76 #define DbgKdWriteControlSpaceApi 0x00003138
77 #define DbgKdReadIoSpaceApi 0x00003139
78 #define DbgKdWriteIoSpaceApi 0x0000313A
79 #define DbgKdRebootApi 0x0000313B
80 #define DbgKdContinueApi2 0x0000313C
81 #define DbgKdReadPhysicalMemoryApi 0x0000313D
82 #define DbgKdWritePhysicalMemoryApi 0x0000313E
83 #define DbgKdQuerySpecialCallsApi 0x0000313F
84 #define DbgKdSetSpecialCallApi 0x00003140
85 #define DbgKdClearSpecialCallsApi 0x00003141
86 #define DbgKdSetInternalBreakPointApi 0x00003142
87 #define DbgKdGetInternalBreakPointApi 0x00003143
88 #define DbgKdReadIoSpaceExtendedApi 0x00003144
89 #define DbgKdWriteIoSpaceExtendedApi 0x00003145
90 #define DbgKdGetVersionApi 0x00003146
91 #define DbgKdWriteBreakPointExApi 0x00003147
92 #define DbgKdRestoreBreakPointExApi 0x00003148
93 #define DbgKdCauseBugCheckApi 0x00003149
94 #define DbgKdSwitchProcessor 0x00003150
95 #define DbgKdPageInApi 0x00003151
96 #define DbgKdReadMachineSpecificRegister 0x00003152
97 #define DbgKdWriteMachineSpecificRegister 0x00003153
98 #define OldVlm1 0x00003154
99 #define OldVlm2 0x00003155
100 #define DbgKdSearchMemoryApi 0x00003156
101 #define DbgKdGetBusDataApi 0x00003157
102 #define DbgKdSetBusDataApi 0x00003158
103 #define DbgKdCheckLowMemoryApi 0x00003159
104 #define DbgKdClearAllInternalBreakpointsApi 0x0000315A
105 #define DbgKdFillMemoryApi 0x0000315B
106 #define DbgKdQueryMemoryApi 0x0000315C
107 #define DbgKdSwitchPartition 0x0000315D
108 #define DbgKdMaximumManipulate 0x0000315E
109
110 //
111 // Debug I/O Types
112 //
113 #define DbgKdPrintStringApi 0x00003230
114 #define DbgKdGetStringApi 0x00003231
115
116 //
117 // Control Report Flags
118 //
119 #define REPORT_INCLUDES_SEGS 0x0001
120 #define REPORT_INCLUDES_CS 0x0002
121
122 //
123 // Protocol Versions
124 //
125 #define DBGKD_64BIT_PROTOCOL_VERSION1 5
126 #define DBGKD_64BIT_PROTOCOL_VERSION2 6
127
128 //
129 // Query Memory Address Spaces
130 //
131 #define DBGKD_QUERY_MEMORY_VIRTUAL 0
132 #define DBGKD_QUERY_MEMORY_PROCESS 0
133 #define DBGKD_QUERY_MEMORY_SESSION 1
134 #define DBGKD_QUERY_MEMORY_KERNEL 2
135
136 //
137 // Query Memory Flags
138 //
139 #define DBGKD_QUERY_MEMORY_READ 0x01
140 #define DBGKD_QUERY_MEMORY_WRITE 0x02
141 #define DBGKD_QUERY_MEMORY_EXECUTE 0x04
142 #define DBGKD_QUERY_MEMORY_FIXED 0x08
143
144 //
145 // KD Packet Structure
146 //
147 typedef struct _KD_PACKET
148 {
149 ULONG PacketLeader;
150 USHORT PacketType;
151 USHORT ByteCount;
152 ULONG PacketId;
153 ULONG Checksum;
154 } KD_PACKET, *PKD_PACKET;
155
156 //
157 // KD Context
158 //
159 typedef struct _KD_CONTEXT
160 {
161 ULONG KdpDefaultRetries;
162 BOOLEAN KdpControlCPending;
163 } KD_CONTEXT, *PKD_CONTEXT;
164
165 //
166 // Control Sets for Supported Architectures
167 //
168 #include <pshpack4.h>
169 typedef struct _X86_DBGKD_CONTROL_SET
170 {
171 ULONG TraceFlag;
172 ULONG Dr7;
173 ULONG CurrentSymbolStart;
174 ULONG CurrentSymbolEnd;
175 } X86_DBGKD_CONTROL_SET, *PX86_DBGKD_CONTROL_SET;
176
177 typedef struct _IA64_DBGKD_CONTROL_SET
178 {
179 ULONG Continue;
180 ULONG64 CurrentSymbolStart;
181 ULONG64 CurrentSymbolEnd;
182 } IA64_DBGKD_CONTROL_SET, *PIA64_DBGKD_CONTROL_SET;
183
184 typedef struct _AMD64_DBGKD_CONTROL_SET
185 {
186 ULONG TraceFlag;
187 ULONG64 Dr7;
188 ULONG64 CurrentSymbolStart;
189 ULONG64 CurrentSymbolEnd;
190 } AMD64_DBGKD_CONTROL_SET, *PAMD64_DBGKD_CONTROL_SET;
191
192 typedef struct _DBGKD_ANY_CONTROL_SET
193 {
194 union
195 {
196 X86_DBGKD_CONTROL_SET X86ControlSet;
197 IA64_DBGKD_CONTROL_SET IA64ControlSet;
198 AMD64_DBGKD_CONTROL_SET Amd64ControlSet;
199 };
200 } DBGKD_ANY_CONTROL_SET, *PDBGKD_ANY_CONTROL_SET;
201 #include <poppack.h>
202
203 typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET;
204
205 //
206 // DBGKM Structure for Exceptions
207 //
208 typedef struct _DBGKM_EXCEPTION64
209 {
210 EXCEPTION_RECORD64 ExceptionRecord;
211 ULONG FirstChance;
212 } DBGKM_EXCEPTION64, *PDBGKM_EXCEPTION64;
213
214 //
215 // DBGKD Structure for State Change
216 //
217 typedef struct _DBGKD_CONTROL_REPORT
218 {
219 ULONG Dr6;
220 ULONG Dr7;
221 USHORT InstructionCount;
222 USHORT ReportFlags;
223 UCHAR InstructionStream[DBGKD_MAXSTREAM];
224 USHORT SegCs;
225 USHORT SegDs;
226 USHORT SegEs;
227 USHORT SegFs;
228 ULONG EFlags;
229 } DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
230
231 //
232 // DBGKD Structure for Debug I/O Type Print String
233 //
234 typedef struct _DBGKD_PRINT_STRING
235 {
236 ULONG LengthOfString;
237 } DBGKD_PRINT_STRING, *PDBGKD_PRINT_STRING;
238
239 //
240 // DBGKD Structure for Debug I/O Type Get String
241 //
242 typedef struct _DBGKD_GET_STRING
243 {
244 ULONG LengthOfPromptString;
245 ULONG LengthOfStringRead;
246 } DBGKD_GET_STRING, *PDBGKD_GET_STRING;
247
248 //
249 // DBGKD Structure for Debug I/O
250 //
251 typedef struct _DBGKD_DEBUG_IO
252 {
253 ULONG ApiNumber;
254 USHORT ProcessorLevel;
255 USHORT Processor;
256 union
257 {
258 DBGKD_PRINT_STRING PrintString;
259 DBGKD_GET_STRING GetString;
260 } u;
261 } DBGKD_DEBUG_IO, *PDBGKD_DEBUG_IO;
262
263 //
264 // DBGKD Structure for Load Symbols
265 //
266 typedef struct _DBGKD_LOAD_SYMBOLS64
267 {
268 ULONG PathNameLength;
269 ULONG64 BaseOfDll;
270 ULONG64 ProcessId;
271 ULONG CheckSum;
272 ULONG SizeOfImage;
273 BOOLEAN UnloadSymbols;
274 } DBGKD_LOAD_SYMBOLS64, *PDBGKD_LOAD_SYMBOLS64;
275
276 //
277 // DBGKD Structure for Wait State Change
278 //
279 typedef struct _DBGKD_WAIT_STATE_CHANGE64
280 {
281 ULONG NewState;
282 USHORT ProcessorLevel;
283 USHORT Processor;
284 ULONG NumberProcessors;
285 ULONG64 Thread;
286 ULONG64 ProgramCounter;
287 union
288 {
289 DBGKM_EXCEPTION64 Exception;
290 DBGKD_LOAD_SYMBOLS64 LoadSymbols;
291 } u;
292 DBGKD_CONTROL_REPORT ControlReport;
293 CONTEXT Context;
294 } DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
295
296 //
297 // DBGKD Manipulate Structures
298 //
299 typedef struct _DBGKD_READ_MEMORY64
300 {
301 ULONG64 TargetBaseAddress;
302 ULONG TransferCount;
303 ULONG ActualBytesRead;
304 } DBGKD_READ_MEMORY64, *PDBGKD_READ_MEMORY64;
305
306 typedef struct _DBGKD_WRITE_MEMORY64
307 {
308 ULONG64 TargetBaseAddress;
309 ULONG TransferCount;
310 ULONG ActualBytesWritten;
311 } DBGKD_WRITE_MEMORY64, *PDBGKD_WRITE_MEMORY64;
312
313 typedef struct _DBGKD_GET_CONTEXT
314 {
315 ULONG Unused;
316 } DBGKD_GET_CONTEXT, *PDBGKD_GET_CONTEXT;
317
318 typedef struct _DBGKD_SET_CONTEXT
319 {
320 ULONG ContextFlags;
321 } DBGKD_SET_CONTEXT, *PDBGKD_SET_CONTEXT;
322
323 typedef struct _DBGKD_WRITE_BREAKPOINT64
324 {
325 ULONG64 BreakPointAddress;
326 ULONG BreakPointHandle;
327 } DBGKD_WRITE_BREAKPOINT64, *PDBGKD_WRITE_BREAKPOINT64;
328
329 typedef struct _DBGKD_RESTORE_BREAKPOINT
330 {
331 ULONG BreakPointHandle;
332 } DBGKD_RESTORE_BREAKPOINT, *PDBGKD_RESTORE_BREAKPOINT;
333
334 typedef struct _DBGKD_CONTINUE
335 {
336 NTSTATUS ContinueStatus;
337 } DBGKD_CONTINUE, *PDBGKD_CONTINUE;
338
339 #include <pshpack4.h>
340 typedef struct _DBGKD_CONTINUE2
341 {
342 NTSTATUS ContinueStatus;
343 union
344 {
345 DBGKD_CONTROL_SET ControlSet;
346 DBGKD_ANY_CONTROL_SET AnyControlSet;
347 };
348 } DBGKD_CONTINUE2, *PDBGKD_CONTINUE2;
349 #include <poppack.h>
350
351 typedef struct _DBGKD_READ_WRITE_IO64
352 {
353 ULONG64 IoAddress;
354 ULONG DataSize;
355 ULONG DataValue;
356 } DBGKD_READ_WRITE_IO64, *PDBGKD_READ_WRITE_IO64;
357
358 typedef struct _DBGKD_READ_WRITE_IO_EXTENDED64
359 {
360 ULONG DataSize;
361 ULONG InterfaceType;
362 ULONG BusNumber;
363 ULONG AddressSpace;
364 ULONG64 IoAddress;
365 ULONG DataValue;
366 } DBGKD_READ_WRITE_IO_EXTENDED64, *PDBGKD_READ_WRITE_IO_EXTENDED64;
367
368 typedef struct _DBGKD_READ_WRITE_MSR
369 {
370 ULONG Msr;
371 ULONG DataValueLow;
372 ULONG DataValueHigh;
373 } DBGKD_READ_WRITE_MSR, *PDBGKD_READ_WRITE_MSR;
374
375 typedef struct _DBGKD_QUERY_SPECIAL_CALLS
376 {
377 ULONG NumberOfSpecialCalls;
378 } DBGKD_QUERY_SPECIAL_CALLS, *PDBGKD_QUERY_SPECIAL_CALLS;
379
380 typedef struct _DBGKD_SET_SPECIAL_CALL64
381 {
382 ULONG64 SpecialCall;
383 } DBGKD_SET_SPECIAL_CALL64, *PDBGKD_SET_SPECIAL_CALL64;
384
385 typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT64
386 {
387 ULONG64 BreakpointAddress;
388 ULONG Flags;
389 } DBGKD_SET_INTERNAL_BREAKPOINT64, *PDBGKD_SET_INTERNAL_BREAKPOINT64;
390
391 typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT64
392 {
393 ULONG64 BreakpointAddress;
394 ULONG Flags;
395 ULONG Calls;
396 ULONG MaxCallsPerPeriod;
397 ULONG MinInstructions;
398 ULONG MaxInstructions;
399 ULONG TotalInstructions;
400 } DBGKD_GET_INTERNAL_BREAKPOINT64, *PDBGKD_GET_INTERNAL_BREAKPOINT64;
401
402 typedef struct _DBGKD_BREAKPOINTEX
403 {
404 ULONG BreakPointCount;
405 NTSTATUS ContinueStatus;
406 } DBGKD_BREAKPOINTEX, *PDBGKD_BREAKPOINTEX;
407
408 typedef struct _DBGKD_SEARCH_MEMORY
409 {
410 union
411 {
412 ULONG64 SearchAddress;
413 ULONG64 FoundAddress;
414 };
415 ULONG64 SearchLength;
416 ULONG PatternLength;
417 } DBGKD_SEARCH_MEMORY, *PDBGKD_SEARCH_MEMORY;
418
419 typedef struct _DBGKD_GET_SET_BUS_DATA
420 {
421 ULONG BusDataType;
422 ULONG BusNumber;
423 ULONG SlotNumber;
424 ULONG Offset;
425 ULONG Length;
426 } DBGKD_GET_SET_BUS_DATA, *PDBGKD_GET_SET_BUS_DATA;
427
428 typedef struct _DBGKD_FILL_MEMORY
429 {
430 ULONG64 Address;
431 ULONG Length;
432 USHORT Flags;
433 USHORT PatternLength;
434 } DBGKD_FILL_MEMORY, *PDBGKD_FILL_MEMORY;
435
436 typedef struct _DBGKD_QUERY_MEMORY
437 {
438 ULONG64 Address;
439 ULONG64 Reserved;
440 ULONG AddressSpace;
441 ULONG Flags;
442 } DBGKD_QUERY_MEMORY, *PDBGKD_QUERY_MEMORY;
443
444 typedef struct _DBGKD_SWITCH_PARTITION
445 {
446 ULONG Partition;
447 } DBGKD_SWITCH_PARTITION;
448
449 //
450 // DBGKD Structure for Manipulate
451 //
452 typedef struct _DBGKD_MANIPULATE_STATE64
453 {
454 ULONG ApiNumber;
455 USHORT ProcessorLevel;
456 USHORT Processor;
457 NTSTATUS ReturnStatus;
458 union
459 {
460 DBGKD_READ_MEMORY64 ReadMemory;
461 DBGKD_WRITE_MEMORY64 WriteMemory;
462 DBGKD_GET_CONTEXT GetContext;
463 DBGKD_SET_CONTEXT SetContext;
464 DBGKD_WRITE_BREAKPOINT64 WriteBreakPoint;
465 DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint;
466 DBGKD_CONTINUE Continue;
467 DBGKD_CONTINUE2 Continue2;
468 DBGKD_READ_WRITE_IO64 ReadWriteIo;
469 DBGKD_READ_WRITE_IO_EXTENDED64 ReadWriteIoExtended;
470 DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls;
471 DBGKD_SET_SPECIAL_CALL64 SetSpecialCall;
472 DBGKD_SET_INTERNAL_BREAKPOINT64 SetInternalBreakpoint;
473 DBGKD_GET_INTERNAL_BREAKPOINT64 GetInternalBreakpoint;
474 DBGKD_GET_VERSION64 GetVersion64;
475 DBGKD_BREAKPOINTEX BreakPointEx;
476 DBGKD_READ_WRITE_MSR ReadWriteMsr;
477 DBGKD_SEARCH_MEMORY SearchMemory;
478 DBGKD_GET_SET_BUS_DATA GetSetBusData;
479 DBGKD_FILL_MEMORY FillMemory;
480 DBGKD_QUERY_MEMORY QueryMemory;
481 DBGKD_SWITCH_PARTITION SwitchPartition;
482 } u;
483 } DBGKD_MANIPULATE_STATE64, *PDBGKD_MANIPULATE_STATE64;
484
485 FORCEINLINE
486 VOID
487 ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
488 OUT PEXCEPTION_RECORD64 Ex64)
489 {
490 ULONG i;
491
492 Ex64->ExceptionCode = Ex32->ExceptionCode;
493 Ex64->ExceptionFlags = Ex32->ExceptionFlags;
494 Ex64->ExceptionRecord = Ex32->ExceptionRecord;
495 COPYSE(Ex64,Ex32,ExceptionAddress);
496 Ex64->NumberParameters = Ex32->NumberParameters;
497
498 for (i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
499 {
500 COPYSE(Ex64,Ex32,ExceptionInformation[i]);
501 }
502 }
503
504 #endif