Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "client/crashpad_client.h" | |
| 16 | |
| 17 #include <windows.h> | |
| 18 | |
| 19 #include "base/logging.h" | |
| 20 | |
| 21 namespace { | |
| 22 // Time to wait for the handler to create a dump. This is tricky to figure out. | |
| 23 const DWORD kMillisecondsUntilTerminate = 5000; | |
| 24 | |
| 25 // This is the exit code that the process will return to the system once the | |
| 26 // crash has been handled by Crashpad. We don't want to clash with the | |
| 27 // application-defined exit codes but we don't know them so we use one that is | |
| 28 // unlikely to be used. | |
| 29 const UINT kCrashExitCode = 0xffff7001; | |
| 30 | |
| 31 // These two handles to events are leaked. | |
| 32 HANDLE g_signal_exception = nullptr; | |
| 33 HANDLE g_wait_termination = nullptr; | |
| 34 | |
| 35 LONG WINAPI UnhandledExceptionHandler(EXCEPTION_POINTERS* exception_pointers) { | |
| 36 // TODO (cpu): Here write |exception_pointers| to g_crashpad_info. | |
| 37 DWORD rv = SignalObjectAndWait(g_signal_exception, | |
| 38 g_wait_termination, | |
| 39 kMillisecondsUntilTerminate, | |
| 40 FALSE); | |
| 41 if (rv != WAIT_OBJECT_0) { | |
| 42 // Something went wrong. It is likely that a dump has not been created. | |
| 43 if (rv == WAIT_TIMEOUT) { | |
| 44 LOG(INFO) << "SignalObjectAndWait timed out"; | |
|
Mark Mentovai
2015/04/29 20:17:25
These two should probably be more severe than INFO
| |
| 45 } else { | |
| 46 LOG(INFO) << "SignalObjectAndWait returned " << rv | |
|
Mark Mentovai
2015/04/29 20:17:25
You can use PLOG which will stream and explain Get
| |
| 47 << " with GLE = " << GetLastError(); | |
| 48 } | |
| 49 } | |
| 50 // We don't want to generate more exceptions, so we take the fast route. | |
| 51 TerminateProcess(GetCurrentProcess(), kCrashExitCode); | |
| 52 return 0L; | |
| 53 } | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 namespace crashpad { | |
| 58 | |
| 59 CrashpadClient::CrashpadClient() { | |
| 60 } | |
| 61 | |
| 62 CrashpadClient::~CrashpadClient() { | |
| 63 } | |
| 64 | |
| 65 bool CrashpadClient::StartHandler( | |
| 66 const base::FilePath& handler, | |
| 67 const base::FilePath& database, | |
| 68 const std::string& url, | |
| 69 const std::map<std::string, std::string>& annotations, | |
| 70 const std::vector<std::string>& arguments) { | |
| 71 // TODO(cpu): Provide a reference implementation. | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 bool SetHandler(const std::string& ipc_port) { | |
| 76 // TODO (cpu): Contact the handler and obtain g_signal_exception and | |
| 77 // g_wait_termination. | |
| 78 return false; | |
| 79 } | |
| 80 | |
| 81 bool CrashpadClient::UseHandler() { | |
| 82 if (!g_signal_exception) | |
| 83 return false; | |
| 84 if (!g_wait_termination) | |
| 85 return false; | |
| 86 // In theory we could store the previous handler but it is not clear what | |
| 87 // use we have for it. | |
| 88 SetUnhandledExceptionFilter(&UnhandledExceptionHandler); | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 } // namespace crashpad | |
| OLD | NEW |