| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "native_client/src/trusted/plugin/pnacl_translate_thread.h" | 5 #include "native_client/src/trusted/plugin/pnacl_translate_thread.h" |
| 6 | 6 |
| 7 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 7 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 8 #include "native_client/src/trusted/plugin/plugin.h" | 8 #include "native_client/src/trusted/plugin/plugin.h" |
| 9 #include "native_client/src/trusted/plugin/pnacl_resources.h" | 9 #include "native_client/src/trusted/plugin/pnacl_resources.h" |
| 10 #include "native_client/src/trusted/plugin/srpc_params.h" | 10 #include "native_client/src/trusted/plugin/srpc_params.h" |
| 11 #include "native_client/src/trusted/plugin/temporary_file.h" | 11 #include "native_client/src/trusted/plugin/temporary_file.h" |
| 12 #include "native_client/src/trusted/plugin/utility.h" | 12 #include "native_client/src/trusted/plugin/utility.h" |
| 13 | 13 |
| 14 namespace plugin { | 14 namespace plugin { |
| 15 | 15 |
| 16 PnaclTranslateThread::PnaclTranslateThread() : subprocesses_should_die_(false), | 16 PnaclTranslateThread::PnaclTranslateThread() : subprocesses_should_die_(false), |
| 17 current_rev_interface_(NULL), |
| 17 manifest_(NULL), | 18 manifest_(NULL), |
| 18 ld_manifest_(NULL), | 19 ld_manifest_(NULL), |
| 19 obj_file_(NULL), | 20 obj_file_(NULL), |
| 20 nexe_file_(NULL), | 21 nexe_file_(NULL), |
| 21 coordinator_error_info_(NULL), | 22 coordinator_error_info_(NULL), |
| 22 resources_(NULL), | 23 resources_(NULL), |
| 23 plugin_(NULL) { | 24 plugin_(NULL) { |
| 24 NaClXMutexCtor(&subprocess_mu_); | 25 NaClXMutexCtor(&subprocess_mu_); |
| 25 } | 26 } |
| 26 | 27 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 if (!obj_file_->Reset()) { | 67 if (!obj_file_->Reset()) { |
| 67 TranslateFailed("Link process could not reset object file"); | 68 TranslateFailed("Link process could not reset object file"); |
| 68 return false; | 69 return false; |
| 69 } | 70 } |
| 70 nacl::DescWrapper* ld_in_file = obj_file_->get_wrapper(); | 71 nacl::DescWrapper* ld_in_file = obj_file_->get_wrapper(); |
| 71 nacl::DescWrapper* ld_out_file = nexe_file_->write_wrapper(); | 72 nacl::DescWrapper* ld_out_file = nexe_file_->write_wrapper(); |
| 72 PluginReverseInterface* ld_reverse = | 73 PluginReverseInterface* ld_reverse = |
| 73 ld_subprocess->service_runtime()->rev_interface(); | 74 ld_subprocess->service_runtime()->rev_interface(); |
| 74 ld_reverse->AddQuotaManagedFile(nexe_file_->identifier(), | 75 ld_reverse->AddQuotaManagedFile(nexe_file_->identifier(), |
| 75 nexe_file_->write_file_io()); | 76 nexe_file_->write_file_io()); |
| 77 RegisterReverseInterface(ld_reverse); |
| 76 if (!ld_subprocess->InvokeSrpcMethod("RunWithDefaultCommandLine", | 78 if (!ld_subprocess->InvokeSrpcMethod("RunWithDefaultCommandLine", |
| 77 "hhiss", | 79 "hhiss", |
| 78 ¶ms, | 80 ¶ms, |
| 79 ld_in_file->desc(), | 81 ld_in_file->desc(), |
| 80 ld_out_file->desc(), | 82 ld_out_file->desc(), |
| 81 is_shared_library, | 83 is_shared_library, |
| 82 soname.c_str(), | 84 soname.c_str(), |
| 83 lib_dependencies.c_str())) { | 85 lib_dependencies.c_str())) { |
| 84 TranslateFailed("link failed."); | 86 TranslateFailed("link failed."); |
| 85 return false; | 87 return false; |
| 86 } | 88 } |
| 87 PLUGIN_PRINTF(("PnaclCoordinator: link (translator=%p) succeeded\n", | 89 PLUGIN_PRINTF(("PnaclCoordinator: link (translator=%p) succeeded\n", |
| 88 this)); | 90 this)); |
| 89 // Shut down the ld subprocess. | 91 // Shut down the ld subprocess. |
| 92 RegisterReverseInterface(NULL); |
| 90 ld_subprocess.reset(NULL); | 93 ld_subprocess.reset(NULL); |
| 91 if (SubprocessesShouldDie()) { | 94 if (SubprocessesShouldDie()) { |
| 92 TranslateFailed("stopped by coordinator."); | 95 TranslateFailed("stopped by coordinator."); |
| 93 return false; | 96 return false; |
| 94 } | 97 } |
| 95 return true; | 98 return true; |
| 96 } | 99 } |
| 97 | 100 |
| 98 void PnaclTranslateThread::TranslateFailed(const nacl::string& error_string) { | 101 void PnaclTranslateThread::TranslateFailed(const nacl::string& error_string) { |
| 99 PLUGIN_PRINTF(("PnaclTranslateThread::TranslateFailed (error_string='%s')\n", | 102 PLUGIN_PRINTF(("PnaclTranslateThread::TranslateFailed (error_string='%s')\n", |
| 100 error_string.c_str())); | 103 error_string.c_str())); |
| 101 pp::Core* core = pp::Module::Get()->core(); | 104 pp::Core* core = pp::Module::Get()->core(); |
| 102 if (coordinator_error_info_->message().empty()) { | 105 if (coordinator_error_info_->message().empty()) { |
| 103 // Only use our message if one hasn't already been set by the coordinator | 106 // Only use our message if one hasn't already been set by the coordinator |
| 104 // (e.g. pexe load failed). | 107 // (e.g. pexe load failed). |
| 105 coordinator_error_info_->SetReport(ERROR_UNKNOWN, | 108 coordinator_error_info_->SetReport(ERROR_UNKNOWN, |
| 106 nacl::string("PnaclCoordinator: ") + | 109 nacl::string("PnaclCoordinator: ") + |
| 107 error_string); | 110 error_string); |
| 108 } | 111 } |
| 109 core->CallOnMainThread(0, report_translate_finished_, PP_ERROR_FAILED); | 112 core->CallOnMainThread(0, report_translate_finished_, PP_ERROR_FAILED); |
| 110 } | 113 } |
| 111 | 114 |
| 115 // This synchronization method (using the pointer directly in the |
| 116 // translation thread, setting a copy here, and calling shutdown on the |
| 117 // main thread) is safe only because only the translation thread sets |
| 118 // the copy, and the shutdown method is thread-safe. This method must be |
| 119 // called on the translation thread before any RPCs are called, and called |
| 120 // again with NULL before the object is destroyed. |
| 121 void PnaclTranslateThread::RegisterReverseInterface( |
| 122 PluginReverseInterface *interface) { |
| 123 nacl::MutexLocker ml(&subprocess_mu_); |
| 124 current_rev_interface_ = interface; |
| 125 } |
| 126 |
| 127 |
| 112 bool PnaclTranslateThread::SubprocessesShouldDie() { | 128 bool PnaclTranslateThread::SubprocessesShouldDie() { |
| 113 nacl::MutexLocker ml(&subprocess_mu_); | 129 nacl::MutexLocker ml(&subprocess_mu_); |
| 114 return subprocesses_should_die_; | 130 return subprocesses_should_die_; |
| 115 } | 131 } |
| 116 | 132 |
| 117 void PnaclTranslateThread::SetSubprocessesShouldDie() { | 133 void PnaclTranslateThread::SetSubprocessesShouldDie() { |
| 118 PLUGIN_PRINTF(("PnaclTranslateThread::SetSubprocessesShouldDie\n")); | 134 PLUGIN_PRINTF(("PnaclTranslateThread::SetSubprocessesShouldDie\n")); |
| 119 nacl::MutexLocker ml(&subprocess_mu_); | 135 nacl::MutexLocker ml(&subprocess_mu_); |
| 120 subprocesses_should_die_ = true; | 136 subprocesses_should_die_ = true; |
| 137 if (current_rev_interface_) { |
| 138 current_rev_interface_->ShutDown(); |
| 139 current_rev_interface_ = NULL; |
| 140 } |
| 121 } | 141 } |
| 122 | 142 |
| 123 PnaclTranslateThread::~PnaclTranslateThread() { | 143 PnaclTranslateThread::~PnaclTranslateThread() { |
| 124 PLUGIN_PRINTF(("~PnaclTranslateThread (translate_thread=%p)\n", | |
| 125 translate_thread_.get())); | |
| 126 if (translate_thread_ != NULL) { | |
| 127 SetSubprocessesShouldDie(); | |
| 128 NaClThreadJoin(translate_thread_.get()); | |
| 129 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); | |
| 130 } | |
| 131 NaClMutexDtor(&subprocess_mu_); | 144 NaClMutexDtor(&subprocess_mu_); |
| 132 } | 145 } |
| 133 | 146 |
| 134 } // namespace plugin | 147 } // namespace plugin |
| OLD | NEW |