| 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 "ppapi/native_client/src/trusted/plugin/plugin.h" | 5 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| 6 | 6 |
| 7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/types.h> | 8 #include <sys/types.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool Plugin::LoadHelperNaClModuleInternal(NaClSubprocess* subprocess, | 67 bool Plugin::LoadHelperNaClModuleInternal(NaClSubprocess* subprocess, |
| 68 const SelLdrStartParams& params) { | 68 const SelLdrStartParams& params) { |
| 69 CHECK(!pp::Module::Get()->core()->IsMainThread()); | 69 CHECK(!pp::Module::Get()->core()->IsMainThread()); |
| 70 ServiceRuntime* service_runtime = | 70 ServiceRuntime* service_runtime = |
| 71 new ServiceRuntime(this, | 71 new ServiceRuntime(this, |
| 72 pp_instance(), | 72 pp_instance(), |
| 73 false, // No main_service_runtime. | 73 false, // No main_service_runtime. |
| 74 false, // No non-SFI mode (i.e. in SFI-mode). | 74 false, // No non-SFI mode (i.e. in SFI-mode). |
| 75 pp::BlockUntilComplete(), | |
| 76 pp::BlockUntilComplete()); | 75 pp::BlockUntilComplete()); |
| 77 subprocess->set_service_runtime(service_runtime); | 76 subprocess->set_service_runtime(service_runtime); |
| 78 | 77 |
| 79 // Now start the SelLdr instance. This must be created on the main thread. | 78 // Now start the SelLdr instance. This must be created on the main thread. |
| 80 bool service_runtime_started = false; | 79 bool service_runtime_started = false; |
| 81 pp::CompletionCallback sel_ldr_callback = | 80 pp::CompletionCallback sel_ldr_callback = |
| 82 callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone, | 81 callback_factory_.NewCallback(&Plugin::SignalStartSelLdrDone, |
| 83 &service_runtime_started, | 82 &service_runtime_started, |
| 84 service_runtime); | 83 service_runtime); |
| 85 pp::CompletionCallback callback = | 84 pp::CompletionCallback callback = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 ServiceRuntime* service_runtime) { | 120 ServiceRuntime* service_runtime) { |
| 122 *started = (pp_error == PP_OK); | 121 *started = (pp_error == PP_OK); |
| 123 service_runtime->SignalStartSelLdrDone(); | 122 service_runtime->SignalStartSelLdrDone(); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, | 125 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, |
| 127 bool uses_nonsfi_mode, | 126 bool uses_nonsfi_mode, |
| 128 bool enable_dyncode_syscalls, | 127 bool enable_dyncode_syscalls, |
| 129 bool enable_exception_handling, | 128 bool enable_exception_handling, |
| 130 bool enable_crash_throttling, | 129 bool enable_crash_throttling, |
| 131 const pp::CompletionCallback& init_done_cb, | 130 const pp::CompletionCallback& init_done_cb) { |
| 132 const pp::CompletionCallback& crash_cb) { | |
| 133 CHECK(pp::Module::Get()->core()->IsMainThread()); | 131 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 134 // Before forking a new sel_ldr process, ensure that we do not leak | 132 // Before forking a new sel_ldr process, ensure that we do not leak |
| 135 // the ServiceRuntime object for an existing subprocess, and that any | 133 // the ServiceRuntime object for an existing subprocess, and that any |
| 136 // associated listener threads do not go unjoined because if they | 134 // associated listener threads do not go unjoined because if they |
| 137 // outlive the Plugin object, they will not be memory safe. | 135 // outlive the Plugin object, they will not be memory safe. |
| 138 ShutDownSubprocesses(); | 136 ShutDownSubprocesses(); |
| 139 pp::Var manifest_base_url = | 137 pp::Var manifest_base_url = |
| 140 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); | 138 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); |
| 141 std::string manifest_base_url_str = manifest_base_url.AsString(); | 139 std::string manifest_base_url_str = manifest_base_url.AsString(); |
| 142 | 140 |
| 143 SelLdrStartParams params(manifest_base_url_str, | 141 SelLdrStartParams params(manifest_base_url_str, |
| 144 file_info, | 142 file_info, |
| 145 true /* uses_irt */, | 143 true /* uses_irt */, |
| 146 true /* uses_ppapi */, | 144 true /* uses_ppapi */, |
| 147 enable_dyncode_syscalls, | 145 enable_dyncode_syscalls, |
| 148 enable_exception_handling, | 146 enable_exception_handling, |
| 149 enable_crash_throttling); | 147 enable_crash_throttling); |
| 150 ErrorInfo error_info; | 148 ErrorInfo error_info; |
| 151 ServiceRuntime* service_runtime = new ServiceRuntime( | 149 ServiceRuntime* service_runtime = new ServiceRuntime( |
| 152 this, pp_instance(), true, uses_nonsfi_mode, init_done_cb, crash_cb); | 150 this, pp_instance(), true, uses_nonsfi_mode, init_done_cb); |
| 153 main_subprocess_.set_service_runtime(service_runtime); | 151 main_subprocess_.set_service_runtime(service_runtime); |
| 154 if (NULL == service_runtime) { | 152 if (NULL == service_runtime) { |
| 155 error_info.SetReport( | 153 error_info.SetReport( |
| 156 PP_NACL_ERROR_SEL_LDR_INIT, | 154 PP_NACL_ERROR_SEL_LDR_INIT, |
| 157 "sel_ldr init failure " + main_subprocess_.description()); | 155 "sel_ldr init failure " + main_subprocess_.description()); |
| 158 ReportLoadError(error_info); | 156 ReportLoadError(error_info); |
| 159 return; | 157 return; |
| 160 } | 158 } |
| 161 | 159 |
| 162 // We don't take any action once nexe loading has completed, so pass an empty | 160 // We don't take any action once nexe loading has completed, so pass an empty |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 327 |
| 330 void Plugin::NexeFileDidOpen(int32_t pp_error) { | 328 void Plugin::NexeFileDidOpen(int32_t pp_error) { |
| 331 if (pp_error != PP_OK) | 329 if (pp_error != PP_OK) |
| 332 return; | 330 return; |
| 333 LoadNaClModule( | 331 LoadNaClModule( |
| 334 nexe_file_info_, | 332 nexe_file_info_, |
| 335 uses_nonsfi_mode_, | 333 uses_nonsfi_mode_, |
| 336 true, /* enable_dyncode_syscalls */ | 334 true, /* enable_dyncode_syscalls */ |
| 337 true, /* enable_exception_handling */ | 335 true, /* enable_exception_handling */ |
| 338 false, /* enable_crash_throttling */ | 336 false, /* enable_crash_throttling */ |
| 339 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation), | 337 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation)); |
| 340 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); | |
| 341 } | 338 } |
| 342 | 339 |
| 343 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) { | 340 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) { |
| 344 UNREFERENCED_PARAMETER(pp_error); | 341 UNREFERENCED_PARAMETER(pp_error); |
| 345 NaClLog(4, "Entered NexeFileDidOpenContinuation\n"); | 342 NaClLog(4, "Entered NexeFileDidOpenContinuation\n"); |
| 346 if (LoadNaClModuleContinuationIntern()) { | 343 if (LoadNaClModuleContinuationIntern()) { |
| 347 NaClLog(4, "NexeFileDidOpenContinuation: success;" | 344 NaClLog(4, "NexeFileDidOpenContinuation: success;" |
| 348 " setting histograms\n"); | 345 " setting histograms\n"); |
| 349 int64_t nexe_size = nacl_interface_->GetNexeSize(pp_instance()); | 346 int64_t nexe_size = nacl_interface_->GetNexeSize(pp_instance()); |
| 350 nacl_interface_->ReportLoadSuccess( | 347 nacl_interface_->ReportLoadSuccess( |
| 351 pp_instance(), nexe_size, nexe_size); | 348 pp_instance(), nexe_size, nexe_size); |
| 352 } else { | 349 } else { |
| 353 NaClLog(4, "NexeFileDidOpenContinuation: failed."); | 350 NaClLog(4, "NexeFileDidOpenContinuation: failed."); |
| 354 } | 351 } |
| 355 NaClLog(4, "Leaving NexeFileDidOpenContinuation\n"); | 352 NaClLog(4, "Leaving NexeFileDidOpenContinuation\n"); |
| 356 } | 353 } |
| 357 | 354 |
| 358 void Plugin::NexeDidCrash(int32_t pp_error) { | |
| 359 PLUGIN_PRINTF(("Plugin::NexeDidCrash (pp_error=%" NACL_PRId32 ")\n", | |
| 360 pp_error)); | |
| 361 nacl_interface_->NexeDidCrash(pp_instance()); | |
| 362 } | |
| 363 | |
| 364 void Plugin::BitcodeDidTranslate(int32_t pp_error) { | 355 void Plugin::BitcodeDidTranslate(int32_t pp_error) { |
| 365 PLUGIN_PRINTF(("Plugin::BitcodeDidTranslate (pp_error=%" NACL_PRId32 ")\n", | 356 PLUGIN_PRINTF(("Plugin::BitcodeDidTranslate (pp_error=%" NACL_PRId32 ")\n", |
| 366 pp_error)); | 357 pp_error)); |
| 367 if (pp_error != PP_OK) { | 358 if (pp_error != PP_OK) { |
| 368 // Error should have been reported by pnacl. Just return. | 359 // Error should have been reported by pnacl. Just return. |
| 369 return; | 360 return; |
| 370 } | 361 } |
| 371 | 362 |
| 372 // Inform JavaScript that we successfully translated the bitcode to a nexe. | 363 // Inform JavaScript that we successfully translated the bitcode to a nexe. |
| 373 PP_FileHandle handle = pnacl_coordinator_->TakeTranslatedFileHandle(); | 364 PP_FileHandle handle = pnacl_coordinator_->TakeTranslatedFileHandle(); |
| 374 | 365 |
| 375 PP_NaClFileInfo info; | 366 PP_NaClFileInfo info; |
| 376 info.handle = handle; | 367 info.handle = handle; |
| 377 info.token_lo = 0; | 368 info.token_lo = 0; |
| 378 info.token_hi = 0; | 369 info.token_hi = 0; |
| 379 LoadNaClModule( | 370 LoadNaClModule( |
| 380 info, | 371 info, |
| 381 false, /* uses_nonsfi_mode */ | 372 false, /* uses_nonsfi_mode */ |
| 382 false, /* enable_dyncode_syscalls */ | 373 false, /* enable_dyncode_syscalls */ |
| 383 false, /* enable_exception_handling */ | 374 false, /* enable_exception_handling */ |
| 384 true, /* enable_crash_throttling */ | 375 true, /* enable_crash_throttling */ |
| 385 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation), | 376 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation)); |
| 386 callback_factory_.NewCallback(&Plugin::NexeDidCrash)); | |
| 387 } | 377 } |
| 388 | 378 |
| 389 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) { | 379 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) { |
| 390 NaClLog(4, "Entered BitcodeDidTranslateContinuation\n"); | 380 NaClLog(4, "Entered BitcodeDidTranslateContinuation\n"); |
| 391 UNREFERENCED_PARAMETER(pp_error); | 381 UNREFERENCED_PARAMETER(pp_error); |
| 392 if (LoadNaClModuleContinuationIntern()) { | 382 if (LoadNaClModuleContinuationIntern()) { |
| 393 int64_t loaded; | 383 int64_t loaded; |
| 394 int64_t total; | 384 int64_t total; |
| 395 // TODO(teravest): Tighten this up so we can get rid of | 385 // TODO(teravest): Tighten this up so we can get rid of |
| 396 // GetCurrentProgress(). loaded should always equal total. | 386 // GetCurrentProgress(). loaded should always equal total. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 error_info.message().c_str()); | 433 error_info.message().c_str()); |
| 444 } | 434 } |
| 445 | 435 |
| 446 bool Plugin::DocumentCanRequest(const std::string& url) { | 436 bool Plugin::DocumentCanRequest(const std::string& url) { |
| 447 CHECK(pp::Module::Get()->core()->IsMainThread()); | 437 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 448 CHECK(pp::URLUtil_Dev::Get() != NULL); | 438 CHECK(pp::URLUtil_Dev::Get() != NULL); |
| 449 return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url)); | 439 return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url)); |
| 450 } | 440 } |
| 451 | 441 |
| 452 } // namespace plugin | 442 } // namespace plugin |
| OLD | NEW |