OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #define NACL_LOG_MODULE_NAME "Plugin::ServiceRuntime" | 7 #define NACL_LOG_MODULE_NAME "Plugin::ServiceRuntime" |
8 | 8 |
9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" | 9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" |
10 | 10 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 manifest, | 483 manifest, |
484 this, | 484 this, |
485 init_done_cb, crash_cb)), | 485 init_done_cb, crash_cb)), |
486 exit_status_(-1), | 486 exit_status_(-1), |
487 start_sel_ldr_done_(false) { | 487 start_sel_ldr_done_(false) { |
488 NaClSrpcChannelInitialize(&command_channel_); | 488 NaClSrpcChannelInitialize(&command_channel_); |
489 NaClXMutexCtor(&mu_); | 489 NaClXMutexCtor(&mu_); |
490 NaClXCondVarCtor(&cond_); | 490 NaClXCondVarCtor(&cond_); |
491 } | 491 } |
492 | 492 |
493 bool ServiceRuntime::InitCommunication(nacl::DescWrapper* nacl_desc, | 493 bool ServiceRuntime::LoadModule(nacl::DescWrapper* nacl_desc, |
494 ErrorInfo* error_info) { | 494 ErrorInfo* error_info) { |
495 NaClLog(4, "ServiceRuntime::InitCommunication" | 495 NaClLog(4, "ServiceRuntime::LoadModule" |
496 " (this=%p, subprocess=%p)\n", | 496 " (this=%p, subprocess=%p)\n", |
497 static_cast<void*>(this), | 497 static_cast<void*>(this), |
498 static_cast<void*>(subprocess_.get())); | 498 static_cast<void*>(subprocess_.get())); |
499 // Create the command channel to the sel_ldr and load the nexe from nacl_desc. | 499 // Create the command channel to the sel_ldr and load the nexe from nacl_desc. |
500 if (!subprocess_->SetupCommandAndLoad(&command_channel_, nacl_desc)) { | 500 if (!subprocess_->SetupCommand(&command_channel_)) { |
501 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL, | 501 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL, |
502 "ServiceRuntime: command channel creation failed"); | 502 "ServiceRuntime: command channel creation failed"); |
503 return false; | 503 return false; |
504 } | 504 } |
505 | |
506 if (nacl_desc && !subprocess_->LoadModule(&command_channel_, nacl_desc)) { | |
Mark Seaborn
2014/01/16 22:02:41
You might want to remove the NULL check for nacl_d
| |
507 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL, | |
508 "ServiceRuntime: load module failed"); | |
509 return false; | |
510 } | |
511 return true; | |
512 } | |
513 | |
514 bool ServiceRuntime::InitReverseService(ErrorInfo* error_info) { | |
505 // Hook up the reverse service channel. We are the IMC client, but | 515 // Hook up the reverse service channel. We are the IMC client, but |
506 // provide SRPC service. | 516 // provide SRPC service. |
507 NaClDesc* out_conn_cap; | 517 NaClDesc* out_conn_cap; |
508 NaClSrpcResultCodes rpc_result = | 518 NaClSrpcResultCodes rpc_result = |
509 NaClSrpcInvokeBySignature(&command_channel_, | 519 NaClSrpcInvokeBySignature(&command_channel_, |
510 "reverse_setup::h", | 520 "reverse_setup::h", |
511 &out_conn_cap); | 521 &out_conn_cap); |
512 | 522 |
513 if (NACL_SRPC_RESULT_OK != rpc_result) { | 523 if (NACL_SRPC_RESULT_OK != rpc_result) { |
514 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SETUP, | 524 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SETUP, |
515 "ServiceRuntime: reverse setup rpc failed"); | 525 "ServiceRuntime: reverse setup rpc failed"); |
516 return false; | 526 return false; |
517 } | 527 } |
518 // Get connection capability to service runtime where the IMC | 528 // Get connection capability to service runtime where the IMC |
519 // server/SRPC client is waiting for a rendezvous. | 529 // server/SRPC client is waiting for a rendezvous. |
520 NaClLog(4, "ServiceRuntime: got 0x%" NACL_PRIxPTR "\n", | 530 NaClLog(4, "ServiceRuntime: got 0x%" NACL_PRIxPTR "\n", |
521 (uintptr_t) out_conn_cap); | 531 (uintptr_t) out_conn_cap); |
522 nacl::DescWrapper* conn_cap = plugin_->wrapper_factory()->MakeGenericCleanup( | 532 nacl::DescWrapper* conn_cap = plugin_->wrapper_factory()->MakeGenericCleanup( |
523 out_conn_cap); | 533 out_conn_cap); |
524 if (conn_cap == NULL) { | 534 if (conn_cap == NULL) { |
525 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_WRAPPER, | 535 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_WRAPPER, |
526 "ServiceRuntime: wrapper allocation failure"); | 536 "ServiceRuntime: wrapper allocation failure"); |
527 return false; | 537 return false; |
528 } | 538 } |
529 out_conn_cap = NULL; // ownership passed | 539 out_conn_cap = NULL; // ownership passed |
530 NaClLog(4, "ServiceRuntime::InitCommunication: starting reverse service\n"); | 540 NaClLog(4, "ServiceRuntime::InitReverseService: starting reverse service\n"); |
531 reverse_service_ = new nacl::ReverseService(conn_cap, rev_interface_->Ref()); | 541 reverse_service_ = new nacl::ReverseService(conn_cap, rev_interface_->Ref()); |
532 if (!reverse_service_->Start()) { | 542 if (!reverse_service_->Start()) { |
533 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE, | 543 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE, |
534 "ServiceRuntime: starting reverse services failed"); | 544 "ServiceRuntime: starting reverse services failed"); |
535 return false; | 545 return false; |
536 } | 546 } |
547 return true; | |
548 } | |
537 | 549 |
550 bool ServiceRuntime::StartModule(ErrorInfo* error_info) { | |
538 // start the module. otherwise we cannot connect for multimedia | 551 // start the module. otherwise we cannot connect for multimedia |
539 // subsystem since that is handled by user-level code (not secure!) | 552 // subsystem since that is handled by user-level code (not secure!) |
540 // in libsrpc. | 553 // in libsrpc. |
541 int load_status = -1; | 554 int load_status = -1; |
542 rpc_result = | 555 NaClSrpcResultCodes rpc_result = |
543 NaClSrpcInvokeBySignature(&command_channel_, | 556 NaClSrpcInvokeBySignature(&command_channel_, |
544 "start_module::i", | 557 "start_module::i", |
545 &load_status); | 558 &load_status); |
546 | 559 |
547 if (NACL_SRPC_RESULT_OK != rpc_result) { | 560 if (NACL_SRPC_RESULT_OK != rpc_result) { |
548 error_info->SetReport(ERROR_SEL_LDR_START_MODULE, | 561 error_info->SetReport(ERROR_SEL_LDR_START_MODULE, |
549 "ServiceRuntime: could not start nacl module"); | 562 "ServiceRuntime: could not start nacl module"); |
550 return false; | 563 return false; |
551 } | 564 } |
552 NaClLog(4, "ServiceRuntime::InitCommunication (load_status=%d)\n", | 565 NaClLog(4, "ServiceRuntime::StartModule (load_status=%d)\n", |
553 load_status); | 566 load_status); |
554 if (main_service_runtime_) { | 567 if (main_service_runtime_) { |
555 plugin_->ReportSelLdrLoadStatus(load_status); | 568 plugin_->ReportSelLdrLoadStatus(load_status); |
556 } | 569 } |
557 if (LOAD_OK != load_status) { | 570 if (LOAD_OK != load_status) { |
558 error_info->SetReport( | 571 error_info->SetReport( |
559 ERROR_SEL_LDR_START_STATUS, | 572 ERROR_SEL_LDR_START_STATUS, |
560 NaClErrorString(static_cast<NaClErrorCode>(load_status))); | 573 NaClErrorString(static_cast<NaClErrorCode>(load_status))); |
561 return false; | 574 return false; |
562 } | 575 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 nacl::MutexLocker take(&mu_); | 623 nacl::MutexLocker take(&mu_); |
611 start_sel_ldr_done_ = true; | 624 start_sel_ldr_done_ = true; |
612 NaClXCondVarSignal(&cond_); | 625 NaClXCondVarSignal(&cond_); |
613 } | 626 } |
614 | 627 |
615 bool ServiceRuntime::LoadNexeAndStart(nacl::DescWrapper* nacl_desc, | 628 bool ServiceRuntime::LoadNexeAndStart(nacl::DescWrapper* nacl_desc, |
616 ErrorInfo* error_info, | 629 ErrorInfo* error_info, |
617 const pp::CompletionCallback& crash_cb) { | 630 const pp::CompletionCallback& crash_cb) { |
618 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (nacl_desc=%p)\n", | 631 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (nacl_desc=%p)\n", |
619 reinterpret_cast<void*>(nacl_desc)); | 632 reinterpret_cast<void*>(nacl_desc)); |
620 if (!InitCommunication(nacl_desc, error_info)) { | 633 bool ok = LoadModule(nacl_desc, error_info) && |
634 InitReverseService(error_info) && | |
635 StartModule(error_info); | |
636 if (!ok) { | |
621 // On a load failure the service runtime does not crash itself to | 637 // On a load failure the service runtime does not crash itself to |
622 // avoid a race where the no-more-senders error on the reverse | 638 // avoid a race where the no-more-senders error on the reverse |
623 // channel esrvice thread might cause the crash-detection logic to | 639 // channel esrvice thread might cause the crash-detection logic to |
624 // kick in before the start_module RPC reply has been received. So | 640 // kick in before the start_module RPC reply has been received. So |
625 // we induce a service runtime crash here. We do not release | 641 // we induce a service runtime crash here. We do not release |
626 // subprocess_ since it's needed to collect crash log output after | 642 // subprocess_ since it's needed to collect crash log output after |
627 // the error is reported. | 643 // the error is reported. |
628 Log(LOG_FATAL, "reap logs"); | 644 Log(LOG_FATAL, "reap logs"); |
629 if (NULL == reverse_service_) { | 645 if (NULL == reverse_service_) { |
630 // No crash detector thread. | 646 // No crash detector thread. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 | 735 |
720 nacl::string ServiceRuntime::GetCrashLogOutput() { | 736 nacl::string ServiceRuntime::GetCrashLogOutput() { |
721 if (NULL != subprocess_.get()) { | 737 if (NULL != subprocess_.get()) { |
722 return subprocess_->GetCrashLogOutput(); | 738 return subprocess_->GetCrashLogOutput(); |
723 } else { | 739 } else { |
724 return std::string(); | 740 return std::string(); |
725 } | 741 } |
726 } | 742 } |
727 | 743 |
728 } // namespace plugin | 744 } // namespace plugin |
OLD | NEW |