| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 void Plugin::SignalStartSelLdrDone(int32_t pp_error, | 112 void Plugin::SignalStartSelLdrDone(int32_t pp_error, |
| 113 bool* started, | 113 bool* started, |
| 114 ServiceRuntime* service_runtime) { | 114 ServiceRuntime* service_runtime) { |
| 115 *started = (pp_error == PP_OK); | 115 *started = (pp_error == PP_OK); |
| 116 service_runtime->SignalStartSelLdrDone(); | 116 service_runtime->SignalStartSelLdrDone(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, | 119 void Plugin::LoadNaClModule(PP_NaClFileInfo file_info, |
| 120 PP_NaClResourceFileHandle* resource_file_handles, |
| 120 bool uses_nonsfi_mode, | 121 bool uses_nonsfi_mode, |
| 121 PP_NaClAppProcessType process_type, | 122 PP_NaClAppProcessType process_type, |
| 122 const pp::CompletionCallback& init_done_cb) { | 123 const pp::CompletionCallback& init_done_cb) { |
| 123 CHECK(pp::Module::Get()->core()->IsMainThread()); | 124 CHECK(pp::Module::Get()->core()->IsMainThread()); |
| 124 // Before forking a new sel_ldr process, ensure that we do not leak | 125 // Before forking a new sel_ldr process, ensure that we do not leak |
| 125 // the ServiceRuntime object for an existing subprocess, and that any | 126 // the ServiceRuntime object for an existing subprocess, and that any |
| 126 // associated listener threads do not go unjoined because if they | 127 // associated listener threads do not go unjoined because if they |
| 127 // outlive the Plugin object, they will not be memory safe. | 128 // outlive the Plugin object, they will not be memory safe. |
| 128 ShutDownSubprocesses(); | 129 ShutDownSubprocesses(); |
| 129 pp::Var manifest_base_url = | 130 pp::Var manifest_base_url = |
| 130 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); | 131 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); |
| 131 std::string manifest_base_url_str = manifest_base_url.AsString(); | 132 std::string manifest_base_url_str = manifest_base_url.AsString(); |
| 132 | 133 |
| 133 SelLdrStartParams params(manifest_base_url_str, | 134 SelLdrStartParams params(manifest_base_url_str, |
| 134 file_info, | 135 file_info, |
| 136 resource_file_handles, |
| 135 process_type); | 137 process_type); |
| 136 ErrorInfo error_info; | 138 ErrorInfo error_info; |
| 137 ServiceRuntime* service_runtime = new ServiceRuntime( | 139 ServiceRuntime* service_runtime = new ServiceRuntime( |
| 138 this, pp_instance(), true, uses_nonsfi_mode, init_done_cb); | 140 this, pp_instance(), true, uses_nonsfi_mode, init_done_cb); |
| 139 main_subprocess_.set_service_runtime(service_runtime); | 141 main_subprocess_.set_service_runtime(service_runtime); |
| 140 if (NULL == service_runtime) { | 142 if (NULL == service_runtime) { |
| 141 error_info.SetReport( | 143 error_info.SetReport( |
| 142 PP_NACL_ERROR_SEL_LDR_INIT, | 144 PP_NACL_ERROR_SEL_LDR_INIT, |
| 143 "sel_ldr init failure " + main_subprocess_.description()); | 145 "sel_ldr init failure " + main_subprocess_.description()); |
| 144 ReportLoadError(error_info); | 146 ReportLoadError(error_info); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 "unable to allocate helper subprocess."); | 192 "unable to allocate helper subprocess."); |
| 191 return NULL; | 193 return NULL; |
| 192 } | 194 } |
| 193 | 195 |
| 194 // Do not report UMA stats for translator-related nexes. | 196 // Do not report UMA stats for translator-related nexes. |
| 195 // TODO(sehr): define new UMA stats for translator related nexe events. | 197 // TODO(sehr): define new UMA stats for translator related nexe events. |
| 196 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is | 198 // NOTE: The PNaCl translator nexes are not built to use the IRT. This is |
| 197 // done to save on address space and swap space. | 199 // done to save on address space and swap space. |
| 198 SelLdrStartParams params(helper_url, | 200 SelLdrStartParams params(helper_url, |
| 199 file_info, | 201 file_info, |
| 202 NULL, |
| 200 PP_PNACL_TRANSLATOR_PROCESS_TYPE); | 203 PP_PNACL_TRANSLATOR_PROCESS_TYPE); |
| 201 | 204 |
| 202 // Helper NaCl modules always use the PNaCl manifest, as there is no | 205 // Helper NaCl modules always use the PNaCl manifest, as there is no |
| 203 // corresponding NMF. | 206 // corresponding NMF. |
| 204 if (!LoadHelperNaClModuleInternal(nacl_subprocess.get(), params)) | 207 if (!LoadHelperNaClModuleInternal(nacl_subprocess.get(), params)) |
| 205 return NULL; | 208 return NULL; |
| 206 | 209 |
| 207 // We need not wait for the init_done callback. We can block | 210 // We need not wait for the init_done callback. We can block |
| 208 // here in StartSrpcServices, since helper NaCl modules | 211 // here in StartSrpcServices, since helper NaCl modules |
| 209 // are spawned from a private thread. | 212 // are spawned from a private thread. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 nacl_interface_->RequestNaClManifest(pp_instance(), | 244 nacl_interface_->RequestNaClManifest(pp_instance(), |
| 242 open_cb.pp_completion_callback()); | 245 open_cb.pp_completion_callback()); |
| 243 return true; | 246 return true; |
| 244 } | 247 } |
| 245 | 248 |
| 246 Plugin::Plugin(PP_Instance pp_instance) | 249 Plugin::Plugin(PP_Instance pp_instance) |
| 247 : pp::Instance(pp_instance), | 250 : pp::Instance(pp_instance), |
| 248 main_subprocess_("main subprocess", NULL, NULL), | 251 main_subprocess_("main subprocess", NULL, NULL), |
| 249 uses_nonsfi_mode_(false), | 252 uses_nonsfi_mode_(false), |
| 250 wrapper_factory_(NULL), | 253 wrapper_factory_(NULL), |
| 254 resource_file_handles_(NULL), |
| 251 nacl_interface_(NULL), | 255 nacl_interface_(NULL), |
| 252 uma_interface_(this) { | 256 uma_interface_(this) { |
| 253 callback_factory_.Initialize(this); | 257 callback_factory_.Initialize(this); |
| 254 nacl_interface_ = GetNaClInterface(); | 258 nacl_interface_ = GetNaClInterface(); |
| 255 CHECK(nacl_interface_ != NULL); | 259 CHECK(nacl_interface_ != NULL); |
| 256 | 260 |
| 257 // Notify PPB_NaCl_Private that the instance is created before altering any | 261 // Notify PPB_NaCl_Private that the instance is created before altering any |
| 258 // state that it tracks. | 262 // state that it tracks. |
| 259 nacl_interface_->InstanceCreated(pp_instance); | 263 nacl_interface_->InstanceCreated(pp_instance); |
| 260 nexe_file_info_ = kInvalidNaClFileInfo; | 264 nexe_file_info_ = kInvalidNaClFileInfo; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 289 // | 293 // |
| 290 // The main_subprocess object, which wraps the main service_runtime | 294 // The main_subprocess object, which wraps the main service_runtime |
| 291 // object, is dtor'd implicitly after the explicit code below runs, | 295 // object, is dtor'd implicitly after the explicit code below runs, |
| 292 // so the main service runtime object will not have been dtor'd, | 296 // so the main service runtime object will not have been dtor'd, |
| 293 // though the Shutdown method may have been called, during the | 297 // though the Shutdown method may have been called, during the |
| 294 // lifetime of the service threads. | 298 // lifetime of the service threads. |
| 295 ShutDownSubprocesses(); | 299 ShutDownSubprocesses(); |
| 296 | 300 |
| 297 delete wrapper_factory_; | 301 delete wrapper_factory_; |
| 298 | 302 |
| 303 if (resource_file_handles_) { |
| 304 for (size_t i = 0; |
| 305 resource_file_handles_[i].handle != PP_kInvalidFileHandle; ++i) { |
| 306 free(resource_file_handles_[i].key); |
| 307 } |
| 308 delete[] resource_file_handles_; |
| 309 } |
| 310 |
| 299 HistogramTimeSmall( | 311 HistogramTimeSmall( |
| 300 "NaCl.Perf.ShutdownTime.Total", | 312 "NaCl.Perf.ShutdownTime.Total", |
| 301 (NaClGetTimeOfDayMicroseconds() - shutdown_start) | 313 (NaClGetTimeOfDayMicroseconds() - shutdown_start) |
| 302 / NACL_MICROS_PER_MILLI); | 314 / NACL_MICROS_PER_MILLI); |
| 303 } | 315 } |
| 304 | 316 |
| 305 bool Plugin::HandleDocumentLoad(const pp::URLLoader& url_loader) { | 317 bool Plugin::HandleDocumentLoad(const pp::URLLoader& url_loader) { |
| 306 // We don't know if the plugin will handle the document load, but return | 318 // We don't know if the plugin will handle the document load, but return |
| 307 // true in order to give it a chance to respond once the proxy is started. | 319 // true in order to give it a chance to respond once the proxy is started. |
| 308 return true; | 320 return true; |
| 309 } | 321 } |
| 310 | 322 |
| 311 void Plugin::NexeFileDidOpen(int32_t pp_error) { | 323 void Plugin::NexeFileDidOpen(int32_t pp_error) { |
| 312 if (pp_error != PP_OK) | 324 if (pp_error != PP_OK) |
| 313 return; | 325 return; |
| 314 LoadNaClModule( | 326 LoadNaClModule( |
| 315 nexe_file_info_, | 327 nexe_file_info_, |
| 328 resource_file_handles_, |
| 316 uses_nonsfi_mode_, | 329 uses_nonsfi_mode_, |
| 317 PP_NATIVE_NACL_PROCESS_TYPE, | 330 PP_NATIVE_NACL_PROCESS_TYPE, |
| 318 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation)); | 331 callback_factory_.NewCallback(&Plugin::NexeFileDidOpenContinuation)); |
| 319 } | 332 } |
| 320 | 333 |
| 321 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) { | 334 void Plugin::NexeFileDidOpenContinuation(int32_t pp_error) { |
| 322 UNREFERENCED_PARAMETER(pp_error); | 335 UNREFERENCED_PARAMETER(pp_error); |
| 323 NaClLog(4, "Entered NexeFileDidOpenContinuation\n"); | 336 NaClLog(4, "Entered NexeFileDidOpenContinuation\n"); |
| 324 if (LoadNaClModuleContinuationIntern()) { | 337 if (LoadNaClModuleContinuationIntern()) { |
| 325 NaClLog(4, "NexeFileDidOpenContinuation: success;" | 338 NaClLog(4, "NexeFileDidOpenContinuation: success;" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 343 | 356 |
| 344 // Inform JavaScript that we successfully translated the bitcode to a nexe. | 357 // Inform JavaScript that we successfully translated the bitcode to a nexe. |
| 345 PP_FileHandle handle = pnacl_coordinator_->TakeTranslatedFileHandle(); | 358 PP_FileHandle handle = pnacl_coordinator_->TakeTranslatedFileHandle(); |
| 346 | 359 |
| 347 PP_NaClFileInfo info; | 360 PP_NaClFileInfo info; |
| 348 info.handle = handle; | 361 info.handle = handle; |
| 349 info.token_lo = 0; | 362 info.token_lo = 0; |
| 350 info.token_hi = 0; | 363 info.token_hi = 0; |
| 351 LoadNaClModule( | 364 LoadNaClModule( |
| 352 info, | 365 info, |
| 366 NULL, |
| 353 false, /* uses_nonsfi_mode */ | 367 false, /* uses_nonsfi_mode */ |
| 354 PP_PNACL_PROCESS_TYPE, | 368 PP_PNACL_PROCESS_TYPE, |
| 355 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation)); | 369 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslateContinuation)); |
| 356 } | 370 } |
| 357 | 371 |
| 358 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) { | 372 void Plugin::BitcodeDidTranslateContinuation(int32_t pp_error) { |
| 359 NaClLog(4, "Entered BitcodeDidTranslateContinuation\n"); | 373 NaClLog(4, "Entered BitcodeDidTranslateContinuation\n"); |
| 360 UNREFERENCED_PARAMETER(pp_error); | 374 UNREFERENCED_PARAMETER(pp_error); |
| 361 if (LoadNaClModuleContinuationIntern()) { | 375 if (LoadNaClModuleContinuationIntern()) { |
| 362 int64_t loaded; | 376 int64_t loaded; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 392 program_url, | 406 program_url, |
| 393 pnacl_options, | 407 pnacl_options, |
| 394 translate_callback)); | 408 translate_callback)); |
| 395 return; | 409 return; |
| 396 } else { | 410 } else { |
| 397 pp::CompletionCallback open_callback = | 411 pp::CompletionCallback open_callback = |
| 398 callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); | 412 callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); |
| 399 // Will always call the callback on success or failure. | 413 // Will always call the callback on success or failure. |
| 400 nacl_interface_->DownloadNexe(pp_instance(), | 414 nacl_interface_->DownloadNexe(pp_instance(), |
| 401 program_url.c_str(), | 415 program_url.c_str(), |
| 416 // pre-open resource files on nonsfi mode |
| 417 // TODO(yusukes): Enable the feature for |
| 418 // SFI-NaCl too. |
| 419 uses_nonsfi_mode, |
| 402 &nexe_file_info_, | 420 &nexe_file_info_, |
| 421 &resource_file_handles_, |
| 403 open_callback.pp_completion_callback()); | 422 open_callback.pp_completion_callback()); |
| 404 return; | 423 return; |
| 405 } | 424 } |
| 406 } | 425 } |
| 407 } | 426 } |
| 408 | 427 |
| 409 void Plugin::ReportLoadError(const ErrorInfo& error_info) { | 428 void Plugin::ReportLoadError(const ErrorInfo& error_info) { |
| 410 nacl_interface_->ReportLoadError(pp_instance(), | 429 nacl_interface_->ReportLoadError(pp_instance(), |
| 411 error_info.error_code(), | 430 error_info.error_code(), |
| 412 error_info.message().c_str()); | 431 error_info.message().c_str()); |
| 413 } | 432 } |
| 414 | 433 |
| 415 } // namespace plugin | 434 } // namespace plugin |
| OLD | NEW |