| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #define NACL_LOG_MODULE_NAME "Plugin::ServiceRuntime" | 7 #define NACL_LOG_MODULE_NAME "Plugin::ServiceRuntime" |
| 8 | 8 |
| 9 #include "native_client/src/trusted/plugin/service_runtime.h" | 9 #include "native_client/src/trusted/plugin/service_runtime.h" |
| 10 | 10 |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 #include <map> | |
| 13 #include <set> | 12 #include <set> |
| 14 #include <string> | 13 #include <string> |
| 15 #include <utility> | 14 #include <utility> |
| 16 #include <vector> | |
| 17 | 15 |
| 18 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 19 | 17 |
| 20 #include "native_client/src/include/portability_io.h" | 18 #include "native_client/src/include/portability_io.h" |
| 21 #include "native_client/src/include/nacl_macros.h" | 19 #include "native_client/src/include/nacl_macros.h" |
| 22 #include "native_client/src/include/nacl_scoped_ptr.h" | 20 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 23 #include "native_client/src/include/nacl_string.h" | 21 #include "native_client/src/include/nacl_string.h" |
| 24 #include "native_client/src/shared/imc/nacl_imc.h" | 22 #include "native_client/src/shared/imc/nacl_imc.h" |
| 25 #include "native_client/src/shared/platform/nacl_check.h" | 23 #include "native_client/src/shared/platform/nacl_check.h" |
| 26 #include "native_client/src/shared/platform/nacl_log.h" | 24 #include "native_client/src/shared/platform/nacl_log.h" |
| 27 #include "native_client/src/shared/platform/nacl_sync.h" | 25 #include "native_client/src/shared/platform/nacl_sync.h" |
| 28 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 26 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 29 #include "native_client/src/shared/platform/nacl_sync_raii.h" | 27 #include "native_client/src/shared/platform/nacl_sync_raii.h" |
| 30 #include "native_client/src/shared/platform/scoped_ptr_refcount.h" | 28 #include "native_client/src/shared/platform/scoped_ptr_refcount.h" |
| 31 #include "native_client/src/trusted/desc/nacl_desc_imc.h" | 29 #include "native_client/src/trusted/desc/nacl_desc_imc.h" |
| 32 #include "native_client/src/trusted/desc/nrd_xfer.h" | 30 #include "native_client/src/trusted/desc/nrd_xfer.h" |
| 33 #include "native_client/src/trusted/desc/nrd_xfer_effector.h" | 31 #include "native_client/src/trusted/desc/nrd_xfer_effector.h" |
| 34 #include "native_client/src/trusted/handle_pass/browser_handle.h" | 32 #include "native_client/src/trusted/handle_pass/browser_handle.h" |
| 35 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 33 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
| 36 | |
| 37 // browser_interface includes portability.h for uintptr_t etc, but it | |
| 38 // also transitively includes windows.h, where PostMessage gets | |
| 39 // defined as a preprocessor symbol | |
| 40 #include "native_client/src/trusted/plugin/browser_interface.h" | |
| 41 | |
| 42 #include "native_client/src/trusted/plugin/manifest.h" | 34 #include "native_client/src/trusted/plugin/manifest.h" |
| 43 | 35 |
| 44 // This is here due to a Windows API collision; plugin.h through | 36 // This is here due to a Windows API collision; plugin.h through |
| 45 // file_downloader.h transitively includes Instance.h which defines a | 37 // file_downloader.h transitively includes Instance.h which defines a |
| 46 // PostMessage method, so this undef must appear before any of those. | 38 // PostMessage method, so this undef must appear before any of those. |
| 47 #ifdef PostMessage | 39 #ifdef PostMessage |
| 48 #undef PostMessage | 40 #undef PostMessage |
| 49 #endif | 41 #endif |
| 50 #include "native_client/src/trusted/plugin/plugin.h" | 42 #include "native_client/src/trusted/plugin/plugin.h" |
| 51 #include "native_client/src/trusted/plugin/plugin_error.h" | 43 #include "native_client/src/trusted/plugin/plugin_error.h" |
| 52 #include "native_client/src/trusted/plugin/scriptable_handle.h" | |
| 53 #include "native_client/src/trusted/plugin/srpc_client.h" | 44 #include "native_client/src/trusted/plugin/srpc_client.h" |
| 54 #include "native_client/src/trusted/plugin/utility.h" | 45 #include "native_client/src/trusted/plugin/utility.h" |
| 55 | 46 |
| 56 #include "native_client/src/trusted/weak_ref/call_on_main_thread.h" | 47 #include "native_client/src/trusted/weak_ref/call_on_main_thread.h" |
| 57 | 48 |
| 58 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 49 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
| 59 #include "native_client/src/trusted/service_runtime/include/sys/nacl_imc_api.h" | 50 #include "native_client/src/trusted/service_runtime/include/sys/nacl_imc_api.h" |
| 60 | 51 |
| 61 #include "ppapi/c/pp_errors.h" | 52 #include "ppapi/c/pp_errors.h" |
| 62 #include "ppapi/cpp/core.h" | 53 #include "ppapi/cpp/core.h" |
| 63 #include "ppapi/cpp/completion_callback.h" | 54 #include "ppapi/cpp/completion_callback.h" |
| 64 | 55 |
| 65 using std::vector; | |
| 66 | |
| 67 namespace plugin { | 56 namespace plugin { |
| 68 | 57 |
| 69 PluginReverseInterface::PluginReverseInterface( | 58 PluginReverseInterface::PluginReverseInterface( |
| 70 nacl::WeakRefAnchor* anchor, | 59 nacl::WeakRefAnchor* anchor, |
| 71 Plugin* plugin, | 60 Plugin* plugin, |
| 72 const Manifest* manifest, | 61 const Manifest* manifest, |
| 73 ServiceRuntime* service_runtime, | 62 ServiceRuntime* service_runtime, |
| 74 pp::CompletionCallback init_done_cb, | 63 pp::CompletionCallback init_done_cb, |
| 75 pp::CompletionCallback crash_cb) | 64 pp::CompletionCallback crash_cb) |
| 76 : anchor_(anchor), | 65 : anchor_(anchor), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 125 } |
| 137 } | 126 } |
| 138 | 127 |
| 139 void PluginReverseInterface::Log_MainThreadContinuation( | 128 void PluginReverseInterface::Log_MainThreadContinuation( |
| 140 LogToJavaScriptConsoleResource* p, | 129 LogToJavaScriptConsoleResource* p, |
| 141 int32_t err) { | 130 int32_t err) { |
| 142 UNREFERENCED_PARAMETER(err); | 131 UNREFERENCED_PARAMETER(err); |
| 143 NaClLog(4, | 132 NaClLog(4, |
| 144 "PluginReverseInterface::Log_MainThreadContinuation(%s)\n", | 133 "PluginReverseInterface::Log_MainThreadContinuation(%s)\n", |
| 145 p->message.c_str()); | 134 p->message.c_str()); |
| 146 plugin_->browser_interface()->AddToConsole(static_cast<Plugin*>(plugin_), | 135 plugin_->AddToConsole(p->message); |
| 147 p->message); | |
| 148 } | 136 } |
| 149 void PluginReverseInterface::PostMessage_MainThreadContinuation( | 137 void PluginReverseInterface::PostMessage_MainThreadContinuation( |
| 150 PostMessageResource* p, | 138 PostMessageResource* p, |
| 151 int32_t err) { | 139 int32_t err) { |
| 152 UNREFERENCED_PARAMETER(err); | 140 UNREFERENCED_PARAMETER(err); |
| 153 NaClLog(4, | 141 NaClLog(4, |
| 154 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n", | 142 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n", |
| 155 p->message.c_str()); | 143 p->message.c_str()); |
| 156 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message); | 144 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message); |
| 157 } | 145 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 service_runtime_->set_exit_status(exit_status); | 368 service_runtime_->set_exit_status(exit_status); |
| 381 } | 369 } |
| 382 | 370 |
| 383 ServiceRuntime::ServiceRuntime(Plugin* plugin, | 371 ServiceRuntime::ServiceRuntime(Plugin* plugin, |
| 384 const Manifest* manifest, | 372 const Manifest* manifest, |
| 385 bool should_report_uma, | 373 bool should_report_uma, |
| 386 pp::CompletionCallback init_done_cb, | 374 pp::CompletionCallback init_done_cb, |
| 387 pp::CompletionCallback crash_cb) | 375 pp::CompletionCallback crash_cb) |
| 388 : plugin_(plugin), | 376 : plugin_(plugin), |
| 389 should_report_uma_(should_report_uma), | 377 should_report_uma_(should_report_uma), |
| 390 browser_interface_(plugin->browser_interface()), | |
| 391 reverse_service_(NULL), | 378 reverse_service_(NULL), |
| 392 subprocess_(NULL), | 379 subprocess_(NULL), |
| 393 async_receive_desc_(NULL), | |
| 394 async_send_desc_(NULL), | |
| 395 anchor_(new nacl::WeakRefAnchor()), | 380 anchor_(new nacl::WeakRefAnchor()), |
| 396 rev_interface_(new PluginReverseInterface(anchor_, plugin, | 381 rev_interface_(new PluginReverseInterface(anchor_, plugin, |
| 397 manifest, | 382 manifest, |
| 398 this, | 383 this, |
| 399 init_done_cb, crash_cb)), | 384 init_done_cb, crash_cb)), |
| 400 exit_status_(-1) { | 385 exit_status_(-1) { |
| 401 NaClSrpcChannelInitialize(&command_channel_); | 386 NaClSrpcChannelInitialize(&command_channel_); |
| 402 NaClXMutexCtor(&mu_); | 387 NaClXMutexCtor(&mu_); |
| 403 } | 388 } |
| 404 | 389 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 491 } |
| 507 return true; | 492 return true; |
| 508 } | 493 } |
| 509 | 494 |
| 510 bool ServiceRuntime::Start(nacl::DescWrapper* nacl_desc, | 495 bool ServiceRuntime::Start(nacl::DescWrapper* nacl_desc, |
| 511 ErrorInfo* error_info) { | 496 ErrorInfo* error_info) { |
| 512 PLUGIN_PRINTF(("ServiceRuntime::Start (nacl_desc=%p)\n", | 497 PLUGIN_PRINTF(("ServiceRuntime::Start (nacl_desc=%p)\n", |
| 513 reinterpret_cast<void*>(nacl_desc))); | 498 reinterpret_cast<void*>(nacl_desc))); |
| 514 | 499 |
| 515 nacl::scoped_ptr<nacl::SelLdrLauncher> | 500 nacl::scoped_ptr<nacl::SelLdrLauncher> |
| 516 tmp_subprocess(new(std::nothrow) nacl::SelLdrLauncher()); | 501 tmp_subprocess(new nacl::SelLdrLauncher()); |
| 517 if (NULL == tmp_subprocess.get()) { | 502 if (NULL == tmp_subprocess.get()) { |
| 518 PLUGIN_PRINTF(("ServiceRuntime::Start (subprocess create failed)\n")); | 503 PLUGIN_PRINTF(("ServiceRuntime::Start (subprocess create failed)\n")); |
| 519 error_info->SetReport(ERROR_SEL_LDR_CREATE_LAUNCHER, | 504 error_info->SetReport(ERROR_SEL_LDR_CREATE_LAUNCHER, |
| 520 "ServiceRuntime: failed to create sel_ldr launcher"); | 505 "ServiceRuntime: failed to create sel_ldr launcher"); |
| 521 return false; | 506 return false; |
| 522 } | 507 } |
| 523 nacl::Handle sockets[3]; | 508 nacl::Handle sockets[3]; |
| 524 if (!tmp_subprocess->Start(NACL_ARRAY_SIZE(sockets), sockets)) { | 509 if (!tmp_subprocess->Start(NACL_ARRAY_SIZE(sockets), sockets)) { |
| 525 PLUGIN_PRINTF(("ServiceRuntime::Start (start failed)\n")); | 510 PLUGIN_PRINTF(("ServiceRuntime::Start (start failed)\n")); |
| 526 error_info->SetReport(ERROR_SEL_LDR_LAUNCH, | 511 error_info->SetReport(ERROR_SEL_LDR_LAUNCH, |
| 527 "ServiceRuntime: failed to start"); | 512 "ServiceRuntime: failed to start"); |
| 528 return false; | 513 return false; |
| 529 } | 514 } |
| 530 | 515 |
| 531 async_receive_desc_.reset( | |
| 532 plugin()->wrapper_factory()->MakeImcSock(sockets[1])); | |
| 533 async_send_desc_.reset(plugin()->wrapper_factory()->MakeImcSock(sockets[2])); | |
| 534 | |
| 535 subprocess_.reset(tmp_subprocess.release()); | 516 subprocess_.reset(tmp_subprocess.release()); |
| 536 if (!InitCommunication(nacl_desc, error_info)) { | 517 if (!InitCommunication(nacl_desc, error_info)) { |
| 537 subprocess_.reset(NULL); | 518 subprocess_.reset(NULL); |
| 538 return false; | 519 return false; |
| 539 } | 520 } |
| 540 | 521 |
| 541 PLUGIN_PRINTF(("ServiceRuntime::Start (return 1)\n")); | 522 PLUGIN_PRINTF(("ServiceRuntime::Start (return 1)\n")); |
| 542 return true; | 523 return true; |
| 543 } | 524 } |
| 544 | 525 |
| 545 SrpcClient* ServiceRuntime::SetupAppChannel() { | 526 SrpcClient* ServiceRuntime::SetupAppChannel() { |
| 546 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", | 527 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", |
| 547 reinterpret_cast<void*>(subprocess_.get()))); | 528 reinterpret_cast<void*>(subprocess_.get()))); |
| 548 nacl::DescWrapper* connect_desc = subprocess_->socket_addr()->Connect(); | 529 nacl::DescWrapper* connect_desc = subprocess_->socket_addr()->Connect(); |
| 549 if (NULL == connect_desc) { | 530 if (NULL == connect_desc) { |
| 550 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (connect failed)\n")); | 531 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (connect failed)\n")); |
| 551 return NULL; | 532 return NULL; |
| 552 } else { | 533 } else { |
| 553 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (conect_desc=%p)\n", | 534 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (conect_desc=%p)\n", |
| 554 static_cast<void*>(connect_desc))); | 535 static_cast<void*>(connect_desc))); |
| 555 SrpcClient* srpc_client = SrpcClient::New(plugin(), connect_desc); | 536 SrpcClient* srpc_client = SrpcClient::New(connect_desc); |
| 556 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (srpc_client=%p)\n", | 537 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (srpc_client=%p)\n", |
| 557 static_cast<void*>(srpc_client))); | 538 static_cast<void*>(srpc_client))); |
| 558 delete connect_desc; | 539 delete connect_desc; |
| 559 return srpc_client; | 540 return srpc_client; |
| 560 } | 541 } |
| 561 } | 542 } |
| 562 | 543 |
| 563 bool ServiceRuntime::Kill() { | 544 bool ServiceRuntime::Kill() { |
| 564 return subprocess_->KillChildProcess(); | 545 return subprocess_->KillChildProcess(); |
| 565 } | 546 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 nacl::MutexLocker take(&mu_); | 603 nacl::MutexLocker take(&mu_); |
| 623 return exit_status_; | 604 return exit_status_; |
| 624 } | 605 } |
| 625 | 606 |
| 626 void ServiceRuntime::set_exit_status(int exit_status) { | 607 void ServiceRuntime::set_exit_status(int exit_status) { |
| 627 nacl::MutexLocker take(&mu_); | 608 nacl::MutexLocker take(&mu_); |
| 628 exit_status_ = exit_status & 0xff; | 609 exit_status_ = exit_status & 0xff; |
| 629 } | 610 } |
| 630 | 611 |
| 631 } // namespace plugin | 612 } // namespace plugin |
| OLD | NEW |