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.

316 lines
14 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. faultrep.cpp
  5. Abstract:
  6. Constants & useful header type stuff for fault reporting
  7. Revision History:
  8. created derekm 07/07/00
  9. ******************************************************************************/
  10. #ifndef FRUTIL_H
  11. #define FRUTIL_H
  12. ///////////////////////////////////////////////////////////////////////////////
  13. // Global stuff
  14. // globals
  15. extern HINSTANCE g_hInstance;
  16. extern BOOL g_fAlreadyReportingFault;
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // Constants
  19. // command lines
  20. const WCHAR c_wszDWCmdLineU[] = L"%ls\\dwwin.exe -x -s %lu";
  21. const WCHAR c_wszDWCmdLineKH[] = L"%ls\\dwwin.exe -d %ls";
  22. const WCHAR c_wszDRCmdLineMD[] = L"%ls\\dumprep.exe %ld -dm 7 7 %ls %I64d";
  23. // manifest constants
  24. const WCHAR c_wszManMisc[] = L"\r\nServer=%ls\r\nUI LCID=%d\r\nFlags=%d\r\nBrand=%ls\r\nTitleName=";
  25. const WCHAR c_wszManSubPath[] = L"\r\nRegSubPath=Microsoft\\PCHealth\\ErrorReporting\\DW";
  26. const WCHAR c_wszManPID[] = L"\r\nDigPidRegPath=HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId";
  27. const WCHAR c_wszManCorpPath[] = L"\r\nErrorSubPath=";
  28. const WCHAR c_wszManFiles[] = L"\r\nDataFiles=";
  29. const WCHAR c_wszManHdrText[] = L"\r\nHeaderText=";
  30. const WCHAR c_wszManErrText[] = L"\r\nErrorText=";
  31. const WCHAR c_wszManPleaText[] = L"\r\nPlea=";
  32. const WCHAR c_wszManSendText[] = L"\r\nReportButton=";
  33. const WCHAR c_wszManNSendText[] = L"\r\nNoReportButton=";
  34. const WCHAR c_wszManEventSrc[] = L"\r\nEventLogSource=";
  35. const WCHAR c_wszManStageOne[] = L"\r\nStage1URL=";
  36. const WCHAR c_wszManStageTwo[] = L"\r\nStage2URL=";
  37. const WCHAR c_wszManHeapDump[] = L"\r\nHeap=";
  38. const WCHAR c_wszManKS2[] = L"\r\nStage2URL=/dw/bluetwo.asp?BCCode=%x&BCP1=%p&BCP2=%p&BCP3=%p&BCP4=%p&OSVer=%d_%d_%d&SP=%d_%d&Product=%d_%d";
  39. const WCHAR c_wszManSS2[] = L"\r\nStage2URL=/dw/ShutdownTwo.asp?OSVer=%d_%d_%d&SP=%d_%d&Product=%d_%d";
  40. const WCHAR c_wszManFS164[] = L"\r\nStage1URL=/StageOne/%ls/%d_%d_%d_%d/%ls/%d_%d_%d_%d/%016I64x.htm";
  41. const WCHAR c_wszManFS264[] = L"\r\nStage2URL=/dw/stagetwo64.asp?szAppName=%ls&szAppVer=%d.%d.%d.%d&szModName=%ls&szModVer=%d.%d.%d.%d&offset=%016I64x";
  42. const WCHAR c_wszManFCP64[] = L"%ls\\%d.%d.%d.%d\\%ls\\%d.%d.%d.%d\\%016I64x";
  43. const WCHAR c_wszManHS164[] = L"\r\nStage1URL=/StageOne/%ls/%ls/hangme.hng/0_0_0_0/ffffffffffffffff.htm";
  44. const WCHAR c_wszManHS264[] = L"\r\nStage2URL=/dw/stagetwo64.asp?szAppName=%ls&szAppVer=%ls&szModName=hangme.hng&szModVer=0.0.0.0&offset=ffffffffffffffff";
  45. const WCHAR c_wszManHCP64[] = L"%ls\\%ls\\hangme.hng\\0.0.0.0\\ffffffffffffffff";
  46. const WCHAR c_wszManFS132[] = L"\r\nStage1URL=/StageOne/%ls/%d_%d_%d_%d/%ls/%d_%d_%d_%d/%08x.htm";
  47. const WCHAR c_wszManFS232[] = L"\r\nStage2URL=/dw/stagetwo.asp?szAppName=%ls&szAppVer=%d.%d.%d.%d&szModName=%ls&szModVer=%d.%d.%d.%d&offset=%08x";
  48. const WCHAR c_wszManFCP32[] = L"%ls\\%d.%d.%d.%d\\%ls\\%d.%d.%d.%d\\%08x";
  49. const WCHAR c_wszManHS132[] = L"\r\nStage1URL=/StageOne/%ls/%ls/hangme.hng/0_0_0_0/ffffffff.htm";
  50. const WCHAR c_wszManHS232[] = L"\r\nStage2URL=/dw/stagetwo.asp?szAppName=%ls&szAppVer=%ls&szModName=hangme.hng&szModVer=0.0.0.0&offset=ffffffff";
  51. const WCHAR c_wszManHCP32[] = L"%ls\\%ls\\hangme.hng\\0.0.0.0\\ffffffff";
  52. const WCHAR c_wszManKCorpPath[] = L"blue";
  53. const WCHAR c_wszManSCorpPath[] = L"shutdown";
  54. // note: 3 * size of (szAppName + szModName) still need to be added to this value
  55. const DWORD c_cbFaultBlob32 = (sizeof(c_wszManFS132) + sizeof(c_wszManFS232) + sizeof(c_wszManFCP32)) + // initial strings
  56. (8 * 3 * 5 * sizeof(WCHAR)) + // 3 strings * 8 version fields per string * upto 5 chars per field
  57. 8; // 8 chars for hex offset
  58. const DWORD c_cbFaultBlob64 = (sizeof(c_wszManFS164) + sizeof(c_wszManFS264) + sizeof(c_wszManFCP64)) + // initial strings
  59. (8 * 3 * 5 * sizeof(WCHAR)) + // 3 strings * 8 version fields per string * upto 5 chars per field
  60. 16; // 8 chars for hex offset
  61. // note, 3 * size of (szAppName + szAppVer) still need to be added to this value
  62. const DWORD c_cbHangBlob32 = (sizeof(c_wszManHS132) + sizeof(c_wszManHS232) + sizeof(c_wszManHCP32)); // initial strings
  63. const DWORD c_cbHangBlob64 = (sizeof(c_wszManHS164) + sizeof(c_wszManHS264) + sizeof(c_wszManHCP64)); // initial strings
  64. // misc DW constants
  65. const WCHAR c_wszDWDefServerI[] = L"officewatson";
  66. const WCHAR c_wszDWDefServerE[] = L"watson.microsoft.com";
  67. const WCHAR c_wszDWBrand[] = L"WINDOWS";
  68. const WCHAR c_wszLogFileName[] = L"errorlog.log";
  69. const WCHAR c_wszFaultEvSrc[] = L"Application Error";
  70. // queue stuff
  71. const WCHAR c_wszQSubdir[] = L"PCHealth\\ErrorRep\\UserDumps\\";
  72. const WCHAR c_wszQFileName[] = L"%ls.%04d%02d%02d-%02d%02d%02d-00.mdmp";
  73. // reg keys & values
  74. const WCHAR c_wszRPSvc[] = L"System\\CurrentControlSet\\Services";
  75. const WCHAR c_wszRVSvcType[] = L"Type";
  76. const WCHAR c_wszRVSvcPath[] = L"ImagePath";
  77. const WCHAR c_wszRKSetup[] = L"System\\Setup";
  78. const WCHAR c_wszRVSetupNow[] = L"SystemSetupInProgress";
  79. const WCHAR c_wszRVVKFC[] = L"%systemroot%\\system32\\dumprep 0 -k";
  80. const WCHAR c_wszRVVUFC[] = L"%systemroot%\\system32\\dumprep 0 -u";
  81. const WCHAR c_wszRVVSEC[] = L"%systemroot%\\system32\\dumprep 0 -s";
  82. const WCHAR c_wszRKBiosInfo[] = L"HARDWARE\\Description\\System";
  83. const WCHAR c_wszRVBiosVer[] = L"SystemBiosVersion";
  84. const WCHAR c_wszRVBiosDate[] = L"SystemBiosDate";
  85. const WCHAR c_wszRKProcInfo[] = L"HARDWARE\\Description\\System\\CentralProcessor\\0";
  86. const WCHAR c_wszRKWNTCurVer[] = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion";
  87. const WCHAR c_wszRVProdName[] = L"ProductName";
  88. const WCHAR c_wszRVBuildLab[] = L"BuildLab";
  89. const WCHAR c_wszRKAeDebug[] = L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug";
  90. const WCHAR c_wszRVDebugger[] = L"Debugger";
  91. const WCHAR c_wszRVAuto[] = L"Auto";
  92. // shared memory constants
  93. const char c_szDWRegSubPath[] = "Microsoft\\PCHealth\\ErrorReporting\\DW";
  94. const char c_szDWDefServerI[] = "officewatson";
  95. const char c_szDWDefServerE[] = "watson.microsoft.com";
  96. const char c_szDWBrand[] = "WINDOWS";
  97. const char c_szRKVDigPid[] = "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\DigitalProductId";
  98. // kernel fault extra info constants
  99. const WCHAR c_wszXMLOpenDevices[] = L"<DEVICES>\r\n";
  100. const WCHAR c_wszXMLCloseDevices[] = L"</DEVICES>\r\n";
  101. const WCHAR c_wszXMLOpenDevice[] = L"\t<DEVICE>\r\n";
  102. const WCHAR c_wszXMLCloseDevice[] = L"\t</DEVICE>\r\n";
  103. const WCHAR c_wszXMLOpenDevDesc[] = L"\t\t<DESCRIPTION>";
  104. const WCHAR c_wszXMLCloseDevDesc[] = L"</DESCRIPTION>\r\n";
  105. const WCHAR c_wszXMLOpenDevHwId[] = L"\t\t<HARDWAREID>";
  106. const WCHAR c_wszXMLCloseDevHwId[] = L"</HARDWAREID>\r\n";
  107. const WCHAR c_wszXMLOpenDevService[] = L"\t\t<SERVICE>";
  108. const WCHAR c_wszXMLCloseDevService[] = L"</SERVICE>\r\n";
  109. const WCHAR c_wszXMLOpenDevImage[] = L"\t\t<DRIVER>";
  110. const WCHAR c_wszXMLCloseDevImage[] = L"</DRIVER>\r\n";
  111. const WCHAR c_wszXMLHeader[] = L"<?xml version=\"1.0\" encoding=\"Unicode\" ?>\r\n<SYSTEMINFO>\r\n<SYSTEM>\r\n\t<OSNAME>%ls %ls</OSNAME>\r\n\t<OSVER>%d.%d.%d %d.%d</OSVER>\r\n\t<OSLANGUAGE>%d</OSLANGUAGE>\r\n";
  112. const WCHAR c_wszXMLCloseSystem[] = L"</SYSTEM>\r\n";
  113. const WCHAR c_wszXMLOpenDrivers[] = L"<DRIVERS>\r\n";
  114. const WCHAR c_wszXMLDriver1[] = L"\t<DRIVER>\r\n\t\t<FILENAME>";
  115. const WCHAR c_wszXMLDriver2[] = L"</FILENAME>\r\n\t\t<FILESIZE>%d</FILESIZE>\r\n\t\t<CREATIONDATE>%02d-%02d-%04d %02d:%02d:%02d</CREATIONDATE>\r\n\t\t<VERSION>";
  116. const WCHAR c_wszXMLDriver3[] = L"</VERSION>\r\n\t\t<MANUFACTURER>";
  117. const WCHAR c_wszXMLDriver4[] = L"</MANUFACTURER>\r\n\t<PRODUCTNAME>\r\n";
  118. const WCHAR c_wszXMLDriver5[] = L"</PRODUCTNAME>\r\n\t</DRIVER>\r\n";
  119. const WCHAR c_wszXMLFooter[] = L"</DRIVERS>\r\n</SYSTEMINFO>\r\n";
  120. const WCHAR c_wszDriversDir[] = L"\\drivers\\*";
  121. const WCHAR c_wszKrnlCmdLine[] = L"\\dumprep 0 -kg";
  122. const WCHAR c_wszShutCmdLine[] = L"\\dumprep 0 -sg";
  123. // event sources
  124. const WCHAR c_wszHangEventSrc[] = L"Application Hang";
  125. const WCHAR c_wszKrnlEventSrc[] = L"System Error";
  126. const WCHAR c_wszUserEventSrc[] = L"Application Error";
  127. // filename stuff
  128. const WCHAR c_wszACFileName[] = L"appcompat.txt";
  129. const WCHAR c_wszManFileName[] = L"manifest.txt";
  130. const WCHAR c_wszEventData[] = L"sysdata.xml";
  131. // event types
  132. const WCHAR c_wszKernel[] = L"Kernel fault";
  133. const WCHAR c_wszShutdown[] = L"Unplanned shutdown";
  134. const WCHAR c_wszUnknown[] = L"Unknown event";
  135. const LPCWSTR c_rgwszEvents[] = { c_wszKernel, c_wszShutdown, c_wszUnknown };
  136. #ifdef MANIFEST_HEAP
  137. // minidump flags
  138. const ULONG c_ulModuleWriteDefault =
  139. ModuleWriteModule | ModuleWriteMiscRecord | ModuleWriteCvRecord;
  140. const ULONG c_ulThreadWriteDefault =
  141. ThreadWriteThread | ThreadWriteStack |
  142. ThreadWriteContext | ThreadWriteBackingStore |
  143. ThreadWriteInstructionWindow;
  144. #endif // MANIFEST_HEAP
  145. // misc
  146. const WCHAR c_wszDbgHelpDll[] = L"\\dbghelp.dll";
  147. const WCHAR c_wszAppHelpDll[] = L"\\apphelp.dll";
  148. const WCHAR c_wszKernel32Dll[] = L"\\kernel32.dll";
  149. #ifdef _WIN64
  150. #define c_wszManFS1 c_wszManFS164
  151. #define c_wszManFS2 c_wszManFS264
  152. #define c_wszManHS1 c_wszManHS164
  153. #define c_wszManHS2 c_wszManHS264
  154. #else
  155. #define c_wszManFS1 c_wszManFS132
  156. #define c_wszManFS2 c_wszManFS232
  157. #define c_wszManHS1 c_wszManHS132
  158. #define c_wszManHS2 c_wszManHS232
  159. #endif
  160. ///////////////////////////////////////////////////////////////////////////////
  161. // internal structs
  162. typedef enum tagEManifestOptions
  163. {
  164. emoUseIEforURLs = 0x1,
  165. emoSupressBucketLogs = 0x2,
  166. emoNoDefCabLimit = 0x4,
  167. emoShowDebugButton = 0x8,
  168. } EManifestOptions;
  169. typedef struct tagSDWManifestBlob
  170. {
  171. LPCWSTR wszTitle;
  172. UINT nidTitle;
  173. LPCWSTR wszErrMsg;
  174. UINT nidErrMsg;
  175. LPCWSTR wszHdr;
  176. UINT nidHdr;
  177. LPCWSTR wszStage1;
  178. LPCWSTR wszStage2;
  179. LPCWSTR wszBrand;
  180. LPCWSTR wszFileList;
  181. LPCWSTR wszEventSrc;
  182. LPCWSTR dwEventId;
  183. LPCWSTR wszCorpPath;
  184. LPCWSTR wszSendBtn;
  185. LPCWSTR wszNoSendBtn;
  186. LPWSTR wszPlea;
  187. DWORD dwOptions;
  188. // fault / hang reporting specific stuff
  189. PROCESS_INFORMATION pi;
  190. LPVOID pvEnv;
  191. HANDLE hToken;
  192. BOOL fIsMSApp;
  193. } SDWManifestBlob;
  194. typedef struct tagSSuspendThreads
  195. {
  196. HANDLE *rghThreads;
  197. DWORD cThreads;
  198. } SSuspendThreads;
  199. ///////////////////////////////////////////////////////////////////////////////
  200. // prototypes
  201. void __cdecl TextLogOut(PCSTR pszFormat, ...);
  202. #ifndef MANIFEST_HEAP
  203. BOOL InternalGenerateMinidump(HANDLE hProc, DWORD dwpid, LPCWSTR wszPath,
  204. SMDumpOptions *psmdo);
  205. BOOL InternalGenerateMinidump(HANDLE hProc, DWORD dwpid, HANDLE hFile,
  206. SMDumpOptions *psmdo, LPCWSTR wszPath);
  207. #else
  208. BOOL InternalGenerateMinidump(HANDLE hProc, DWORD dwpid, LPCWSTR wszPath,
  209. SMDumpOptions *psmdo, BOOL f64bit);
  210. BOOL InternalGenerateMinidumpEx(HANDLE hProc, DWORD dwpid, HANDLE hFile,
  211. SMDumpOptions *psmdo, LPCWSTR wszPath, BOOL f64bit);
  212. BOOL InternalGenFullAndTriageMinidumps(HANDLE hProc, DWORD dwpid, LPCWSTR wszPath,
  213. HANDLE hFile, SMDumpOptions *psmdo, BOOL f64bit);
  214. BOOL CopyFullAndTriageMiniDumps(LPWSTR pwszTriageDumpFrom,LPWSTR pwszTriageDumpTo);
  215. #endif // MANIFEST_HEAP
  216. HRESULT GetExePath(HANDLE hProc, LPWSTR wszPath, DWORD cchPath);
  217. HRESULT GetVerName(LPWSTR wszModule, LPWSTR wszName, DWORD cchName,
  218. LPWSTR wszVer = NULL, DWORD cchVer = 0,
  219. LPWSTR wszCompany = NULL, DWORD cchCompany = 0,
  220. BOOL fAcceptUnicodeCP = FALSE,
  221. BOOL fWantActualName = FALSE);
  222. HRESULT BuildManifestURLs(LPWSTR wszAppName, LPWSTR wszModName,
  223. WORD rgAppVer[4], WORD rgModVer[4], UINT64 pvOffset,
  224. BOOL f64Bit, LPWSTR *ppwszS1, LPWSTR *ppwszS2,
  225. LPWSTR *ppwszCP, BYTE **ppb);
  226. EFaultRepRetVal StartDWManifest(CPFFaultClientCfg &oCfg, SDWManifestBlob& dwmb,
  227. LPWSTR wszManifestIn = NULL,
  228. BOOL fAllowSend = TRUE,
  229. DWORD dwTimeout = 300000);
  230. BOOL TransformForWire(LPCWSTR wszSrc, LPWSTR wszDest, DWORD cchDest);
  231. LPWSTR MarshallString(LPCWSTR wszSrc, PBYTE pBase, ULONG cbMaxBuf,
  232. PBYTE *ppToWrite, DWORD *pcbWritten);
  233. BOOL GetAppCompatData(LPCWSTR wszAppPath, LPCWSTR wszModPath, LPCWSTR wszFile);
  234. BOOL IsASCII(LPCWSTR wszSrc);
  235. void FreezeAllThreads(void);
  236. BOOL DoUserContextsMatch(void);
  237. BOOL DoWinstaDesktopMatch(void);
  238. BOOL AmIPrivileged(BOOL fOnlyCheckLS);
  239. BOOL FindAdminSession(DWORD *pdwSession, HANDLE *phToken);
  240. BOOL FreezeAllThreads(DWORD dwpid, DWORD dwtidFilter, SSuspendThreads *pst);
  241. BOOL ThawAllThreads(SSuspendThreads *pst);
  242. HRESULT LogHang(LPCWSTR wszApp, WORD *rgAppVer, LPCWSTR wszMod, WORD *rgModVer,
  243. ULONG64 ulOffset, BOOL f64bit);
  244. HRESULT LogUser(LPCWSTR wszApp, WORD *rgAppVer, LPCWSTR wszMod, WORD *rgModVer,
  245. ULONG64 ulOffset, BOOL f64bit, DWORD dwEventID);
  246. #ifndef _WIN64
  247. HRESULT LogKrnl(ULONG ulBCCode, ULONG ulBCP1, ULONG ulBCP2, ULONG ulBCP3,
  248. ULONG ulBCP4);
  249. #else
  250. HRESULT LogKrnl(ULONG ulBCCode, ULONG64 ulBCP1, ULONG64 ulBCP2, ULONG64 ulBCP3,
  251. ULONG64 ulBCP4);
  252. #endif
  253. ///////////////////////////////////////////////////////////////////////////////
  254. // inlines
  255. // **************************************************************************
  256. inline DWORD RolloverSubtract(DWORD dwA, DWORD dwB)
  257. {
  258. return (dwA >= dwB) ? (dwA - dwB) : (dwA + ((DWORD)-1 - dwB));
  259. }
  260. #endif