OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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(WARNING) << "SignalObjectAndWait timed out"; |
| 45 } else { |
| 46 PLOG(WARNING) << "SignalObjectAndWait error"; |
| 47 } |
| 48 } |
| 49 // We don't want to generate more exceptions, so we take the fast route. |
| 50 TerminateProcess(GetCurrentProcess(), kCrashExitCode); |
| 51 return 0L; |
| 52 } |
| 53 |
| 54 } // namespace |
| 55 |
| 56 namespace crashpad { |
| 57 |
| 58 CrashpadClient::CrashpadClient() { |
| 59 } |
| 60 |
| 61 CrashpadClient::~CrashpadClient() { |
| 62 } |
| 63 |
| 64 bool CrashpadClient::StartHandler( |
| 65 const base::FilePath& handler, |
| 66 const base::FilePath& database, |
| 67 const std::string& url, |
| 68 const std::map<std::string, std::string>& annotations, |
| 69 const std::vector<std::string>& arguments) { |
| 70 // TODO(cpu): Provide a reference implementation. |
| 71 return false; |
| 72 } |
| 73 |
| 74 bool SetHandler(const std::string& ipc_port) { |
| 75 // TODO (cpu): Contact the handler and obtain g_signal_exception and |
| 76 // g_wait_termination. |
| 77 return false; |
| 78 } |
| 79 |
| 80 bool CrashpadClient::UseHandler() { |
| 81 if (!g_signal_exception) |
| 82 return false; |
| 83 if (!g_wait_termination) |
| 84 return false; |
| 85 // In theory we could store the previous handler but it is not clear what |
| 86 // use we have for it. |
| 87 SetUnhandledExceptionFilter(&UnhandledExceptionHandler); |
| 88 return true; |
| 89 } |
| 90 |
| 91 } // namespace crashpad |
OLD | NEW |