| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // crash_report.cc : Implementation crash reporting. | |
| 6 #include "chrome_frame/crash_report.h" | |
| 7 | |
| 8 #include "base/file_util.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/win_util.h" | |
| 11 #include "breakpad/src/client/windows/handler/exception_handler.h" | |
| 12 #include "chrome/installer/util/google_update_settings.h" | |
| 13 #include "chrome/installer/util/install_util.h" | |
| 14 #include "chrome_frame/vectored_handler.h" | |
| 15 #include "chrome_frame/vectored_handler-impl.h" | |
| 16 | |
| 17 namespace { | |
| 18 // TODO(joshia): factor out common code with chrome used for crash reporting | |
| 19 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\"; | |
| 20 const wchar_t kChromePipeName[] = L"\\\\.\\pipe\\ChromeCrashServices"; | |
| 21 // Well known SID for the system principal. | |
| 22 const wchar_t kSystemPrincipalSid[] = L"S-1-5-18"; | |
| 23 google_breakpad::ExceptionHandler* g_breakpad = NULL; | |
| 24 | |
| 25 // Returns the custom info structure based on the dll in parameter and the | |
| 26 // process type. | |
| 27 google_breakpad::CustomClientInfo* GetCustomInfo() { | |
| 28 // TODO(joshia): Grab these based on build. | |
| 29 static google_breakpad::CustomInfoEntry ver_entry(L"ver", L"0.1.0.0"); | |
| 30 static google_breakpad::CustomInfoEntry prod_entry(L"prod", L"ChromeFrame"); | |
| 31 static google_breakpad::CustomInfoEntry plat_entry(L"plat", L"Win32"); | |
| 32 static google_breakpad::CustomInfoEntry type_entry(L"ptype", L"chrome_frame"); | |
| 33 static google_breakpad::CustomInfoEntry entries[] = { | |
| 34 ver_entry, prod_entry, plat_entry, type_entry }; | |
| 35 static google_breakpad::CustomClientInfo custom_info = { | |
| 36 entries, arraysize(entries) }; | |
| 37 return &custom_info; | |
| 38 } | |
| 39 | |
| 40 __declspec(naked) | |
| 41 static EXCEPTION_REGISTRATION_RECORD* InternalRtlpGetExceptionList() { | |
| 42 __asm { | |
| 43 mov eax, fs:0 | |
| 44 ret | |
| 45 } | |
| 46 } | |
| 47 } // end of namespace | |
| 48 | |
| 49 // Class which methods simply forwards to Win32 API and uses breakpad to write | |
| 50 // a minidump. Used as template (external interface) of VectoredHandlerT<E>. | |
| 51 class Win32VEHTraits : public VEHTraitsBase { | |
| 52 public: | |
| 53 static inline void* Register(PVECTORED_EXCEPTION_HANDLER func, | |
| 54 const void* module_start, const void* module_end) { | |
| 55 VEHTraitsBase::SetModule(module_start, module_end); | |
| 56 return ::AddVectoredExceptionHandler(1, func); | |
| 57 } | |
| 58 | |
| 59 static inline ULONG Unregister(void* handle) { | |
| 60 return ::RemoveVectoredExceptionHandler(handle); | |
| 61 } | |
| 62 | |
| 63 static inline bool WriteDump(EXCEPTION_POINTERS* p) { | |
| 64 return g_breakpad->WriteMinidumpForException(p); | |
| 65 } | |
| 66 | |
| 67 static inline EXCEPTION_REGISTRATION_RECORD* RtlpGetExceptionList() { | |
| 68 return InternalRtlpGetExceptionList(); | |
| 69 } | |
| 70 | |
| 71 static inline WORD RtlCaptureStackBackTrace(DWORD FramesToSkip, | |
| 72 DWORD FramesToCapture, void** BackTrace, DWORD* BackTraceHash) { | |
| 73 return ::RtlCaptureStackBackTrace(FramesToSkip, FramesToCapture, | |
| 74 BackTrace, BackTraceHash); | |
| 75 } | |
| 76 }; | |
| 77 | |
| 78 extern "C" IMAGE_DOS_HEADER __ImageBase; | |
| 79 bool InitializeCrashReporting(bool use_crash_service, bool full_dump) { | |
| 80 if (g_breakpad) | |
| 81 return true; | |
| 82 | |
| 83 std::wstring pipe_name; | |
| 84 if (use_crash_service) { | |
| 85 // Crash reporting is done by crash_service.exe. | |
| 86 pipe_name = kChromePipeName; | |
| 87 } else { | |
| 88 // We want to use the Google Update crash reporting. We need to check if the | |
| 89 // user allows it first. | |
| 90 if (!GoogleUpdateSettings::GetCollectStatsConsent()) | |
| 91 return true; | |
| 92 | |
| 93 // Build the pipe name. It can be either: | |
| 94 // System-wide install: "NamedPipe\GoogleCrashServices\S-1-5-18" | |
| 95 // Per-user install: "NamedPipe\GoogleCrashServices\<user SID>" | |
| 96 wchar_t dll_path[MAX_PATH * 2] = {0}; | |
| 97 GetModuleFileName(reinterpret_cast<HMODULE>(&__ImageBase), dll_path, | |
| 98 arraysize(dll_path)); | |
| 99 | |
| 100 std::wstring user_sid; | |
| 101 if (InstallUtil::IsPerUserInstall(dll_path)) { | |
| 102 if (!win_util::GetUserSidString(&user_sid)) { | |
| 103 return false; | |
| 104 } | |
| 105 } else { | |
| 106 user_sid = kSystemPrincipalSid; | |
| 107 } | |
| 108 | |
| 109 pipe_name = kGoogleUpdatePipeName; | |
| 110 pipe_name += user_sid; | |
| 111 } | |
| 112 | |
| 113 // Get the alternate dump directory. We use the temp path. | |
| 114 FilePath temp_directory; | |
| 115 if (!file_util::GetTempDir(&temp_directory) || temp_directory.empty()) { | |
| 116 return false; | |
| 117 } | |
| 118 | |
| 119 MINIDUMP_TYPE dump_type = full_dump ? MiniDumpWithFullMemory : MiniDumpNormal; | |
| 120 g_breakpad = new google_breakpad::ExceptionHandler( | |
| 121 temp_directory.value(), NULL, NULL, NULL, | |
| 122 google_breakpad::ExceptionHandler::HANDLER_INVALID_PARAMETER | | |
| 123 google_breakpad::ExceptionHandler::HANDLER_PURECALL, dump_type, | |
| 124 pipe_name.c_str(), GetCustomInfo()); | |
| 125 | |
| 126 if (g_breakpad) { | |
| 127 // Find current module boundaries. | |
| 128 const void* start = &__ImageBase; | |
| 129 const char* s = reinterpret_cast<const char*>(start); | |
| 130 const IMAGE_NT_HEADERS32* nt = reinterpret_cast<const IMAGE_NT_HEADERS32*> | |
| 131 (s + __ImageBase.e_lfanew); | |
| 132 const void* end = s + nt->OptionalHeader.SizeOfImage; | |
| 133 VectoredHandler::Register(start, end); | |
| 134 } | |
| 135 | |
| 136 return g_breakpad != NULL; | |
| 137 } | |
| 138 | |
| 139 bool ShutdownCrashReporting() { | |
| 140 VectoredHandler::Unregister(); | |
| 141 delete g_breakpad; | |
| 142 g_breakpad = NULL; | |
| 143 return true; | |
| 144 } | |
| OLD | NEW |