Chromium Code Reviews| Index: components/nacl/browser/nacl_process_host.cc |
| diff --git a/components/nacl/browser/nacl_process_host.cc b/components/nacl/browser/nacl_process_host.cc |
| index 3b6ddcf7050d0caa0f59588b5e4854146e7b4984..2d0f04cdbf58cd4af4f528a4065140a1176cc5a1 100644 |
| --- a/components/nacl/browser/nacl_process_host.cc |
| +++ b/components/nacl/browser/nacl_process_host.cc |
| @@ -632,8 +632,6 @@ bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| OnQueryKnownToValidate) |
| IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, |
| OnSetKnownToValidate) |
| - IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken, |
| - OnResolveFileToken) |
| IPC_MESSAGE_HANDLER(NaClProcessMsg_ResolveFileTokenAsync, |
| OnResolveFileTokenAsync) |
| @@ -822,11 +820,6 @@ bool NaClProcessHost::StartNaClExecution() { |
| params.enable_debug_stub = enable_debug_stub_ && |
| NaClBrowser::GetDelegate()->URLMatchesDebugPatterns(manifest_url_); |
| - // TODO(teravest): Resolve the file tokens right now instead of making the |
| - // loader send IPC to resolve them later. |
| - params.nexe_token_lo = nexe_token_.lo; |
| - params.nexe_token_hi = nexe_token_.hi; |
| - |
| const ChildProcessData& data = process_->GetData(); |
| if (!ShareHandleToSelLdr(data.handle, |
| socket_for_sel_ldr_.TakePlatformFile(), |
| @@ -881,18 +874,68 @@ bool NaClProcessHost::StartNaClExecution() { |
| #endif |
| } |
| - params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(), |
| - process_->GetData().handle); |
| if (!crash_info_shmem_.ShareToProcess(process_->GetData().handle, |
| ¶ms.crash_info_shmem_handle)) { |
| DLOG(ERROR) << "Failed to ShareToProcess() a shared memory buffer"; |
| return false; |
| } |
| + base::FilePath file_path; |
| + if (NaClBrowser::GetInstance()->GetFilePath(nexe_token_.lo, |
| + nexe_token_.hi, |
| + &file_path)) { |
| + // We have to reopen the file in the browser process; we don't want a |
| + // compromised renderer to pass an arbitrary fd that could get loaded |
| + // into the plugin process. |
| + if (base::PostTaskAndReplyWithResult( |
| + content::BrowserThread::GetBlockingPool(), |
| + FROM_HERE, |
| + base::Bind(OpenNaClReadExecImpl, |
| + file_path, |
| + true /* is_executable */), |
| + base::Bind(&NaClProcessHost::StartNaClFileResolved, |
| + weak_factory_.GetWeakPtr(), |
| + params, |
| + file_path))) { |
| + return true; |
| + } |
| + } |
| + |
| + params.nexe_file = IPC::TakeFileHandleForProcess(nexe_file_.Pass(), |
| + process_->GetData().handle); |
| process_->Send(new NaClProcessMsg_Start(params)); |
| return true; |
| } |
| +void ClosePlatformFile(base::PlatformFile file) { |
|
Mark Seaborn
2014/10/14 17:37:24
Shouldn't this be in an anon namespace? Doesn't b
teravest
2014/10/14 18:15:00
I've moved this to an anonymous namespace and chan
|
| +#if defined(OS_WIN) |
| + ::CloseHandle(file); |
| +#elif defined(OS_POSIX) |
| + IGNORE_EINTR(::close(file)); |
| +#endif |
| +} |
| + |
| +void NaClProcessHost::StartNaClFileResolved( |
| + NaClStartParams params, |
| + const base::FilePath& file_path, |
| + base::File nexe_file) { |
| + if (nexe_file.IsValid()) { |
| + // Release the file received from the renderer. This has to be done on a |
| + // thread where IO is permitted, though. |
| + base::File close_nexe_file = nexe_file_.Pass(); |
| + content::BrowserThread::GetBlockingPool()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&ClosePlatformFile, close_nexe_file.TakePlatformFile())); |
| + params.nexe_file_path = file_path; |
| + params.nexe_file = IPC::TakeFileHandleForProcess( |
| + nexe_file.Pass(), process_->GetData().handle); |
| + } else { |
| + params.nexe_file = IPC::TakeFileHandleForProcess( |
| + nexe_file_.Pass(), process_->GetData().handle); |
| + } |
| + process_->Send(new NaClProcessMsg_Start(params)); |
| +} |
| + |
| // This method is called when NaClProcessHostMsg_PpapiChannelCreated is |
| // received. |
| void NaClProcessHost::OnPpapiChannelsCreated( |
| @@ -995,9 +1038,8 @@ void NaClProcessHost::OnSetKnownToValidate(const std::string& signature) { |
| signature, off_the_record_); |
| } |
| -void NaClProcessHost::OnResolveFileToken(uint64 file_token_lo, |
| - uint64 file_token_hi, |
| - IPC::Message* reply_msg) { |
| +void NaClProcessHost::OnResolveFileTokenAsync(uint64 file_token_lo, |
| + uint64 file_token_hi) { |
| // Was the file registered? |
| // |
| // Note that the file path cache is of bounded size, and old entries can get |
| @@ -1018,42 +1060,6 @@ void NaClProcessHost::OnResolveFileToken(uint64 file_token_lo, |
| // nexe are currently not resolved. Shared libraries will be resolved. They |
| // will be loaded sequentially, so they will only consume a single entry |
| // while the load is in flight. |
| - // |
| - // TODO(ncbray): track behavior with UMA. If entries are getting evicted or |
| - // bogus keys are getting queried, this would be good to know. |
| - CHECK(!uses_nonsfi_mode_); |
| - base::FilePath file_path; |
| - if (!NaClBrowser::GetInstance()->GetFilePath( |
| - file_token_lo, file_token_hi, &file_path)) { |
| - NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| - reply_msg, |
| - IPC::InvalidPlatformFileForTransit(), |
| - base::FilePath()); |
| - Send(reply_msg); |
| - return; |
| - } |
| - |
| - // Open the file. |
| - if (!base::PostTaskAndReplyWithResult( |
| - content::BrowserThread::GetBlockingPool(), |
| - FROM_HERE, |
| - base::Bind(OpenNaClReadExecImpl, file_path, true /* is_executable */), |
| - base::Bind(&NaClProcessHost::FileResolved, |
| - weak_factory_.GetWeakPtr(), |
| - file_path, |
| - reply_msg))) { |
| - NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| - reply_msg, |
| - IPC::InvalidPlatformFileForTransit(), |
| - base::FilePath()); |
| - Send(reply_msg); |
| - } |
| -} |
| - |
| -void NaClProcessHost::OnResolveFileTokenAsync(uint64 file_token_lo, |
| - uint64 file_token_hi) { |
| - // See the comment at OnResolveFileToken() for details of the file path cache |
| - // behavior. |
| CHECK(!uses_nonsfi_mode_); |
| base::FilePath file_path; |
| if (!NaClBrowser::GetInstance()->GetFilePath( |
| @@ -1084,27 +1090,6 @@ void NaClProcessHost::OnResolveFileTokenAsync(uint64 file_token_lo, |
| } |
| } |
| -void NaClProcessHost::FileResolved( |
| - const base::FilePath& file_path, |
| - IPC::Message* reply_msg, |
| - base::File file) { |
| - if (file.IsValid()) { |
| - IPC::PlatformFileForTransit handle = IPC::TakeFileHandleForProcess( |
| - file.Pass(), |
| - process_->GetData().handle); |
| - NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| - reply_msg, |
| - handle, |
| - file_path); |
| - } else { |
| - NaClProcessMsg_ResolveFileToken::WriteReplyParams( |
| - reply_msg, |
| - IPC::InvalidPlatformFileForTransit(), |
| - base::FilePath()); |
| - } |
| - Send(reply_msg); |
| -} |
| - |
| void NaClProcessHost::FileResolvedAsync( |
| uint64_t file_token_lo, |
| uint64_t file_token_hi, |