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.

2254 lines
58 KiB

  1. /*++
  2. Copyright (c) 1992-1999 Microsoft Corporation
  3. Module Name:
  4. wdbgexts.h
  5. Abstract:
  6. This file contains the necessary prototypes and data types for a user
  7. to write a debugger extension DLL. This header file is also included
  8. by the NT debuggers (WINDBG & KD).
  9. This header file must be included after "windows.h" and "dbghelp.h".
  10. Please see the NT DDK documentation for specific information about
  11. how to write your own debugger extension DLL.
  12. Environment:
  13. Win32 only.
  14. Revision History:
  15. --*/
  16. #ifndef _WDBGEXTS_
  17. #define _WDBGEXTS_
  18. #if _MSC_VER > 1000
  19. #pragma once
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #if !defined(WDBGAPI)
  25. #define WDBGAPI __stdcall
  26. #endif
  27. #if !defined(WDBGAPIV)
  28. #define WDBGAPIV __cdecl
  29. #endif
  30. #ifndef _WINDEF_
  31. typedef CONST void *LPCVOID;
  32. #endif
  33. #ifndef _ULONGLONG_
  34. typedef unsigned __int64 ULONGLONG;
  35. typedef ULONGLONG *PULONGLONG;
  36. #endif
  37. typedef
  38. VOID
  39. (WDBGAPIV*PWINDBG_OUTPUT_ROUTINE)(
  40. PCSTR lpFormat,
  41. ...
  42. );
  43. typedef
  44. ULONG_PTR
  45. (WDBGAPI*PWINDBG_GET_EXPRESSION)(
  46. PCSTR lpExpression
  47. );
  48. typedef
  49. ULONG
  50. (WDBGAPI*PWINDBG_GET_EXPRESSION32)(
  51. PCSTR lpExpression
  52. );
  53. typedef
  54. ULONG64
  55. (WDBGAPI*PWINDBG_GET_EXPRESSION64)(
  56. PCSTR lpExpression
  57. );
  58. typedef
  59. VOID
  60. (WDBGAPI*PWINDBG_GET_SYMBOL)(
  61. PVOID offset,
  62. PCHAR pchBuffer,
  63. ULONG_PTR *pDisplacement
  64. );
  65. typedef
  66. VOID
  67. (WDBGAPI*PWINDBG_GET_SYMBOL32)(
  68. ULONG offset,
  69. PCHAR pchBuffer,
  70. PULONG pDisplacement
  71. );
  72. typedef
  73. VOID
  74. (WDBGAPI*PWINDBG_GET_SYMBOL64)(
  75. ULONG64 offset,
  76. PCHAR pchBuffer,
  77. PULONG64 pDisplacement
  78. );
  79. typedef
  80. ULONG
  81. (WDBGAPI*PWINDBG_DISASM)(
  82. ULONG_PTR *lpOffset,
  83. PCSTR lpBuffer,
  84. ULONG fShowEffectiveAddress
  85. );
  86. typedef
  87. ULONG
  88. (WDBGAPI*PWINDBG_DISASM32)(
  89. ULONG *lpOffset,
  90. PCSTR lpBuffer,
  91. ULONG fShowEffectiveAddress
  92. );
  93. typedef
  94. ULONG
  95. (WDBGAPI*PWINDBG_DISASM64)(
  96. ULONG64 *lpOffset,
  97. PCSTR lpBuffer,
  98. ULONG fShowEffectiveAddress
  99. );
  100. typedef
  101. ULONG
  102. (WDBGAPI*PWINDBG_CHECK_CONTROL_C)(
  103. VOID
  104. );
  105. typedef
  106. ULONG
  107. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE)(
  108. ULONG_PTR offset,
  109. PVOID lpBuffer,
  110. ULONG cb,
  111. PULONG lpcbBytesRead
  112. );
  113. typedef
  114. ULONG
  115. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE32)(
  116. ULONG offset,
  117. PVOID lpBuffer,
  118. ULONG cb,
  119. PULONG lpcbBytesRead
  120. );
  121. typedef
  122. ULONG
  123. (WDBGAPI*PWINDBG_READ_PROCESS_MEMORY_ROUTINE64)(
  124. ULONG64 offset,
  125. PVOID lpBuffer,
  126. ULONG cb,
  127. PULONG lpcbBytesRead
  128. );
  129. typedef
  130. ULONG
  131. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE)(
  132. ULONG_PTR offset,
  133. LPCVOID lpBuffer,
  134. ULONG cb,
  135. PULONG lpcbBytesWritten
  136. );
  137. typedef
  138. ULONG
  139. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE32)(
  140. ULONG offset,
  141. LPCVOID lpBuffer,
  142. ULONG cb,
  143. PULONG lpcbBytesWritten
  144. );
  145. typedef
  146. ULONG
  147. (WDBGAPI*PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE64)(
  148. ULONG64 offset,
  149. LPCVOID lpBuffer,
  150. ULONG cb,
  151. PULONG lpcbBytesWritten
  152. );
  153. typedef
  154. ULONG
  155. (WDBGAPI*PWINDBG_GET_THREAD_CONTEXT_ROUTINE)(
  156. ULONG Processor,
  157. PCONTEXT lpContext,
  158. ULONG cbSizeOfContext
  159. );
  160. typedef
  161. ULONG
  162. (WDBGAPI*PWINDBG_SET_THREAD_CONTEXT_ROUTINE)(
  163. ULONG Processor,
  164. PCONTEXT lpContext,
  165. ULONG cbSizeOfContext
  166. );
  167. typedef
  168. ULONG
  169. (WDBGAPI*PWINDBG_IOCTL_ROUTINE)(
  170. USHORT IoctlType,
  171. PVOID lpvData,
  172. ULONG cbSize
  173. );
  174. typedef
  175. ULONG
  176. (WDBGAPI*PWINDBG_OLDKD_READ_PHYSICAL_MEMORY)(
  177. ULONGLONG address,
  178. PVOID buffer,
  179. ULONG count,
  180. PULONG bytesread
  181. );
  182. typedef
  183. ULONG
  184. (WDBGAPI*PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY)(
  185. ULONGLONG address,
  186. PVOID buffer,
  187. ULONG length,
  188. PULONG byteswritten
  189. );
  190. typedef struct _EXTSTACKTRACE {
  191. ULONG FramePointer;
  192. ULONG ProgramCounter;
  193. ULONG ReturnAddress;
  194. ULONG Args[4];
  195. } EXTSTACKTRACE, *PEXTSTACKTRACE;
  196. typedef struct _EXTSTACKTRACE32 {
  197. ULONG FramePointer;
  198. ULONG ProgramCounter;
  199. ULONG ReturnAddress;
  200. ULONG Args[4];
  201. } EXTSTACKTRACE32, *PEXTSTACKTRACE32;
  202. typedef struct _EXTSTACKTRACE64 {
  203. ULONG64 FramePointer;
  204. ULONG64 ProgramCounter;
  205. ULONG64 ReturnAddress;
  206. ULONG64 Args[4];
  207. } EXTSTACKTRACE64, *PEXTSTACKTRACE64;
  208. typedef
  209. ULONG
  210. (*PWINDBG_STACKTRACE_ROUTINE)(
  211. ULONG FramePointer,
  212. ULONG StackPointer,
  213. ULONG ProgramCounter,
  214. PEXTSTACKTRACE StackFrames,
  215. ULONG Frames
  216. );
  217. typedef
  218. ULONG
  219. (*PWINDBG_STACKTRACE_ROUTINE32)(
  220. ULONG FramePointer,
  221. ULONG StackPointer,
  222. ULONG ProgramCounter,
  223. PEXTSTACKTRACE32 StackFrames,
  224. ULONG Frames
  225. );
  226. typedef
  227. ULONG
  228. (*PWINDBG_STACKTRACE_ROUTINE64)(
  229. ULONG64 FramePointer,
  230. ULONG64 StackPointer,
  231. ULONG64 ProgramCounter,
  232. PEXTSTACKTRACE64 StackFrames,
  233. ULONG Frames
  234. );
  235. typedef struct _WINDBG_EXTENSION_APIS {
  236. ULONG nSize;
  237. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  238. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  239. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  240. PWINDBG_DISASM lpDisasmRoutine;
  241. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  242. PWINDBG_READ_PROCESS_MEMORY_ROUTINE lpReadProcessMemoryRoutine;
  243. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE lpWriteProcessMemoryRoutine;
  244. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  245. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  246. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  247. PWINDBG_STACKTRACE_ROUTINE lpStackTraceRoutine;
  248. } WINDBG_EXTENSION_APIS, *PWINDBG_EXTENSION_APIS;
  249. typedef struct _WINDBG_EXTENSION_APIS32 {
  250. ULONG nSize;
  251. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  252. PWINDBG_GET_EXPRESSION32 lpGetExpressionRoutine;
  253. PWINDBG_GET_SYMBOL32 lpGetSymbolRoutine;
  254. PWINDBG_DISASM32 lpDisasmRoutine;
  255. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  256. PWINDBG_READ_PROCESS_MEMORY_ROUTINE32 lpReadProcessMemoryRoutine;
  257. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE32 lpWriteProcessMemoryRoutine;
  258. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  259. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  260. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  261. PWINDBG_STACKTRACE_ROUTINE32 lpStackTraceRoutine;
  262. } WINDBG_EXTENSION_APIS32, *PWINDBG_EXTENSION_APIS32;
  263. typedef struct _WINDBG_EXTENSION_APIS64 {
  264. ULONG nSize;
  265. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  266. PWINDBG_GET_EXPRESSION64 lpGetExpressionRoutine;
  267. PWINDBG_GET_SYMBOL64 lpGetSymbolRoutine;
  268. PWINDBG_DISASM64 lpDisasmRoutine;
  269. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  270. PWINDBG_READ_PROCESS_MEMORY_ROUTINE64 lpReadProcessMemoryRoutine;
  271. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE64 lpWriteProcessMemoryRoutine;
  272. PWINDBG_GET_THREAD_CONTEXT_ROUTINE lpGetThreadContextRoutine;
  273. PWINDBG_SET_THREAD_CONTEXT_ROUTINE lpSetThreadContextRoutine;
  274. PWINDBG_IOCTL_ROUTINE lpIoctlRoutine;
  275. PWINDBG_STACKTRACE_ROUTINE64 lpStackTraceRoutine;
  276. } WINDBG_EXTENSION_APIS64, *PWINDBG_EXTENSION_APIS64;
  277. typedef struct _WINDBG_OLD_EXTENSION_APIS {
  278. ULONG nSize;
  279. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  280. PWINDBG_GET_EXPRESSION lpGetExpressionRoutine;
  281. PWINDBG_GET_SYMBOL lpGetSymbolRoutine;
  282. PWINDBG_DISASM lpDisasmRoutine;
  283. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  284. } WINDBG_OLD_EXTENSION_APIS, *PWINDBG_OLD_EXTENSION_APIS;
  285. typedef struct _WINDBG_OLDKD_EXTENSION_APIS {
  286. ULONG nSize;
  287. PWINDBG_OUTPUT_ROUTINE lpOutputRoutine;
  288. PWINDBG_GET_EXPRESSION32 lpGetExpressionRoutine;
  289. PWINDBG_GET_SYMBOL32 lpGetSymbolRoutine;
  290. PWINDBG_DISASM32 lpDisasmRoutine;
  291. PWINDBG_CHECK_CONTROL_C lpCheckControlCRoutine;
  292. PWINDBG_READ_PROCESS_MEMORY_ROUTINE32 lpReadVirtualMemRoutine;
  293. PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE32 lpWriteVirtualMemRoutine;
  294. PWINDBG_OLDKD_READ_PHYSICAL_MEMORY lpReadPhysicalMemRoutine;
  295. PWINDBG_OLDKD_WRITE_PHYSICAL_MEMORY lpWritePhysicalMemRoutine;
  296. } WINDBG_OLDKD_EXTENSION_APIS, *PWINDBG_OLDKD_EXTENSION_APIS;
  297. typedef
  298. VOID
  299. (WDBGAPI*PWINDBG_OLD_EXTENSION_ROUTINE)(
  300. ULONG dwCurrentPc,
  301. PWINDBG_EXTENSION_APIS lpExtensionApis,
  302. PCSTR lpArgumentString
  303. );
  304. typedef
  305. VOID
  306. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE)(
  307. HANDLE hCurrentProcess,
  308. HANDLE hCurrentThread,
  309. ULONG dwCurrentPc,
  310. ULONG dwProcessor,
  311. PCSTR lpArgumentString
  312. );
  313. typedef
  314. VOID
  315. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE32)(
  316. HANDLE hCurrentProcess,
  317. HANDLE hCurrentThread,
  318. ULONG dwCurrentPc,
  319. ULONG dwProcessor,
  320. PCSTR lpArgumentString
  321. );
  322. typedef
  323. VOID
  324. (WDBGAPI*PWINDBG_EXTENSION_ROUTINE64)(
  325. HANDLE hCurrentProcess,
  326. HANDLE hCurrentThread,
  327. ULONG64 dwCurrentPc,
  328. ULONG dwProcessor,
  329. PCSTR lpArgumentString
  330. );
  331. typedef
  332. VOID
  333. (WDBGAPI*PWINDBG_OLDKD_EXTENSION_ROUTINE)(
  334. ULONG dwCurrentPc,
  335. PWINDBG_OLDKD_EXTENSION_APIS lpExtensionApis,
  336. PCSTR lpArgumentString
  337. );
  338. typedef
  339. VOID
  340. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT)(
  341. PWINDBG_EXTENSION_APIS lpExtensionApis,
  342. USHORT MajorVersion,
  343. USHORT MinorVersion
  344. );
  345. typedef
  346. VOID
  347. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT32)(
  348. PWINDBG_EXTENSION_APIS32 lpExtensionApis,
  349. USHORT MajorVersion,
  350. USHORT MinorVersion
  351. );
  352. typedef
  353. VOID
  354. (WDBGAPI*PWINDBG_EXTENSION_DLL_INIT64)(
  355. PWINDBG_EXTENSION_APIS64 lpExtensionApis,
  356. USHORT MajorVersion,
  357. USHORT MinorVersion
  358. );
  359. typedef
  360. ULONG
  361. (WDBGAPI*PWINDBG_CHECK_VERSION)(
  362. VOID
  363. );
  364. #define EXT_API_VERSION_NUMBER 5
  365. #define EXT_API_VERSION_NUMBER32 5
  366. #define EXT_API_VERSION_NUMBER64 6
  367. typedef struct EXT_API_VERSION {
  368. USHORT MajorVersion;
  369. USHORT MinorVersion;
  370. USHORT Revision;
  371. USHORT Reserved;
  372. } EXT_API_VERSION, *LPEXT_API_VERSION;
  373. typedef
  374. LPEXT_API_VERSION
  375. (WDBGAPI*PWINDBG_EXTENSION_API_VERSION)(
  376. VOID
  377. );
  378. #define IG_KD_CONTEXT 1
  379. #define IG_READ_CONTROL_SPACE 2
  380. #define IG_WRITE_CONTROL_SPACE 3
  381. #define IG_READ_IO_SPACE 4
  382. #define IG_WRITE_IO_SPACE 5
  383. #define IG_READ_PHYSICAL 6
  384. #define IG_WRITE_PHYSICAL 7
  385. #define IG_READ_IO_SPACE_EX 8
  386. #define IG_WRITE_IO_SPACE_EX 9
  387. #define IG_KSTACK_HELP 10 // obsolete
  388. #define IG_SET_THREAD 11
  389. #define IG_READ_MSR 12
  390. #define IG_WRITE_MSR 13
  391. #define IG_GET_DEBUGGER_DATA 14
  392. #define IG_GET_KERNEL_VERSION 15
  393. #define IG_RELOAD_SYMBOLS 16
  394. #define IG_GET_SET_SYMPATH 17
  395. #define IG_GET_EXCEPTION_RECORD 18
  396. #define IG_IS_PTR64 19
  397. #define IG_GET_BUS_DATA 20
  398. #define IG_SET_BUS_DATA 21
  399. #define IG_DUMP_SYMBOL_INFO 22
  400. #define IG_LOWMEM_CHECK 23
  401. #define IG_SEARCH_MEMORY 24
  402. #define IG_GET_CURRENT_THREAD 25
  403. #define IG_GET_CURRENT_PROCESS 26
  404. #define IG_GET_TYPE_SIZE 27
  405. #define IG_GET_CURRENT_PROCESS_HANDLE 28
  406. #define IG_GET_INPUT_LINE 29
  407. #define IG_GET_EXPRESSION_EX 30
  408. #define IG_TRANSLATE_VIRTUAL_TO_PHYSICAL 31
  409. #define IG_GET_TEB_ADDRESS 128
  410. #define IG_GET_PEB_ADDRESS 129
  411. typedef struct _PROCESSORINFO {
  412. USHORT Processor; // current processor
  413. USHORT NumberProcessors; // total number of processors
  414. } PROCESSORINFO, *PPROCESSORINFO;
  415. typedef struct _READCONTROLSPACE {
  416. USHORT Processor;
  417. ULONG Address;
  418. ULONG BufLen;
  419. UCHAR Buf[1];
  420. } READCONTROLSPACE, *PREADCONTROLSPACE;
  421. typedef struct _READCONTROLSPACE32 {
  422. USHORT Processor;
  423. ULONG Address;
  424. ULONG BufLen;
  425. UCHAR Buf[1];
  426. } READCONTROLSPACE32, *PREADCONTROLSPACE32;
  427. typedef struct _READCONTROLSPACE64 {
  428. USHORT Processor;
  429. ULONG64 Address;
  430. ULONG BufLen;
  431. UCHAR Buf[1];
  432. } READCONTROLSPACE64, *PREADCONTROLSPACE64;
  433. typedef struct _IOSPACE {
  434. ULONG Address;
  435. ULONG Length; // 1, 2, or 4 bytes
  436. ULONG Data;
  437. } IOSPACE, *PIOSPACE;
  438. typedef struct _IOSPACE32 {
  439. ULONG Address;
  440. ULONG Length; // 1, 2, or 4 bytes
  441. ULONG Data;
  442. } IOSPACE32, *PIOSPACE32;
  443. typedef struct _IOSPACE64 {
  444. ULONG64 Address;
  445. ULONG Length; // 1, 2, or 4 bytes
  446. ULONG Data;
  447. } IOSPACE64, *PIOSPACE64;
  448. typedef struct _IOSPACE_EX {
  449. ULONG Address;
  450. ULONG Length; // 1, 2, or 4 bytes
  451. ULONG Data;
  452. ULONG InterfaceType;
  453. ULONG BusNumber;
  454. ULONG AddressSpace;
  455. } IOSPACE_EX, *PIOSPACE_EX;
  456. typedef struct _IOSPACE_EX32 {
  457. ULONG Address;
  458. ULONG Length; // 1, 2, or 4 bytes
  459. ULONG Data;
  460. ULONG InterfaceType;
  461. ULONG BusNumber;
  462. ULONG AddressSpace;
  463. } IOSPACE_EX32, *PIOSPACE_EX32;
  464. typedef struct _IOSPACE_EX64 {
  465. ULONG64 Address;
  466. ULONG Length; // 1, 2, or 4 bytes
  467. ULONG Data;
  468. ULONG InterfaceType;
  469. ULONG BusNumber;
  470. ULONG AddressSpace;
  471. } IOSPACE_EX64, *PIOSPACE_EX64;
  472. typedef struct _GETSETBUSDATA {
  473. ULONG BusDataType;
  474. ULONG BusNumber;
  475. ULONG SlotNumber;
  476. PVOID Buffer;
  477. ULONG Offset;
  478. ULONG Length;
  479. } BUSDATA, *PBUSDATA;
  480. typedef struct _SEARCHMEMORY {
  481. ULONG64 SearchAddress;
  482. ULONG64 SearchLength;
  483. ULONG64 FoundAddress;
  484. ULONG PatternLength;
  485. PVOID Pattern;
  486. } SEARCHMEMORY, *PSEARCHMEMORY;
  487. typedef struct _PHYSICAL {
  488. ULONGLONG Address;
  489. ULONG BufLen;
  490. UCHAR Buf[1];
  491. } PHYSICAL, *PPHYSICAL;
  492. typedef struct _READ_WRITE_MSR {
  493. ULONG Msr;
  494. LONGLONG Value;
  495. } READ_WRITE_MSR, *PREAD_WRITE_MSR;
  496. typedef struct _GET_SET_SYMPATH {
  497. PCSTR Args; // args to !reload command
  498. PSTR Result; // returns new path
  499. int Length; // Length of result buffer
  500. } GET_SET_SYMPATH, *PGET_SET_SYMPATH;
  501. typedef struct _GET_TEB_ADDRESS {
  502. ULONGLONG Address;
  503. } GET_TEB_ADDRESS, *PGET_TEB_ADDRESS;
  504. typedef struct _GET_PEB_ADDRESS {
  505. ULONG64 CurrentThread;
  506. ULONGLONG Address;
  507. } GET_PEB_ADDRESS, *PGET_PEB_ADDRESS;
  508. typedef struct _GET_CURRENT_THREAD_ADDRESS {
  509. ULONG Processor;
  510. ULONG64 Address;
  511. } GET_CURRENT_THREAD_ADDRESS, *PGET_CURRENT_THREAD_ADDRESS;
  512. typedef struct _GET_CURRENT_PROCESS_ADDRESS {
  513. ULONG Processor;
  514. ULONG64 CurrentThread;
  515. ULONG64 Address;
  516. } GET_CURRENT_PROCESS_ADDRESS, *PGET_CURRENT_PROCESS_ADDRESS;
  517. typedef struct _GET_INPUT_LINE {
  518. PCSTR Prompt;
  519. PSTR Buffer;
  520. ULONG BufferSize;
  521. ULONG InputSize;
  522. } GET_INPUT_LINE, *PGET_INPUT_LINE;
  523. typedef struct _GET_EXPRESSION_EX {
  524. PCSTR Expression;
  525. PCSTR Remainder;
  526. ULONG64 Value;
  527. } GET_EXPRESSION_EX, *PGET_EXPRESSION_EX;
  528. typedef struct _TRANSLATE_VIRTUAL_TO_PHYSICAL {
  529. ULONG64 Virtual;
  530. ULONG64 Physical;
  531. } TRANSLATE_VIRTUAL_TO_PHYSICAL, *PTRANSLATE_VIRTUAL_TO_PHYSICAL;
  532. //
  533. // If DBGKD_VERS_FLAG_DATA is set in Flags, info should be retrieved from
  534. // the KDDEBUGGER_DATA block rather than from the DBGKD_GET_VERSION
  535. // packet. The data will remain in the version packet for a while to
  536. // reduce compatibility problems.
  537. //
  538. #define DBGKD_VERS_FLAG_MP 0x0001 // kernel is MP built
  539. #define DBGKD_VERS_FLAG_DATA 0x0002 // DebuggerDataList is valid
  540. #define DBGKD_VERS_FLAG_PTR64 0x0004 // native pointers are 64 bits
  541. #define DBGKD_VERS_FLAG_NOMM 0x0008 // No MM - don't decode PTEs
  542. #define DBGKD_VERS_FLAG_HSS 0x0010 // hardware stepping support
  543. #define DBGKD_VERS_FLAG_USER_DEBUG 0x0020 // User debugging support
  544. #define KDBG_TAG 'GBDK'
  545. // **********************************************************************
  546. // DO NOT CHANGE THESE 32 BIT STRUCTURES!
  547. // ONLY MAKE CHAGES TO THE 64 BIT VERSION BELOW!!
  548. // **********************************************************************
  549. //
  550. // The following structure has changed in more than pointer size.
  551. //
  552. // This is the version packet for pre-NT5 Beta 2 systems.
  553. // For now, it is also still used on x86
  554. //
  555. typedef struct _DBGKD_GET_VERSION32 {
  556. USHORT MajorVersion;
  557. USHORT MinorVersion;
  558. USHORT ProtocolVersion;
  559. USHORT Flags;
  560. ULONG KernBase;
  561. ULONG PsLoadedModuleList;
  562. USHORT MachineType;
  563. //
  564. // help for walking stacks with user callbacks:
  565. //
  566. //
  567. // The address of the thread structure is provided in the
  568. // WAIT_STATE_CHANGE packet. This is the offset from the base of
  569. // the thread structure to the pointer to the kernel stack frame
  570. // for the currently active usermode callback.
  571. //
  572. USHORT ThCallbackStack; // offset in thread data
  573. //
  574. // these values are offsets into that frame:
  575. //
  576. USHORT NextCallback; // saved pointer to next callback frame
  577. USHORT FramePointer; // saved frame pointer
  578. //
  579. // Address of the kernel callout routine.
  580. //
  581. ULONG KiCallUserMode; // kernel routine
  582. //
  583. // Address of the usermode entry point for callbacks.
  584. //
  585. ULONG KeUserCallbackDispatcher; // address in ntdll
  586. //
  587. // DbgBreakPointWithStatus is a function which takes a ULONG argument
  588. // and hits a breakpoint. This field contains the address of the
  589. // breakpoint instruction. When the debugger sees a breakpoint
  590. // at this address, it may retrieve the argument from the first
  591. // argument register, or on x86 the eax register.
  592. //
  593. ULONG BreakpointWithStatus; // address of breakpoint
  594. //
  595. // Components may register a debug data block for use by
  596. // debugger extensions. This is the address of the list head.
  597. //
  598. ULONG DebuggerDataList;
  599. } DBGKD_GET_VERSION32, *PDBGKD_GET_VERSION32;
  600. //
  601. // This is the debugger data packet for pre NT5 Beta 2 systems.
  602. // For now, it is still used on x86
  603. //
  604. typedef struct _DBGKD_DEBUG_DATA_HEADER32 {
  605. LIST_ENTRY32 List;
  606. ULONG OwnerTag;
  607. ULONG Size;
  608. } DBGKD_DEBUG_DATA_HEADER32, *PDBGKD_DEBUG_DATA_HEADER32;
  609. typedef struct _KDDEBUGGER_DATA32 {
  610. DBGKD_DEBUG_DATA_HEADER32 Header;
  611. ULONG KernBase;
  612. ULONG BreakpointWithStatus; // address of breakpoint
  613. ULONG SavedContext;
  614. USHORT ThCallbackStack; // offset in thread data
  615. USHORT NextCallback; // saved pointer to next callback frame
  616. USHORT FramePointer; // saved frame pointer
  617. USHORT PaeEnabled:1;
  618. ULONG KiCallUserMode; // kernel routine
  619. ULONG KeUserCallbackDispatcher; // address in ntdll
  620. ULONG PsLoadedModuleList;
  621. ULONG PsActiveProcessHead;
  622. ULONG PspCidTable;
  623. ULONG ExpSystemResourcesList;
  624. ULONG ExpPagedPoolDescriptor;
  625. ULONG ExpNumberOfPagedPools;
  626. ULONG KeTimeIncrement;
  627. ULONG KeBugCheckCallbackListHead;
  628. ULONG KiBugcheckData;
  629. ULONG IopErrorLogListHead;
  630. ULONG ObpRootDirectoryObject;
  631. ULONG ObpTypeObjectType;
  632. ULONG MmSystemCacheStart;
  633. ULONG MmSystemCacheEnd;
  634. ULONG MmSystemCacheWs;
  635. ULONG MmPfnDatabase;
  636. ULONG MmSystemPtesStart;
  637. ULONG MmSystemPtesEnd;
  638. ULONG MmSubsectionBase;
  639. ULONG MmNumberOfPagingFiles;
  640. ULONG MmLowestPhysicalPage;
  641. ULONG MmHighestPhysicalPage;
  642. ULONG MmNumberOfPhysicalPages;
  643. ULONG MmMaximumNonPagedPoolInBytes;
  644. ULONG MmNonPagedSystemStart;
  645. ULONG MmNonPagedPoolStart;
  646. ULONG MmNonPagedPoolEnd;
  647. ULONG MmPagedPoolStart;
  648. ULONG MmPagedPoolEnd;
  649. ULONG MmPagedPoolInformation;
  650. ULONG MmPageSize;
  651. ULONG MmSizeOfPagedPoolInBytes;
  652. ULONG MmTotalCommitLimit;
  653. ULONG MmTotalCommittedPages;
  654. ULONG MmSharedCommit;
  655. ULONG MmDriverCommit;
  656. ULONG MmProcessCommit;
  657. ULONG MmPagedPoolCommit;
  658. ULONG MmExtendedCommit;
  659. ULONG MmZeroedPageListHead;
  660. ULONG MmFreePageListHead;
  661. ULONG MmStandbyPageListHead;
  662. ULONG MmModifiedPageListHead;
  663. ULONG MmModifiedNoWritePageListHead;
  664. ULONG MmAvailablePages;
  665. ULONG MmResidentAvailablePages;
  666. ULONG PoolTrackTable;
  667. ULONG NonPagedPoolDescriptor;
  668. ULONG MmHighestUserAddress;
  669. ULONG MmSystemRangeStart;
  670. ULONG MmUserProbeAddress;
  671. ULONG KdPrintCircularBuffer;
  672. ULONG KdPrintCircularBufferEnd;
  673. ULONG KdPrintWritePointer;
  674. ULONG KdPrintRolloverCount;
  675. ULONG MmLoadedUserImageList;
  676. } KDDEBUGGER_DATA32, *PKDDEBUGGER_DATA32;
  677. // **********************************************************************
  678. //
  679. // DO NOT CHANGE KDDEBUGGER_DATA32!!
  680. // ONLY MAKE CHANGES TO KDDEBUGGER_DATA64!!!
  681. //
  682. // **********************************************************************
  683. typedef struct _DBGKD_GET_VERSION64 {
  684. USHORT MajorVersion;
  685. USHORT MinorVersion;
  686. USHORT ProtocolVersion;
  687. USHORT Flags;
  688. USHORT MachineType;
  689. USHORT Unused[3];
  690. ULONG64 KernBase;
  691. ULONG64 PsLoadedModuleList;
  692. //
  693. // Components may register a debug data block for use by
  694. // debugger extensions. This is the address of the list head.
  695. //
  696. // There will always be an entry for the debugger.
  697. //
  698. ULONG64 DebuggerDataList;
  699. } DBGKD_GET_VERSION64, *PDBGKD_GET_VERSION64;
  700. //
  701. // This structure is used by the debugger for all targets
  702. // It is the same size as DBGKD_DATA_HEADER on all systems
  703. //
  704. typedef struct _DBGKD_DEBUG_DATA_HEADER64 {
  705. //
  706. // Link to other blocks
  707. //
  708. LIST_ENTRY64 List;
  709. //
  710. // This is a unique tag to identify the owner of the block.
  711. // If your component only uses one pool tag, use it for this, too.
  712. //
  713. ULONG OwnerTag;
  714. //
  715. // This must be initialized to the size of the data block,
  716. // including this structure.
  717. //
  718. ULONG Size;
  719. } DBGKD_DEBUG_DATA_HEADER64, *PDBGKD_DEBUG_DATA_HEADER64;
  720. //
  721. // This structure is the same size on all systems. The only field
  722. // which must be translated by the debugger is Header.List.
  723. //
  724. //
  725. // DO NOT ADD OR REMOVE FIELDS FROM THE MIDDLE OF THIS STRUCTURE!!!
  726. //
  727. // If you remove a field, replace it with an "unused" placeholder.
  728. // Do not reuse fields until there has been enough time for old debuggers
  729. // and extensions to age out.
  730. //
  731. typedef struct _KDDEBUGGER_DATA64 {
  732. DBGKD_DEBUG_DATA_HEADER64 Header;
  733. //
  734. // Base address of kernel image
  735. //
  736. ULONG64 KernBase;
  737. //
  738. // DbgBreakPointWithStatus is a function which takes an argument
  739. // and hits a breakpoint. This field contains the address of the
  740. // breakpoint instruction. When the debugger sees a breakpoint
  741. // at this address, it may retrieve the argument from the first
  742. // argument register, or on x86 the eax register.
  743. //
  744. ULONG64 BreakpointWithStatus; // address of breakpoint
  745. //
  746. // Address of the saved context record during a bugcheck
  747. //
  748. // N.B. This is an automatic in KeBugcheckEx's frame, and
  749. // is only valid after a bugcheck.
  750. //
  751. ULONG64 SavedContext;
  752. //
  753. // help for walking stacks with user callbacks:
  754. //
  755. //
  756. // The address of the thread structure is provided in the
  757. // WAIT_STATE_CHANGE packet. This is the offset from the base of
  758. // the thread structure to the pointer to the kernel stack frame
  759. // for the currently active usermode callback.
  760. //
  761. USHORT ThCallbackStack; // offset in thread data
  762. //
  763. // these values are offsets into that frame:
  764. //
  765. USHORT NextCallback; // saved pointer to next callback frame
  766. USHORT FramePointer; // saved frame pointer
  767. //
  768. // pad to a quad boundary
  769. //
  770. USHORT PaeEnabled:1;
  771. //
  772. // Address of the kernel callout routine.
  773. //
  774. ULONG64 KiCallUserMode; // kernel routine
  775. //
  776. // Address of the usermode entry point for callbacks.
  777. //
  778. ULONG64 KeUserCallbackDispatcher; // address in ntdll
  779. //
  780. // Addresses of various kernel data structures and lists
  781. // that are of interest to the kernel debugger.
  782. //
  783. ULONG64 PsLoadedModuleList;
  784. ULONG64 PsActiveProcessHead;
  785. ULONG64 PspCidTable;
  786. ULONG64 ExpSystemResourcesList;
  787. ULONG64 ExpPagedPoolDescriptor;
  788. ULONG64 ExpNumberOfPagedPools;
  789. ULONG64 KeTimeIncrement;
  790. ULONG64 KeBugCheckCallbackListHead;
  791. ULONG64 KiBugcheckData;
  792. ULONG64 IopErrorLogListHead;
  793. ULONG64 ObpRootDirectoryObject;
  794. ULONG64 ObpTypeObjectType;
  795. ULONG64 MmSystemCacheStart;
  796. ULONG64 MmSystemCacheEnd;
  797. ULONG64 MmSystemCacheWs;
  798. ULONG64 MmPfnDatabase;
  799. ULONG64 MmSystemPtesStart;
  800. ULONG64 MmSystemPtesEnd;
  801. ULONG64 MmSubsectionBase;
  802. ULONG64 MmNumberOfPagingFiles;
  803. ULONG64 MmLowestPhysicalPage;
  804. ULONG64 MmHighestPhysicalPage;
  805. ULONG64 MmNumberOfPhysicalPages;
  806. ULONG64 MmMaximumNonPagedPoolInBytes;
  807. ULONG64 MmNonPagedSystemStart;
  808. ULONG64 MmNonPagedPoolStart;
  809. ULONG64 MmNonPagedPoolEnd;
  810. ULONG64 MmPagedPoolStart;
  811. ULONG64 MmPagedPoolEnd;
  812. ULONG64 MmPagedPoolInformation;
  813. ULONG64 MmPageSize;
  814. ULONG64 MmSizeOfPagedPoolInBytes;
  815. ULONG64 MmTotalCommitLimit;
  816. ULONG64 MmTotalCommittedPages;
  817. ULONG64 MmSharedCommit;
  818. ULONG64 MmDriverCommit;
  819. ULONG64 MmProcessCommit;
  820. ULONG64 MmPagedPoolCommit;
  821. ULONG64 MmExtendedCommit;
  822. ULONG64 MmZeroedPageListHead;
  823. ULONG64 MmFreePageListHead;
  824. ULONG64 MmStandbyPageListHead;
  825. ULONG64 MmModifiedPageListHead;
  826. ULONG64 MmModifiedNoWritePageListHead;
  827. ULONG64 MmAvailablePages;
  828. ULONG64 MmResidentAvailablePages;
  829. ULONG64 PoolTrackTable;
  830. ULONG64 NonPagedPoolDescriptor;
  831. ULONG64 MmHighestUserAddress;
  832. ULONG64 MmSystemRangeStart;
  833. ULONG64 MmUserProbeAddress;
  834. ULONG64 KdPrintCircularBuffer;
  835. ULONG64 KdPrintCircularBufferEnd;
  836. ULONG64 KdPrintWritePointer;
  837. ULONG64 KdPrintRolloverCount;
  838. ULONG64 MmLoadedUserImageList;
  839. // NT 5.1 Addition
  840. ULONG64 NtBuildLab;
  841. ULONG64 KiNormalSystemCall;
  842. // NT 5.0 QFE addition
  843. ULONG64 KiProcessorBlock;
  844. ULONG64 MmUnloadedDrivers;
  845. ULONG64 MmLastUnloadedDriver;
  846. ULONG64 MmTriageActionTaken;
  847. ULONG64 MmSpecialPoolTag;
  848. ULONG64 KernelVerifier;
  849. ULONG64 MmVerifierData;
  850. ULONG64 MmAllocatedNonPagedPool;
  851. ULONG64 MmPeakCommitment;
  852. ULONG64 MmTotalCommitLimitMaximum;
  853. ULONG64 CmNtCSDVersion;
  854. // NT 5.1 Addition
  855. ULONG64 MmPhysicalMemoryBlock;
  856. } KDDEBUGGER_DATA64, *PKDDEBUGGER_DATA64;
  857. /************************************
  858. Type Dump Ioctl
  859. *************************************/
  860. //
  861. // Fields are not indented if this is set
  862. //
  863. #define DBG_DUMP_NO_INDENT 0x00000001
  864. //
  865. // Offsets are not printed if this is set
  866. //
  867. #define DBG_DUMP_NO_OFFSET 0x00000002
  868. //
  869. // Verbose output
  870. //
  871. #define DBG_DUMP_VERBOSE 0x00000004
  872. //
  873. // Callback is done for each of fields
  874. //
  875. #define DBG_DUMP_CALL_FOR_EACH 0x00000008
  876. //
  877. // A list of type is dumped, listLink should have info about next element pointer
  878. //
  879. #define DBG_DUMP_LIST 0x00000020
  880. //
  881. // Nothing is printed if this is set (only callbacks and data copies done)
  882. //
  883. #define DBG_DUMP_NO_PRINT 0x00000040
  884. //
  885. // Ioctl returns the size as usual, but will not do field prints/callbacks if this is set
  886. //
  887. #define DBG_DUMP_GET_SIZE_ONLY 0x00000080
  888. //
  889. // Specifies how much deep into structs we can go
  890. //
  891. #define DBG_DUMP_RECUR_LEVEL(l) ((l & 0xf) << 8)
  892. //
  893. // No newlines are printed after each field
  894. //
  895. #define DBG_DUMP_COMPACT_OUT 0x00002000
  896. //
  897. // An array of type is dumped, number of elements can be specified in listLink->size
  898. //
  899. #define DBG_DUMP_ARRAY 0x00008000
  900. //
  901. // The specified addr value is actually the address of field listLink->fName
  902. //
  903. #define DBG_DUMP_ADDRESS_OF_FIELD 0x00010000
  904. //
  905. // The specified addr value is actually the adress at the end of type
  906. //
  907. #define DBG_DUMP_ADDRESS_AT_END 0x00020000
  908. //
  909. // This could be used to copy only the primitive types like ULONG, PVOID etc.
  910. // - will not work with structures/unions
  911. //
  912. #define DBG_DUMP_COPY_TYPE_DATA 0x00040000
  913. //
  914. // Flag to allow read directly from physical memory
  915. //
  916. #define DBG_DUMP_READ_PHYSICAL 0x00080000
  917. //
  918. // This causes a function type to be dumped in format function(arg1, arg2, ...)
  919. //
  920. #define DBG_DUMP_FUNCTION_FORMAT 0x00100000
  921. //
  922. // Obsolete defs
  923. //
  924. #define DBG_RETURN_TYPE 0
  925. #define DBG_RETURN_SUBTYPES 0
  926. #define DBG_RETURN_TYPE_VALUES 0
  927. //
  928. // Dump and callback optons for fields - Options used in FIELD_INFO.fOptions
  929. //
  930. //
  931. // Callback is done before printing the field if this is set
  932. //
  933. #define DBG_DUMP_FIELD_CALL_BEFORE_PRINT 0x00000001
  934. //
  935. // No callback is done
  936. //
  937. #define DBG_DUMP_FIELD_NO_CALLBACK_REQ 0x00000002
  938. //
  939. // Subfields of the fields are processesed
  940. //
  941. #define DBG_DUMP_FIELD_RECUR_ON_THIS 0x00000004
  942. //
  943. // fName must match completely for the field to be dumped instead just a prefix
  944. // match by default
  945. //
  946. #define DBG_DUMP_FIELD_FULL_NAME 0x00000008
  947. //
  948. // This causes array elements of an array field to be printed
  949. //
  950. #define DBG_DUMP_FIELD_ARRAY 0x00000010
  951. //
  952. // The data of the field is copied into fieldCallBack
  953. //
  954. #define DBG_DUMP_FIELD_COPY_FIELD_DATA 0x00000020
  955. //
  956. // In callback or when Ioctl returns, the FIELD_INFO.address has the address of field.
  957. // If no address is supplied for the type, it contains total offset of the field.
  958. //
  959. #define DBG_DUMP_FIELD_RETURN_ADDRESS 0x00001000
  960. //
  961. // Return the offset and size in bits instead of bytes is case of Bitfield
  962. //
  963. #define DBG_DUMP_FIELD_SIZE_IN_BITS 0x00002000
  964. //
  965. // Nothing is printed for field if this is set (only callbacks and data copies done)
  966. //
  967. #define DBG_DUMP_FIELD_NO_PRINT 0x00004000
  968. //
  969. // If the field is a pointer, it is dumped as a string, ANSI, WCHAR, MULTI or GUID
  970. // depending on following options
  971. //
  972. #define DBG_DUMP_FIELD_DEFAULT_STRING 0x00010000
  973. #define DBG_DUMP_FIELD_WCHAR_STRING 0x00020000
  974. #define DBG_DUMP_FIELD_MULTI_STRING 0x00040000
  975. #define DBG_DUMP_FIELD_GUID_STRING 0x00080000
  976. //
  977. // Error status returned on TYPE DUMP Ioctl failure
  978. //
  979. #define MEMORY_READ_ERROR 0x01
  980. #define SYMBOL_TYPE_INDEX_NOT_FOUND 0x02
  981. #define SYMBOL_TYPE_INFO_NOT_FOUND 0x03
  982. #define FIELDS_DID_NOT_MATCH 0x04
  983. #define NULL_SYM_DUMP_PARAM 0x05
  984. #define NULL_FIELD_NAME 0x06
  985. #define INCORRECT_VERSION_INFO 0x07
  986. #define EXIT_ON_CONTROLC 0x08
  987. #define CANNOT_ALLOCATE_MEMORY 0x09
  988. #define INSUFFICIENT_SPACE_TO_COPY 0x0a
  989. //////////////////////////////////////////////////////////////////////////*/
  990. typedef
  991. ULONG
  992. (WDBGAPI*PSYM_DUMP_FIELD_CALLBACK)(
  993. struct _FIELD_INFO *pField,
  994. PVOID UserContext
  995. );
  996. typedef struct _FIELD_INFO {
  997. PUCHAR fName; // Name of the field
  998. PUCHAR printName; // Name to be printed at dump
  999. ULONG size; // Size of the field
  1000. ULONG fOptions; // Dump Options for the field
  1001. ULONG64 address; // address of the field
  1002. PVOID fieldCallBack; // Return info or callBack routine for the field
  1003. } FIELD_INFO, *PFIELD_INFO;
  1004. typedef struct _SYM_DUMP_PARAM {
  1005. ULONG size; // size of this struct
  1006. PUCHAR sName; // type name
  1007. ULONG Options; // Dump options
  1008. ULONG64 addr; // Address to take data for type
  1009. PFIELD_INFO listLink; // fName here would be used to do list dump
  1010. PVOID Context; // Usercontext passed to CallbackRoutine
  1011. PSYM_DUMP_FIELD_CALLBACK CallbackRoutine;
  1012. // Routine called back
  1013. ULONG nFields; // # elements in Fields
  1014. PFIELD_INFO Fields; // Used to return information about field
  1015. } SYM_DUMP_PARAM, *PSYM_DUMP_PARAM;
  1016. #ifdef __cplusplus
  1017. #define CPPMOD extern "C"
  1018. #else
  1019. #define CPPMOD
  1020. #endif
  1021. #ifndef NOEXTAPI
  1022. #if defined(KDEXT_64BIT)
  1023. #define WINDBG_EXTENSION_APIS WINDBG_EXTENSION_APIS64
  1024. #define PWINDBG_EXTENSION_APIS PWINDBG_EXTENSION_APIS64
  1025. #define DECLARE_API(s) DECLARE_API64(s)
  1026. #elif defined(KDEXT_32BIT)
  1027. #define WINDBG_EXTENSION_APIS WINDBG_EXTENSION_APIS32
  1028. #define PWINDBG_EXTENSION_APIS PWINDBG_EXTENSION_APIS32
  1029. #define DECLARE_API(s) DECLARE_API32(s)
  1030. #else
  1031. #define DECLARE_API(s) \
  1032. CPPMOD VOID \
  1033. s( \
  1034. HANDLE hCurrentProcess, \
  1035. HANDLE hCurrentThread, \
  1036. ULONG dwCurrentPc, \
  1037. ULONG dwProcessor, \
  1038. PCSTR args \
  1039. )
  1040. #endif
  1041. #define DECLARE_API32(s) \
  1042. CPPMOD VOID \
  1043. s( \
  1044. HANDLE hCurrentProcess, \
  1045. HANDLE hCurrentThread, \
  1046. ULONG dwCurrentPc, \
  1047. ULONG dwProcessor, \
  1048. PCSTR args \
  1049. )
  1050. #define DECLARE_API64(s) \
  1051. CPPMOD VOID \
  1052. s( \
  1053. HANDLE hCurrentProcess, \
  1054. HANDLE hCurrentThread, \
  1055. ULONG64 dwCurrentPc, \
  1056. ULONG dwProcessor, \
  1057. PCSTR args \
  1058. )
  1059. extern WINDBG_EXTENSION_APIS ExtensionApis;
  1060. #define dprintf (ExtensionApis.lpOutputRoutine)
  1061. #define GetExpression (ExtensionApis.lpGetExpressionRoutine)
  1062. #define CheckControlC (ExtensionApis.lpCheckControlCRoutine)
  1063. #define GetContext (ExtensionApis.lpGetThreadContextRoutine)
  1064. #define SetContext (ExtensionApis.lpSetThreadContextRoutine)
  1065. #define Ioctl (ExtensionApis.lpIoctlRoutine)
  1066. #define Disasm (ExtensionApis.lpDisasmRoutine)
  1067. #define GetSymbol (ExtensionApis.lpGetSymbolRoutine)
  1068. #define ReadMemory (ExtensionApis.lpReadProcessMemoryRoutine)
  1069. #define WriteMemory (ExtensionApis.lpWriteProcessMemoryRoutine)
  1070. #define StackTrace (ExtensionApis.lpStackTraceRoutine)
  1071. #define GetKdContext(ppi) \
  1072. Ioctl( IG_KD_CONTEXT, (PVOID)ppi, sizeof(*ppi) )
  1073. //
  1074. // BOOL
  1075. // GetDebuggerData(
  1076. // ULONG Tag,
  1077. // PVOID Buf,
  1078. // ULONG Size
  1079. // )
  1080. //
  1081. #define GetDebuggerData(TAG, BUF, SIZE) \
  1082. ( (((PDBGKD_DEBUG_DATA_HEADER64)(BUF))->OwnerTag = (TAG)), \
  1083. (((PDBGKD_DEBUG_DATA_HEADER64)(BUF))->Size = (SIZE)), \
  1084. Ioctl( IG_GET_DEBUGGER_DATA, (PVOID)(BUF), (SIZE) ) )
  1085. // Check if LocalAlloc is prototyped
  1086. //#ifdef _WINBASE_
  1087. __inline VOID
  1088. ReadPhysical(
  1089. ULONG64 address,
  1090. PVOID buf,
  1091. ULONG size,
  1092. PULONG sizer
  1093. )
  1094. {
  1095. PPHYSICAL phy;
  1096. *sizer = 0;
  1097. phy = (PPHYSICAL)LocalAlloc(LPTR, sizeof(*phy) + size );
  1098. if (phy) {
  1099. ZeroMemory( phy->Buf, size );
  1100. phy->Address = address;
  1101. phy->BufLen = size;
  1102. Ioctl( IG_READ_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  1103. *sizer = phy->BufLen;
  1104. CopyMemory( buf, phy->Buf, *sizer );
  1105. LocalFree( phy );
  1106. }
  1107. }
  1108. __inline VOID
  1109. WritePhysical(
  1110. ULONG64 address,
  1111. PVOID buf,
  1112. ULONG size,
  1113. PULONG sizew
  1114. )
  1115. {
  1116. PPHYSICAL phy;
  1117. *sizew = 0;
  1118. phy = (PPHYSICAL)LocalAlloc(LPTR, sizeof(*phy) + size );
  1119. if (phy) {
  1120. ZeroMemory( phy->Buf, size );
  1121. phy->Address = address;
  1122. phy->BufLen = size;
  1123. CopyMemory( phy->Buf, buf, size );
  1124. Ioctl( IG_WRITE_PHYSICAL, (PVOID)phy, sizeof(*phy) + size );
  1125. *sizew = phy->BufLen;
  1126. LocalFree( phy );
  1127. }
  1128. }
  1129. __inline VOID
  1130. ReadMsr(
  1131. ULONG MsrReg,
  1132. ULONGLONG *MsrValue
  1133. )
  1134. {
  1135. READ_WRITE_MSR msr;
  1136. msr.Msr = MsrReg;
  1137. Ioctl( IG_READ_MSR, (PVOID)&msr, sizeof(msr) );
  1138. *MsrValue = msr.Value;
  1139. }
  1140. __inline VOID
  1141. WriteMsr(
  1142. ULONG MsrReg,
  1143. ULONGLONG MsrValue
  1144. )
  1145. {
  1146. READ_WRITE_MSR msr;
  1147. msr.Msr = MsrReg;
  1148. msr.Value = MsrValue;
  1149. Ioctl( IG_WRITE_MSR, (PVOID)&msr, sizeof(msr) );
  1150. }
  1151. __inline VOID
  1152. SetThreadForOperation(
  1153. ULONG_PTR * Thread
  1154. )
  1155. {
  1156. Ioctl(IG_SET_THREAD, (PVOID)Thread, sizeof(PULONG));
  1157. }
  1158. __inline VOID
  1159. SetThreadForOperation32(
  1160. ULONG Thread
  1161. )
  1162. {
  1163. Ioctl(IG_SET_THREAD, (PVOID)LongToPtr(Thread), sizeof(PULONG));
  1164. }
  1165. __inline VOID
  1166. SetThreadForOperation64(
  1167. PULONG64 Thread
  1168. )
  1169. {
  1170. Ioctl(IG_SET_THREAD, (PVOID)Thread, sizeof(PULONG));
  1171. }
  1172. __inline VOID
  1173. ReadControlSpace(
  1174. USHORT processor,
  1175. ULONG address,
  1176. PVOID buf,
  1177. ULONG size
  1178. )
  1179. {
  1180. PREADCONTROLSPACE prc;
  1181. prc = (PREADCONTROLSPACE)LocalAlloc(LPTR, sizeof(*prc) + size );
  1182. if (prc) {
  1183. ZeroMemory( prc->Buf, size );
  1184. prc->Processor = processor;
  1185. prc->Address = address;
  1186. prc->BufLen = size;
  1187. Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  1188. CopyMemory( buf, prc->Buf, size );
  1189. LocalFree( prc );
  1190. }
  1191. }
  1192. __inline VOID
  1193. ReadControlSpace32(
  1194. USHORT processor,
  1195. ULONG address,
  1196. PVOID buf,
  1197. ULONG size
  1198. )
  1199. {
  1200. PREADCONTROLSPACE32 prc;
  1201. prc = (PREADCONTROLSPACE32)LocalAlloc(LPTR, sizeof(*prc) + size );
  1202. if (prc) {
  1203. ZeroMemory( prc->Buf, size );
  1204. prc->Processor = processor;
  1205. prc->Address = address;
  1206. prc->BufLen = size;
  1207. Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  1208. CopyMemory( buf, prc->Buf, size );
  1209. LocalFree( prc );
  1210. }
  1211. }
  1212. #define ReadTypedControlSpace32( _Proc, _Addr, _Buf ) \
  1213. ReadControlSpace64( (USHORT)(_Proc), (ULONG)(_Addr), (PVOID)&(_Buf), (ULONG)sizeof(_Buf) )
  1214. __inline VOID
  1215. ReadControlSpace64(
  1216. USHORT processor,
  1217. ULONG64 address,
  1218. PVOID buf,
  1219. ULONG size
  1220. )
  1221. {
  1222. PREADCONTROLSPACE64 prc;
  1223. prc = (PREADCONTROLSPACE64)LocalAlloc(LPTR, sizeof(*prc) + size );
  1224. if (prc) {
  1225. ZeroMemory( prc->Buf, size );
  1226. prc->Processor = processor;
  1227. prc->Address = address;
  1228. prc->BufLen = size;
  1229. Ioctl( IG_READ_CONTROL_SPACE, (PVOID)prc, sizeof(*prc) + size );
  1230. CopyMemory( buf, prc->Buf, size );
  1231. LocalFree( prc );
  1232. }
  1233. }
  1234. #define ReadTypedControlSpace64( _Proc, _Addr, _Buf ) \
  1235. ReadControlSpace64( (USHORT)(_Proc), (ULONG64)(_Addr), (PVOID)&(_Buf), (ULONG)sizeof(_Buf) )
  1236. // #endif // _WINBASE_
  1237. __inline VOID
  1238. ReadIoSpace(
  1239. ULONG address,
  1240. PULONG data,
  1241. PULONG size
  1242. )
  1243. {
  1244. IOSPACE is;
  1245. is.Address = address;
  1246. is.Length = *size;
  1247. Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  1248. memcpy(data, &is.Data, is.Length);
  1249. *size = is.Length;
  1250. }
  1251. __inline VOID
  1252. ReadIoSpace32(
  1253. ULONG address,
  1254. PULONG data,
  1255. PULONG size
  1256. )
  1257. {
  1258. IOSPACE32 is;
  1259. is.Address = address;
  1260. is.Length = *size;
  1261. Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  1262. memcpy(data, &is.Data, is.Length);
  1263. *size = is.Length;
  1264. }
  1265. __inline VOID
  1266. ReadIoSpace64(
  1267. ULONG64 address,
  1268. PULONG data,
  1269. PULONG size
  1270. )
  1271. {
  1272. IOSPACE64 is;
  1273. is.Address = address;
  1274. is.Length = *size;
  1275. Ioctl( IG_READ_IO_SPACE, (PVOID)&is, sizeof(is) );
  1276. memcpy(data, &is.Data, is.Length);
  1277. *size = is.Length;
  1278. }
  1279. __inline VOID
  1280. WriteIoSpace(
  1281. ULONG address,
  1282. ULONG data,
  1283. PULONG size
  1284. )
  1285. {
  1286. IOSPACE is;
  1287. is.Address = (ULONG)address;
  1288. is.Length = *size;
  1289. is.Data = data;
  1290. Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  1291. *size = is.Length;
  1292. }
  1293. __inline VOID
  1294. WriteIoSpace32(
  1295. ULONG address,
  1296. ULONG data,
  1297. PULONG size
  1298. )
  1299. {
  1300. IOSPACE32 is;
  1301. is.Address = address;
  1302. is.Length = *size;
  1303. is.Data = data;
  1304. Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  1305. *size = is.Length;
  1306. }
  1307. __inline VOID
  1308. WriteIoSpace64(
  1309. ULONG64 address,
  1310. ULONG data,
  1311. PULONG size
  1312. )
  1313. {
  1314. IOSPACE64 is;
  1315. is.Address = address;
  1316. is.Length = *size;
  1317. is.Data = data;
  1318. Ioctl( IG_WRITE_IO_SPACE, (PVOID)&is, sizeof(is) );
  1319. *size = is.Length;
  1320. }
  1321. __inline VOID
  1322. ReadIoSpaceEx(
  1323. ULONG address,
  1324. PULONG data,
  1325. PULONG size,
  1326. ULONG interfacetype,
  1327. ULONG busnumber,
  1328. ULONG addressspace
  1329. )
  1330. {
  1331. IOSPACE_EX is;
  1332. is.Address = (ULONG)address;
  1333. is.Length = *size;
  1334. is.Data = 0;
  1335. is.InterfaceType = interfacetype;
  1336. is.BusNumber = busnumber;
  1337. is.AddressSpace = addressspace;
  1338. Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1339. *data = is.Data;
  1340. *size = is.Length;
  1341. }
  1342. __inline VOID
  1343. ReadIoSpaceEx32(
  1344. ULONG address,
  1345. PULONG data,
  1346. PULONG size,
  1347. ULONG interfacetype,
  1348. ULONG busnumber,
  1349. ULONG addressspace
  1350. )
  1351. {
  1352. IOSPACE_EX32 is;
  1353. is.Address = address;
  1354. is.Length = *size;
  1355. is.Data = 0;
  1356. is.InterfaceType = interfacetype;
  1357. is.BusNumber = busnumber;
  1358. is.AddressSpace = addressspace;
  1359. Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1360. *data = is.Data;
  1361. *size = is.Length;
  1362. }
  1363. __inline VOID
  1364. ReadIoSpaceEx64(
  1365. ULONG64 address,
  1366. PULONG data,
  1367. PULONG size,
  1368. ULONG interfacetype,
  1369. ULONG busnumber,
  1370. ULONG addressspace
  1371. )
  1372. {
  1373. IOSPACE_EX64 is;
  1374. is.Address = address;
  1375. is.Length = *size;
  1376. is.Data = 0;
  1377. is.InterfaceType = interfacetype;
  1378. is.BusNumber = busnumber;
  1379. is.AddressSpace = addressspace;
  1380. Ioctl( IG_READ_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1381. *data = is.Data;
  1382. *size = is.Length;
  1383. }
  1384. __inline VOID
  1385. WriteIoSpaceEx(
  1386. ULONG address,
  1387. ULONG data,
  1388. PULONG size,
  1389. ULONG interfacetype,
  1390. ULONG busnumber,
  1391. ULONG addressspace
  1392. )
  1393. {
  1394. IOSPACE_EX is;
  1395. is.Address = (ULONG)address;
  1396. is.Length = *size;
  1397. is.Data = data;
  1398. is.InterfaceType = interfacetype;
  1399. is.BusNumber = busnumber;
  1400. is.AddressSpace = addressspace;
  1401. Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1402. *size = is.Length;
  1403. }
  1404. __inline VOID
  1405. WriteIoSpaceEx32(
  1406. ULONG address,
  1407. ULONG data,
  1408. PULONG size,
  1409. ULONG interfacetype,
  1410. ULONG busnumber,
  1411. ULONG addressspace
  1412. )
  1413. {
  1414. IOSPACE_EX32 is;
  1415. is.Address = address;
  1416. is.Length = *size;
  1417. is.Data = data;
  1418. is.InterfaceType = interfacetype;
  1419. is.BusNumber = busnumber;
  1420. is.AddressSpace = addressspace;
  1421. Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1422. *size = is.Length;
  1423. }
  1424. __inline VOID
  1425. WriteIoSpaceEx64(
  1426. ULONG64 address,
  1427. ULONG data,
  1428. PULONG size,
  1429. ULONG interfacetype,
  1430. ULONG busnumber,
  1431. ULONG addressspace
  1432. )
  1433. {
  1434. IOSPACE_EX64 is;
  1435. is.Address = address;
  1436. is.Length = *size;
  1437. is.Data = data;
  1438. is.InterfaceType = interfacetype;
  1439. is.BusNumber = busnumber;
  1440. is.AddressSpace = addressspace;
  1441. Ioctl( IG_WRITE_IO_SPACE_EX, (PVOID)&is, sizeof(is) );
  1442. *size = is.Length;
  1443. }
  1444. __inline VOID
  1445. ReloadSymbols(
  1446. IN PSTR Arg OPTIONAL
  1447. )
  1448. /*++
  1449. Routine Description:
  1450. Calls the debugger to reload symbols.
  1451. Arguments:
  1452. Args - Supplies the tail of a !reload command string.
  1453. !reload [flags] [module[=address]]
  1454. flags: /n do not load from usermode list
  1455. /u unload symbols, no reload
  1456. /v verbose
  1457. A value of NULL is equivalent to an empty string
  1458. Return Value:
  1459. None
  1460. --*/
  1461. {
  1462. Ioctl(IG_RELOAD_SYMBOLS, (PVOID)Arg, Arg?(strlen(Arg)+1):0);
  1463. }
  1464. __inline VOID
  1465. GetSetSympath(
  1466. IN PSTR Arg,
  1467. OUT PSTR Result OPTIONAL,
  1468. IN int Length
  1469. )
  1470. /*++
  1471. Routine Description:
  1472. Calls the debugger to set or retrieve symbol search path.
  1473. Arguments:
  1474. Arg - Supplies new search path. If Arg is NULL or string is empty,
  1475. the search path is not changed and the current setting is
  1476. returned in Result. When the symbol search path is changed,
  1477. a call to ReloadSymbols is made implicitly.
  1478. Result - OPTIONAL Returns the symbol search path setting.
  1479. Length - Supplies the size of the buffer supplied by Result.
  1480. Return Value:
  1481. None
  1482. --*/
  1483. {
  1484. GET_SET_SYMPATH gss;
  1485. gss.Args = Arg;
  1486. gss.Result = Result;
  1487. gss.Length = Length;
  1488. Ioctl(IG_GET_SET_SYMPATH, (PVOID)&gss, sizeof(gss));
  1489. }
  1490. #if defined(KDEXT_64BIT)
  1491. __inline
  1492. ULONG
  1493. IsPtr64(
  1494. void
  1495. )
  1496. {
  1497. static ULONG flag = -1;
  1498. ULONG dw;
  1499. if (flag == -1) {
  1500. if (Ioctl(IG_IS_PTR64, &dw, sizeof(dw))) {
  1501. flag = ((dw != 0) ? 1 : 0);
  1502. } else {
  1503. flag = 0;
  1504. }
  1505. }
  1506. return flag;
  1507. }
  1508. __inline
  1509. ULONG
  1510. ReadListEntry(
  1511. ULONG64 Address,
  1512. PLIST_ENTRY64 List
  1513. )
  1514. {
  1515. ULONG cb;
  1516. if (IsPtr64()) {
  1517. return (ReadMemory(Address, (PVOID)List, sizeof(*List), &cb) && cb == sizeof(*List));
  1518. } else {
  1519. LIST_ENTRY32 List32;
  1520. ULONG Status;
  1521. Status = ReadMemory(Address,
  1522. (PVOID)&List32,
  1523. sizeof(List32),
  1524. &cb);
  1525. if (Status && cb == sizeof(List32)) {
  1526. List->Flink = (ULONG64)(LONG64)(LONG)List32.Flink;
  1527. List->Blink = (ULONG64)(LONG64)(LONG)List32.Blink;
  1528. return 1;
  1529. }
  1530. return 0;
  1531. }
  1532. }
  1533. __inline
  1534. ULONG
  1535. ReadPointer(
  1536. ULONG64 Address,
  1537. PULONG64 Pointer
  1538. )
  1539. {
  1540. ULONG cb;
  1541. if (IsPtr64()) {
  1542. return (ReadMemory(Address, (PVOID)Pointer, sizeof(*Pointer), &cb) && cb == sizeof(*Pointer));
  1543. } else {
  1544. ULONG Pointer32;
  1545. ULONG Status;
  1546. Status = ReadMemory(Address,
  1547. (PVOID)&Pointer32,
  1548. sizeof(Pointer32),
  1549. &cb);
  1550. if (Status && cb == sizeof(Pointer32)) {
  1551. *Pointer = (ULONG64)(LONG64)(LONG)Pointer32;
  1552. return 1;
  1553. }
  1554. return 0;
  1555. }
  1556. }
  1557. __inline
  1558. ULONG
  1559. WritePointer(
  1560. ULONG64 Address,
  1561. ULONG64 Pointer
  1562. )
  1563. {
  1564. ULONG cb;
  1565. if (IsPtr64()) {
  1566. return (WriteMemory(Address, &Pointer, sizeof(Pointer), &cb) && cb == sizeof(Pointer));
  1567. } else {
  1568. ULONG Pointer32 = (ULONG)Pointer;
  1569. ULONG Status;
  1570. Status = WriteMemory(Address,
  1571. &Pointer32,
  1572. sizeof(Pointer32),
  1573. &cb);
  1574. return (Status && cb == sizeof(Pointer32)) ? 1 : 0;
  1575. }
  1576. }
  1577. /**
  1578. This does Ioctl call for type info and returns size of the type on success.
  1579. **/
  1580. __inline
  1581. ULONG
  1582. GetTypeSize (
  1583. IN LPCSTR Type
  1584. )
  1585. {
  1586. SYM_DUMP_PARAM Sym = {
  1587. sizeof (SYM_DUMP_PARAM), (PUCHAR)Type, DBG_DUMP_NO_PRINT | DBG_DUMP_GET_SIZE_ONLY, 0,
  1588. NULL, NULL, NULL, 0, NULL
  1589. };
  1590. return Ioctl( IG_GET_TYPE_SIZE, &Sym, Sym.size );
  1591. }
  1592. /**
  1593. GetFieldData
  1594. Copies the value of the specified field into pOutValue assuming TypeAddress
  1595. points to start of the type in debugee.
  1596. If the Field is NULL and the size of Type is <= 8 Whole type value is read into
  1597. pOutValue. This is to allow to read in primitive types suchas ULONG, PVOID etc.
  1598. If address is zero this considers Type a global variable.
  1599. It raises an exception if OutSize is less than size to be copied.
  1600. Returns 0 on success, errorvalue (defined with SYM_DUMP_PARAM) otherwise.
  1601. **/
  1602. __inline
  1603. ULONG
  1604. GetFieldData (
  1605. IN ULONG64 TypeAddress,
  1606. IN LPCSTR Type,
  1607. IN LPCSTR Field,
  1608. IN ULONG OutSize,
  1609. OUT PVOID pOutValue
  1610. )
  1611. {
  1612. FIELD_INFO flds = {(PUCHAR)Field, NULL, 0, DBG_DUMP_FIELD_FULL_NAME | DBG_DUMP_FIELD_COPY_FIELD_DATA | DBG_DUMP_FIELD_RETURN_ADDRESS, 0, pOutValue};
  1613. SYM_DUMP_PARAM Sym = {
  1614. sizeof (SYM_DUMP_PARAM), (PUCHAR)Type, DBG_DUMP_NO_PRINT, TypeAddress,
  1615. NULL, NULL, NULL, 1, &flds
  1616. };
  1617. ULONG RetVal;
  1618. if (!Field) {
  1619. Sym.nFields =0; Sym.Options |= DBG_DUMP_COPY_TYPE_DATA;
  1620. Sym.Context = pOutValue;
  1621. }
  1622. ZeroMemory(pOutValue, OutSize);
  1623. RetVal = Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  1624. if (OutSize < ((Field == NULL) ? 8 : flds.size)) {
  1625. // Fail
  1626. dprintf("Not enough space to read %s-%s\n", Type, Field);
  1627. RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);
  1628. return 0;
  1629. }
  1630. return RetVal;
  1631. }
  1632. //
  1633. // Typecast the buffer where value is to be read
  1634. //
  1635. #define GetFieldValue(Addr, Type, Field, OutValue) \
  1636. GetFieldData(Addr, Type, Field, sizeof(OutValue), (PVOID) &(OutValue))
  1637. //
  1638. // Used to read in value of a short (<= 8 bytes) fields
  1639. //
  1640. __inline
  1641. ULONG64
  1642. GetShortField (
  1643. IN ULONG64 TypeAddress,
  1644. IN LPCSTR Name,
  1645. IN USHORT StoreAddress
  1646. )
  1647. {
  1648. static ULONG64 SavedAddress;
  1649. static PUCHAR SavedName;
  1650. static ULONG ReadPhysical;
  1651. FIELD_INFO flds = {(PUCHAR) Name, NULL, 0, DBG_DUMP_FIELD_FULL_NAME, 0, NULL};
  1652. SYM_DUMP_PARAM Sym = {
  1653. sizeof (SYM_DUMP_PARAM), SavedName, DBG_DUMP_NO_PRINT | ((StoreAddress & 2) ? DBG_DUMP_READ_PHYSICAL : 0),
  1654. SavedAddress, NULL, NULL, NULL, 1, &flds
  1655. };
  1656. if (StoreAddress) {
  1657. Sym.sName = (PUCHAR) Name;
  1658. Sym.nFields = 0;
  1659. SavedName = (PUCHAR) Name;
  1660. Sym.addr = SavedAddress = TypeAddress;
  1661. ReadPhysical = (StoreAddress & 2);
  1662. return SavedAddress ? Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size ) : MEMORY_READ_ERROR; // zero on success
  1663. } else {
  1664. Sym.Options |= ReadPhysical ? DBG_DUMP_READ_PHYSICAL : 0;
  1665. }
  1666. if (!Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size )) {
  1667. return flds.address;
  1668. }
  1669. return 0;
  1670. }
  1671. //
  1672. // Stores the address and type name for future reads
  1673. //
  1674. #define InitTypeRead(Addr, Type) GetShortField(Addr, #Type, 1)
  1675. //
  1676. // Stores the address and type name for future reads
  1677. //
  1678. #define InitTypeReadPhysical(Addr, Type) GetShortField(Addr, #Type, 3)
  1679. //
  1680. // Returns the field's value as ULONG64 if size of field is <= sizeof (ULONG64)
  1681. //
  1682. #define ReadField(Field) GetShortField(0, #Field, 0)
  1683. //
  1684. // Read in a pointer value
  1685. //
  1686. __inline
  1687. ULONG
  1688. ReadPtr(
  1689. ULONG64 Addr,
  1690. PULONG64 pPointer
  1691. )
  1692. {
  1693. return GetFieldData(Addr, "PVOID", NULL, sizeof(ULONG64), (PVOID) pPointer);
  1694. }
  1695. /*
  1696. * ListType
  1697. *
  1698. * Routine ListType gives a callback on each element in the list of Type.
  1699. *
  1700. * Type : Name of the type to be listed
  1701. *
  1702. * NextPointer : Name of field which gives address of next element in list
  1703. *
  1704. * Context, CallbackRoutine :
  1705. * Context and the callback routine. The address field in PFIELD_INFO
  1706. * parameter of callback contains the address of next Type element in list.
  1707. *
  1708. * Address, ListByFieldAddress :
  1709. * if ListByFieldAddress is 0, Adress is the address of first element of Type List.
  1710. *
  1711. * Lists by LIST_ENTRY are also handled implicitly (by Ioctl). If the NextPointer
  1712. * is a pointer to LIST_ENTRY type, the type address is properly calculated by
  1713. * subtracting the offsets.
  1714. *
  1715. * If ListByFieldAddress is 1, the Address is considered to be the address of field
  1716. * "NextPointer" of the first Type element and first element address is derived
  1717. * from it.
  1718. *
  1719. */
  1720. __inline
  1721. ULONG
  1722. ListType (
  1723. IN LPCSTR Type,
  1724. IN ULONG64 Address,
  1725. IN USHORT ListByFieldAddress,
  1726. IN LPCSTR NextPointer,
  1727. IN PVOID Context,
  1728. IN PSYM_DUMP_FIELD_CALLBACK CallbackRoutine
  1729. )
  1730. {
  1731. FIELD_INFO flds = {(PUCHAR)NextPointer, NULL, 0, 0, 0, NULL};
  1732. SYM_DUMP_PARAM Sym = {
  1733. sizeof (SYM_DUMP_PARAM), (PUCHAR) Type, DBG_DUMP_NO_PRINT | DBG_DUMP_LIST, Address,
  1734. &flds, Context, CallbackRoutine, 0, NULL
  1735. };
  1736. if (ListByFieldAddress==1) {
  1737. //
  1738. // Address is the address of "NextPointer"
  1739. //
  1740. Sym.Options |= DBG_DUMP_ADDRESS_OF_FIELD;
  1741. }
  1742. return Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  1743. }
  1744. /**
  1745. Routine to get offset of a "Field" of "Type" on a debugee machine. This uses
  1746. Ioctl call for type info.
  1747. Returns 0 on success, Ioctl error value otherwise.
  1748. **/
  1749. __inline
  1750. ULONG
  1751. GetFieldOffset (
  1752. IN LPCSTR Type,
  1753. IN LPCSTR Field,
  1754. OUT PULONG pOffset
  1755. )
  1756. {
  1757. FIELD_INFO flds = {
  1758. (PUCHAR)Field,
  1759. (PUCHAR)"",
  1760. 0,
  1761. DBG_DUMP_FIELD_FULL_NAME | DBG_DUMP_FIELD_RETURN_ADDRESS,
  1762. 0,
  1763. NULL};
  1764. SYM_DUMP_PARAM Sym = {
  1765. sizeof (SYM_DUMP_PARAM),
  1766. (PUCHAR)Type,
  1767. DBG_DUMP_NO_PRINT,
  1768. 0,
  1769. NULL,
  1770. NULL,
  1771. NULL,
  1772. 1,
  1773. &flds
  1774. };
  1775. ULONG Err;
  1776. Sym.nFields = 1;
  1777. Err = Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  1778. *pOffset = (ULONG) (flds.address - Sym.addr);
  1779. return Err;
  1780. }
  1781. #endif // defined(KDEXT_64BIT)
  1782. __inline VOID
  1783. GetCurrentProcessHandle(
  1784. PHANDLE hp
  1785. )
  1786. {
  1787. Ioctl(IG_GET_CURRENT_PROCESS_HANDLE, hp, sizeof(HANDLE));
  1788. }
  1789. __inline VOID
  1790. GetTebAddress(
  1791. PULONGLONG Address
  1792. )
  1793. {
  1794. GET_TEB_ADDRESS gpt;
  1795. gpt.Address = 0;
  1796. Ioctl(IG_GET_TEB_ADDRESS, (PVOID)&gpt, sizeof(gpt));
  1797. *Address = gpt.Address;
  1798. }
  1799. __inline VOID
  1800. GetPebAddress(
  1801. ULONG64 CurrentThread,
  1802. PULONGLONG Address
  1803. )
  1804. {
  1805. GET_PEB_ADDRESS gpt;
  1806. gpt.CurrentThread = CurrentThread;
  1807. gpt.Address = 0;
  1808. Ioctl(IG_GET_PEB_ADDRESS, (PVOID)&gpt, sizeof(gpt));
  1809. *Address = gpt.Address;
  1810. }
  1811. __inline VOID
  1812. GetCurrentThreadAddr(
  1813. DWORD Processor,
  1814. PULONG64 Address
  1815. )
  1816. {
  1817. GET_CURRENT_THREAD_ADDRESS ct;
  1818. ct.Processor = Processor;
  1819. Ioctl(IG_GET_CURRENT_THREAD, (PVOID)&ct, sizeof(ct));
  1820. *Address = ct.Address;
  1821. }
  1822. __inline VOID
  1823. GetCurrentProcessAddr(
  1824. DWORD Processor,
  1825. ULONG64 CurrentThread,
  1826. PULONG64 Address
  1827. )
  1828. {
  1829. GET_CURRENT_PROCESS_ADDRESS cp;
  1830. cp.Processor = Processor;
  1831. cp.CurrentThread = CurrentThread;
  1832. Ioctl(IG_GET_CURRENT_PROCESS, (PVOID)&cp, sizeof(cp));
  1833. *Address = cp.Address;
  1834. }
  1835. __inline VOID
  1836. SearchMemory(
  1837. ULONG64 SearchAddress,
  1838. ULONG64 SearchLength,
  1839. ULONG PatternLength,
  1840. PVOID Pattern,
  1841. PULONG64 FoundAddress
  1842. )
  1843. {
  1844. SEARCHMEMORY sm;
  1845. sm.SearchAddress = SearchAddress;
  1846. sm.SearchLength = SearchLength;
  1847. sm.FoundAddress = 0;
  1848. sm.PatternLength = PatternLength;
  1849. sm.Pattern = Pattern;
  1850. Ioctl(IG_SEARCH_MEMORY, (PVOID)&sm, sizeof(sm));
  1851. *FoundAddress = sm.FoundAddress;
  1852. }
  1853. __inline ULONG
  1854. GetInputLine(
  1855. PCSTR Prompt,
  1856. PSTR Buffer,
  1857. ULONG BufferSize
  1858. )
  1859. {
  1860. GET_INPUT_LINE InLine;
  1861. InLine.Prompt = Prompt;
  1862. InLine.Buffer = Buffer;
  1863. InLine.BufferSize = BufferSize;
  1864. if (Ioctl(IG_GET_INPUT_LINE, (PVOID)&InLine, sizeof(InLine)))
  1865. {
  1866. return InLine.InputSize;
  1867. }
  1868. else
  1869. {
  1870. return 0;
  1871. }
  1872. }
  1873. __inline BOOL
  1874. GetExpressionEx(
  1875. PCSTR Expression,
  1876. ULONG64* Value,
  1877. PCSTR* Remainder
  1878. )
  1879. {
  1880. GET_EXPRESSION_EX Expr;
  1881. Expr.Expression = Expression;
  1882. if (Ioctl(IG_GET_EXPRESSION_EX, (PVOID)&Expr, sizeof(Expr)))
  1883. {
  1884. *Value = Expr.Value;
  1885. if (Remainder != NULL)
  1886. {
  1887. *Remainder = Expr.Remainder;
  1888. }
  1889. return TRUE;
  1890. }
  1891. return FALSE;
  1892. }
  1893. __inline BOOL
  1894. TranslateVirtualToPhysical(
  1895. ULONG64 Virtual,
  1896. ULONG64* Physical
  1897. )
  1898. {
  1899. TRANSLATE_VIRTUAL_TO_PHYSICAL VToP;
  1900. VToP.Virtual = Virtual;
  1901. if (Ioctl(IG_TRANSLATE_VIRTUAL_TO_PHYSICAL, (PVOID)&VToP, sizeof(VToP)))
  1902. {
  1903. *Physical = VToP.Physical;
  1904. return TRUE;
  1905. }
  1906. return FALSE;
  1907. }
  1908. #endif
  1909. #ifdef __cplusplus
  1910. }
  1911. #endif
  1912. #endif // _WDBGEXTS_