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 "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h" | 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_translate_thread.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
10 #include "ppapi/cpp/var.h" | 10 #include "ppapi/cpp/var.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 data_buffers_.push_back(std::vector<char>()); | 139 data_buffers_.push_back(std::vector<char>()); |
140 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data. | 140 bytes->swap(data_buffers_.back()); // Avoid copying the buffer data. |
141 | 141 |
142 NaClXCondVarSignal(&buffer_cond_); | 142 NaClXCondVarSignal(&buffer_cond_); |
143 NaClXMutexUnlock(&cond_mu_); | 143 NaClXMutexUnlock(&cond_mu_); |
144 | 144 |
145 // Ensure the buffer we send back to the coordinator is the expected size | 145 // Ensure the buffer we send back to the coordinator is the expected size |
146 bytes->resize(buffer_size); | 146 bytes->resize(buffer_size); |
147 } | 147 } |
148 | 148 |
149 NaClSubprocess* PnaclTranslateThread::StartSubprocess( | |
150 const nacl::string& url_for_nexe, | |
151 int32_t manifest_id, | |
152 ErrorInfo* error_info) { | |
153 PLUGIN_PRINTF(("PnaclTranslateThread::StartSubprocess (url_for_nexe=%s)\n", | |
154 url_for_nexe.c_str())); | |
155 nacl::DescWrapper* wrapper = resources_->WrapperForUrl(url_for_nexe); | |
156 // Supply a URL for the translator components, different from the app URL, | |
157 // so that NaCl GDB can filter-out the translator processes (and not debug | |
158 // the translator itself). Must have a full URL with schema, otherwise the | |
159 // string gets silently dropped by GURL. | |
160 nacl::string full_url = resources_->GetFullUrl( | |
161 url_for_nexe, plugin_->nacl_interface()->GetSandboxArch()); | |
162 nacl::scoped_ptr<NaClSubprocess> subprocess(plugin_->LoadHelperNaClModule( | |
163 full_url, wrapper, manifest_id, error_info)); | |
164 if (subprocess.get() == NULL) { | |
165 PLUGIN_PRINTF(( | |
166 "PnaclTranslateThread::StartSubprocess: subprocess creation failed\n")); | |
167 return NULL; | |
168 } | |
169 return subprocess.release(); | |
170 } | |
171 | |
172 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { | 149 void WINAPI PnaclTranslateThread::DoTranslateThread(void* arg) { |
173 PnaclTranslateThread* translator = | 150 PnaclTranslateThread* translator = |
174 reinterpret_cast<PnaclTranslateThread*>(arg); | 151 reinterpret_cast<PnaclTranslateThread*>(arg); |
175 translator->DoTranslate(); | 152 translator->DoTranslate(); |
176 } | 153 } |
177 | 154 |
178 void PnaclTranslateThread::DoTranslate() { | 155 void PnaclTranslateThread::DoTranslate() { |
179 ErrorInfo error_info; | 156 ErrorInfo error_info; |
180 SrpcParams params; | 157 SrpcParams params; |
181 std::vector<nacl::DescWrapper*> llc_out_files; | 158 std::vector<nacl::DescWrapper*> llc_out_files; |
182 size_t i; | 159 size_t i; |
183 for (i = 0; i < obj_files_->size(); i++) { | 160 for (i = 0; i < obj_files_->size(); i++) |
184 llc_out_files.push_back((*obj_files_)[i]->write_wrapper()); | 161 llc_out_files.push_back((*obj_files_)[i]->write_wrapper()); |
185 } | 162 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) |
186 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) { | |
187 llc_out_files.push_back(invalid_desc_wrapper_); | 163 llc_out_files.push_back(invalid_desc_wrapper_); |
188 } | |
189 | 164 |
190 pp::Core* core = pp::Module::Get()->core(); | 165 pp::Core* core = pp::Module::Get()->core(); |
191 { | 166 { |
192 nacl::MutexLocker ml(&subprocess_mu_); | 167 nacl::MutexLocker ml(&subprocess_mu_); |
193 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds(); | 168 int64_t llc_start_time = NaClGetTimeOfDayMicroseconds(); |
194 llc_subprocess_.reset( | 169 PP_FileHandle llc_file_handle = resources_->TakeLlcFileHandle(); |
195 StartSubprocess(resources_->GetLlcUrl(), manifest_id_, &error_info)); | 170 |
196 if (llc_subprocess_ == NULL) { | 171 // On success, ownership of llc_file_handle is transferred. |
| 172 llc_subprocess_.reset(plugin_->LoadHelperNaClModule( |
| 173 resources_->GetLlcUrl(), llc_file_handle, manifest_id_, &error_info)); |
| 174 if (llc_subprocess_.get() == NULL) { |
| 175 if (llc_file_handle != PP_kInvalidFileHandle) |
| 176 CloseFileHandle(llc_file_handle); |
197 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP, | 177 TranslateFailed(PP_NACL_ERROR_PNACL_LLC_SETUP, |
198 "Compile process could not be created: " + | 178 "Compile process could not be created: " + |
199 error_info.message()); | 179 error_info.message()); |
200 return; | 180 return; |
201 } | 181 } |
| 182 |
202 llc_subprocess_active_ = true; | 183 llc_subprocess_active_ = true; |
203 core->CallOnMainThread(0, | 184 core->CallOnMainThread(0, |
204 coordinator_->GetUMATimeCallback( | 185 coordinator_->GetUMATimeCallback( |
205 "NaCl.Perf.PNaClLoadTime.LoadCompiler", | 186 "NaCl.Perf.PNaClLoadTime.LoadCompiler", |
206 NaClGetTimeOfDayMicroseconds() - llc_start_time), | 187 NaClGetTimeOfDayMicroseconds() - llc_start_time), |
207 PP_OK); | 188 PP_OK); |
208 // Run LLC. | 189 // Run LLC. |
209 PluginReverseInterface* llc_reverse = | 190 PluginReverseInterface* llc_reverse = |
210 llc_subprocess_->service_runtime()->rev_interface(); | 191 llc_subprocess_->service_runtime()->rev_interface(); |
211 for (size_t i = 0; i < obj_files_->size(); i++) { | 192 for (size_t i = 0; i < obj_files_->size(); i++) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 size_t i; | 327 size_t i; |
347 for (i = 0; i < obj_files_->size(); i++) { | 328 for (i = 0; i < obj_files_->size(); i++) { |
348 // Reset object file for reading first. | 329 // Reset object file for reading first. |
349 if (!(*obj_files_)[i]->Reset()) { | 330 if (!(*obj_files_)[i]->Reset()) { |
350 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, | 331 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, |
351 "Link process could not reset object file"); | 332 "Link process could not reset object file"); |
352 return false; | 333 return false; |
353 } | 334 } |
354 ld_in_files.push_back((*obj_files_)[i]->read_wrapper()); | 335 ld_in_files.push_back((*obj_files_)[i]->read_wrapper()); |
355 } | 336 } |
356 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) { | 337 for (; i < PnaclCoordinator::kMaxTranslatorObjectFiles; i++) |
357 ld_in_files.push_back(invalid_desc_wrapper_); | 338 ld_in_files.push_back(invalid_desc_wrapper_); |
358 } | |
359 | 339 |
360 nacl::DescWrapper* ld_out_file = nexe_file_->write_wrapper(); | 340 nacl::DescWrapper* ld_out_file = nexe_file_->write_wrapper(); |
361 pp::Core* core = pp::Module::Get()->core(); | 341 pp::Core* core = pp::Module::Get()->core(); |
362 { | 342 { |
363 // Create LD process | 343 // Create LD process |
364 nacl::MutexLocker ml(&subprocess_mu_); | 344 nacl::MutexLocker ml(&subprocess_mu_); |
365 int64_t ld_start_time = NaClGetTimeOfDayMicroseconds(); | 345 int64_t ld_start_time = NaClGetTimeOfDayMicroseconds(); |
366 ld_subprocess_.reset( | 346 PP_FileHandle ld_file_handle = resources_->TakeLdFileHandle(); |
367 StartSubprocess(resources_->GetLdUrl(), manifest_id_, &error_info)); | 347 |
| 348 // On success, ownership of ld_file_handle is transferred. |
| 349 ld_subprocess_.reset(plugin_->LoadHelperNaClModule( |
| 350 resources_->GetLdUrl(), ld_file_handle, manifest_id_, &error_info)); |
368 if (ld_subprocess_ == NULL) { | 351 if (ld_subprocess_ == NULL) { |
| 352 if (ld_file_handle != PP_kInvalidFileHandle) |
| 353 CloseFileHandle(ld_file_handle); |
369 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, | 354 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, |
370 "Link process could not be created: " + | 355 "Link process could not be created: " + |
371 error_info.message()); | 356 error_info.message()); |
372 return false; | 357 return false; |
373 } | 358 } |
374 ld_subprocess_active_ = true; | 359 ld_subprocess_active_ = true; |
375 core->CallOnMainThread(0, | 360 core->CallOnMainThread(0, |
376 coordinator_->GetUMATimeCallback( | 361 coordinator_->GetUMATimeCallback( |
377 "NaCl.Perf.PNaClLoadTime.LoadLinker", | 362 "NaCl.Perf.PNaClLoadTime.LoadLinker", |
378 NaClGetTimeOfDayMicroseconds() - ld_start_time), | 363 NaClGetTimeOfDayMicroseconds() - ld_start_time), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 AbortSubprocesses(); | 451 AbortSubprocesses(); |
467 if (translate_thread_ != NULL) | 452 if (translate_thread_ != NULL) |
468 NaClThreadJoin(translate_thread_.get()); | 453 NaClThreadJoin(translate_thread_.get()); |
469 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); | 454 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); |
470 NaClCondVarDtor(&buffer_cond_); | 455 NaClCondVarDtor(&buffer_cond_); |
471 NaClMutexDtor(&cond_mu_); | 456 NaClMutexDtor(&cond_mu_); |
472 NaClMutexDtor(&subprocess_mu_); | 457 NaClMutexDtor(&subprocess_mu_); |
473 } | 458 } |
474 | 459 |
475 } // namespace plugin | 460 } // namespace plugin |
OLD | NEW |