home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / wdbgexts.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  45.7 KB  |  1,784 lines

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