| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "client/crashpad_client.h" | 15 #include "client/crashpad_client.h" |
| 16 | 16 |
| 17 #include <string.h> | 17 #include <string.h> |
| 18 #include <windows.h> | 18 #include <windows.h> |
| 19 | 19 |
| 20 #include "base/atomicops.h" | 20 #include "base/atomicops.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 25 #include "util/file/file_io.h" | 25 #include "util/file/file_io.h" |
| 26 #include "util/win/critical_section_with_debug_info.h" |
| 26 #include "util/win/registration_protocol_win.h" | 27 #include "util/win/registration_protocol_win.h" |
| 27 #include "util/win/scoped_handle.h" | 28 #include "util/win/scoped_handle.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // This handle is never closed. This is used to signal to the server that a dump | 32 // This handle is never closed. This is used to signal to the server that a dump |
| 32 // should be taken in the event of a crash. | 33 // should be taken in the event of a crash. |
| 33 HANDLE g_signal_exception = INVALID_HANDLE_VALUE; | 34 HANDLE g_signal_exception = INVALID_HANDLE_VALUE; |
| 34 | 35 |
| 35 // Where we store the exception information that the crash handler reads. | 36 // Where we store the exception information that the crash handler reads. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 Sleep(kMillisecondsUntilTerminate); | 95 Sleep(kMillisecondsUntilTerminate); |
| 95 | 96 |
| 96 LOG(ERROR) << "crash server did not respond, self-terminating"; | 97 LOG(ERROR) << "crash server did not respond, self-terminating"; |
| 97 | 98 |
| 98 const UINT kCrashExitCodeNoDump = 0xffff7001; | 99 const UINT kCrashExitCodeNoDump = 0xffff7001; |
| 99 TerminateProcess(GetCurrentProcess(), kCrashExitCodeNoDump); | 100 TerminateProcess(GetCurrentProcess(), kCrashExitCodeNoDump); |
| 100 | 101 |
| 101 return EXCEPTION_CONTINUE_SEARCH; | 102 return EXCEPTION_CONTINUE_SEARCH; |
| 102 } | 103 } |
| 103 | 104 |
| 104 BOOL CrashpadInitializeCriticalSectionEx( | |
| 105 CRITICAL_SECTION* critical_section, | |
| 106 DWORD spin_count, | |
| 107 DWORD flags) { | |
| 108 static decltype(InitializeCriticalSectionEx)* initialize_critical_section_ex = | |
| 109 reinterpret_cast<decltype(InitializeCriticalSectionEx)*>(GetProcAddress( | |
| 110 LoadLibrary(L"kernel32.dll"), "InitializeCriticalSectionEx")); | |
| 111 if (!initialize_critical_section_ex) | |
| 112 return false; | |
| 113 return initialize_critical_section_ex(critical_section, spin_count, flags); | |
| 114 } | |
| 115 | |
| 116 } // namespace | 105 } // namespace |
| 117 | 106 |
| 118 namespace crashpad { | 107 namespace crashpad { |
| 119 | 108 |
| 120 CrashpadClient::CrashpadClient() { | 109 CrashpadClient::CrashpadClient() { |
| 121 } | 110 } |
| 122 | 111 |
| 123 CrashpadClient::~CrashpadClient() { | 112 CrashpadClient::~CrashpadClient() { |
| 124 } | 113 } |
| 125 | 114 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 149 message.registration.non_crash_exception_information = | 138 message.registration.non_crash_exception_information = |
| 150 reinterpret_cast<WinVMAddress>(&g_non_crash_exception_information); | 139 reinterpret_cast<WinVMAddress>(&g_non_crash_exception_information); |
| 151 | 140 |
| 152 // We create this dummy CRITICAL_SECTION with the | 141 // We create this dummy CRITICAL_SECTION with the |
| 153 // RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO flag set to have an entry point | 142 // RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO flag set to have an entry point |
| 154 // into the doubly-linked list of RTL_CRITICAL_SECTION_DEBUG objects. This | 143 // into the doubly-linked list of RTL_CRITICAL_SECTION_DEBUG objects. This |
| 155 // allows us to walk the list at crash time to gather data for !locks. A | 144 // allows us to walk the list at crash time to gather data for !locks. A |
| 156 // debugger would instead inspect ntdll!RtlCriticalSectionList to get the head | 145 // debugger would instead inspect ntdll!RtlCriticalSectionList to get the head |
| 157 // of the list. But that is not an exported symbol, so on an arbitrary client | 146 // of the list. But that is not an exported symbol, so on an arbitrary client |
| 158 // machine, we don't have a way of getting that pointer. | 147 // machine, we don't have a way of getting that pointer. |
| 159 if (CrashpadInitializeCriticalSectionEx( | 148 if (InitializeCriticalSectionWithDebugInfoIfPossible( |
| 160 &g_critical_section_with_debug_info, | 149 &g_critical_section_with_debug_info)) { |
| 161 0, | |
| 162 RTL_CRITICAL_SECTION_FLAG_FORCE_DEBUG_INFO)) { | |
| 163 message.registration.critical_section_address = | 150 message.registration.critical_section_address = |
| 164 reinterpret_cast<WinVMAddress>(&g_critical_section_with_debug_info); | 151 reinterpret_cast<WinVMAddress>(&g_critical_section_with_debug_info); |
| 165 } else { | |
| 166 PLOG(ERROR) << "InitializeCriticalSectionEx"; | |
| 167 } | 152 } |
| 168 | 153 |
| 169 ServerToClientMessage response = {0}; | 154 ServerToClientMessage response = {0}; |
| 170 | 155 |
| 171 if (!SendToCrashHandlerServer( | 156 if (!SendToCrashHandlerServer( |
| 172 base::UTF8ToUTF16(ipc_port), message, &response)) { | 157 base::UTF8ToUTF16(ipc_port), message, &response)) { |
| 173 return false; | 158 return false; |
| 174 } | 159 } |
| 175 | 160 |
| 176 // The server returns these already duplicated to be valid in this process. | 161 // The server returns these already duplicated to be valid in this process. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 reinterpret_cast<crashpad::WinVMAddress>(&exception_pointers); | 230 reinterpret_cast<crashpad::WinVMAddress>(&exception_pointers); |
| 246 | 231 |
| 247 bool set_event_result = SetEvent(g_signal_non_crash_dump); | 232 bool set_event_result = SetEvent(g_signal_non_crash_dump); |
| 248 PLOG_IF(ERROR, !set_event_result) << "SetEvent"; | 233 PLOG_IF(ERROR, !set_event_result) << "SetEvent"; |
| 249 | 234 |
| 250 DWORD wfso_result = WaitForSingleObject(g_non_crash_dump_done, INFINITE); | 235 DWORD wfso_result = WaitForSingleObject(g_non_crash_dump_done, INFINITE); |
| 251 PLOG_IF(ERROR, wfso_result != WAIT_OBJECT_0) << "WaitForSingleObject"; | 236 PLOG_IF(ERROR, wfso_result != WAIT_OBJECT_0) << "WaitForSingleObject"; |
| 252 } | 237 } |
| 253 | 238 |
| 254 } // namespace crashpad | 239 } // namespace crashpad |
| OLD | NEW |