| 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_streaming_translate_thread.h" | 5 #include "native_client/src/trusted/plugin/pnacl_streaming_translate_thread.h" |
| 6 | 6 |
| 7 #include "native_client/src/include/nacl_scoped_ptr.h" | 7 #include "native_client/src/include/nacl_scoped_ptr.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 | 12 |
| 13 namespace plugin { | 13 namespace plugin { |
| 14 | 14 |
| 15 PnaclStreamingTranslateThread::PnaclStreamingTranslateThread() : done_(false) { | 15 PnaclStreamingTranslateThread::PnaclStreamingTranslateThread() : done_(false) { |
| 16 NaClXMutexCtor(&cond_mu_); | 16 NaClXMutexCtor(&cond_mu_); |
| 17 NaClXCondVarCtor(&buffer_cond_); | 17 NaClXCondVarCtor(&buffer_cond_); |
| 18 } | 18 } |
| 19 | 19 |
| 20 PnaclStreamingTranslateThread::~PnaclStreamingTranslateThread() {} | 20 PnaclStreamingTranslateThread::~PnaclStreamingTranslateThread() { |
| 21 PLUGIN_PRINTF(("~PnaclTranslateThread (translate_thread=%p)\n", this)); |
| 22 SetSubprocessesShouldDie(); |
| 23 NaClThreadJoin(translate_thread_.get()); |
| 24 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); |
| 25 } |
| 21 | 26 |
| 22 void PnaclStreamingTranslateThread::RunTranslate( | 27 void PnaclStreamingTranslateThread::RunTranslate( |
| 23 const pp::CompletionCallback& finish_callback, | 28 const pp::CompletionCallback& finish_callback, |
| 24 const Manifest* manifest, | 29 const Manifest* manifest, |
| 25 const Manifest* ld_manifest, | 30 const Manifest* ld_manifest, |
| 26 TempFile* obj_file, | 31 TempFile* obj_file, |
| 27 LocalTempFile* nexe_file, | 32 LocalTempFile* nexe_file, |
| 28 ErrorInfo* error_info, | 33 ErrorInfo* error_info, |
| 29 PnaclResources* resources, | 34 PnaclResources* resources, |
| 30 Plugin* plugin) { | 35 Plugin* plugin) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 TranslateFailed("Compile process could not be created: " + | 101 TranslateFailed("Compile process could not be created: " + |
| 97 error_info.message()); | 102 error_info.message()); |
| 98 return; | 103 return; |
| 99 } | 104 } |
| 100 // Run LLC. | 105 // Run LLC. |
| 101 SrpcParams params; | 106 SrpcParams params; |
| 102 nacl::DescWrapper* llc_out_file = obj_file_->get_wrapper(); | 107 nacl::DescWrapper* llc_out_file = obj_file_->get_wrapper(); |
| 103 PluginReverseInterface* llc_reverse = | 108 PluginReverseInterface* llc_reverse = |
| 104 llc_subprocess->service_runtime()->rev_interface(); | 109 llc_subprocess->service_runtime()->rev_interface(); |
| 105 llc_reverse->AddTempQuotaManagedFile(obj_file_->identifier()); | 110 llc_reverse->AddTempQuotaManagedFile(obj_file_->identifier()); |
| 111 RegisterReverseInterface(llc_reverse); |
| 106 | 112 |
| 107 if (!llc_subprocess->InvokeSrpcMethod("StreamInit", | 113 if (!llc_subprocess->InvokeSrpcMethod("StreamInit", |
| 108 "h", | 114 "h", |
| 109 ¶ms, | 115 ¶ms, |
| 110 llc_out_file->desc())) { | 116 llc_out_file->desc())) { |
| 111 // StreamInit returns an error message if the RPC fails. | 117 // StreamInit returns an error message if the RPC fails. |
| 112 TranslateFailed(nacl::string("Stream init failed: ") + | 118 TranslateFailed(nacl::string("Stream init failed: ") + |
| 113 nacl::string(params.outs()[0]->arrays.str)); | 119 nacl::string(params.outs()[0]->arrays.str)); |
| 114 return; | 120 return; |
| 115 } | 121 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 135 ¶ms, | 141 ¶ms, |
| 136 &data[0], | 142 &data[0], |
| 137 data.size())) { | 143 data.size())) { |
| 138 TranslateFailed("Compile stream chunk failed."); | 144 TranslateFailed("Compile stream chunk failed."); |
| 139 return; | 145 return; |
| 140 } | 146 } |
| 141 PLUGIN_PRINTF(("StreamChunk Successful\n")); | 147 PLUGIN_PRINTF(("StreamChunk Successful\n")); |
| 142 } else { | 148 } else { |
| 143 NaClXMutexUnlock(&cond_mu_); | 149 NaClXMutexUnlock(&cond_mu_); |
| 144 } | 150 } |
| 151 if (SubprocessesShouldDie()) { |
| 152 TranslateFailed("Stopped by coordinator."); |
| 153 return; |
| 154 } |
| 145 } | 155 } |
| 146 PLUGIN_PRINTF(("PnaclTranslateThread done with chunks\n")); | 156 PLUGIN_PRINTF(("PnaclTranslateThread done with chunks\n")); |
| 147 // Finish llc. | 157 // Finish llc. |
| 148 if(!llc_subprocess->InvokeSrpcMethod("StreamEnd", | 158 if(!llc_subprocess->InvokeSrpcMethod("StreamEnd", |
| 149 "", | 159 "", |
| 150 ¶ms)) { | 160 ¶ms)) { |
| 151 PLUGIN_PRINTF(("PnaclTranslateThread StreamEnd failed\n")); | 161 PLUGIN_PRINTF(("PnaclTranslateThread StreamEnd failed\n")); |
| 152 TranslateFailed(params.outs()[3]->arrays.str); | 162 TranslateFailed(params.outs()[3]->arrays.str); |
| 153 return; | 163 return; |
| 154 } | 164 } |
| 155 // LLC returns values that are used to determine how linking is done. | 165 // LLC returns values that are used to determine how linking is done. |
| 156 int is_shared_library = (params.outs()[0]->u.ival != 0); | 166 int is_shared_library = (params.outs()[0]->u.ival != 0); |
| 157 nacl::string soname = params.outs()[1]->arrays.str; | 167 nacl::string soname = params.outs()[1]->arrays.str; |
| 158 nacl::string lib_dependencies = params.outs()[2]->arrays.str; | 168 nacl::string lib_dependencies = params.outs()[2]->arrays.str; |
| 159 PLUGIN_PRINTF(("PnaclCoordinator: compile (translator=%p) succeeded" | 169 PLUGIN_PRINTF(("PnaclCoordinator: compile (translator=%p) succeeded" |
| 160 " is_shared_library=%d, soname='%s', lib_dependencies='%s')\n", | 170 " is_shared_library=%d, soname='%s', lib_dependencies='%s')\n", |
| 161 this, is_shared_library, soname.c_str(), | 171 this, is_shared_library, soname.c_str(), |
| 162 lib_dependencies.c_str())); | 172 lib_dependencies.c_str())); |
| 163 | 173 |
| 164 // Shut down the llc subprocess. | 174 // Shut down the llc subprocess. |
| 175 RegisterReverseInterface(NULL); |
| 165 llc_subprocess.reset(NULL); | 176 llc_subprocess.reset(NULL); |
| 166 if (SubprocessesShouldDie()) { | 177 if (SubprocessesShouldDie()) { |
| 167 TranslateFailed("stopped by coordinator."); | 178 TranslateFailed("stopped by coordinator."); |
| 168 return; | 179 return; |
| 169 } | 180 } |
| 170 | 181 |
| 171 if(!RunLdSubprocess(is_shared_library, soname, lib_dependencies)) { | 182 if(!RunLdSubprocess(is_shared_library, soname, lib_dependencies)) { |
| 172 return; | 183 return; |
| 173 } | 184 } |
| 174 pp::Core* core = pp::Module::Get()->core(); | 185 pp::Core* core = pp::Module::Get()->core(); |
| 175 core->CallOnMainThread(0, report_translate_finished_, PP_OK); | 186 core->CallOnMainThread(0, report_translate_finished_, PP_OK); |
| 176 } | 187 } |
| 177 | 188 |
| 178 void PnaclStreamingTranslateThread::SetSubprocessesShouldDie() { | 189 void PnaclStreamingTranslateThread::SetSubprocessesShouldDie() { |
| 179 PnaclTranslateThread::SetSubprocessesShouldDie(); | 190 PnaclTranslateThread::SetSubprocessesShouldDie(); |
| 180 nacl::MutexLocker ml(&cond_mu_); | 191 nacl::MutexLocker ml(&cond_mu_); |
| 181 done_ = true; | 192 done_ = true; |
| 182 NaClXCondVarSignal(&buffer_cond_); | 193 NaClXCondVarSignal(&buffer_cond_); |
| 183 } | 194 } |
| 184 | 195 |
| 185 } // namespace plugin | 196 } // namespace plugin |
| OLD | NEW |