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 "chrome/browser/nacl_host/nacl_process_host.h" | 5 #include "chrome/browser/nacl_host/nacl_process_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 // for this use case. | 138 // for this use case. |
139 process_->SetName(net::FormatUrl(manifest_url_, std::string())); | 139 process_->SetName(net::FormatUrl(manifest_url_, std::string())); |
140 | 140 |
141 // We allow untrusted hardware exception handling to be enabled via | 141 // We allow untrusted hardware exception handling to be enabled via |
142 // an env var for consistency with the standalone build of NaCl. | 142 // an env var for consistency with the standalone build of NaCl. |
143 if (CommandLine::ForCurrentProcess()->HasSwitch( | 143 if (CommandLine::ForCurrentProcess()->HasSwitch( |
144 switches::kEnableNaClExceptionHandling) || | 144 switches::kEnableNaClExceptionHandling) || |
145 getenv("NACL_UNTRUSTED_EXCEPTION_HANDLING") != NULL) { | 145 getenv("NACL_UNTRUSTED_EXCEPTION_HANDLING") != NULL) { |
146 enable_exception_handling_ = true; | 146 enable_exception_handling_ = true; |
147 } | 147 } |
148 | |
149 enable_ipc_proxy_ = | |
150 CommandLine::ForCurrentProcess()->HasSwitch( | |
Mark Seaborn
2012/06/21 19:49:49
Nit: this would fit on the previous line
bbudge
2012/06/21 21:20:01
Done.
| |
151 switches::kEnableNaClIPCProxy); | |
148 } | 152 } |
149 | 153 |
150 NaClProcessHost::~NaClProcessHost() { | 154 NaClProcessHost::~NaClProcessHost() { |
151 int exit_code; | 155 int exit_code; |
152 process_->GetTerminationStatus(&exit_code); | 156 process_->GetTerminationStatus(&exit_code); |
153 std::string message = | 157 std::string message = |
154 base::StringPrintf("NaCl process exited with status %i (0x%x)", | 158 base::StringPrintf("NaCl process exited with status %i (0x%x)", |
155 exit_code, exit_code); | 159 exit_code, exit_code); |
156 if (exit_code == 0) { | 160 if (exit_code == 0) { |
157 LOG(INFO) << message; | 161 LOG(INFO) << message; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 bool handled = true; | 534 bool handled = true; |
531 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) | 535 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) |
532 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, | 536 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, |
533 OnQueryKnownToValidate) | 537 OnQueryKnownToValidate) |
534 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, | 538 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, |
535 OnSetKnownToValidate) | 539 OnSetKnownToValidate) |
536 #if defined(OS_WIN) | 540 #if defined(OS_WIN) |
537 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, | 541 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, |
538 OnAttachDebugExceptionHandler) | 542 OnAttachDebugExceptionHandler) |
539 #endif | 543 #endif |
544 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated, | |
545 OnPpapiChannelCreated) | |
540 IPC_MESSAGE_UNHANDLED(handled = false) | 546 IPC_MESSAGE_UNHANDLED(handled = false) |
541 IPC_END_MESSAGE_MAP() | 547 IPC_END_MESSAGE_MAP() |
542 return handled; | 548 return handled; |
543 } | 549 } |
544 | 550 |
545 void NaClProcessHost::OnProcessLaunched() { | 551 void NaClProcessHost::OnProcessLaunched() { |
546 if (!StartWithLaunchedProcess()) | 552 if (!StartWithLaunchedProcess()) |
547 delete this; | 553 delete this; |
548 } | 554 } |
549 | 555 |
550 // Called when the NaClBrowser singleton has been fully initialized. | 556 // Called when the NaClBrowser singleton has been fully initialized. |
551 void NaClProcessHost::OnResourcesReady() { | 557 void NaClProcessHost::OnResourcesReady() { |
552 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 558 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
553 if (!nacl_browser->IsReady() || !SendStart()) { | 559 if (!nacl_browser->IsReady() || !SendStart()) { |
554 DLOG(ERROR) << "Cannot launch NaCl process"; | 560 DLOG(ERROR) << "Cannot launch NaCl process"; |
555 delete this; | 561 delete this; |
556 } | 562 } |
557 } | 563 } |
558 | 564 |
559 bool NaClProcessHost::ReplyToRenderer() { | 565 bool NaClProcessHost::ReplyToRenderer( |
566 const IPC::ChannelHandle& channel_handle) { | |
560 std::vector<nacl::FileDescriptor> handles_for_renderer; | 567 std::vector<nacl::FileDescriptor> handles_for_renderer; |
561 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { | 568 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { |
562 #if defined(OS_WIN) | 569 #if defined(OS_WIN) |
563 // Copy the handle into the renderer process. | 570 // Copy the handle into the renderer process. |
564 HANDLE handle_in_renderer; | 571 HANDLE handle_in_renderer; |
565 if (!DuplicateHandle(base::GetCurrentProcessHandle(), | 572 if (!DuplicateHandle(base::GetCurrentProcessHandle(), |
566 reinterpret_cast<HANDLE>( | 573 reinterpret_cast<HANDLE>( |
567 internal_->sockets_for_renderer[i]), | 574 internal_->sockets_for_renderer[i]), |
568 chrome_render_message_filter_->peer_handle(), | 575 chrome_render_message_filter_->peer_handle(), |
569 &handle_in_renderer, | 576 &handle_in_renderer, |
(...skipping 23 matching lines...) Expand all Loading... | |
593 // BrokerDuplicateHandle(). | 600 // BrokerDuplicateHandle(). |
594 if (RunningOnWOW64()) { | 601 if (RunningOnWOW64()) { |
595 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { | 602 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { |
596 DLOG(ERROR) << "Failed to add NaCl process PID"; | 603 DLOG(ERROR) << "Failed to add NaCl process PID"; |
597 return false; | 604 return false; |
598 } | 605 } |
599 } | 606 } |
600 #endif | 607 #endif |
601 | 608 |
602 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( | 609 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( |
603 reply_msg_, handles_for_renderer); | 610 reply_msg_, handles_for_renderer, channel_handle); |
604 chrome_render_message_filter_->Send(reply_msg_); | 611 chrome_render_message_filter_->Send(reply_msg_); |
605 chrome_render_message_filter_ = NULL; | 612 chrome_render_message_filter_ = NULL; |
606 reply_msg_ = NULL; | 613 reply_msg_ = NULL; |
607 internal_->sockets_for_renderer.clear(); | 614 internal_->sockets_for_renderer.clear(); |
608 return true; | 615 return true; |
609 } | 616 } |
610 | 617 |
611 bool NaClProcessHost::StartNaClExecution() { | 618 bool NaClProcessHost::StartNaClExecution() { |
612 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 619 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
613 | 620 |
614 nacl::NaClStartParams params; | 621 nacl::NaClStartParams params; |
615 params.validation_cache_enabled = nacl_browser->ValidationCacheIsEnabled(); | 622 params.validation_cache_enabled = nacl_browser->ValidationCacheIsEnabled(); |
616 params.validation_cache_key = nacl_browser->GetValidationCacheKey(); | 623 params.validation_cache_key = nacl_browser->GetValidationCacheKey(); |
617 params.version = chrome::VersionInfo().CreateVersionString(); | 624 params.version = chrome::VersionInfo().CreateVersionString(); |
618 params.enable_exception_handling = enable_exception_handling_; | 625 params.enable_exception_handling = enable_exception_handling_; |
619 params.enable_debug_stub = | 626 params.enable_debug_stub = |
620 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaClDebug); | 627 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaClDebug); |
628 params.enable_ipc_proxy = enable_ipc_proxy_; | |
621 | 629 |
622 base::PlatformFile irt_file = nacl_browser->IrtFile(); | 630 base::PlatformFile irt_file = nacl_browser->IrtFile(); |
623 CHECK_NE(irt_file, base::kInvalidPlatformFileValue); | 631 CHECK_NE(irt_file, base::kInvalidPlatformFileValue); |
624 | 632 |
625 const ChildProcessData& data = process_->GetData(); | 633 const ChildProcessData& data = process_->GetData(); |
626 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { | 634 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { |
627 if (!ShareHandleToSelLdr(data.handle, | 635 if (!ShareHandleToSelLdr(data.handle, |
628 internal_->sockets_for_sel_ldr[i], true, | 636 internal_->sockets_for_sel_ldr[i], true, |
629 ¶ms.handles)) { | 637 ¶ms.handles)) { |
630 return false; | 638 return false; |
(...skipping 27 matching lines...) Expand all Loading... | |
658 params.handles.push_back(memory_fd); | 666 params.handles.push_back(memory_fd); |
659 #endif | 667 #endif |
660 | 668 |
661 process_->Send(new NaClProcessMsg_Start(params)); | 669 process_->Send(new NaClProcessMsg_Start(params)); |
662 | 670 |
663 internal_->sockets_for_sel_ldr.clear(); | 671 internal_->sockets_for_sel_ldr.clear(); |
664 return true; | 672 return true; |
665 } | 673 } |
666 | 674 |
667 bool NaClProcessHost::SendStart() { | 675 bool NaClProcessHost::SendStart() { |
668 return ReplyToRenderer() && StartNaClExecution(); | 676 if (!enable_ipc_proxy_) { |
677 if (!ReplyToRenderer(IPC::ChannelHandle())) | |
678 return false; | |
679 } | |
680 return StartNaClExecution(); | |
681 } | |
682 | |
683 void NaClProcessHost::OnPpapiChannelCreated( | |
684 const IPC::ChannelHandle& channel_handle) { | |
685 DCHECK(enable_ipc_proxy_); | |
686 ReplyToRenderer(channel_handle); | |
669 } | 687 } |
670 | 688 |
671 bool NaClProcessHost::StartWithLaunchedProcess() { | 689 bool NaClProcessHost::StartWithLaunchedProcess() { |
672 #if defined(OS_LINUX) | 690 #if defined(OS_LINUX) |
673 if (wait_for_nacl_gdb_) { | 691 if (wait_for_nacl_gdb_) { |
674 if (LaunchNaClGdb(base::GetProcId(process_->GetData().handle))) { | 692 if (LaunchNaClGdb(base::GetProcId(process_->GetData().handle))) { |
675 // We will be called with wait_for_nacl_gdb_ = false once debugger is | 693 // We will be called with wait_for_nacl_gdb_ = false once debugger is |
676 // attached to the program. | 694 // attached to the program. |
677 return true; | 695 return true; |
678 } | 696 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 } else { | 783 } else { |
766 NaClStartDebugExceptionHandlerThread( | 784 NaClStartDebugExceptionHandlerThread( |
767 process_handle.Take(), info, | 785 process_handle.Take(), info, |
768 base::MessageLoopProxy::current(), | 786 base::MessageLoopProxy::current(), |
769 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 787 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
770 weak_factory_.GetWeakPtr())); | 788 weak_factory_.GetWeakPtr())); |
771 return true; | 789 return true; |
772 } | 790 } |
773 } | 791 } |
774 #endif | 792 #endif |
OLD | NEW |