Create a branch for network fixes.
[reactos.git] / ntoskrnl / kd64 / kddata.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/kd64/kddata.c
5 * PURPOSE: Contains all global variables and settings for KD64
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14
15 VOID NTAPI RtlpBreakWithStatusInstruction(VOID);
16
17 /* GLOBALS *******************************************************************/
18
19 //
20 // Debugger State
21 //
22 KD_CONTEXT KdpContext;
23 BOOLEAN KdpPortLocked;
24 KSPIN_LOCK KdpDebuggerLock;
25 BOOLEAN KdpControlCPressed;
26
27 //
28 // Debug Trap Handlers
29 //
30 PKDEBUG_ROUTINE KiDebugRoutine = KdpStub;
31 PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;
32
33 //
34 // Debugger Configuration Settings
35 //
36 BOOLEAN KdBreakAfterSymbolLoad;
37 BOOLEAN KdPitchDebugger;
38 BOOLEAN _KdDebuggerNotPresent;
39 BOOLEAN _KdDebuggerEnabled;
40 BOOLEAN KdAutoEnableOnEvent;
41 BOOLEAN KdPreviouslyEnabled;
42 BOOLEAN KdpDebuggerStructuresInitialized;
43 BOOLEAN KdEnteredDebugger;
44 ULONG KdDisableCount;
45 LARGE_INTEGER KdPerformanceCounterRate;
46
47 //
48 // Breakpoint Data
49 //
50 BREAKPOINT_ENTRY KdpBreakpointTable[20];
51 ULONG KdpBreakpointInstruction = 0xCC;
52 BOOLEAN KdpOweBreakpoint;
53 BOOLEAN BreakpointsSuspended;
54 ULONG KdpNumInternalBreakpoints;
55
56 ULONG KdpCurrentSymbolStart, KdpCurrentSymbolEnd;
57
58 //
59 // Tracepoint Data
60 //
61 ULONG TraceDataBuffer[40];
62 ULONG TraceDataBufferPosition = 1;
63
64 //
65 // Time Slip Support
66 //
67 KDPC KdpTimeSlipDpc;
68 KTIMER KdpTimeSlipTimer;
69 WORK_QUEUE_ITEM KdpTimeSlipWorkItem;
70 LONG KdpTimeSlipPending = 1;
71 PKEVENT KdpTimeSlipEvent;
72 KSPIN_LOCK KdpTimeSlipEventLock;
73 LARGE_INTEGER KdTimerStop, KdTimerStart, KdTimerDifference;
74
75 //
76 // Buffers
77 //
78 CHAR KdpMessageBuffer[4096];
79 CHAR KdpPathBuffer[4096];
80
81 //
82 // KdPrint Buffers
83 //
84 CHAR KdPrintDefaultCircularBuffer[0x8000];
85 PCHAR KdPrintWritePointer = KdPrintDefaultCircularBuffer;
86 ULONG KdPrintRolloverCount;
87 PCHAR KdPrintCircularBuffer = KdPrintDefaultCircularBuffer;
88 ULONG KdPrintBufferSize = sizeof(KdPrintDefaultCircularBuffer);
89 ULONG KdPrintBufferChanges = 0;
90
91 //
92 // Debug Filter Masks
93 //
94 ULONG Kd_WIN2000_Mask = 1;
95 ULONG Kd_SYSTEM_Mask;
96 ULONG Kd_SMSS_Mask;
97 ULONG Kd_SETUP_Mask;
98 ULONG Kd_NTFS_Mask;
99 ULONG Kd_FSTUB_Mask;
100 ULONG Kd_CRASHDUMP_Mask;
101 ULONG Kd_CDAUDIO_Mask;
102 ULONG Kd_CDROM_Mask;
103 ULONG Kd_CLASSPNP_Mask;
104 ULONG Kd_DISK_Mask;
105 ULONG Kd_REDBOOK_Mask;
106 ULONG Kd_STORPROP_Mask;
107 ULONG Kd_SCSIPORT_Mask;
108 ULONG Kd_SCSIMINIPORT_Mask;
109 ULONG Kd_CONFIG_Mask;
110 ULONG Kd_I8042PRT_Mask;
111 ULONG Kd_SERMOUSE_Mask;
112 ULONG Kd_LSERMOUS_Mask;
113 ULONG Kd_KBDHID_Mask;
114 ULONG Kd_MOUHID_Mask;
115 ULONG Kd_KBDCLASS_Mask;
116 ULONG Kd_MOUCLASS_Mask;
117 ULONG Kd_TWOTRACK_Mask;
118 ULONG Kd_WMILIB_Mask;
119 ULONG Kd_ACPI_Mask;
120 ULONG Kd_AMLI_Mask;
121 ULONG Kd_HALIA64_Mask;
122 ULONG Kd_VIDEO_Mask;
123 ULONG Kd_SVCHOST_Mask;
124 ULONG Kd_VIDEOPRT_Mask;
125 ULONG Kd_TCPIP_Mask;
126 ULONG Kd_DMSYNTH_Mask;
127 ULONG Kd_NTOSPNP_Mask;
128 ULONG Kd_FASTFAT_Mask;
129 ULONG Kd_SAMSS_Mask;
130 ULONG Kd_PNPMGR_Mask;
131 ULONG Kd_NETAPI_Mask;
132 ULONG Kd_SCSERVER_Mask;
133 ULONG Kd_SCCLIENT_Mask;
134 ULONG Kd_SERIAL_Mask;
135 ULONG Kd_SERENUM_Mask;
136 ULONG Kd_UHCD_Mask;
137 ULONG Kd_RPCPROXY_Mask;
138 ULONG Kd_AUTOCHK_Mask;
139 ULONG Kd_DCOMSS_Mask;
140 ULONG Kd_UNIMODEM_Mask;
141 ULONG Kd_SIS_Mask;
142 ULONG Kd_FLTMGR_Mask;
143 ULONG Kd_WMICORE_Mask;
144 ULONG Kd_BURNENG_Mask;
145 ULONG Kd_IMAPI_Mask;
146 ULONG Kd_SXS_Mask;
147 ULONG Kd_FUSION_Mask;
148 ULONG Kd_IDLETASK_Mask;
149 ULONG Kd_SOFTPCI_Mask;
150 ULONG Kd_TAPE_Mask;
151 ULONG Kd_MCHGR_Mask;
152 ULONG Kd_IDEP_Mask;
153 ULONG Kd_PCIIDE_Mask;
154 ULONG Kd_FLOPPY_Mask;
155 ULONG Kd_FDC_Mask;
156 ULONG Kd_TERMSRV_Mask;
157 ULONG Kd_W32TIME_Mask;
158 ULONG Kd_PREFETCHER_Mask;
159 ULONG Kd_RSFILTER_Mask;
160 ULONG Kd_FCPORT_Mask;
161 ULONG Kd_PCI_Mask;
162 ULONG Kd_DMIO_Mask;
163 ULONG Kd_DMCONFIG_Mask;
164 ULONG Kd_DMADMIN_Mask;
165 ULONG Kd_WSOCKTRANSPORT_Mask;
166 ULONG Kd_VSS_Mask;
167 ULONG Kd_PNPMEM_Mask;
168 ULONG Kd_PROCESSOR_Mask;
169 ULONG Kd_DMSERVER_Mask;
170 ULONG Kd_SR_Mask;
171 ULONG Kd_INFINIBAND_Mask;
172 ULONG Kd_IHVDRIVER_Mask;
173 ULONG Kd_IHVVIDEO_Mask;
174 ULONG Kd_IHVAUDIO_Mask;
175 ULONG Kd_IHVNETWORK_Mask;
176 ULONG Kd_IHVSTREAMING_Mask;
177 ULONG Kd_IHVBUS_Mask;
178 ULONG Kd_HPS_Mask;
179 ULONG Kd_RTLTHREADPOOL_Mask;
180 ULONG Kd_LDR_Mask;
181 ULONG Kd_TCPIP6_Mask;
182 ULONG Kd_ISAPNP_Mask;
183 ULONG Kd_SHPC_Mask;
184 ULONG Kd_STORPORT_Mask;
185 ULONG Kd_STORMINIPORT_Mask;
186 ULONG Kd_PRINTSPOOLER_Mask;
187 ULONG Kd_VSSDYNDISK_Mask;
188 ULONG Kd_VERIFIER_Mask;
189 ULONG Kd_VDS_Mask;
190 ULONG Kd_VDSBAS_Mask;
191 ULONG Kd_VDSDYNDR_Mask;
192 ULONG Kd_VDSUTIL_Mask;
193 ULONG Kd_DFRGIFC_Mask;
194 ULONG Kd_DEFAULT_Mask;
195 ULONG Kd_MM_Mask;
196 ULONG Kd_DFSC_Mask;
197 ULONG Kd_WOW64_Mask;
198 ULONG Kd_ENDOFTABLE_Mask;
199
200 //
201 // Debug Filter Component Table
202 //
203 PULONG KdComponentTable[104] =
204 {
205 &Kd_SYSTEM_Mask,
206 &Kd_SMSS_Mask,
207 &Kd_SETUP_Mask,
208 &Kd_NTFS_Mask,
209 &Kd_FSTUB_Mask,
210 &Kd_CRASHDUMP_Mask,
211 &Kd_CDAUDIO_Mask,
212 &Kd_CDROM_Mask,
213 &Kd_CLASSPNP_Mask,
214 &Kd_DISK_Mask,
215 &Kd_REDBOOK_Mask,
216 &Kd_STORPROP_Mask,
217 &Kd_SCSIPORT_Mask,
218 &Kd_SCSIMINIPORT_Mask,
219 &Kd_CONFIG_Mask,
220 &Kd_I8042PRT_Mask,
221 &Kd_SERMOUSE_Mask,
222 &Kd_LSERMOUS_Mask,
223 &Kd_KBDHID_Mask,
224 &Kd_MOUHID_Mask,
225 &Kd_KBDCLASS_Mask,
226 &Kd_MOUCLASS_Mask,
227 &Kd_TWOTRACK_Mask,
228 &Kd_WMILIB_Mask,
229 &Kd_ACPI_Mask,
230 &Kd_AMLI_Mask,
231 &Kd_HALIA64_Mask,
232 &Kd_VIDEO_Mask,
233 &Kd_SVCHOST_Mask,
234 &Kd_VIDEOPRT_Mask,
235 &Kd_TCPIP_Mask,
236 &Kd_DMSYNTH_Mask,
237 &Kd_NTOSPNP_Mask,
238 &Kd_FASTFAT_Mask,
239 &Kd_SAMSS_Mask,
240 &Kd_PNPMGR_Mask,
241 &Kd_NETAPI_Mask,
242 &Kd_SCSERVER_Mask,
243 &Kd_SCCLIENT_Mask,
244 &Kd_SERIAL_Mask,
245 &Kd_SERENUM_Mask,
246 &Kd_UHCD_Mask,
247 &Kd_RPCPROXY_Mask,
248 &Kd_AUTOCHK_Mask,
249 &Kd_DCOMSS_Mask,
250 &Kd_UNIMODEM_Mask,
251 &Kd_SIS_Mask,
252 &Kd_FLTMGR_Mask,
253 &Kd_WMICORE_Mask,
254 &Kd_BURNENG_Mask,
255 &Kd_IMAPI_Mask,
256 &Kd_SXS_Mask,
257 &Kd_FUSION_Mask,
258 &Kd_IDLETASK_Mask,
259 &Kd_SOFTPCI_Mask,
260 &Kd_TAPE_Mask,
261 &Kd_MCHGR_Mask,
262 &Kd_IDEP_Mask,
263 &Kd_PCIIDE_Mask,
264 &Kd_FLOPPY_Mask,
265 &Kd_FDC_Mask,
266 &Kd_TERMSRV_Mask,
267 &Kd_W32TIME_Mask,
268 &Kd_PREFETCHER_Mask,
269 &Kd_RSFILTER_Mask,
270 &Kd_FCPORT_Mask,
271 &Kd_PCI_Mask,
272 &Kd_DMIO_Mask,
273 &Kd_DMCONFIG_Mask,
274 &Kd_DMADMIN_Mask,
275 &Kd_WSOCKTRANSPORT_Mask,
276 &Kd_VSS_Mask,
277 &Kd_PNPMEM_Mask,
278 &Kd_PROCESSOR_Mask,
279 &Kd_DMSERVER_Mask,
280 &Kd_SR_Mask,
281 &Kd_INFINIBAND_Mask,
282 &Kd_IHVDRIVER_Mask,
283 &Kd_IHVVIDEO_Mask,
284 &Kd_IHVAUDIO_Mask,
285 &Kd_IHVNETWORK_Mask,
286 &Kd_IHVSTREAMING_Mask,
287 &Kd_IHVBUS_Mask,
288 &Kd_HPS_Mask,
289 &Kd_RTLTHREADPOOL_Mask,
290 &Kd_LDR_Mask,
291 &Kd_TCPIP6_Mask,
292 &Kd_ISAPNP_Mask,
293 &Kd_SHPC_Mask,
294 &Kd_STORPORT_Mask,
295 &Kd_STORMINIPORT_Mask,
296 &Kd_PRINTSPOOLER_Mask,
297 &Kd_VSSDYNDISK_Mask,
298 &Kd_VERIFIER_Mask,
299 &Kd_VDS_Mask,
300 &Kd_VDSBAS_Mask,
301 &Kd_VDSDYNDR_Mask,
302 &Kd_VDSUTIL_Mask,
303 &Kd_DFRGIFC_Mask,
304 &Kd_DEFAULT_Mask,
305 &Kd_MM_Mask,
306 &Kd_DFSC_Mask,
307 &Kd_WOW64_Mask,
308 &Kd_ENDOFTABLE_Mask,
309 };
310
311 ULONG KdComponentTableSize = sizeof(KdComponentTable);
312
313 //
314 // Debugger Data
315 //
316 LIST_ENTRY KdpDebuggerDataListHead;
317 KSPIN_LOCK KdpDataSpinLock;
318
319 //
320 // Debugger Version and Data Block
321 //
322 DBGKD_GET_VERSION64 KdVersionBlock =
323 {
324 0,
325 0,
326 DBGKD_64BIT_PROTOCOL_VERSION2,
327 KD_SECONDARY_VERSION_DEFAULT,
328 DBGKD_VERS_FLAG_DATA,
329 #if defined(_M_IX86)
330 IMAGE_FILE_MACHINE_I386,
331 #elif defined(_M_PPC)
332 IMAGE_FILE_MACHINE_POWERPC,
333 #elif defined(_M_MIPS)
334 IMAGE_FILE_MACHINE_R4000,
335 #else
336 #error Unknown platform
337 #endif
338 PACKET_TYPE_MAX,
339 0,
340 0,
341 DBGKD_SIMULATION_NONE,
342 {0},
343 0,
344 0,
345 0
346 };
347 KDDEBUGGER_DATA64 KdDebuggerDataBlock =
348 {
349 {{0}},
350 0,
351 {PtrToUlong(RtlpBreakWithStatusInstruction)},
352 0,
353 FIELD_OFFSET(KTHREAD, CallbackStack),
354 CBSTACK_CALLBACK_STACK,
355 CBSTACK_EBP,
356 0,
357 {PtrToUlong(KiCallUserMode)},
358 {0},
359 {PtrToUlong(&PsLoadedModuleList)},
360 {PtrToUlong(&PsActiveProcessHead)},
361 {PtrToUlong(&PspCidTable)},
362 {PtrToUlong(&ExpSystemResourcesList)},
363 {0}, // ExpPagedPoolDescriptor
364 {0}, // ExpNumberOfPagedPools
365 {PtrToUlong(&KeTimeIncrement)},
366 {PtrToUlong(&KeBugcheckCallbackListHead)},
367 {PtrToUlong(KiBugCheckData)},
368 {PtrToUlong(&IopErrorLogListHead)},
369 {PtrToUlong(&ObpRootDirectoryObject)},
370 {PtrToUlong(&ObpTypeObjectType)},
371 {0}, // MmSystemCacheStart
372 {0}, // MmSystemCacheEnd
373 {0}, // MmSystemCacheWs
374 {0}, // MmPfnDatabase
375 {0}, // MmSystemPtesStart
376 {0}, // MmSystemPtesEnd
377 {0}, // MmSubsectionBase
378 {0}, // MmNumberOfPagingFiles
379 {0}, // MmLowestPhysicalPage
380 {0}, // MmHighestPhysicalPage
381 {0}, // MmNumberOfPhysicalPages
382 {0}, // MmMaximumNonPagedPoolInBytes
383 {0}, // MmNonPagedSystemStart
384 {0}, // MmNonPagedPoolStart
385 {0}, // MmNonPagedPoolEnd
386 {0}, // MmPagedPoolStart
387 {0}, // MmPagedPoolEnd
388 {0}, // MmPagedPoolInfo
389 PAGE_SIZE,
390 {0}, // MmSizeOfPagedPoolInBytes
391 {0}, // MmTotalCommitLimit
392 {0}, // MmTotalCommittedPages
393 {0}, // MmSharedCommit
394 {0}, // MmDriverCommit
395 {0}, // MmProcessCommit
396 {0}, // MmPagedPoolCommit
397 {0},
398 {0}, // MmZeroedPageListHead
399 {0}, // MmFreePageListHead
400 {0}, // MmStandbyPageListHead
401 {0}, // MmModifiedPageListHead
402 {0}, // MmModifiedNoWritePageListHead
403 {0}, // MmAvailablePages
404 {0}, // MmResidentAvailablePages
405 {0}, // PoolTrackTable
406 {0}, // NonPagedPoolDescriptor
407 {PtrToUlong(&MmHighestUserAddress)},
408 {PtrToUlong(&MmSystemRangeStart)},
409 {PtrToUlong(&MmUserProbeAddress)},
410 {PtrToUlong(KdPrintDefaultCircularBuffer)},
411 {PtrToUlong(KdPrintDefaultCircularBuffer + 1)},
412 {PtrToUlong(&KdPrintWritePointer)},
413 {PtrToUlong(&KdPrintRolloverCount)},
414 {0}, // MmLoadedUserImageList
415 {PtrToUlong(&NtBuildLab)},
416 {0},
417 {PtrToUlong(KiProcessorBlock)},
418 {0}, // MmUnloadedDrivers
419 {0}, // MmLastUnloadedDrivers
420 {0}, // MmTriageActionTaken
421 {0}, // MmSpecialPoolTag
422 {0}, // KernelVerifier
423 {0}, // MmVerifierData
424 {0}, // MmAllocatedNonPagedPool
425 {0}, // MmPeakCommitment
426 {0}, // MmtotalCommitLimitMaximum
427 {PtrToUlong(&CmNtCSDVersion)},
428 {0}, // MmPhysicalMemoryBlock
429 {0}, // MmSessionBase
430 {0}, // MmSessionSize
431 {0},
432 {0},
433 FIELD_OFFSET(KTHREAD, NextProcessor),
434 FIELD_OFFSET(KTHREAD, Teb),
435 FIELD_OFFSET(KTHREAD, KernelStack),
436 FIELD_OFFSET(KTHREAD, InitialStack),
437 FIELD_OFFSET(KTHREAD, ApcState.Process),
438 FIELD_OFFSET(KTHREAD, State),
439 0,
440 0,
441 sizeof(EPROCESS),
442 FIELD_OFFSET(EPROCESS, Peb),
443 FIELD_OFFSET(EPROCESS, InheritedFromUniqueProcessId),
444 FIELD_OFFSET(EPROCESS, Pcb.DirectoryTableBase),
445 sizeof(KPRCB),
446 FIELD_OFFSET(KPRCB, DpcRoutineActive),
447 FIELD_OFFSET(KPRCB, CurrentThread),
448 FIELD_OFFSET(KPRCB, MHz),
449 FIELD_OFFSET(KPRCB, CpuType),
450 FIELD_OFFSET(KPRCB, VendorString),
451 FIELD_OFFSET(KPRCB, ProcessorState.ContextFrame),
452 FIELD_OFFSET(KPRCB, Number),
453 sizeof(ETHREAD),
454 {PtrToUlong(KdPrintDefaultCircularBuffer)},
455 {PtrToUlong(&KdPrintBufferSize)},
456 {PtrToUlong(&KeLoaderBlock)},
457 sizeof(KIPCR) + sizeof(KPRCB),
458 FIELD_OFFSET(KIPCR, Self),
459 FIELD_OFFSET(KPCR, Prcb),
460 FIELD_OFFSET(KIPCR, PrcbData),
461 0,
462 0,
463 0,
464 0,
465 0,
466 FIELD_OFFSET(KIPCR, PrcbData) +
467 FIELD_OFFSET(KPRCB, ProcessorState.SpecialRegisters),
468 KGDT_R0_CODE,
469 KGDT_R0_DATA,
470 KGDT_R0_PCR,
471 KGDT_R3_CODE,
472 KGDT_R3_DATA,
473 KGDT_R3_TEB,
474 KGDT_LDT,
475 KGDT_TSS,
476 0,
477 0,
478 {0}, // IopNumTriagDumpDataBlocks
479 {0}, // IopTriageDumpDataBlocks
480 };