Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

451 lines
12 KiB

  1. /*++
  2. Copyright (c) 1990-2001 Microsoft Corporation
  3. Module Name:
  4. kddata.c
  5. Abstract:
  6. This module contains global data for the portable kernel debgger.
  7. Author:
  8. Mark Lucovsky 1-Nov-1993
  9. Revision History:
  10. --*/
  11. #include "kdp.h"
  12. #include "ke.h"
  13. #include "pool.h"
  14. #include "stdio.h"
  15. //
  16. // Miscellaneous data from all over the kernel
  17. //
  18. extern PHANDLE_TABLE PspCidTable;
  19. extern LIST_ENTRY ExpSystemResourcesList;
  20. extern PPOOL_DESCRIPTOR ExpPagedPoolDescriptor;
  21. extern ULONG ExpNumberOfPagedPools;
  22. extern ULONG KeTimeIncrement;
  23. extern LIST_ENTRY KeBugCheckCallbackListHead;
  24. extern ULONG_PTR KiBugCheckData[];
  25. extern LIST_ENTRY IopErrorLogListHead;
  26. extern POBJECT_DIRECTORY ObpRootDirectoryObject;
  27. extern POBJECT_TYPE ObpTypeObjectType;
  28. extern PVOID MmSystemCacheStart;
  29. extern PVOID MmSystemCacheEnd;
  30. extern PVOID MmPfnDatabase;
  31. extern ULONG MmSystemPtesStart[];
  32. extern ULONG MmSystemPtesEnd[];
  33. extern ULONG MmSubsectionBase;
  34. extern ULONG MmNumberOfPagingFiles;
  35. extern ULONG MmLowestPhysicalPage;
  36. extern ULONG MmHighestPhysicalPage;
  37. extern PFN_COUNT MmNumberOfPhysicalPages;
  38. extern ULONG MmMaximumNonPagedPoolInBytes;
  39. extern PVOID MmNonPagedSystemStart;
  40. extern PVOID MmNonPagedPoolStart;
  41. extern PVOID MmNonPagedPoolEnd;
  42. extern PVOID MmPagedPoolStart;
  43. extern PVOID MmPagedPoolEnd;
  44. extern ULONG MmPagedPoolInfo[];
  45. extern ULONG MmSizeOfPagedPoolInBytes;
  46. extern ULONG MmTotalCommitLimit;
  47. extern ULONG MmTotalCommittedPages;
  48. extern ULONG MmSharedCommit;
  49. extern ULONG MmDriverCommit;
  50. extern ULONG MmProcessCommit;
  51. extern ULONG MmPagedPoolCommit;
  52. extern MMPFNLIST MmZeroedPageListHead;
  53. extern MMPFNLIST MmFreePageListHead;
  54. extern MMPFNLIST MmStandbyPageListHead;
  55. extern MMPFNLIST MmModifiedPageListHead;
  56. extern MMPFNLIST MmModifiedNoWritePageListHead;
  57. extern ULONG MmAvailablePages;
  58. extern LONG MmResidentAvailablePages;
  59. extern LIST_ENTRY MmLoadedUserImageList;
  60. extern PPOOL_TRACKER_TABLE PoolTrackTable;
  61. extern POOL_DESCRIPTOR NonPagedPoolDescriptor;
  62. extern PUNLOADED_DRIVERS MmUnloadedDrivers;
  63. extern ULONG MmLastUnloadedDriver;
  64. extern ULONG MmTriageActionTaken;
  65. extern ULONG MmSpecialPoolTag;
  66. extern LOGICAL KernelVerifier;
  67. extern PVOID MmVerifierData;
  68. extern PFN_NUMBER MmAllocatedNonPagedPool;
  69. extern SIZE_T MmPeakCommitment;
  70. extern SIZE_T MmTotalCommitLimitMaximum;
  71. extern ULONG_PTR MmSessionBase;
  72. extern ULONG_PTR MmSessionSize;
  73. #ifdef _IA64_
  74. extern PFN_NUMBER MmSystemParentTablePage;
  75. #endif
  76. //
  77. // These blocks of data needs to always be present because crashdumps
  78. // need the information. Otherwise, things like PAGE_SIZE are not available
  79. // in crashdumps, and extensions like !pool fail.
  80. //
  81. DBGKD_GET_VERSION64 KdVersionBlock = {
  82. 0,
  83. 0,
  84. DBGKD_64BIT_PROTOCOL_VERSION2,
  85. #if defined(_M_AMD64)
  86. DBGKD_VERS_FLAG_PTR64 | DBGKD_VERS_FLAG_DATA,
  87. IMAGE_FILE_MACHINE_AMD64,
  88. #elif defined(_M_IX86)
  89. DBGKD_VERS_FLAG_DATA,
  90. IMAGE_FILE_MACHINE_I386,
  91. #elif defined(_M_IA64)
  92. DBGKD_VERS_FLAG_HSS| DBGKD_VERS_FLAG_PTR64 | DBGKD_VERS_FLAG_DATA,
  93. IMAGE_FILE_MACHINE_IA64,
  94. #endif
  95. PACKET_TYPE_MAX,
  96. 0,
  97. 0,
  98. 0,
  99. 0,
  100. 0,
  101. 0,
  102. 0
  103. };
  104. KDDEBUGGER_DATA64 KdDebuggerDataBlock = {
  105. {0}, // DBGKD_DEBUG_DATA_HEADER Header;
  106. (ULONG64)0,
  107. (ULONG64)RtlpBreakWithStatusInstruction,
  108. (ULONG64)0,
  109. (USHORT)FIELD_OFFSET(KTHREAD, CallbackStack), // USHORT ThCallbackStack;
  110. #if defined(_AMD64_)
  111. (USHORT)FIELD_OFFSET(KCALLOUT_FRAME, CallbackStack), // USHORT NextCallback;
  112. #else
  113. (USHORT)FIELD_OFFSET(KCALLOUT_FRAME, CbStk), // USHORT NextCallback;
  114. #endif
  115. #if defined(_X86_)
  116. (USHORT)FIELD_OFFSET(KCALLOUT_FRAME, Ebp),
  117. #else
  118. (USHORT)0, // USHORT FramePointer;
  119. #endif
  120. #if defined(_X86PAE_) || defined(_AMD64_)
  121. (USHORT)1,
  122. #else
  123. (USHORT)0, // USHORT PaeEnabled;
  124. #endif
  125. (ULONG64)KiCallUserMode,
  126. (ULONG64)0,
  127. (ULONG64)&PsLoadedModuleList,
  128. (ULONG64)&PsActiveProcessHead,
  129. (ULONG64)&PspCidTable,
  130. (ULONG64)&ExpSystemResourcesList,
  131. (ULONG64)&ExpPagedPoolDescriptor,
  132. (ULONG64)&ExpNumberOfPagedPools,
  133. (ULONG64)&KeTimeIncrement,
  134. (ULONG64)&KeBugCheckCallbackListHead,
  135. (ULONG64)KiBugCheckData,
  136. (ULONG64)&IopErrorLogListHead,
  137. (ULONG64)&ObpRootDirectoryObject,
  138. (ULONG64)&ObpTypeObjectType,
  139. (ULONG64)&MmSystemCacheStart,
  140. (ULONG64)&MmSystemCacheEnd,
  141. (ULONG64)&MmSystemCacheWs,
  142. (ULONG64)&MmPfnDatabase,
  143. (ULONG64)MmSystemPtesStart,
  144. (ULONG64)MmSystemPtesEnd,
  145. (ULONG64)&MmSubsectionBase,
  146. (ULONG64)&MmNumberOfPagingFiles,
  147. (ULONG64)&MmLowestPhysicalPage,
  148. (ULONG64)&MmHighestPhysicalPage,
  149. (ULONG64)&MmNumberOfPhysicalPages,
  150. (ULONG64)&MmMaximumNonPagedPoolInBytes,
  151. (ULONG64)&MmNonPagedSystemStart,
  152. (ULONG64)&MmNonPagedPoolStart,
  153. (ULONG64)&MmNonPagedPoolEnd,
  154. (ULONG64)&MmPagedPoolStart,
  155. (ULONG64)&MmPagedPoolEnd,
  156. (ULONG64)&MmPagedPoolInfo,
  157. (ULONG64)PAGE_SIZE,
  158. (ULONG64)&MmSizeOfPagedPoolInBytes,
  159. (ULONG64)&MmTotalCommitLimit,
  160. (ULONG64)&MmTotalCommittedPages,
  161. (ULONG64)&MmSharedCommit,
  162. (ULONG64)&MmDriverCommit,
  163. (ULONG64)&MmProcessCommit,
  164. (ULONG64)&MmPagedPoolCommit,
  165. (ULONG64)0,
  166. (ULONG64)&MmZeroedPageListHead,
  167. (ULONG64)&MmFreePageListHead,
  168. (ULONG64)&MmStandbyPageListHead,
  169. (ULONG64)&MmModifiedPageListHead,
  170. (ULONG64)&MmModifiedNoWritePageListHead,
  171. (ULONG64)&MmAvailablePages,
  172. (ULONG64)&MmResidentAvailablePages,
  173. (ULONG64)&PoolTrackTable,
  174. (ULONG64)&NonPagedPoolDescriptor,
  175. (ULONG64)&MmHighestUserAddress,
  176. (ULONG64)&MmSystemRangeStart,
  177. (ULONG64)&MmUserProbeAddress,
  178. (ULONG64)KdPrintCircularBuffer,
  179. (ULONG64)KdPrintCircularBuffer+sizeof(KdPrintCircularBuffer),
  180. (ULONG64)&KdPrintWritePointer,
  181. (ULONG64)&KdPrintRolloverCount,
  182. (ULONG64)&MmLoadedUserImageList,
  183. // Nt 5.1 additions
  184. (ULONG64)NtBuildLab,
  185. #if defined(_IA64_)
  186. (ULONG64)KiNormalSystemCall,
  187. #else
  188. (ULONG64)0,
  189. #endif
  190. //
  191. (ULONG64)KiProcessorBlock,
  192. (ULONG64)&MmUnloadedDrivers,
  193. (ULONG64)&MmLastUnloadedDriver,
  194. (ULONG64)&MmTriageActionTaken,
  195. (ULONG64)&MmSpecialPoolTag,
  196. (ULONG64)&KernelVerifier,
  197. (ULONG64)&MmVerifierData,
  198. (ULONG64)&MmAllocatedNonPagedPool,
  199. (ULONG64)&MmPeakCommitment,
  200. (ULONG64)&MmTotalCommitLimitMaximum,
  201. (ULONG64)&CmNtCSDVersion,
  202. // Nt 5.1 additions
  203. (ULONG64)&MmPhysicalMemoryBlock,
  204. (ULONG64)&MmSessionBase,
  205. (ULONG64)&MmSessionSize,
  206. #ifdef _IA64_
  207. (ULONG64)&MmSystemParentTablePage,
  208. #else
  209. 0,
  210. #endif
  211. };
  212. //
  213. // Initialize the component name debug print filter table.
  214. //
  215. ULONG Kd_WIN2000_Mask = 1;
  216. #include "dpfilter.c"
  217. ULONG KdComponentTableSize = sizeof(KdComponentTable) / sizeof(PULONG);
  218. //
  219. // All dta from here on will be paged out if the kernel debugger is
  220. // not enabled.
  221. //
  222. #ifdef _X86_
  223. #ifdef ALLOC_PRAGMA
  224. #pragma data_seg("PAGEKD")
  225. #endif
  226. #endif // _X86_
  227. UCHAR KdPrintCircularBuffer[KDPRINTBUFFERSIZE] = {0};
  228. PUCHAR KdPrintWritePointer = KdPrintCircularBuffer;
  229. ULONG KdPrintRolloverCount = 0;
  230. BREAKPOINT_ENTRY KdpBreakpointTable[BREAKPOINT_TABLE_SIZE] = {0};
  231. // The message buffer needs to be 64-bit aligned.
  232. UCHAR DECLSPEC_ALIGN(8) KdpMessageBuffer[KDP_MESSAGE_BUFFER_SIZE] = {0};
  233. UCHAR KdpPathBuffer[KDP_MESSAGE_BUFFER_SIZE] = {0};
  234. DBGKD_INTERNAL_BREAKPOINT KdpInternalBPs[DBGKD_MAX_INTERNAL_BREAKPOINTS] = {0};
  235. KD_REMOTE_FILE KdpRemoteFiles[KD_MAX_REMOTE_FILES];
  236. LARGE_INTEGER KdPerformanceCounterRate = {0,0};
  237. LARGE_INTEGER KdTimerStart = {0,0} ;
  238. LARGE_INTEGER KdTimerStop = {0,0};
  239. LARGE_INTEGER KdTimerDifference = {0,0};
  240. ULONG_PTR KdpCurrentSymbolStart = 0;
  241. ULONG_PTR KdpCurrentSymbolEnd = 0;
  242. LONG KdpNextCallLevelChange = 0; // used only over returns to the debugger.
  243. ULONG_PTR KdSpecialCalls[DBGKD_MAX_SPECIAL_CALLS] = {0};
  244. ULONG KdNumberOfSpecialCalls = 0;
  245. ULONG_PTR InitialSP = 0;
  246. ULONG KdpNumInternalBreakpoints = 0;
  247. KTIMER InternalBreakpointTimer = {0};
  248. KDPC InternalBreakpointCheckDpc = {0};
  249. BOOLEAN KdpPortLocked = FALSE;
  250. DBGKD_TRACE_DATA TraceDataBuffer[TRACE_DATA_BUFFER_MAX_SIZE] = {0};
  251. ULONG TraceDataBufferPosition = 1; // Element # to write next
  252. // Recall elt 0 is a length
  253. TRACE_DATA_SYM TraceDataSyms[256] = {0};
  254. UCHAR NextTraceDataSym = 0; // what's the next one to be replaced
  255. UCHAR NumTraceDataSyms = 0; // how many are valid?
  256. ULONG IntBPsSkipping = 0; // number of exceptions that are being skipped
  257. // now
  258. BOOLEAN WatchStepOver = FALSE;
  259. BOOLEAN BreakPointTimerStarted = FALSE;
  260. PVOID WSOThread = NULL; // thread doing stepover
  261. ULONG_PTR WSOEsp = 0; // stack pointer of thread doing stepover (yes, we need it)
  262. ULONG WatchStepOverHandle = 0;
  263. ULONG_PTR WatchStepOverBreakAddr = 0; // where the WatchStepOver break is set
  264. BOOLEAN WatchStepOverSuspended = FALSE;
  265. ULONG InstructionsTraced = 0;
  266. BOOLEAN SymbolRecorded = FALSE;
  267. LONG CallLevelChange = 0;
  268. LONG_PTR oldpc = 0;
  269. BOOLEAN InstrCountInternal = FALSE; // Processing a non-COUNTONLY?
  270. BOOLEAN BreakpointsSuspended = FALSE;
  271. BOOLEAN KdpControlCPressed = FALSE;
  272. KDP_BREAKPOINT_TYPE KdpBreakpointInstruction = KDP_BREAKPOINT_VALUE;
  273. KD_CONTEXT KdpContext;
  274. LIST_ENTRY KdpDebuggerDataListHead = {NULL,NULL};
  275. //
  276. // !search support variables (page hit database)
  277. //
  278. PFN_NUMBER KdpSearchPageHits [SEARCH_PAGE_HIT_DATABASE_SIZE] = {0};
  279. ULONG KdpSearchPageHitOffsets [SEARCH_PAGE_HIT_DATABASE_SIZE] = {0};
  280. ULONG KdpSearchPageHitIndex = 0;
  281. LOGICAL KdpSearchInProgress = FALSE;
  282. PFN_NUMBER KdpSearchStartPageFrame = 0;
  283. PFN_NUMBER KdpSearchEndPageFrame = 0;
  284. ULONG_PTR KdpSearchAddressRangeStart = 0;
  285. ULONG_PTR KdpSearchAddressRangeEnd = 0;
  286. PFN_NUMBER KdpSearchPfnValue = 0;
  287. ULONG KdpSearchCheckPoint = KDP_SEARCH_SYMBOL_CHECK;
  288. BOOLEAN KdpDebuggerStructuresInitialized = FALSE ;
  289. #ifdef _X86_
  290. #ifdef ALLOC_PRAGMA
  291. #pragma data_seg()
  292. #endif
  293. #endif // _X86_
  294. KSPIN_LOCK KdpPrintSpinLock = 0;
  295. KSPIN_LOCK KdpDataSpinLock = 0;
  296. KSPIN_LOCK KdpTimeSlipEventLock = 0;
  297. PVOID KdpTimeSlipEvent = NULL;
  298. KDPC KdpTimeSlipDpc = {0};
  299. WORK_QUEUE_ITEM KdpTimeSlipWorkItem = {NULL};
  300. KTIMER KdpTimeSlipTimer = {0};
  301. ULONG KdpTimeSlipPending = 1;
  302. BOOLEAN KdDebuggerNotPresent = FALSE;
  303. BOOLEAN KdDebuggerEnabled = FALSE;
  304. BOOLEAN KdPitchDebugger = TRUE;
  305. BOOLEAN KdpOweBreakpoint = FALSE;
  306. ULONG KdEnteredDebugger = FALSE;
  307. #if defined(_AMD64_)
  308. //
  309. // No checks for now.
  310. //
  311. #elif defined(_X86_)
  312. C_ASSERT(sizeof(KPRCB) == X86_NT51_KPRCB_SIZE);
  313. C_ASSERT(sizeof(EPROCESS) == X86_NT51_EPROCESS_SIZE);
  314. C_ASSERT(FIELD_OFFSET(EPROCESS, Peb) == X86_PEB_IN_EPROCESS);
  315. #if !defined (PERF_DATA)
  316. C_ASSERT(sizeof(ETHREAD) == X86_ETHREAD_SIZE);
  317. #endif
  318. C_ASSERT(sizeof(CONTEXT) == sizeof(X86_NT5_CONTEXT));
  319. C_ASSERT(FIELD_OFFSET(KTHREAD, NextProcessor) == X86_NT51_KTHREAD_NEXTPROCESSOR_OFFSET);
  320. #elif defined(_IA64_)
  321. C_ASSERT(sizeof(KPRCB) == IA64_KPRCB_SIZE);
  322. C_ASSERT(sizeof(EPROCESS) == IA64_EPROCESS_SIZE);
  323. C_ASSERT(FIELD_OFFSET(EPROCESS, Peb) == IA64_2259_PEB_IN_EPROCESS);
  324. #if !defined (PERF_DATA)
  325. C_ASSERT(sizeof(ETHREAD) == IA64_ETHREAD_SIZE);
  326. #endif
  327. C_ASSERT(sizeof(CONTEXT) == sizeof(IA64_CONTEXT));
  328. C_ASSERT(FIELD_OFFSET(KTHREAD, NextProcessor) == IA64_KTHREAD_NEXTPROCESSOR_OFFSET);
  329. #include <ia64\miia64.h>
  330. C_ASSERT(IA64_PAGE_SIZE == PAGE_SIZE);
  331. C_ASSERT(IA64_PAGE_SHIFT == PAGE_SHIFT);
  332. C_ASSERT(IA64_MM_PTE_TRANSITION_MASK == MM_PTE_TRANSITION_MASK);
  333. C_ASSERT(IA64_MM_PTE_PROTOTYPE_MASK == MM_PTE_PROTOTYPE_MASK);
  334. #else
  335. #error "no target architecture"
  336. #endif