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_coordinator.h" | 5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "native_client/src/include/portability_io.h" | 10 #include "native_client/src/include/portability_io.h" |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 error_info, pnacl_translate); | 390 error_info, pnacl_translate); |
391 } | 391 } |
392 | 392 |
393 private: | 393 private: |
394 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclLDManifest); | 394 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclLDManifest); |
395 | 395 |
396 const Manifest* nexe_manifest_; | 396 const Manifest* nexe_manifest_; |
397 const Manifest* extension_manifest_; | 397 const Manifest* extension_manifest_; |
398 }; | 398 }; |
399 | 399 |
| 400 static int64_t start_download_time = 0; |
| 401 |
400 ////////////////////////////////////////////////////////////////////// | 402 ////////////////////////////////////////////////////////////////////// |
401 // The coordinator class. | 403 // The coordinator class. |
402 ////////////////////////////////////////////////////////////////////// | 404 ////////////////////////////////////////////////////////////////////// |
403 PnaclCoordinator* PnaclCoordinator::BitcodeToNative( | 405 PnaclCoordinator* PnaclCoordinator::BitcodeToNative( |
404 Plugin* plugin, | 406 Plugin* plugin, |
405 const nacl::string& pexe_url, | 407 const nacl::string& pexe_url, |
406 const nacl::string& cache_identity, | 408 const nacl::string& cache_identity, |
407 const pp::CompletionCallback& translate_notify_callback) { | 409 const pp::CompletionCallback& translate_notify_callback) { |
408 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", | 410 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", |
409 static_cast<void*>(plugin), pexe_url.c_str())); | 411 static_cast<void*>(plugin), pexe_url.c_str())); |
410 PnaclCoordinator* coordinator = | 412 PnaclCoordinator* coordinator = |
411 new PnaclCoordinator(plugin, pexe_url, | 413 new PnaclCoordinator(plugin, pexe_url, |
412 cache_identity, translate_notify_callback); | 414 cache_identity, translate_notify_callback); |
413 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p)\n", | 415 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p)\n", |
414 reinterpret_cast<const void*>(coordinator->manifest_.get()))); | 416 reinterpret_cast<const void*>(coordinator->manifest_.get()))); |
415 // Load llc and ld. | 417 // Load llc and ld. |
416 std::vector<nacl::string> resource_urls; | 418 std::vector<nacl::string> resource_urls; |
417 resource_urls.push_back(kLlcUrl); | 419 resource_urls.push_back(kLlcUrl); |
418 resource_urls.push_back(kLdUrl); | 420 resource_urls.push_back(kLdUrl); |
419 pp::CompletionCallback resources_cb = | 421 pp::CompletionCallback resources_cb = |
420 coordinator->callback_factory_.NewCallback( | 422 coordinator->callback_factory_.NewCallback( |
421 &PnaclCoordinator::ResourcesDidLoad); | 423 &PnaclCoordinator::ResourcesDidLoad); |
422 coordinator->resources_.reset( | 424 coordinator->resources_.reset( |
423 new PnaclResources(plugin, | 425 new PnaclResources(plugin, |
424 coordinator, | 426 coordinator, |
425 coordinator->manifest_.get(), | 427 coordinator->manifest_.get(), |
426 resource_urls, | 428 resource_urls, |
427 resources_cb)); | 429 resources_cb)); |
428 CHECK(coordinator->resources_ != NULL); | 430 CHECK(coordinator->resources_ != NULL); |
| 431 |
| 432 start_download_time = NaClGetTimeOfDayMicroseconds(); |
429 coordinator->resources_->StartDownloads(); | 433 coordinator->resources_->StartDownloads(); |
430 // ResourcesDidLoad will be invoked when all resources have been received. | 434 // ResourcesDidLoad will be invoked when all resources have been received. |
431 return coordinator; | 435 return coordinator; |
432 } | 436 } |
433 | 437 |
434 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error, | 438 int32_t PnaclCoordinator::GetLoadedFileDesc(int32_t pp_error, |
435 const nacl::string& url, | 439 const nacl::string& url, |
436 const nacl::string& component) { | 440 const nacl::string& component) { |
437 PLUGIN_PRINTF(("PnaclCoordinator::GetLoadedFileDesc (pp_error=%" | 441 PLUGIN_PRINTF(("PnaclCoordinator::GetLoadedFileDesc (pp_error=%" |
438 NACL_PRId32", url=%s, component=%s)\n", pp_error, | 442 NACL_PRId32", url=%s, component=%s)\n", pp_error, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 620 |
617 void PnaclCoordinator::TranslateFailed(const nacl::string& error_string) { | 621 void PnaclCoordinator::TranslateFailed(const nacl::string& error_string) { |
618 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFailed (error_string=%" | 622 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFailed (error_string=%" |
619 NACL_PRId32")\n", error_string.c_str())); | 623 NACL_PRId32")\n", error_string.c_str())); |
620 pp::Core* core = pp::Module::Get()->core(); | 624 pp::Core* core = pp::Module::Get()->core(); |
621 error_info_.SetReport(ERROR_UNKNOWN, | 625 error_info_.SetReport(ERROR_UNKNOWN, |
622 nacl::string("PnaclCoordinator: ") + error_string); | 626 nacl::string("PnaclCoordinator: ") + error_string); |
623 core->CallOnMainThread(0, report_translate_finished_, PP_ERROR_FAILED); | 627 core->CallOnMainThread(0, report_translate_finished_, PP_ERROR_FAILED); |
624 } | 628 } |
625 | 629 |
| 630 |
| 631 // DEBUGGING test junk -- to be removed before checkin and replaced |
| 632 // with something like a test... |
| 633 static void TestPnaclOpenFile(const nacl::string& filename, bool expect_works) { |
| 634 PLUGIN_PRINTF(("JAN calling get_readonly_pnacl_fd: %s\n", filename.c_str())); |
| 635 int fd = get_readonly_pnacl_fd(filename.c_str()); |
| 636 const char *expect_success_msg = expect_works ? "YAY!" : "NOO!"; |
| 637 const char *expect_fail_msg = expect_works ? "NOO!" : "YAY!"; |
| 638 |
| 639 if (fd < 0) { |
| 640 PLUGIN_PRINTF(("JAN get %s failed (fd='%d') %s\n", |
| 641 filename.c_str(), fd, expect_fail_msg)); |
| 642 } else { |
| 643 PLUGIN_PRINTF(("JAN get %s succeeded (fd='%d') %s\n", |
| 644 filename.c_str(), fd, expect_success_msg)); |
| 645 // Try to stat the mofo. |
| 646 struct stat stat_buf; |
| 647 if (0 != fstat(fd, &stat_buf)) { |
| 648 PLUGIN_PRINTF(("JAN stat %s fd failed: %s\n", |
| 649 filename.c_str(), expect_fail_msg)); |
| 650 } else { |
| 651 PLUGIN_PRINTF(("JAN stat %s fd (size='%d') succeed: %s\n", |
| 652 filename.c_str(), stat_buf.st_size, expect_success_msg)); |
| 653 } |
| 654 close(fd); |
| 655 PLUGIN_PRINTF(("JAN got fd for %s and now closing: %d\n", |
| 656 filename.c_str(), fd)); |
| 657 } |
| 658 } |
| 659 |
| 660 static void WINAPI DoTestFileOpens(void* arg) { |
| 661 nacl::string sandbox_isa = GetSandboxISA(); |
| 662 TestPnaclOpenFile(sandbox_isa + nacl::string("llc"), true); |
| 663 TestPnaclOpenFile(sandbox_isa + "ld", true); |
| 664 TestPnaclOpenFile(sandbox_isa + "crtbegin.o", true); |
| 665 TestPnaclOpenFile("non-existent-file", false); |
| 666 TestPnaclOpenFile("../../chrome_shutdown_ms.txt", false); |
| 667 TestPnaclOpenFile("/bin/ls", false); |
| 668 TestPnaclOpenFile("$HOME/.bashrc", false); |
| 669 } |
| 670 // END DEBUGGING test junk. |
| 671 |
| 672 |
626 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { | 673 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { |
627 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" | 674 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" |
628 NACL_PRId32")\n", pp_error)); | 675 NACL_PRId32")\n", pp_error)); |
| 676 |
| 677 int64_t end_download_time = NaClGetTimeOfDayMicroseconds(); |
| 678 PLUGIN_PRINTF(("PnaclCoordinator:: url load time total=%"NACL_PRId64")\n", |
| 679 end_download_time - start_download_time)); |
| 680 |
| 681 // BEGIN debugging hack. |
| 682 // On thread accesses work... |
| 683 PLUGIN_PRINTF(("JAN Testing from main thread.\n")); |
| 684 int64_t start_download_time2 = NaClGetTimeOfDayMicroseconds(); |
| 685 DoTestFileOpens(NULL); |
| 686 int64_t end_download_time2 = NaClGetTimeOfDayMicroseconds(); |
| 687 PLUGIN_PRINTF(("PnaclCoordinator::fd load time total=%"NACL_PRId64")\n", |
| 688 end_download_time2 - start_download_time2)); |
| 689 |
| 690 // Off thread use doesn't seem to work... |
| 691 // PLUGIN_PRINTF(("JAN Testing from secondary thread.\n")); |
| 692 // static NaClThread *debugging_file_thread = new NaClThread(); |
| 693 // if (!NaClThreadCreateJoinable(debugging_file_thread, |
| 694 // DoTestFileOpens, |
| 695 // NULL, |
| 696 // 128 * 1024)) { |
| 697 // PLUGIN_PRINTF(("JAN Failed to creaate test thread\n")); |
| 698 // } |
| 699 PLUGIN_PRINTF(("JAN Testing all done!\n")); |
| 700 // END debugging. |
| 701 |
629 if (pp_error != PP_OK) { | 702 if (pp_error != PP_OK) { |
630 ReportPpapiError(pp_error, "resources failed to load."); | 703 ReportPpapiError(pp_error, "resources failed to load."); |
631 return; | 704 return; |
632 } | 705 } |
633 // Open the local temporary file system to create the temporary files | 706 // Open the local temporary file system to create the temporary files |
634 // for the object and nexe. | 707 // for the object and nexe. |
635 pp::CompletionCallback cb = | 708 pp::CompletionCallback cb = |
636 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen); | 709 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen); |
637 if (!file_system_->Open(0, cb)) { | 710 if (!file_system_->Open(0, cb)) { |
638 ReportNonPpapiError("failed to open file system."); | 711 ReportNonPpapiError("failed to open file system."); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 } | 802 } |
730 } | 803 } |
731 | 804 |
732 void PnaclCoordinator::RunTranslate(int32_t pp_error) { | 805 void PnaclCoordinator::RunTranslate(int32_t pp_error) { |
733 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" | 806 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" |
734 NACL_PRId32")\n", pp_error)); | 807 NACL_PRId32")\n", pp_error)); |
735 int32_t fd = GetLoadedFileDesc(pp_error, pexe_url_, "pexe"); | 808 int32_t fd = GetLoadedFileDesc(pp_error, pexe_url_, "pexe"); |
736 if (fd < 0) { | 809 if (fd < 0) { |
737 return; | 810 return; |
738 } | 811 } |
| 812 |
739 pexe_wrapper_.reset(plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY)); | 813 pexe_wrapper_.reset(plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY)); |
740 // Invoke llc followed by ld off the main thread. This allows use of | 814 // Invoke llc followed by ld off the main thread. This allows use of |
741 // blocking RPCs that would otherwise block the JavaScript main thread. | 815 // blocking RPCs that would otherwise block the JavaScript main thread. |
742 report_translate_finished_ = | 816 report_translate_finished_ = |
743 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); | 817 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); |
744 translate_thread_.reset(new NaClThread); | 818 translate_thread_.reset(new NaClThread); |
745 if (translate_thread_ == NULL) { | 819 if (translate_thread_ == NULL) { |
746 ReportNonPpapiError("could not allocate thread struct."); | 820 ReportNonPpapiError("could not allocate thread struct."); |
747 return; | 821 return; |
748 } | 822 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 nacl::MutexLocker ml(&subprocess_mu_); | 924 nacl::MutexLocker ml(&subprocess_mu_); |
851 return subprocesses_should_die_; | 925 return subprocesses_should_die_; |
852 } | 926 } |
853 | 927 |
854 void PnaclCoordinator::SetSubprocessesShouldDie(bool subprocesses_should_die) { | 928 void PnaclCoordinator::SetSubprocessesShouldDie(bool subprocesses_should_die) { |
855 nacl::MutexLocker ml(&subprocess_mu_); | 929 nacl::MutexLocker ml(&subprocess_mu_); |
856 subprocesses_should_die_ = subprocesses_should_die; | 930 subprocesses_should_die_ = subprocesses_should_die; |
857 } | 931 } |
858 | 932 |
859 } // namespace plugin | 933 } // namespace plugin |
OLD | NEW |