Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 #include "components/crash/content/app/fallback_crash_handling_win.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/base_switches.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "components/crash/content/app/crash_switches.h" | |
| 13 #include "components/crash/content/app/fallback_crash_handler_launcher_win.h" | |
| 14 #include "components/crash/content/app/fallback_crash_handler_win.h" | |
| 15 | |
| 16 namespace crash_reporter { | |
| 17 | |
| 18 namespace switches { | |
| 19 const char kFallbackCrashHandler[] = "fallback-handler"; | |
| 20 } | |
| 21 | |
| 22 const uint32_t kFallbackCrashTerminationCode = 0xFFFF8001; | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 std::unique_ptr<FallbackCrashHandlerLauncher> g_fallback_crash_handler_launcher; | |
| 27 | |
| 28 LONG WINAPI FallbackUnhandledExceptionFilter(EXCEPTION_POINTERS* exc_ptrs) { | |
| 29 if (!g_fallback_crash_handler_launcher) | |
| 30 return EXCEPTION_CONTINUE_SEARCH; | |
| 31 | |
| 32 return g_fallback_crash_handler_launcher->LaunchAndWaitForHandler(exc_ptrs); | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 bool SetupFallbackCrashHandling(const base::CommandLine& command_line) { | |
| 38 DCHECK(!g_fallback_crash_handler_launcher); | |
| 39 | |
| 40 // Run the same program. | |
| 41 base::CommandLine base_command_line(command_line.GetProgram()); | |
| 42 base_command_line.AppendSwitchASCII("type", switches::kFallbackCrashHandler); | |
| 43 | |
| 44 // This is to support testing under gtest. | |
| 45 if (command_line.HasSwitch(::switches::kTestChildProcess)) { | |
| 46 base_command_line.AppendSwitchASCII( | |
| 47 ::switches::kTestChildProcess, | |
| 48 command_line.GetSwitchValueASCII(::switches::kTestChildProcess)); | |
| 49 } | |
| 50 | |
| 51 // Get the database path. | |
| 52 base::FilePath database_path = command_line.GetSwitchValuePath("database"); | |
| 53 if (database_path.empty()) { | |
| 54 NOTREACHED(); | |
| 55 return false; | |
| 56 } | |
| 57 | |
| 58 std::unique_ptr<FallbackCrashHandlerLauncher> fallback_launcher( | |
| 59 new FallbackCrashHandlerLauncher()); | |
| 60 | |
| 61 if (!fallback_launcher->Initialize(base_command_line, database_path)) { | |
| 62 NOTREACHED(); | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 // Success, pass ownership to the global. | |
| 67 g_fallback_crash_handler_launcher = std::move(fallback_launcher); | |
| 68 | |
| 69 SetUnhandledExceptionFilter(&FallbackUnhandledExceptionFilter); | |
|
scottmg
2017/01/16 18:32:57
I have the feeling this won't do anything, due to
Sigurður Ásgeirsson
2017/01/16 18:52:44
I think you may be right - I haven't tested this i
| |
| 70 | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 int RunAsFallbackCrashHandler(const base::CommandLine& command_line, | |
| 75 std::string product_name, | |
| 76 std::string version, | |
| 77 std::string channel_name) { | |
| 78 FallbackCrashHandler fallback_handler; | |
| 79 | |
| 80 if (!fallback_handler.ParseCommandLine(command_line)) { | |
| 81 // TODO(siggi): Figure out how to UMA from this process, if need be. | |
| 82 return 1; | |
| 83 } | |
| 84 | |
| 85 if (!fallback_handler.GenerateCrashDump( | |
| 86 product_name, version, channel_name, | |
| 87 crash_reporter::switches::kCrashpadHandler)) { | |
| 88 // TODO(siggi): Figure out how to UMA from this process, if need be. | |
| 89 return 2; | |
| 90 } | |
| 91 | |
| 92 if (!fallback_handler.process().Terminate(kFallbackCrashTerminationCode, | |
| 93 false)) { | |
| 94 return 3; | |
| 95 } | |
| 96 | |
| 97 return 0; | |
| 98 } | |
| 99 | |
| 100 } // namespace crash_reporter | |
| OLD | NEW |