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.

208 lines
5.6 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. #ifdef THIS_FILE
  20. #undef THIS_FILE
  21. #endif
  22. static char __szTraceSourceFile[] = __FILE__;
  23. #define THIS_FILE __szTraceSourceFile
  24. ///////////////////////////////////////////////////////////////////////////////
  25. // DllMain
  26. // **************************************************************************
  27. extern "C"
  28. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  29. {
  30. switch(dwReason)
  31. {
  32. case DLL_PROCESS_ATTACH:
  33. g_hInstance = hInstance;
  34. DisableThreadLibraryCalls(hInstance);
  35. #ifdef DEBUG
  36. if (!g_fAlreadySpewing)
  37. {
  38. INIT_TRACING;
  39. g_fAlreadySpewing = TRUE;
  40. }
  41. #endif
  42. break;
  43. case DLL_PROCESS_DETACH:
  44. break;
  45. }
  46. return TRUE;
  47. }
  48. ///////////////////////////////////////////////////////////////////////////////
  49. // exported functions
  50. // **************************************************************************
  51. BOOL APIENTRY CreateMinidumpW(DWORD dwpid, LPCWSTR wszPath,
  52. SMDumpOptions *psmdo)
  53. {
  54. USE_TRACING("CreateMinidumpW");
  55. SMDumpOptions smdo;
  56. HANDLE hProc;
  57. BOOL fRet, f64bit;
  58. if (dwpid == 0 || wszPath == NULL)
  59. {
  60. SetLastError(ERROR_INVALID_PARAMETER);
  61. return FALSE;
  62. }
  63. hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE,
  64. dwpid);
  65. if (hProc == NULL)
  66. return FALSE;
  67. #ifdef _WIN64
  68. ULONG_PTR Wow64Info = 0;
  69. NTSTATUS Status;
  70. // Do something here to decide if this is a 32 or 64 bit app...
  71. // need to determine if we're a Wow64 process so we can build the appropriate
  72. // signatures...
  73. Status = NtQueryInformationProcess(hProc, ProcessWow64Information,
  74. &Wow64Info, sizeof(Wow64Info), NULL);
  75. if (NT_SUCCESS(Status) == FALSE) {
  76. // assume that this is 64 bit if we fail
  77. f64bit = TRUE;
  78. } else {
  79. // use the value returned from ntdll
  80. f64bit = (Wow64Info == 0);
  81. }
  82. #else
  83. f64bit=FALSE;
  84. #endif
  85. // if we want to collect a signature, by default the module needs to
  86. // be set to 'unknown'
  87. if (psmdo && (psmdo->dfOptions & dfCollectSig) != 0)
  88. StringCbCopyW(psmdo->wszMod, sizeof(psmdo->wszMod), L"unknown");
  89. fRet = InternalGenerateMinidump(hProc, dwpid, wszPath, psmdo, f64bit);
  90. CloseHandle(hProc);
  91. return fRet;
  92. }
  93. // **************************************************************************
  94. BOOL AddERExcludedApplicationW(LPCWSTR wszApplication)
  95. {
  96. USE_TRACING("AddERExcludedApplicationW");
  97. LPCWSTR pwszApp;
  98. DWORD dw, dwData;
  99. HKEY hkey = NULL;
  100. if (wszApplication == NULL)
  101. {
  102. SetLastError(ERROR_INVALID_PARAMETER);
  103. return FALSE;
  104. }
  105. // make sure the user didn't give us a full path (ie, one containing
  106. // backslashes). If he did, only use the part of the string after the
  107. // last backslash
  108. for (pwszApp = wszApplication + wcslen(wszApplication);
  109. *pwszApp != L'\\' && pwszApp > wszApplication;
  110. pwszApp--);
  111. if (*pwszApp == L'\\')
  112. pwszApp++;
  113. if (*pwszApp == L'\0')
  114. {
  115. SetLastError(ERROR_INVALID_PARAMETER);
  116. return FALSE;
  117. }
  118. // gotta open the reg key
  119. dw = RegCreateKeyExW(HKEY_LOCAL_MACHINE, c_wszRPCfgCPLExList, 0, NULL, 0,
  120. KEY_ALL_ACCESS | KEY_WOW64_64KEY, NULL, &hkey, NULL);
  121. if (dw != ERROR_SUCCESS)
  122. {
  123. SetLastError(dw);
  124. return FALSE;
  125. }
  126. // set the value
  127. dwData = 1;
  128. dw = RegSetValueExW(hkey, pwszApp, NULL, REG_DWORD, (PBYTE)&dwData,
  129. sizeof(dwData));
  130. RegCloseKey(hkey);
  131. if (dw != ERROR_SUCCESS)
  132. {
  133. SetLastError(dw);
  134. return FALSE;
  135. }
  136. return TRUE;
  137. }
  138. // **************************************************************************
  139. BOOL AddERExcludedApplicationA(LPCSTR szApplication)
  140. {
  141. USE_TRACING("AddERExcludedApplicationA");
  142. LPWSTR wszApp = NULL;
  143. DWORD cch;
  144. if (szApplication == NULL || szApplication[0] == '\0')
  145. {
  146. SetLastError(ERROR_INVALID_PARAMETER);
  147. return FALSE;
  148. }
  149. cch = MultiByteToWideChar(CP_ACP, 0, szApplication, -1, wszApp, 0);
  150. __try { wszApp = (LPWSTR)_alloca(cch * sizeof(WCHAR)); }
  151. __except(EXCEPTION_STACK_OVERFLOW == GetExceptionCode() ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
  152. {
  153. // _resetstkoflw();
  154. wszApp = NULL;
  155. }
  156. if (wszApp == NULL)
  157. {
  158. SetLastError(ERROR_OUTOFMEMORY);
  159. return FALSE;
  160. }
  161. if (MultiByteToWideChar(CP_ACP, 0, szApplication, -1, wszApp, cch) == 0)
  162. return FALSE;
  163. return AddERExcludedApplicationW(wszApp);
  164. }