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 "components/nacl/browser/nacl_process_host.h" | 5 #include "components/nacl/browser/nacl_process_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, | 647 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, |
648 OnQueryKnownToValidate) | 648 OnQueryKnownToValidate) |
649 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, | 649 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, |
650 OnSetKnownToValidate) | 650 OnSetKnownToValidate) |
651 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken, | 651 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken, |
652 OnResolveFileToken) | 652 OnResolveFileToken) |
653 #if defined(OS_WIN) | 653 #if defined(OS_WIN) |
654 IPC_MESSAGE_HANDLER_DELAY_REPLY( | 654 IPC_MESSAGE_HANDLER_DELAY_REPLY( |
655 NaClProcessMsg_AttachDebugExceptionHandler, | 655 NaClProcessMsg_AttachDebugExceptionHandler, |
656 OnAttachDebugExceptionHandler) | 656 OnAttachDebugExceptionHandler) |
657 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_DebugStubPortSelected, | |
658 OnDebugStubPortSelected) | |
657 #endif | 659 #endif |
658 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelsCreated, | 660 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelsCreated, |
659 OnPpapiChannelsCreated) | 661 OnPpapiChannelsCreated) |
660 IPC_MESSAGE_UNHANDLED(handled = false) | 662 IPC_MESSAGE_UNHANDLED(handled = false) |
661 IPC_END_MESSAGE_MAP() | 663 IPC_END_MESSAGE_MAP() |
662 } | 664 } |
663 return handled; | 665 return handled; |
664 } | 666 } |
665 | 667 |
666 void NaClProcessHost::OnProcessLaunched() { | 668 void NaClProcessHost::OnProcessLaunched() { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
748 DCHECK(reply_msg_); | 750 DCHECK(reply_msg_); |
749 if (nacl_host_message_filter_ != NULL && reply_msg_ != NULL) { | 751 if (nacl_host_message_filter_ != NULL && reply_msg_ != NULL) { |
750 NaClHostMsg_LaunchNaCl::WriteReplyParams( | 752 NaClHostMsg_LaunchNaCl::WriteReplyParams( |
751 reply_msg_, result, error_message); | 753 reply_msg_, result, error_message); |
752 nacl_host_message_filter_->Send(reply_msg_); | 754 nacl_host_message_filter_->Send(reply_msg_); |
753 nacl_host_message_filter_ = NULL; | 755 nacl_host_message_filter_ = NULL; |
754 reply_msg_ = NULL; | 756 reply_msg_ = NULL; |
755 } | 757 } |
756 } | 758 } |
757 | 759 |
760 void NaClProcessHost::SetDebugStubPort(uint16_t port) { | |
761 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | |
762 if (nacl_browser->HasGdbDebugStubPortListener()) { | |
763 nacl_browser->FireGdbDebugStubPortOpened(port); | |
764 } | |
765 // Set debug stub port on the process object. | |
766 process_->SetNaClDebugStubPort(port); | |
767 } | |
768 | |
769 #if defined(OS_POSIX) | |
758 // TCP port we chose for NaCl debug stub. It can be any other number. | 770 // TCP port we chose for NaCl debug stub. It can be any other number. |
759 static const int kInitialDebugStubPort = 4014; | 771 static const int kInitialDebugStubPort = 4014; |
760 | 772 |
761 #if defined(OS_POSIX) | |
762 net::SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { | 773 net::SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { |
763 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | |
764 net::SocketDescriptor s = net::kInvalidSocket; | 774 net::SocketDescriptor s = net::kInvalidSocket; |
765 // We always try to allocate the default port first. If this fails, we then | 775 // We always try to allocate the default port first. If this fails, we then |
766 // allocate any available port. | 776 // allocate any available port. |
767 // On success, if the test system has register a handler | 777 // On success, if the test system has register a handler |
768 // (GdbDebugStubPortListener), we fire a notification. | 778 // (GdbDebugStubPortListener), we fire a notification. |
769 int port = kInitialDebugStubPort; | 779 int port = kInitialDebugStubPort; |
770 s = net::TCPListenSocket::CreateAndBind("127.0.0.1", port); | 780 s = net::TCPListenSocket::CreateAndBind("127.0.0.1", port); |
771 if (s == net::kInvalidSocket) { | 781 if (s == net::kInvalidSocket) { |
772 s = net::TCPListenSocket::CreateAndBindAnyPort("127.0.0.1", &port); | 782 s = net::TCPListenSocket::CreateAndBindAnyPort("127.0.0.1", &port); |
773 } | 783 } |
774 if (s != net::kInvalidSocket) { | 784 if (s != net::kInvalidSocket) { |
775 if (nacl_browser->HasGdbDebugStubPortListener()) { | 785 SetDebugStubPort(port); |
776 nacl_browser->FireGdbDebugStubPortOpened(port); | |
777 } | |
778 } | 786 } |
779 // Set debug stub port on the process object. | |
780 process_->SetNaClDebugStubPort(port); | |
781 if (s == net::kInvalidSocket) { | 787 if (s == net::kInvalidSocket) { |
782 LOG(ERROR) << "failed to open socket for debug stub"; | 788 LOG(ERROR) << "failed to open socket for debug stub"; |
783 return net::kInvalidSocket; | 789 return net::kInvalidSocket; |
784 } else { | 790 } else { |
785 LOG(WARNING) << "debug stub on port " << port; | 791 LOG(WARNING) << "debug stub on port " << port; |
786 } | 792 } |
787 if (listen(s, 1)) { | 793 if (listen(s, 1)) { |
788 LOG(ERROR) << "listen() failed on debug stub socket"; | 794 LOG(ERROR) << "listen() failed on debug stub socket"; |
789 if (IGNORE_EINTR(close(s)) < 0) | 795 if (IGNORE_EINTR(close(s)) < 0) |
790 PLOG(ERROR) << "failed to close debug stub socket"; | 796 PLOG(ERROR) << "failed to close debug stub socket"; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
931 ReplyToRenderer(ppapi_renderer_channel_handle, | 937 ReplyToRenderer(ppapi_renderer_channel_handle, |
932 trusted_renderer_channel_handle, | 938 trusted_renderer_channel_handle, |
933 manifest_service_channel_handle); | 939 manifest_service_channel_handle); |
934 } else { | 940 } else { |
935 // Attempt to open more than 1 browser channel is not supported. | 941 // Attempt to open more than 1 browser channel is not supported. |
936 // Shut down the NaCl process. | 942 // Shut down the NaCl process. |
937 process_->GetHost()->ForceShutdown(); | 943 process_->GetHost()->ForceShutdown(); |
938 } | 944 } |
939 } | 945 } |
940 | 946 |
947 #if defined(OS_WIN) | |
948 void NaClProcessHost::OnDebugStubPortSelected(uint16_t debug_stub_port) { | |
Mark Seaborn
2014/05/08 18:04:44
Nit: Can you try to keep the same ordering as in t
bradn
2014/05/08 18:09:25
Done.
| |
949 CHECK(!uses_nonsfi_mode_); | |
950 SetDebugStubPort(debug_stub_port); | |
951 } | |
952 #endif | |
953 | |
941 bool NaClProcessHost::StartWithLaunchedProcess() { | 954 bool NaClProcessHost::StartWithLaunchedProcess() { |
942 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 955 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
943 | 956 |
944 if (nacl_browser->IsReady()) { | 957 if (nacl_browser->IsReady()) { |
945 return StartNaClExecution(); | 958 return StartNaClExecution(); |
946 } else if (nacl_browser->IsOk()) { | 959 } else if (nacl_browser->IsOk()) { |
947 nacl_browser->WaitForResources( | 960 nacl_browser->WaitForResources( |
948 base::Bind(&NaClProcessHost::OnResourcesReady, | 961 base::Bind(&NaClProcessHost::OnResourcesReady, |
949 weak_factory_.GetWeakPtr())); | 962 weak_factory_.GetWeakPtr())); |
950 return true; | 963 return true; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1108 process_handle.Take(), info, | 1121 process_handle.Take(), info, |
1109 base::MessageLoopProxy::current(), | 1122 base::MessageLoopProxy::current(), |
1110 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1123 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
1111 weak_factory_.GetWeakPtr())); | 1124 weak_factory_.GetWeakPtr())); |
1112 return true; | 1125 return true; |
1113 } | 1126 } |
1114 } | 1127 } |
1115 #endif | 1128 #endif |
1116 | 1129 |
1117 } // namespace nacl | 1130 } // namespace nacl |
OLD | NEW |