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, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 mach_msg_type_number_t code_count, | 118 mach_msg_type_number_t code_count, |
119 thread_state_flavor_t* flavor, | 119 thread_state_flavor_t* flavor, |
120 ConstThreadState old_state, | 120 ConstThreadState old_state, |
121 mach_msg_type_number_t old_state_count, | 121 mach_msg_type_number_t old_state_count, |
122 thread_state_t new_state, | 122 thread_state_t new_state, |
123 mach_msg_type_number_t* new_state_count, | 123 mach_msg_type_number_t* new_state_count, |
124 const mach_msg_trailer_t* trailer, | 124 const mach_msg_trailer_t* trailer, |
125 bool* destroy_complex_request) override { | 125 bool* destroy_complex_request) override { |
126 if (exception_port != exception_port_) { | 126 if (exception_port != exception_port_) { |
127 LOG(WARNING) << "exception port mismatch"; | 127 LOG(WARNING) << "exception port mismatch"; |
128 return MIG_BAD_ID; | 128 return KERN_FAILURE; |
129 } | 129 } |
130 | 130 |
131 return exception_interface_->CatchMachException(behavior, | 131 return exception_interface_->CatchMachException(behavior, |
132 exception_port, | 132 exception_port, |
133 thread, | 133 thread, |
134 task, | 134 task, |
135 exception, | 135 exception, |
136 code, | 136 code, |
137 code_count, | 137 code_count, |
138 flavor, | 138 flavor, |
(...skipping 26 matching lines...) Expand all Loading... |
165 notify_port_t notify, | 165 notify_port_t notify, |
166 mach_port_mscount_t mscount, | 166 mach_port_mscount_t mscount, |
167 const mach_msg_trailer_t* trailer) override { | 167 const mach_msg_trailer_t* trailer) override { |
168 if (notify != notify_port_) { | 168 if (notify != notify_port_) { |
169 // The message was received as part of a port set. This check ensures that | 169 // The message was received as part of a port set. This check ensures that |
170 // only the authorized sender of the no-senders notification is able to | 170 // only the authorized sender of the no-senders notification is able to |
171 // stop the exception server. Otherwise, a malicious client would be able | 171 // stop the exception server. Otherwise, a malicious client would be able |
172 // to craft and send a no-senders notification via its exception port, and | 172 // to craft and send a no-senders notification via its exception port, and |
173 // cause the handler to stop processing exceptions and exit. | 173 // cause the handler to stop processing exceptions and exit. |
174 LOG(WARNING) << "notify port mismatch"; | 174 LOG(WARNING) << "notify port mismatch"; |
175 return MIG_BAD_ID; | 175 return KERN_FAILURE; |
176 } | 176 } |
177 | 177 |
178 running_ = false; | 178 running_ = false; |
179 | 179 |
180 return KERN_SUCCESS; | 180 return KERN_SUCCESS; |
181 } | 181 } |
182 | 182 |
183 kern_return_t DoMachNotifySendOnce( | 183 kern_return_t DoMachNotifySendOnce( |
184 notify_port_t notify, | 184 notify_port_t notify, |
185 const mach_msg_trailer_t* trailer) override { | 185 const mach_msg_trailer_t* trailer) override { |
186 return UnimplementedNotifyRoutine(notify); | 186 return UnimplementedNotifyRoutine(notify); |
187 } | 187 } |
188 | 188 |
189 kern_return_t DoMachNotifyDeadName( | 189 kern_return_t DoMachNotifyDeadName( |
190 notify_port_t notify, | 190 notify_port_t notify, |
191 mach_port_name_t name, | 191 mach_port_name_t name, |
192 const mach_msg_trailer_t* trailer) override { | 192 const mach_msg_trailer_t* trailer) override { |
193 return UnimplementedNotifyRoutine(notify); | 193 return UnimplementedNotifyRoutine(notify); |
194 } | 194 } |
195 | 195 |
196 private: | 196 private: |
197 kern_return_t UnimplementedNotifyRoutine(notify_port_t notify) { | 197 kern_return_t UnimplementedNotifyRoutine(notify_port_t notify) { |
198 // Most of the routines in the notify subsystem are not expected to be | 198 // Most of the routines in the notify subsystem are not expected to be |
199 // called. | 199 // called. |
200 if (notify != notify_port_) { | 200 if (notify != notify_port_) { |
201 LOG(WARNING) << "notify port mismatch"; | 201 LOG(WARNING) << "notify port mismatch"; |
202 return MIG_BAD_ID; | 202 return KERN_FAILURE; |
203 } | 203 } |
204 | 204 |
205 NOTREACHED(); | 205 NOTREACHED(); |
206 return KERN_FAILURE; | 206 return MIG_BAD_ID; |
207 } | 207 } |
208 | 208 |
209 UniversalMachExcServer mach_exc_server_; | 209 UniversalMachExcServer mach_exc_server_; |
210 NotifyServer notify_server_; | 210 NotifyServer notify_server_; |
211 CompositeMachMessageServer composite_mach_message_server_; | 211 CompositeMachMessageServer composite_mach_message_server_; |
212 UniversalMachExcServer::Interface* exception_interface_; // weak | 212 UniversalMachExcServer::Interface* exception_interface_; // weak |
213 mach_port_t exception_port_; // weak | 213 mach_port_t exception_port_; // weak |
214 base::mac::ScopedMachReceiveRight notify_port_; | 214 base::mac::ScopedMachReceiveRight notify_port_; |
215 bool running_; | 215 bool running_; |
216 | 216 |
217 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServerRun); | 217 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServerRun); |
218 }; | 218 }; |
219 | 219 |
220 } // namespace | 220 } // namespace |
221 | 221 |
222 ExceptionHandlerServer::ExceptionHandlerServer() | 222 ExceptionHandlerServer::ExceptionHandlerServer( |
223 : receive_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)) { | 223 base::mac::ScopedMachReceiveRight receive_port) |
| 224 : receive_port_(receive_port.Pass()) { |
224 CHECK(receive_port_.is_valid()); | 225 CHECK(receive_port_.is_valid()); |
225 } | 226 } |
226 | 227 |
227 ExceptionHandlerServer::~ExceptionHandlerServer() { | 228 ExceptionHandlerServer::~ExceptionHandlerServer() { |
228 } | 229 } |
229 | 230 |
230 void ExceptionHandlerServer::Run( | 231 void ExceptionHandlerServer::Run( |
231 UniversalMachExcServer::Interface* exception_interface) { | 232 UniversalMachExcServer::Interface* exception_interface) { |
232 ExceptionHandlerServerRun run(receive_port_.get(), exception_interface); | 233 ExceptionHandlerServerRun run(receive_port_.get(), exception_interface); |
233 run.Run(); | 234 run.Run(); |
234 } | 235 } |
235 | 236 |
236 } // namespace crashpad | 237 } // namespace crashpad |
OLD | NEW |