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 "components/nacl/renderer/plugin/pnacl_translate_thread.h" | 5 #include "components/nacl/renderer/plugin/pnacl_translate_thread.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <iterator> | 9 #include <iterator> |
10 #include <sstream> | 10 #include <sstream> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "components/nacl/renderer/plugin/plugin.h" | 13 #include "components/nacl/renderer/plugin/plugin.h" |
14 #include "components/nacl/renderer/plugin/plugin_error.h" | 14 #include "components/nacl/renderer/plugin/plugin_error.h" |
15 #include "components/nacl/renderer/plugin/temporary_file.h" | |
16 #include "components/nacl/renderer/plugin/utility.h" | 15 #include "components/nacl/renderer/plugin/utility.h" |
17 #include "content/public/common/sandbox_init.h" | 16 #include "content/public/common/sandbox_init.h" |
18 #include "native_client/src/shared/platform/nacl_sync_raii.h" | 17 #include "native_client/src/shared/platform/nacl_sync_raii.h" |
19 #include "ppapi/c/ppb_file_io.h" | 18 #include "ppapi/c/ppb_file_io.h" |
20 #include "ppapi/cpp/var.h" | 19 #include "ppapi/cpp/var.h" |
21 #include "ppapi/proxy/ppapi_messages.h" | 20 #include "ppapi/proxy/ppapi_messages.h" |
22 | 21 |
23 namespace plugin { | 22 namespace plugin { |
24 namespace { | 23 namespace { |
25 | 24 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ld_channel_peer_pid_(base::kNullProcessId) { | 75 ld_channel_peer_pid_(base::kNullProcessId) { |
77 NaClXMutexCtor(&subprocess_mu_); | 76 NaClXMutexCtor(&subprocess_mu_); |
78 NaClXMutexCtor(&cond_mu_); | 77 NaClXMutexCtor(&cond_mu_); |
79 NaClXCondVarCtor(&buffer_cond_); | 78 NaClXCondVarCtor(&buffer_cond_); |
80 } | 79 } |
81 | 80 |
82 void PnaclTranslateThread::SetupState( | 81 void PnaclTranslateThread::SetupState( |
83 const pp::CompletionCallback& finish_callback, | 82 const pp::CompletionCallback& finish_callback, |
84 NaClSubprocess* compiler_subprocess, | 83 NaClSubprocess* compiler_subprocess, |
85 NaClSubprocess* ld_subprocess, | 84 NaClSubprocess* ld_subprocess, |
86 const std::vector<TempFile*>* obj_files, | 85 std::vector<base::File>* obj_files, |
87 int num_threads, | 86 int num_threads, |
88 TempFile* nexe_file, | 87 base::File* nexe_file, |
89 ErrorInfo* error_info, | 88 ErrorInfo* error_info, |
90 PP_PNaClOptions* pnacl_options, | 89 PP_PNaClOptions* pnacl_options, |
91 const std::string& architecture_attributes, | 90 const std::string& architecture_attributes, |
92 PnaclCoordinator* coordinator) { | 91 PnaclCoordinator* coordinator) { |
93 PLUGIN_PRINTF(("PnaclTranslateThread::SetupState)\n")); | 92 PLUGIN_PRINTF(("PnaclTranslateThread::SetupState)\n")); |
94 compiler_subprocess_ = compiler_subprocess; | 93 compiler_subprocess_ = compiler_subprocess; |
95 ld_subprocess_ = ld_subprocess; | 94 ld_subprocess_ = ld_subprocess; |
96 obj_files_ = obj_files; | 95 obj_files_ = obj_files; |
97 num_threads_ = num_threads; | 96 num_threads_ = num_threads; |
98 nexe_file_ = nexe_file; | 97 nexe_file_ = nexe_file; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 188 } |
190 | 189 |
191 void PnaclTranslateThread::EndStream() { | 190 void PnaclTranslateThread::EndStream() { |
192 NaClXMutexLock(&cond_mu_); | 191 NaClXMutexLock(&cond_mu_); |
193 done_ = true; | 192 done_ = true; |
194 NaClXCondVarSignal(&buffer_cond_); | 193 NaClXCondVarSignal(&buffer_cond_); |
195 NaClXMutexUnlock(&cond_mu_); | 194 NaClXMutexUnlock(&cond_mu_); |
196 } | 195 } |
197 | 196 |
198 ppapi::proxy::SerializedHandle PnaclTranslateThread::GetHandleForSubprocess( | 197 ppapi::proxy::SerializedHandle PnaclTranslateThread::GetHandleForSubprocess( |
199 TempFile* file, int32_t open_flags, base::ProcessId peer_pid) { | 198 base::File* file, int32_t open_flags, base::ProcessId peer_pid) { |
200 IPC::PlatformFileForTransit file_for_transit; | 199 IPC::PlatformFileForTransit file_for_transit; |
201 | 200 |
| 201 DCHECK(file->IsValid()); |
202 #if defined(OS_WIN) | 202 #if defined(OS_WIN) |
203 if (!content::BrokerDuplicateHandle( | 203 if (!content::BrokerDuplicateHandle( |
204 file->GetFileHandle(), | 204 file->GetPlatformFile(), |
205 peer_pid, | 205 peer_pid, |
206 &file_for_transit, | 206 &file_for_transit, |
207 0, // desired_access is 0 since we're using DUPLICATE_SAME_ACCESS. | 207 0, // desired_access is 0 since we're using DUPLICATE_SAME_ACCESS. |
208 DUPLICATE_SAME_ACCESS)) { | 208 DUPLICATE_SAME_ACCESS)) { |
209 return ppapi::proxy::SerializedHandle(); | 209 return ppapi::proxy::SerializedHandle(); |
210 } | 210 } |
211 #else | 211 #else |
212 file_for_transit = base::FileDescriptor(dup(file->GetFileHandle()), true); | 212 file_for_transit = base::FileDescriptor(dup(file->GetPlatformFile()), true); |
213 #endif | 213 #endif |
214 | 214 |
215 // Using 0 disables any use of quota enforcement for this file handle. | 215 // Using 0 disables any use of quota enforcement for this file handle. |
216 PP_Resource file_io = 0; | 216 PP_Resource file_io = 0; |
217 | 217 |
218 ppapi::proxy::SerializedHandle handle; | 218 ppapi::proxy::SerializedHandle handle; |
219 handle.set_file_handle(file_for_transit, open_flags, file_io); | 219 handle.set_file_handle(file_for_transit, open_flags, file_io); |
220 return handle; | 220 return handle; |
221 } | 221 } |
222 | 222 |
223 void WINAPI PnaclTranslateThread::DoCompileThread(void* arg) { | 223 void WINAPI PnaclTranslateThread::DoCompileThread(void* arg) { |
224 PnaclTranslateThread* translator = | 224 PnaclTranslateThread* translator = |
225 reinterpret_cast<PnaclTranslateThread*>(arg); | 225 reinterpret_cast<PnaclTranslateThread*>(arg); |
226 translator->DoCompile(); | 226 translator->DoCompile(); |
227 } | 227 } |
228 | 228 |
229 void PnaclTranslateThread::DoCompile() { | 229 void PnaclTranslateThread::DoCompile() { |
230 { | 230 { |
231 nacl::MutexLocker ml(&subprocess_mu_); | 231 nacl::MutexLocker ml(&subprocess_mu_); |
232 // If the main thread asked us to exit in between starting the thread | 232 // If the main thread asked us to exit in between starting the thread |
233 // and now, just leave now. | 233 // and now, just leave now. |
234 if (!compiler_subprocess_active_) | 234 if (!compiler_subprocess_active_) |
235 return; | 235 return; |
236 } | 236 } |
237 | 237 |
238 std::vector<ppapi::proxy::SerializedHandle> compiler_output_files; | 238 std::vector<ppapi::proxy::SerializedHandle> compiler_output_files; |
239 for (TempFile* obj_file : *obj_files_) { | 239 for (base::File& obj_file : *obj_files_) { |
240 compiler_output_files.push_back( | 240 compiler_output_files.push_back( |
241 GetHandleForSubprocess(obj_file, PP_FILEOPENFLAG_WRITE, | 241 GetHandleForSubprocess(&obj_file, PP_FILEOPENFLAG_WRITE, |
242 compiler_channel_peer_pid_)); | 242 compiler_channel_peer_pid_)); |
243 } | 243 } |
244 | 244 |
245 PLUGIN_PRINTF(("DoCompile using subzero: %d\n", pnacl_options_->use_subzero)); | 245 PLUGIN_PRINTF(("DoCompile using subzero: %d\n", pnacl_options_->use_subzero)); |
246 | 246 |
247 pp::Core* core = pp::Module::Get()->core(); | 247 pp::Core* core = pp::Module::Get()->core(); |
248 int64_t do_compile_start_time = NaClGetTimeOfDayMicroseconds(); | 248 int64_t do_compile_start_time = NaClGetTimeOfDayMicroseconds(); |
249 | 249 |
250 std::vector<std::string> args; | 250 std::vector<std::string> args; |
251 if (pnacl_options_->use_subzero) { | 251 if (pnacl_options_->use_subzero) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 void PnaclTranslateThread::DoLink() { | 358 void PnaclTranslateThread::DoLink() { |
359 { | 359 { |
360 nacl::MutexLocker ml(&subprocess_mu_); | 360 nacl::MutexLocker ml(&subprocess_mu_); |
361 // If the main thread asked us to exit in between starting the thread | 361 // If the main thread asked us to exit in between starting the thread |
362 // and now, just leave now. | 362 // and now, just leave now. |
363 if (!ld_subprocess_active_) | 363 if (!ld_subprocess_active_) |
364 return; | 364 return; |
365 } | 365 } |
366 | 366 |
367 // Reset object files for reading first. We do this before duplicating | 367 // Reset object files for reading first. We do this before duplicating |
368 // handles/FDs to prevent any handle/FD leaks in case any of the Reset() | 368 // handles/FDs to prevent any handle/FD leaks in case any of the Seek() |
369 // calls fail. | 369 // calls fail. |
370 for (TempFile* obj_file : *obj_files_) { | 370 for (base::File& obj_file : *obj_files_) { |
371 if (!obj_file->Reset()) { | 371 if (obj_file.Seek(base::File::FROM_BEGIN, 0) != 0) { |
372 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, | 372 TranslateFailed(PP_NACL_ERROR_PNACL_LD_SETUP, |
373 "Link process could not reset object file"); | 373 "Link process could not reset object file"); |
374 return; | 374 return; |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 ppapi::proxy::SerializedHandle nexe_file = | 378 ppapi::proxy::SerializedHandle nexe_file = |
379 GetHandleForSubprocess(nexe_file_, PP_FILEOPENFLAG_WRITE, | 379 GetHandleForSubprocess(nexe_file_, PP_FILEOPENFLAG_WRITE, |
380 ld_channel_peer_pid_); | 380 ld_channel_peer_pid_); |
381 std::vector<ppapi::proxy::SerializedHandle> ld_input_files; | 381 std::vector<ppapi::proxy::SerializedHandle> ld_input_files; |
382 for (TempFile* obj_file : *obj_files_) { | 382 for (base::File& obj_file : *obj_files_) { |
383 ld_input_files.push_back( | 383 ld_input_files.push_back( |
384 GetHandleForSubprocess(obj_file, PP_FILEOPENFLAG_READ, | 384 GetHandleForSubprocess(&obj_file, PP_FILEOPENFLAG_READ, |
385 ld_channel_peer_pid_)); | 385 ld_channel_peer_pid_)); |
386 } | 386 } |
387 | 387 |
388 int64_t link_start_time = NaClGetTimeOfDayMicroseconds(); | 388 int64_t link_start_time = NaClGetTimeOfDayMicroseconds(); |
389 bool success = false; | 389 bool success = false; |
390 bool sent = ld_channel_filter_->Send( | 390 bool sent = ld_channel_filter_->Send( |
391 new PpapiMsg_PnaclTranslatorLink(ld_input_files, nexe_file, &success)); | 391 new PpapiMsg_PnaclTranslatorLink(ld_input_files, nexe_file, &success)); |
392 if (!sent) { | 392 if (!sent) { |
393 TranslateFailed(PP_NACL_ERROR_PNACL_LD_INTERNAL, | 393 TranslateFailed(PP_NACL_ERROR_PNACL_LD_INTERNAL, |
394 "link failed: reply not received from linker."); | 394 "link failed: reply not received from linker."); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 AbortSubprocesses(); | 459 AbortSubprocesses(); |
460 if (translate_thread_ != NULL) | 460 if (translate_thread_ != NULL) |
461 NaClThreadJoin(translate_thread_.get()); | 461 NaClThreadJoin(translate_thread_.get()); |
462 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); | 462 PLUGIN_PRINTF(("~PnaclTranslateThread joined\n")); |
463 NaClCondVarDtor(&buffer_cond_); | 463 NaClCondVarDtor(&buffer_cond_); |
464 NaClMutexDtor(&cond_mu_); | 464 NaClMutexDtor(&cond_mu_); |
465 NaClMutexDtor(&subprocess_mu_); | 465 NaClMutexDtor(&subprocess_mu_); |
466 } | 466 } |
467 | 467 |
468 } // namespace plugin | 468 } // namespace plugin |
OLD | NEW |