Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: components/nacl/browser/nacl_process_host.cc

Issue 728113002: obsolete: SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/nacl/browser/nacl_process_host.h ('k') | components/nacl/loader/nacl_ipc_adapter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 } 906 }
907 #endif 907 #endif
908 } 908 }
909 909
910 if (!crash_info_shmem_.ShareToProcess(process_->GetData().handle, 910 if (!crash_info_shmem_.ShareToProcess(process_->GetData().handle,
911 &params.crash_info_shmem_handle)) { 911 &params.crash_info_shmem_handle)) {
912 DLOG(ERROR) << "Failed to ShareToProcess() a shared memory buffer"; 912 DLOG(ERROR) << "Failed to ShareToProcess() a shared memory buffer";
913 return false; 913 return false;
914 } 914 }
915 915
916 base::FilePath file_path; 916 base::FilePath nexe_file_path;
917 // Don't retrieve the file path when using nonsfi mode; there's no validation 917 // Don't retrieve the file path when using nonsfi mode; there's no validation
918 // caching in that case, so it's unnecessary work, and would expose the file 918 // caching in that case, so it's unnecessary work, and would expose the file
919 // path to the plugin. 919 // path to the plugin.
920 if (uses_nonsfi_mode_) { 920 if (uses_nonsfi_mode_) {
921 for (size_t i = 0; i < resource_files_info_len_; ++i) { 921 for (size_t i = 0; i < resource_files_info_len_; ++i) {
922 IPC::PlatformFileForTransit file = IPC::TakeFileHandleForProcess( 922 IPC::PlatformFileForTransit file = IPC::TakeFileHandleForProcess(
923 resource_files_info_[i].file().Pass(), process_->GetData().handle); 923 resource_files_info_[i].file().Pass(), process_->GetData().handle);
924 std::string file_key = resource_files_info_[i].file_key(); 924 std::string file_key = resource_files_info_[i].file_key();
925 params.resource_files.push_back( 925 params.resource_files.push_back(
926 // Pass an empty base::FilePath since Non-SFI mode does not use it. 926 // Pass an empty base::FilePath since Non-SFI mode does not use it.
927 NaClStartParams::ResourceFileInfo(file, base::FilePath(), file_key)); 927 NaClStartParams::ResourceFileInfo(file, base::FilePath(), file_key));
928 } 928 }
929 } else if (NaClBrowser::GetInstance()->GetFilePath(nexe_token_.lo, 929 } else if (NaClBrowser::GetInstance()->GetFilePath(nexe_token_.lo,
930 nexe_token_.hi, 930 nexe_token_.hi,
931 &file_path)) { 931 &nexe_file_path)) {
932 // We have to reopen the file in the browser process; we don't want a 932 std::vector<base::FilePath> nexe_file_paths(resource_files_info_len_ + 1);
933 // compromised renderer to pass an arbitrary fd that could get loaded 933 nexe_file_paths[0] = nexe_file_path;
934 for (size_t i = 0; i < resource_files_info_len_; ++i) {
935 if (!NaClBrowser::GetInstance()->GetFilePath(
936 resource_files_info_[i].file_token().lo,
937 resource_files_info_[i].file_token().hi,
938 &nexe_file_paths[i + 1])) {
939 nexe_file_paths.resize(1); // We still need to open the main nexe file.
940 break;
941 }
942 }
943 // We have to reopen the files in the browser process; we don't want a
944 // compromised renderer to pass arbitrary fds that could get loaded
934 // into the plugin process. 945 // into the plugin process.
935 if (base::PostTaskAndReplyWithResult( 946 if (base::PostTaskAndReplyWithResult(
936 content::BrowserThread::GetBlockingPool(), 947 content::BrowserThread::GetBlockingPool(),
937 FROM_HERE, 948 FROM_HERE,
938 base::Bind(OpenNaClReadExecImpl, 949 base::Bind(OpenNaClFilesReadExecImpl,
939 file_path, 950 nexe_file_paths,
940 true /* is_executable */), 951 true /* is_executable */),
941 base::Bind(&NaClProcessHost::StartNaClFileResolved, 952 base::Bind(&NaClProcessHost::StartNaClFilesResolved,
942 weak_factory_.GetWeakPtr(), 953 weak_factory_.GetWeakPtr(),
943 params, 954 params,
944 file_path))) { 955 nexe_file_paths.size()))) {
945 return true; 956 return true;
946 } 957 }
947 } 958 }
948 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(), 959 params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(),
949 process_->GetData().handle); 960 process_->GetData().handle);
950
951 params.CheckNumOfDescriptors(); 961 params.CheckNumOfDescriptors();
952 process_->Send(new NaClProcessMsg_Start(params)); 962 process_->Send(new NaClProcessMsg_Start(params));
953 return true; 963 return true;
954 } 964 }
955 965
956 void NaClProcessHost::StartNaClFileResolved( 966 void NaClProcessHost::StartNaClFilesResolved(
957 NaClStartParams params, 967 NaClStartParams params,
958 const base::FilePath& file_path, 968 size_t checked_nexe_files_len,
959 base::File checked_nexe_file) { 969 scoped_ptr<OpenNaClFileReadExecImplResult[]> checked_nexe_files) {
960 if (checked_nexe_file.IsValid()) { 970 // The first element of the array is for the main nexe.
971 DCHECK(checked_nexe_files_len > 0);
972 if (checked_nexe_files[0].IsValid()) {
961 // Release the file received from the renderer. This has to be done on a 973 // Release the file received from the renderer. This has to be done on a
962 // thread where IO is permitted, though. 974 // thread where IO is permitted, though.
963 content::BrowserThread::GetBlockingPool()->PostTask( 975 content::BrowserThread::GetBlockingPool()->PostTask(
964 FROM_HERE, 976 FROM_HERE,
965 base::Bind(&CloseFile, base::Passed(nexe_file_.Pass()))); 977 base::Bind(&CloseFile, base::Passed(nexe_file_.Pass())));
966 params.nexe_file_path_metadata = file_path; 978 params.nexe_file_path_metadata = checked_nexe_files[0].file_path();
967 params.nexe_file = IPC::TakeFileHandleForProcess( 979 params.nexe_file = IPC::TakeFileHandleForProcess(
968 checked_nexe_file.Pass(), process_->GetData().handle); 980 checked_nexe_files[0].file().Pass(), process_->GetData().handle);
969 } else { 981 } else {
970 params.nexe_file = IPC::TakeFileHandleForProcess( 982 params.nexe_file = IPC::TakeFileHandleForProcess(
971 nexe_file_.Pass(), process_->GetData().handle); 983 nexe_file_.Pass(), process_->GetData().handle);
972 } 984 }
985
986 // The rest is for resource files.
987 for (size_t i = 1; i < checked_nexe_files_len; ++i) {
988 // Release the resource files received from the renderer too.
989 content::BrowserThread::GetBlockingPool()->PostTask(
990 FROM_HERE,
991 base::Bind(&CloseFile,
992 base::Passed(resource_files_info_[i - 1].file().Pass())));
993 if (!checked_nexe_files[i].IsValid())
994 continue;
995 IPC::PlatformFileForTransit file = IPC::TakeFileHandleForProcess(
996 checked_nexe_files[i].file().Pass(), process_->GetData().handle);
997 std::string file_key = resource_files_info_[i - 1].file_key();
998 params.resource_files.push_back(NaClStartParams::ResourceFileInfo(
999 file, checked_nexe_files[i].file_path(), file_key));
1000 }
1001
1002 params.CheckNumOfDescriptors();
973 process_->Send(new NaClProcessMsg_Start(params)); 1003 process_->Send(new NaClProcessMsg_Start(params));
974 } 1004 }
975 1005
976 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is 1006 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is
977 // received. 1007 // received.
978 void NaClProcessHost::OnPpapiChannelsCreated( 1008 void NaClProcessHost::OnPpapiChannelsCreated(
979 const IPC::ChannelHandle& browser_channel_handle, 1009 const IPC::ChannelHandle& browser_channel_handle,
980 const IPC::ChannelHandle& ppapi_renderer_channel_handle, 1010 const IPC::ChannelHandle& ppapi_renderer_channel_handle,
981 const IPC::ChannelHandle& trusted_renderer_channel_handle, 1011 const IPC::ChannelHandle& trusted_renderer_channel_handle,
982 const IPC::ChannelHandle& manifest_service_channel_handle) { 1012 const IPC::ChannelHandle& manifest_service_channel_handle) {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 process_handle.Take(), info, 1249 process_handle.Take(), info,
1220 base::MessageLoopProxy::current(), 1250 base::MessageLoopProxy::current(),
1221 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1251 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
1222 weak_factory_.GetWeakPtr())); 1252 weak_factory_.GetWeakPtr()));
1223 return true; 1253 return true;
1224 } 1254 }
1225 } 1255 }
1226 #endif 1256 #endif
1227 1257
1228 } // namespace nacl 1258 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/browser/nacl_process_host.h ('k') | components/nacl/loader/nacl_ipc_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698