| 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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // return success. | 411 // return success. |
| 412 return true; | 412 return true; |
| 413 } | 413 } |
| 414 | 414 |
| 415 void PluginReverseInterface::ReportCrash() { | 415 void PluginReverseInterface::ReportCrash() { |
| 416 NaClLog(4, "PluginReverseInterface::ReportCrash\n"); | 416 NaClLog(4, "PluginReverseInterface::ReportCrash\n"); |
| 417 | 417 |
| 418 if (crash_cb_.pp_completion_callback().func != NULL) { | 418 if (crash_cb_.pp_completion_callback().func != NULL) { |
| 419 NaClLog(4, "PluginReverseInterface::ReportCrash: invoking CB\n"); | 419 NaClLog(4, "PluginReverseInterface::ReportCrash: invoking CB\n"); |
| 420 pp::Module::Get()->core()->CallOnMainThread(0, crash_cb_, PP_OK); | 420 pp::Module::Get()->core()->CallOnMainThread(0, crash_cb_, PP_OK); |
| 421 // Clear the callback to avoid it gets invoked twice. |
| 422 crash_cb_ = pp::CompletionCallback(); |
| 421 } else { | 423 } else { |
| 422 NaClLog(1, | 424 NaClLog(1, |
| 423 "PluginReverseInterface::ReportCrash:" | 425 "PluginReverseInterface::ReportCrash:" |
| 424 " crash_cb_ not valid, skipping\n"); | 426 " crash_cb_ not valid, skipping\n"); |
| 425 } | 427 } |
| 426 } | 428 } |
| 427 | 429 |
| 428 void PluginReverseInterface::ReportExitStatus(int exit_status) { | 430 void PluginReverseInterface::ReportExitStatus(int exit_status) { |
| 429 service_runtime_->set_exit_status(exit_status); | 431 service_runtime_->set_exit_status(exit_status); |
| 430 } | 432 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 nexe_started_ = false; | 678 nexe_started_ = false; |
| 677 } | 679 } |
| 678 | 680 |
| 679 void ServiceRuntime::SignalNexeStarted() { | 681 void ServiceRuntime::SignalNexeStarted() { |
| 680 nacl::MutexLocker take(&mu_); | 682 nacl::MutexLocker take(&mu_); |
| 681 nexe_started_ = true; | 683 nexe_started_ = true; |
| 682 NaClXCondVarSignal(&cond_); | 684 NaClXCondVarSignal(&cond_); |
| 683 } | 685 } |
| 684 | 686 |
| 685 void ServiceRuntime::LoadNexeAndStart(PP_NaClFileInfo file_info, | 687 void ServiceRuntime::LoadNexeAndStart(PP_NaClFileInfo file_info, |
| 686 const pp::CompletionCallback& started_cb, | 688 const pp::CompletionCallback& callback) { |
| 687 const pp::CompletionCallback& crash_cb) { | |
| 688 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (handle_valid=%d " | 689 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (handle_valid=%d " |
| 689 "token_lo=%" NACL_PRIu64 " token_hi=%" NACL_PRIu64 ")\n", | 690 "token_lo=%" NACL_PRIu64 " token_hi=%" NACL_PRIu64 ")\n", |
| 690 file_info.handle != PP_kInvalidFileHandle, | 691 file_info.handle != PP_kInvalidFileHandle, |
| 691 file_info.token_lo, | 692 file_info.token_lo, |
| 692 file_info.token_hi); | 693 file_info.token_hi); |
| 693 | 694 |
| 694 bool ok = SetupCommandChannel() && | 695 bool ok = SetupCommandChannel() && |
| 695 InitReverseService() && | 696 InitReverseService() && |
| 696 LoadModule(file_info) && | 697 LoadModule(file_info) && |
| 697 StartModule(); | 698 StartModule(); |
| 698 if (!ok) { | 699 if (ok) { |
| 700 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (return 1)\n"); |
| 701 } else { |
| 699 // On a load failure the service runtime does not crash itself to | 702 // On a load failure the service runtime does not crash itself to |
| 700 // avoid a race where the no-more-senders error on the reverse | 703 // avoid a race where the no-more-senders error on the reverse |
| 701 // channel esrvice thread might cause the crash-detection logic to | 704 // channel esrvice thread might cause the crash-detection logic to |
| 702 // kick in before the start_module RPC reply has been received. So | 705 // kick in before the start_module RPC reply has been received. So |
| 703 // we induce a service runtime crash here. We do not release | 706 // we induce a service runtime crash here. We do not release |
| 704 // subprocess_ since it's needed to collect crash log output after | 707 // subprocess_ since it's needed to collect crash log output after |
| 705 // the error is reported. | 708 // the error is reported. |
| 706 Log(LOG_FATAL, "reap logs"); | 709 Log(LOG_FATAL, "reap logs"); |
| 707 if (NULL == reverse_service_) { | 710 if (NULL == reverse_service_) { |
| 708 // No crash detector thread. | 711 // No crash detector thread. |
| 709 NaClLog(LOG_ERROR, "scheduling to get crash log\n"); | 712 NaClLog(LOG_ERROR, "scheduling to get crash log\n"); |
| 710 pp::Module::Get()->core()->CallOnMainThread(0, crash_cb, PP_OK); | 713 // Invoking rev_interface's method is workaround to avoid crash_cb |
| 714 // gets called twice or more. We should clean this up later. |
| 715 rev_interface_->ReportCrash(); |
| 711 NaClLog(LOG_ERROR, "should fire soon\n"); | 716 NaClLog(LOG_ERROR, "should fire soon\n"); |
| 712 } else { | 717 } else { |
| 713 NaClLog(LOG_ERROR, "Reverse service thread will pick up crash log\n"); | 718 NaClLog(LOG_ERROR, "Reverse service thread will pick up crash log\n"); |
| 714 } | 719 } |
| 715 pp::Module::Get()->core()->CallOnMainThread(0, started_cb, PP_ERROR_FAILED); | |
| 716 return; | |
| 717 } | 720 } |
| 718 | 721 pp::Module::Get()->core()->CallOnMainThread( |
| 719 NaClLog(4, "ServiceRuntime::LoadNexeAndStart (return 1)\n"); | 722 0, callback, ok ? PP_OK : PP_ERROR_FAILED); |
| 720 pp::Module::Get()->core()->CallOnMainThread(0, started_cb, PP_OK); | |
| 721 } | 723 } |
| 722 | 724 |
| 723 SrpcClient* ServiceRuntime::SetupAppChannel() { | 725 SrpcClient* ServiceRuntime::SetupAppChannel() { |
| 724 NaClLog(4, "ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", | 726 NaClLog(4, "ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", |
| 725 reinterpret_cast<void*>(subprocess_.get())); | 727 reinterpret_cast<void*>(subprocess_.get())); |
| 726 nacl::DescWrapper* connect_desc = subprocess_->socket_addr()->Connect(); | 728 nacl::DescWrapper* connect_desc = subprocess_->socket_addr()->Connect(); |
| 727 if (NULL == connect_desc) { | 729 if (NULL == connect_desc) { |
| 728 NaClLog(LOG_ERROR, "ServiceRuntime::SetupAppChannel (connect failed)\n"); | 730 NaClLog(LOG_ERROR, "ServiceRuntime::SetupAppChannel (connect failed)\n"); |
| 729 return NULL; | 731 return NULL; |
| 730 } else { | 732 } else { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 799 |
| 798 nacl::string ServiceRuntime::GetCrashLogOutput() { | 800 nacl::string ServiceRuntime::GetCrashLogOutput() { |
| 799 if (NULL != subprocess_.get()) { | 801 if (NULL != subprocess_.get()) { |
| 800 return subprocess_->GetCrashLogOutput(); | 802 return subprocess_->GetCrashLogOutput(); |
| 801 } else { | 803 } else { |
| 802 return std::string(); | 804 return std::string(); |
| 803 } | 805 } |
| 804 } | 806 } |
| 805 | 807 |
| 806 } // namespace plugin | 808 } // namespace plugin |
| OLD | NEW |