Leaked source code of windows server 2003
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.

2084 lines
74 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Abstraction of target-specific information.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999-2002.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __TARGET_HPP__
  9. #define __TARGET_HPP__
  10. #define INVALID_PRODUCT_TYPE 0
  11. #define SELECTOR_CACHE_LENGTH 6
  12. typedef struct _SEL_CACHE_ENTRY
  13. {
  14. struct _SEL_CACHE_ENTRY* Younger;
  15. struct _SEL_CACHE_ENTRY* Older;
  16. ULONG Processor;
  17. ULONG Selector;
  18. DESCRIPTOR64 Desc;
  19. } SEL_CACHE_ENTRY;
  20. //----------------------------------------------------------------------------
  21. //
  22. // Target configuration information.
  23. //
  24. //----------------------------------------------------------------------------
  25. #define IS_KERNEL_TARGET(Target) \
  26. ((Target) && (Target)->m_Class == DEBUG_CLASS_KERNEL)
  27. #define IS_USER_TARGET(Target) \
  28. ((Target) && (Target)->m_Class == DEBUG_CLASS_USER_WINDOWS)
  29. #define IS_CONN_KERNEL_TARGET(Target) \
  30. (IS_KERNEL_TARGET(Target) && \
  31. (Target)->m_ClassQualifier == DEBUG_KERNEL_CONNECTION)
  32. #define IS_LOCAL_KERNEL_TARGET(Target) \
  33. (IS_KERNEL_TARGET(Target) && \
  34. (Target)->m_ClassQualifier == DEBUG_KERNEL_LOCAL)
  35. #define IS_EXDI_KERNEL_TARGET(Target) \
  36. (IS_KERNEL_TARGET(Target) && \
  37. (Target)->m_ClassQualifier == DEBUG_KERNEL_EXDI_DRIVER)
  38. #define IS_LIVE_USER_TARGET(Target) \
  39. (IS_USER_TARGET(Target) && !IS_DUMP_TARGET(Target))
  40. #define IS_LIVE_KERNEL_TARGET(Target) \
  41. (IS_KERNEL_TARGET(Target) && !IS_DUMP_TARGET(Target))
  42. // Local kernels do not need caching. Anything else does.
  43. #define IS_REMOTE_KERNEL_TARGET(Target) \
  44. (IS_LIVE_KERNEL_TARGET(Target) && \
  45. (Target)->m_ClassQualifier != DEBUG_KERNEL_LOCAL)
  46. #define IS_MACHINE_SET(Target) \
  47. ((Target) && (Target)->m_MachinesInitialized)
  48. // Checks whether the debuggee is in a state where it
  49. // can be examined. This requires that the debuggee is known
  50. // and paused so that its state is available.
  51. #define IS_CUR_MACHINE_ACCESSIBLE() \
  52. (IS_MACHINE_SET(g_Target) && !IS_RUNNING(g_CmdState) && \
  53. g_Process && g_Thread && g_Machine)
  54. // Further restricts the check to just context state as a
  55. // local kernel session can examine memory and therefore is
  56. // accessible but it does not have a context.
  57. #define IS_CUR_CONTEXT_ACCESSIBLE() \
  58. (IS_CUR_MACHINE_ACCESSIBLE() && !IS_LOCAL_KERNEL_TARGET(g_Target))
  59. // Event variable checks do not check g_CmdState as they
  60. // may be used in the middle of initializing the regular state.
  61. #define IS_EVENT_MACHINE_ACCESSIBLE() \
  62. (IS_MACHINE_SET(g_EventTarget) && \
  63. g_EventProcess && g_EventThread && g_EventMachine)
  64. #define IS_EVENT_CONTEXT_ACCESSIBLE() \
  65. (IS_EVENT_MACHINE_ACCESSIBLE() && !IS_LOCAL_KERNEL_TARGET(g_EventTarget))
  66. // Simpler context check for code which may be on the suspend/
  67. // resume path and therefore may be in the middle of initializing
  68. // the variables that IS_CONTEXT_ACCESSIBLE checks. This
  69. // macro just checks whether it's possible to get any
  70. // context information.
  71. #define IS_CONTEXT_POSSIBLE(Target) \
  72. ((Target) && !IS_LOCAL_KERNEL_TARGET(Target) && \
  73. (Target)->m_RegContextThread != NULL)
  74. //
  75. // System version is an internal abstraction of build numbers
  76. // and product types. The only requirement is that within
  77. // a specific system family the numbers increase for newer
  78. // systems.
  79. //
  80. // Most of the debugger code is built around NT system versions
  81. // so there's a SystemVersion variable which is always an
  82. // NT system version. The ActualSystemVersion contains the
  83. // true system version which gets mapped into a compatible NT
  84. // system version for SystemVersion.
  85. //
  86. enum
  87. {
  88. SVER_INVALID = 0,
  89. NT_SVER_START = 4 * 1024,
  90. NT_SVER_NT4,
  91. NT_SVER_W2K_RC3,
  92. NT_SVER_W2K,
  93. NT_SVER_XP,
  94. NT_SVER_NET_SERVER,
  95. NT_SVER_LONGHORN,
  96. NT_SVER_END,
  97. W9X_SVER_START = 8 * 1024,
  98. W9X_SVER_W95,
  99. W9X_SVER_W98,
  100. W9X_SVER_W98SE,
  101. W9X_SVER_WME,
  102. W9X_SVER_END,
  103. XBOX_SVER_START = 12 * 1024,
  104. XBOX_SVER_1,
  105. XBOX_SVER_END,
  106. BIG_SVER_START = 16 * 1024,
  107. BIG_SVER_1,
  108. BIG_SVER_END,
  109. EXDI_SVER_START = 20 * 1024,
  110. EXDI_SVER_1,
  111. EXDI_SVER_END,
  112. NTBD_SVER_START = 24 * 1024,
  113. NTBD_SVER_XP,
  114. NTBD_SVER_END,
  115. EFI_SVER_START = 28 * 1024,
  116. EFI_SVER_1,
  117. EFI_SVER_END,
  118. WCE_SVER_START = 32 * 1024,
  119. WCE_SVER_CE,
  120. WCE_SVER_END,
  121. };
  122. //----------------------------------------------------------------------------
  123. //
  124. // Macros for using the implicit target/system/process/thread/machine
  125. // globals in common target calls.
  126. //
  127. //----------------------------------------------------------------------------
  128. #define CurReadVirtual(Offset, Buffer, BufferSize, Read) \
  129. g_Target->ReadVirtual(g_Process, Offset, Buffer, BufferSize, Read)
  130. #define CurReadAllVirtual(Offset, Buffer, BufferSize) \
  131. g_Target->ReadAllVirtual(g_Process, Offset, Buffer, BufferSize)
  132. //----------------------------------------------------------------------------
  133. //
  134. // This class abstracts processing of target-class-dependent
  135. // information. g_Target is set to the appropriate implementation
  136. // once the class of target is known.
  137. //
  138. // In theory a single TargetInfo could handle multiple systems
  139. // if the systems are all similar. For example, a single user-mode
  140. // TargetInfo could be used for multiple user-mode systems
  141. // if there was a separate list of systems. This doesn't
  142. // enable any functionality, though, and adds significant
  143. // complexity as now a separate list has to be maintained and
  144. // more information has to be passed around to identify both
  145. // system and target. Instead a TargetInfo is created per
  146. // system and the TargetInfo has both the role of abstracting
  147. // manipulation of the debuggee and keeping global information
  148. // about the debuggee.
  149. //
  150. //----------------------------------------------------------------------------
  151. // Hard-coded type information for machine and platform version.
  152. typedef struct _SYSTEM_TYPE_INFO
  153. {
  154. ULONG64 TriagePrcbOffset;
  155. // Size of the native context for the target machine.
  156. ULONG SizeTargetContext;
  157. // Offset of the flags ULONG in the native context.
  158. ULONG OffsetTargetContextFlags;
  159. // Control space offset for special registers.
  160. ULONG OffsetSpecialRegisters;
  161. ULONG SizeControlReport;
  162. ULONG SizeKspecialRegisters;
  163. // Size of the debugger's *_THREAD partial structure.
  164. ULONG SizePageFrameNumber;
  165. ULONG SizePte;
  166. ULONG64 SharedUserDataOffset;
  167. ULONG64 UmSharedUserDataOffset;
  168. ULONG64 UmSharedSysCallOffset;
  169. ULONG UmSharedSysCallSize;
  170. ULONG SizeDynamicFunctionTable;
  171. ULONG SizeRuntimeFunction;
  172. } SYSTEM_TYPE_INFO, *PSYSTEM_TYPE_INFO;
  173. enum WAIT_INIT_TYPE
  174. {
  175. WINIT_FIRST,
  176. WINIT_NOT_FIRST,
  177. WINIT_TEST
  178. };
  179. class TargetInfo
  180. {
  181. public:
  182. TargetInfo(ULONG Class, ULONG Qual, BOOL DynamicEvents);
  183. virtual ~TargetInfo(void);
  184. ULONG m_Class;
  185. ULONG m_ClassQualifier;
  186. TargetInfo* m_Next;
  187. void Link(void);
  188. void Unlink(void);
  189. //
  190. // Event information.
  191. //
  192. ULONG m_NumEvents;
  193. ULONG m_EventIndex;
  194. ULONG m_NextEventIndex;
  195. ULONG m_FirstWait:1;
  196. ULONG m_EventPossible:1;
  197. ULONG m_DynamicEvents:1;
  198. ULONG m_BreakInMessage:1;
  199. ULONG m_WaitTimeBase;
  200. //
  201. // Debuggee global information.
  202. //
  203. ULONG m_NumProcesses;
  204. ProcessInfo* m_ProcessHead;
  205. ProcessInfo* m_CurrentProcess;
  206. ULONG m_AllProcessFlags;
  207. ULONG m_TotalNumberThreads;
  208. ULONG m_MaxThreadsInProcess;
  209. ULONG m_UserId;
  210. ULONG m_SystemId;
  211. ULONG m_Exited:1;
  212. ULONG m_DeferContinueEvent:1;
  213. ULONG m_BreakInTimeout:1;
  214. ULONG m_Notify:1;
  215. ULONG m_ProcessesAdded:1;
  216. SYSTEM_TYPE_INFO m_TypeInfo;
  217. ULONG m_SystemVersion;
  218. ULONG m_ActualSystemVersion;
  219. ULONG m_BuildNumber;
  220. ULONG m_CheckedBuild;
  221. ULONG m_PlatformId;
  222. char m_ServicePackString[MAX_PATH];
  223. ULONG m_ServicePackNumber;
  224. char m_BuildLabName[272];
  225. ULONG m_ProductType;
  226. ULONG m_SuiteMask;
  227. ULONG m_NumProcessors;
  228. ULONG m_MachineType;
  229. // Leave one extra slot at the end so indexing
  230. // MACHIDX_COUNT returns NULL for the undefined case.
  231. MachineInfo* m_Machines[MACHIDX_COUNT + 1];
  232. MachineInfo* m_Machine;
  233. ULONG m_EffMachineType;
  234. MachineIndex m_EffMachineIndex;
  235. MachineInfo* m_EffMachine;
  236. DEBUG_PROCESSOR_IDENTIFICATION_ALL m_FirstProcessorId;
  237. BOOL m_MachinesInitialized;
  238. ThreadInfo* m_RegContextThread;
  239. ULONG m_RegContextProcessor;
  240. ULONG64 m_SystemRangeStart;
  241. ULONG64 m_SystemCallVirtualAddress;
  242. KDDEBUGGER_DATA64 m_KdDebuggerData;
  243. DBGKD_GET_VERSION64 m_KdVersion;
  244. ULONG64 m_KdDebuggerDataOffset;
  245. BOOL m_KdApi64;
  246. PhysicalMemoryCache m_PhysicalCache;
  247. PSTR m_ExtensionSearchPath;
  248. ULONG64 m_ImplicitProcessData;
  249. BOOL m_ImplicitProcessDataIsDefault;
  250. ThreadInfo* m_ImplicitProcessDataThread;
  251. virtual void ResetSystemInfo(void);
  252. virtual void DeleteSystemInfo(void);
  253. HRESULT ReadKdDataBlock(ProcessInfo* Process);
  254. HRESULT QueryKernelInfo(ThreadInfo* Thread, BOOL LoadImage);
  255. void SetNtCsdVersion(ULONG Build, ULONG CsdVersion);
  256. void SetKernel32BuildString(ProcessInfo* Process);
  257. HRESULT CreateVirtualProcess(ULONG Threads);
  258. ProcessInfo* FindProcessByUserId(ULONG Id);
  259. ProcessInfo* FindProcessBySystemId(ULONG Id);
  260. ProcessInfo* FindProcessByHandle(ULONG64 Handle);
  261. void InsertProcess(ProcessInfo* Process);
  262. void RemoveProcess(ProcessInfo* Process);
  263. void ResetAllProcessInfo(void);
  264. void AddThreadToAllProcessInfo(ProcessInfo* Process,
  265. ThreadInfo* Thread);
  266. void RemoveThreadFromAllProcessInfo(ProcessInfo* Process,
  267. ThreadInfo* Thread)
  268. {
  269. UNREFERENCED_PARAMETER(Process);
  270. UNREFERENCED_PARAMETER(Thread);
  271. ResetAllProcessInfo();
  272. }
  273. BOOL DeleteExitedInfos(void);
  274. void InvalidateMemoryCaches(BOOL VirtOnly);
  275. void SetSystemVersionAndBuild(ULONG Build, ULONG PlatformId);
  276. HRESULT InitializeForProcessor(void);
  277. HRESULT InitializeMachines(ULONG MachineType);
  278. void SetEffMachine(ULONG Machine, BOOL Notify);
  279. void ChangeRegContext(ThreadInfo* Thread);
  280. void FlushRegContext(void);
  281. BOOL AnySystemProcesses(BOOL LocalOnly);
  282. void OutputProcessesAndThreads(PSTR Title);
  283. void OutputProcessInfo(ProcessInfo* Match);
  284. void OutputVersion(void);
  285. void OutputTime(void);
  286. void AddSpecificExtensions(void);
  287. void PrepareForExecution(void);
  288. //
  289. // Pure abstraction methods.
  290. // Unless otherwise indicated, base implementations give
  291. // an error message and return E_UNEXPECTED.
  292. //
  293. // Base implementation must be called.
  294. virtual HRESULT Initialize(void);
  295. virtual HRESULT GetDescription(PSTR Buffer, ULONG BufferLen,
  296. PULONG DescLen) = 0;
  297. // Called when a debuggee has reset but the session is
  298. // still active, such as a reboot during kernel debugging.
  299. virtual void DebuggeeReset(ULONG Reason, BOOL FromEvent);
  300. // Determines the next byte offset and next page offset
  301. // that might have different validity than the given offset.
  302. virtual void NearestDifferentlyValidOffsets(ULONG64 Offset,
  303. PULONG64 NextOffset,
  304. PULONG64 NextPage);
  305. virtual HRESULT ReadVirtual(
  306. IN ProcessInfo* Process,
  307. IN ULONG64 Offset,
  308. OUT PVOID Buffer,
  309. IN ULONG BufferSize,
  310. OUT OPTIONAL PULONG BytesRead
  311. );
  312. virtual HRESULT WriteVirtual(
  313. IN ProcessInfo* Process,
  314. IN ULONG64 Offset,
  315. IN PVOID Buffer,
  316. IN ULONG BufferSize,
  317. OUT OPTIONAL PULONG BytesWritten
  318. );
  319. // Base implementation layers on ReadVirtual.
  320. virtual HRESULT SearchVirtual(
  321. IN ProcessInfo* Process,
  322. IN ULONG64 Offset,
  323. IN ULONG64 Length,
  324. IN PVOID Pattern,
  325. IN ULONG PatternSize,
  326. IN ULONG PatternGranularity,
  327. OUT PULONG64 MatchOffset
  328. );
  329. // Base implementations just call Read/WriteVirtual.
  330. virtual HRESULT ReadVirtualUncached(
  331. IN ProcessInfo* Process,
  332. IN ULONG64 Offset,
  333. OUT PVOID Buffer,
  334. IN ULONG BufferSize,
  335. OUT OPTIONAL PULONG BytesRead
  336. );
  337. virtual HRESULT WriteVirtualUncached(
  338. IN ProcessInfo* Process,
  339. IN ULONG64 Offset,
  340. IN PVOID Buffer,
  341. IN ULONG BufferSize,
  342. OUT OPTIONAL PULONG BytesWritten
  343. );
  344. virtual HRESULT ReadPhysical(
  345. IN ULONG64 Offset,
  346. OUT PVOID Buffer,
  347. IN ULONG BufferSize,
  348. IN ULONG Flags,
  349. OUT OPTIONAL PULONG BytesRead
  350. );
  351. virtual HRESULT WritePhysical(
  352. IN ULONG64 Offset,
  353. IN PVOID Buffer,
  354. IN ULONG BufferSize,
  355. IN ULONG Flags,
  356. OUT OPTIONAL PULONG BytesWritten
  357. );
  358. // Base implementation layers on ReadPhysical.
  359. virtual HRESULT PointerSearchPhysical(
  360. IN ULONG64 Offset,
  361. IN ULONG64 Length,
  362. IN ULONG64 PointerMin,
  363. IN ULONG64 PointerMax,
  364. IN ULONG Flags,
  365. OUT PULONG64 MatchOffsets,
  366. IN ULONG MatchOffsetsSize,
  367. OUT PULONG MatchOffsetsCount
  368. );
  369. // Base implementations just call Read/WritePhysical.
  370. virtual HRESULT ReadPhysicalUncached(
  371. IN ULONG64 Offset,
  372. OUT PVOID Buffer,
  373. IN ULONG BufferSize,
  374. IN ULONG Flags,
  375. OUT OPTIONAL PULONG BytesRead
  376. );
  377. virtual HRESULT WritePhysicalUncached(
  378. IN ULONG64 Offset,
  379. IN PVOID Buffer,
  380. IN ULONG BufferSize,
  381. IN ULONG Flags,
  382. OUT OPTIONAL PULONG BytesWritten
  383. );
  384. virtual HRESULT ReadControl(
  385. IN ULONG Processor,
  386. IN ULONG64 Offset,
  387. OUT PVOID Buffer,
  388. IN ULONG BufferSize,
  389. OUT OPTIONAL PULONG BytesRead
  390. );
  391. virtual HRESULT WriteControl(
  392. IN ULONG Processor,
  393. IN ULONG64 Offset,
  394. IN PVOID Buffer,
  395. IN ULONG BufferSize,
  396. OUT OPTIONAL PULONG BytesWritten
  397. );
  398. virtual HRESULT ReadIo(
  399. IN ULONG InterfaceType,
  400. IN ULONG BusNumber,
  401. IN ULONG AddressSpace,
  402. IN ULONG64 Offset,
  403. OUT PVOID Buffer,
  404. IN ULONG BufferSize,
  405. OUT OPTIONAL PULONG BytesRead
  406. );
  407. virtual HRESULT WriteIo(
  408. IN ULONG InterfaceType,
  409. IN ULONG BusNumber,
  410. IN ULONG AddressSpace,
  411. IN ULONG64 Offset,
  412. IN PVOID Buffer,
  413. IN ULONG BufferSize,
  414. OUT OPTIONAL PULONG BytesWritten
  415. );
  416. virtual HRESULT ReadMsr(
  417. IN ULONG Msr,
  418. OUT PULONG64 Value
  419. );
  420. virtual HRESULT WriteMsr(
  421. IN ULONG Msr,
  422. IN ULONG64 Value
  423. );
  424. virtual HRESULT ReadBusData(
  425. IN ULONG BusDataType,
  426. IN ULONG BusNumber,
  427. IN ULONG SlotNumber,
  428. IN ULONG Offset,
  429. OUT PVOID Buffer,
  430. IN ULONG BufferSize,
  431. OUT OPTIONAL PULONG BytesRead
  432. );
  433. virtual HRESULT WriteBusData(
  434. IN ULONG BusDataType,
  435. IN ULONG BusNumber,
  436. IN ULONG SlotNumber,
  437. IN ULONG Offset,
  438. IN PVOID Buffer,
  439. IN ULONG BufferSize,
  440. OUT OPTIONAL PULONG BytesWritten
  441. );
  442. virtual HRESULT GetProcessorSystemDataOffset(
  443. IN ULONG Processor,
  444. IN ULONG Index,
  445. OUT PULONG64 Offset
  446. );
  447. virtual HRESULT CheckLowMemory(
  448. );
  449. virtual HRESULT ReadHandleData(
  450. IN ProcessInfo* Process,
  451. IN ULONG64 Handle,
  452. IN ULONG DataType,
  453. OUT OPTIONAL PVOID Buffer,
  454. IN ULONG BufferSize,
  455. OUT OPTIONAL PULONG DataSize
  456. );
  457. // Base implementations layer on WriteVirtual/Physical.
  458. virtual HRESULT FillVirtual(
  459. THIS_
  460. IN ProcessInfo* Process,
  461. IN ULONG64 Start,
  462. IN ULONG Size,
  463. IN PVOID Pattern,
  464. IN ULONG PatternSize,
  465. OUT PULONG Filled
  466. );
  467. virtual HRESULT FillPhysical(
  468. THIS_
  469. IN ULONG64 Start,
  470. IN ULONG Size,
  471. IN PVOID Pattern,
  472. IN ULONG PatternSize,
  473. OUT PULONG Filled
  474. );
  475. virtual HRESULT GetProcessorId(
  476. ULONG Processor,
  477. PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id
  478. );
  479. virtual HRESULT GetProcessorSpeed(
  480. ULONG Processor,
  481. PULONG Speed
  482. );
  483. virtual HRESULT GetGenericProcessorFeatures(
  484. ULONG Processor,
  485. PULONG64 Features,
  486. ULONG FeaturesSize,
  487. PULONG Used
  488. );
  489. virtual HRESULT GetSpecificProcessorFeatures(
  490. ULONG Processor,
  491. PULONG64 Features,
  492. ULONG FeaturesSize,
  493. PULONG Used
  494. );
  495. // Generic calling code assumes that tagged data can
  496. // be represented by a linear space with an overall
  497. // DUMP_BLOB_FILE_HEADER at the base offset and followed
  498. // by all existing blob headers and their data.
  499. // Base implementations fail.
  500. virtual HRESULT GetTaggedBaseOffset(PULONG64 Offset);
  501. virtual HRESULT ReadTagged(ULONG64 Offset, PVOID Buffer, ULONG BufferSize);
  502. // Base implementation silently fails as many targets do
  503. // not support this.
  504. virtual HRESULT ReadPageFile(ULONG PfIndex, ULONG64 PfOffset,
  505. PVOID Buffer, ULONG Size);
  506. virtual HRESULT GetUnloadedModuleListHead(ProcessInfo* Process,
  507. PULONG64 Head);
  508. virtual HRESULT GetFunctionTableListHead(ProcessInfo* Process,
  509. PULONG64 Head);
  510. virtual PVOID FindDynamicFunctionEntry(ProcessInfo* Process,
  511. ULONG64 Address);
  512. virtual ULONG64 GetDynamicFunctionTableBase(ProcessInfo* Process,
  513. ULONG64 Address);
  514. virtual HRESULT ReadOutOfProcessDynamicFunctionTable(ProcessInfo* Process,
  515. PWSTR Dll,
  516. ULONG64 Table,
  517. PULONG TableSize,
  518. PVOID* TableData);
  519. static PVOID CALLBACK DynamicFunctionTableCallback(HANDLE Process,
  520. ULONG64 Address,
  521. ULONG64 Context);
  522. virtual HRESULT EnumFunctionTables(IN ProcessInfo* Process,
  523. IN OUT PULONG64 Start,
  524. IN OUT PULONG64 Handle,
  525. OUT PULONG64 MinAddress,
  526. OUT PULONG64 MaxAddress,
  527. OUT PULONG64 BaseAddress,
  528. OUT PULONG EntryCount,
  529. OUT PCROSS_PLATFORM_DYNAMIC_FUNCTION_TABLE RawTable,
  530. OUT PVOID* RawEntries);
  531. virtual HRESULT GetTargetContext(
  532. ULONG64 Thread,
  533. PVOID Context
  534. );
  535. virtual HRESULT SetTargetContext(
  536. ULONG64 Thread,
  537. PVOID Context
  538. );
  539. // Retrieves segment register descriptors if they are available
  540. // directly. Invalid descriptors may be returned, indicating
  541. // either segment registers aren't supported or that the
  542. // descriptors must be looked up in descriptor tables.
  543. // Base implementation returns invalid descriptors.
  544. virtual HRESULT GetTargetSegRegDescriptors(ULONG64 Thread,
  545. ULONG Start, ULONG Count,
  546. PDESCRIPTOR64 Descs);
  547. // Base implementations call Read/WriteSpecialRegisters.
  548. virtual HRESULT GetTargetSpecialRegisters
  549. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  550. virtual HRESULT SetTargetSpecialRegisters
  551. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  552. // Called when the current context state is being
  553. // discarded so that caches can be flushed.
  554. // Base implementation does nothing.
  555. virtual void InvalidateTargetContext(void);
  556. virtual HRESULT GetThreadIdByProcessor(
  557. IN ULONG Processor,
  558. OUT PULONG Id
  559. );
  560. virtual HRESULT GetThreadStartOffset(ThreadInfo* Thread,
  561. PULONG64 StartOffset);
  562. // Base implementations do nothing.
  563. virtual void SuspendThreads(void);
  564. virtual BOOL ResumeThreads(void);
  565. // This method takes both a ThreadInfo* and a "handle"
  566. // to make things simpler for the kernel thread-to-processor
  567. // mapping. If Thread is NULL processor must be a processor
  568. // index in kernel mode or a thread handle in user mode.
  569. virtual HRESULT GetThreadInfoDataOffset(ThreadInfo* Thread,
  570. ULONG64 ThreadHandle,
  571. PULONG64 Offset);
  572. // In theory this method should take a ProcessInfo*.
  573. // Due to the current kernel process and thread structure
  574. // where there's only a kernel process and threads per
  575. // processor such a call would be useless in kernel mode.
  576. // Instead it allows you to either get the process data
  577. // for a thread of that process or get the process data
  578. // from a thread data.
  579. virtual HRESULT GetProcessInfoDataOffset(ThreadInfo* Thread,
  580. ULONG Processor,
  581. ULONG64 ThreadData,
  582. PULONG64 Offset);
  583. virtual HRESULT GetThreadInfoTeb(ThreadInfo* Thread,
  584. ULONG Processor,
  585. ULONG64 ThreadData,
  586. PULONG64 Offset);
  587. virtual HRESULT GetProcessInfoPeb(ThreadInfo* Thread,
  588. ULONG Processor,
  589. ULONG64 ThreadData,
  590. PULONG64 Offset);
  591. // This is on target rather than machine since it has
  592. // both user and kernel variations and the implementations
  593. // don't have much processor-specific code in them.
  594. virtual HRESULT GetSelDescriptor(ThreadInfo* Thread,
  595. MachineInfo* Machine,
  596. ULONG Selector,
  597. PDESCRIPTOR64 Desc);
  598. virtual HRESULT SwitchProcessors(ULONG Processor);
  599. virtual HRESULT SwitchToTarget(TargetInfo* From);
  600. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  601. virtual HRESULT ReadBugCheckData(PULONG Code, ULONG64 Args[4]);
  602. virtual ModuleInfo* GetModuleInfo(BOOL UserMode);
  603. virtual UnloadedModuleInfo* GetUnloadedModuleInfo(void);
  604. // Image can be identified either by its path or base address.
  605. virtual HRESULT GetImageVersionInformation(ProcessInfo* Process,
  606. PCSTR ImagePath,
  607. ULONG64 ImageBase,
  608. PCSTR Item,
  609. PVOID Buffer, ULONG BufferSize,
  610. PULONG VerInfoSize);
  611. HRESULT Reload(ThreadInfo* Thread,
  612. PCSTR Args, PCSTR* ArgsRet);
  613. virtual HRESULT GetExceptionContext(PCROSS_PLATFORM_CONTEXT Context);
  614. virtual ULONG64 GetCurrentTimeDateN(void);
  615. virtual ULONG64 GetCurrentSystemUpTimeN(void);
  616. virtual ULONG64 GetProcessUpTimeN(ProcessInfo* Process);
  617. virtual HRESULT GetProcessTimes(ProcessInfo* Process,
  618. PULONG64 Create,
  619. PULONG64 Exit,
  620. PULONG64 Kernel,
  621. PULONG64 User);
  622. virtual HRESULT GetThreadTimes(ThreadInfo* Thread,
  623. PULONG64 Create,
  624. PULONG64 Exit,
  625. PULONG64 Kernel,
  626. PULONG64 User);
  627. virtual HRESULT GetProductInfo(PULONG ProductType, PULONG SuiteMask);
  628. // Base implementation does nothing.
  629. virtual HRESULT InitializeTargetControlledStepping(void);
  630. virtual void InitializeWatchTrace(void);
  631. virtual void ProcessWatchTraceEvent(PDBGKD_TRACE_DATA TraceData,
  632. PADDR PcAddr,
  633. PBOOL StepOver);
  634. // Base implementation returns defaults.
  635. virtual HRESULT GetEventIndexDescription(IN ULONG Index,
  636. IN ULONG Which,
  637. IN OPTIONAL PSTR Buffer,
  638. IN ULONG BufferSize,
  639. OUT OPTIONAL PULONG DescSize);
  640. virtual HRESULT WaitInitialize(ULONG Flags,
  641. ULONG Timeout,
  642. WAIT_INIT_TYPE Type,
  643. PULONG DesiredTimeout);
  644. virtual HRESULT ReleaseLastEvent(ULONG ContinueStatus);
  645. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout,
  646. ULONG ElapsedTime, PULONG EventStatus);
  647. virtual HRESULT RequestBreakIn(void);
  648. virtual HRESULT ClearBreakIn(void);
  649. virtual HRESULT Reboot(void);
  650. virtual HRESULT Crash(ULONG Code);
  651. virtual HRESULT BeginInsertingBreakpoints(void);
  652. virtual HRESULT InsertCodeBreakpoint(ProcessInfo* Process,
  653. class MachineInfo* Machine,
  654. PADDR Addr,
  655. ULONG InstrFlags,
  656. PUCHAR StorageSpace);
  657. virtual HRESULT InsertDataBreakpoint(ProcessInfo* Process,
  658. ThreadInfo* Thread,
  659. class MachineInfo* Machine,
  660. PADDR Addr,
  661. ULONG Size,
  662. ULONG AccessType,
  663. PUCHAR StorageSpace);
  664. virtual void EndInsertingBreakpoints(void);
  665. virtual void BeginRemovingBreakpoints(void);
  666. virtual HRESULT RemoveCodeBreakpoint(ProcessInfo* Process,
  667. class MachineInfo* Machine,
  668. PADDR Addr,
  669. ULONG InstrFlags,
  670. PUCHAR StorageSpace);
  671. virtual HRESULT RemoveDataBreakpoint(ProcessInfo* Process,
  672. ThreadInfo* Thread,
  673. class MachineInfo* Machine,
  674. PADDR Addr,
  675. ULONG Size,
  676. ULONG AccessType,
  677. PUCHAR StorageSpace);
  678. virtual void EndRemovingBreakpoints(void);
  679. virtual HRESULT RemoveAllDataBreakpoints(ProcessInfo* Process);
  680. // Base implementation does nothing.
  681. virtual HRESULT RemoveAllTargetBreakpoints(void);
  682. virtual HRESULT IsDataBreakpointHit(ThreadInfo* Thread,
  683. PADDR Addr,
  684. ULONG Size,
  685. ULONG AccessType,
  686. PUCHAR StorageSpace);
  687. virtual HRESULT InsertTargetCountBreakpoint(PADDR Addr,
  688. ULONG Flags);
  689. virtual HRESULT RemoveTargetCountBreakpoint(PADDR Addr);
  690. virtual HRESULT QueryTargetCountBreakpoint(PADDR Addr,
  691. PULONG Flags,
  692. PULONG Calls,
  693. PULONG MinInstr,
  694. PULONG MaxInstr,
  695. PULONG TotInstr,
  696. PULONG MaxCps);
  697. // Returns information similar to VirtualQueryEx for
  698. // user-mode targets. Used when writing dump files.
  699. virtual HRESULT QueryMemoryRegion(ProcessInfo* Process,
  700. PULONG64 Handle,
  701. BOOL HandleIsOffset,
  702. PMEMORY_BASIC_INFORMATION64 Info);
  703. // Returns information about the kind of memory the
  704. // given address refers to.
  705. // Base implementation returns rwx with process for
  706. // user-mode and kernel for kernel mode. In other words,
  707. // the least restrictive settings.
  708. virtual HRESULT QueryAddressInformation(ProcessInfo* Process,
  709. ULONG64 Address, ULONG InSpace,
  710. PULONG OutSpace, PULONG OutFlags);
  711. // Base implementations fail.
  712. virtual HRESULT StartAttachProcess(ULONG ProcessId,
  713. ULONG AttachFlags,
  714. PPENDING_PROCESS* Pending);
  715. virtual HRESULT StartCreateProcess(PWSTR CommandLine,
  716. ULONG CreateFlags,
  717. PBOOL InheritHandles,
  718. PWSTR CurrentDir,
  719. PPENDING_PROCESS* Pending);
  720. virtual HRESULT TerminateProcesses(void);
  721. virtual HRESULT DetachProcesses(void);
  722. //
  723. // Layered methods. These are usually common code that
  724. // use pure methods to do their work.
  725. //
  726. HRESULT ReadAllVirtual(ProcessInfo* Process,
  727. ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  728. {
  729. HRESULT Status;
  730. ULONG Done;
  731. if ((Status = ReadVirtual(Process,
  732. Address, Buffer, BufferSize, &Done)) == S_OK
  733. && Done != BufferSize)
  734. {
  735. Status = HRESULT_FROM_WIN32(ERROR_READ_FAULT);
  736. }
  737. return Status;
  738. }
  739. HRESULT WriteAllVirtual(ProcessInfo* Process,
  740. ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  741. {
  742. HRESULT Status;
  743. ULONG Done;
  744. if ((Status = WriteVirtual(Process,
  745. Address, Buffer, BufferSize, &Done)) == S_OK
  746. && Done != BufferSize)
  747. {
  748. Status = HRESULT_FROM_WIN32(ERROR_WRITE_FAULT);
  749. }
  750. return Status;
  751. }
  752. HRESULT ReadAllPhysical(ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  753. {
  754. HRESULT Status;
  755. ULONG Done;
  756. if ((Status = ReadPhysical(Address, Buffer, BufferSize,
  757. PHYS_FLAG_DEFAULT, &Done)) == S_OK
  758. && Done != BufferSize)
  759. {
  760. Status = HRESULT_FROM_WIN32(ERROR_READ_FAULT);
  761. }
  762. return Status;
  763. }
  764. HRESULT WriteAllPhysical(ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  765. {
  766. HRESULT Status;
  767. ULONG Done;
  768. if ((Status = WritePhysical(Address, Buffer, BufferSize,
  769. PHYS_FLAG_DEFAULT, &Done)) == S_OK
  770. && Done != BufferSize)
  771. {
  772. Status = HRESULT_FROM_WIN32(ERROR_WRITE_FAULT);
  773. }
  774. return Status;
  775. }
  776. HRESULT ReadPointer(ProcessInfo* Process, MachineInfo* Machine,
  777. ULONG64 Address, PULONG64 PointerValue);
  778. HRESULT WritePointer(ProcessInfo* Process, MachineInfo* Machine,
  779. ULONG64 Address, ULONG64 PointerValue);
  780. HRESULT ReadListEntry(ProcessInfo* Process, MachineInfo* Machine,
  781. ULONG64 Address, PLIST_ENTRY64 List);
  782. HRESULT ReadLoaderEntry(ProcessInfo* Process, MachineInfo* Machine,
  783. ULONG64 Address, PKLDR_DATA_TABLE_ENTRY64 Entry);
  784. HRESULT ReadUnicodeString(ProcessInfo* Process, MachineInfo* Machine,
  785. ULONG64 Address, PUNICODE_STRING64 String);
  786. HRESULT ReadImageVersionInfo(ProcessInfo* Process,
  787. ULONG64 ImageBase,
  788. PCSTR Item,
  789. PVOID Buffer,
  790. ULONG BufferSize,
  791. PULONG VerInfoSize,
  792. PIMAGE_DATA_DIRECTORY ResDataDir);
  793. HRESULT ReadImageNtHeaders(ProcessInfo* Process,
  794. ULONG64 ImageBase,
  795. PIMAGE_NT_HEADERS64 Headers);
  796. HRESULT ReadDirectoryTableBase(PULONG64 DirBase);
  797. HRESULT ReadSharedUserTimeDateN(PULONG64 TimeDate);
  798. HRESULT ReadSharedUserUpTimeN(PULONG64 UpTime);
  799. HRESULT ReadSharedUserProductInfo(PULONG ProductType, PULONG SuiteMask);
  800. // Internal routines which provide canonical context input
  801. // and output, applying any necessary conversions before
  802. // or after calling Get/SetTargetContext.
  803. HRESULT GetContext(
  804. ULONG64 Thread,
  805. PCROSS_PLATFORM_CONTEXT Context
  806. );
  807. HRESULT SetContext(
  808. ULONG64 Thread,
  809. PCROSS_PLATFORM_CONTEXT Context
  810. );
  811. HRESULT GetContextFromThreadStack(ULONG64 ThreadBase,
  812. PCROSS_PLATFORM_CONTEXT Context,
  813. BOOL Verbose);
  814. HRESULT EmulateNtX86SelDescriptor(ThreadInfo* Thread,
  815. MachineInfo* Machine,
  816. ULONG Selector,
  817. PDESCRIPTOR64 Desc);
  818. HRESULT EmulateNtAmd64SelDescriptor(ThreadInfo* Thread,
  819. MachineInfo* Machine,
  820. ULONG Selector,
  821. PDESCRIPTOR64 Desc);
  822. HRESULT EmulateNtSelDescriptor(ThreadInfo* Thread,
  823. MachineInfo* Machine,
  824. ULONG Selector,
  825. PDESCRIPTOR64 Desc);
  826. void ResetImplicitData(void)
  827. {
  828. m_ImplicitProcessData = 0;
  829. m_ImplicitProcessDataIsDefault = TRUE;
  830. m_ImplicitProcessDataThread = NULL;
  831. }
  832. HRESULT GetImplicitProcessData(ThreadInfo* Thread, PULONG64 Offset);
  833. HRESULT GetImplicitProcessDataPeb(ThreadInfo* Thread, PULONG64 Offset);
  834. HRESULT GetImplicitProcessDataParentCID(ThreadInfo* Thread, PULONG64 Pcid);
  835. HRESULT SetImplicitProcessData(ThreadInfo* Thread,
  836. ULONG64 Offset, BOOL Verbose);
  837. HRESULT ReadImplicitProcessInfoPointer(ThreadInfo* Thread,
  838. ULONG Offset, PULONG64 Ptr);
  839. // Internal implementations based on user or kernel
  840. // registers and data. Placed here for sharing between
  841. // live and dump sessions rather than using multiple
  842. // inheritance.
  843. HRESULT KdGetThreadInfoDataOffset(ThreadInfo* Thread,
  844. ULONG64 ThreadHandle,
  845. PULONG64 Offset);
  846. HRESULT KdGetProcessInfoDataOffset(ThreadInfo* Thread,
  847. ULONG Processor,
  848. ULONG64 ThreadData,
  849. PULONG64 Offset);
  850. HRESULT KdGetThreadInfoTeb(ThreadInfo* Thread,
  851. ULONG Processor,
  852. ULONG64 ThreadData,
  853. PULONG64 Offset);
  854. HRESULT KdGetProcessInfoPeb(ThreadInfo* Thread,
  855. ULONG Processor,
  856. ULONG64 ThreadData,
  857. PULONG64 Offset);
  858. HRESULT KdGetSelDescriptor(ThreadInfo* Thread,
  859. MachineInfo* Machine,
  860. ULONG Selector,
  861. PDESCRIPTOR64 Desc);
  862. void FlushSelectorCache(void);
  863. BOOL FindSelector(ULONG Processor, ULONG Selector,
  864. PDESCRIPTOR64 Desc);
  865. void PutSelector(ULONG Processor, ULONG Selector,
  866. PDESCRIPTOR64 Desc);
  867. // This selector cache is only used for kernel targets
  868. // but it's here on TargetInfo so that the kernel dump
  869. // targets inherit it.
  870. SEL_CACHE_ENTRY m_SelectorCache[SELECTOR_CACHE_LENGTH];
  871. SEL_CACHE_ENTRY* m_YoungestSel;
  872. SEL_CACHE_ENTRY* m_OldestSel;
  873. };
  874. //----------------------------------------------------------------------------
  875. //
  876. // LiveKernelTargetInfo.
  877. //
  878. //----------------------------------------------------------------------------
  879. class LiveKernelTargetInfo : public TargetInfo
  880. {
  881. public:
  882. LiveKernelTargetInfo(ULONG Qual, BOOL DynamicEvents);
  883. // TargetInfo.
  884. virtual void ResetSystemInfo(void);
  885. virtual HRESULT GetProcessorId(
  886. ULONG Processor,
  887. PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id
  888. );
  889. virtual HRESULT GetProcessorSpeed(
  890. ULONG Processor,
  891. PULONG Speed
  892. );
  893. virtual HRESULT GetThreadIdByProcessor(
  894. IN ULONG Processor,
  895. OUT PULONG Id
  896. );
  897. virtual HRESULT GetThreadInfoDataOffset(ThreadInfo* Thread,
  898. ULONG64 ThreadHandle,
  899. PULONG64 Offset);
  900. virtual HRESULT GetProcessInfoDataOffset(ThreadInfo* Thread,
  901. ULONG Processor,
  902. ULONG64 ThreadData,
  903. PULONG64 Offset);
  904. virtual HRESULT GetThreadInfoTeb(ThreadInfo* Thread,
  905. ULONG Processor,
  906. ULONG64 ThreadData,
  907. PULONG64 Offset);
  908. virtual HRESULT GetProcessInfoPeb(ThreadInfo* Thread,
  909. ULONG Processor,
  910. ULONG64 ThreadData,
  911. PULONG64 Offset);
  912. virtual HRESULT GetSelDescriptor(ThreadInfo* Thread,
  913. MachineInfo* Machine,
  914. ULONG Selector,
  915. PDESCRIPTOR64 Desc);
  916. virtual HRESULT ReadBugCheckData(PULONG Code, ULONG64 Args[4]);
  917. virtual ULONG64 GetCurrentTimeDateN(void);
  918. virtual ULONG64 GetCurrentSystemUpTimeN(void);
  919. // LiveKernelTargetInfo.
  920. HRESULT InitFromKdVersion(void);
  921. // Options are only valid in Initialize.
  922. PCSTR m_ConnectOptions;
  923. ULONG m_KdMaxPacketType;
  924. ULONG m_KdMaxStateChange;
  925. ULONG m_KdMaxManipulate;
  926. };
  927. //----------------------------------------------------------------------------
  928. //
  929. // ConnLiveKernelTargetInfo.
  930. //
  931. //----------------------------------------------------------------------------
  932. class ConnLiveKernelTargetInfo : public LiveKernelTargetInfo
  933. {
  934. public:
  935. ConnLiveKernelTargetInfo(void);
  936. virtual ~ConnLiveKernelTargetInfo(void);
  937. // TargetInfo.
  938. virtual void ResetSystemInfo(void);
  939. virtual HRESULT Initialize(void);
  940. virtual HRESULT GetDescription(PSTR Buffer, ULONG BufferLen,
  941. PULONG DescLen);
  942. virtual void DebuggeeReset(ULONG Reason, BOOL FromEvent);
  943. virtual HRESULT ReadVirtual(
  944. IN ProcessInfo* Process,
  945. IN ULONG64 Offset,
  946. OUT PVOID Buffer,
  947. IN ULONG BufferSize,
  948. OUT OPTIONAL PULONG BytesRead
  949. );
  950. virtual HRESULT WriteVirtual(
  951. IN ProcessInfo* Process,
  952. IN ULONG64 Offset,
  953. IN PVOID Buffer,
  954. IN ULONG BufferSize,
  955. OUT OPTIONAL PULONG BytesWritten
  956. );
  957. virtual HRESULT SearchVirtual(
  958. IN ProcessInfo* Process,
  959. IN ULONG64 Offset,
  960. IN ULONG64 Length,
  961. IN PVOID Pattern,
  962. IN ULONG PatternSize,
  963. IN ULONG PatternGranularity,
  964. OUT PULONG64 MatchOffset
  965. );
  966. virtual HRESULT ReadVirtualUncached(
  967. IN ProcessInfo* Process,
  968. IN ULONG64 Offset,
  969. OUT PVOID Buffer,
  970. IN ULONG BufferSize,
  971. OUT OPTIONAL PULONG BytesRead
  972. );
  973. virtual HRESULT WriteVirtualUncached(
  974. IN ProcessInfo* Process,
  975. IN ULONG64 Offset,
  976. IN PVOID Buffer,
  977. IN ULONG BufferSize,
  978. OUT OPTIONAL PULONG BytesWritten
  979. );
  980. virtual HRESULT ReadPhysical(
  981. IN ULONG64 Offset,
  982. OUT PVOID Buffer,
  983. IN ULONG BufferSize,
  984. IN ULONG Flags,
  985. OUT OPTIONAL PULONG BytesRead
  986. );
  987. virtual HRESULT WritePhysical(
  988. IN ULONG64 Offset,
  989. IN PVOID Buffer,
  990. IN ULONG BufferSize,
  991. IN ULONG Flags,
  992. OUT OPTIONAL PULONG BytesWritten
  993. );
  994. virtual HRESULT PointerSearchPhysical(
  995. IN ULONG64 Offset,
  996. IN ULONG64 Length,
  997. IN ULONG64 PointerMin,
  998. IN ULONG64 PointerMax,
  999. IN ULONG Flags,
  1000. OUT PULONG64 MatchOffsets,
  1001. IN ULONG MatchOffsetsSize,
  1002. OUT PULONG MatchOffsetsCount
  1003. );
  1004. virtual HRESULT ReadPhysicalUncached(
  1005. IN ULONG64 Offset,
  1006. OUT PVOID Buffer,
  1007. IN ULONG BufferSize,
  1008. IN ULONG Flags,
  1009. OUT OPTIONAL PULONG BytesRead
  1010. );
  1011. virtual HRESULT WritePhysicalUncached(
  1012. IN ULONG64 Offset,
  1013. IN PVOID Buffer,
  1014. IN ULONG BufferSize,
  1015. IN ULONG Flags,
  1016. OUT OPTIONAL PULONG BytesWritten
  1017. );
  1018. virtual HRESULT ReadControl(
  1019. IN ULONG Processor,
  1020. IN ULONG64 Offset,
  1021. OUT PVOID Buffer,
  1022. IN ULONG BufferSize,
  1023. OUT OPTIONAL PULONG BytesRead
  1024. );
  1025. virtual HRESULT WriteControl(
  1026. IN ULONG Processor,
  1027. IN ULONG64 Offset,
  1028. IN PVOID Buffer,
  1029. IN ULONG BufferSize,
  1030. OUT OPTIONAL PULONG BytesWritten
  1031. );
  1032. virtual HRESULT ReadIo(
  1033. IN ULONG InterfaceType,
  1034. IN ULONG BusNumber,
  1035. IN ULONG AddressSpace,
  1036. IN ULONG64 Offset,
  1037. OUT PVOID Buffer,
  1038. IN ULONG BufferSize,
  1039. OUT OPTIONAL PULONG BytesRead
  1040. );
  1041. virtual HRESULT WriteIo(
  1042. IN ULONG InterfaceType,
  1043. IN ULONG BusNumber,
  1044. IN ULONG AddressSpace,
  1045. IN ULONG64 Offset,
  1046. IN PVOID Buffer,
  1047. IN ULONG BufferSize,
  1048. OUT OPTIONAL PULONG BytesWritten
  1049. );
  1050. virtual HRESULT ReadMsr(
  1051. IN ULONG Msr,
  1052. OUT PULONG64 Value
  1053. );
  1054. virtual HRESULT WriteMsr(
  1055. IN ULONG Msr,
  1056. IN ULONG64 Value
  1057. );
  1058. virtual HRESULT ReadBusData(
  1059. IN ULONG BusDataType,
  1060. IN ULONG BusNumber,
  1061. IN ULONG SlotNumber,
  1062. IN ULONG Offset,
  1063. OUT PVOID Buffer,
  1064. IN ULONG BufferSize,
  1065. OUT OPTIONAL PULONG BytesRead
  1066. );
  1067. virtual HRESULT WriteBusData(
  1068. IN ULONG BusDataType,
  1069. IN ULONG BusNumber,
  1070. IN ULONG SlotNumber,
  1071. IN ULONG Offset,
  1072. IN PVOID Buffer,
  1073. IN ULONG BufferSize,
  1074. OUT OPTIONAL PULONG BytesWritten
  1075. );
  1076. virtual HRESULT CheckLowMemory(
  1077. );
  1078. virtual HRESULT FillVirtual(
  1079. THIS_
  1080. IN ProcessInfo* Process,
  1081. IN ULONG64 Start,
  1082. IN ULONG Size,
  1083. IN PVOID Pattern,
  1084. IN ULONG PatternSize,
  1085. OUT PULONG Filled
  1086. );
  1087. virtual HRESULT FillPhysical(
  1088. THIS_
  1089. IN ULONG64 Start,
  1090. IN ULONG Size,
  1091. IN PVOID Pattern,
  1092. IN ULONG PatternSize,
  1093. OUT PULONG Filled
  1094. );
  1095. virtual HRESULT GetTargetContext(
  1096. ULONG64 Thread,
  1097. PVOID Context
  1098. );
  1099. virtual HRESULT SetTargetContext(
  1100. ULONG64 Thread,
  1101. PVOID Context
  1102. );
  1103. virtual HRESULT SwitchProcessors(ULONG Processor);
  1104. virtual HRESULT SwitchToTarget(TargetInfo* From);
  1105. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  1106. virtual HRESULT InitializeTargetControlledStepping(void);
  1107. virtual void InitializeWatchTrace(void);
  1108. virtual void ProcessWatchTraceEvent(PDBGKD_TRACE_DATA TraceData,
  1109. PADDR PcAddr,
  1110. PBOOL StepOver);
  1111. virtual HRESULT WaitInitialize(ULONG Flags,
  1112. ULONG Timeout,
  1113. WAIT_INIT_TYPE Type,
  1114. PULONG DesiredTimeout);
  1115. virtual HRESULT ReleaseLastEvent(ULONG ContinueStatus);
  1116. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout,
  1117. ULONG ElapsedTime, PULONG EventStatus);
  1118. virtual HRESULT RequestBreakIn(void);
  1119. virtual HRESULT ClearBreakIn(void);
  1120. virtual HRESULT Reboot(void);
  1121. virtual HRESULT Crash(ULONG Code);
  1122. virtual HRESULT InsertCodeBreakpoint(ProcessInfo* Process,
  1123. class MachineInfo* Machine,
  1124. PADDR Addr,
  1125. ULONG InstrFlags,
  1126. PUCHAR StorageSpace);
  1127. virtual HRESULT RemoveCodeBreakpoint(ProcessInfo* Process,
  1128. class MachineInfo* Machine,
  1129. PADDR Addr,
  1130. ULONG InstrFlags,
  1131. PUCHAR StorageSpace);
  1132. virtual HRESULT RemoveAllDataBreakpoints(ProcessInfo* Process);
  1133. virtual HRESULT RemoveAllTargetBreakpoints(void);
  1134. virtual HRESULT InsertTargetCountBreakpoint(PADDR Addr,
  1135. ULONG Flags);
  1136. virtual HRESULT RemoveTargetCountBreakpoint(PADDR Addr);
  1137. virtual HRESULT QueryTargetCountBreakpoint(PADDR Addr,
  1138. PULONG Flags,
  1139. PULONG Calls,
  1140. PULONG MinInstr,
  1141. PULONG MaxInstr,
  1142. PULONG TotInstr,
  1143. PULONG MaxCps);
  1144. virtual HRESULT QueryAddressInformation(ProcessInfo* Process,
  1145. ULONG64 Address, ULONG InSpace,
  1146. PULONG OutSpace, PULONG OutFlags);
  1147. // ConnLiveKernelTargetInfo.
  1148. NTSTATUS WaitStateChange(OUT PDBGKD_ANY_WAIT_STATE_CHANGE StateChange,
  1149. OUT PVOID Buffer,
  1150. IN ULONG BufferLength,
  1151. IN BOOL SuspendEngine);
  1152. ULONG ProcessStateChange(PDBGKD_ANY_WAIT_STATE_CHANGE StateChange,
  1153. PCHAR StateChangeData);
  1154. NTSTATUS KdContinue(ULONG ContinueStatus,
  1155. PDBGKD_ANY_CONTROL_SET ControlSet);
  1156. NTSTATUS KdRestoreBreakPoint(ULONG BreakPointHandle);
  1157. NTSTATUS KdFillMemory(IN ULONG Flags,
  1158. IN ULONG64 Start,
  1159. IN ULONG Size,
  1160. IN PVOID Pattern,
  1161. IN ULONG PatternSize,
  1162. OUT PULONG Filled);
  1163. NTSTATUS KdReadVirtual(
  1164. IN ULONG64 Offset,
  1165. OUT PVOID Buffer,
  1166. IN ULONG BufferSize,
  1167. OUT OPTIONAL PULONG BytesRead
  1168. );
  1169. NTSTATUS KdWriteVirtual(
  1170. IN ULONG64 Offset,
  1171. IN PVOID Buffer,
  1172. IN ULONG BufferSize,
  1173. OUT OPTIONAL PULONG BytesWritten
  1174. );
  1175. HRESULT KdReadVirtualTranslated(
  1176. IN ULONG64 Offset,
  1177. OUT PVOID Buffer,
  1178. IN ULONG BufferSize,
  1179. OUT OPTIONAL PULONG BytesRead
  1180. );
  1181. HRESULT KdWriteVirtualTranslated(
  1182. IN ULONG64 Offset,
  1183. IN PVOID Buffer,
  1184. IN ULONG BufferSize,
  1185. OUT OPTIONAL PULONG BytesWritten
  1186. );
  1187. // ConnLiveKernelTargetInfo.
  1188. void ResetConnection(void);
  1189. DbgKdTransport* m_Transport;
  1190. BOOL m_CurrentPartition;
  1191. TargetInfo* m_SwitchTarget;
  1192. ULONG m_SwitchProcessor;
  1193. ULONG64 m_KdpSearchPageHits;
  1194. ULONG64 m_KdpSearchPageHitOffsets;
  1195. ULONG64 m_KdpSearchPageHitIndex;
  1196. ULONG64 m_KdpSearchCheckPoint;
  1197. ULONG64 m_KdpSearchInProgress;
  1198. ULONG64 m_KdpSearchStartPageFrame;
  1199. ULONG64 m_KdpSearchEndPageFrame;
  1200. ULONG64 m_KdpSearchAddressRangeStart;
  1201. ULONG64 m_KdpSearchAddressRangeEnd;
  1202. ULONG64 m_KdpSearchPfnValue;
  1203. };
  1204. //----------------------------------------------------------------------------
  1205. //
  1206. // LocalLiveKernelTargetInfo.
  1207. //
  1208. //----------------------------------------------------------------------------
  1209. class LocalLiveKernelTargetInfo : public LiveKernelTargetInfo
  1210. {
  1211. public:
  1212. LocalLiveKernelTargetInfo(void)
  1213. : LiveKernelTargetInfo(DEBUG_KERNEL_LOCAL, FALSE) {}
  1214. // TargetInfo.
  1215. virtual HRESULT Initialize(void);
  1216. virtual HRESULT GetDescription(PSTR Buffer, ULONG BufferLen,
  1217. PULONG DescLen);
  1218. virtual HRESULT ReadVirtual(
  1219. IN ProcessInfo* Process,
  1220. IN ULONG64 Offset,
  1221. OUT PVOID Buffer,
  1222. IN ULONG BufferSize,
  1223. OUT OPTIONAL PULONG BytesRead
  1224. );
  1225. virtual HRESULT WriteVirtual(
  1226. IN ProcessInfo* Process,
  1227. IN ULONG64 Offset,
  1228. IN PVOID Buffer,
  1229. IN ULONG BufferSize,
  1230. OUT OPTIONAL PULONG BytesWritten
  1231. );
  1232. virtual HRESULT ReadPhysical(
  1233. IN ULONG64 Offset,
  1234. OUT PVOID Buffer,
  1235. IN ULONG BufferSize,
  1236. IN ULONG Flags,
  1237. OUT OPTIONAL PULONG BytesRead
  1238. );
  1239. virtual HRESULT WritePhysical(
  1240. IN ULONG64 Offset,
  1241. IN PVOID Buffer,
  1242. IN ULONG BufferSize,
  1243. IN ULONG Flags,
  1244. OUT OPTIONAL PULONG BytesWritten
  1245. );
  1246. virtual HRESULT ReadControl(
  1247. IN ULONG Processor,
  1248. IN ULONG64 Offset,
  1249. OUT PVOID Buffer,
  1250. IN ULONG BufferSize,
  1251. OUT OPTIONAL PULONG BytesRead
  1252. );
  1253. virtual HRESULT WriteControl(
  1254. IN ULONG Processor,
  1255. IN ULONG64 Offset,
  1256. IN PVOID Buffer,
  1257. IN ULONG BufferSize,
  1258. OUT OPTIONAL PULONG BytesWritten
  1259. );
  1260. virtual HRESULT ReadIo(
  1261. IN ULONG InterfaceType,
  1262. IN ULONG BusNumber,
  1263. IN ULONG AddressSpace,
  1264. IN ULONG64 Offset,
  1265. OUT PVOID Buffer,
  1266. IN ULONG BufferSize,
  1267. OUT OPTIONAL PULONG BytesRead
  1268. );
  1269. virtual HRESULT WriteIo(
  1270. IN ULONG InterfaceType,
  1271. IN ULONG BusNumber,
  1272. IN ULONG AddressSpace,
  1273. IN ULONG64 Offset,
  1274. IN PVOID Buffer,
  1275. IN ULONG BufferSize,
  1276. OUT OPTIONAL PULONG BytesWritten
  1277. );
  1278. virtual HRESULT ReadMsr(
  1279. IN ULONG Msr,
  1280. OUT PULONG64 Value
  1281. );
  1282. virtual HRESULT WriteMsr(
  1283. IN ULONG Msr,
  1284. IN ULONG64 Value
  1285. );
  1286. virtual HRESULT ReadBusData(
  1287. IN ULONG BusDataType,
  1288. IN ULONG BusNumber,
  1289. IN ULONG SlotNumber,
  1290. IN ULONG Offset,
  1291. OUT PVOID Buffer,
  1292. IN ULONG BufferSize,
  1293. OUT OPTIONAL PULONG BytesRead
  1294. );
  1295. virtual HRESULT WriteBusData(
  1296. IN ULONG BusDataType,
  1297. IN ULONG BusNumber,
  1298. IN ULONG SlotNumber,
  1299. IN ULONG Offset,
  1300. IN PVOID Buffer,
  1301. IN ULONG BufferSize,
  1302. OUT OPTIONAL PULONG BytesWritten
  1303. );
  1304. virtual HRESULT CheckLowMemory(
  1305. );
  1306. virtual HRESULT GetTargetContext(
  1307. ULONG64 Thread,
  1308. PVOID Context
  1309. );
  1310. virtual HRESULT SetTargetContext(
  1311. ULONG64 Thread,
  1312. PVOID Context
  1313. );
  1314. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  1315. virtual HRESULT WaitInitialize(ULONG Flags,
  1316. ULONG Timeout,
  1317. WAIT_INIT_TYPE Type,
  1318. PULONG DesiredTimeout);
  1319. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout,
  1320. ULONG ElapsedTime, PULONG EventStatus);
  1321. };
  1322. //----------------------------------------------------------------------------
  1323. //
  1324. // ExdiLiveKernelTargetInfo.
  1325. //
  1326. //----------------------------------------------------------------------------
  1327. class ExdiNotifyRunChange : public IeXdiClientNotifyRunChg
  1328. {
  1329. public:
  1330. ExdiNotifyRunChange(void);
  1331. ~ExdiNotifyRunChange(void);
  1332. HRESULT Initialize(void);
  1333. void Uninitialize(void);
  1334. // IUnknown.
  1335. STDMETHOD(QueryInterface)(
  1336. THIS_
  1337. IN REFIID InterfaceId,
  1338. OUT PVOID* Interface
  1339. );
  1340. STDMETHOD_(ULONG, AddRef)(
  1341. THIS
  1342. );
  1343. STDMETHOD_(ULONG, Release)(
  1344. THIS
  1345. );
  1346. // IeXdiClientNotifyRunChg.
  1347. STDMETHOD(NotifyRunStateChange)(RUN_STATUS_TYPE ersCurrent,
  1348. HALT_REASON_TYPE ehrCurrent,
  1349. ADDRESS_TYPE CurrentExecAddress,
  1350. DWORD dwExceptionCode);
  1351. // ExdiNotifyRunChange.
  1352. HANDLE m_Event;
  1353. HALT_REASON_TYPE m_HaltReason;
  1354. ADDRESS_TYPE m_ExecAddress;
  1355. ULONG m_ExceptionCode;
  1356. };
  1357. typedef union _EXDI_CONTEXT
  1358. {
  1359. CONTEXT_X86 X86Context;
  1360. CONTEXT_X86_EX X86ExContext;
  1361. CONTEXT_X86_64 Amd64Context;
  1362. EXDI_CONTEXT_IA64 IA64Context;
  1363. } EXDI_CONTEXT, *PEXDI_CONTEXT;
  1364. enum EXDI_CONTEXT_TYPE
  1365. {
  1366. EXDI_CTX_X86,
  1367. EXDI_CTX_X86_EX,
  1368. EXDI_CTX_AMD64,
  1369. EXDI_CTX_IA64,
  1370. };
  1371. enum EXDI_KD_SUPPORT
  1372. {
  1373. EXDI_KD_NONE,
  1374. EXDI_KD_IOCTL,
  1375. EXDI_KD_GS_PCR
  1376. };
  1377. class ExdiLiveKernelTargetInfo : public LiveKernelTargetInfo
  1378. {
  1379. public:
  1380. ExdiLiveKernelTargetInfo(void);
  1381. virtual ~ExdiLiveKernelTargetInfo(void);
  1382. // TargetInfo.
  1383. virtual HRESULT Initialize(void);
  1384. virtual HRESULT GetDescription(PSTR Buffer, ULONG BufferLen,
  1385. PULONG DescLen);
  1386. virtual HRESULT ReadVirtual(
  1387. IN ProcessInfo* Process,
  1388. IN ULONG64 Offset,
  1389. OUT PVOID Buffer,
  1390. IN ULONG BufferSize,
  1391. OUT OPTIONAL PULONG BytesRead
  1392. );
  1393. virtual HRESULT WriteVirtual(
  1394. IN ProcessInfo* Process,
  1395. IN ULONG64 Offset,
  1396. IN PVOID Buffer,
  1397. IN ULONG BufferSize,
  1398. OUT OPTIONAL PULONG BytesWritten
  1399. );
  1400. virtual HRESULT ReadPhysical(
  1401. IN ULONG64 Offset,
  1402. OUT PVOID Buffer,
  1403. IN ULONG BufferSize,
  1404. IN ULONG Flags,
  1405. OUT OPTIONAL PULONG BytesRead
  1406. );
  1407. virtual HRESULT WritePhysical(
  1408. IN ULONG64 Offset,
  1409. IN PVOID Buffer,
  1410. IN ULONG BufferSize,
  1411. IN ULONG Flags,
  1412. OUT OPTIONAL PULONG BytesWritten
  1413. );
  1414. virtual HRESULT ReadControl(
  1415. IN ULONG Processor,
  1416. IN ULONG64 Offset,
  1417. OUT PVOID Buffer,
  1418. IN ULONG BufferSize,
  1419. OUT OPTIONAL PULONG BytesRead
  1420. );
  1421. virtual HRESULT WriteControl(
  1422. IN ULONG Processor,
  1423. IN ULONG64 Offset,
  1424. IN PVOID Buffer,
  1425. IN ULONG BufferSize,
  1426. OUT OPTIONAL PULONG BytesWritten
  1427. );
  1428. virtual HRESULT ReadIo(
  1429. IN ULONG InterfaceType,
  1430. IN ULONG BusNumber,
  1431. IN ULONG AddressSpace,
  1432. IN ULONG64 Offset,
  1433. OUT PVOID Buffer,
  1434. IN ULONG BufferSize,
  1435. OUT OPTIONAL PULONG BytesRead
  1436. );
  1437. virtual HRESULT WriteIo(
  1438. IN ULONG InterfaceType,
  1439. IN ULONG BusNumber,
  1440. IN ULONG AddressSpace,
  1441. IN ULONG64 Offset,
  1442. IN PVOID Buffer,
  1443. IN ULONG BufferSize,
  1444. OUT OPTIONAL PULONG BytesWritten
  1445. );
  1446. virtual HRESULT ReadMsr(
  1447. IN ULONG Msr,
  1448. OUT PULONG64 Value
  1449. );
  1450. virtual HRESULT WriteMsr(
  1451. IN ULONG Msr,
  1452. IN ULONG64 Value
  1453. );
  1454. virtual HRESULT ReadBusData(
  1455. IN ULONG BusDataType,
  1456. IN ULONG BusNumber,
  1457. IN ULONG SlotNumber,
  1458. IN ULONG Offset,
  1459. OUT PVOID Buffer,
  1460. IN ULONG BufferSize,
  1461. OUT OPTIONAL PULONG BytesRead
  1462. );
  1463. virtual HRESULT WriteBusData(
  1464. IN ULONG BusDataType,
  1465. IN ULONG BusNumber,
  1466. IN ULONG SlotNumber,
  1467. IN ULONG Offset,
  1468. IN PVOID Buffer,
  1469. IN ULONG BufferSize,
  1470. OUT OPTIONAL PULONG BytesWritten
  1471. );
  1472. virtual HRESULT CheckLowMemory(
  1473. );
  1474. virtual HRESULT GetProcessorSystemDataOffset(
  1475. IN ULONG Processor,
  1476. IN ULONG Index,
  1477. OUT PULONG64 Offset
  1478. );
  1479. virtual HRESULT GetTargetContext(
  1480. ULONG64 Thread,
  1481. PVOID Context
  1482. );
  1483. virtual HRESULT SetTargetContext(
  1484. ULONG64 Thread,
  1485. PVOID Context
  1486. );
  1487. virtual HRESULT GetTargetSegRegDescriptors(ULONG64 Thread,
  1488. ULONG Start, ULONG Count,
  1489. PDESCRIPTOR64 Descs);
  1490. virtual HRESULT GetTargetSpecialRegisters
  1491. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  1492. virtual HRESULT SetTargetSpecialRegisters
  1493. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  1494. virtual void InvalidateTargetContext(void);
  1495. virtual HRESULT SwitchProcessors(ULONG Processor);
  1496. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  1497. virtual HRESULT WaitInitialize(ULONG Flags,
  1498. ULONG Timeout,
  1499. WAIT_INIT_TYPE Type,
  1500. PULONG DesiredTimeout);
  1501. virtual HRESULT ReleaseLastEvent(ULONG ContinueStatus);
  1502. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout,
  1503. ULONG ElapsedTime, PULONG EventStatus);
  1504. virtual HRESULT RequestBreakIn(void);
  1505. virtual HRESULT Reboot(void);
  1506. virtual HRESULT BeginInsertingBreakpoints(void);
  1507. virtual HRESULT InsertCodeBreakpoint(ProcessInfo* Process,
  1508. class MachineInfo* Machine,
  1509. PADDR Addr,
  1510. ULONG InstrFlags,
  1511. PUCHAR StorageSpace);
  1512. virtual HRESULT InsertDataBreakpoint(ProcessInfo* Process,
  1513. ThreadInfo* Thread,
  1514. class MachineInfo* Machine,
  1515. PADDR Addr,
  1516. ULONG Size,
  1517. ULONG AccessType,
  1518. PUCHAR StorageSpace);
  1519. virtual void EndInsertingBreakpoints(void);
  1520. virtual void BeginRemovingBreakpoints(void);
  1521. virtual HRESULT RemoveCodeBreakpoint(ProcessInfo* Process,
  1522. class MachineInfo* Machine,
  1523. PADDR Addr,
  1524. ULONG InstrFlags,
  1525. PUCHAR StorageSpace);
  1526. virtual HRESULT RemoveDataBreakpoint(ProcessInfo* Process,
  1527. ThreadInfo* Thread,
  1528. class MachineInfo* Machine,
  1529. PADDR Addr,
  1530. ULONG Size,
  1531. ULONG AccessType,
  1532. PUCHAR StorageSpace);
  1533. virtual void EndRemovingBreakpoints(void);
  1534. virtual HRESULT IsDataBreakpointHit(ThreadInfo* Thread,
  1535. PADDR Addr,
  1536. ULONG Size,
  1537. ULONG AccessType,
  1538. PUCHAR StorageSpace);
  1539. // ExdiLiveKernelTargetInfo.
  1540. ULONG GetCurrentProcessor(void);
  1541. ULONG ProcessRunChange(ULONG HaltReason,
  1542. ULONG ExceptionCode);
  1543. IeXdiServer* m_Server;
  1544. IStream* m_MarshalledServer;
  1545. IUnknown* m_Context;
  1546. BOOL m_ContextValid;
  1547. EXDI_CONTEXT m_ContextData;
  1548. EXDI_CONTEXT_TYPE m_ContextType;
  1549. GLOBAL_TARGET_INFO_STRUCT m_GlobalInfo;
  1550. EXDI_KD_SUPPORT m_KdSupport;
  1551. BOOL m_ForceX86;
  1552. ULONG m_ExpectedMachine;
  1553. CBP_KIND m_CodeBpType;
  1554. ExdiNotifyRunChange m_RunChange;
  1555. DBGENG_EXDI_IOCTL_CODE m_IoctlMin;
  1556. DBGENG_EXDI_IOCTL_CODE m_IoctlMax;
  1557. BOOL m_ExdiDataBreaks;
  1558. DBGENG_EXDI_IOCTL_GET_BREAKPOINT_HIT_OUT m_BpHit;
  1559. };
  1560. //----------------------------------------------------------------------------
  1561. //
  1562. // LiveUserTargetInfo.
  1563. //
  1564. //----------------------------------------------------------------------------
  1565. class LiveUserTargetInfo : public TargetInfo
  1566. {
  1567. public:
  1568. LiveUserTargetInfo(ULONG Qual);
  1569. virtual ~LiveUserTargetInfo(void);
  1570. // TargetInfo.
  1571. virtual void DeleteSystemInfo(void);
  1572. virtual HRESULT Initialize(void);
  1573. virtual HRESULT GetDescription(PSTR Buffer, ULONG BufferLen,
  1574. PULONG DescLen);
  1575. virtual HRESULT ReadVirtual(
  1576. IN ProcessInfo* Process,
  1577. IN ULONG64 Offset,
  1578. OUT PVOID Buffer,
  1579. IN ULONG BufferSize,
  1580. OUT OPTIONAL PULONG BytesRead
  1581. );
  1582. virtual HRESULT WriteVirtual(
  1583. IN ProcessInfo* Process,
  1584. IN ULONG64 Offset,
  1585. IN PVOID Buffer,
  1586. IN ULONG BufferSize,
  1587. OUT OPTIONAL PULONG BytesWritten
  1588. );
  1589. virtual HRESULT ReadVirtualUncached(
  1590. IN ProcessInfo* Process,
  1591. IN ULONG64 Offset,
  1592. OUT PVOID Buffer,
  1593. IN ULONG BufferSize,
  1594. OUT OPTIONAL PULONG BytesRead
  1595. );
  1596. virtual HRESULT WriteVirtualUncached(
  1597. IN ProcessInfo* Process,
  1598. IN ULONG64 Offset,
  1599. IN PVOID Buffer,
  1600. IN ULONG BufferSize,
  1601. OUT OPTIONAL PULONG BytesWritten
  1602. );
  1603. virtual HRESULT ReadHandleData(
  1604. IN ProcessInfo* Process,
  1605. IN ULONG64 Handle,
  1606. IN ULONG DataType,
  1607. OUT OPTIONAL PVOID Buffer,
  1608. IN ULONG BufferSize,
  1609. OUT OPTIONAL PULONG DataSize
  1610. );
  1611. virtual HRESULT GetProcessorId(
  1612. ULONG Processor,
  1613. PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id
  1614. );
  1615. virtual HRESULT GetProcessorSpeed(
  1616. ULONG Processor,
  1617. PULONG Speed
  1618. );
  1619. virtual HRESULT GetGenericProcessorFeatures(
  1620. ULONG Processor,
  1621. PULONG64 Features,
  1622. ULONG FeaturesSize,
  1623. PULONG Used
  1624. );
  1625. virtual HRESULT GetSpecificProcessorFeatures(
  1626. ULONG Processor,
  1627. PULONG64 Features,
  1628. ULONG FeaturesSize,
  1629. PULONG Used
  1630. );
  1631. virtual HRESULT GetUnloadedModuleListHead(ProcessInfo* Process,
  1632. PULONG64 Head);
  1633. virtual HRESULT GetFunctionTableListHead(ProcessInfo* Process,
  1634. PULONG64 Head);
  1635. virtual HRESULT ReadOutOfProcessDynamicFunctionTable(ProcessInfo* Process,
  1636. PWSTR Dll,
  1637. ULONG64 Table,
  1638. PULONG TableSize,
  1639. PVOID* TableData);
  1640. virtual HRESULT GetTargetContext(
  1641. ULONG64 Thread,
  1642. PVOID Context
  1643. );
  1644. virtual HRESULT SetTargetContext(
  1645. ULONG64 Thread,
  1646. PVOID Context
  1647. );
  1648. virtual HRESULT GetThreadStartOffset(ThreadInfo* Thread,
  1649. PULONG64 StartOffset);
  1650. virtual void SuspendThreads(void);
  1651. virtual BOOL ResumeThreads(void);
  1652. virtual HRESULT GetThreadInfoDataOffset(ThreadInfo* Thread,
  1653. ULONG64 ThreadHandle,
  1654. PULONG64 Offset);
  1655. virtual HRESULT GetProcessInfoDataOffset(ThreadInfo* Thread,
  1656. ULONG Processor,
  1657. ULONG64 ThreadData,
  1658. PULONG64 Offset);
  1659. virtual HRESULT GetThreadInfoTeb(ThreadInfo* Thread,
  1660. ULONG Processor,
  1661. ULONG64 ThreadData,
  1662. PULONG64 Offset);
  1663. virtual HRESULT GetProcessInfoPeb(ThreadInfo* Thread,
  1664. ULONG Processor,
  1665. ULONG64 ThreadData,
  1666. PULONG64 Offset);
  1667. virtual HRESULT GetSelDescriptor(ThreadInfo* Thread,
  1668. MachineInfo* Machine,
  1669. ULONG Selector,
  1670. PDESCRIPTOR64 Desc);
  1671. virtual HRESULT GetImageVersionInformation(ProcessInfo* Process,
  1672. PCSTR ImagePath,
  1673. ULONG64 ImageBase,
  1674. PCSTR Item,
  1675. PVOID Buffer, ULONG BufferSize,
  1676. PULONG VerInfoSize);
  1677. virtual ULONG64 GetCurrentTimeDateN(void);
  1678. virtual ULONG64 GetCurrentSystemUpTimeN(void);
  1679. virtual ULONG64 GetProcessUpTimeN(ProcessInfo* Process);
  1680. virtual HRESULT GetProcessTimes(ProcessInfo* Process,
  1681. PULONG64 Create,
  1682. PULONG64 Exit,
  1683. PULONG64 Kernel,
  1684. PULONG64 User);
  1685. virtual HRESULT GetThreadTimes(ThreadInfo* Thread,
  1686. PULONG64 Create,
  1687. PULONG64 Exit,
  1688. PULONG64 Kernel,
  1689. PULONG64 User);
  1690. virtual void InitializeWatchTrace(void);
  1691. virtual void ProcessWatchTraceEvent(PDBGKD_TRACE_DATA TraceData,
  1692. PADDR PcAddr,
  1693. PBOOL StepOver);
  1694. virtual HRESULT WaitInitialize(ULONG Flags,
  1695. ULONG Timeout,
  1696. WAIT_INIT_TYPE Type,
  1697. PULONG DesiredTimeout);
  1698. virtual HRESULT ReleaseLastEvent(ULONG ContinueStatus);
  1699. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout,
  1700. ULONG ElapsedTime, PULONG EventStatus);
  1701. virtual HRESULT RequestBreakIn(void);
  1702. virtual HRESULT BeginInsertingBreakpoints(void);
  1703. virtual HRESULT InsertCodeBreakpoint(ProcessInfo* Process,
  1704. class MachineInfo* Machine,
  1705. PADDR Addr,
  1706. ULONG InstrFlags,
  1707. PUCHAR StorageSpace);
  1708. virtual HRESULT InsertDataBreakpoint(ProcessInfo* Process,
  1709. ThreadInfo* Thread,
  1710. class MachineInfo* Machine,
  1711. PADDR Addr,
  1712. ULONG Size,
  1713. ULONG AccessType,
  1714. PUCHAR StorageSpace);
  1715. virtual void EndInsertingBreakpoints(void);
  1716. virtual HRESULT RemoveCodeBreakpoint(ProcessInfo* Process,
  1717. class MachineInfo* Machine,
  1718. PADDR Addr,
  1719. ULONG InstrFlags,
  1720. PUCHAR StorageSpace);
  1721. virtual HRESULT RemoveDataBreakpoint(ProcessInfo* Process,
  1722. ThreadInfo* Thread,
  1723. class MachineInfo* Machine,
  1724. PADDR Addr,
  1725. ULONG Size,
  1726. ULONG AccessType,
  1727. PUCHAR StorageSpace);
  1728. virtual HRESULT IsDataBreakpointHit(ThreadInfo* Thread,
  1729. PADDR Addr,
  1730. ULONG Size,
  1731. ULONG AccessType,
  1732. PUCHAR StorageSpace);
  1733. virtual HRESULT QueryMemoryRegion(ProcessInfo* Process,
  1734. PULONG64 Handle,
  1735. BOOL HandleIsOffset,
  1736. PMEMORY_BASIC_INFORMATION64 Info);
  1737. virtual HRESULT StartAttachProcess(ULONG ProcessId,
  1738. ULONG AttachFlags,
  1739. PPENDING_PROCESS* Pending);
  1740. virtual HRESULT StartCreateProcess(PWSTR CommandLine,
  1741. ULONG CreateFlags,
  1742. PBOOL InheritHandles,
  1743. PWSTR CurrentDir,
  1744. PPENDING_PROCESS* Pending);
  1745. virtual HRESULT TerminateProcesses(void);
  1746. virtual HRESULT DetachProcesses(void);
  1747. // LiveUserTargetInfo.
  1748. HRESULT SetServices(PUSER_DEBUG_SERVICES Services, BOOL Remote);
  1749. HRESULT InitFromServices(void);
  1750. ULONG ProcessDebugEvent(DEBUG_EVENT64* Event,
  1751. ULONG PendingFlags,
  1752. ULONG PendingOptions);
  1753. ULONG ProcessEventException(DEBUG_EVENT64* Event);
  1754. ULONG OutputEventDebugString(OUTPUT_DEBUG_STRING_INFO64* Info);
  1755. void AddPendingProcess(PPENDING_PROCESS Pending);
  1756. void RemovePendingProcess(PPENDING_PROCESS Pending);
  1757. void DiscardPendingProcess(PPENDING_PROCESS Pending);
  1758. void DiscardPendingProcesses(void);
  1759. PPENDING_PROCESS FindPendingProcessByFlags(ULONG Flags);
  1760. PPENDING_PROCESS FindPendingProcessById(ULONG Id);
  1761. void VerifyPendingProcesses(void);
  1762. void AddExamineToPendingAttach(void);
  1763. void SuspendResumeThreads(ProcessInfo* Process,
  1764. BOOL Susp,
  1765. ThreadInfo* Match);
  1766. PUSER_DEBUG_SERVICES m_Services;
  1767. ULONG m_ServiceFlags;
  1768. char m_ProcessServer[MAX_COMPUTERNAME_LENGTH + DBGRPC_MAX_IDENTITY + 8];
  1769. ULONG m_Local:1;
  1770. BOOL m_DataBpAddrValid;
  1771. HRESULT m_DataBpAddrStatus;
  1772. ULONG64 m_DataBpAddr;
  1773. ULONG m_DataBpAccess;
  1774. PPENDING_PROCESS m_ProcessPending;
  1775. ULONG m_AllPendingFlags;
  1776. };
  1777. //----------------------------------------------------------------------------
  1778. //
  1779. // DumpTargetInfo hierarchy is in dump.hpp.
  1780. //
  1781. //----------------------------------------------------------------------------
  1782. //----------------------------------------------------------------------------
  1783. //
  1784. // Generic layer definitions.
  1785. //
  1786. //----------------------------------------------------------------------------
  1787. extern ULONG g_NumberTargets;
  1788. extern TargetInfo* g_TargetHead;
  1789. #define ForProcessThreads(Process) \
  1790. for (Thread = (Process)->m_ThreadHead; Thread; Thread = Thread->m_Next)
  1791. #define ForTargetProcesses(Target) \
  1792. for (Process = (Target)->m_ProcessHead; Process; Process = Process->m_Next)
  1793. #define ForTargets() \
  1794. for (Target = g_TargetHead; Target; Target = Target->m_Next)
  1795. #define ForAllLayers() \
  1796. ForTargets() \
  1797. ForTargetProcesses(Target) \
  1798. ForProcessThreads(Process)
  1799. #define ForAllLayersToProcess() \
  1800. ForTargets() \
  1801. ForTargetProcesses(Target)
  1802. #define ForAllLayersToTarget() \
  1803. ForTargets()
  1804. extern TargetInfo* g_Target;
  1805. extern ProcessInfo* g_Process;
  1806. extern ThreadInfo* g_Thread;
  1807. extern MachineInfo* g_Machine;
  1808. struct StackSaveLayers
  1809. {
  1810. StackSaveLayers(void)
  1811. {
  1812. m_Target = g_Target;
  1813. m_Process = g_Process;
  1814. m_Thread = g_Thread;
  1815. m_Machine = g_Machine;
  1816. }
  1817. ~StackSaveLayers(void)
  1818. {
  1819. g_Target = m_Target;
  1820. g_Process = m_Process;
  1821. g_Thread = m_Thread;
  1822. g_Machine = m_Machine;
  1823. }
  1824. TargetInfo* m_Target;
  1825. ProcessInfo* m_Process;
  1826. ThreadInfo* m_Thread;
  1827. MachineInfo* m_Machine;
  1828. };
  1829. extern ULONG g_UserIdFragmented[LAYER_COUNT];
  1830. extern ULONG g_HighestUserId[LAYER_COUNT];
  1831. void SetLayersFromTarget(TargetInfo* Target);
  1832. void SetLayersFromProcess(ProcessInfo* Process);
  1833. void SetLayersFromThread(ThreadInfo* Thread);
  1834. void SetToAnyLayers(BOOL SetPrompt);
  1835. ULONG FindNextUserId(LAYER Layer);
  1836. //----------------------------------------------------------------------------
  1837. //
  1838. // Functions.
  1839. //
  1840. //----------------------------------------------------------------------------
  1841. TargetInfo* FindTargetByUserId(ULONG Id);
  1842. TargetInfo* FindTargetBySystemId(ULONG SysId);
  1843. TargetInfo* FindTargetByServer(ULONG64 Server);
  1844. void SuspendAllThreads(void);
  1845. BOOL ResumeAllThreads(void);
  1846. BOOL DeleteAllExitedInfos(void);
  1847. BOOL AnyActiveProcesses(BOOL FinalOnly);
  1848. BOOL AnySystemProcesses(BOOL LocalOnly);
  1849. ULONG AllProcessFlags(void);
  1850. BOOL AnyLiveUserTargets(void);
  1851. void InvalidateAllMemoryCaches(void);
  1852. HANDLE GloballyUniqueProcessHandle(TargetInfo* Target, ULONG64 FullHandle);
  1853. ULONG NtBuildToSystemVersion(ULONG Build);
  1854. ULONG Win9xBuildToSystemVersion(ULONG Build);
  1855. ULONG WinCeBuildToSystemVersion(ULONG Build);
  1856. PCSTR SystemVersionName(ULONG Sver);
  1857. void ParseSystemCommands(void);
  1858. #endif // #ifndef __TARGET_HPP__