1 /* 2 * PROJECT: ReactOS Kernel 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: ntoskrnl/include/internal/kd64.h 5 * PURPOSE: Internal header for the KD64 Library 6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 7 */ 8 9 #pragma once 10 11 // 12 // Default size of the DbgPrint log buffer 13 // 14 #if DBG 15 #define KD_DEFAULT_LOG_BUFFER_SIZE 0x8000 16 #else 17 #define KD_DEFAULT_LOG_BUFFER_SIZE 0x1000 18 #endif 19 20 // 21 // Maximum supported number of breakpoints 22 // 23 #define KD_BREAKPOINT_MAX 32 24 25 // 26 // Highest limit starting which we consider that breakpoint addresses 27 // are either in system space, or in user space but inside shared DLLs. 28 // 29 // I'm wondering whether this can be computed using MmHighestUserAddress 30 // or whether there is already some #define somewhere else... 31 // See http://www.drdobbs.com/windows/faster-dll-load-load/184416918 32 // and http://www.drdobbs.com/rebasing-win32-dlls/184416272 33 // for a tentative explanation. 34 // 35 #define KD_HIGHEST_USER_BREAKPOINT_ADDRESS (PVOID)0x60000000 // MmHighestUserAddress 36 37 // 38 // Breakpoint Status Flags 39 // 40 #define KD_BREAKPOINT_ACTIVE 0x01 41 #define KD_BREAKPOINT_PENDING 0x02 42 #define KD_BREAKPOINT_SUSPENDED 0x04 43 #define KD_BREAKPOINT_EXPIRED 0x08 44 45 // 46 // Structure for Breakpoints 47 // 48 typedef struct _BREAKPOINT_ENTRY 49 { 50 ULONG Flags; 51 ULONG_PTR DirectoryTableBase; 52 PVOID Address; 53 KD_BREAKPOINT_TYPE Content; 54 } BREAKPOINT_ENTRY, *PBREAKPOINT_ENTRY; 55 56 // 57 // Debug and Multi-Processor Switch Routine Definitions 58 // 59 typedef 60 BOOLEAN 61 (NTAPI *PKDEBUG_ROUTINE)( 62 IN PKTRAP_FRAME TrapFrame, 63 IN PKEXCEPTION_FRAME ExceptionFrame, 64 IN PEXCEPTION_RECORD ExceptionRecord, 65 IN PCONTEXT Context, 66 IN KPROCESSOR_MODE PreviousMode, 67 IN BOOLEAN SecondChance 68 ); 69 70 typedef 71 BOOLEAN 72 (NTAPI *PKDEBUG_SWITCH_ROUTINE)( 73 IN PEXCEPTION_RECORD ExceptionRecord, 74 IN PCONTEXT Context, 75 IN BOOLEAN SecondChance 76 ); 77 78 // 79 // Initialization Routines 80 // 81 BOOLEAN 82 NTAPI 83 KdInitSystem( 84 ULONG Reserved, 85 PLOADER_PARAMETER_BLOCK LoaderBlock 86 ); 87 88 VOID 89 NTAPI 90 KdUpdateDataBlock( 91 VOID 92 ); 93 94 // 95 // Determines if the kernel debugger must handle a particular trap 96 // 97 BOOLEAN 98 NTAPI 99 KdIsThisAKdTrap( 100 IN PEXCEPTION_RECORD ExceptionRecord, 101 IN PCONTEXT Context, 102 IN KPROCESSOR_MODE PreviousMode 103 ); 104 105 // 106 // Multi-Processor Switch Support 107 // 108 BOOLEAN 109 NTAPI 110 KdpSwitchProcessor( 111 IN PEXCEPTION_RECORD ExceptionRecord, 112 IN OUT PCONTEXT ContextRecord, 113 IN BOOLEAN SecondChanceException 114 ); 115 116 // 117 // Time Slip Support 118 // 119 VOID 120 NTAPI 121 KdpTimeSlipWork( 122 IN PVOID Context 123 ); 124 125 VOID 126 NTAPI 127 KdpTimeSlipDpcRoutine( 128 IN PKDPC Dpc, 129 IN PVOID DeferredContext, 130 IN PVOID SystemArgument1, 131 IN PVOID SystemArgument2 132 ); 133 134 // 135 // Debug Trap Handlers 136 // 137 BOOLEAN 138 NTAPI 139 KdpStub( 140 IN PKTRAP_FRAME TrapFrame, 141 IN PKEXCEPTION_FRAME ExceptionFrame, 142 IN PEXCEPTION_RECORD ExceptionRecord, 143 IN PCONTEXT ContextRecord, 144 IN KPROCESSOR_MODE PreviousMode, 145 IN BOOLEAN SecondChanceException 146 ); 147 148 BOOLEAN 149 NTAPI 150 KdpTrap( 151 IN PKTRAP_FRAME TrapFrame, 152 IN PKEXCEPTION_FRAME ExceptionFrame, 153 IN PEXCEPTION_RECORD ExceptionRecord, 154 IN PCONTEXT ContextRecord, 155 IN KPROCESSOR_MODE PreviousMode, 156 IN BOOLEAN SecondChanceException 157 ); 158 159 // 160 // Port Locking 161 // 162 VOID 163 NTAPI 164 KdpPortLock( 165 VOID 166 ); 167 168 VOID 169 NTAPI 170 KdpPortUnlock( 171 VOID 172 ); 173 174 BOOLEAN 175 NTAPI 176 KdpPollBreakInWithPortLock( 177 VOID 178 ); 179 180 // 181 // Debugger Enter, Exit, Enable and Disable 182 // 183 BOOLEAN 184 NTAPI 185 KdEnterDebugger( 186 IN PKTRAP_FRAME TrapFrame, 187 IN PKEXCEPTION_FRAME ExceptionFrame 188 ); 189 190 VOID 191 NTAPI 192 KdExitDebugger( 193 IN BOOLEAN Enable 194 ); 195 196 NTSTATUS 197 NTAPI 198 KdEnableDebuggerWithLock( 199 IN BOOLEAN NeedLock 200 ); 201 202 NTSTATUS 203 NTAPI 204 KdDisableDebuggerWithLock( 205 IN BOOLEAN NeedLock 206 ); 207 208 // 209 // Debug Event Handlers 210 // 211 NTSTATUS 212 NTAPI 213 KdpPrint( 214 IN ULONG ComponentId, 215 IN ULONG Level, 216 IN LPSTR String, 217 IN USHORT Length, 218 IN KPROCESSOR_MODE PreviousMode, 219 IN PKTRAP_FRAME TrapFrame, 220 IN PKEXCEPTION_FRAME ExceptionFrame, 221 OUT PBOOLEAN Handled 222 ); 223 224 USHORT 225 NTAPI 226 KdpPrompt( 227 IN LPSTR PromptString, 228 IN USHORT PromptLength, 229 OUT LPSTR ResponseString, 230 IN USHORT MaximumResponseLength, 231 IN KPROCESSOR_MODE PreviousMode, 232 IN PKTRAP_FRAME TrapFrame, 233 IN PKEXCEPTION_FRAME ExceptionFrame 234 ); 235 236 VOID 237 NTAPI 238 KdpSymbol( 239 IN PSTRING DllPath, 240 IN PKD_SYMBOLS_INFO SymbolInfo, 241 IN BOOLEAN Unload, 242 IN KPROCESSOR_MODE PreviousMode, 243 IN PCONTEXT ContextRecord, 244 IN PKTRAP_FRAME TrapFrame, 245 IN PKEXCEPTION_FRAME ExceptionFrame 246 ); 247 248 VOID 249 NTAPI 250 KdpCommandString( 251 IN PSTRING NameString, 252 IN PSTRING CommandString, 253 IN KPROCESSOR_MODE PreviousMode, 254 IN PCONTEXT ContextRecord, 255 IN PKTRAP_FRAME TrapFrame, 256 IN PKEXCEPTION_FRAME ExceptionFrame 257 ); 258 259 // 260 // State Change Notifications 261 // 262 VOID 263 NTAPI 264 KdpReportLoadSymbolsStateChange( 265 IN PSTRING PathName, 266 IN PKD_SYMBOLS_INFO SymbolInfo, 267 IN BOOLEAN Unload, 268 IN OUT PCONTEXT Context 269 ); 270 271 VOID 272 NTAPI 273 KdpReportCommandStringStateChange( 274 IN PSTRING NameString, 275 IN PSTRING CommandString, 276 IN OUT PCONTEXT Context 277 ); 278 279 BOOLEAN 280 NTAPI 281 KdpReportExceptionStateChange( 282 IN PEXCEPTION_RECORD ExceptionRecord, 283 IN OUT PCONTEXT Context, 284 IN BOOLEAN SecondChanceException 285 ); 286 287 // 288 // Breakpoint Support 289 // 290 ULONG 291 NTAPI 292 KdpAddBreakpoint( 293 IN PVOID Address 294 ); 295 296 VOID 297 NTAPI 298 KdSetOwedBreakpoints( 299 VOID 300 ); 301 302 BOOLEAN 303 NTAPI 304 KdpDeleteBreakpoint( 305 IN ULONG BpEntry 306 ); 307 308 BOOLEAN 309 NTAPI 310 KdpDeleteBreakpointRange( 311 IN PVOID Base, 312 IN PVOID Limit 313 ); 314 315 VOID 316 NTAPI 317 KdpSuspendBreakPoint( 318 IN ULONG BpEntry 319 ); 320 321 VOID 322 NTAPI 323 KdpRestoreAllBreakpoints( 324 VOID 325 ); 326 327 VOID 328 NTAPI 329 KdpSuspendAllBreakPoints( 330 VOID 331 ); 332 333 // 334 // Routine to determine if it is safe to disable the debugger 335 // 336 NTSTATUS 337 NTAPI 338 KdpAllowDisable( 339 VOID 340 ); 341 342 // 343 // Safe memory read & write Support 344 // 345 NTSTATUS 346 NTAPI 347 KdpCopyMemoryChunks( 348 IN ULONG64 Address, 349 IN PVOID Buffer, 350 IN ULONG TotalSize, 351 IN ULONG ChunkSize, 352 IN ULONG Flags, 353 OUT PULONG ActualSize OPTIONAL 354 ); 355 356 // 357 // Internal memory handling routines for KD isolation 358 // 359 VOID 360 NTAPI 361 KdpMoveMemory( 362 IN PVOID Destination, 363 IN PVOID Source, 364 IN SIZE_T Length 365 ); 366 367 VOID 368 NTAPI 369 KdpZeroMemory( 370 IN PVOID Destination, 371 IN SIZE_T Length 372 ); 373 374 // 375 // Low Level Support Routines for the KD API 376 // 377 378 // 379 // Version 380 // 381 VOID 382 NTAPI 383 KdpSysGetVersion( 384 IN PDBGKD_GET_VERSION64 Version 385 ); 386 387 // 388 // Context 389 // 390 VOID 391 NTAPI 392 KdpGetStateChange( 393 IN PDBGKD_MANIPULATE_STATE64 State, 394 IN PCONTEXT Context 395 ); 396 397 VOID 398 NTAPI 399 KdpSetContextState( 400 IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange, 401 IN PCONTEXT Context 402 ); 403 404 // 405 // MSR 406 // 407 NTSTATUS 408 NTAPI 409 KdpSysReadMsr( 410 IN ULONG Msr, 411 OUT PLARGE_INTEGER MsrValue 412 ); 413 414 NTSTATUS 415 NTAPI 416 KdpSysWriteMsr( 417 IN ULONG Msr, 418 IN PLARGE_INTEGER MsrValue 419 ); 420 421 // 422 // Bus 423 // 424 NTSTATUS 425 NTAPI 426 KdpSysReadBusData( 427 IN ULONG BusDataType, 428 IN ULONG BusNumber, 429 IN ULONG SlotNumber, 430 IN ULONG Offset, 431 IN PVOID Buffer, 432 IN ULONG Length, 433 OUT PULONG ActualLength 434 ); 435 436 NTSTATUS 437 NTAPI 438 KdpSysWriteBusData( 439 IN ULONG BusDataType, 440 IN ULONG BusNumber, 441 IN ULONG SlotNumber, 442 IN ULONG Offset, 443 IN PVOID Buffer, 444 IN ULONG Length, 445 OUT PULONG ActualLength 446 ); 447 448 // 449 // Control Space 450 // 451 NTSTATUS 452 NTAPI 453 KdpSysReadControlSpace( 454 IN ULONG Processor, 455 IN ULONG64 BaseAddress, 456 IN PVOID Buffer, 457 IN ULONG Length, 458 OUT PULONG ActualLength 459 ); 460 461 NTSTATUS 462 NTAPI 463 KdpSysWriteControlSpace( 464 IN ULONG Processor, 465 IN ULONG64 BaseAddress, 466 IN PVOID Buffer, 467 IN ULONG Length, 468 OUT PULONG ActualLength 469 ); 470 471 // 472 // I/O Space 473 // 474 NTSTATUS 475 NTAPI 476 KdpSysReadIoSpace( 477 IN ULONG InterfaceType, 478 IN ULONG BusNumber, 479 IN ULONG AddressSpace, 480 IN ULONG64 IoAddress, 481 IN PVOID DataValue, 482 IN ULONG DataSize, 483 OUT PULONG ActualDataSize 484 ); 485 486 NTSTATUS 487 NTAPI 488 KdpSysWriteIoSpace( 489 IN ULONG InterfaceType, 490 IN ULONG BusNumber, 491 IN ULONG AddressSpace, 492 IN ULONG64 IoAddress, 493 IN PVOID DataValue, 494 IN ULONG DataSize, 495 OUT PULONG ActualDataSize 496 ); 497 498 // 499 // Low Memory 500 // 501 NTSTATUS 502 NTAPI 503 KdpSysCheckLowMemory( 504 IN ULONG Flags 505 ); 506 507 // 508 // Internal routine for sending strings directly to the debugger 509 // 510 VOID 511 __cdecl 512 KdpDprintf( 513 IN PCHAR Format, 514 ... 515 ); 516 517 // 518 // Global KD Data 519 // 520 extern DBGKD_GET_VERSION64 KdVersionBlock; 521 extern KDDEBUGGER_DATA64 KdDebuggerDataBlock; 522 extern LIST_ENTRY KdpDebuggerDataListHead; 523 extern KSPIN_LOCK KdpDataSpinLock; 524 extern LARGE_INTEGER KdPerformanceCounterRate; 525 extern LARGE_INTEGER KdTimerStart; 526 extern ULONG KdDisableCount; 527 extern KD_CONTEXT KdpContext; 528 extern PKDEBUG_ROUTINE KiDebugRoutine; 529 extern PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine; 530 extern BOOLEAN KdBreakAfterSymbolLoad; 531 extern BOOLEAN KdPitchDebugger; 532 extern BOOLEAN KdAutoEnableOnEvent; 533 extern BOOLEAN KdBlockEnable; 534 extern BOOLEAN KdIgnoreUmExceptions; 535 extern BOOLEAN KdPreviouslyEnabled; 536 extern BOOLEAN KdpDebuggerStructuresInitialized; 537 extern BOOLEAN KdEnteredDebugger; 538 extern KDPC KdpTimeSlipDpc; 539 extern KTIMER KdpTimeSlipTimer; 540 extern WORK_QUEUE_ITEM KdpTimeSlipWorkItem; 541 extern LONG KdpTimeSlipPending; 542 extern PKEVENT KdpTimeSlipEvent; 543 extern KSPIN_LOCK KdpTimeSlipEventLock; 544 extern BOOLEAN KdpPortLocked; 545 extern BOOLEAN KdpControlCPressed; 546 extern BOOLEAN KdpContextSent; 547 extern KSPIN_LOCK KdpDebuggerLock; 548 extern LARGE_INTEGER KdTimerStop, KdTimerStart, KdTimerDifference; 549 extern ULONG KdComponentTableSize; 550 extern ULONG Kd_WIN2000_Mask; 551 extern PULONG KdComponentTable[104]; 552 extern CHAR KdpMessageBuffer[0x1000], KdpPathBuffer[0x1000]; 553 extern CHAR KdPrintDefaultCircularBuffer[KD_DEFAULT_LOG_BUFFER_SIZE]; 554 extern BREAKPOINT_ENTRY KdpBreakpointTable[KD_BREAKPOINT_MAX]; 555 extern KD_BREAKPOINT_TYPE KdpBreakpointInstruction; 556 extern BOOLEAN KdpOweBreakpoint; 557 extern BOOLEAN BreakpointsSuspended; 558 extern ULONG KdpNumInternalBreakpoints; 559 extern ULONG_PTR KdpCurrentSymbolStart, KdpCurrentSymbolEnd; 560 extern ULONG TraceDataBuffer[40]; 561 extern ULONG TraceDataBufferPosition; 562