Chromium Code Reviews| 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_ResolveFileNonce, | |
| 627 OnResolveFileNonce) | |
| 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 | |
| 939 if (*file != base::kInvalidPlatformFileValue) { | |
| 940 IPC::PlatformFileForTransit handle = IPC::GetFileHandleForProcess( | |
| 941 *file, | |
| 942 process_->GetData().handle, | |
| 943 true /* close_source */); | |
| 944 NaClProcessMsg_ResolveFileNonce::WriteReplyParams( | |
| 945 reply_msg, | |
| 946 handle, | |
| 947 file_path); | |
| 948 } else { | |
| 949 NaClProcessMsg_ResolveFileNonce::WriteReplyParams( | |
| 950 reply_msg, | |
| 951 IPC::InvalidPlatformFileForTransit(), | |
| 952 base::FilePath(FILE_PATH_LITERAL(""))); | |
| 953 } | |
| 954 Send(reply_msg); | |
| 955 } | |
| 956 | |
| 957 void NaClProcessHost::OnResolveFileNonce(uint64 nonce, | |
| 958 IPC::Message* reply_msg) { | |
| 959 // Was the file registered? | |
| 960 base::FilePath file_path; | |
| 961 if (!NaClBrowser::GetInstance()->GetFilePath(nonce, &file_path)){ | |
|
bennet.yee
2013/05/16 01:52:48
this should never happen in normal operation -- an
Nick Bray (chromium)
2013/05/16 16:38:17
This could happen someone launches 10+ NaCl module
| |
| 962 NaClProcessMsg_ResolveFileNonce::WriteReplyParams( | |
| 963 reply_msg, | |
| 964 IPC::InvalidPlatformFileForTransit(), | |
| 965 base::FilePath(FILE_PATH_LITERAL(""))); | |
| 966 Send(reply_msg); | |
| 967 return; | |
| 968 } | |
| 969 | |
| 970 // Scratch space to share between the callbacks. | |
| 971 base::PlatformFile* data = new base::PlatformFile(); | |
| 972 | |
| 973 // Open the file. | |
| 974 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | |
| 975 FROM_HERE, | |
| 976 base::Bind(nacl::OpenNaClExecutableImpl, | |
| 977 file_path, data), | |
| 978 base::Bind(&NaClProcessHost::FileResolved, | |
| 979 weak_factory_.GetWeakPtr(), | |
| 980 base::Owned(data), | |
| 981 file_path, | |
| 982 reply_msg))) { | |
| 983 NaClProcessMsg_ResolveFileNonce::WriteReplyParams( | |
| 984 reply_msg, | |
| 985 IPC::InvalidPlatformFileForTransit(), | |
| 986 base::FilePath(FILE_PATH_LITERAL(""))); | |
| 987 Send(reply_msg); | |
| 988 } | |
| 989 } | |
| 990 | |
| 933 #if defined(OS_WIN) | 991 #if defined(OS_WIN) |
| 934 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info, | 992 void NaClProcessHost::OnAttachDebugExceptionHandler(const std::string& info, |
| 935 IPC::Message* reply_msg) { | 993 IPC::Message* reply_msg) { |
| 936 if (!AttachDebugExceptionHandler(info, reply_msg)) { | 994 if (!AttachDebugExceptionHandler(info, reply_msg)) { |
| 937 // Send failure message. | 995 // Send failure message. |
| 938 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg, | 996 NaClProcessMsg_AttachDebugExceptionHandler::WriteReplyParams(reply_msg, |
| 939 false); | 997 false); |
| 940 Send(reply_msg); | 998 Send(reply_msg); |
| 941 } | 999 } |
| 942 } | 1000 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 } else { | 1049 } else { |
| 992 NaClStartDebugExceptionHandlerThread( | 1050 NaClStartDebugExceptionHandlerThread( |
| 993 process_handle.Take(), info, | 1051 process_handle.Take(), info, |
| 994 base::MessageLoopProxy::current(), | 1052 base::MessageLoopProxy::current(), |
| 995 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1053 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 996 weak_factory_.GetWeakPtr())); | 1054 weak_factory_.GetWeakPtr())); |
| 997 return true; | 1055 return true; |
| 998 } | 1056 } |
| 999 } | 1057 } |
| 1000 #endif | 1058 #endif |
| OLD | NEW |