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