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.

397 lines
11 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. common.h
  5. Abstract:
  6. Main header file for vdmdbg
  7. Author:
  8. Bob Day (bobday) 16-Sep-1992 Wrote it
  9. Revision History:
  10. Neil Sandlin (neilsa) 1-Mar-1997 Enhanced it
  11. --*/
  12. #if DBG
  13. #define DEBUG 1
  14. #endif
  15. #define TOOL_HMASTER 0 // Offset to hGlobalHeap (in kdata.asm)
  16. #define TOOL_HMODFIRST 4 // Offset to hExeHead (in kdata.asm)
  17. #define TOOL_HEADTDB 14 // Offset to headTDB (in kdata.asm)
  18. #define TOOL_HMASTLEN 22 // Offset to SelTableLen (in kdata.asm)
  19. #define TOOL_HMASTSTART 24 // Offset to SelTableStart (in kdata.asm)
  20. #define HI_FIRST 6 // Offset to hi_first in heap header
  21. #define HI_SIZE 24 // Size of HeapInfo structure
  22. #define GI_LRUCHAIN 2 // Offset to gi_lruchain in heap header
  23. #define GI_LRUCOUNT 4 // Offset to gi_lrucount in heap header
  24. #define GI_FREECOUNT 16 // Offset to gi_free_count in heap header
  25. #define GA_COUNT 0 // Offset to ga_count in arena header
  26. #define GA_OWNER386 18 // Offset to "pga_owner member in globalarena
  27. #define GA_OWNER 1 // Offset to "owner" member within Arena
  28. #define GA_FLAGS 5 // Offset to ga_flags in arena header
  29. #define GA_NEXT 9 // Offset to ga_next in arena header
  30. #define GA_HANDLE 10 // Offset to ga_handle in arena header
  31. #define GA_LRUNEXT 14 // Offset to ga_lrunext in arena header
  32. #define GA_FREENEXT GA_LRUNEXT // Offset to ga_freenext in arena header
  33. #define GA_SIZE 16 // Size of the GlobalArena structure
  34. #define LI_SIG HI_SIZE+10 // Offset to signature
  35. #define LI_SIZE HI_SIZE+12 // Size of LocalInfo structure
  36. #define LOCALSIG 0x4C48 // 'HL' Signature
  37. #define TDB_next 0 // Offset to next TDB in TDB
  38. #define TDB_PDB 72 // Offset to PDB in TDB
  39. #define GF_PDB_OWNER 0x100 // Low byte is kernel flags
  40. #define NEMAGIC 0x454E // 'NE' Signature
  41. #define NE_MAGIC 0 // Offset to NE in module header
  42. #define NE_USAGE 2 // Offset to usage
  43. #define NE_CBENTTAB 6 // Offset to cbenttab (really next module ptr)
  44. #define NE_PATHOFFSET 10 // Offset to file path stuff
  45. #define NE_CSEG 28 // Offset to cseg, number of segs in module
  46. #define NE_SEGTAB 34 // Offset to segment table ptr in modhdr
  47. #define NE_RESTAB 38 // Offset to resident names table ptr in modhdr
  48. #define NS_HANDLE 8 // Offset to handle in seg table
  49. #define NEW_SEG1_SIZE 10 // Size of the NS_ stuff
  50. typedef struct {
  51. DWORD dwSize;
  52. DWORD dwAddress;
  53. DWORD dwBlockSize;
  54. WORD hBlock;
  55. WORD wcLock;
  56. WORD wcPageLock;
  57. WORD wFlags;
  58. WORD wHeapPresent;
  59. WORD hOwner;
  60. WORD wType;
  61. WORD wData;
  62. DWORD dwNext;
  63. DWORD dwNextAlt;
  64. } GLOBALENTRY16, *LPGLOBALENTRY16;
  65. #pragma pack(2)
  66. typedef struct {
  67. DWORD dwSize;
  68. char szModule[MAX_MODULE_NAME];
  69. WORD hModule;
  70. WORD wcUsage;
  71. char szExePath[MAX_PATH16];
  72. WORD wNext;
  73. } MODULEENTRY16, *LPMODULEENTRY16;
  74. #pragma pack()
  75. typedef struct _segentry {
  76. struct _segentry *Next;
  77. int type;
  78. char szExePath[MAX_PATH16];
  79. char szModule[MAX_MODULE_NAME];
  80. WORD selector;
  81. WORD segment;
  82. DWORD length;
  83. } SEGENTRY, *PSEGENTRY;
  84. #define SEGTYPE_V86 1
  85. #define SEGTYPE_PROT 2
  86. #pragma pack(1)
  87. typedef struct _GNODE32 { // GlobalArena
  88. DWORD pga_next ; // next arena entry (last points to self)
  89. DWORD pga_prev ; // previous arena entry (first points to self)
  90. DWORD pga_address ; // 32 bit linear address of memory
  91. DWORD pga_size ; // 32 bit size in bytes
  92. WORD pga_handle ; // back link to handle table entry
  93. WORD pga_owner ; // Owner field (current task)
  94. BYTE pga_count ; // lock count for movable segments
  95. BYTE pga_pglock ; // # times page locked
  96. BYTE pga_flags ; // 1 word available for flags
  97. BYTE pga_selcount ; // Number of selectors allocated
  98. DWORD pga_lruprev ; // Previous entry in lru chain
  99. DWORD pga_lrunext ; // Next entry in lru chain
  100. } GNODE32;
  101. typedef GNODE32 UNALIGNED *PGNODE32;
  102. typedef struct _GHI32 {
  103. WORD hi_check ; // arena check word (non-zero enables heap checking)
  104. WORD hi_freeze ; // arena frozen word (non-zero prevents compaction)
  105. WORD hi_count ; // #entries in arena
  106. WORD hi_first ; // first arena entry (sentinel, always busy)
  107. WORD hi_res1 ; // reserved
  108. WORD hi_last ; // last arena entry (sentinel, always busy)
  109. WORD hi_res2 ; // reserved
  110. BYTE hi_ncompact ; // #compactions done so far (max of 3)
  111. BYTE hi_dislevel ; // current discard level
  112. DWORD hi_distotal ; // total amount discarded so far
  113. WORD hi_htable ; // head of handle table list
  114. WORD hi_hfree ; // head of free handle table list
  115. WORD hi_hdelta ; // #handles to allocate each time
  116. WORD hi_hexpand ; // address of near procedure to expand handles for this arena
  117. WORD hi_pstats ; // address of statistics table or zero
  118. } GHI32;
  119. typedef GHI32 UNALIGNED *PGHI32;
  120. typedef struct _HEAPENTRY {
  121. GNODE32 gnode;
  122. DWORD CurrentEntry;
  123. DWORD NextEntry;
  124. WORD Selector;
  125. int SegmentNumber;
  126. char OwnerName[9];
  127. char FileName[9];
  128. char ModuleArg[9];
  129. } HEAPENTRY;
  130. typedef struct _NEHEADER {
  131. WORD ne_magic ;
  132. BYTE ne_ver ;
  133. BYTE ne_rev ;
  134. WORD ne_enttab ;
  135. WORD ne_cbenttab ;
  136. DWORD ne_crc ;
  137. WORD ne_flags ;
  138. WORD ne_autodata ;
  139. WORD ne_heap ;
  140. WORD ne_stack ;
  141. DWORD ne_csip ;
  142. DWORD ne_sssp ;
  143. WORD ne_cseg ;
  144. WORD ne_cmod ;
  145. WORD ne_cbnrestab ;
  146. WORD ne_segtab ;
  147. WORD ne_rsrctab ;
  148. WORD ne_restab ;
  149. WORD ne_modtab ;
  150. WORD ne_imptab ;
  151. DWORD ne_nrestab ;
  152. WORD ne_cmovent ;
  153. WORD ne_align ;
  154. WORD ne_cres ;
  155. BYTE ne_exetyp ;
  156. BYTE ne_flagsothers ;
  157. WORD ne_pretthunks ;
  158. WORD ne_psegrefbytes;
  159. WORD ne_swaparea ;
  160. WORD ne_expver ;
  161. } NEHEADER;
  162. typedef NEHEADER UNALIGNED *PNEHEADER;
  163. #pragma pack()
  164. #ifndef i386
  165. //
  166. // Structures in 486 emulator for obtaining registers (FROM NT_CPU.C)
  167. //
  168. typedef struct NT_CPU_REG {
  169. ULONG *nano_reg; /* where the nano CPU keeps the register */
  170. ULONG *reg; /* where the light compiler keeps the reg */
  171. ULONG *saved_reg; /* where currently unused bits are kept */
  172. ULONG universe_8bit_mask;/* is register in 8-bit form? */
  173. ULONG universe_16bit_mask;/* is register in 16-bit form? */
  174. } NT_CPU_REG;
  175. typedef struct NT_CPU_INFO {
  176. /* Variables for deciding what mode we're in */
  177. BOOL *in_nano_cpu; /* is the Nano CPU executing? */
  178. ULONG *universe; /* the mode that the CPU is in */
  179. /* General purpose register pointers */
  180. NT_CPU_REG eax, ebx, ecx, edx, esi, edi, ebp;
  181. /* Variables for getting SP or ESP. */
  182. BOOL *stack_is_big; /* is the stack 32-bit? */
  183. ULONG *nano_esp; /* where the Nano CPU keeps ESP */
  184. UCHAR **host_sp; /* ptr to variable holding stack pointer as a
  185. host address */
  186. UCHAR **ss_base; /* ptr to variables holding base of SS as a
  187. host address */
  188. ULONG *esp_sanctuary; /* top 16 bits of ESP if we're now using SP */
  189. ULONG *eip;
  190. /* Segment registers. */
  191. USHORT *cs, *ds, *es, *fs, *gs, *ss;
  192. ULONG *flags;
  193. /* CR0, mainly to let us figure out if we're in real or protect mode */
  194. ULONG *cr0;
  195. } NT_CPU_INFO;
  196. #endif // i386
  197. #define HANDLE_NULL ((HANDLE)NULL)
  198. #define LONG_TIMEOUT INFINITE
  199. #define READ_FIXED_ITEM(seg,offset,item) \
  200. if ( ReadItem(hProcess,seg,offset,&item,sizeof(item)) ) goto punt;
  201. #define WRITE_FIXED_ITEM(seg,offset,item) \
  202. if ( WriteItem(hProcess,seg,offset,&item,sizeof(item)) ) goto punt;
  203. #define LOAD_FIXED_ITEM(seg,offset,item) \
  204. ReadItem(hProcess,seg,offset,&item,sizeof(item))
  205. #define READ_SIZED_ITEM(seg,offset,item,size) \
  206. if ( ReadItem(hProcess,seg,offset,item,size) ) goto punt;
  207. #define WRITE_SIZED_ITEM(seg,offset,item,size) \
  208. if ( WriteItem(hProcess,seg,offset,item,size) ) goto punt;
  209. #define MALLOC(cb) HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, cb)
  210. #define FREE(addr) HeapFree(GetProcessHeap(), 0, addr)
  211. extern WORD wKernelSeg;
  212. extern DWORD dwOffsetTHHOOK;
  213. extern LPVOID lpRemoteAddress;
  214. extern DWORD lpRemoteBlock;
  215. extern BOOL fKernel386;
  216. extern DWORD dwLdtBase;
  217. extern DWORD dwIntelBase;
  218. extern LPVOID lpNtvdmState;
  219. extern LPVOID lpVdmDbgFlags;
  220. extern LPVOID lpNtCpuInfo;
  221. extern LPVOID lpVdmContext;
  222. extern LPVOID lpVdmBreakPoints;
  223. BOOL
  224. InternalGetThreadSelectorEntry(
  225. HANDLE hProcess,
  226. WORD wSelector,
  227. LPVDMLDT_ENTRY lpSelectorEntry
  228. );
  229. ULONG
  230. InternalGetPointer(
  231. HANDLE hProcess,
  232. WORD wSelector,
  233. DWORD dwOffset,
  234. BOOL fProtMode
  235. );
  236. BOOL
  237. ReadItem(
  238. HANDLE hProcess,
  239. WORD wSeg,
  240. DWORD dwOffset,
  241. LPVOID lpitem,
  242. UINT nSize
  243. );
  244. BOOL
  245. WriteItem(
  246. HANDLE hProcess,
  247. WORD wSeg,
  248. DWORD dwOffset,
  249. LPVOID lpitem,
  250. UINT nSize
  251. );
  252. BOOL
  253. CallRemote16(
  254. HANDLE hProcess,
  255. LPSTR lpModuleName,
  256. LPSTR lpEntryName,
  257. LPBYTE lpArgs,
  258. WORD wArgsPassed,
  259. WORD wArgsSize,
  260. LPDWORD lpdwReturnValue,
  261. DEBUGEVENTPROC lpEventProc,
  262. LPVOID lpData
  263. );
  264. DWORD
  265. GetRemoteBlock16(
  266. VOID
  267. );
  268. VOID
  269. ProcessBPNotification(
  270. LPDEBUG_EVENT lpDebugEvent
  271. );
  272. VOID
  273. ProcessInitNotification(
  274. LPDEBUG_EVENT lpDebugEvent
  275. );
  276. VOID
  277. ProcessSegmentNotification(
  278. LPDEBUG_EVENT lpDebugEvent
  279. );
  280. VOID
  281. ParseModuleName(
  282. LPSTR szName,
  283. LPSTR szPath
  284. );
  285. BOOL
  286. GetInfoBySegmentNumber(
  287. LPSTR szModule,
  288. WORD SegNumber,
  289. VDM_SEGINFO *si
  290. );
  291. BOOL
  292. EnumerateModulesForValue(
  293. BOOL (WINAPI *pfnEnumModuleProc)(LPSTR,LPSTR,PWORD,PDWORD,PWORD),
  294. LPSTR szSymbol,
  295. PWORD pSelector,
  296. PDWORD pOffset,
  297. PWORD pType
  298. );
  299. #ifndef _X86_
  300. WORD
  301. ReadWord(
  302. HANDLE hProcess,
  303. LPVOID lpAddress
  304. );
  305. DWORD
  306. ReadDword(
  307. HANDLE hProcess,
  308. LPVOID lpAddress
  309. );
  310. ULONG
  311. GetRegValue(
  312. HANDLE hProcess,
  313. NT_CPU_REG reg,
  314. BOOL bInNano,
  315. ULONG UMask
  316. );
  317. ULONG
  318. GetEspValue(
  319. HANDLE hProcess,
  320. NT_CPU_INFO nt_cpu_info,
  321. BOOL bInNano
  322. );
  323. #endif