| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // crash_report.cc : Implementation crash reporting. | 5 // crash_report.cc : Implementation crash reporting. |
| 6 #include "chrome_frame/crash_report.h" | 6 #include "chrome_frame/crash_reporting/crash_report.h" |
| 7 | 7 |
| 8 #include "base/file_util.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/win_util.h" | |
| 11 #include "breakpad/src/client/windows/handler/exception_handler.h" | 10 #include "breakpad/src/client/windows/handler/exception_handler.h" |
| 12 #include "chrome/installer/util/google_update_settings.h" | 11 #include "chrome_frame/crash_reporting/vectored_handler.h" |
| 13 #include "chrome/installer/util/install_util.h" | 12 #include "chrome_frame/crash_reporting/vectored_handler-impl.h" |
| 14 #include "chrome_frame/vectored_handler.h" | |
| 15 #include "chrome_frame/vectored_handler-impl.h" | |
| 16 | 13 |
| 17 namespace { | 14 namespace { |
| 18 // TODO(joshia): factor out common code with chrome used for crash reporting | 15 // TODO(joshia): factor out common code with chrome used for crash reporting |
| 19 const wchar_t kGoogleUpdatePipeName[] = L"\\\\.\\pipe\\GoogleCrashServices\\"; | 16 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; | 17 google_breakpad::ExceptionHandler* g_breakpad = NULL; |
| 24 | 18 |
| 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) | 19 __declspec(naked) |
| 41 static EXCEPTION_REGISTRATION_RECORD* InternalRtlpGetExceptionList() { | 20 static EXCEPTION_REGISTRATION_RECORD* InternalRtlpGetExceptionList() { |
| 42 __asm { | 21 __asm { |
| 43 mov eax, fs:0 | 22 mov eax, fs:0 |
| 44 ret | 23 ret |
| 45 } | 24 } |
| 46 } | 25 } |
| 47 } // end of namespace | 26 } // end of namespace |
| 48 | 27 |
| 49 // Class which methods simply forwards to Win32 API and uses breakpad to write | 28 // Class which methods simply forwards to Win32 API and uses breakpad to write |
| (...skipping 19 matching lines...) Expand all Loading... |
| 69 } | 48 } |
| 70 | 49 |
| 71 static inline WORD RtlCaptureStackBackTrace(DWORD FramesToSkip, | 50 static inline WORD RtlCaptureStackBackTrace(DWORD FramesToSkip, |
| 72 DWORD FramesToCapture, void** BackTrace, DWORD* BackTraceHash) { | 51 DWORD FramesToCapture, void** BackTrace, DWORD* BackTraceHash) { |
| 73 return ::RtlCaptureStackBackTrace(FramesToSkip, FramesToCapture, | 52 return ::RtlCaptureStackBackTrace(FramesToSkip, FramesToCapture, |
| 74 BackTrace, BackTraceHash); | 53 BackTrace, BackTraceHash); |
| 75 } | 54 } |
| 76 }; | 55 }; |
| 77 | 56 |
| 78 extern "C" IMAGE_DOS_HEADER __ImageBase; | 57 extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 79 bool InitializeCrashReporting(bool use_crash_service, bool full_dump) { | 58 |
| 59 bool InitializeVectoredCrashReporting( |
| 60 bool full_dump, |
| 61 const wchar_t* user_sid, |
| 62 const std::wstring& dump_path, |
| 63 google_breakpad::CustomClientInfo* client_info) { |
| 64 DCHECK(user_sid); |
| 65 DCHECK(client_info); |
| 80 if (g_breakpad) | 66 if (g_breakpad) |
| 81 return true; | 67 return true; |
| 82 | 68 |
| 83 std::wstring pipe_name; | 69 std::wstring pipe_name(kGoogleUpdatePipeName); |
| 84 if (use_crash_service) { | 70 pipe_name += user_sid; |
| 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 | 71 |
| 93 // Build the pipe name. It can be either: | 72 if (dump_path.empty()) { |
| 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; | 73 return false; |
| 117 } | 74 } |
| 118 | 75 |
| 119 MINIDUMP_TYPE dump_type = full_dump ? MiniDumpWithFullMemory : MiniDumpNormal; | 76 MINIDUMP_TYPE dump_type = full_dump ? MiniDumpWithFullMemory : MiniDumpNormal; |
| 120 g_breakpad = new google_breakpad::ExceptionHandler( | 77 g_breakpad = new google_breakpad::ExceptionHandler( |
| 121 temp_directory.value(), NULL, NULL, NULL, | 78 dump_path, NULL, NULL, NULL, |
| 122 google_breakpad::ExceptionHandler::HANDLER_INVALID_PARAMETER | | 79 google_breakpad::ExceptionHandler::HANDLER_INVALID_PARAMETER | |
| 123 google_breakpad::ExceptionHandler::HANDLER_PURECALL, dump_type, | 80 google_breakpad::ExceptionHandler::HANDLER_PURECALL, dump_type, |
| 124 pipe_name.c_str(), GetCustomInfo()); | 81 pipe_name.c_str(), client_info); |
| 125 | 82 |
| 126 if (g_breakpad) { | 83 if (g_breakpad) { |
| 127 // Find current module boundaries. | 84 // Find current module boundaries. |
| 128 const void* start = &__ImageBase; | 85 const void* start = &__ImageBase; |
| 129 const char* s = reinterpret_cast<const char*>(start); | 86 const char* s = reinterpret_cast<const char*>(start); |
| 130 const IMAGE_NT_HEADERS32* nt = reinterpret_cast<const IMAGE_NT_HEADERS32*> | 87 const IMAGE_NT_HEADERS32* nt = reinterpret_cast<const IMAGE_NT_HEADERS32*> |
| 131 (s + __ImageBase.e_lfanew); | 88 (s + __ImageBase.e_lfanew); |
| 132 const void* end = s + nt->OptionalHeader.SizeOfImage; | 89 const void* end = s + nt->OptionalHeader.SizeOfImage; |
| 133 VectoredHandler::Register(start, end); | 90 VectoredHandler::Register(start, end); |
| 134 } | 91 } |
| 135 | 92 |
| 136 return g_breakpad != NULL; | 93 return g_breakpad != NULL; |
| 137 } | 94 } |
| 138 | 95 |
| 139 bool ShutdownCrashReporting() { | 96 bool ShutdownVectoredCrashReporting() { |
| 140 VectoredHandler::Unregister(); | 97 VectoredHandler::Unregister(); |
| 141 delete g_breakpad; | 98 delete g_breakpad; |
| 142 g_breakpad = NULL; | 99 g_breakpad = NULL; |
| 143 return true; | 100 return true; |
| 144 } | 101 } |
| OLD | NEW |