| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "components/crash/content/app/crashpad.h" | 5 #include "components/crash/content/app/crashpad.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/debug/crash_logging.h" | 9 #include "base/debug/crash_logging.h" |
| 10 #include "base/environment.h" | 10 #include "base/environment.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/lazy_instance.h" | |
| 13 #include "base/numerics/safe_conversions.h" | 12 #include "base/numerics/safe_conversions.h" |
| 14 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 15 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 20 #include "components/crash/content/app/crash_reporter_client.h" | 19 #include "components/crash/content/app/crash_reporter_client.h" |
| 21 #include "components/crash/content/app/crash_switches.h" | 20 #include "components/crash/content/app/crash_switches.h" |
| 22 #include "third_party/crashpad/crashpad/client/crashpad_client.h" | 21 #include "third_party/crashpad/crashpad/client/crashpad_client.h" |
| 23 #include "third_party/crashpad/crashpad/client/crashpad_info.h" | 22 #include "third_party/crashpad/crashpad/client/crashpad_info.h" |
| 24 #include "third_party/crashpad/crashpad/client/simulate_crash_win.h" | 23 #include "third_party/crashpad/crashpad/client/simulate_crash_win.h" |
| 25 | 24 |
| 26 namespace crash_reporter { | 25 namespace crash_reporter { |
| 27 namespace internal { | 26 namespace internal { |
| 28 | 27 |
| 29 namespace { | |
| 30 | |
| 31 base::LazyInstance<crashpad::CrashpadClient>::Leaky g_crashpad_client = | |
| 32 LAZY_INSTANCE_INITIALIZER; | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 void GetPlatformCrashpadAnnotations( | 28 void GetPlatformCrashpadAnnotations( |
| 37 std::map<std::string, std::string>* annotations) { | 29 std::map<std::string, std::string>* annotations) { |
| 38 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); | 30 CrashReporterClient* crash_reporter_client = GetCrashReporterClient(); |
| 39 wchar_t exe_file[MAX_PATH] = {}; | 31 wchar_t exe_file[MAX_PATH] = {}; |
| 40 CHECK(::GetModuleFileName(nullptr, exe_file, arraysize(exe_file))); | 32 CHECK(::GetModuleFileName(nullptr, exe_file, arraysize(exe_file))); |
| 41 base::string16 product_name, version, special_build, channel_name; | 33 base::string16 product_name, version, special_build, channel_name; |
| 42 crash_reporter_client->GetProductNameAndVersion( | 34 crash_reporter_client->GetProductNameAndVersion( |
| 43 exe_file, &product_name, &version, &special_build, &channel_name); | 35 exe_file, &product_name, &version, &special_build, &channel_name); |
| 44 (*annotations)["prod"] = base::UTF16ToUTF8(product_name); | 36 (*annotations)["prod"] = base::UTF16ToUTF8(product_name); |
| 45 (*annotations)["ver"] = base::UTF16ToUTF8(version); | 37 (*annotations)["ver"] = base::UTF16ToUTF8(version); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 arguments.push_back(std::string("--type=") + switches::kCrashpadHandler); | 101 arguments.push_back(std::string("--type=") + switches::kCrashpadHandler); |
| 110 // The prefetch argument added here has to be documented in | 102 // The prefetch argument added here has to be documented in |
| 111 // chrome_switches.cc, below the kPrefetchArgument* constants. A constant | 103 // chrome_switches.cc, below the kPrefetchArgument* constants. A constant |
| 112 // can't be used here because crashpad can't depend on Chrome. | 104 // can't be used here because crashpad can't depend on Chrome. |
| 113 arguments.push_back("/prefetch:7"); | 105 arguments.push_back("/prefetch:7"); |
| 114 } else { | 106 } else { |
| 115 base::FilePath exe_dir = exe_file.DirName(); | 107 base::FilePath exe_dir = exe_file.DirName(); |
| 116 exe_file = exe_dir.Append(FILE_PATH_LITERAL("crashpad_handler.exe")); | 108 exe_file = exe_dir.Append(FILE_PATH_LITERAL("crashpad_handler.exe")); |
| 117 } | 109 } |
| 118 | 110 |
| 119 g_crashpad_client.Get().StartHandler(exe_file, database_path, metrics_path, | 111 GetCrashpadClient().StartHandler(exe_file, database_path, metrics_path, url, |
| 120 url, process_annotations, arguments, | 112 process_annotations, arguments, false, |
| 121 false, false); | 113 false); |
| 122 | 114 |
| 123 // If we're the browser, push the pipe name into the environment so child | 115 // If we're the browser, push the pipe name into the environment so child |
| 124 // processes can connect to it. If we inherited another crashpad_handler's | 116 // processes can connect to it. If we inherited another crashpad_handler's |
| 125 // pipe name, we'll overwrite it here. | 117 // pipe name, we'll overwrite it here. |
| 126 env->SetVar(kPipeNameVar, | 118 env->SetVar(kPipeNameVar, |
| 127 base::UTF16ToUTF8(g_crashpad_client.Get().GetHandlerIPCPipe())); | 119 base::UTF16ToUTF8(GetCrashpadClient().GetHandlerIPCPipe())); |
| 128 } else { | 120 } else { |
| 129 std::string pipe_name_utf8; | 121 std::string pipe_name_utf8; |
| 130 if (env->GetVar(kPipeNameVar, &pipe_name_utf8)) { | 122 if (env->GetVar(kPipeNameVar, &pipe_name_utf8)) { |
| 131 g_crashpad_client.Get().SetHandlerIPCPipe( | 123 GetCrashpadClient().SetHandlerIPCPipe(base::UTF8ToUTF16(pipe_name_utf8)); |
| 132 base::UTF8ToUTF16(pipe_name_utf8)); | |
| 133 } | 124 } |
| 134 } | 125 } |
| 135 | 126 |
| 136 return database_path; | 127 return database_path; |
| 137 } | 128 } |
| 138 | 129 |
| 139 // TODO(scottmg): http://crbug.com/546288 These exported functions are for | 130 // TODO(scottmg): http://crbug.com/546288 These exported functions are for |
| 140 // compatibility with how Breakpad worked, but it seems like there's no need to | 131 // compatibility with how Breakpad worked, but it seems like there's no need to |
| 141 // do the CreateRemoteThread() dance with a minor extension of the Crashpad API | 132 // do the CreateRemoteThread() dance with a minor extension of the Crashpad API |
| 142 // (to just pass the pid we want a dump for). We should add that and then modify | 133 // (to just pass the pid we want a dump for). We should add that and then modify |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 extern "C" { | 202 extern "C" { |
| 212 | 203 |
| 213 // Crashes the process after generating a dump for the provided exception. Note | 204 // Crashes the process after generating a dump for the provided exception. Note |
| 214 // that the crash reporter should be initialized before calling this function | 205 // that the crash reporter should be initialized before calling this function |
| 215 // for it to do anything. | 206 // for it to do anything. |
| 216 // NOTE: This function is used by SyzyASAN to invoke a crash. If you change the | 207 // NOTE: This function is used by SyzyASAN to invoke a crash. If you change the |
| 217 // the name or signature of this function you will break SyzyASAN instrumented | 208 // the name or signature of this function you will break SyzyASAN instrumented |
| 218 // releases of Chrome. Please contact syzygy-team@chromium.org before doing so! | 209 // releases of Chrome. Please contact syzygy-team@chromium.org before doing so! |
| 219 int __declspec(dllexport) CrashForException( | 210 int __declspec(dllexport) CrashForException( |
| 220 EXCEPTION_POINTERS* info) { | 211 EXCEPTION_POINTERS* info) { |
| 221 crash_reporter::internal::g_crashpad_client.Get().DumpAndCrash(info); | 212 crash_reporter::GetCrashpadClient().DumpAndCrash(info); |
| 222 return EXCEPTION_CONTINUE_SEARCH; | 213 return EXCEPTION_CONTINUE_SEARCH; |
| 223 } | 214 } |
| 224 | 215 |
| 225 // Injects a thread into a remote process to dump state when there is no crash. | 216 // Injects a thread into a remote process to dump state when there is no crash. |
| 226 HANDLE __declspec(dllexport) __cdecl InjectDumpProcessWithoutCrash( | 217 HANDLE __declspec(dllexport) __cdecl InjectDumpProcessWithoutCrash( |
| 227 HANDLE process) { | 218 HANDLE process) { |
| 228 return CreateRemoteThread( | 219 return CreateRemoteThread( |
| 229 process, nullptr, 0, | 220 process, nullptr, 0, |
| 230 crash_reporter::internal::DumpProcessWithoutCrashThread, nullptr, 0, | 221 crash_reporter::internal::DumpProcessWithoutCrashThread, nullptr, 0, |
| 231 nullptr); | 222 nullptr); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 void __declspec(dllexport) __cdecl UnregisterNonABICompliantCodeRange( | 332 void __declspec(dllexport) __cdecl UnregisterNonABICompliantCodeRange( |
| 342 void* start) { | 333 void* start) { |
| 343 ExceptionHandlerRecord* record = | 334 ExceptionHandlerRecord* record = |
| 344 reinterpret_cast<ExceptionHandlerRecord*>(start); | 335 reinterpret_cast<ExceptionHandlerRecord*>(start); |
| 345 | 336 |
| 346 CHECK(RtlDeleteFunctionTable(&record->runtime_function)); | 337 CHECK(RtlDeleteFunctionTable(&record->runtime_function)); |
| 347 } | 338 } |
| 348 #endif // ARCH_CPU_X86_64 | 339 #endif // ARCH_CPU_X86_64 |
| 349 | 340 |
| 350 } // extern "C" | 341 } // extern "C" |
| OLD | NEW |