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.

1499 lines
47 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Abstraction of target-specific information.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999-2001.
  6. //
  7. //----------------------------------------------------------------------------
  8. #ifndef __TARGET_HPP__
  9. #define __TARGET_HPP__
  10. extern DBGKD_GET_VERSION64 g_KdVersion;
  11. HRESULT EmulateNtSelDescriptor(class MachineInfo* Machine,
  12. ULONG Selector, PDESCRIPTOR64 Desc);
  13. ULONG NtBuildToSystemVersion(ULONG Build);
  14. ULONG Win9xBuildToSystemVersion(ULONG Build);
  15. void SetTargetSystemVersionAndBuild(ULONG Build, ULONG PlatformId);
  16. PCSTR SystemVersionName(ULONG Sver);
  17. BOOL
  18. GetUserModuleListAddress(
  19. MachineInfo* Machine,
  20. ULONG64 Peb,
  21. BOOL Quiet,
  22. PULONG64 OrderModuleListStart,
  23. PULONG64 FirstEntry
  24. );
  25. BOOL
  26. GetModNameFromLoaderList(
  27. MachineInfo* Machine,
  28. ULONG64 Peb,
  29. ULONG64 ModuleBase,
  30. PSTR NameBuffer,
  31. ULONG BufferSize,
  32. BOOL FullPath
  33. );
  34. void InitSelCache(void);
  35. void
  36. ConvertLoaderEntry32To64(
  37. PKLDR_DATA_TABLE_ENTRY32 b32,
  38. PKLDR_DATA_TABLE_ENTRY64 b64
  39. );
  40. void SetTargetNtCsdVersion(ULONG CsdVersion);
  41. //----------------------------------------------------------------------------
  42. //
  43. // Module list abstraction.
  44. //
  45. //----------------------------------------------------------------------------
  46. // If the image header is paged out the true values for
  47. // certain fields cannot be retrieved. These placeholders
  48. // are used instead.
  49. #define UNKNOWN_CHECKSUM 0xffffffff
  50. #define UNKNOWN_TIMESTAMP 0xfffffffe
  51. typedef struct _MODULE_INFO_ENTRY
  52. {
  53. // NamePtr should include a path if one is available.
  54. // It is the responsibility of callers to find the
  55. // file tail if that's all they care about.
  56. // If UnicodeNamePtr is false NameLength is ignored.
  57. PSTR NamePtr;
  58. ULONG UnicodeNamePtr:1;
  59. ULONG ImageInfoValid:1;
  60. ULONG ImageInfoPartial:1;
  61. ULONG ImageDebugHeader:1;
  62. ULONG Unused:28;
  63. // Length in bytes not including the terminator.
  64. ULONG NameLength;
  65. PSTR ModuleName;
  66. HANDLE File;
  67. ULONG64 Base;
  68. ULONG Size;
  69. ULONG SizeOfCode;
  70. ULONG SizeOfData;
  71. ULONG CheckSum;
  72. ULONG TimeDateStamp;
  73. PVOID DebugHeader;
  74. ULONG SizeOfDebugHeader;
  75. CHAR Buffer[MAX_IMAGE_PATH * sizeof(WCHAR)];
  76. } MODULE_INFO_ENTRY, *PMODULE_INFO_ENTRY;
  77. class ModuleInfo
  78. {
  79. public:
  80. virtual HRESULT Initialize(void) = 0;
  81. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry) = 0;
  82. // Base implementation does nothing.
  83. // Updates the entry image info by reading the
  84. // image header.
  85. void ReadImageHeaderInfo(PMODULE_INFO_ENTRY Entry);
  86. };
  87. class NtModuleInfo : public ModuleInfo
  88. {
  89. public:
  90. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  91. protected:
  92. MachineInfo* m_Machine;
  93. ULONG64 m_Head;
  94. ULONG64 m_Cur;
  95. };
  96. class NtKernelModuleInfo : public NtModuleInfo
  97. {
  98. public:
  99. virtual HRESULT Initialize(void);
  100. };
  101. extern NtKernelModuleInfo g_NtKernelModuleIterator;
  102. class NtUserModuleInfo : public NtModuleInfo
  103. {
  104. public:
  105. virtual HRESULT Initialize(void);
  106. protected:
  107. ULONG64 m_Peb;
  108. };
  109. class NtTargetUserModuleInfo : public NtUserModuleInfo
  110. {
  111. public:
  112. virtual HRESULT Initialize(void);
  113. };
  114. extern NtTargetUserModuleInfo g_NtTargetUserModuleIterator;
  115. class NtWow64UserModuleInfo : public NtUserModuleInfo
  116. {
  117. public:
  118. virtual HRESULT Initialize(void);
  119. private:
  120. HRESULT GetPeb32(PULONG64 Peb32);
  121. };
  122. extern NtWow64UserModuleInfo g_NtWow64UserModuleIterator;
  123. class DebuggerModuleInfo : public ModuleInfo
  124. {
  125. public:
  126. virtual HRESULT Initialize(void);
  127. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  128. private:
  129. PDEBUG_IMAGE_INFO m_Image;
  130. };
  131. extern DebuggerModuleInfo g_DebuggerModuleIterator;
  132. class UnloadedModuleInfo
  133. {
  134. public:
  135. virtual HRESULT Initialize(void) = 0;
  136. virtual HRESULT GetEntry(PSTR Name, PDEBUG_MODULE_PARAMETERS Params) = 0;
  137. };
  138. class NtKernelUnloadedModuleInfo : public UnloadedModuleInfo
  139. {
  140. public:
  141. virtual HRESULT Initialize(void);
  142. virtual HRESULT GetEntry(PSTR Name, PDEBUG_MODULE_PARAMETERS Params);
  143. protected:
  144. ULONG64 m_Base;
  145. ULONG m_Index;
  146. ULONG m_Count;
  147. };
  148. extern NtKernelUnloadedModuleInfo g_NtKernelUnloadedModuleIterator;
  149. class W9xModuleInfo : public ModuleInfo
  150. {
  151. public:
  152. virtual HRESULT Initialize(void);
  153. virtual HRESULT GetEntry(PMODULE_INFO_ENTRY Entry);
  154. protected:
  155. HANDLE m_Snap;
  156. BOOL m_First;
  157. ULONG m_LastId;
  158. };
  159. extern W9xModuleInfo g_W9xModuleIterator;
  160. //----------------------------------------------------------------------------
  161. //
  162. // Target configuration information.
  163. //
  164. //----------------------------------------------------------------------------
  165. #define IS_TARGET_SET() (g_TargetClass != DEBUG_CLASS_UNINITIALIZED)
  166. #define IS_KERNEL_TARGET() (g_TargetClass == DEBUG_CLASS_KERNEL)
  167. #define IS_USER_TARGET() (g_TargetClass == DEBUG_CLASS_USER_WINDOWS)
  168. #define IS_CONN_KERNEL_TARGET() \
  169. (IS_KERNEL_TARGET() && g_TargetClassQualifier == DEBUG_KERNEL_CONNECTION)
  170. #define IS_LOCAL_KERNEL_TARGET() \
  171. (IS_KERNEL_TARGET() && g_TargetClassQualifier == DEBUG_KERNEL_LOCAL)
  172. #define IS_EXDI_KERNEL_TARGET() \
  173. (IS_KERNEL_TARGET() && g_TargetClassQualifier == DEBUG_KERNEL_EXDI_DRIVER)
  174. #define IS_LIVE_USER_TARGET() \
  175. (IS_USER_TARGET() && !IS_DUMP_TARGET())
  176. #define IS_LIVE_KERNEL_TARGET() \
  177. (IS_KERNEL_TARGET() && !IS_DUMP_TARGET())
  178. #define IS_REMOTE_USER_TARGET() \
  179. (IS_USER_TARGET() && \
  180. g_TargetClassQualifier == DEBUG_USER_WINDOWS_PROCESS_SERVER)
  181. #define IS_LOCAL_USER_TARGET() \
  182. (IS_USER_TARGET() && \
  183. g_TargetClassQualifier != DEBUG_USER_WINDOWS_PROCESS_SERVER)
  184. // Local kernels do not need caching. Anything else does.
  185. #define IS_REMOTE_KERNEL_TARGET() \
  186. (IS_LIVE_KERNEL_TARGET() && g_TargetClassQualifier != DEBUG_KERNEL_LOCAL)
  187. // g_TargetMachineType is sometimes set before InitializeMachine
  188. // is called so it can't be used as a direct check for
  189. // initialization. Instead a separate, clean initialization
  190. // variable is used.
  191. // IS_MACHINE_SET == TRUE implies a target is set
  192. // since it isn't possible to determine the machine type
  193. // without knowing the target.
  194. #define IS_MACHINE_SET() g_MachineInitialized
  195. // Checks whether the debuggee is in a state where it
  196. // can be examined. This requires that the debuggee is known
  197. // and paused so that its state is available.
  198. #define IS_MACHINE_ACCESSIBLE() \
  199. (IS_MACHINE_SET() && !IS_RUNNING(g_CmdState) && \
  200. g_CurrentProcess != NULL && g_CurrentProcess->CurrentThread != NULL)
  201. // Further restricts the check to just context state as a
  202. // local kernel session can examine memory and therefore is
  203. // accessible but it does not have a context.
  204. #define IS_CONTEXT_ACCESSIBLE() \
  205. (IS_MACHINE_ACCESSIBLE() && !IS_LOCAL_KERNEL_TARGET())
  206. // Simpler context check for code which may be on the suspend/
  207. // resume path and therefore may be in the middle of initializing
  208. // the variables that IS_CONTEXT_ACCESSIBLE checks. This
  209. // macro just checks whether it's possible to get any
  210. // context information.
  211. #define IS_CONTEXT_POSSIBLE() \
  212. (g_RegContextThread != NULL && !IS_LOCAL_KERNEL_TARGET())
  213. // Dumps and local kernel sessions cannot ever support
  214. // execution so disallow execution commands for them.
  215. #define IS_EXECUTION_POSSIBLE() \
  216. (!(IS_DUMP_TARGET() || IS_LOCAL_KERNEL_TARGET()))
  217. //
  218. // System version is an internal abstraction of build numbers
  219. // and product types. The only requirement is that within
  220. // a specific system family the numbers increase for newer
  221. // systems.
  222. //
  223. // Most of the debugger code is built around NT system versions
  224. // so there's a SystemVersion variable which is always an
  225. // NT system version. The ActualSystemVersion contains the
  226. // true system version which gets mapped into a compatible NT
  227. // system version for SystemVersion.
  228. //
  229. enum
  230. {
  231. SVER_INVALID = 0,
  232. NT_SVER_START = 4 * 1024,
  233. NT_SVER_NT4,
  234. NT_SVER_W2K_RC3,
  235. NT_SVER_W2K,
  236. NT_SVER_W2K_WHISTLER,
  237. NT_SVER_END,
  238. W9X_SVER_START = 8 * 1024,
  239. W9X_SVER_W95,
  240. W9X_SVER_W98,
  241. W9X_SVER_W98SE,
  242. W9X_SVER_WME,
  243. W9X_SVER_END,
  244. XBOX_SVER_START = 12 * 1024,
  245. XBOX_SVER_1,
  246. XBOX_SVER_END,
  247. BIG_SVER_START = 16 * 1024,
  248. BIG_SVER_1,
  249. BIG_SVER_END,
  250. EXDI_SVER_START = 20 * 1024,
  251. EXDI_SVER_1,
  252. EXDI_SVER_END,
  253. NTBD_SVER_START = 24 * 1024,
  254. NTBD_SVER_W2K_WHISTLER,
  255. NTBD_SVER_END,
  256. EFI_SVER_START = 28 * 1024,
  257. EFI_SVER_1,
  258. EFI_SVER_END,
  259. };
  260. // KD version MajorVersion high-byte identifiers.
  261. enum
  262. {
  263. KD_MAJOR_NT,
  264. KD_MAJOR_XBOX,
  265. KD_MAJOR_BIG,
  266. KD_MAJOR_EXDI,
  267. KD_MAJOR_NTBD,
  268. KD_MAJOR_EFI,
  269. KD_MAJOR_COUNT
  270. };
  271. extern ULONG g_SystemVersion;
  272. extern ULONG g_ActualSystemVersion;
  273. extern ULONG g_TargetCheckedBuild;
  274. extern ULONG g_TargetBuildNumber;
  275. extern BOOL g_MachineInitialized;
  276. extern ULONG g_TargetMachineType;
  277. extern ULONG g_TargetExecMachine;
  278. extern ULONG g_TargetPlatformId;
  279. extern char g_TargetServicePackString[MAX_PATH];
  280. extern ULONG g_TargetServicePackNumber;
  281. extern char g_TargetBuildLabName[272];
  282. extern ULONG g_TargetNumberProcessors;
  283. extern ULONG g_TargetClass;
  284. extern ULONG g_TargetClassQualifier;
  285. //----------------------------------------------------------------------------
  286. //
  287. // Convenience routines.
  288. //
  289. //----------------------------------------------------------------------------
  290. extern ULONG g_TmpCount;
  291. #define ReadVirt(Offset, Var) \
  292. (g_Target->ReadVirtual(Offset, &(Var), sizeof(Var), \
  293. &g_TmpCount) == S_OK && g_TmpCount == sizeof(Var))
  294. #define WriteVirt(Offset, Var) \
  295. (g_Target->WriteVirtual(Offset, &(Var), sizeof(Var), \
  296. &g_TmpCount) == S_OK && g_TmpCount == sizeof(Var))
  297. //----------------------------------------------------------------------------
  298. //
  299. // This class abstracts processing of target-class-dependent
  300. // information. g_Target is set to the appropriate implementation
  301. // once the class of target is known.
  302. //
  303. //----------------------------------------------------------------------------
  304. class TargetInfo
  305. {
  306. public:
  307. //
  308. // Pure abstraction methods.
  309. // Unless otherwise indicated, base implementations give
  310. // an error message and return E_UNEXPECTED.
  311. //
  312. virtual HRESULT Initialize(void);
  313. // Base implementation does nothing.
  314. virtual void Uninitialize(void);
  315. // Some targets, such as eXDI, require initialization
  316. // per thread. In eXDI's case, it's calling CoInitialize.
  317. // Base implementations do nothing.
  318. virtual HRESULT ThreadInitialize(void);
  319. virtual void ThreadUninitialize(void);
  320. // Determines the next byte offset and next page offset
  321. // that might have different validity than the given offset.
  322. virtual void NearestDifferentlyValidOffsets(ULONG64 Offset,
  323. PULONG64 NextOffset,
  324. PULONG64 NextPage);
  325. virtual HRESULT ReadVirtual(
  326. IN ULONG64 Offset,
  327. OUT PVOID Buffer,
  328. IN ULONG BufferSize,
  329. OUT OPTIONAL PULONG BytesRead
  330. );
  331. virtual HRESULT WriteVirtual(
  332. IN ULONG64 Offset,
  333. IN PVOID Buffer,
  334. IN ULONG BufferSize,
  335. OUT OPTIONAL PULONG BytesWritten
  336. );
  337. // Base implementation layers on ReadVirtual.
  338. virtual HRESULT SearchVirtual(
  339. IN ULONG64 Offset,
  340. IN ULONG64 Length,
  341. IN PVOID Pattern,
  342. IN ULONG PatternSize,
  343. IN ULONG PatternGranularity,
  344. OUT PULONG64 MatchOffset
  345. );
  346. // Base implementations just call Read/WriteVirtual.
  347. virtual HRESULT ReadVirtualUncached(
  348. IN ULONG64 Offset,
  349. OUT PVOID Buffer,
  350. IN ULONG BufferSize,
  351. OUT OPTIONAL PULONG BytesRead
  352. );
  353. virtual HRESULT WriteVirtualUncached(
  354. IN ULONG64 Offset,
  355. IN PVOID Buffer,
  356. IN ULONG BufferSize,
  357. OUT OPTIONAL PULONG BytesWritten
  358. );
  359. virtual HRESULT ReadPhysical(
  360. IN ULONG64 Offset,
  361. OUT PVOID Buffer,
  362. IN ULONG BufferSize,
  363. OUT OPTIONAL PULONG BytesRead
  364. );
  365. virtual HRESULT WritePhysical(
  366. IN ULONG64 Offset,
  367. IN PVOID Buffer,
  368. IN ULONG BufferSize,
  369. OUT OPTIONAL PULONG BytesWritten
  370. );
  371. // Base implementations just call Read/WritePhysical.
  372. virtual HRESULT ReadPhysicalUncached(
  373. IN ULONG64 Offset,
  374. OUT PVOID Buffer,
  375. IN ULONG BufferSize,
  376. OUT OPTIONAL PULONG BytesRead
  377. );
  378. virtual HRESULT WritePhysicalUncached(
  379. IN ULONG64 Offset,
  380. IN PVOID Buffer,
  381. IN ULONG BufferSize,
  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 ULONG64 Handle,
  451. IN ULONG DataType,
  452. OUT OPTIONAL PVOID Buffer,
  453. IN ULONG BufferSize,
  454. OUT OPTIONAL PULONG DataSize
  455. );
  456. // Base implementations layer on WriteVirtual/Physical.
  457. virtual HRESULT FillVirtual(
  458. THIS_
  459. IN ULONG64 Start,
  460. IN ULONG Size,
  461. IN PVOID Pattern,
  462. IN ULONG PatternSize,
  463. OUT PULONG Filled
  464. );
  465. virtual HRESULT FillPhysical(
  466. THIS_
  467. IN ULONG64 Start,
  468. IN ULONG Size,
  469. IN PVOID Pattern,
  470. IN ULONG PatternSize,
  471. OUT PULONG Filled
  472. );
  473. virtual HRESULT GetProcessorId
  474. (ULONG Processor, PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id);
  475. // Base implementation silently fails as many targets do
  476. // not support this.
  477. virtual HRESULT ReadPageFile(ULONG PfIndex, ULONG64 PfOffset,
  478. PVOID Buffer, ULONG Size);
  479. virtual HRESULT GetFunctionTableListHead(void);
  480. virtual PVOID FindDynamicFunctionEntry(MachineInfo* Machine,
  481. ULONG64 Address);
  482. virtual ULONG64 GetDynamicFunctionTableBase(MachineInfo* Machine,
  483. ULONG64 Address);
  484. virtual HRESULT ReadOutOfProcessDynamicFunctionTable(PWSTR Dll,
  485. ULONG64 Table,
  486. PULONG TableSize,
  487. PVOID* TableData);
  488. static PVOID CALLBACK DynamicFunctionTableCallback(HANDLE Process,
  489. ULONG64 Address,
  490. ULONG64 Context);
  491. virtual HRESULT GetTargetContext(
  492. ULONG64 Thread,
  493. PVOID Context
  494. );
  495. virtual HRESULT SetTargetContext(
  496. ULONG64 Thread,
  497. PVOID Context
  498. );
  499. // Retrieves segment register descriptors if they are available
  500. // directly. Invalid descriptors may be returned, indicating
  501. // either segment registers aren't supported or that the
  502. // descriptors must be looked up in descriptor tables.
  503. // Base implementation returns invalid descriptors.
  504. virtual HRESULT GetTargetSegRegDescriptors(ULONG64 Thread,
  505. ULONG Start, ULONG Count,
  506. PDESCRIPTOR64 Descs);
  507. // Base implementations call Read/WriteSpecialRegisters.
  508. virtual HRESULT GetTargetSpecialRegisters
  509. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  510. virtual HRESULT SetTargetSpecialRegisters
  511. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  512. // Called when the current context state is being
  513. // discarded so that caches can be flushed.
  514. // Base implementation does nothing.
  515. virtual void InvalidateTargetContext(void);
  516. virtual HRESULT GetThreadIdByProcessor(
  517. IN ULONG Processor,
  518. OUT PULONG Id
  519. );
  520. // This method takes both a PTHREAD_INFO and a "handle"
  521. // to make things simpler for the kernel thread-to-processor
  522. // mapping. If Thread is NULL processor must be a processor
  523. // index in kernel mode or a thread handle in user mode.
  524. virtual HRESULT GetThreadInfoDataOffset(PTHREAD_INFO Thread,
  525. ULONG64 ThreadHandle,
  526. PULONG64 Offset);
  527. // In theory this method should take a PPROCESS_INFO.
  528. // Due to the current kernel process and thread structure
  529. // where there's only a kernel process and threads per
  530. // processor such a call would be useless in kernel mode.
  531. // Instead it allows you to either get the process data
  532. // for a thread of that process or get the process data
  533. // from a thread data.
  534. virtual HRESULT GetProcessInfoDataOffset(PTHREAD_INFO Thread,
  535. ULONG Processor,
  536. ULONG64 ThreadData,
  537. PULONG64 Offset);
  538. virtual HRESULT GetThreadInfoTeb(PTHREAD_INFO Thread,
  539. ULONG Processor,
  540. ULONG64 ThreadData,
  541. PULONG64 Offset);
  542. virtual HRESULT GetProcessInfoPeb(PTHREAD_INFO Thread,
  543. ULONG Processor,
  544. ULONG64 ThreadData,
  545. PULONG64 Offset);
  546. // This is on target rather than machine since it has
  547. // both user and kernel variations and the implementations
  548. // don't have much processor-specific code in them.
  549. virtual HRESULT GetSelDescriptor(class MachineInfo* Machine,
  550. ULONG64 Thread, ULONG Selector,
  551. PDESCRIPTOR64 Desc);
  552. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  553. virtual HRESULT ReadBugCheckData(PULONG Code, ULONG64 Args[4]);
  554. virtual HRESULT OutputVersion(void);
  555. virtual HRESULT OutputTime(void);
  556. virtual ModuleInfo* GetModuleInfo(BOOL UserMode);
  557. virtual UnloadedModuleInfo* GetUnloadedModuleInfo(void);
  558. // Image can be identified either by its path or base address.
  559. virtual HRESULT GetImageVersionInformation(PCSTR ImagePath,
  560. ULONG64 ImageBase,
  561. PCSTR Item,
  562. PVOID Buffer, ULONG BufferSize,
  563. PULONG VerInfoSize);
  564. virtual HRESULT Reload(PCSTR Args);
  565. virtual HRESULT GetExceptionContext(PCROSS_PLATFORM_CONTEXT Context);
  566. virtual ULONG64 GetCurrentTimeDateN(void);
  567. virtual ULONG64 GetCurrentSystemUpTimeN(void);
  568. virtual ULONG64 GetProcessUpTimeN(ULONG64 Process);
  569. virtual void InitializeWatchTrace(void);
  570. virtual void ProcessWatchTraceEvent(PDBGKD_TRACE_DATA TraceData,
  571. ADDR PcAddr);
  572. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout);
  573. virtual HRESULT RequestBreakIn(void);
  574. virtual HRESULT Reboot(void);
  575. virtual HRESULT InsertCodeBreakpoint(PPROCESS_INFO Process,
  576. class MachineInfo* Machine,
  577. PADDR Addr,
  578. PUCHAR StorageSpace);
  579. virtual HRESULT RemoveCodeBreakpoint(PPROCESS_INFO Process,
  580. class MachineInfo* Machine,
  581. PADDR Addr,
  582. PUCHAR StorageSpace);
  583. // Returns information similar to VirtualQueryEx for
  584. // user-mode targets. Used when writing dump files.
  585. virtual HRESULT QueryMemoryRegion(PULONG64 Handle,
  586. BOOL HandleIsOffset,
  587. PMEMORY_BASIC_INFORMATION64 Info);
  588. // Returns information about the kind of memory the
  589. // given address refers to.
  590. // Base implementation returns rwx with process for
  591. // user-mode and kernel for kernel mode. In other words,
  592. // the least restrictive settings.
  593. virtual HRESULT QueryAddressInformation(ULONG64 Address, ULONG InSpace,
  594. PULONG OutSpace, PULONG OutFlags);
  595. //
  596. // Layered methods. These are usually common code that
  597. // use pure methods to do their work.
  598. //
  599. HRESULT ReadAllVirtual(ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  600. {
  601. HRESULT Status;
  602. ULONG Done;
  603. if ((Status = ReadVirtual(Address, Buffer, BufferSize, &Done)) == S_OK
  604. && Done != BufferSize)
  605. {
  606. Status = HRESULT_FROM_WIN32(ERROR_READ_FAULT);
  607. }
  608. return Status;
  609. }
  610. HRESULT WriteAllVirtual(ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  611. {
  612. HRESULT Status;
  613. ULONG Done;
  614. if ((Status = WriteVirtual(Address, Buffer, BufferSize, &Done)) == S_OK
  615. && Done != BufferSize)
  616. {
  617. Status = HRESULT_FROM_WIN32(ERROR_WRITE_FAULT);
  618. }
  619. return Status;
  620. }
  621. HRESULT ReadAllPhysical(ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  622. {
  623. HRESULT Status;
  624. ULONG Done;
  625. if ((Status = ReadPhysical(Address, Buffer, BufferSize, &Done)) == S_OK
  626. && Done != BufferSize)
  627. {
  628. Status = HRESULT_FROM_WIN32(ERROR_READ_FAULT);
  629. }
  630. return Status;
  631. }
  632. HRESULT WriteAllPhysical(ULONG64 Address, PVOID Buffer, ULONG BufferSize)
  633. {
  634. HRESULT Status;
  635. ULONG Done;
  636. if ((Status = WritePhysical(Address, Buffer, BufferSize,
  637. &Done)) == S_OK
  638. && Done != BufferSize)
  639. {
  640. Status = HRESULT_FROM_WIN32(ERROR_WRITE_FAULT);
  641. }
  642. return Status;
  643. }
  644. HRESULT ReadPointer(MachineInfo* Machine,
  645. ULONG64 Address, PULONG64 PointerValue);
  646. HRESULT WritePointer(MachineInfo* Machine,
  647. ULONG64 Address, ULONG64 PointerValue);
  648. HRESULT ReadListEntry(MachineInfo* Machine,
  649. ULONG64 Address, PLIST_ENTRY64 List);
  650. HRESULT ReadLoaderEntry(MachineInfo* Machine,
  651. ULONG64 Address, PKLDR_DATA_TABLE_ENTRY64 Entry);
  652. HRESULT ReadUnicodeString(MachineInfo* Machine,
  653. ULONG64 Address, PUNICODE_STRING64 String);
  654. HRESULT ReadDirectoryTableBase(PULONG64 DirBase);
  655. HRESULT ReadSharedUserTimeDateN(PULONG64 TimeDate);
  656. HRESULT ReadSharedUserUpTimeN(PULONG64 UpTime);
  657. HRESULT ReadImageVersionInfo(ULONG64 ImageBase,
  658. PCSTR Item,
  659. PVOID Buffer,
  660. ULONG BufferSize,
  661. PULONG VerInfoSize,
  662. PIMAGE_DATA_DIRECTORY ResDataDir);
  663. HRESULT ReadImplicitThreadInfoPointer(ULONG Offset, PULONG64 Ptr);
  664. HRESULT ReadImplicitProcessInfoPointer(ULONG Offset, PULONG64 Ptr);
  665. // Internal routines which provide canonical context input
  666. // and output, applying any necessary conversions before
  667. // or after calling Get/SetTargetContext.
  668. HRESULT GetContext(
  669. ULONG64 Thread,
  670. PCROSS_PLATFORM_CONTEXT Context
  671. );
  672. HRESULT SetContext(
  673. ULONG64 Thread,
  674. PCROSS_PLATFORM_CONTEXT Context
  675. );
  676. // Calls GetTargetKdVersion on g_KdVersion and outputs the content.
  677. void GetKdVersion(void);
  678. // Internal implementations based on user or kernel
  679. // registers and data. Placed here for sharing between
  680. // live and dump sessions rather than using multiple
  681. // inheritance.
  682. HRESULT KdGetThreadInfoDataOffset(PTHREAD_INFO Thread,
  683. ULONG64 ThreadHandle,
  684. PULONG64 Offset);
  685. HRESULT KdGetProcessInfoDataOffset(PTHREAD_INFO Thread,
  686. ULONG Processor,
  687. ULONG64 ThreadData,
  688. PULONG64 Offset);
  689. HRESULT KdGetThreadInfoTeb(PTHREAD_INFO Thread,
  690. ULONG Processor,
  691. ULONG64 ThreadData,
  692. PULONG64 Offset);
  693. HRESULT KdGetProcessInfoPeb(PTHREAD_INFO Thread,
  694. ULONG Processor,
  695. ULONG64 ThreadData,
  696. PULONG64 Offset);
  697. HRESULT KdGetSelDescriptor(class MachineInfo* Machine,
  698. ULONG64 Thread, ULONG Selector,
  699. PDESCRIPTOR64 Desc);
  700. };
  701. // Base failure behaviors for when a specific target isn't selected.
  702. extern TargetInfo g_UnexpectedTarget;
  703. extern TargetInfo* g_Target;
  704. //----------------------------------------------------------------------------
  705. //
  706. // LiveKernelTargetInfo.
  707. //
  708. //----------------------------------------------------------------------------
  709. class LiveKernelTargetInfo : public TargetInfo
  710. {
  711. public:
  712. // TargetInfo.
  713. virtual HRESULT Initialize(void);
  714. virtual HRESULT GetProcessorId
  715. (ULONG Processor, PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id);
  716. virtual HRESULT GetThreadIdByProcessor(
  717. IN ULONG Processor,
  718. OUT PULONG Id
  719. );
  720. virtual HRESULT GetThreadInfoDataOffset(PTHREAD_INFO Thread,
  721. ULONG64 ThreadHandle,
  722. PULONG64 Offset);
  723. virtual HRESULT GetProcessInfoDataOffset(PTHREAD_INFO Thread,
  724. ULONG Processor,
  725. ULONG64 ThreadData,
  726. PULONG64 Offset);
  727. virtual HRESULT GetThreadInfoTeb(PTHREAD_INFO Thread,
  728. ULONG Processor,
  729. ULONG64 ThreadData,
  730. PULONG64 Offset);
  731. virtual HRESULT GetProcessInfoPeb(PTHREAD_INFO Thread,
  732. ULONG Processor,
  733. ULONG64 ThreadData,
  734. PULONG64 Offset);
  735. virtual HRESULT GetSelDescriptor(class MachineInfo* Machine,
  736. ULONG64 Thread, ULONG Selector,
  737. PDESCRIPTOR64 Desc);
  738. virtual HRESULT ReadBugCheckData(PULONG Code, ULONG64 Args[4]);
  739. virtual ULONG64 GetCurrentTimeDateN(void);
  740. virtual ULONG64 GetCurrentSystemUpTimeN(void);
  741. // LiveKernelTargetInfo.
  742. // Options are only valid in Initialize.
  743. PCSTR m_ConnectOptions;
  744. };
  745. //----------------------------------------------------------------------------
  746. //
  747. // ConnLiveKernelTargetInfo.
  748. //
  749. //----------------------------------------------------------------------------
  750. class ConnLiveKernelTargetInfo : public LiveKernelTargetInfo
  751. {
  752. public:
  753. // TargetInfo.
  754. virtual HRESULT Initialize(void);
  755. virtual void Uninitialize(void);
  756. virtual HRESULT ReadVirtual(
  757. IN ULONG64 Offset,
  758. OUT PVOID Buffer,
  759. IN ULONG BufferSize,
  760. OUT OPTIONAL PULONG BytesRead
  761. );
  762. virtual HRESULT WriteVirtual(
  763. IN ULONG64 Offset,
  764. IN PVOID Buffer,
  765. IN ULONG BufferSize,
  766. OUT OPTIONAL PULONG BytesWritten
  767. );
  768. virtual HRESULT SearchVirtual(
  769. IN ULONG64 Offset,
  770. IN ULONG64 Length,
  771. IN PVOID Pattern,
  772. IN ULONG PatternSize,
  773. IN ULONG PatternGranularity,
  774. OUT PULONG64 MatchOffset
  775. );
  776. virtual HRESULT ReadVirtualUncached(
  777. IN ULONG64 Offset,
  778. OUT PVOID Buffer,
  779. IN ULONG BufferSize,
  780. OUT OPTIONAL PULONG BytesRead
  781. );
  782. virtual HRESULT WriteVirtualUncached(
  783. IN ULONG64 Offset,
  784. IN PVOID Buffer,
  785. IN ULONG BufferSize,
  786. OUT OPTIONAL PULONG BytesWritten
  787. );
  788. virtual HRESULT ReadPhysical(
  789. IN ULONG64 Offset,
  790. OUT PVOID Buffer,
  791. IN ULONG BufferSize,
  792. OUT OPTIONAL PULONG BytesRead
  793. );
  794. virtual HRESULT WritePhysical(
  795. IN ULONG64 Offset,
  796. IN PVOID Buffer,
  797. IN ULONG BufferSize,
  798. OUT OPTIONAL PULONG BytesWritten
  799. );
  800. virtual HRESULT ReadPhysicalUncached(
  801. IN ULONG64 Offset,
  802. OUT PVOID Buffer,
  803. IN ULONG BufferSize,
  804. OUT OPTIONAL PULONG BytesRead
  805. );
  806. virtual HRESULT WritePhysicalUncached(
  807. IN ULONG64 Offset,
  808. IN PVOID Buffer,
  809. IN ULONG BufferSize,
  810. OUT OPTIONAL PULONG BytesWritten
  811. );
  812. virtual HRESULT ReadControl(
  813. IN ULONG Processor,
  814. IN ULONG64 Offset,
  815. OUT PVOID Buffer,
  816. IN ULONG BufferSize,
  817. OUT OPTIONAL PULONG BytesRead
  818. );
  819. virtual HRESULT WriteControl(
  820. IN ULONG Processor,
  821. IN ULONG64 Offset,
  822. IN PVOID Buffer,
  823. IN ULONG BufferSize,
  824. OUT OPTIONAL PULONG BytesWritten
  825. );
  826. virtual HRESULT ReadIo(
  827. IN ULONG InterfaceType,
  828. IN ULONG BusNumber,
  829. IN ULONG AddressSpace,
  830. IN ULONG64 Offset,
  831. OUT PVOID Buffer,
  832. IN ULONG BufferSize,
  833. OUT OPTIONAL PULONG BytesRead
  834. );
  835. virtual HRESULT WriteIo(
  836. IN ULONG InterfaceType,
  837. IN ULONG BusNumber,
  838. IN ULONG AddressSpace,
  839. IN ULONG64 Offset,
  840. IN PVOID Buffer,
  841. IN ULONG BufferSize,
  842. OUT OPTIONAL PULONG BytesWritten
  843. );
  844. virtual HRESULT ReadMsr(
  845. IN ULONG Msr,
  846. OUT PULONG64 Value
  847. );
  848. virtual HRESULT WriteMsr(
  849. IN ULONG Msr,
  850. IN ULONG64 Value
  851. );
  852. virtual HRESULT ReadBusData(
  853. IN ULONG BusDataType,
  854. IN ULONG BusNumber,
  855. IN ULONG SlotNumber,
  856. IN ULONG Offset,
  857. OUT PVOID Buffer,
  858. IN ULONG BufferSize,
  859. OUT OPTIONAL PULONG BytesRead
  860. );
  861. virtual HRESULT WriteBusData(
  862. IN ULONG BusDataType,
  863. IN ULONG BusNumber,
  864. IN ULONG SlotNumber,
  865. IN ULONG Offset,
  866. IN PVOID Buffer,
  867. IN ULONG BufferSize,
  868. OUT OPTIONAL PULONG BytesWritten
  869. );
  870. virtual HRESULT CheckLowMemory(
  871. );
  872. virtual HRESULT FillVirtual(
  873. THIS_
  874. IN ULONG64 Start,
  875. IN ULONG Size,
  876. IN PVOID Pattern,
  877. IN ULONG PatternSize,
  878. OUT PULONG Filled
  879. );
  880. virtual HRESULT FillPhysical(
  881. THIS_
  882. IN ULONG64 Start,
  883. IN ULONG Size,
  884. IN PVOID Pattern,
  885. IN ULONG PatternSize,
  886. OUT PULONG Filled
  887. );
  888. virtual HRESULT GetTargetContext(
  889. ULONG64 Thread,
  890. PVOID Context
  891. );
  892. virtual HRESULT SetTargetContext(
  893. ULONG64 Thread,
  894. PVOID Context
  895. );
  896. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  897. virtual void InitializeWatchTrace(void);
  898. virtual void ProcessWatchTraceEvent(PDBGKD_TRACE_DATA TraceData,
  899. ADDR PcAddr);
  900. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout);
  901. virtual HRESULT RequestBreakIn(void);
  902. virtual HRESULT Reboot(void);
  903. virtual HRESULT InsertCodeBreakpoint(PPROCESS_INFO Process,
  904. class MachineInfo* Machine,
  905. PADDR Addr,
  906. PUCHAR StorageSpace);
  907. virtual HRESULT RemoveCodeBreakpoint(PPROCESS_INFO Process,
  908. class MachineInfo* Machine,
  909. PADDR Addr,
  910. PUCHAR StorageSpace);
  911. virtual HRESULT QueryAddressInformation(ULONG64 Address, ULONG InSpace,
  912. PULONG OutSpace, PULONG OutFlags);
  913. };
  914. extern ConnLiveKernelTargetInfo g_ConnLiveKernelTarget;
  915. //----------------------------------------------------------------------------
  916. //
  917. // LocalLiveKernelTargetInfo.
  918. //
  919. //----------------------------------------------------------------------------
  920. class LocalLiveKernelTargetInfo : public LiveKernelTargetInfo
  921. {
  922. public:
  923. // TargetInfo.
  924. virtual HRESULT Initialize(void);
  925. virtual HRESULT ReadVirtual(
  926. IN ULONG64 Offset,
  927. OUT PVOID Buffer,
  928. IN ULONG BufferSize,
  929. OUT OPTIONAL PULONG BytesRead
  930. );
  931. virtual HRESULT WriteVirtual(
  932. IN ULONG64 Offset,
  933. IN PVOID Buffer,
  934. IN ULONG BufferSize,
  935. OUT OPTIONAL PULONG BytesWritten
  936. );
  937. virtual HRESULT ReadPhysical(
  938. IN ULONG64 Offset,
  939. OUT PVOID Buffer,
  940. IN ULONG BufferSize,
  941. OUT OPTIONAL PULONG BytesRead
  942. );
  943. virtual HRESULT WritePhysical(
  944. IN ULONG64 Offset,
  945. IN PVOID Buffer,
  946. IN ULONG BufferSize,
  947. OUT OPTIONAL PULONG BytesWritten
  948. );
  949. virtual HRESULT ReadControl(
  950. IN ULONG Processor,
  951. IN ULONG64 Offset,
  952. OUT PVOID Buffer,
  953. IN ULONG BufferSize,
  954. OUT OPTIONAL PULONG BytesRead
  955. );
  956. virtual HRESULT WriteControl(
  957. IN ULONG Processor,
  958. IN ULONG64 Offset,
  959. IN PVOID Buffer,
  960. IN ULONG BufferSize,
  961. OUT OPTIONAL PULONG BytesWritten
  962. );
  963. virtual HRESULT ReadIo(
  964. IN ULONG InterfaceType,
  965. IN ULONG BusNumber,
  966. IN ULONG AddressSpace,
  967. IN ULONG64 Offset,
  968. OUT PVOID Buffer,
  969. IN ULONG BufferSize,
  970. OUT OPTIONAL PULONG BytesRead
  971. );
  972. virtual HRESULT WriteIo(
  973. IN ULONG InterfaceType,
  974. IN ULONG BusNumber,
  975. IN ULONG AddressSpace,
  976. IN ULONG64 Offset,
  977. IN PVOID Buffer,
  978. IN ULONG BufferSize,
  979. OUT OPTIONAL PULONG BytesWritten
  980. );
  981. virtual HRESULT ReadMsr(
  982. IN ULONG Msr,
  983. OUT PULONG64 Value
  984. );
  985. virtual HRESULT WriteMsr(
  986. IN ULONG Msr,
  987. IN ULONG64 Value
  988. );
  989. virtual HRESULT ReadBusData(
  990. IN ULONG BusDataType,
  991. IN ULONG BusNumber,
  992. IN ULONG SlotNumber,
  993. IN ULONG Offset,
  994. OUT PVOID Buffer,
  995. IN ULONG BufferSize,
  996. OUT OPTIONAL PULONG BytesRead
  997. );
  998. virtual HRESULT WriteBusData(
  999. IN ULONG BusDataType,
  1000. IN ULONG BusNumber,
  1001. IN ULONG SlotNumber,
  1002. IN ULONG Offset,
  1003. IN PVOID Buffer,
  1004. IN ULONG BufferSize,
  1005. OUT OPTIONAL PULONG BytesWritten
  1006. );
  1007. virtual HRESULT CheckLowMemory(
  1008. );
  1009. virtual HRESULT GetTargetContext(
  1010. ULONG64 Thread,
  1011. PVOID Context
  1012. );
  1013. virtual HRESULT SetTargetContext(
  1014. ULONG64 Thread,
  1015. PVOID Context
  1016. );
  1017. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  1018. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout);
  1019. };
  1020. extern LocalLiveKernelTargetInfo g_LocalLiveKernelTarget;
  1021. //----------------------------------------------------------------------------
  1022. //
  1023. // ExdiLiveKernelTargetInfo.
  1024. //
  1025. //----------------------------------------------------------------------------
  1026. class ExdiNotifyRunChange : public IeXdiClientNotifyRunChg
  1027. {
  1028. public:
  1029. HRESULT Initialize(void);
  1030. void Uninitialize(void);
  1031. // IUnknown.
  1032. STDMETHOD(QueryInterface)(
  1033. THIS_
  1034. IN REFIID InterfaceId,
  1035. OUT PVOID* Interface
  1036. );
  1037. STDMETHOD_(ULONG, AddRef)(
  1038. THIS
  1039. );
  1040. STDMETHOD_(ULONG, Release)(
  1041. THIS
  1042. );
  1043. // IeXdiClientNotifyRunChg.
  1044. STDMETHOD(NotifyRunStateChange)(RUN_STATUS_TYPE ersCurrent,
  1045. HALT_REASON_TYPE ehrCurrent,
  1046. ADDRESS_TYPE CurrentExecAddress,
  1047. DWORD dwExceptionCode);
  1048. // ExdiNotifyRunChange.
  1049. HANDLE m_Event;
  1050. HALT_REASON_TYPE m_HaltReason;
  1051. ADDRESS_TYPE m_ExecAddress;
  1052. ULONG m_ExceptionCode;
  1053. };
  1054. typedef union _EXDI_CONTEXT
  1055. {
  1056. CONTEXT_X86 X86Context;
  1057. CONTEXT_X86_64 Amd64Context;
  1058. } EXDI_CONTEXT, *PEXDI_CONTEXT;
  1059. enum EXDI_KD_SUPPORT
  1060. {
  1061. EXDI_KD_NONE,
  1062. EXDI_KD_IOCTL,
  1063. EXDI_KD_GS_PCR
  1064. };
  1065. class ExdiLiveKernelTargetInfo : public LiveKernelTargetInfo
  1066. {
  1067. public:
  1068. // TargetInfo.
  1069. virtual HRESULT Initialize(void);
  1070. virtual void Uninitialize(void);
  1071. virtual HRESULT ThreadInitialize(void);
  1072. virtual void ThreadUninitialize(void);
  1073. virtual HRESULT ReadVirtual(
  1074. IN ULONG64 Offset,
  1075. OUT PVOID Buffer,
  1076. IN ULONG BufferSize,
  1077. OUT OPTIONAL PULONG BytesRead
  1078. );
  1079. virtual HRESULT WriteVirtual(
  1080. IN ULONG64 Offset,
  1081. IN PVOID Buffer,
  1082. IN ULONG BufferSize,
  1083. OUT OPTIONAL PULONG BytesWritten
  1084. );
  1085. virtual HRESULT ReadPhysical(
  1086. IN ULONG64 Offset,
  1087. OUT PVOID Buffer,
  1088. IN ULONG BufferSize,
  1089. OUT OPTIONAL PULONG BytesRead
  1090. );
  1091. virtual HRESULT WritePhysical(
  1092. IN ULONG64 Offset,
  1093. IN PVOID Buffer,
  1094. IN ULONG BufferSize,
  1095. OUT OPTIONAL PULONG BytesWritten
  1096. );
  1097. virtual HRESULT ReadControl(
  1098. IN ULONG Processor,
  1099. IN ULONG64 Offset,
  1100. OUT PVOID Buffer,
  1101. IN ULONG BufferSize,
  1102. OUT OPTIONAL PULONG BytesRead
  1103. );
  1104. virtual HRESULT WriteControl(
  1105. IN ULONG Processor,
  1106. IN ULONG64 Offset,
  1107. IN PVOID Buffer,
  1108. IN ULONG BufferSize,
  1109. OUT OPTIONAL PULONG BytesWritten
  1110. );
  1111. virtual HRESULT ReadIo(
  1112. IN ULONG InterfaceType,
  1113. IN ULONG BusNumber,
  1114. IN ULONG AddressSpace,
  1115. IN ULONG64 Offset,
  1116. OUT PVOID Buffer,
  1117. IN ULONG BufferSize,
  1118. OUT OPTIONAL PULONG BytesRead
  1119. );
  1120. virtual HRESULT WriteIo(
  1121. IN ULONG InterfaceType,
  1122. IN ULONG BusNumber,
  1123. IN ULONG AddressSpace,
  1124. IN ULONG64 Offset,
  1125. IN PVOID Buffer,
  1126. IN ULONG BufferSize,
  1127. OUT OPTIONAL PULONG BytesWritten
  1128. );
  1129. virtual HRESULT ReadMsr(
  1130. IN ULONG Msr,
  1131. OUT PULONG64 Value
  1132. );
  1133. virtual HRESULT WriteMsr(
  1134. IN ULONG Msr,
  1135. IN ULONG64 Value
  1136. );
  1137. virtual HRESULT ReadBusData(
  1138. IN ULONG BusDataType,
  1139. IN ULONG BusNumber,
  1140. IN ULONG SlotNumber,
  1141. IN ULONG Offset,
  1142. OUT PVOID Buffer,
  1143. IN ULONG BufferSize,
  1144. OUT OPTIONAL PULONG BytesRead
  1145. );
  1146. virtual HRESULT WriteBusData(
  1147. IN ULONG BusDataType,
  1148. IN ULONG BusNumber,
  1149. IN ULONG SlotNumber,
  1150. IN ULONG Offset,
  1151. IN PVOID Buffer,
  1152. IN ULONG BufferSize,
  1153. OUT OPTIONAL PULONG BytesWritten
  1154. );
  1155. virtual HRESULT GetProcessorSystemDataOffset(
  1156. IN ULONG Processor,
  1157. IN ULONG Index,
  1158. OUT PULONG64 Offset
  1159. );
  1160. virtual HRESULT CheckLowMemory(
  1161. );
  1162. virtual HRESULT GetTargetContext(
  1163. ULONG64 Thread,
  1164. PVOID Context
  1165. );
  1166. virtual HRESULT SetTargetContext(
  1167. ULONG64 Thread,
  1168. PVOID Context
  1169. );
  1170. virtual HRESULT GetTargetSegRegDescriptors(ULONG64 Thread,
  1171. ULONG Start, ULONG Count,
  1172. PDESCRIPTOR64 Descs);
  1173. virtual HRESULT GetTargetSpecialRegisters
  1174. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  1175. virtual HRESULT SetTargetSpecialRegisters
  1176. (ULONG64 Thread, PCROSS_PLATFORM_KSPECIAL_REGISTERS Special);
  1177. virtual void InvalidateTargetContext(void);
  1178. virtual HRESULT GetTargetKdVersion(PDBGKD_GET_VERSION64 Version);
  1179. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout);
  1180. virtual HRESULT RequestBreakIn(void);
  1181. virtual HRESULT Reboot(void);
  1182. virtual HRESULT InsertCodeBreakpoint(PPROCESS_INFO Process,
  1183. class MachineInfo* Machine,
  1184. PADDR Addr,
  1185. PUCHAR StorageSpace);
  1186. virtual HRESULT RemoveCodeBreakpoint(PPROCESS_INFO Process,
  1187. class MachineInfo* Machine,
  1188. PADDR Addr,
  1189. PUCHAR StorageSpace);
  1190. // ExdiLiveKernelTargetInfo.
  1191. IeXdiServer* m_Server;
  1192. IUnknown* m_Context;
  1193. ULONG m_ContextValid;
  1194. EXDI_CONTEXT m_ContextData;
  1195. GLOBAL_TARGET_INFO_STRUCT m_GlobalInfo;
  1196. EXDI_KD_SUPPORT m_KdSupport;
  1197. BOOL m_ForceX86;
  1198. ULONG m_ExpectedMachine;
  1199. CBP_KIND m_CodeBpType;
  1200. ExdiNotifyRunChange m_RunChange;
  1201. };
  1202. extern ExdiLiveKernelTargetInfo g_ExdiLiveKernelTarget;
  1203. //----------------------------------------------------------------------------
  1204. //
  1205. // UserTargetInfo.
  1206. //
  1207. //----------------------------------------------------------------------------
  1208. class UserTargetInfo : public TargetInfo
  1209. {
  1210. public:
  1211. // TargetInfo.
  1212. virtual HRESULT Initialize(void);
  1213. virtual void Uninitialize(void);
  1214. virtual HRESULT ReadVirtualUncached(
  1215. IN ULONG64 Offset,
  1216. OUT PVOID Buffer,
  1217. IN ULONG BufferSize,
  1218. OUT OPTIONAL PULONG BytesRead
  1219. );
  1220. virtual HRESULT WriteVirtualUncached(
  1221. IN ULONG64 Offset,
  1222. IN PVOID Buffer,
  1223. IN ULONG BufferSize,
  1224. OUT OPTIONAL PULONG BytesWritten
  1225. );
  1226. virtual HRESULT ReadHandleData(
  1227. IN ULONG64 Handle,
  1228. IN ULONG DataType,
  1229. OUT OPTIONAL PVOID Buffer,
  1230. IN ULONG BufferSize,
  1231. OUT OPTIONAL PULONG DataSize
  1232. );
  1233. virtual HRESULT GetProcessorId
  1234. (ULONG Processor, PDEBUG_PROCESSOR_IDENTIFICATION_ALL Id);
  1235. virtual HRESULT GetFunctionTableListHead(void);
  1236. virtual HRESULT ReadOutOfProcessDynamicFunctionTable(PWSTR Dll,
  1237. ULONG64 Table,
  1238. PULONG TableSize,
  1239. PVOID* TableData);
  1240. virtual HRESULT GetTargetContext(
  1241. ULONG64 Thread,
  1242. PVOID Context
  1243. );
  1244. virtual HRESULT SetTargetContext(
  1245. ULONG64 Thread,
  1246. PVOID Context
  1247. );
  1248. virtual HRESULT GetThreadInfoDataOffset(PTHREAD_INFO Thread,
  1249. ULONG64 ThreadHandle,
  1250. PULONG64 Offset);
  1251. virtual HRESULT GetProcessInfoDataOffset(PTHREAD_INFO Thread,
  1252. ULONG Processor,
  1253. ULONG64 ThreadData,
  1254. PULONG64 Offset);
  1255. virtual HRESULT GetThreadInfoTeb(PTHREAD_INFO Thread,
  1256. ULONG Processor,
  1257. ULONG64 ThreadData,
  1258. PULONG64 Offset);
  1259. virtual HRESULT GetProcessInfoPeb(PTHREAD_INFO Thread,
  1260. ULONG Processor,
  1261. ULONG64 ThreadData,
  1262. PULONG64 Offset);
  1263. virtual HRESULT GetSelDescriptor(class MachineInfo* Machine,
  1264. ULONG64 Thread, ULONG Selector,
  1265. PDESCRIPTOR64 Desc);
  1266. virtual HRESULT GetImageVersionInformation(PCSTR ImagePath,
  1267. ULONG64 ImageBase,
  1268. PCSTR Item,
  1269. PVOID Buffer, ULONG BufferSize,
  1270. PULONG VerInfoSize);
  1271. virtual ULONG64 GetCurrentTimeDateN(void);
  1272. virtual ULONG64 GetCurrentSystemUpTimeN(void);
  1273. virtual ULONG64 GetProcessUpTimeN(ULONG64 Process);
  1274. virtual void InitializeWatchTrace(void);
  1275. virtual void ProcessWatchTraceEvent(PDBGKD_TRACE_DATA TraceData,
  1276. ADDR PcAddr);
  1277. virtual HRESULT WaitForEvent(ULONG Flags, ULONG Timeout);
  1278. virtual HRESULT RequestBreakIn(void);
  1279. virtual HRESULT InsertCodeBreakpoint(PPROCESS_INFO Process,
  1280. class MachineInfo* Machine,
  1281. PADDR Addr,
  1282. PUCHAR StorageSpace);
  1283. virtual HRESULT RemoveCodeBreakpoint(PPROCESS_INFO Process,
  1284. class MachineInfo* Machine,
  1285. PADDR Addr,
  1286. PUCHAR StorageSpace);
  1287. virtual HRESULT QueryMemoryRegion(PULONG64 Handle,
  1288. BOOL HandleIsOffset,
  1289. PMEMORY_BASIC_INFORMATION64 Info);
  1290. IUserDebugServices* m_Services;
  1291. ULONG m_ServiceFlags;
  1292. };
  1293. class LocalUserTargetInfo : public UserTargetInfo
  1294. {
  1295. public:
  1296. // TargetInfo.
  1297. virtual HRESULT ReadVirtual(
  1298. IN ULONG64 Offset,
  1299. OUT PVOID Buffer,
  1300. IN ULONG BufferSize,
  1301. OUT OPTIONAL PULONG BytesRead
  1302. );
  1303. virtual HRESULT WriteVirtual(
  1304. IN ULONG64 Offset,
  1305. IN PVOID Buffer,
  1306. IN ULONG BufferSize,
  1307. OUT OPTIONAL PULONG BytesWritten
  1308. );
  1309. };
  1310. extern LocalUserTargetInfo g_LocalUserTarget;
  1311. class RemoteUserTargetInfo : public UserTargetInfo
  1312. {
  1313. public:
  1314. // TargetInfo.
  1315. virtual HRESULT ReadVirtual(
  1316. IN ULONG64 Offset,
  1317. OUT PVOID Buffer,
  1318. IN ULONG BufferSize,
  1319. OUT OPTIONAL PULONG BytesRead
  1320. );
  1321. virtual HRESULT WriteVirtual(
  1322. IN ULONG64 Offset,
  1323. IN PVOID Buffer,
  1324. IN ULONG BufferSize,
  1325. OUT OPTIONAL PULONG BytesWritten
  1326. );
  1327. };
  1328. extern RemoteUserTargetInfo g_RemoteUserTarget;
  1329. //----------------------------------------------------------------------------
  1330. //
  1331. // DumpTargetInfo hierarchy is in dump.hpp.
  1332. //
  1333. //----------------------------------------------------------------------------
  1334. #endif // #ifndef __TARGET_HPP__