Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: trunk/src/ppapi/native_client/src/trusted/plugin/plugin.cc

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

Powered by Google App Engine
This is Rietveld 408576698