| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/loader/nacl_ipc_adapter.h" | 5 #include "components/nacl/loader/nacl_ipc_adapter.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 621 |
| 622 // Write empty file tokens. | 622 // Write empty file tokens. |
| 623 new_msg->WriteUInt64(0); // token_lo | 623 new_msg->WriteUInt64(0); // token_lo |
| 624 new_msg->WriteUInt64(0); // token_hi | 624 new_msg->WriteUInt64(0); // token_hi |
| 625 return new_msg.Pass(); | 625 return new_msg.Pass(); |
| 626 } | 626 } |
| 627 | 627 |
| 628 void NaClIPCAdapter::OnFileTokenResolved(const IPC::Message& orig_msg, | 628 void NaClIPCAdapter::OnFileTokenResolved(const IPC::Message& orig_msg, |
| 629 IPC::PlatformFileForTransit ipc_fd, | 629 IPC::PlatformFileForTransit ipc_fd, |
| 630 base::FilePath file_path) { | 630 base::FilePath file_path) { |
| 631 base::AutoLock lock(lock_); |
| 632 OnFileTokenResolvedLocked(orig_msg, ipc_fd, file_path); |
| 633 } |
| 634 |
| 635 void NaClIPCAdapter::OnFileTokenResolvedLocked( |
| 636 const IPC::Message& orig_msg, |
| 637 IPC::PlatformFileForTransit ipc_fd, |
| 638 base::FilePath file_path) { |
| 639 lock_.AssertAcquired(); |
| 631 // The path where an invalid ipc_fd is returned isn't currently | 640 // The path where an invalid ipc_fd is returned isn't currently |
| 632 // covered by any tests. | 641 // covered by any tests. |
| 633 if (ipc_fd == IPC::InvalidPlatformFileForTransit()) { | 642 if (ipc_fd == IPC::InvalidPlatformFileForTransit()) { |
| 634 // The file token didn't resolve successfully, so we give the | 643 // The file token didn't resolve successfully, so we give the |
| 635 // original FD to the client without making a validated NaClDesc. | 644 // original FD to the client without making a validated NaClDesc. |
| 636 // However, we must rewrite the message to clear the file tokens. | 645 // However, we must rewrite the message to clear the file tokens. |
| 637 PickleIterator iter = IPC::SyncMessage::GetDataIterator(&orig_msg); | 646 PickleIterator iter = IPC::SyncMessage::GetDataIterator(&orig_msg); |
| 638 ppapi::proxy::SerializedHandle sh; | 647 ppapi::proxy::SerializedHandle sh; |
| 639 | 648 |
| 640 // We know that this can be read safely; see the original read in | 649 // We know that this can be read safely; see the original read in |
| 641 // OnMessageReceived(). | 650 // OnMessageReceived(). |
| 642 CHECK(IPC::ReadParam(&orig_msg, &iter, &sh)); | 651 CHECK(IPC::ReadParam(&orig_msg, &iter, &sh)); |
| 643 scoped_ptr<IPC::Message> new_msg = CreateOpenResourceReply(orig_msg, sh); | 652 scoped_ptr<IPC::Message> new_msg = CreateOpenResourceReply(orig_msg, sh); |
| 644 | 653 |
| 645 scoped_ptr<NaClDescWrapper> desc_wrapper(new NaClDescWrapper( | 654 scoped_ptr<NaClDescWrapper> desc_wrapper(new NaClDescWrapper( |
| 646 NaClDescIoDescFromHandleAllocCtor( | 655 NaClDescIoDescFromHandleAllocCtor( |
| 647 #if defined(OS_WIN) | 656 #if defined(OS_WIN) |
| 648 sh.descriptor(), | 657 sh.descriptor(), |
| 649 #else | 658 #else |
| 650 sh.descriptor().fd, | 659 sh.descriptor().fd, |
| 651 #endif | 660 #endif |
| 652 NACL_ABI_O_RDONLY))); | 661 NACL_ABI_O_RDONLY))); |
| 653 | 662 |
| 654 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); | 663 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); |
| 655 rewritten_msg->AddDescriptor(desc_wrapper.release()); | 664 rewritten_msg->AddDescriptor(desc_wrapper.release()); |
| 656 { | 665 SaveMessage(*new_msg, rewritten_msg.get()); |
| 657 base::AutoLock lock(lock_); | 666 cond_var_.Signal(); |
| 658 SaveMessage(*new_msg, rewritten_msg.get()); | |
| 659 cond_var_.Signal(); | |
| 660 } | |
| 661 return; | 667 return; |
| 662 } | 668 } |
| 663 | 669 |
| 664 // The file token was sucessfully resolved. | 670 // The file token was sucessfully resolved. |
| 665 std::string file_path_str = file_path.AsUTF8Unsafe(); | 671 std::string file_path_str = file_path.AsUTF8Unsafe(); |
| 666 base::PlatformFile handle = | 672 base::PlatformFile handle = |
| 667 IPC::PlatformFileForTransitToPlatformFile(ipc_fd); | 673 IPC::PlatformFileForTransitToPlatformFile(ipc_fd); |
| 668 // The file token was resolved successfully, so we populate the new | 674 // The file token was resolved successfully, so we populate the new |
| 669 // NaClDesc with that information. | 675 // NaClDesc with that information. |
| 670 char* alloc_file_path = static_cast<char*>( | 676 char* alloc_file_path = static_cast<char*>( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 685 static_cast<uint32_t>(file_path_str.length()); | 691 static_cast<uint32_t>(file_path_str.length()); |
| 686 NaClSetFileOriginInfo(desc_wrapper->desc(), &info); | 692 NaClSetFileOriginInfo(desc_wrapper->desc(), &info); |
| 687 NaClRichFileInfoDtor(&info); | 693 NaClRichFileInfoDtor(&info); |
| 688 | 694 |
| 689 ppapi::proxy::SerializedHandle sh; | 695 ppapi::proxy::SerializedHandle sh; |
| 690 sh.set_file_handle(ipc_fd, PP_FILEOPENFLAG_READ, 0); | 696 sh.set_file_handle(ipc_fd, PP_FILEOPENFLAG_READ, 0); |
| 691 scoped_ptr<IPC::Message> new_msg = CreateOpenResourceReply(orig_msg, sh); | 697 scoped_ptr<IPC::Message> new_msg = CreateOpenResourceReply(orig_msg, sh); |
| 692 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); | 698 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); |
| 693 | 699 |
| 694 rewritten_msg->AddDescriptor(desc_wrapper.release()); | 700 rewritten_msg->AddDescriptor(desc_wrapper.release()); |
| 695 { | 701 SaveMessage(*new_msg, rewritten_msg.get()); |
| 696 base::AutoLock lock(lock_); | 702 cond_var_.Signal(); |
| 697 SaveMessage(*new_msg, rewritten_msg.get()); | |
| 698 cond_var_.Signal(); | |
| 699 } | |
| 700 } | 703 } |
| 701 | 704 |
| 702 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) { | 705 void NaClIPCAdapter::OnChannelConnected(int32 peer_pid) { |
| 703 } | 706 } |
| 704 | 707 |
| 705 void NaClIPCAdapter::OnChannelError() { | 708 void NaClIPCAdapter::OnChannelError() { |
| 706 CloseChannel(); | 709 CloseChannel(); |
| 707 } | 710 } |
| 708 | 711 |
| 709 NaClIPCAdapter::~NaClIPCAdapter() { | 712 NaClIPCAdapter::~NaClIPCAdapter() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 // here before we drop the message. | 773 // here before we drop the message. |
| 771 return false; | 774 return false; |
| 772 } | 775 } |
| 773 | 776 |
| 774 // Scan all untrusted messages. | 777 // Scan all untrusted messages. |
| 775 scoped_ptr<IPC::Message> new_msg; | 778 scoped_ptr<IPC::Message> new_msg; |
| 776 locked_data_.nacl_msg_scanner_.ScanUntrustedMessage(*msg, &new_msg); | 779 locked_data_.nacl_msg_scanner_.ScanUntrustedMessage(*msg, &new_msg); |
| 777 if (new_msg) | 780 if (new_msg) |
| 778 msg.reset(new_msg.release()); | 781 msg.reset(new_msg.release()); |
| 779 | 782 |
| 783 // Handle PpapiHostMsg_OpenResource locally without sending an IPC to the |
| 784 // renderer when possible. |
| 785 PpapiHostMsg_OpenResource::Schema::SendParam send_params; |
| 786 if (!open_resource_cb_.is_null() && |
| 787 (msg->type() == PpapiHostMsg_OpenResource::ID) && |
| 788 PpapiHostMsg_OpenResource::ReadSendParam(msg.get(), &send_params)) { |
| 789 const std::string key = send_params.a; |
| 790 if (open_resource_cb_.Run( |
| 791 *msg.get(), key, |
| 792 base::Bind(&NaClIPCAdapter::OnFileTokenResolvedLocked, this))) { |
| 793 // The callback sent a reply to the untrusted side. |
| 794 return true; |
| 795 } |
| 796 } |
| 797 |
| 780 // Actual send must be done on the I/O thread. | 798 // Actual send must be done on the I/O thread. |
| 781 task_runner_->PostTask(FROM_HERE, | 799 task_runner_->PostTask(FROM_HERE, |
| 782 base::Bind(&NaClIPCAdapter::SendMessageOnIOThread, this, | 800 base::Bind(&NaClIPCAdapter::SendMessageOnIOThread, this, |
| 783 base::Passed(&msg))); | 801 base::Passed(&msg))); |
| 784 return true; | 802 return true; |
| 785 } | 803 } |
| 786 | 804 |
| 787 void NaClIPCAdapter::ClearToBeSent() { | 805 void NaClIPCAdapter::ClearToBeSent() { |
| 788 lock_.AssertAcquired(); | 806 lock_.AssertAcquired(); |
| 789 | 807 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 header.flags = msg.flags(); | 844 header.flags = msg.flags(); |
| 827 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); | 845 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); |
| 828 | 846 |
| 829 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); | 847 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); |
| 830 locked_data_.to_be_received_.push(rewritten_msg); | 848 locked_data_.to_be_received_.push(rewritten_msg); |
| 831 } | 849 } |
| 832 | 850 |
| 833 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { | 851 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { |
| 834 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); | 852 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); |
| 835 } | 853 } |
| OLD | NEW |