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

547 lines
14 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. vdmexts.h
  5. Abstract:
  6. This file header defines most of the stuff used in VDMEXTS
  7. Revision History:
  8. Neil Sandlin (NeilSa) 15-Jan-1996 Merged with vdmexts
  9. --*/
  10. //
  11. // Pointers to WINDBG api
  12. //
  13. extern PWINDBG_OUTPUT_ROUTINE Print;
  14. extern PWINDBG_GET_EXPRESSION GetExpression;
  15. extern PWINDBG_GET_SYMBOL GetSymbol;
  16. extern PWINDBG_DISASM Disassemble;
  17. extern PWINDBG_CHECK_CONTROL_C CheckCtrlC;
  18. extern PWINDBG_READ_PROCESS_MEMORY_ROUTINE ReadMem;
  19. extern PWINDBG_WRITE_PROCESS_MEMORY_ROUTINE WriteMem;
  20. extern PWINDBG_GET_THREAD_CONTEXT_ROUTINE ExtGetThreadContext;
  21. extern PWINDBG_SET_THREAD_CONTEXT_ROUTINE ExtSetThreadContext;
  22. extern PWINDBG_IOCTL_ROUTINE ExtIoctl;
  23. extern PWINDBG_STACKTRACE_ROUTINE ExtStackTrace;
  24. extern HANDLE hCurrentProcess;
  25. extern HANDLE hCurrentThread;
  26. extern LPSTR lpArgumentString;
  27. #define PRINTF (* Print)
  28. #define EXPRESSION (* GetExpression)
  29. #define ReadDword(x) read_dword((ULONG)x, FALSE)
  30. #define ReadWord(x) read_word ((ULONG)x, FALSE)
  31. #define ReadByte(x) read_byte ((ULONG)x, FALSE)
  32. #define ReadDwordSafe(x) read_dword((ULONG)x, TRUE)
  33. #define ReadWordSafe(x) read_word ((ULONG)x, TRUE)
  34. #define ReadByteSafe(x) read_byte ((ULONG)x, TRUE)
  35. #define ReadGNode32(x,p) read_gnode32((ULONG)x,p,FALSE)
  36. #define ReadGNode32Safe(x,p) read_gnode32((ULONG)x,p,TRUE)
  37. /****** macros common to all versions *******/
  38. #define CMD_ARGLIST HANDLE CurrentProcess, \
  39. HANDLE CurrentThread, \
  40. DWORD CurrentPc, \
  41. PWINDBG_EXTENSION_APIS pXApis, \
  42. LPSTR ArgumentString
  43. #define CMD_INIT() \
  44. UNREFERENCED_PARAMETER(CurrentPc); \
  45. hCurrentProcess = CurrentProcess; \
  46. hCurrentThread = CurrentThread; \
  47. lpArgumentString = ArgumentString; \
  48. \
  49. Print = pXApis->lpOutputRoutine; \
  50. GetSymbol = pXApis->lpGetSymbolRoutine; \
  51. GetExpression = pXApis->lpGetExpressionRoutine; \
  52. CheckCtrlC = pXApis->lpCheckControlCRoutine; \
  53. \
  54. ReadMem = pXApis->lpReadProcessMemoryRoutine; \
  55. WriteMem = pXApis->lpWriteProcessMemoryRoutine; \
  56. ExtGetThreadContext = pXApis->lpGetThreadContextRoutine; \
  57. ExtSetThreadContext = pXApis->lpSetThreadContextRoutine; \
  58. ExtIoctl = pXApis->lpIoctlRoutine; \
  59. ExtStackTrace = pXApis->lpStackTraceRoutine; \
  60. #define READMEM( addr, buff, size ) ReadProcessMem(addr, buff, size)
  61. #define WRITEMEM( addr, buff, size ) WriteProcessMem(addr, buff, size)
  62. #define READMEM_XRET(buff, addr)\
  63. try {\
  64. READMEM( (LPVOID)(addr), (LPVOID)&(buff), sizeof(buff));\
  65. } except (EXCEPTION_EXECUTE_HANDLER) {\
  66. Print("ReadProcessMemory Failed !\n");\
  67. return;\
  68. }
  69. #define READMEM_XRETV(buff, addr, ret)\
  70. try {\
  71. READMEM((LPVOID) (addr), (LPVOID)&(buff), sizeof(buff));\
  72. } except (EXCEPTION_EXECUTE_HANDLER) {\
  73. Print("ReadProcessMemory Failed !\n");\
  74. return ret;\
  75. }
  76. #define WRITEMEM_XRET(addr, buff)\
  77. try {\
  78. WRITEMEM((LPVOID)(addr), (LPVOID)&(buff), sizeof(buff));\
  79. } except (EXCEPTION_EXECUTE_HANDLER) {\
  80. Print("WriteProcessMemory Failed !\n");\
  81. return;\
  82. }
  83. #define WRITEMEM_N_XRET(addr, buff, n)\
  84. try {\
  85. WRITEMEM((LPVOID)(addr), (LPVOID)(buff), n);\
  86. } except (EXCEPTION_EXECUTE_HANDLER) {\
  87. Print("WriteProcessMemory Failed !\n");\
  88. return;\
  89. }
  90. #define GETEXPRVALUE(dst, expr, typ) \
  91. {\
  92. PVOID lpA = (PVOID)GetExpression(expr);\
  93. READMEM_XRET(dst, lpA);\
  94. }
  95. #define GETEXPRADDR(dst, expr) \
  96. {\
  97. dst = (PVOID)GetExpression(expr);\
  98. }
  99. #define ASSERT_WOW_PRESENT { \
  100. if (!EXPRESSION("wow32!gptdTaskHead")) { \
  101. PRINTF("Could not resolve needed symbols for WOW32\n"); \
  102. return; \
  103. } \
  104. }
  105. #define ASSERT_CHECKED_WOW_PRESENT { \
  106. if (!EXPRESSION("wow32!iCircBuffer")) { \
  107. PRINTF("Could not resolve needed symbols for checked WOW32\n"); \
  108. return; \
  109. } \
  110. }
  111. #define BEFORE 0
  112. #define AFTER 1
  113. #define RPL_MASK 0x78
  114. #define V86_BITS 0x20000
  115. #define SELECTOR_LDT 0x04
  116. #define SELECTOR_RPL 0x03
  117. #define V86_MODE 0
  118. #define PROT_MODE 1
  119. #define FLAT_MODE 2
  120. #define NOT_LOADED 3
  121. #define CALL_NEAR_RELATIVE 0xE8
  122. #define CALL_NEAR_INDIRECT 0xFF
  123. #define INDIRECT_NEAR_TYPE 0x02
  124. #define CALL_FAR_ABSOLUTE 0x9A
  125. #define CALL_FAR_INDIRECT 0xFF
  126. #define INDIRECT_FAR_TYPE 0x03
  127. #define PUSH_CS 0x0E
  128. #define ADD_SP 0xC483
  129. #define TYPE_BITS 0x38
  130. #define TYPE0 0x00
  131. #define TYPE1 0x08
  132. #define TYPE2 0x10
  133. #define TYPE3 0x18
  134. #define TYPE4 0x20
  135. #define TYPE5 0x28
  136. #define TYPE6 0x30
  137. #define TYPE7 0x38
  138. #define MOD_BITS 0xC0
  139. #define MOD0 0x00
  140. #define MOD1 0x40
  141. #define MOD2 0x80
  142. #define MOD3 0xC0
  143. #define RM_BITS 0x07
  144. #define RM0 0x00
  145. #define RM1 0x01
  146. #define RM2 0x02
  147. #define RM3 0x03
  148. #define RM4 0x04
  149. #define RM5 0x05
  150. #define RM6 0x06
  151. #define RM7 0x07
  152. #define FLAG_OVERFLOW 0x0800
  153. #define FLAG_DIRECTION 0x0400
  154. #define FLAG_INTERRUPT 0x0200
  155. #define FLAG_SIGN 0x0080
  156. #define FLAG_ZERO 0x0040
  157. #define FLAG_AUXILLIARY 0x0010
  158. #define FLAG_PARITY 0x0004
  159. #define FLAG_CARRY 0x0001
  160. typedef struct _SELECTORINFO {
  161. DWORD Base;
  162. DWORD Limit;
  163. BOOL bCode;
  164. BOOL bSystem;
  165. BOOL bPresent;
  166. BOOL bWrite;
  167. BOOL bAccessed;
  168. BOOL bBig;
  169. BOOL bExpandDown;
  170. } SELECTORINFO;
  171. typedef struct _segentry {
  172. struct _segentry *Next;
  173. int type;
  174. char szExePath[MAX_PATH16];
  175. char szModule[MAX_MODULE_NAME];
  176. WORD selector;
  177. WORD segment;
  178. DWORD length;
  179. } SEGENTRY, *PSEGENTRY;
  180. #define SEGTYPE_V86 1
  181. #define SEGTYPE_PROT 2
  182. #pragma pack(1)
  183. typedef struct _GNODE32 { // GlobalArena
  184. DWORD pga_next ; // next arena entry (last points to self)
  185. DWORD pga_prev ; // previous arena entry (first points to self)
  186. DWORD pga_address ; // 32 bit linear address of memory
  187. DWORD pga_size ; // 32 bit size in bytes
  188. WORD pga_handle ; // back link to handle table entry
  189. WORD pga_owner ; // Owner field (current task)
  190. BYTE pga_count ; // lock count for movable segments
  191. BYTE pga_pglock ; // # times page locked
  192. BYTE pga_flags ; // 1 word available for flags
  193. BYTE pga_selcount ; // Number of selectors allocated
  194. DWORD pga_lruprev ; // Previous entry in lru chain
  195. DWORD pga_lrunext ; // Next entry in lru chain
  196. } GNODE32;
  197. typedef GNODE32 UNALIGNED *PGNODE32;
  198. typedef struct _GHI32 {
  199. WORD hi_check ; // arena check word (non-zero enables heap checking)
  200. WORD hi_freeze ; // arena frozen word (non-zero prevents compaction)
  201. WORD hi_count ; // #entries in arena
  202. WORD hi_first ; // first arena entry (sentinel, always busy)
  203. WORD hi_res1 ; // reserved
  204. WORD hi_last ; // last arena entry (sentinel, always busy)
  205. WORD hi_res2 ; // reserved
  206. BYTE hi_ncompact ; // #compactions done so far (max of 3)
  207. BYTE hi_dislevel ; // current discard level
  208. DWORD hi_distotal ; // total amount discarded so far
  209. WORD hi_htable ; // head of handle table list
  210. WORD hi_hfree ; // head of free handle table list
  211. WORD hi_hdelta ; // #handles to allocate each time
  212. WORD hi_hexpand ; // address of near procedure to expand handles for this arena
  213. WORD hi_pstats ; // address of statistics table or zero
  214. } GHI32;
  215. typedef GHI32 UNALIGNED *PGHI32;
  216. typedef struct _HEAPENTRY {
  217. GNODE32 gnode;
  218. DWORD CurrentEntry;
  219. DWORD NextEntry;
  220. WORD Selector;
  221. int SegmentNumber;
  222. char OwnerName[9];
  223. char FileName[9];
  224. char ModuleArg[9];
  225. } HEAPENTRY;
  226. typedef struct _NEHEADER {
  227. WORD ne_magic ;
  228. BYTE ne_ver ;
  229. BYTE ne_rev ;
  230. WORD ne_enttab ;
  231. WORD ne_cbenttab ;
  232. DWORD ne_crc ;
  233. WORD ne_flags ;
  234. WORD ne_autodata ;
  235. WORD ne_heap ;
  236. WORD ne_stack ;
  237. DWORD ne_csip ;
  238. DWORD ne_sssp ;
  239. WORD ne_cseg ;
  240. WORD ne_cmod ;
  241. WORD ne_cbnrestab ;
  242. WORD ne_segtab ;
  243. WORD ne_rsrctab ;
  244. WORD ne_restab ;
  245. WORD ne_modtab ;
  246. WORD ne_imptab ;
  247. DWORD ne_nrestab ;
  248. WORD ne_cmovent ;
  249. WORD ne_align ;
  250. WORD ne_cres ;
  251. BYTE ne_exetyp ;
  252. BYTE ne_flagsothers ;
  253. WORD ne_pretthunks ;
  254. WORD ne_psegrefbytes;
  255. WORD ne_swaparea ;
  256. WORD ne_expver ;
  257. } NEHEADER;
  258. typedef NEHEADER UNALIGNED *PNEHEADER;
  259. #pragma pack()
  260. #ifndef i386
  261. //
  262. // Structures in 486 cpu for obtaining registers (FROM NT_CPU.C)
  263. //
  264. typedef struct NT_CPU_REG {
  265. ULONG *nano_reg; /* where the nano CPU keeps the register */
  266. ULONG *reg; /* where the light compiler keeps the reg */
  267. ULONG *saved_reg; /* where currently unused bits are kept */
  268. ULONG universe_8bit_mask;/* is register in 8-bit form? */
  269. ULONG universe_16bit_mask;/* is register in 16-bit form? */
  270. } NT_CPU_REG;
  271. typedef struct NT_CPU_INFO {
  272. /* Variables for deciding what mode we're in */
  273. BOOL *in_nano_cpu; /* is the Nano CPU executing? */
  274. ULONG *universe; /* the mode that the CPU is in */
  275. /* General purpose register pointers */
  276. NT_CPU_REG eax, ebx, ecx, edx, esi, edi, ebp;
  277. /* Variables for getting SP or ESP. */
  278. BOOL *stack_is_big; /* is the stack 32-bit? */
  279. ULONG *nano_esp; /* where the Nano CPU keeps ESP */
  280. UCHAR **host_sp; /* ptr to variable holding stack pointer as a
  281. host address */
  282. UCHAR **ss_base; /* ptr to variables holding base of SS as a
  283. host address */
  284. ULONG *esp_sanctuary; /* top 16 bits of ESP if we're now using SP */
  285. ULONG *eip;
  286. /* Segment registers. */
  287. USHORT *cs, *ds, *es, *fs, *gs, *ss;
  288. ULONG *flags;
  289. /* CR0, mainly to let us figure out if we're in real or protect mode */
  290. ULONG *cr0;
  291. } NT_CPU_INFO;
  292. #endif // i386
  293. BOOL
  294. WINAPI
  295. ReadProcessMem(
  296. LPVOID lpBaseAddress,
  297. LPVOID lpBuffer,
  298. DWORD nSize
  299. );
  300. BOOL
  301. WINAPI
  302. WriteProcessMem(
  303. LPVOID lpBaseAddress,
  304. LPVOID lpBuffer,
  305. DWORD nSize
  306. );
  307. BOOL
  308. ReadMemExpression(
  309. LPSTR expr,
  310. LPVOID buffer,
  311. ULONG len
  312. );
  313. BOOL
  314. CheckGlobalHeap(
  315. BOOL bVerbose
  316. );
  317. int GetContext(
  318. VDMCONTEXT* lpContext
  319. );
  320. ULONG GetInfoFromSelector(
  321. WORD selector,
  322. int mode,
  323. SELECTORINFO *si
  324. );
  325. BOOL
  326. FindHeapEntry(
  327. HEAPENTRY *he,
  328. UINT FindMethod,
  329. BOOL bVerbose
  330. );
  331. #define FHE_FIND_ANY 0
  332. #define FHE_FIND_SEL_ONLY 1
  333. #define FHE_FIND_MOD_ONLY 2
  334. #define FHE_FIND_QUIET FALSE
  335. #define FHE_FIND_VERBOSE TRUE
  336. BOOL
  337. FindAddress(
  338. LPSTR sym_text,
  339. LPSTR filename,
  340. WORD *psegment,
  341. WORD *pselector,
  342. LONG *poffset,
  343. int *pmode,
  344. BOOL bDumpAll
  345. );
  346. BOOL FindSymbol(
  347. WORD selector,
  348. LONG offset,
  349. LPSTR sym_text,
  350. LONG *dist,
  351. int direction,
  352. int mode
  353. );
  354. int
  355. unassemble_one(
  356. BYTE *pInstrStart,
  357. BOOL bDefaultBig,
  358. WORD wInstrSeg,
  359. DWORD dwInstrOff,
  360. char *pchOutput,
  361. char *pchExtra,
  362. VDMCONTEXT *pThreadContext,
  363. int mode
  364. );
  365. ULONG GetIntelBase(
  366. VOID
  367. );
  368. DWORD read_dword(
  369. ULONG lpAddress,
  370. BOOL bSafe
  371. );
  372. WORD read_word(
  373. ULONG lpAddress,
  374. BOOL bSafe
  375. );
  376. BYTE read_byte(
  377. ULONG lpAddress,
  378. BOOL bSafe
  379. );
  380. BOOL read_gnode32(
  381. ULONG lpAddress,
  382. PGNODE32 p,
  383. BOOL bSafe
  384. );
  385. BOOL GetNextToken(
  386. VOID
  387. );
  388. ULONG EvaluateToken(
  389. VOID
  390. );
  391. VOID helpAPIProfDmp(
  392. VOID
  393. );
  394. VOID helpMsgProfDmp(
  395. VOID
  396. );
  397. BOOL
  398. InVdmPrompt(
  399. VOID
  400. );
  401. BOOL ParseIntelAddress(
  402. int *pMode,
  403. WORD *pSelector,
  404. PULONG pOffset
  405. );
  406. VOID
  407. ParseModuleName(
  408. LPSTR szName,
  409. LPSTR szPath
  410. );
  411. VOID
  412. EnableDebuggerBreakpoints(
  413. VOID
  414. );
  415. BOOL
  416. IsVdmBreakPoint(
  417. USHORT selector,
  418. ULONG offset,
  419. BOOL bProt,
  420. PULONG pBpNum,
  421. PUCHAR pBpData
  422. );
  423. BOOL
  424. LoadBreakPointCache(
  425. VOID
  426. );
  427. BOOL
  428. SkipToNextWhiteSpace(
  429. VOID
  430. );
  431. BOOL
  432. IsTokenHex(
  433. VOID
  434. );
  435. PSEGENTRY
  436. GetSegtablePointer(
  437. VOID
  438. );
  439. VOID Drp (VOID);
  440. VOID Erp (VOID);
  441. VOID EventInfop (VOID);
  442. VOID ProfDumpp (VOID);
  443. VOID ProfIntp (VOID);
  444. VOID ProfStartp (VOID);
  445. VOID ProfStopp (VOID);
  446. VOID VdmTibp (VOID);
  447. VOID Fpup (VOID);
  448. BOOL DumpEnvironment(WORD segEnv, int mode);
  449. ULONG GetCurrentVdmTib(VOID);