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.

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