OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 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 <errno.h> | 17 #include <errno.h> |
18 #include <mach/mach.h> | 18 #include <mach/mach.h> |
19 #include <pthread.h> | 19 #include <pthread.h> |
20 #include <sys/wait.h> | 20 #include <sys/wait.h> |
21 #include <unistd.h> | 21 #include <unistd.h> |
22 | 22 |
| 23 #include <utility> |
| 24 |
23 #include "base/logging.h" | 25 #include "base/logging.h" |
24 #include "base/mac/mach_logging.h" | 26 #include "base/mac/mach_logging.h" |
25 #include "base/posix/eintr_wrapper.h" | 27 #include "base/posix/eintr_wrapper.h" |
26 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
27 #include "util/mac/mac_util.h" | 29 #include "util/mac/mac_util.h" |
28 #include "util/mach/child_port_handshake.h" | 30 #include "util/mach/child_port_handshake.h" |
29 #include "util/mach/exception_ports.h" | 31 #include "util/mach/exception_ports.h" |
30 #include "util/mach/mach_extensions.h" | 32 #include "util/mach/mach_extensions.h" |
31 #include "util/mach/mach_message.h" | 33 #include "util/mach/mach_message.h" |
32 #include "util/mach/notify_server.h" | 34 #include "util/mach/notify_server.h" |
33 #include "util/misc/clock.h" | 35 #include "util/misc/clock.h" |
34 #include "util/misc/implicit_cast.h" | 36 #include "util/misc/implicit_cast.h" |
35 #include "util/stdlib/move.h" | |
36 #include "util/posix/close_multiple.h" | 37 #include "util/posix/close_multiple.h" |
37 | 38 |
38 namespace crashpad { | 39 namespace crashpad { |
39 | 40 |
40 namespace { | 41 namespace { |
41 | 42 |
42 std::string FormatArgumentString(const std::string& name, | 43 std::string FormatArgumentString(const std::string& name, |
43 const std::string& value) { | 44 const std::string& value) { |
44 return base::StringPrintf("--%s=%s", name.c_str(), value.c_str()); | 45 return base::StringPrintf("--%s=%s", name.c_str(), value.c_str()); |
45 } | 46 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // without the ability to restart. | 153 // without the ability to restart. |
153 handler_restarter.reset(); | 154 handler_restarter.reset(); |
154 } | 155 } |
155 } | 156 } |
156 | 157 |
157 if (!CommonStart(handler, | 158 if (!CommonStart(handler, |
158 database, | 159 database, |
159 url, | 160 url, |
160 annotations, | 161 annotations, |
161 arguments, | 162 arguments, |
162 crashpad::move(receive_right), | 163 std::move(receive_right), |
163 handler_restarter.get(), | 164 handler_restarter.get(), |
164 false)) { | 165 false)) { |
165 return base::mac::ScopedMachSendRight(); | 166 return base::mac::ScopedMachSendRight(); |
166 } | 167 } |
167 | 168 |
168 if (handler_restarter && | 169 if (handler_restarter && |
169 handler_restarter->StartRestartThread( | 170 handler_restarter->StartRestartThread( |
170 handler, database, url, annotations, arguments)) { | 171 handler, database, url, annotations, arguments)) { |
171 // The thread owns the object now. | 172 // The thread owns the object now. |
172 ignore_result(handler_restarter.release()); | 173 ignore_result(handler_restarter.release()); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 HandlerStarter::InitialStart(handler, | 533 HandlerStarter::InitialStart(handler, |
533 database, | 534 database, |
534 url, | 535 url, |
535 annotations, | 536 annotations, |
536 arguments, | 537 arguments, |
537 restartable && MacOSXMinorVersion() >= 10)); | 538 restartable && MacOSXMinorVersion() >= 10)); |
538 if (!exception_port.is_valid()) { | 539 if (!exception_port.is_valid()) { |
539 return false; | 540 return false; |
540 } | 541 } |
541 | 542 |
542 SetHandlerMachPort(crashpad::move(exception_port)); | 543 SetHandlerMachPort(std::move(exception_port)); |
543 return true; | 544 return true; |
544 } | 545 } |
545 | 546 |
546 bool CrashpadClient::SetHandlerMachService(const std::string& service_name) { | 547 bool CrashpadClient::SetHandlerMachService(const std::string& service_name) { |
547 base::mac::ScopedMachSendRight exception_port(BootstrapLookUp(service_name)); | 548 base::mac::ScopedMachSendRight exception_port(BootstrapLookUp(service_name)); |
548 if (!exception_port.is_valid()) { | 549 if (!exception_port.is_valid()) { |
549 return false; | 550 return false; |
550 } | 551 } |
551 | 552 |
552 SetHandlerMachPort(crashpad::move(exception_port)); | 553 SetHandlerMachPort(std::move(exception_port)); |
553 return true; | 554 return true; |
554 } | 555 } |
555 | 556 |
556 void CrashpadClient::SetHandlerMachPort( | 557 void CrashpadClient::SetHandlerMachPort( |
557 base::mac::ScopedMachSendRight exception_port) { | 558 base::mac::ScopedMachSendRight exception_port) { |
558 DCHECK(exception_port.is_valid()); | 559 DCHECK(exception_port.is_valid()); |
559 exception_port_ = crashpad::move(exception_port); | 560 exception_port_ = std::move(exception_port); |
560 } | 561 } |
561 | 562 |
562 bool CrashpadClient::UseHandler() { | 563 bool CrashpadClient::UseHandler() { |
563 DCHECK(exception_port_.is_valid()); | 564 DCHECK(exception_port_.is_valid()); |
564 | 565 |
565 return SetCrashExceptionPorts(exception_port_.get()); | 566 return SetCrashExceptionPorts(exception_port_.get()); |
566 } | 567 } |
567 | 568 |
568 // static | 569 // static |
569 void CrashpadClient::UseSystemDefaultHandler() { | 570 void CrashpadClient::UseSystemDefaultHandler() { |
570 base::mac::ScopedMachSendRight | 571 base::mac::ScopedMachSendRight |
571 system_crash_reporter_handler(SystemCrashReporterHandler()); | 572 system_crash_reporter_handler(SystemCrashReporterHandler()); |
572 | 573 |
573 // Proceed even if SystemCrashReporterHandler() failed, setting MACH_PORT_NULL | 574 // Proceed even if SystemCrashReporterHandler() failed, setting MACH_PORT_NULL |
574 // to clear the current exception ports. | 575 // to clear the current exception ports. |
575 if (!SetCrashExceptionPorts(system_crash_reporter_handler.get())) { | 576 if (!SetCrashExceptionPorts(system_crash_reporter_handler.get())) { |
576 SetCrashExceptionPorts(MACH_PORT_NULL); | 577 SetCrashExceptionPorts(MACH_PORT_NULL); |
577 } | 578 } |
578 } | 579 } |
579 | 580 |
580 } // namespace crashpad | 581 } // namespace crashpad |
OLD | NEW |