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 // Note that the file path cache is of bounded size, and old entries can get | |
961 // evicted. If a large number of NaCl modules are being launched at once, | |
962 // resolving the file_token may fail because the path cache was thrashed | |
963 // while the file_token was in flight. In this case the query fails, and we | |
964 // need to fall back to the slower path. | |
965 base::FilePath file_path; | |
966 if (!NaClBrowser::GetInstance()->GetFilePath(file_token_lo, file_token_hi, | |
967 &file_path)) { | |
jschuh
2013/05/23 01:02:32
This seems like unambiguously bad occurrence. At a
Nick Bray (chromium)
2013/05/23 16:44:11
See the above comment. Bounding the cache size im
bsy_cr
2013/05/23 17:57:24
Just because it's valid doesn't mean it's likely.
Nick Bray (chromium)
2013/05/24 16:54:28
Done.
| |
968 NaClProcessMsg_ResolveFileToken::WriteReplyParams( | |
969 reply_msg, | |
970 IPC::InvalidPlatformFileForTransit(), | |
971 base::FilePath(FILE_PATH_LITERAL(""))); | |
972 Send(reply_msg); | |
973 return; | |
974 } | |
975 | |
976 // Scratch space to share between the callbacks. | |
977 base::PlatformFile* data = new base::PlatformFile(); | |
978 | |
979 // Open the file. | |
980 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | |
981 FROM_HERE, | |
982 base::Bind(nacl::OpenNaClExecutableImpl, | |
983 file_path, data), | |
984 base::Bind(&NaClProcessHost::FileResolved, | |
985 weak_factory_.GetWeakPtr(), | |
986 base::Owned(data), | |
987 file_path, | |
988 reply_msg))) { | |
989 NaClProcessMsg_ResolveFileToken::WriteReplyParams( | |
990 reply_msg, | |
991 IPC::InvalidPlatformFileForTransit(), | |
992 base::FilePath(FILE_PATH_LITERAL(""))); | |
993 Send(reply_msg); | |
994 } | |
995 } | |
996 | |
933 #if defined(OS_WIN) | 997 #if defined(OS_WIN) |
934 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info, | 998 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info, |
935 IPC::Message* reply_msg) { | 999 IPC::Message* reply_msg) { |
936 if (!AttachDebugExceptionHandler(info, reply_msg)) { | 1000 if (!AttachDebugExceptionHandler(info, reply_msg)) { |
937 // Send failure message. | 1001 // Send failure message. |
938 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg, | 1002 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg, |
939 false); | 1003 false); |
940 Send(reply_msg); | 1004 Send(reply_msg); |
941 } | 1005 } |
942 } | 1006 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
991 } else { | 1055 } else { |
992 NaClStartDebugExceptionHandlerThread( | 1056 NaClStartDebugExceptionHandlerThread( |
993 process_handle.Take(), info, | 1057 process_handle.Take(), info, |
994 base::MessageLoopProxy::current(), | 1058 base::MessageLoopProxy::current(), |
995 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1059 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
996 weak_factory_.GetWeakPtr())); | 1060 weak_factory_.GetWeakPtr())); |
997 return true; | 1061 return true; |
998 } | 1062 } |
999 } | 1063 } |
1000 #endif | 1064 #endif |
OLD | NEW |