OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #include "util/mach/exc_server_variants.h" |
| 16 |
| 17 #include <algorithm> |
| 18 #include <vector> |
| 19 |
| 20 #include "base/basictypes.h" |
| 21 #include "base/logging.h" |
| 22 #include "util/mach/exc.h" |
| 23 #include "util/mach/excServer.h" |
| 24 #include "util/mach/mach_exc.h" |
| 25 #include "util/mach/mach_excServer.h" |
| 26 |
| 27 extern "C" { |
| 28 |
| 29 // These six functions are not used, and are in fact obsoleted by the other |
| 30 // functionality implemented in this file. The standard MIG-generated exc_server |
| 31 // (in excServer.c) and mach_exc_server (in mach_excServer.c) server dispatch |
| 32 // routines usable with the standard mach_msg_server() function call out to |
| 33 // these functions. exc_server() and mach_exc_server() are unused and are |
| 34 // replaced by the more flexible ExcServer and MachExcServer, but the linker |
| 35 // still needs to see these six function definitions. |
| 36 |
| 37 kern_return_t catch_exception_raise(exception_handler_t exception_port, |
| 38 thread_t thread, |
| 39 task_t task, |
| 40 exception_type_t exception, |
| 41 exception_data_t code, |
| 42 mach_msg_type_number_t code_count) { |
| 43 NOTREACHED(); |
| 44 return KERN_FAILURE; |
| 45 } |
| 46 |
| 47 kern_return_t catch_exception_raise_state( |
| 48 exception_handler_t exception_port, |
| 49 exception_type_t exception, |
| 50 exception_data_t code, |
| 51 mach_msg_type_number_t code_count, |
| 52 thread_state_flavor_t* flavor, |
| 53 thread_state_t old_state, |
| 54 mach_msg_type_number_t old_state_count, |
| 55 thread_state_t new_state, |
| 56 mach_msg_type_number_t* new_state_count) { |
| 57 NOTREACHED(); |
| 58 return KERN_FAILURE; |
| 59 } |
| 60 |
| 61 kern_return_t catch_exception_raise_state_identity( |
| 62 exception_handler_t exception_port, |
| 63 thread_t thread, |
| 64 task_t task, |
| 65 exception_type_t exception, |
| 66 exception_data_t code, |
| 67 mach_msg_type_number_t code_count, |
| 68 thread_state_flavor_t* flavor, |
| 69 thread_state_t old_state, |
| 70 mach_msg_type_number_t old_state_count, |
| 71 thread_state_t new_state, |
| 72 mach_msg_type_number_t* new_state_count) { |
| 73 NOTREACHED(); |
| 74 return KERN_FAILURE; |
| 75 } |
| 76 |
| 77 kern_return_t catch_mach_exception_raise(exception_handler_t exception_port, |
| 78 thread_t thread, |
| 79 task_t task, |
| 80 exception_type_t exception, |
| 81 mach_exception_data_t code, |
| 82 mach_msg_type_number_t code_count) { |
| 83 NOTREACHED(); |
| 84 return KERN_FAILURE; |
| 85 } |
| 86 |
| 87 kern_return_t catch_mach_exception_raise_state( |
| 88 exception_handler_t exception_port, |
| 89 exception_type_t exception, |
| 90 mach_exception_data_t code, |
| 91 mach_msg_type_number_t code_count, |
| 92 thread_state_flavor_t* flavor, |
| 93 thread_state_t old_state, |
| 94 mach_msg_type_number_t old_state_count, |
| 95 thread_state_t new_state, |
| 96 mach_msg_type_number_t* new_state_count) { |
| 97 NOTREACHED(); |
| 98 return KERN_FAILURE; |
| 99 } |
| 100 |
| 101 kern_return_t catch_mach_exception_raise_state_identity( |
| 102 exception_handler_t exception_port, |
| 103 thread_t thread, |
| 104 task_t task, |
| 105 exception_type_t exception, |
| 106 mach_exception_data_t code, |
| 107 mach_msg_type_number_t code_count, |
| 108 thread_state_flavor_t* flavor, |
| 109 thread_state_t old_state, |
| 110 mach_msg_type_number_t old_state_count, |
| 111 thread_state_t new_state, |
| 112 mach_msg_type_number_t* new_state_count) { |
| 113 NOTREACHED(); |
| 114 return KERN_FAILURE; |
| 115 } |
| 116 |
| 117 } // extern "C" |
| 118 |
| 119 namespace { |
| 120 |
| 121 void PrepareReplyFromRequest(const mach_msg_header_t* in_header, |
| 122 mach_msg_header_t* out_header) { |
| 123 out_header->msgh_bits = |
| 124 MACH_MSGH_BITS(MACH_MSGH_BITS_REMOTE(in_header->msgh_bits), 0); |
| 125 out_header->msgh_remote_port = in_header->msgh_remote_port; |
| 126 out_header->msgh_size = sizeof(mig_reply_error_t); |
| 127 out_header->msgh_local_port = MACH_PORT_NULL; |
| 128 out_header->msgh_id = in_header->msgh_id + 100; |
| 129 reinterpret_cast<mig_reply_error_t*>(out_header)->NDR = NDR_record; |
| 130 } |
| 131 |
| 132 void SetReplyError(mach_msg_header_t* out_header, kern_return_t error) { |
| 133 reinterpret_cast<mig_reply_error_t*>(out_header)->RetCode = error; |
| 134 } |
| 135 |
| 136 // There are no predefined constants for these. |
| 137 enum MachMessageID : mach_msg_id_t { |
| 138 kMachMessageIDExceptionRaise = 2401, |
| 139 kMachMessageIDExceptionRaiseState = 2402, |
| 140 kMachMessageIDExceptionRaiseStateIdentity = 2403, |
| 141 kMachMessageIDMachExceptionRaise = 2405, |
| 142 kMachMessageIDMachExceptionRaiseState = 2406, |
| 143 kMachMessageIDMachExceptionRaiseStateIdentity = 2407, |
| 144 }; |
| 145 |
| 146 } // namespace |
| 147 |
| 148 namespace crashpad { |
| 149 namespace internal { |
| 150 |
| 151 ExcServer::ExcServer(ExcServer::Interface* interface) |
| 152 : MachMessageServer::Interface(), |
| 153 interface_(interface) { |
| 154 } |
| 155 |
| 156 bool ExcServer::MachMessageServerFunction(mach_msg_header_t* in_header, |
| 157 mach_msg_header_t* out_header, |
| 158 bool* destroy_complex_request) { |
| 159 PrepareReplyFromRequest(in_header, out_header); |
| 160 |
| 161 switch (in_header->msgh_id) { |
| 162 case kMachMessageIDExceptionRaise: { |
| 163 // exception_raise(), catch_exception_raise(). |
| 164 typedef __Request__exception_raise_t Request; |
| 165 Request* in_request = reinterpret_cast<Request*>(in_header); |
| 166 kern_return_t kr = __MIG_check__Request__exception_raise_t(in_request); |
| 167 if (kr != MACH_MSG_SUCCESS) { |
| 168 SetReplyError(out_header, kr); |
| 169 return true; |
| 170 } |
| 171 |
| 172 typedef __Reply__exception_raise_t Reply; |
| 173 Reply* out_reply = reinterpret_cast<Reply*>(out_header); |
| 174 out_reply->RetCode = |
| 175 interface_->CatchExceptionRaise(in_header->msgh_local_port, |
| 176 in_request->thread.name, |
| 177 in_request->task.name, |
| 178 in_request->exception, |
| 179 in_request->code, |
| 180 in_request->codeCnt, |
| 181 destroy_complex_request); |
| 182 if (out_reply->RetCode != KERN_SUCCESS) { |
| 183 return true; |
| 184 } |
| 185 |
| 186 out_header->msgh_size = sizeof(*out_reply); |
| 187 return true; |
| 188 } |
| 189 |
| 190 case kMachMessageIDExceptionRaiseState: { |
| 191 // exception_raise_state(), catch_exception_raise_state(). |
| 192 typedef __Request__exception_raise_state_t Request; |
| 193 Request* in_request = reinterpret_cast<Request*>(in_header); |
| 194 |
| 195 // in_request_1 is used for the portion of the request after the codes, |
| 196 // which in theory can be variable-length. The check function will set it. |
| 197 Request* in_request_1; |
| 198 kern_return_t kr = __MIG_check__Request__exception_raise_state_t( |
| 199 in_request, &in_request_1); |
| 200 if (kr != MACH_MSG_SUCCESS) { |
| 201 SetReplyError(out_header, kr); |
| 202 return true; |
| 203 } |
| 204 |
| 205 typedef __Reply__exception_raise_state_t Reply; |
| 206 Reply* out_reply = reinterpret_cast<Reply*>(out_header); |
| 207 out_reply->new_stateCnt = arraysize(out_reply->new_state); |
| 208 out_reply->RetCode = |
| 209 interface_->CatchExceptionRaiseState(in_header->msgh_local_port, |
| 210 in_request->exception, |
| 211 in_request->code, |
| 212 in_request->codeCnt, |
| 213 &in_request_1->flavor, |
| 214 in_request_1->old_state, |
| 215 in_request_1->old_stateCnt, |
| 216 out_reply->new_state, |
| 217 &out_reply->new_stateCnt); |
| 218 if (out_reply->RetCode != KERN_SUCCESS) { |
| 219 return true; |
| 220 } |
| 221 |
| 222 out_reply->flavor = in_request_1->flavor; |
| 223 out_header->msgh_size = |
| 224 sizeof(*out_reply) - sizeof(out_reply->new_state) + |
| 225 sizeof(out_reply->new_state[0]) * out_reply->new_stateCnt; |
| 226 return true; |
| 227 } |
| 228 |
| 229 case kMachMessageIDExceptionRaiseStateIdentity: { |
| 230 // exception_raise_state_identity(), |
| 231 // catch_exception_raise_state_identity(). |
| 232 typedef __Request__exception_raise_state_identity_t Request; |
| 233 Request* in_request = reinterpret_cast<Request*>(in_header); |
| 234 |
| 235 // in_request_1 is used for the portion of the request after the codes, |
| 236 // which in theory can be variable-length. The check function will set it. |
| 237 Request* in_request_1; |
| 238 kern_return_t kr = __MIG_check__Request__exception_raise_state_identity_t( |
| 239 in_request, &in_request_1); |
| 240 if (kr != MACH_MSG_SUCCESS) { |
| 241 SetReplyError(out_header, kr); |
| 242 return true; |
| 243 } |
| 244 |
| 245 typedef __Reply__exception_raise_state_identity_t Reply; |
| 246 Reply* out_reply = reinterpret_cast<Reply*>(out_header); |
| 247 out_reply->new_stateCnt = arraysize(out_reply->new_state); |
| 248 out_reply->RetCode = interface_->CatchExceptionRaiseStateIdentity( |
| 249 in_header->msgh_local_port, |
| 250 in_request->thread.name, |
| 251 in_request->task.name, |
| 252 in_request->exception, |
| 253 in_request->code, |
| 254 in_request->codeCnt, |
| 255 &in_request_1->flavor, |
| 256 in_request_1->old_state, |
| 257 in_request_1->old_stateCnt, |
| 258 out_reply->new_state, |
| 259 &out_reply->new_stateCnt, |
| 260 destroy_complex_request); |
| 261 if (out_reply->RetCode != KERN_SUCCESS) { |
| 262 return true; |
| 263 } |
| 264 |
| 265 out_reply->flavor = in_request_1->flavor; |
| 266 out_header->msgh_size = |
| 267 sizeof(*out_reply) - sizeof(out_reply->new_state) + |
| 268 sizeof(out_reply->new_state[0]) * out_reply->new_stateCnt; |
| 269 return true; |
| 270 } |
| 271 } |
| 272 |
| 273 SetReplyError(out_header, MIG_BAD_ID); |
| 274 return false; |
| 275 } |
| 276 |
| 277 mach_msg_size_t ExcServer::MachMessageServerRequestSize() { |
| 278 return sizeof(__RequestUnion__exc_subsystem); |
| 279 } |
| 280 |
| 281 mach_msg_size_t ExcServer::MachMessageServerReplySize() { |
| 282 return sizeof(__ReplyUnion__exc_subsystem); |
| 283 } |
| 284 |
| 285 MachExcServer::MachExcServer(MachExcServer::Interface* interface) |
| 286 : MachMessageServer::Interface(), |
| 287 interface_(interface) { |
| 288 } |
| 289 |
| 290 bool MachExcServer::MachMessageServerFunction(mach_msg_header_t* in_header, |
| 291 mach_msg_header_t* out_header, |
| 292 bool* destroy_complex_request) { |
| 293 PrepareReplyFromRequest(in_header, out_header); |
| 294 |
| 295 switch (in_header->msgh_id) { |
| 296 case kMachMessageIDMachExceptionRaise: { |
| 297 // mach_exception_raise(), catch_mach_exception_raise(). |
| 298 typedef __Request__mach_exception_raise_t Request; |
| 299 Request* in_request = reinterpret_cast<Request*>(in_header); |
| 300 kern_return_t kr = |
| 301 __MIG_check__Request__mach_exception_raise_t(in_request); |
| 302 if (kr != MACH_MSG_SUCCESS) { |
| 303 SetReplyError(out_header, kr); |
| 304 return true; |
| 305 } |
| 306 |
| 307 typedef __Reply__mach_exception_raise_t Reply; |
| 308 Reply* out_reply = reinterpret_cast<Reply*>(out_header); |
| 309 out_reply->RetCode = |
| 310 interface_->CatchMachExceptionRaise(in_header->msgh_local_port, |
| 311 in_request->thread.name, |
| 312 in_request->task.name, |
| 313 in_request->exception, |
| 314 in_request->code, |
| 315 in_request->codeCnt, |
| 316 destroy_complex_request); |
| 317 if (out_reply->RetCode != KERN_SUCCESS) { |
| 318 return true; |
| 319 } |
| 320 |
| 321 out_header->msgh_size = sizeof(*out_reply); |
| 322 return true; |
| 323 } |
| 324 |
| 325 case kMachMessageIDMachExceptionRaiseState: { |
| 326 // mach_exception_raise_state(), catch_mach_exception_raise_state(). |
| 327 typedef __Request__mach_exception_raise_state_t Request; |
| 328 Request* in_request = reinterpret_cast<Request*>(in_header); |
| 329 |
| 330 // in_request_1 is used for the portion of the request after the codes, |
| 331 // which in theory can be variable-length. The check function will set it. |
| 332 Request* in_request_1; |
| 333 kern_return_t kr = __MIG_check__Request__mach_exception_raise_state_t( |
| 334 in_request, &in_request_1); |
| 335 if (kr != MACH_MSG_SUCCESS) { |
| 336 SetReplyError(out_header, kr); |
| 337 return true; |
| 338 } |
| 339 |
| 340 typedef __Reply__mach_exception_raise_state_t Reply; |
| 341 Reply* out_reply = reinterpret_cast<Reply*>(out_header); |
| 342 out_reply->new_stateCnt = arraysize(out_reply->new_state); |
| 343 out_reply->RetCode = |
| 344 interface_->CatchMachExceptionRaiseState(in_header->msgh_local_port, |
| 345 in_request->exception, |
| 346 in_request->code, |
| 347 in_request->codeCnt, |
| 348 &in_request_1->flavor, |
| 349 in_request_1->old_state, |
| 350 in_request_1->old_stateCnt, |
| 351 out_reply->new_state, |
| 352 &out_reply->new_stateCnt); |
| 353 if (out_reply->RetCode != KERN_SUCCESS) { |
| 354 return true; |
| 355 } |
| 356 |
| 357 out_reply->flavor = in_request_1->flavor; |
| 358 out_header->msgh_size = |
| 359 sizeof(*out_reply) - sizeof(out_reply->new_state) + |
| 360 sizeof(out_reply->new_state[0]) * out_reply->new_stateCnt; |
| 361 return true; |
| 362 } |
| 363 |
| 364 case kMachMessageIDMachExceptionRaiseStateIdentity: { |
| 365 // mach_exception_raise_state_identity(), |
| 366 // catch_mach_exception_raise_state_identity(). |
| 367 typedef __Request__mach_exception_raise_state_identity_t Request; |
| 368 Request* in_request = reinterpret_cast<Request*>(in_header); |
| 369 |
| 370 // in_request_1 is used for the portion of the request after the codes, |
| 371 // which in theory can be variable-length. The check function will set it. |
| 372 Request* in_request_1; |
| 373 kern_return_t kr = |
| 374 __MIG_check__Request__mach_exception_raise_state_identity_t( |
| 375 in_request, &in_request_1); |
| 376 if (kr != MACH_MSG_SUCCESS) { |
| 377 SetReplyError(out_header, kr); |
| 378 return true; |
| 379 } |
| 380 |
| 381 typedef __Reply__mach_exception_raise_state_identity_t Reply; |
| 382 Reply* out_reply = reinterpret_cast<Reply*>(out_header); |
| 383 out_reply->new_stateCnt = arraysize(out_reply->new_state); |
| 384 out_reply->RetCode = interface_->CatchMachExceptionRaiseStateIdentity( |
| 385 in_header->msgh_local_port, |
| 386 in_request->thread.name, |
| 387 in_request->task.name, |
| 388 in_request->exception, |
| 389 in_request->code, |
| 390 in_request->codeCnt, |
| 391 &in_request_1->flavor, |
| 392 in_request_1->old_state, |
| 393 in_request_1->old_stateCnt, |
| 394 out_reply->new_state, |
| 395 &out_reply->new_stateCnt, |
| 396 destroy_complex_request); |
| 397 if (out_reply->RetCode != KERN_SUCCESS) { |
| 398 return true; |
| 399 } |
| 400 |
| 401 out_reply->flavor = in_request_1->flavor; |
| 402 out_header->msgh_size = |
| 403 sizeof(*out_reply) - sizeof(out_reply->new_state) + |
| 404 sizeof(out_reply->new_state[0]) * out_reply->new_stateCnt; |
| 405 return true; |
| 406 } |
| 407 } |
| 408 |
| 409 SetReplyError(out_header, MIG_BAD_ID); |
| 410 return false; |
| 411 } |
| 412 |
| 413 mach_msg_size_t MachExcServer::MachMessageServerRequestSize() { |
| 414 return sizeof(__RequestUnion__mach_exc_subsystem); |
| 415 } |
| 416 |
| 417 mach_msg_size_t MachExcServer::MachMessageServerReplySize() { |
| 418 return sizeof(__ReplyUnion__mach_exc_subsystem); |
| 419 } |
| 420 |
| 421 SimplifiedExcServer::SimplifiedExcServer( |
| 422 SimplifiedExcServer::Interface* interface) |
| 423 : ExcServer(this), |
| 424 ExcServer::Interface(), |
| 425 interface_(interface) { |
| 426 } |
| 427 |
| 428 kern_return_t SimplifiedExcServer::CatchExceptionRaise( |
| 429 exception_handler_t exception_port, |
| 430 thread_t thread, |
| 431 task_t task, |
| 432 exception_type_t exception, |
| 433 const exception_data_type_t* code, |
| 434 mach_msg_type_number_t code_count, |
| 435 bool* destroy_request) { |
| 436 thread_state_flavor_t flavor = THREAD_STATE_NONE; |
| 437 mach_msg_type_number_t new_state_count = 0; |
| 438 return interface_->CatchException(EXCEPTION_DEFAULT, |
| 439 exception_port, |
| 440 thread, |
| 441 task, |
| 442 exception, |
| 443 code, |
| 444 code_count, |
| 445 &flavor, |
| 446 NULL, |
| 447 0, |
| 448 NULL, |
| 449 &new_state_count, |
| 450 destroy_request); |
| 451 } |
| 452 |
| 453 kern_return_t SimplifiedExcServer::CatchExceptionRaiseState( |
| 454 exception_handler_t exception_port, |
| 455 exception_type_t exception, |
| 456 const exception_data_type_t* code, |
| 457 mach_msg_type_number_t code_count, |
| 458 thread_state_flavor_t* flavor, |
| 459 const natural_t* old_state, |
| 460 mach_msg_type_number_t old_state_count, |
| 461 thread_state_t new_state, |
| 462 mach_msg_type_number_t* new_state_count) { |
| 463 bool destroy_complex_request = false; |
| 464 return interface_->CatchException(EXCEPTION_STATE, |
| 465 exception_port, |
| 466 MACH_PORT_NULL, |
| 467 MACH_PORT_NULL, |
| 468 exception, |
| 469 code, |
| 470 code_count, |
| 471 flavor, |
| 472 old_state, |
| 473 old_state_count, |
| 474 new_state, |
| 475 new_state_count, |
| 476 &destroy_complex_request); |
| 477 } |
| 478 |
| 479 kern_return_t SimplifiedExcServer::CatchExceptionRaiseStateIdentity( |
| 480 exception_handler_t exception_port, |
| 481 thread_t thread, |
| 482 task_t task, |
| 483 exception_type_t exception, |
| 484 const exception_data_type_t* code, |
| 485 mach_msg_type_number_t code_count, |
| 486 thread_state_flavor_t* flavor, |
| 487 const natural_t* old_state, |
| 488 mach_msg_type_number_t old_state_count, |
| 489 thread_state_t new_state, |
| 490 mach_msg_type_number_t* new_state_count, |
| 491 bool* destroy_request) { |
| 492 return interface_->CatchException(EXCEPTION_STATE_IDENTITY, |
| 493 exception_port, |
| 494 thread, |
| 495 task, |
| 496 exception, |
| 497 code, |
| 498 code_count, |
| 499 flavor, |
| 500 old_state, |
| 501 old_state_count, |
| 502 new_state, |
| 503 new_state_count, |
| 504 destroy_request); |
| 505 } |
| 506 |
| 507 SimplifiedMachExcServer::SimplifiedMachExcServer( |
| 508 SimplifiedMachExcServer::Interface* interface) |
| 509 : MachExcServer(this), |
| 510 MachExcServer::Interface(), |
| 511 interface_(interface) { |
| 512 } |
| 513 |
| 514 kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaise( |
| 515 exception_handler_t exception_port, |
| 516 thread_t thread, |
| 517 task_t task, |
| 518 exception_type_t exception, |
| 519 const mach_exception_data_type_t* code, |
| 520 mach_msg_type_number_t code_count, |
| 521 bool* destroy_request) { |
| 522 thread_state_flavor_t flavor = THREAD_STATE_NONE; |
| 523 mach_msg_type_number_t new_state_count = 0; |
| 524 return interface_->CatchMachException( |
| 525 EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES, |
| 526 exception_port, |
| 527 thread, |
| 528 task, |
| 529 exception, |
| 530 code, |
| 531 code_count, |
| 532 &flavor, |
| 533 NULL, |
| 534 0, |
| 535 NULL, |
| 536 &new_state_count, |
| 537 destroy_request); |
| 538 } |
| 539 |
| 540 kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaiseState( |
| 541 exception_handler_t exception_port, |
| 542 exception_type_t exception, |
| 543 const mach_exception_data_type_t* code, |
| 544 mach_msg_type_number_t code_count, |
| 545 thread_state_flavor_t* flavor, |
| 546 const natural_t* old_state, |
| 547 mach_msg_type_number_t old_state_count, |
| 548 thread_state_t new_state, |
| 549 mach_msg_type_number_t* new_state_count) { |
| 550 bool destroy_complex_request = false; |
| 551 return interface_->CatchMachException(EXCEPTION_STATE | MACH_EXCEPTION_CODES, |
| 552 exception_port, |
| 553 MACH_PORT_NULL, |
| 554 MACH_PORT_NULL, |
| 555 exception, |
| 556 code, |
| 557 code_count, |
| 558 flavor, |
| 559 old_state, |
| 560 old_state_count, |
| 561 new_state, |
| 562 new_state_count, |
| 563 &destroy_complex_request); |
| 564 } |
| 565 |
| 566 kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaiseStateIdentity( |
| 567 exception_handler_t exception_port, |
| 568 thread_t thread, |
| 569 task_t task, |
| 570 exception_type_t exception, |
| 571 const mach_exception_data_type_t* code, |
| 572 mach_msg_type_number_t code_count, |
| 573 thread_state_flavor_t* flavor, |
| 574 const natural_t* old_state, |
| 575 mach_msg_type_number_t old_state_count, |
| 576 thread_state_t new_state, |
| 577 mach_msg_type_number_t* new_state_count, |
| 578 bool* destroy_request) { |
| 579 return interface_->CatchMachException( |
| 580 EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, |
| 581 exception_port, |
| 582 thread, |
| 583 task, |
| 584 exception, |
| 585 code, |
| 586 code_count, |
| 587 flavor, |
| 588 old_state, |
| 589 old_state_count, |
| 590 new_state, |
| 591 new_state_count, |
| 592 destroy_request); |
| 593 } |
| 594 |
| 595 } // namespace internal |
| 596 |
| 597 UniversalMachExcServer::UniversalMachExcServer() |
| 598 : MachMessageServer::Interface(), |
| 599 internal::SimplifiedExcServer::Interface(), |
| 600 internal::SimplifiedMachExcServer::Interface(), |
| 601 exc_server_(this), |
| 602 mach_exc_server_(this) { |
| 603 } |
| 604 |
| 605 bool UniversalMachExcServer::MachMessageServerFunction( |
| 606 mach_msg_header_t* in_header, |
| 607 mach_msg_header_t* out_header, |
| 608 bool* destroy_complex_request) { |
| 609 switch (in_header->msgh_id) { |
| 610 case kMachMessageIDMachExceptionRaise: |
| 611 case kMachMessageIDMachExceptionRaiseState: |
| 612 case kMachMessageIDMachExceptionRaiseStateIdentity: |
| 613 return mach_exc_server_.MachMessageServerFunction( |
| 614 in_header, out_header, destroy_complex_request); |
| 615 case kMachMessageIDExceptionRaise: |
| 616 case kMachMessageIDExceptionRaiseState: |
| 617 case kMachMessageIDExceptionRaiseStateIdentity: |
| 618 return exc_server_.MachMessageServerFunction( |
| 619 in_header, out_header, destroy_complex_request); |
| 620 } |
| 621 |
| 622 // Do what the MIG-generated server routines do when they can’t dispatch a |
| 623 // message. |
| 624 PrepareReplyFromRequest(in_header, out_header); |
| 625 SetReplyError(out_header, MIG_BAD_ID); |
| 626 return false; |
| 627 } |
| 628 |
| 629 mach_msg_size_t UniversalMachExcServer::MachMessageServerRequestSize() { |
| 630 return std::max(mach_exc_server_.MachMessageServerRequestSize(), |
| 631 exc_server_.MachMessageServerRequestSize()); |
| 632 } |
| 633 |
| 634 mach_msg_size_t UniversalMachExcServer::MachMessageServerReplySize() { |
| 635 return std::max(mach_exc_server_.MachMessageServerReplySize(), |
| 636 exc_server_.MachMessageServerReplySize()); |
| 637 } |
| 638 |
| 639 kern_return_t UniversalMachExcServer::CatchException( |
| 640 exception_behavior_t behavior, |
| 641 exception_handler_t exception_port, |
| 642 thread_t thread, |
| 643 task_t task, |
| 644 exception_type_t exception, |
| 645 const exception_data_type_t* code, |
| 646 mach_msg_type_number_t code_count, |
| 647 thread_state_flavor_t* flavor, |
| 648 const natural_t* old_state, |
| 649 mach_msg_type_number_t old_state_count, |
| 650 thread_state_t new_state, |
| 651 mach_msg_type_number_t* new_state_count, |
| 652 bool* destroy_complex_request) { |
| 653 std::vector<mach_exception_data_type_t> mach_codes; |
| 654 mach_codes.reserve(code_count); |
| 655 for (size_t index = 0; index < code_count; ++index) { |
| 656 mach_codes.push_back(code[index]); |
| 657 } |
| 658 |
| 659 return CatchMachException(behavior, |
| 660 exception_port, |
| 661 thread, |
| 662 task, |
| 663 exception, |
| 664 code_count ? &mach_codes[0] : NULL, |
| 665 code_count, |
| 666 flavor, |
| 667 old_state, |
| 668 old_state_count, |
| 669 new_state, |
| 670 new_state_count, |
| 671 destroy_complex_request); |
| 672 } |
| 673 |
| 674 } // namespace crashpad |
OLD | NEW |