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 "util/mach/exception_ports.h" | 15 #include "util/mach/exception_ports.h" |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/mac/mach_logging.h" | 18 #include "base/mac/mach_logging.h" |
19 | 19 |
20 namespace crashpad { | 20 namespace crashpad { |
21 | 21 |
| 22 ExceptionPorts::ExceptionHandlerVector::ExceptionHandlerVector() |
| 23 : vector_() { |
| 24 } |
| 25 |
| 26 ExceptionPorts::ExceptionHandlerVector::~ExceptionHandlerVector() { |
| 27 Deallocate(); |
| 28 } |
| 29 |
| 30 void ExceptionPorts::ExceptionHandlerVector::clear() { |
| 31 Deallocate(); |
| 32 vector_.clear(); |
| 33 } |
| 34 |
| 35 void ExceptionPorts::ExceptionHandlerVector::Deallocate() { |
| 36 for (ExceptionHandler& exception_handler : vector_) { |
| 37 if (exception_handler.port != MACH_PORT_NULL) { |
| 38 kern_return_t kr = |
| 39 mach_port_deallocate(mach_task_self(), exception_handler.port); |
| 40 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_port_deallocate"; |
| 41 } |
| 42 } |
| 43 } |
| 44 |
22 ExceptionPorts::ExceptionPorts(TargetType target_type, mach_port_t target_port) | 45 ExceptionPorts::ExceptionPorts(TargetType target_type, mach_port_t target_port) |
23 : target_port_(target_port), dealloc_target_port_(false) { | 46 : target_port_(target_port), dealloc_target_port_(false) { |
24 switch (target_type) { | 47 switch (target_type) { |
25 case kTargetTypeHost: | 48 case kTargetTypeHost: |
26 get_exception_ports_ = host_get_exception_ports; | 49 get_exception_ports_ = host_get_exception_ports; |
27 set_exception_ports_ = host_set_exception_ports; | 50 set_exception_ports_ = host_set_exception_ports; |
28 target_name_ = "host"; | 51 target_name_ = "host"; |
29 if (target_port_ == HOST_NULL) { | 52 if (target_port_ == HOST_NULL) { |
30 target_port_ = mach_host_self(); | 53 target_port_ = mach_host_self(); |
31 dealloc_target_port_ = true; | 54 dealloc_target_port_ = true; |
(...skipping 30 matching lines...) Expand all Loading... |
62 } | 85 } |
63 } | 86 } |
64 | 87 |
65 ExceptionPorts::~ExceptionPorts() { | 88 ExceptionPorts::~ExceptionPorts() { |
66 if (dealloc_target_port_) { | 89 if (dealloc_target_port_) { |
67 kern_return_t kr = mach_port_deallocate(mach_task_self(), target_port_); | 90 kern_return_t kr = mach_port_deallocate(mach_task_self(), target_port_); |
68 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_port_deallocate"; | 91 MACH_LOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_port_deallocate"; |
69 } | 92 } |
70 } | 93 } |
71 | 94 |
72 bool ExceptionPorts::GetExceptionPorts( | 95 bool ExceptionPorts::GetExceptionPorts(exception_mask_t mask, |
73 exception_mask_t mask, | 96 ExceptionHandlerVector* handlers) const { |
74 std::vector<ExceptionHandler>* handlers) const { | |
75 // <mach/mach_types.defs> says that these arrays have room for 32 elements, | 97 // <mach/mach_types.defs> says that these arrays have room for 32 elements, |
76 // despite EXC_TYPES_COUNT only being as low as 11 (in the 10.6 SDK), and | 98 // despite EXC_TYPES_COUNT only being as low as 11 (in the 10.6 SDK), and |
77 // later operating system versions have defined more exception types. The | 99 // later operating system versions have defined more exception types. The |
78 // generated task_get_exception_ports() in taskUser.c expects there to be room | 100 // generated task_get_exception_ports() in taskUser.c expects there to be room |
79 // for 32. | 101 // for 32. |
80 const int kMaxPorts = 32; | 102 const int kMaxPorts = 32; |
81 | 103 |
82 // task_get_exception_ports() doesn’t actually use the initial value of | 104 // task_get_exception_ports() doesn’t actually use the initial value of |
83 // handler_count, but 10.9.4 | 105 // handler_count, but 10.9.4 |
84 // xnu-2422.110.17/osfmk/man/task_get_exception_ports.html says it does. Humor | 106 // xnu-2422.110.17/osfmk/man/task_get_exception_ports.html says it does. Humor |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 146 } |
125 | 147 |
126 return true; | 148 return true; |
127 } | 149 } |
128 | 150 |
129 const char* ExceptionPorts::TargetTypeName() const { | 151 const char* ExceptionPorts::TargetTypeName() const { |
130 return target_name_; | 152 return target_name_; |
131 } | 153 } |
132 | 154 |
133 } // namespace crashpad | 155 } // namespace crashpad |
OLD | NEW |