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/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
26 #include "util/file/file_io.h" | 26 #include "util/file/file_io.h" |
27 #include "util/win/command_line.h" | 27 #include "util/win/command_line.h" |
28 #include "util/win/critical_section_with_debug_info.h" | 28 #include "util/win/critical_section_with_debug_info.h" |
| 29 #include "util/win/handle.h" |
29 #include "util/win/registration_protocol_win.h" | 30 #include "util/win/registration_protocol_win.h" |
30 #include "util/win/scoped_handle.h" | 31 #include "util/win/scoped_handle.h" |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // This handle is never closed. This is used to signal to the server that a dump | 35 // This handle is never closed. This is used to signal to the server that a dump |
35 // should be taken in the event of a crash. | 36 // should be taken in the event of a crash. |
36 HANDLE g_signal_exception = INVALID_HANDLE_VALUE; | 37 HANDLE g_signal_exception = INVALID_HANDLE_VALUE; |
37 | 38 |
38 // Where we store the exception information that the crash handler reads. | 39 // Where we store the exception information that the crash handler reads. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 AppendCommandLineArgument(FormatArgumentString("url", | 160 AppendCommandLineArgument(FormatArgumentString("url", |
160 base::UTF8ToUTF16(url)), | 161 base::UTF8ToUTF16(url)), |
161 &command_line); | 162 &command_line); |
162 } | 163 } |
163 for (const auto& kv : annotations) { | 164 for (const auto& kv : annotations) { |
164 AppendCommandLineArgument( | 165 AppendCommandLineArgument( |
165 FormatArgumentString("annotation", | 166 FormatArgumentString("annotation", |
166 base::UTF8ToUTF16(kv.first + '=' + kv.second)), | 167 base::UTF8ToUTF16(kv.first + '=' + kv.second)), |
167 &command_line); | 168 &command_line); |
168 } | 169 } |
169 | |
170 // According to | |
171 // https://msdn.microsoft.com/en-us/library/windows/desktop/aa384203, HANDLEs | |
172 // are always 32 bits. | |
173 AppendCommandLineArgument( | 170 AppendCommandLineArgument( |
174 base::UTF8ToUTF16(base::StringPrintf("--handshake-handle=0x%x", | 171 base::UTF8ToUTF16(base::StringPrintf("--handshake-handle=0x%x", |
175 pipe_write)), | 172 HandleToInt(pipe_write))), |
176 &command_line); | 173 &command_line); |
177 | 174 |
178 STARTUPINFO startup_info = {}; | 175 STARTUPINFO startup_info = {}; |
179 startup_info.cb = sizeof(startup_info); | 176 startup_info.cb = sizeof(startup_info); |
180 startup_info.dwFlags = STARTF_USESTDHANDLES; | 177 startup_info.dwFlags = STARTF_USESTDHANDLES; |
181 startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); | 178 startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE); |
182 startup_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); | 179 startup_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); |
183 startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); | 180 startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE); |
184 PROCESS_INFORMATION process_info; | 181 PROCESS_INFORMATION process_info; |
185 rv = CreateProcess(handler.value().c_str(), | 182 rv = CreateProcess(handler.value().c_str(), |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 reinterpret_cast<WinVMAddress>(&g_critical_section_with_debug_info); | 261 reinterpret_cast<WinVMAddress>(&g_critical_section_with_debug_info); |
265 } | 262 } |
266 | 263 |
267 ServerToClientMessage response = {0}; | 264 ServerToClientMessage response = {0}; |
268 | 265 |
269 if (!SendToCrashHandlerServer(ipc_pipe_, message, &response)) { | 266 if (!SendToCrashHandlerServer(ipc_pipe_, message, &response)) { |
270 return false; | 267 return false; |
271 } | 268 } |
272 | 269 |
273 // The server returns these already duplicated to be valid in this process. | 270 // The server returns these already duplicated to be valid in this process. |
274 g_signal_exception = reinterpret_cast<HANDLE>( | 271 g_signal_exception = |
275 static_cast<uintptr_t>(response.registration.request_crash_dump_event)); | 272 IntToHandle(response.registration.request_crash_dump_event); |
276 g_signal_non_crash_dump = reinterpret_cast<HANDLE>(static_cast<uintptr_t>( | 273 g_signal_non_crash_dump = |
277 response.registration.request_non_crash_dump_event)); | 274 IntToHandle(response.registration.request_non_crash_dump_event); |
278 g_non_crash_dump_done = reinterpret_cast<HANDLE>(static_cast<uintptr_t>( | 275 g_non_crash_dump_done = |
279 response.registration.non_crash_dump_completed_event)); | 276 IntToHandle(response.registration.non_crash_dump_completed_event); |
280 | 277 |
281 g_non_crash_dump_lock = new base::Lock(); | 278 g_non_crash_dump_lock = new base::Lock(); |
282 | 279 |
283 // In theory we could store the previous handler but it is not clear what | 280 // In theory we could store the previous handler but it is not clear what |
284 // use we have for it. | 281 // use we have for it. |
285 SetUnhandledExceptionFilter(&UnhandledExceptionHandler); | 282 SetUnhandledExceptionFilter(&UnhandledExceptionHandler); |
286 return true; | 283 return true; |
287 } | 284 } |
288 | 285 |
289 // static | 286 // static |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 reinterpret_cast<crashpad::WinVMAddress>(&exception_pointers); | 329 reinterpret_cast<crashpad::WinVMAddress>(&exception_pointers); |
333 | 330 |
334 bool set_event_result = !!SetEvent(g_signal_non_crash_dump); | 331 bool set_event_result = !!SetEvent(g_signal_non_crash_dump); |
335 PLOG_IF(ERROR, !set_event_result) << "SetEvent"; | 332 PLOG_IF(ERROR, !set_event_result) << "SetEvent"; |
336 | 333 |
337 DWORD wfso_result = WaitForSingleObject(g_non_crash_dump_done, INFINITE); | 334 DWORD wfso_result = WaitForSingleObject(g_non_crash_dump_done, INFINITE); |
338 PLOG_IF(ERROR, wfso_result != WAIT_OBJECT_0) << "WaitForSingleObject"; | 335 PLOG_IF(ERROR, wfso_result != WAIT_OBJECT_0) << "WaitForSingleObject"; |
339 } | 336 } |
340 | 337 |
341 } // namespace crashpad | 338 } // namespace crashpad |
OLD | NEW |