| 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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "native_client/src/shared/platform/nacl_log.h" | 26 #include "native_client/src/shared/platform/nacl_log.h" |
| 27 #include "native_client/src/shared/platform/nacl_sync.h" | 27 #include "native_client/src/shared/platform/nacl_sync.h" |
| 28 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 28 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 29 #include "native_client/src/shared/platform/nacl_sync_raii.h" | 29 #include "native_client/src/shared/platform/nacl_sync_raii.h" |
| 30 #include "native_client/src/shared/platform/scoped_ptr_refcount.h" | 30 #include "native_client/src/shared/platform/scoped_ptr_refcount.h" |
| 31 #include "native_client/src/trusted/desc/nacl_desc_imc.h" | 31 #include "native_client/src/trusted/desc/nacl_desc_imc.h" |
| 32 #include "native_client/src/trusted/desc/nrd_xfer.h" | 32 #include "native_client/src/trusted/desc/nrd_xfer.h" |
| 33 #include "native_client/src/trusted/desc/nrd_xfer_effector.h" | 33 #include "native_client/src/trusted/desc/nrd_xfer_effector.h" |
| 34 #include "native_client/src/trusted/handle_pass/browser_handle.h" | 34 #include "native_client/src/trusted/handle_pass/browser_handle.h" |
| 35 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 35 #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" | 36 #include "native_client/src/trusted/plugin/manifest.h" |
| 43 | 37 |
| 44 // This is here due to a Windows API collision; plugin.h through | 38 // This is here due to a Windows API collision; plugin.h through |
| 45 // file_downloader.h transitively includes Instance.h which defines a | 39 // file_downloader.h transitively includes Instance.h which defines a |
| 46 // PostMessage method, so this undef must appear before any of those. | 40 // PostMessage method, so this undef must appear before any of those. |
| 47 #ifdef PostMessage | 41 #ifdef PostMessage |
| 48 #undef PostMessage | 42 #undef PostMessage |
| 49 #endif | 43 #endif |
| 50 #include "native_client/src/trusted/plugin/plugin.h" | 44 #include "native_client/src/trusted/plugin/plugin.h" |
| 51 #include "native_client/src/trusted/plugin/plugin_error.h" | 45 #include "native_client/src/trusted/plugin/plugin_error.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 130 } |
| 137 } | 131 } |
| 138 | 132 |
| 139 void PluginReverseInterface::Log_MainThreadContinuation( | 133 void PluginReverseInterface::Log_MainThreadContinuation( |
| 140 LogToJavaScriptConsoleResource* p, | 134 LogToJavaScriptConsoleResource* p, |
| 141 int32_t err) { | 135 int32_t err) { |
| 142 UNREFERENCED_PARAMETER(err); | 136 UNREFERENCED_PARAMETER(err); |
| 143 NaClLog(4, | 137 NaClLog(4, |
| 144 "PluginReverseInterface::Log_MainThreadContinuation(%s)\n", | 138 "PluginReverseInterface::Log_MainThreadContinuation(%s)\n", |
| 145 p->message.c_str()); | 139 p->message.c_str()); |
| 146 plugin_->browser_interface()->AddToConsole(static_cast<Plugin*>(plugin_), | 140 plugin_->AddToConsole(p->message); |
| 147 p->message); | |
| 148 } | 141 } |
| 149 void PluginReverseInterface::PostMessage_MainThreadContinuation( | 142 void PluginReverseInterface::PostMessage_MainThreadContinuation( |
| 150 PostMessageResource* p, | 143 PostMessageResource* p, |
| 151 int32_t err) { | 144 int32_t err) { |
| 152 UNREFERENCED_PARAMETER(err); | 145 UNREFERENCED_PARAMETER(err); |
| 153 NaClLog(4, | 146 NaClLog(4, |
| 154 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n", | 147 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n", |
| 155 p->message.c_str()); | 148 p->message.c_str()); |
| 156 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message); | 149 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message); |
| 157 } | 150 } |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 service_runtime_->set_exit_status(exit_status); | 373 service_runtime_->set_exit_status(exit_status); |
| 381 } | 374 } |
| 382 | 375 |
| 383 ServiceRuntime::ServiceRuntime(Plugin* plugin, | 376 ServiceRuntime::ServiceRuntime(Plugin* plugin, |
| 384 const Manifest* manifest, | 377 const Manifest* manifest, |
| 385 bool should_report_uma, | 378 bool should_report_uma, |
| 386 pp::CompletionCallback init_done_cb, | 379 pp::CompletionCallback init_done_cb, |
| 387 pp::CompletionCallback crash_cb) | 380 pp::CompletionCallback crash_cb) |
| 388 : plugin_(plugin), | 381 : plugin_(plugin), |
| 389 should_report_uma_(should_report_uma), | 382 should_report_uma_(should_report_uma), |
| 390 browser_interface_(plugin->browser_interface()), | |
| 391 reverse_service_(NULL), | 383 reverse_service_(NULL), |
| 392 subprocess_(NULL), | 384 subprocess_(NULL), |
| 393 async_receive_desc_(NULL), | |
| 394 async_send_desc_(NULL), | |
| 395 anchor_(new nacl::WeakRefAnchor()), | 385 anchor_(new nacl::WeakRefAnchor()), |
| 396 rev_interface_(new PluginReverseInterface(anchor_, plugin, | 386 rev_interface_(new PluginReverseInterface(anchor_, plugin, |
| 397 manifest, | 387 manifest, |
| 398 this, | 388 this, |
| 399 init_done_cb, crash_cb)), | 389 init_done_cb, crash_cb)), |
| 400 exit_status_(-1) { | 390 exit_status_(-1) { |
| 401 NaClSrpcChannelInitialize(&command_channel_); | 391 NaClSrpcChannelInitialize(&command_channel_); |
| 402 NaClXMutexCtor(&mu_); | 392 NaClXMutexCtor(&mu_); |
| 403 } | 393 } |
| 404 | 394 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 return false; | 511 return false; |
| 522 } | 512 } |
| 523 nacl::Handle sockets[3]; | 513 nacl::Handle sockets[3]; |
| 524 if (!tmp_subprocess->Start(NACL_ARRAY_SIZE(sockets), sockets)) { | 514 if (!tmp_subprocess->Start(NACL_ARRAY_SIZE(sockets), sockets)) { |
| 525 PLUGIN_PRINTF(("ServiceRuntime::Start (start failed)\n")); | 515 PLUGIN_PRINTF(("ServiceRuntime::Start (start failed)\n")); |
| 526 error_info->SetReport(ERROR_SEL_LDR_LAUNCH, | 516 error_info->SetReport(ERROR_SEL_LDR_LAUNCH, |
| 527 "ServiceRuntime: failed to start"); | 517 "ServiceRuntime: failed to start"); |
| 528 return false; | 518 return false; |
| 529 } | 519 } |
| 530 | 520 |
| 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()); | 521 subprocess_.reset(tmp_subprocess.release()); |
| 536 if (!InitCommunication(nacl_desc, error_info)) { | 522 if (!InitCommunication(nacl_desc, error_info)) { |
| 537 subprocess_.reset(NULL); | 523 subprocess_.reset(NULL); |
| 538 return false; | 524 return false; |
| 539 } | 525 } |
| 540 | 526 |
| 541 PLUGIN_PRINTF(("ServiceRuntime::Start (return 1)\n")); | 527 PLUGIN_PRINTF(("ServiceRuntime::Start (return 1)\n")); |
| 542 return true; | 528 return true; |
| 543 } | 529 } |
| 544 | 530 |
| 545 SrpcClient* ServiceRuntime::SetupAppChannel() { | 531 SrpcClient* ServiceRuntime::SetupAppChannel() { |
| 546 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", | 532 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (subprocess_=%p)\n", |
| 547 reinterpret_cast<void*>(subprocess_.get()))); | 533 reinterpret_cast<void*>(subprocess_.get()))); |
| 548 nacl::DescWrapper* connect_desc = subprocess_->socket_addr()->Connect(); | 534 nacl::DescWrapper* connect_desc = subprocess_->socket_addr()->Connect(); |
| 549 if (NULL == connect_desc) { | 535 if (NULL == connect_desc) { |
| 550 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (connect failed)\n")); | 536 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (connect failed)\n")); |
| 551 return NULL; | 537 return NULL; |
| 552 } else { | 538 } else { |
| 553 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (conect_desc=%p)\n", | 539 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (conect_desc=%p)\n", |
| 554 static_cast<void*>(connect_desc))); | 540 static_cast<void*>(connect_desc))); |
| 555 SrpcClient* srpc_client = SrpcClient::New(plugin(), connect_desc); | 541 SrpcClient* srpc_client = SrpcClient::New(connect_desc); |
| 556 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (srpc_client=%p)\n", | 542 PLUGIN_PRINTF(("ServiceRuntime::SetupAppChannel (srpc_client=%p)\n", |
| 557 static_cast<void*>(srpc_client))); | 543 static_cast<void*>(srpc_client))); |
| 558 delete connect_desc; | 544 delete connect_desc; |
| 559 return srpc_client; | 545 return srpc_client; |
| 560 } | 546 } |
| 561 } | 547 } |
| 562 | 548 |
| 563 bool ServiceRuntime::Kill() { | 549 bool ServiceRuntime::Kill() { |
| 564 return subprocess_->KillChildProcess(); | 550 return subprocess_->KillChildProcess(); |
| 565 } | 551 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 nacl::MutexLocker take(&mu_); | 608 nacl::MutexLocker take(&mu_); |
| 623 return exit_status_; | 609 return exit_status_; |
| 624 } | 610 } |
| 625 | 611 |
| 626 void ServiceRuntime::set_exit_status(int exit_status) { | 612 void ServiceRuntime::set_exit_status(int exit_status) { |
| 627 nacl::MutexLocker take(&mu_); | 613 nacl::MutexLocker take(&mu_); |
| 628 exit_status_ = exit_status & 0xff; | 614 exit_status_ = exit_status & 0xff; |
| 629 } | 615 } |
| 630 | 616 |
| 631 } // namespace plugin | 617 } // namespace plugin |
| OLD | NEW |