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.

547 lines
11 KiB

  1. /*++
  2. Copyright(c) 1999-2002 Microsoft Corporation
  3. Module Name:
  4. mdump.h
  5. Abstract:
  6. Private header for minidump user-mode crashdump support.
  7. Author:
  8. Matthew D Hendel (math) 20-Aug-1999
  9. --*/
  10. #pragma once
  11. #define IsFlagSet(_var, _flag) ( ((_var) & (_flag)) != 0 )
  12. #define IsFlagClear(_var, _flag) ( !IsFlagSet(_var, _flag) )
  13. //
  14. // StartOfStack gives the lowest address of the stack. SizeOfStack gives
  15. // the size of the stack. Used together, they will give the memory region
  16. // used by the stack.
  17. //
  18. #define StartOfStack(_thread) ((_thread)->StackEnd)
  19. #define SizeOfStack(_thread) ((ULONG)((_thread)->StackBase - (_thread)->StackEnd)))
  20. // Types of memory regions.
  21. typedef enum
  22. {
  23. MEMBLOCK_OTHER,
  24. MEMBLOCK_MERGED,
  25. MEMBLOCK_STACK,
  26. MEMBLOCK_STORE,
  27. MEMBLOCK_DATA_SEG,
  28. MEMBLOCK_UNWIND_INFO,
  29. MEMBLOCK_INSTR_WINDOW,
  30. MEMBLOCK_PEB,
  31. MEMBLOCK_TEB,
  32. MEMBLOCK_INDIRECT,
  33. MEMBLOCK_PRIVATE_RW,
  34. MEMBLOCK_COR,
  35. MEMBLOCK_MEM_CALLBACK,
  36. } MEMBLOCK_TYPE;
  37. //
  38. // A VA_RANGE is a range of addresses that represents Size bytes beginning
  39. // at Start.
  40. //
  41. typedef struct _VA_RANGE {
  42. ULONG64 Start;
  43. ULONG Size;
  44. MEMBLOCK_TYPE Type;
  45. LIST_ENTRY NextLink;
  46. } VA_RANGE, *PVA_RANGE;
  47. //
  48. // INTERNAL_MODULE is the structure minidump uses internally to manage modules.
  49. // A linked list of INTERNAL_MODULE structures are built up when
  50. // GenGetProcessInfo is called.
  51. //
  52. typedef struct _INTERNAL_MODULE {
  53. //
  54. // File handle to the image.
  55. //
  56. HANDLE FileHandle;
  57. //
  58. // Base address, size, CheckSum, and TimeDateStamp for the image.
  59. //
  60. ULONG64 BaseOfImage;
  61. ULONG SizeOfImage;
  62. ULONG CheckSum;
  63. ULONG TimeDateStamp;
  64. //
  65. // Version information for the image.
  66. //
  67. VS_FIXEDFILEINFO VersionInfo;
  68. //
  69. // Buffer and size containing NB10 record for given module.
  70. //
  71. PVOID CvRecord;
  72. ULONG SizeOfCvRecord;
  73. //
  74. // Buffer and size of MISC debug record. We only get this with
  75. // images that have been split.
  76. //
  77. PVOID MiscRecord;
  78. ULONG SizeOfMiscRecord;
  79. //
  80. // Full path to the image.
  81. //
  82. WCHAR FullPath [ MAX_PATH + 1];
  83. // Portion of full path to write in the module list. This
  84. // allows paths to be filtered out for privacy reasons.
  85. PWSTR SavePath;
  86. //
  87. // What sections of the module does the client want written.
  88. //
  89. ULONG WriteFlags;
  90. //
  91. // Next image pointer.
  92. //
  93. LIST_ENTRY ModulesLink;
  94. } INTERNAL_MODULE, *PINTERNAL_MODULE;
  95. //
  96. // INTERNAL_UNLOADED_MODULE is the structure minidump uses
  97. // internally to manage unloaded modules.
  98. // A linked list of INTERNAL_UNLOADED_MODULE structures are built up when
  99. // GenGetProcessInfo is called.
  100. //
  101. //
  102. typedef struct _INTERNAL_UNLOADED_MODULE {
  103. ULONG64 BaseOfImage;
  104. ULONG SizeOfImage;
  105. ULONG CheckSum;
  106. ULONG TimeDateStamp;
  107. //
  108. // As much of the path to the image as can be recovered.
  109. //
  110. WCHAR Path[MAX_PATH + 1];
  111. //
  112. // Next image pointer.
  113. //
  114. LIST_ENTRY ModulesLink;
  115. } INTERNAL_UNLOADED_MODULE, *PINTERNAL_UNLOADED_MODULE;
  116. //
  117. // INTERNAL_THREAD is the structure the minidump uses internally to
  118. // manage threads. A list of INTERNAL_THREAD structures is built when
  119. // GenGetProcessInfo is called.
  120. //
  121. typedef struct _INTERNAL_THREAD {
  122. //
  123. // The Win32 thread id of the thread an an open handle for the
  124. // thread.
  125. //
  126. ULONG ThreadId;
  127. HANDLE ThreadHandle;
  128. //
  129. // Suspend count, priority, priority class for the thread.
  130. //
  131. ULONG SuspendCount;
  132. ULONG PriorityClass;
  133. ULONG Priority;
  134. //
  135. // Thread TEB, Context and Size of Context.
  136. //
  137. ULONG64 Teb;
  138. ULONG SizeOfTeb;
  139. PVOID ContextBuffer;
  140. //
  141. // Current program counter.
  142. //
  143. ULONG64 CurrentPc;
  144. //
  145. // Stack variables. Remember, the stack grows down, so StackBase is
  146. // the highest stack address and StackEnd is the lowest.
  147. //
  148. ULONG64 StackBase;
  149. ULONG64 StackEnd;
  150. //
  151. // Backing store variables.
  152. //
  153. ULONG64 BackingStoreBase;
  154. ULONG BackingStoreSize;
  155. //
  156. // What sections of the module we should actually write to the file.
  157. //
  158. ULONG WriteFlags;
  159. //
  160. // Link to next thread.
  161. //
  162. LIST_ENTRY ThreadsLink;
  163. } INTERNAL_THREAD, *PINTERNAL_THREAD;
  164. //
  165. // INTERNAL_FUNCTION_TABLE is the structure minidump uses
  166. // internally to manage function tables.
  167. // A linked list of INTERNAL_FUNCTION_TABLE structures is built up when
  168. // GenGetProcessInfo is called.
  169. //
  170. typedef struct _INTERNAL_FUNCTION_TABLE {
  171. ULONG64 MinimumAddress;
  172. ULONG64 MaximumAddress;
  173. ULONG64 BaseAddress;
  174. ULONG EntryCount;
  175. PVOID RawTable;
  176. PVOID RawEntries;
  177. LIST_ENTRY TableLink;
  178. } INTERNAL_FUNCTION_TABLE, *PINTERNAL_FUNCTION_TABLE;
  179. typedef struct _INTERNAL_PROCESS {
  180. //
  181. // The process id for the process.
  182. //
  183. ULONG ProcessId;
  184. //
  185. // Process data.
  186. //
  187. ULONG64 Peb;
  188. ULONG SizeOfPeb;
  189. //
  190. // Process run time information.
  191. //
  192. BOOL TimesValid;
  193. ULONG CreateTime;
  194. ULONG UserTime;
  195. ULONG KernelTime;
  196. //
  197. // An open handle to the process with read permissions.
  198. //
  199. HANDLE ProcessHandle;
  200. //
  201. // Number of threads for the process.
  202. //
  203. ULONG NumberOfThreads;
  204. ULONG NumberOfThreadsToWrite;
  205. ULONG MaxStackOrStoreSize;
  206. //
  207. // Number of modules for the process.
  208. //
  209. ULONG NumberOfModules;
  210. ULONG NumberOfModulesToWrite;
  211. //
  212. // Number of unloaded modules for the process.
  213. //
  214. ULONG NumberOfUnloadedModules;
  215. //
  216. // Number of function tables for the process.
  217. //
  218. ULONG NumberOfFunctionTables;
  219. //
  220. // Thread, module and function table lists for the process.
  221. //
  222. LIST_ENTRY ThreadList;
  223. LIST_ENTRY ModuleList;
  224. LIST_ENTRY UnloadedModuleList;
  225. LIST_ENTRY FunctionTableList;
  226. //
  227. // List of memory blocks to include for the process.
  228. //
  229. LIST_ENTRY MemoryBlocks;
  230. ULONG NumberOfMemoryBlocks;
  231. ULONG SizeOfMemoryBlocks;
  232. //
  233. // Indicates whether mscorwks, mscorsvr or mscoree is
  234. // present in the process. These DLLs are used as an indicator
  235. // of whether the runtime is running in the process or not.
  236. //
  237. PWSTR CorDllType;
  238. ULONG64 CorDllBase;
  239. VS_FIXEDFILEINFO CorDllVer;
  240. WCHAR CorDllPath[MAX_PATH + 1];
  241. } INTERNAL_PROCESS, *PINTERNAL_PROCESS;
  242. //
  243. // The visible streams are: (1) machine info, (2) exception, (3) thread list,
  244. // (4) module list (5) memory list (6) misc info.
  245. // We also add two extra for post-processing tools that want to add data later.
  246. //
  247. #define NUMBER_OF_STREAMS (8)
  248. //
  249. // MINIDUMP_STREAM_INFO is the structure used by the minidump to manage
  250. // it's internal data streams.
  251. //
  252. typedef struct _MINIDUMP_STREAM_INFO {
  253. //
  254. // How many streams we have.
  255. //
  256. ULONG NumberOfStreams;
  257. //
  258. // Reserved space for header.
  259. //
  260. ULONG RvaOfHeader;
  261. ULONG SizeOfHeader;
  262. //
  263. // Reserved space for directory.
  264. //
  265. ULONG RvaOfDirectory;
  266. ULONG SizeOfDirectory;
  267. //
  268. // Reserved space for system info.
  269. //
  270. ULONG RvaOfSystemInfo;
  271. ULONG SizeOfSystemInfo;
  272. ULONG VersionStringLength;
  273. //
  274. // Reserved space for misc info.
  275. //
  276. ULONG RvaOfMiscInfo;
  277. //
  278. // Reserved space for exception list.
  279. //
  280. ULONG RvaOfException;
  281. ULONG SizeOfException;
  282. //
  283. // Reserved space for thread list.
  284. //
  285. ULONG RvaOfThreadList;
  286. ULONG SizeOfThreadList;
  287. ULONG RvaForCurThread;
  288. ULONG ThreadStructSize;
  289. //
  290. // Reserved space for module list.
  291. //
  292. ULONG RvaOfModuleList;
  293. ULONG SizeOfModuleList;
  294. ULONG RvaForCurModule;
  295. //
  296. // Reserved space for unloaded module list.
  297. //
  298. ULONG RvaOfUnloadedModuleList;
  299. ULONG SizeOfUnloadedModuleList;
  300. ULONG RvaForCurUnloadedModule;
  301. //
  302. // Reserved space for function table list.
  303. //
  304. ULONG RvaOfFunctionTableList;
  305. ULONG SizeOfFunctionTableList;
  306. //
  307. // Reserved space for memory descriptors.
  308. //
  309. ULONG RvaOfMemoryDescriptors;
  310. ULONG SizeOfMemoryDescriptors;
  311. ULONG RvaForCurMemoryDescriptor;
  312. //
  313. // Reserved space for actual memory data.
  314. //
  315. ULONG RvaOfMemoryData;
  316. ULONG SizeOfMemoryData;
  317. ULONG RvaForCurMemoryData;
  318. //
  319. // Reserved space for strings.
  320. //
  321. ULONG RvaOfStringPool;
  322. ULONG SizeOfStringPool;
  323. ULONG RvaForCurString;
  324. //
  325. // Reserved space for other data like contexts, debug info records,
  326. // etc.
  327. //
  328. ULONG RvaOfOther;
  329. ULONG SizeOfOther;
  330. ULONG RvaForCurOther;
  331. //
  332. // Reserved space for user streams.
  333. //
  334. ULONG RvaOfUserStreams;
  335. ULONG SizeOfUserStreams;
  336. //
  337. // Reserved space for handle data.
  338. //
  339. ULONG RvaOfHandleData;
  340. ULONG SizeOfHandleData;
  341. } MINIDUMP_STREAM_INFO, *PMINIDUMP_STREAM_INFO;
  342. typedef struct _EXCEPTION_INFO {
  343. DWORD ThreadId;
  344. MINIDUMP_EXCEPTION ExceptionRecord;
  345. PVOID ContextRecord;
  346. } EXCEPTION_INFO, *PEXCEPTION_INFO;
  347. //
  348. // Status flags for accumulated status.
  349. //
  350. // Ran out of memory during dump writing.
  351. #define MDSTATUS_OUT_OF_MEMORY 0x00000001
  352. // Process memory read failed during dump writing.
  353. #define MDSTATUS_UNABLE_TO_READ_MEMORY 0x00000002
  354. // OS routine failed during dump writing.
  355. #define MDSTATUS_CALL_FAILED 0x00000004
  356. // Unexpected internal failure during dump writing.
  357. #define MDSTATUS_INTERNAL_ERROR 0x00000008
  358. //
  359. // Global state carried through a entire dump write operation.
  360. //
  361. typedef struct _MINIDUMP_STATE {
  362. //
  363. // Input values.
  364. //
  365. HANDLE ProcessHandle;
  366. DWORD ProcessId;
  367. MiniDumpSystemProvider* SysProv;
  368. MiniDumpOutputProvider* OutProv;
  369. MiniDumpAllocationProvider* AllocProv;
  370. ULONG DumpType;
  371. MINIDUMP_CALLBACK_ROUTINE CallbackRoutine;
  372. PVOID CallbackParam;
  373. //
  374. // Global state.
  375. //
  376. ULONG CpuType;
  377. PCWSTR CpuTypeName;
  378. BOOL BackingStore;
  379. ULONG OsPlatformId;
  380. ULONG OsMajor;
  381. ULONG OsMinor;
  382. ULONG OsServicePack;
  383. ULONG OsBuildNumber;
  384. USHORT OsProductType;
  385. USHORT OsSuiteMask;
  386. ULONG ContextSize;
  387. ULONG RegScanOffset;
  388. ULONG RegScanCount;
  389. ULONG ExRecordSize;
  390. ULONG PtrSize;
  391. ULONG PageSize;
  392. ULONG FuncTableSize;
  393. ULONG FuncTableEntrySize;
  394. ULONG InstructionWindowSize;
  395. ULONG AccumStatus;
  396. } MINIDUMP_STATE, *PMINIDUMP_STATE;