| 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 "handler/mac/exception_handler_server.h" | 15 #include "handler/mac/exception_handler_server.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 #include "base/strings/stringprintf.h" | |
| 20 #include "util/mach/composite_mach_message_server.h" | 19 #include "util/mach/composite_mach_message_server.h" |
| 21 #include "util/mach/exc_server_variants.h" | |
| 22 #include "util/mach/exception_behaviors.h" | |
| 23 #include "util/mach/mach_extensions.h" | 20 #include "util/mach/mach_extensions.h" |
| 24 #include "util/mach/mach_message.h" | 21 #include "util/mach/mach_message.h" |
| 25 #include "util/mach/mach_message_server.h" | 22 #include "util/mach/mach_message_server.h" |
| 26 #include "util/mach/notify_server.h" | 23 #include "util/mach/notify_server.h" |
| 27 | 24 |
| 28 namespace crashpad { | 25 namespace crashpad { |
| 29 | 26 |
| 30 namespace { | 27 namespace { |
| 31 | 28 |
| 32 class ExceptionHandlerServerRun | 29 class ExceptionHandlerServerRun |
| 33 : public UniversalMachExcServer::Interface, | 30 : public UniversalMachExcServer::Interface, |
| 34 public NotifyServer::Interface { | 31 public NotifyServer::Interface { |
| 35 public: | 32 public: |
| 36 explicit ExceptionHandlerServerRun(mach_port_t exception_port) | 33 ExceptionHandlerServerRun( |
| 34 mach_port_t exception_port, |
| 35 UniversalMachExcServer::Interface* exception_interface) |
| 37 : UniversalMachExcServer::Interface(), | 36 : UniversalMachExcServer::Interface(), |
| 38 NotifyServer::Interface(), | 37 NotifyServer::Interface(), |
| 39 mach_exc_server_(this), | 38 mach_exc_server_(this), |
| 40 notify_server_(this), | 39 notify_server_(this), |
| 41 composite_mach_message_server_(), | 40 composite_mach_message_server_(), |
| 41 exception_interface_(exception_interface), |
| 42 exception_port_(exception_port), | 42 exception_port_(exception_port), |
| 43 notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)), | 43 notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)), |
| 44 running_(true) { | 44 running_(true) { |
| 45 CHECK_NE(notify_port_, kMachPortNull); | 45 CHECK_NE(notify_port_, kMachPortNull); |
| 46 | 46 |
| 47 composite_mach_message_server_.AddHandler(&mach_exc_server_); | 47 composite_mach_message_server_.AddHandler(&mach_exc_server_); |
| 48 composite_mach_message_server_.AddHandler(¬ify_server_); | 48 composite_mach_message_server_.AddHandler(¬ify_server_); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ~ExceptionHandlerServerRun() { | 51 ~ExceptionHandlerServerRun() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 exception_type_t exception, | 117 exception_type_t exception, |
| 118 const mach_exception_data_type_t* code, | 118 const mach_exception_data_type_t* code, |
| 119 mach_msg_type_number_t code_count, | 119 mach_msg_type_number_t code_count, |
| 120 thread_state_flavor_t* flavor, | 120 thread_state_flavor_t* flavor, |
| 121 const natural_t* old_state, | 121 const natural_t* old_state, |
| 122 mach_msg_type_number_t old_state_count, | 122 mach_msg_type_number_t old_state_count, |
| 123 thread_state_t new_state, | 123 thread_state_t new_state, |
| 124 mach_msg_type_number_t* new_state_count, | 124 mach_msg_type_number_t* new_state_count, |
| 125 const mach_msg_trailer_t* trailer, | 125 const mach_msg_trailer_t* trailer, |
| 126 bool* destroy_complex_request) override { | 126 bool* destroy_complex_request) override { |
| 127 *destroy_complex_request = true; | |
| 128 | |
| 129 if (exception_port != exception_port_) { | 127 if (exception_port != exception_port_) { |
| 130 LOG(WARNING) << "exception port mismatch"; | 128 LOG(WARNING) << "exception port mismatch"; |
| 131 return MIG_BAD_ID; | 129 return MIG_BAD_ID; |
| 132 } | 130 } |
| 133 | 131 |
| 134 // The expected behavior is EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, | 132 return exception_interface_->CatchMachException(behavior, |
| 135 // but it’s possible to deal with any exception behavior as long as it | 133 exception_port, |
| 136 // carries identity information (valid thread and task ports). | 134 thread, |
| 137 if (!ExceptionBehaviorHasIdentity(behavior)) { | 135 task, |
| 138 LOG(WARNING) << base::StringPrintf( | 136 exception, |
| 139 "unexpected exception behavior 0x%x, rejecting", behavior); | 137 code, |
| 140 return KERN_FAILURE; | 138 code_count, |
| 141 } else if (behavior != (EXCEPTION_STATE_IDENTITY | kMachExceptionCodes)) { | 139 flavor, |
| 142 LOG(WARNING) << base::StringPrintf( | 140 old_state, |
| 143 "unexpected exception behavior 0x%x, proceeding", behavior); | 141 old_state_count, |
| 144 } | 142 new_state, |
| 145 | 143 new_state_count, |
| 146 // TODO(mark): Implement. | 144 trailer, |
| 147 | 145 destroy_complex_request); |
| 148 return ExcServerSuccessfulReturnValue(behavior, false); | |
| 149 } | 146 } |
| 150 | 147 |
| 151 // NotifyServer::Interface: | 148 // NotifyServer::Interface: |
| 152 | 149 |
| 153 kern_return_t DoMachNotifyPortDeleted( | 150 kern_return_t DoMachNotifyPortDeleted( |
| 154 notify_port_t notify, | 151 notify_port_t notify, |
| 155 mach_port_name_t name, | 152 mach_port_name_t name, |
| 156 const mach_msg_trailer_t* trailer) override { | 153 const mach_msg_trailer_t* trailer) override { |
| 157 return UnimplementedNotifyRoutine(notify); | 154 return UnimplementedNotifyRoutine(notify); |
| 158 } | 155 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return MIG_BAD_ID; | 203 return MIG_BAD_ID; |
| 207 } | 204 } |
| 208 | 205 |
| 209 NOTREACHED(); | 206 NOTREACHED(); |
| 210 return KERN_FAILURE; | 207 return KERN_FAILURE; |
| 211 } | 208 } |
| 212 | 209 |
| 213 UniversalMachExcServer mach_exc_server_; | 210 UniversalMachExcServer mach_exc_server_; |
| 214 NotifyServer notify_server_; | 211 NotifyServer notify_server_; |
| 215 CompositeMachMessageServer composite_mach_message_server_; | 212 CompositeMachMessageServer composite_mach_message_server_; |
| 213 UniversalMachExcServer::Interface* exception_interface_; // weak |
| 216 mach_port_t exception_port_; // weak | 214 mach_port_t exception_port_; // weak |
| 217 base::mac::ScopedMachReceiveRight notify_port_; | 215 base::mac::ScopedMachReceiveRight notify_port_; |
| 218 bool running_; | 216 bool running_; |
| 219 | 217 |
| 220 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServerRun); | 218 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServerRun); |
| 221 }; | 219 }; |
| 222 | 220 |
| 223 } // namespace | 221 } // namespace |
| 224 | 222 |
| 225 ExceptionHandlerServer::ExceptionHandlerServer() | 223 ExceptionHandlerServer::ExceptionHandlerServer() |
| 226 : receive_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)) { | 224 : receive_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)) { |
| 227 CHECK_NE(receive_port_, kMachPortNull); | 225 CHECK_NE(receive_port_, kMachPortNull); |
| 228 } | 226 } |
| 229 | 227 |
| 230 ExceptionHandlerServer::~ExceptionHandlerServer() { | 228 ExceptionHandlerServer::~ExceptionHandlerServer() { |
| 231 } | 229 } |
| 232 | 230 |
| 233 void ExceptionHandlerServer::Run() { | 231 void ExceptionHandlerServer::Run( |
| 234 ExceptionHandlerServerRun run(receive_port_); | 232 UniversalMachExcServer::Interface* exception_interface) { |
| 233 ExceptionHandlerServerRun run(receive_port_, exception_interface); |
| 235 run.Run(); | 234 run.Run(); |
| 236 } | 235 } |
| 237 | 236 |
| 238 } // namespace crashpad | 237 } // namespace crashpad |
| OLD | NEW |