| 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 | |
| 6 // Do not warn about use of std::copy with raw pointers. | |
| 7 #pragma warning(disable : 4996) | |
| 8 #endif | |
| 9 | |
| 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 5 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 11 | 6 |
| 12 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 13 #include <sys/types.h> | 8 #include <sys/types.h> |
| 14 | 9 |
| 15 #include <algorithm> | |
| 16 #include <string> | 10 #include <string> |
| 17 #include <vector> | |
| 18 | 11 |
| 19 #include "native_client/src/include/nacl_base.h" | 12 #include "native_client/src/include/nacl_base.h" |
| 20 #include "native_client/src/include/nacl_macros.h" | 13 #include "native_client/src/include/nacl_macros.h" |
| 21 #include "native_client/src/include/nacl_scoped_ptr.h" | 14 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 22 #include "native_client/src/include/nacl_string.h" | 15 #include "native_client/src/include/nacl_string.h" |
| 23 #include "native_client/src/include/portability.h" | 16 #include "native_client/src/include/portability.h" |
| 24 #include "native_client/src/include/portability_io.h" | 17 #include "native_client/src/include/portability_io.h" |
| 25 #include "native_client/src/include/portability_string.h" | 18 #include "native_client/src/include/portability_string.h" |
| 26 #include "native_client/src/public/nacl_file_info.h" | 19 #include "native_client/src/public/nacl_file_info.h" |
| 27 #include "native_client/src/shared/platform/nacl_check.h" | 20 #include "native_client/src/shared/platform/nacl_check.h" |
| 28 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 21 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 29 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 22 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
| 30 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 23 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
| 31 | 24 |
| 32 #include "ppapi/c/pp_errors.h" | 25 #include "ppapi/c/pp_errors.h" |
| 33 #include "ppapi/c/ppb_var.h" | |
| 34 #include "ppapi/c/private/ppb_nacl_private.h" | 26 #include "ppapi/c/private/ppb_nacl_private.h" |
| 35 #include "ppapi/cpp/dev/url_util_dev.h" | 27 #include "ppapi/cpp/dev/url_util_dev.h" |
| 36 #include "ppapi/cpp/module.h" | 28 #include "ppapi/cpp/module.h" |
| 37 | 29 |
| 38 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 30 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
| 39 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" | 31 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" |
| 40 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" | 32 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" |
| 41 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" | 33 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" |
| 42 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 34 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
| 43 | 35 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 const pp::CompletionCallback& crash_cb) { | 156 const pp::CompletionCallback& crash_cb) { |
| 165 CHECK(pp::Module::Get()->core()->IsMainThread()); | 157 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 166 // Before forking a new sel_ldr process, ensure that we do not leak | 158 // Before forking a new sel_ldr process, ensure that we do not leak |
| 167 // the ServiceRuntime object for an existing subprocess, and that any | 159 // the ServiceRuntime object for an existing subprocess, and that any |
| 168 // associated listener threads do not go unjoined because if they | 160 // associated listener threads do not go unjoined because if they |
| 169 // outlive the Plugin object, they will not be memory safe. | 161 // outlive the Plugin object, they will not be memory safe. |
| 170 ShutDownSubprocesses(); | 162 ShutDownSubprocesses(); |
| 171 pp::Var manifest_base_url = | 163 pp::Var manifest_base_url = |
| 172 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); | 164 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); |
| 173 std::string manifest_base_url_str = manifest_base_url.AsString(); | 165 std::string manifest_base_url_str = manifest_base_url.AsString(); |
| 174 bool enable_dev_interfaces = | |
| 175 nacl_interface_->DevInterfacesEnabled(pp_instance()); | |
| 176 SelLdrStartParams params(manifest_base_url_str, | 166 SelLdrStartParams params(manifest_base_url_str, |
| 177 true /* uses_irt */, | 167 true /* uses_irt */, |
| 178 true /* uses_ppapi */, | 168 true /* uses_ppapi */, |
| 179 uses_nonsfi_mode, | 169 uses_nonsfi_mode, |
| 180 enable_dev_interfaces, | |
| 181 enable_dyncode_syscalls, | 170 enable_dyncode_syscalls, |
| 182 enable_exception_handling, | 171 enable_exception_handling, |
| 183 enable_crash_throttling); | 172 enable_crash_throttling); |
| 184 ErrorInfo error_info; | 173 ErrorInfo error_info; |
| 185 ServiceRuntime* service_runtime = | 174 ServiceRuntime* service_runtime = |
| 186 new ServiceRuntime(this, true, uses_nonsfi_mode, | 175 new ServiceRuntime(this, true, uses_nonsfi_mode, |
| 187 init_done_cb, crash_cb); | 176 init_done_cb, crash_cb); |
| 188 main_subprocess_.set_service_runtime(service_runtime); | 177 main_subprocess_.set_service_runtime(service_runtime); |
| 189 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", | 178 PLUGIN_PRINTF(("Plugin::LoadNaClModule (service_runtime=%p)\n", |
| 190 static_cast<void*>(service_runtime))); | 179 static_cast<void*>(service_runtime))); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 if (NULL == nacl_subprocess.get()) { | 237 if (NULL == nacl_subprocess.get()) { |
| 249 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, | 238 error_info->SetReport(PP_NACL_ERROR_SEL_LDR_INIT, |
| 250 "unable to allocate helper subprocess."); | 239 "unable to allocate helper subprocess."); |
| 251 return NULL; | 240 return NULL; |
| 252 } | 241 } |
| 253 | 242 |
| 254 // Do not report UMA stats for translator-related nexes. | 243 // Do not report UMA stats for translator-related nexes. |
| 255 // TODO(sehr): define new UMA stats for translator related nexe events. | 244 // TODO(sehr): define new UMA stats for translator related nexe events. |
| 256 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is | 245 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is |
| 257 // done to save on address space and swap space. | 246 // done to save on address space and swap space. |
| 258 // TODO(jvoung): See if we still need the uses_ppapi variable, now that | |
| 259 // LaunchSelLdr always happens on the main thread. | |
| 260 bool enable_dev_interfaces = | |
| 261 nacl_interface_->DevInterfacesEnabled(pp_instance()); | |
| 262 SelLdrStartParams params(helper_url, | 247 SelLdrStartParams params(helper_url, |
| 263 false /* uses_irt */, | 248 false /* uses_irt */, |
| 264 false /* uses_ppapi */, | 249 false /* uses_ppapi */, |
| 265 false /* uses_nonsfi_mode */, | 250 false /* uses_nonsfi_mode */, |
| 266 enable_dev_interfaces, | |
| 267 false /* enable_dyncode_syscalls */, | 251 false /* enable_dyncode_syscalls */, |
| 268 false /* enable_exception_handling */, | 252 false /* enable_exception_handling */, |
| 269 true /* enable_crash_throttling */); | 253 true /* enable_crash_throttling */); |
| 270 | 254 |
| 271 // Helper NaCl modules always use the PNaCl manifest, as there is no | 255 // Helper NaCl modules always use the PNaCl manifest, as there is no |
| 272 // corresponding NMF. | 256 // corresponding NMF. |
| 273 if (!LoadNaClModuleFromBackgroundThread(file_handle, nacl_subprocess.get(), | 257 if (!LoadNaClModuleFromBackgroundThread(file_handle, nacl_subprocess.get(), |
| 274 params)) { | 258 params)) { |
| 275 return NULL; | 259 return NULL; |
| 276 } | 260 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 nacl_interface_->RequestNaClManifest(pp_instance(), | 296 nacl_interface_->RequestNaClManifest(pp_instance(), |
| 313 open_cb.pp_completion_callback()); | 297 open_cb.pp_completion_callback()); |
| 314 return true; | 298 return true; |
| 315 } | 299 } |
| 316 | 300 |
| 317 Plugin::Plugin(PP_Instance pp_instance) | 301 Plugin::Plugin(PP_Instance pp_instance) |
| 318 : pp::Instance(pp_instance), | 302 : pp::Instance(pp_instance), |
| 319 main_subprocess_("main subprocess", NULL, NULL), | 303 main_subprocess_("main subprocess", NULL, NULL), |
| 320 uses_nonsfi_mode_(false), | 304 uses_nonsfi_mode_(false), |
| 321 wrapper_factory_(NULL), | 305 wrapper_factory_(NULL), |
| 322 time_of_last_progress_event_(0), | |
| 323 nacl_interface_(NULL), | 306 nacl_interface_(NULL), |
| 324 uma_interface_(this) { | 307 uma_interface_(this) { |
| 325 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" | 308 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" |
| 326 NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance)); | 309 NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance)); |
| 327 callback_factory_.Initialize(this); | 310 callback_factory_.Initialize(this); |
| 328 nacl_interface_ = GetNaClInterface(); | 311 nacl_interface_ = GetNaClInterface(); |
| 329 CHECK(nacl_interface_ != NULL); | 312 CHECK(nacl_interface_ != NULL); |
| 330 | 313 |
| 331 // Notify PPB_NaCl_Private that the instance is created before altering any | 314 // Notify PPB_NaCl_Private that the instance is created before altering any |
| 332 // state that it tracks. | 315 // state that it tracks. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 &nexe_file_info_, | 495 &nexe_file_info_, |
| 513 open_callback.pp_completion_callback()); | 496 open_callback.pp_completion_callback()); |
| 514 return; | 497 return; |
| 515 } | 498 } |
| 516 } | 499 } |
| 517 } | 500 } |
| 518 | 501 |
| 519 void Plugin::ReportLoadError(const ErrorInfo& error_info) { | 502 void Plugin::ReportLoadError(const ErrorInfo& error_info) { |
| 520 nacl_interface_->ReportLoadError(pp_instance(), | 503 nacl_interface_->ReportLoadError(pp_instance(), |
| 521 error_info.error_code(), | 504 error_info.error_code(), |
| 522 error_info.message().c_str(), | 505 error_info.message().c_str()); |
| 523 error_info.console_message().c_str()); | |
| 524 } | 506 } |
| 525 | 507 |
| 526 bool Plugin::DocumentCanRequest(const std::string& url) { | 508 bool Plugin::DocumentCanRequest(const std::string& url) { |
| 527 CHECK(pp::Module::Get()->core()->IsMainThread()); | 509 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 528 CHECK(pp::URLUtil_Dev::Get() != NULL); | 510 CHECK(pp::URLUtil_Dev::Get() != NULL); |
| 529 return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url)); | 511 return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url)); |
| 530 } | 512 } |
| 531 | 513 |
| 532 void Plugin::set_exit_status(int exit_status) { | 514 void Plugin::set_exit_status(int exit_status) { |
| 533 pp::Core* core = pp::Module::Get()->core(); | 515 pp::Core* core = pp::Module::Get()->core(); |
| 534 if (core->IsMainThread()) { | 516 if (core->IsMainThread()) { |
| 535 SetExitStatusOnMainThread(PP_OK, exit_status); | 517 SetExitStatusOnMainThread(PP_OK, exit_status); |
| 536 } else { | 518 } else { |
| 537 pp::CompletionCallback callback = | 519 pp::CompletionCallback callback = |
| 538 callback_factory_.NewCallback(&Plugin::SetExitStatusOnMainThread, | 520 callback_factory_.NewCallback(&Plugin::SetExitStatusOnMainThread, |
| 539 exit_status); | 521 exit_status); |
| 540 core->CallOnMainThread(0, callback, 0); | 522 core->CallOnMainThread(0, callback, 0); |
| 541 } | 523 } |
| 542 } | 524 } |
| 543 | 525 |
| 544 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 526 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
| 545 int exit_status) { | 527 int exit_status) { |
| 546 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 528 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
| 547 DCHECK(nacl_interface_); | 529 DCHECK(nacl_interface_); |
| 548 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 530 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
| 549 } | 531 } |
| 550 | 532 |
| 551 | 533 |
| 552 } // namespace plugin | 534 } // namespace plugin |
| OLD | NEW |