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.

230 lines
6.0 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. faultrep.cpp
  5. Abstract:
  6. Implements misc fault reporting functions
  7. Revision History:
  8. created derekm 07/07/00
  9. ******************************************************************************/
  10. #include "stdafx.h"
  11. #include "wchar.h"
  12. ///////////////////////////////////////////////////////////////////////////////
  13. // Global stuff
  14. HINSTANCE g_hInstance = NULL;
  15. BOOL g_fAlreadyReportingFault = FALSE;
  16. #ifdef DEBUG
  17. BOOL g_fAlreadySpewing = FALSE;
  18. #endif
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // DllMain
  21. // **************************************************************************
  22. extern "C"
  23. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  24. {
  25. switch(dwReason)
  26. {
  27. case DLL_PROCESS_ATTACH:
  28. g_hInstance = hInstance;
  29. DisableThreadLibraryCalls(hInstance);
  30. #ifdef DEBUG
  31. if (!g_fAlreadySpewing)
  32. {
  33. INIT_TRACING;
  34. g_fAlreadySpewing = TRUE;
  35. }
  36. #endif
  37. break;
  38. case DLL_PROCESS_DETACH:
  39. break;
  40. }
  41. return TRUE;
  42. }
  43. ///////////////////////////////////////////////////////////////////////////////
  44. // exported functions
  45. // **************************************************************************
  46. BOOL APIENTRY CreateMinidumpW(DWORD dwpid, LPCWSTR wszPath,
  47. SMDumpOptions *psmdo)
  48. {
  49. USE_TRACING("CreateMinidumpW");
  50. SMDumpOptions smdo;
  51. HANDLE hProc;
  52. BOOL fRet, f64bit;
  53. if (dwpid == 0 || wszPath == NULL)
  54. {
  55. SetLastError(ERROR_INVALID_PARAMETER);
  56. return FALSE;
  57. }
  58. hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE,
  59. dwpid);
  60. if (hProc == NULL)
  61. return FALSE;
  62. #ifdef _WIN64
  63. ULONG_PTR Wow64Info = 0;
  64. NTSTATUS Status;
  65. // Do something here to decide if this is a 32 or 64 bit app...
  66. // need to determine if we're a Wow64 process so we can build the appropriate
  67. // signatures...
  68. Status = NtQueryInformationProcess(hProc, ProcessWow64Information,
  69. &Wow64Info, sizeof(Wow64Info), NULL);
  70. if (NT_SUCCESS(Status) == FALSE) {
  71. // assume that this is 64 bit if we fail
  72. f64bit = TRUE;
  73. } else {
  74. // use the value returned from ntdll
  75. f64bit = (Wow64Info == 0);
  76. }
  77. #else
  78. f64bit=FALSE;
  79. #endif
  80. // if we want to collect a signature, by default the module needs to
  81. // be set to 'unknown'
  82. if (psmdo && (psmdo->dfOptions & dfCollectSig) != 0)
  83. wcscpy(psmdo->wszMod, L"unknown");
  84. #ifndef MANIFEST_HEAP
  85. fRet = InternalGenerateMinidump(hProc, dwpid, wszPath, psmdo);
  86. #else
  87. fRet = InternalGenerateMinidump(hProc, dwpid, wszPath, psmdo, f64bit);
  88. #endif
  89. CloseHandle(hProc);
  90. return fRet;
  91. }
  92. // **************************************************************************
  93. BOOL APIENTRY CreateMinidumpA(DWORD dwpid, LPCSTR szPath, SMDumpOptions *psmdo)
  94. {
  95. USE_TRACING("CreateMinidumpA");
  96. LPWSTR wszPath = NULL;
  97. DWORD cch;
  98. if (szPath == NULL)
  99. {
  100. SetLastError(ERROR_INVALID_PARAMETER);
  101. return FALSE;
  102. }
  103. cch = MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, 0);
  104. __try { wszPath = (LPWSTR)_alloca(cch * sizeof(WCHAR)); }
  105. __except(EXCEPTION_STACK_OVERFLOW) { wszPath = NULL; }
  106. if (wszPath == NULL)
  107. {
  108. SetLastError(ERROR_OUTOFMEMORY);
  109. return FALSE;
  110. }
  111. if (MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, cch) == 0)
  112. return FALSE;
  113. return CreateMinidumpW(dwpid, wszPath, psmdo);
  114. }
  115. // **************************************************************************
  116. BOOL AddERExcludedApplicationW(LPCWSTR wszApplication)
  117. {
  118. USE_TRACING("AddERExcludedApplicationW");
  119. LPCWSTR pwszApp;
  120. DWORD dw, dwData;
  121. HKEY hkey = NULL;
  122. if (wszApplication == NULL)
  123. {
  124. SetLastError(ERROR_INVALID_PARAMETER);
  125. return FALSE;
  126. }
  127. // make sure the user didn't give us a full path (ie, one containing
  128. // backslashes). If he did, only use the part of the string after the
  129. // last backslash
  130. for (pwszApp = wszApplication + wcslen(wszApplication);
  131. *pwszApp != L'\\' && pwszApp > wszApplication;
  132. pwszApp--);
  133. if (*pwszApp == L'\\')
  134. pwszApp++;
  135. if (*pwszApp == L'\0')
  136. {
  137. SetLastError(ERROR_INVALID_PARAMETER);
  138. return FALSE;
  139. }
  140. // gotta open the reg key
  141. dw = RegCreateKeyExW(HKEY_LOCAL_MACHINE, c_wszRPCfgCPLExList, 0, NULL, 0,
  142. KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL, &hkey, NULL);
  143. if (dw != ERROR_SUCCESS)
  144. {
  145. SetLastError(dw);
  146. return FALSE;
  147. }
  148. // set the value
  149. dwData = 1;
  150. dw = RegSetValueExW(hkey, pwszApp, NULL, REG_DWORD, (PBYTE)&dwData,
  151. sizeof(dwData));
  152. RegCloseKey(hkey);
  153. if (dw != ERROR_SUCCESS)
  154. {
  155. SetLastError(dw);
  156. return FALSE;
  157. }
  158. return TRUE;
  159. }
  160. // **************************************************************************
  161. BOOL AddERExcludedApplicationA(LPCSTR szApplication)
  162. {
  163. USE_TRACING("AddERExcludedApplicationA");
  164. LPWSTR wszApp = NULL;
  165. DWORD cch;
  166. if (szApplication == NULL || szApplication[0] == '\0')
  167. {
  168. SetLastError(ERROR_INVALID_PARAMETER);
  169. return FALSE;
  170. }
  171. cch = MultiByteToWideChar(CP_ACP, 0, szApplication, -1, wszApp, 0);
  172. __try { wszApp = (LPWSTR)_alloca(cch * sizeof(WCHAR)); }
  173. __except(EXCEPTION_STACK_OVERFLOW) { wszApp = NULL; }
  174. if (wszApp == NULL)
  175. {
  176. SetLastError(ERROR_OUTOFMEMORY);
  177. return FALSE;
  178. }
  179. if (MultiByteToWideChar(CP_ACP, 0, szApplication, -1, wszApp, cch) == 0)
  180. return FALSE;
  181. return AddERExcludedApplicationW(wszApp);
  182. }