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 #ifdef _MSC_VER | 5 #ifdef _MSC_VER |
6 // Do not warn about use of std::copy with raw pointers. | 6 // Do not warn about use of std::copy with raw pointers. |
7 #pragma warning(disable : 4996) | 7 #pragma warning(disable : 4996) |
8 #endif | 8 #endif |
9 | 9 |
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 27 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
28 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 28 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
29 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 29 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
30 | 30 |
31 #include "ppapi/c/pp_errors.h" | 31 #include "ppapi/c/pp_errors.h" |
32 #include "ppapi/c/ppb_var.h" | 32 #include "ppapi/c/ppb_var.h" |
33 #include "ppapi/c/private/ppb_nacl_private.h" | 33 #include "ppapi/c/private/ppb_nacl_private.h" |
34 #include "ppapi/cpp/dev/url_util_dev.h" | 34 #include "ppapi/cpp/dev/url_util_dev.h" |
35 #include "ppapi/cpp/module.h" | 35 #include "ppapi/cpp/module.h" |
36 | 36 |
37 #include "ppapi/native_client/src/trusted/plugin/json_manifest.h" | |
38 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 37 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
39 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" | 38 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" |
40 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" | 39 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" |
41 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" | 40 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" |
42 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 41 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
43 | 42 |
44 namespace plugin { | 43 namespace plugin { |
45 | 44 |
46 namespace { | 45 namespace { |
47 | 46 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // error. | 128 // error. |
130 // Note: installed files may have "0" for a status code. | 129 // Note: installed files may have "0" for a status code. |
131 if (status < 0 || status >= 600) | 130 if (status < 0 || status >= 600) |
132 sample = 6; | 131 sample = 6; |
133 HistogramEnumerate(name, sample, 7, 6); | 132 HistogramEnumerate(name, sample, 7, 6); |
134 } | 133 } |
135 | 134 |
136 bool Plugin::LoadNaClModuleFromBackgroundThread( | 135 bool Plugin::LoadNaClModuleFromBackgroundThread( |
137 nacl::DescWrapper* wrapper, | 136 nacl::DescWrapper* wrapper, |
138 NaClSubprocess* subprocess, | 137 NaClSubprocess* subprocess, |
139 const Manifest* manifest, | 138 int32_t manifest_id, |
140 const SelLdrStartParams& params) { | 139 const SelLdrStartParams& params) { |
141 CHECK(!pp::Module::Get()->core()->IsMainThread()); | 140 CHECK(!pp::Module::Get()->core()->IsMainThread()); |
142 ServiceRuntime* service_runtime = | 141 ServiceRuntime* service_runtime = |
143 new ServiceRuntime(this, manifest, false, uses_nonsfi_mode_, | 142 new ServiceRuntime(this, manifest_id, false, uses_nonsfi_mode_, |
144 pp::BlockUntilComplete(), pp::BlockUntilComplete()); | 143 pp::BlockUntilComplete(), pp::BlockUntilComplete()); |
145 subprocess->set_service_runtime(service_runtime); | 144 subprocess->set_service_runtime(service_runtime); |
146 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " | 145 PLUGIN_PRINTF(("Plugin::LoadNaClModuleFromBackgroundThread " |
147 "(service_runtime=%p)\n", | 146 "(service_runtime=%p)\n", |
148 static_cast<void*>(service_runtime))); | 147 static_cast<void*>(service_runtime))); |
149 | 148 |
150 // Now start the SelLdr instance. This must be created on the main thread. | 149 // Now start the SelLdr instance. This must be created on the main thread. |
151 bool service_runtime_started = false; | 150 bool service_runtime_started = false; |
152 pp::CompletionCallback sel_ldr_callback = | 151 pp::CompletionCallback sel_ldr_callback = |
153 callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone, | 152 callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 SelLdrStartParams params(manifest_base_url_str, | 220 SelLdrStartParams params(manifest_base_url_str, |
222 true /* uses_irt */, | 221 true /* uses_irt */, |
223 true /* uses_ppapi */, | 222 true /* uses_ppapi */, |
224 uses_nonsfi_mode, | 223 uses_nonsfi_mode, |
225 enable_dev_interfaces, | 224 enable_dev_interfaces, |
226 enable_dyncode_syscalls, | 225 enable_dyncode_syscalls, |
227 enable_exception_handling, | 226 enable_exception_handling, |
228 enable_crash_throttling); | 227 enable_crash_throttling); |
229 ErrorInfo error_info; | 228 ErrorInfo error_info; |
230 ServiceRuntime* service_runtime = | 229 ServiceRuntime* service_runtime = |
231 new ServiceRuntime(this, manifest_.get(), true, uses_nonsfi_mode, | 230 new ServiceRuntime(this, manifest_id_, true, uses_nonsfi_mode, |
232 init_done_cb, crash_cb); | 231 init_done_cb, crash_cb); |
233 main_subprocess_.set_service_runtime(service_runtime); | 232 main_subprocess_.set_service_runtime(service_runtime); |
234 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", | 233 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", |
235 static_cast<void*>(service_runtime))); | 234 static_cast<void*>(service_runtime))); |
236 if (NULL == service_runtime) { | 235 if (NULL == service_runtime) { |
237 error_info.SetReport( | 236 error_info.SetReport( |
238 PP_NACL_ERROR_SEL_LDR_INIT, | 237 PP_NACL_ERROR_SEL_LDR_INIT, |
239 "sel_ldr init failure " + main_subprocess_.description()); | 238 "sel_ldr init failure " + main_subprocess_.description()); |
240 ReportLoadError(error_info); | 239 ReportLoadError(error_info); |
241 return; | 240 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 bool result = PP_ToBool(nacl_interface_->StartPpapiProxy(pp_instance())); | 285 bool result = PP_ToBool(nacl_interface_->StartPpapiProxy(pp_instance())); |
287 if (result) { | 286 if (result) { |
288 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", | 287 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", |
289 main_subprocess_.detailed_description().c_str())); | 288 main_subprocess_.detailed_description().c_str())); |
290 } | 289 } |
291 return result; | 290 return result; |
292 } | 291 } |
293 | 292 |
294 NaClSubprocess* Plugin::LoadHelperNaClModule(const nacl::string& helper_url, | 293 NaClSubprocess* Plugin::LoadHelperNaClModule(const nacl::string& helper_url, |
295 nacl::DescWrapper* wrapper, | 294 nacl::DescWrapper* wrapper, |
296 const Manifest* manifest, | 295 int32_t manifest_id, |
297 ErrorInfo* error_info) { | 296 ErrorInfo* error_info) { |
298 nacl::scoped_ptr<NaClSubprocess> nacl_subprocess( | 297 nacl::scoped_ptr<NaClSubprocess> nacl_subprocess( |
299 new NaClSubprocess("helper module", NULL, NULL)); | 298 new NaClSubprocess("helper module", NULL, NULL)); |
300 if (NULL == nacl_subprocess.get()) { | 299 if (NULL == nacl_subprocess.get()) { |
301 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, | 300 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, |
302 "unable to allocate helper subprocess."); | 301 "unable to allocate helper subprocess."); |
303 return NULL; | 302 return NULL; |
304 } | 303 } |
305 | 304 |
306 // Do not report UMA stats for translator-related nexes. | 305 // Do not report UMA stats for translator-related nexes. |
307 // TODO(sehr): define new UMA stats for translator related nexe events. | 306 // TODO(sehr): define new UMA stats for translator related nexe events. |
308 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is | 307 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is |
309 // done to save on address space and swap space. | 308 // done to save on address space and swap space. |
310 // TODO(jvoung): See if we still need the uses_ppapi variable, now that | 309 // TODO(jvoung): See if we still need the uses_ppapi variable, now that |
311 // LaunchSelLdr always happens on the main thread. | 310 // LaunchSelLdr always happens on the main thread. |
312 bool enable_dev_interfaces = | 311 bool enable_dev_interfaces = |
313 nacl_interface_->DevInterfacesEnabled(pp_instance()); | 312 nacl_interface_->DevInterfacesEnabled(pp_instance()); |
314 SelLdrStartParams params(helper_url, | 313 SelLdrStartParams params(helper_url, |
315 false /* uses_irt */, | 314 false /* uses_irt */, |
316 false /* uses_ppapi */, | 315 false /* uses_ppapi */, |
317 false /* uses_nonsfi_mode */, | 316 false /* uses_nonsfi_mode */, |
318 enable_dev_interfaces, | 317 enable_dev_interfaces, |
319 false /* enable_dyncode_syscalls */, | 318 false /* enable_dyncode_syscalls */, |
320 false /* enable_exception_handling */, | 319 false /* enable_exception_handling */, |
321 true /* enable_crash_throttling */); | 320 true /* enable_crash_throttling */); |
322 if (!LoadNaClModuleFromBackgroundThread(wrapper, nacl_subprocess.get(), | 321 if (!LoadNaClModuleFromBackgroundThread(wrapper, nacl_subprocess.get(), |
323 manifest, params)) { | 322 manifest_id, params)) { |
324 return NULL; | 323 return NULL; |
325 } | 324 } |
326 // We need not wait for the init_done callback. We can block | 325 // We need not wait for the init_done callback. We can block |
327 // here in StartSrpcServices, since helper NaCl modules | 326 // here in StartSrpcServices, since helper NaCl modules |
328 // are spawned from a private thread. | 327 // are spawned from a private thread. |
329 // | 328 // |
330 // TODO(bsy): if helper module crashes, we should abort. | 329 // TODO(bsy): if helper module crashes, we should abort. |
331 // crash_cb is not used here, so we are relying on crashes | 330 // crash_cb is not used here, so we are relying on crashes |
332 // being detected in StartSrpcServices or later. | 331 // being detected in StartSrpcServices or later. |
333 // | 332 // |
(...skipping 29 matching lines...) Expand all Loading... |
363 return true; | 362 return true; |
364 } | 363 } |
365 | 364 |
366 Plugin::Plugin(PP_Instance pp_instance) | 365 Plugin::Plugin(PP_Instance pp_instance) |
367 : pp::Instance(pp_instance), | 366 : pp::Instance(pp_instance), |
368 main_subprocess_("main subprocess", NULL, NULL), | 367 main_subprocess_("main subprocess", NULL, NULL), |
369 uses_nonsfi_mode_(false), | 368 uses_nonsfi_mode_(false), |
370 wrapper_factory_(NULL), | 369 wrapper_factory_(NULL), |
371 time_of_last_progress_event_(0), | 370 time_of_last_progress_event_(0), |
372 nexe_open_time_(-1), | 371 nexe_open_time_(-1), |
| 372 manifest_id_(-1), |
373 nacl_interface_(NULL), | 373 nacl_interface_(NULL), |
374 uma_interface_(this) { | 374 uma_interface_(this) { |
375 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" | 375 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" |
376 NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance)); | 376 NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance)); |
377 callback_factory_.Initialize(this); | 377 callback_factory_.Initialize(this); |
378 nexe_downloader_.Initialize(this); | 378 nexe_downloader_.Initialize(this); |
379 nacl_interface_ = GetNaClInterface(); | 379 nacl_interface_ = GetNaClInterface(); |
380 CHECK(nacl_interface_ != NULL); | 380 CHECK(nacl_interface_ != NULL); |
381 | 381 |
382 // Notify PPB_NaCl_Private that the instance is created before altering any | 382 // Notify PPB_NaCl_Private that the instance is created before altering any |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 ProcessNaClManifest(json_buffer); | 573 ProcessNaClManifest(json_buffer); |
574 } | 574 } |
575 } | 575 } |
576 | 576 |
577 void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { | 577 void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { |
578 HistogramSizeKB("NaCl.Perf.Size.Manifest", | 578 HistogramSizeKB("NaCl.Perf.Size.Manifest", |
579 static_cast<int32_t>(manifest_json.length() / 1024)); | 579 static_cast<int32_t>(manifest_json.length() / 1024)); |
580 if (!SetManifestObject(manifest_json)) | 580 if (!SetManifestObject(manifest_json)) |
581 return; | 581 return; |
582 | 582 |
583 nacl::string program_url; | 583 PP_Var pp_program_url; |
584 PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2}; | 584 PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2}; |
585 bool uses_nonsfi_mode; | 585 PP_Bool uses_nonsfi_mode; |
586 ErrorInfo error_info; | 586 if (nacl_interface_->GetManifestProgramURL(pp_instance(), |
587 if (manifest_->GetProgramURL( | 587 manifest_id_, &pp_program_url, &pnacl_options, &uses_nonsfi_mode)) { |
588 &program_url, &pnacl_options, &uses_nonsfi_mode, &error_info)) { | 588 std::string program_url = pp::Var(pp::PASS_REF, pp_program_url).AsString(); |
589 // TODO(teravest): Make ProcessNaClManifest take responsibility for more of | 589 // TODO(teravest): Make ProcessNaClManifest take responsibility for more of |
590 // this function. | 590 // this function. |
591 nacl_interface_->ProcessNaClManifest(pp_instance(), program_url.c_str()); | 591 nacl_interface_->ProcessNaClManifest(pp_instance(), program_url.c_str()); |
592 uses_nonsfi_mode_ = uses_nonsfi_mode; | 592 uses_nonsfi_mode_ = PP_ToBool(uses_nonsfi_mode); |
593 if (pnacl_options.translate) { | 593 if (pnacl_options.translate) { |
594 pp::CompletionCallback translate_callback = | 594 pp::CompletionCallback translate_callback = |
595 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate); | 595 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate); |
596 // Will always call the callback on success or failure. | |
597 pnacl_coordinator_.reset( | 596 pnacl_coordinator_.reset( |
598 PnaclCoordinator::BitcodeToNative(this, | 597 PnaclCoordinator::BitcodeToNative(this, |
599 program_url, | 598 program_url, |
600 pnacl_options, | 599 pnacl_options, |
601 translate_callback)); | 600 translate_callback)); |
602 return; | 601 return; |
603 } else { | 602 } else { |
604 nexe_open_time_ = NaClGetTimeOfDayMicroseconds(); | 603 nexe_open_time_ = NaClGetTimeOfDayMicroseconds(); |
605 // Try the fast path first. This will only block if the file is installed. | 604 // Try the fast path first. This will only block if the file is installed. |
606 if (OpenURLFast(program_url, &nexe_downloader_)) { | 605 if (OpenURLFast(program_url, &nexe_downloader_)) { |
607 NexeFileDidOpen(PP_OK); | 606 NexeFileDidOpen(PP_OK); |
608 } else { | 607 } else { |
609 pp::CompletionCallback open_callback = | 608 pp::CompletionCallback open_callback = |
610 callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); | 609 callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); |
611 // Will always call the callback on success or failure. | 610 // Will always call the callback on success or failure. |
612 CHECK( | 611 CHECK( |
613 nexe_downloader_.Open(program_url, | 612 nexe_downloader_.Open(program_url, |
614 DOWNLOAD_TO_FILE, | 613 DOWNLOAD_TO_FILE, |
615 open_callback, | 614 open_callback, |
616 true, | 615 true, |
617 &UpdateDownloadProgress)); | 616 &UpdateDownloadProgress)); |
618 } | 617 } |
619 return; | 618 return; |
620 } | 619 } |
621 } | 620 } |
622 // Failed to select the program and/or the translator. | |
623 ReportLoadError(error_info); | |
624 } | 621 } |
625 | 622 |
626 void Plugin::RequestNaClManifest(const nacl::string& url) { | 623 void Plugin::RequestNaClManifest(const nacl::string& url) { |
627 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (url='%s')\n", url.c_str())); | 624 PLUGIN_PRINTF(("Plugin::RequestNaClManifest (url='%s')\n", url.c_str())); |
628 PP_Bool is_data_uri; | 625 PP_Bool is_data_uri; |
629 ErrorInfo error_info; | 626 ErrorInfo error_info; |
630 if (!nacl_interface_->RequestNaClManifest(pp_instance(), url.c_str(), | 627 if (!nacl_interface_->RequestNaClManifest(pp_instance(), url.c_str(), |
631 &is_data_uri)) | 628 &is_data_uri)) |
632 return; | 629 return; |
633 pp::Var nmf_resolved_url = | 630 pp::Var nmf_resolved_url = |
(...skipping 22 matching lines...) Expand all Loading... |
656 pp_instance(), | 653 pp_instance(), |
657 &manifest_data_var_, | 654 &manifest_data_var_, |
658 open_callback.pp_completion_callback()); | 655 open_callback.pp_completion_callback()); |
659 } | 656 } |
660 } | 657 } |
661 | 658 |
662 | 659 |
663 bool Plugin::SetManifestObject(const nacl::string& manifest_json) { | 660 bool Plugin::SetManifestObject(const nacl::string& manifest_json) { |
664 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", | 661 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", |
665 manifest_json.c_str())); | 662 manifest_json.c_str())); |
666 ErrorInfo error_info; | |
667 | |
668 // Determine whether lookups should use portable (i.e., pnacl versions) | 663 // Determine whether lookups should use portable (i.e., pnacl versions) |
669 // rather than platform-specific files. | 664 // rather than platform-specific files. |
670 bool is_pnacl = nacl_interface_->IsPNaCl(pp_instance()); | 665 bool is_pnacl = nacl_interface_->IsPNaCl(pp_instance()); |
671 bool nonsfi_mode_enabled = | |
672 PP_ToBool(nacl_interface_->IsNonSFIModeEnabled()); | |
673 pp::Var manifest_base_url = | 666 pp::Var manifest_base_url = |
674 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); | 667 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); |
675 std::string manifest_base_url_str = manifest_base_url.AsString(); | 668 std::string manifest_base_url_str = manifest_base_url.AsString(); |
676 bool pnacl_debug = GetNaClInterface()->NaClDebugEnabledForURL( | |
677 manifest_base_url_str.c_str()); | |
678 const char* sandbox_isa = nacl_interface_->GetSandboxArch(); | 669 const char* sandbox_isa = nacl_interface_->GetSandboxArch(); |
679 nacl::scoped_ptr<JsonManifest> json_manifest( | 670 |
680 new JsonManifest(pp::URLUtil_Dev::Get(), | 671 int32_t manifest_id = nacl_interface_->CreateJsonManifest( |
681 manifest_base_url_str, | 672 pp_instance(), |
682 (is_pnacl ? kPortableArch : sandbox_isa), | 673 manifest_base_url_str.c_str(), |
683 nonsfi_mode_enabled, | 674 is_pnacl ? kPortableArch : sandbox_isa, |
684 pnacl_debug)); | 675 manifest_json.c_str()); |
685 if (!json_manifest->Init(manifest_json, &error_info)) { | 676 if (manifest_id == -1) |
686 ReportLoadError(error_info); | |
687 return false; | 677 return false; |
688 } | 678 manifest_id_ = manifest_id; |
689 manifest_.reset(json_manifest.release()); | |
690 return true; | 679 return true; |
691 } | 680 } |
692 | 681 |
693 void Plugin::UrlDidOpenForStreamAsFile( | 682 void Plugin::UrlDidOpenForStreamAsFile( |
694 int32_t pp_error, | 683 int32_t pp_error, |
695 FileDownloader* url_downloader, | 684 FileDownloader* url_downloader, |
696 pp::CompletionCallback callback) { | 685 pp::CompletionCallback callback) { |
697 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 | 686 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 |
698 ", url_downloader=%p)\n", pp_error, | 687 ", url_downloader=%p)\n", pp_error, |
699 static_cast<void*>(url_downloader))); | 688 static_cast<void*>(url_downloader))); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 | 887 |
899 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 888 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
900 int exit_status) { | 889 int exit_status) { |
901 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 890 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
902 DCHECK(nacl_interface_); | 891 DCHECK(nacl_interface_); |
903 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 892 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
904 } | 893 } |
905 | 894 |
906 | 895 |
907 } // namespace plugin | 896 } // namespace plugin |
OLD | NEW |