Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/service_runtime.cc

Issue 133073005: Trusted plugin: Break up InitCommunication(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove nacl_desc if check, use CHECK() instead. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/service_runtime.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 CHECK(nacl_desc);
499 // Create the command channel to the sel_ldr and load the nexe from nacl_desc. 500 // Create the command channel to the sel_ldr and load the nexe from nacl_desc.
500 if (!subprocess_->SetupCommandAndLoad(&command_channel_, nacl_desc)) { 501 if (!subprocess_->SetupCommand(&command_channel_)) {
501 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL, 502 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL,
502 "ServiceRuntime: command channel creation failed"); 503 "ServiceRuntime: command channel creation failed");
503 return false; 504 return false;
504 } 505 }
506
507 if (!subprocess_->LoadModule(&command_channel_, nacl_desc)) {
508 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL,
509 "ServiceRuntime: load module failed");
510 return false;
511 }
512 return true;
513 }
514
515 bool ServiceRuntime::InitReverseService(ErrorInfo* error_info) {
505 // Hook up the reverse service channel. We are the IMC client, but 516 // Hook up the reverse service channel. We are the IMC client, but
506 // provide SRPC service. 517 // provide SRPC service.
507 NaClDesc* out_conn_cap; 518 NaClDesc* out_conn_cap;
508 NaClSrpcResultCodes rpc_result = 519 NaClSrpcResultCodes rpc_result =
509 NaClSrpcInvokeBySignature(&command_channel_, 520 NaClSrpcInvokeBySignature(&command_channel_,
510 "reverse_setup::h", 521 "reverse_setup::h",
511 &out_conn_cap); 522 &out_conn_cap);
512 523
513 if (NACL_SRPC_RESULT_OK != rpc_result) { 524 if (NACL_SRPC_RESULT_OK != rpc_result) {
514 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SETUP, 525 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SETUP,
515 "ServiceRuntime: reverse setup rpc failed"); 526 "ServiceRuntime: reverse setup rpc failed");
516 return false; 527 return false;
517 } 528 }
518 // Get connection capability to service runtime where the IMC 529 // Get connection capability to service runtime where the IMC
519 // server/SRPC client is waiting for a rendezvous. 530 // server/SRPC client is waiting for a rendezvous.
520 NaClLog(4, "ServiceRuntime: got 0x%" NACL_PRIxPTR "\n", 531 NaClLog(4, "ServiceRuntime: got 0x%" NACL_PRIxPTR "\n",
521 (uintptr_t) out_conn_cap); 532 (uintptr_t) out_conn_cap);
522 nacl::DescWrapper* conn_cap = plugin_->wrapper_factory()->MakeGenericCleanup( 533 nacl::DescWrapper* conn_cap = plugin_->wrapper_factory()->MakeGenericCleanup(
523 out_conn_cap); 534 out_conn_cap);
524 if (conn_cap == NULL) { 535 if (conn_cap == NULL) {
525 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_WRAPPER, 536 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_WRAPPER,
526 "ServiceRuntime: wrapper allocation failure"); 537 "ServiceRuntime: wrapper allocation failure");
527 return false; 538 return false;
528 } 539 }
529 out_conn_cap = NULL; // ownership passed 540 out_conn_cap = NULL; // ownership passed
530 NaClLog(4, "ServiceRuntime::InitCommunication: starting reverse service\n"); 541 NaClLog(4, "ServiceRuntime::InitReverseService: starting reverse service\n");
531 reverse_service_ = new nacl::ReverseService(conn_cap, rev_interface_->Ref()); 542 reverse_service_ = new nacl::ReverseService(conn_cap, rev_interface_->Ref());
532 if (!reverse_service_->Start()) { 543 if (!reverse_service_->Start()) {
533 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE, 544 error_info->SetReport(ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE,
534 "ServiceRuntime: starting reverse services failed"); 545 "ServiceRuntime: starting reverse services failed");
535 return false; 546 return false;
536 } 547 }
548 return true;
549 }
537 550
551 bool ServiceRuntime::StartModule(ErrorInfo* error_info) {
538 // start the module. otherwise we cannot connect for multimedia 552 // start the module. otherwise we cannot connect for multimedia
539 // subsystem since that is handled by user-level code (not secure!) 553 // subsystem since that is handled by user-level code (not secure!)
540 // in libsrpc. 554 // in libsrpc.
541 int load_status = -1; 555 int load_status = -1;
542 rpc_result = 556 NaClSrpcResultCodes rpc_result =
543 NaClSrpcInvokeBySignature(&command_channel_, 557 NaClSrpcInvokeBySignature(&command_channel_,
544 "start_module::i", 558 "start_module::i",
545 &load_status); 559 &load_status);
546 560
547 if (NACL_SRPC_RESULT_OK != rpc_result) { 561 if (NACL_SRPC_RESULT_OK != rpc_result) {
548 error_info->SetReport(ERROR_SEL_LDR_START_MODULE, 562 error_info->SetReport(ERROR_SEL_LDR_START_MODULE,
549 "ServiceRuntime: could not start nacl module"); 563 "ServiceRuntime: could not start nacl module");
550 return false; 564 return false;
551 } 565 }
552 NaClLog(4, "ServiceRuntime::InitCommunication (load_status=%d)\n", 566 NaClLog(4, "ServiceRuntime::StartModule (load_status=%d)\n",
553 load_status); 567 load_status);
554 if (main_service_runtime_) { 568 if (main_service_runtime_) {
555 plugin_->ReportSelLdrLoadStatus(load_status); 569 plugin_->ReportSelLdrLoadStatus(load_status);
556 } 570 }
557 if (LOAD_OK != load_status) { 571 if (LOAD_OK != load_status) {
558 error_info->SetReport( 572 error_info->SetReport(
559 ERROR_SEL_LDR_START_STATUS, 573 ERROR_SEL_LDR_START_STATUS,
560 NaClErrorString(static_cast<NaClErrorCode>(load_status))); 574 NaClErrorString(static_cast<NaClErrorCode>(load_status)));
561 return false; 575 return false;
562 } 576 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 nacl::MutexLocker take(&mu_); 624 nacl::MutexLocker take(&mu_);
611 start_sel_ldr_done_ = true; 625 start_sel_ldr_done_ = true;
612 NaClXCondVarSignal(&cond_); 626 NaClXCondVarSignal(&cond_);
613 } 627 }
614 628
615 bool ServiceRuntime::LoadNexeAndStart(nacl::DescWrapper* nacl_desc, 629 bool ServiceRuntime::LoadNexeAndStart(nacl::DescWrapper* nacl_desc,
616 ErrorInfo* error_info, 630 ErrorInfo* error_info,
617 const pp::CompletionCallback& crash_cb) { 631 const pp::CompletionCallback& crash_cb) {
618 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (nacl_desc=%p)\n", 632 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (nacl_desc=%p)\n",
619 reinterpret_cast<void*>(nacl_desc)); 633 reinterpret_cast<void*>(nacl_desc));
620 if (!InitCommunication(nacl_desc, error_info)) { 634 bool ok = LoadModule(nacl_desc, error_info) &&
635 InitReverseService(error_info) &&
636 StartModule(error_info);
637 if (!ok) {
621 // On a load failure the service runtime does not crash itself to 638 // 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 639 // avoid a race where the no-more-senders error on the reverse
623 // channel esrvice thread might cause the crash-detection logic to 640 // channel esrvice thread might cause the crash-detection logic to
624 // kick in before the start_module RPC reply has been received. So 641 // kick in before the start_module RPC reply has been received. So
625 // we induce a service runtime crash here. We do not release 642 // we induce a service runtime crash here. We do not release
626 // subprocess_ since it's needed to collect crash log output after 643 // subprocess_ since it's needed to collect crash log output after
627 // the error is reported. 644 // the error is reported.
628 Log(LOG_FATAL, "reap logs"); 645 Log(LOG_FATAL, "reap logs");
629 if (NULL == reverse_service_) { 646 if (NULL == reverse_service_) {
630 // No crash detector thread. 647 // No crash detector thread.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 736
720 nacl::string ServiceRuntime::GetCrashLogOutput() { 737 nacl::string ServiceRuntime::GetCrashLogOutput() {
721 if (NULL != subprocess_.get()) { 738 if (NULL != subprocess_.get()) {
722 return subprocess_->GetCrashLogOutput(); 739 return subprocess_->GetCrashLogOutput();
723 } else { 740 } else {
724 return std::string(); 741 return std::string();
725 } 742 }
726 } 743 }
727 744
728 } // namespace plugin 745 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/service_runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698