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/base_switches.h" | 10 #include "base/base_switches.h" |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 return true; | 616 return true; |
617 } | 617 } |
618 | 618 |
619 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { | 619 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { |
620 bool handled = true; | 620 bool handled = true; |
621 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) | 621 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) |
622 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, | 622 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, |
623 OnQueryKnownToValidate) | 623 OnQueryKnownToValidate) |
624 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, | 624 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, |
625 OnSetKnownToValidate) | 625 OnSetKnownToValidate) |
| 626 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken, |
| 627 OnResolveFileToken) |
626 #if defined(OS_WIN) | 628 #if defined(OS_WIN) |
627 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, | 629 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, |
628 OnAttachDebugExceptionHandler) | 630 OnAttachDebugExceptionHandler) |
629 #endif | 631 #endif |
630 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated, | 632 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated, |
631 OnPpapiChannelCreated) | 633 OnPpapiChannelCreated) |
632 IPC_MESSAGE_UNHANDLED(handled = false) | 634 IPC_MESSAGE_UNHANDLED(handled = false) |
633 IPC_END_MESSAGE_MAP() | 635 IPC_END_MESSAGE_MAP() |
634 return handled; | 636 return handled; |
635 } | 637 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 const ChildProcessData& data = process_->GetData(); | 756 const ChildProcessData& data = process_->GetData(); |
755 if (!ShareHandleToSelLdr(data.handle, | 757 if (!ShareHandleToSelLdr(data.handle, |
756 internal_->socket_for_sel_ldr, true, | 758 internal_->socket_for_sel_ldr, true, |
757 ¶ms.handles)) { | 759 ¶ms.handles)) { |
758 return false; | 760 return false; |
759 } | 761 } |
760 | 762 |
761 if (params.uses_irt) { | 763 if (params.uses_irt) { |
762 base::PlatformFile irt_file = nacl_browser->IrtFile(); | 764 base::PlatformFile irt_file = nacl_browser->IrtFile(); |
763 CHECK_NE(irt_file, base::kInvalidPlatformFileValue); | 765 CHECK_NE(irt_file, base::kInvalidPlatformFileValue); |
764 | |
765 // Send over the IRT file handle. We don't close our own copy! | 766 // Send over the IRT file handle. We don't close our own copy! |
766 if (!ShareHandleToSelLdr(data.handle, irt_file, false, ¶ms.handles)) | 767 if (!ShareHandleToSelLdr(data.handle, irt_file, false, ¶ms.handles)) |
767 return false; | 768 return false; |
768 } | 769 } |
769 | 770 |
770 #if defined(OS_MACOSX) | 771 #if defined(OS_MACOSX) |
771 // For dynamic loading support, NaCl requires a file descriptor that | 772 // For dynamic loading support, NaCl requires a file descriptor that |
772 // was created in /tmp, since those created with shm_open() are not | 773 // was created in /tmp, since those created with shm_open() are not |
773 // mappable with PROT_EXEC. Rather than requiring an extra IPC | 774 // mappable with PROT_EXEC. Rather than requiring an extra IPC |
774 // round trip out of the sandbox, we create an FD here. | 775 // round trip out of the sandbox, we create an FD here. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature, | 924 void NaClProcessHost::OnQueryKnownToValidate(const std::string& signature, |
924 bool* result) { | 925 bool* result) { |
925 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 926 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
926 *result = nacl_browser->QueryKnownToValidate(signature, off_the_record_); | 927 *result = nacl_browser->QueryKnownToValidate(signature, off_the_record_); |
927 } | 928 } |
928 | 929 |
929 void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) { | 930 void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) { |
930 NaClBrowser::GetInstance()->SetKnownToValidate(signature, off_the_record_); | 931 NaClBrowser::GetInstance()->SetKnownToValidate(signature, off_the_record_); |
931 } | 932 } |
932 | 933 |
| 934 void NaClProcessHost::FileResolved( |
| 935 base::PlatformFile* file, |
| 936 const base::FilePath& file_path, |
| 937 IPC::Message* reply_msg) { |
| 938 if (*file != base::kInvalidPlatformFileValue) { |
| 939 IPC::PlatformFileForTransit handle = IPC::GetFileHandleForProcess( |
| 940 *file, |
| 941 process_->GetData().handle, |
| 942 true /* close_source */); |
| 943 NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| 944 reply_msg, |
| 945 handle, |
| 946 file_path); |
| 947 } else { |
| 948 NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| 949 reply_msg, |
| 950 IPC::InvalidPlatformFileForTransit(), |
| 951 base::FilePath(FILE_PATH_LITERAL(""))); |
| 952 } |
| 953 Send(reply_msg); |
| 954 } |
| 955 |
| 956 void NaClProcessHost::OnResolveFileToken(uint64 file_token_lo, |
| 957 uint64 file_token_hi, |
| 958 IPC::Message* reply_msg) { |
| 959 // Was the file registered? |
| 960 // |
| 961 // Note that the file path cache is of bounded size, and old entries can get |
| 962 // evicted. If a large number of NaCl modules are being launched at once, |
| 963 // resolving the file_token may fail because the path cache was thrashed |
| 964 // while the file_token was in flight. In this case the query fails, and we |
| 965 // need to fall back to the slower path. |
| 966 // |
| 967 // However: each NaCl process will consume 2-3 entries as it starts up, this |
| 968 // means that eviction will not happen unless you start up 33+ NaCl processes |
| 969 // at the same time, and this still requires worst-case timing. As a |
| 970 // practical matter, no entries should be evicted prematurely. |
| 971 // The cache itself should take ~ (150 characters * 2 bytes/char + ~60 bytes |
| 972 // data structure overhead) * 100 = 35k when full, so making it bigger should |
| 973 // not be a problem, if needed. |
| 974 // |
| 975 // Each NaCl process will consume 2-3 entries because the manifest and main |
| 976 // nexe are currently not resolved. Shared libraries will be resolved. They |
| 977 // will be loaded sequentially, so they will only consume a single entry |
| 978 // while the load is in flight. |
| 979 // |
| 980 // TODO(ncbray): track behavior with UMA. If entries are getting evicted or |
| 981 // bogus keys are getting queried, this would be good to know. |
| 982 base::FilePath file_path; |
| 983 if (!NaClBrowser::GetInstance()->GetFilePath(file_token_lo, file_token_hi, |
| 984 &file_path)) { |
| 985 NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| 986 reply_msg, |
| 987 IPC::InvalidPlatformFileForTransit(), |
| 988 base::FilePath(FILE_PATH_LITERAL(""))); |
| 989 Send(reply_msg); |
| 990 return; |
| 991 } |
| 992 |
| 993 // Scratch space to share between the callbacks. |
| 994 base::PlatformFile* data = new base::PlatformFile(); |
| 995 |
| 996 // Open the file. |
| 997 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 998 FROM_HERE, |
| 999 base::Bind(nacl::OpenNaClExecutableImpl, |
| 1000 file_path, data), |
| 1001 base::Bind(&NaClProcessHost::FileResolved, |
| 1002 weak_factory_.GetWeakPtr(), |
| 1003 base::Owned(data), |
| 1004 file_path, |
| 1005 reply_msg))) { |
| 1006 NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| 1007 reply_msg, |
| 1008 IPC::InvalidPlatformFileForTransit(), |
| 1009 base::FilePath(FILE_PATH_LITERAL(""))); |
| 1010 Send(reply_msg); |
| 1011 } |
| 1012 } |
| 1013 |
933 #if defined(OS_WIN) | 1014 #if defined(OS_WIN) |
934 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info, | 1015 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info, |
935 IPC::Message* reply_msg) { | 1016 IPC::Message* reply_msg) { |
936 if (!AttachDebugExceptionHandler(info, reply_msg)) { | 1017 if (!AttachDebugExceptionHandler(info, reply_msg)) { |
937 // Send failure message. | 1018 // Send failure message. |
938 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg, | 1019 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg, |
939 false); | 1020 false); |
940 Send(reply_msg); | 1021 Send(reply_msg); |
941 } | 1022 } |
942 } | 1023 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 } else { | 1072 } else { |
992 NaClStartDebugExceptionHandlerThread( | 1073 NaClStartDebugExceptionHandlerThread( |
993 process_handle.Take(), info, | 1074 process_handle.Take(), info, |
994 base::MessageLoopProxy::current(), | 1075 base::MessageLoopProxy::current(), |
995 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1076 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
996 weak_factory_.GetWeakPtr())); | 1077 weak_factory_.GetWeakPtr())); |
997 return true; | 1078 return true; |
998 } | 1079 } |
999 } | 1080 } |
1000 #endif | 1081 #endif |
OLD | NEW |