Chromium Code Reviews| 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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 return MakeNaClDescCustom(this); | 457 return MakeNaClDescCustom(this); |
| 458 } | 458 } |
| 459 | 459 |
| 460 #if defined(OS_POSIX) | 460 #if defined(OS_POSIX) |
| 461 int NaClIPCAdapter::TakeClientFileDescriptor() { | 461 int NaClIPCAdapter::TakeClientFileDescriptor() { |
| 462 return io_thread_data_.channel_->TakeClientFileDescriptor(); | 462 return io_thread_data_.channel_->TakeClientFileDescriptor(); |
| 463 } | 463 } |
| 464 #endif | 464 #endif |
| 465 | 465 |
| 466 bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) { | 466 bool NaClIPCAdapter::OnMessageReceived(const IPC::Message& msg) { |
| 467 uint32_t type = msg.type(); | |
| 468 if (type == IPC_REPLY_ID) { | |
| 469 int id = IPC::SyncMessage::GetMessageId(msg); | |
| 470 IOThreadData::PendingSyncMsgMap::iterator it = | |
| 471 io_thread_data_.pending_sync_msgs_.find(id); | |
| 472 DCHECK(it != io_thread_data_.pending_sync_msgs_.end()); | |
| 473 if (it != io_thread_data_.pending_sync_msgs_.end()) { | |
| 474 type = it->second; | |
| 475 io_thread_data_.pending_sync_msgs_.erase(it); | |
| 476 } | |
| 477 } | |
| 478 | |
| 467 { | 479 { |
| 468 base::AutoLock lock(lock_); | 480 base::AutoLock lock(lock_); |
| 469 | |
| 470 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); | 481 scoped_refptr<RewrittenMessage> rewritten_msg(new RewrittenMessage); |
| 471 | 482 |
| 472 typedef std::vector<ppapi::proxy::SerializedHandle> Handles; | 483 typedef std::vector<ppapi::proxy::SerializedHandle> Handles; |
| 473 Handles handles; | 484 Handles handles; |
| 474 scoped_ptr<IPC::Message> new_msg; | 485 scoped_ptr<IPC::Message> new_msg; |
| 475 if (!locked_data_.nacl_msg_scanner_.ScanMessage(msg, &handles, &new_msg)) | 486 |
| 487 if (!locked_data_.nacl_msg_scanner_.ScanMessage( | |
| 488 msg, type, &handles, &new_msg)) | |
| 476 return false; | 489 return false; |
| 477 | 490 |
| 478 // Now add any descriptors we found to rewritten_msg. |handles| is usually | 491 // Now add any descriptors we found to rewritten_msg. |handles| is usually |
| 479 // empty, unless we read a message containing a FD or handle. | 492 // empty, unless we read a message containing a FD or handle. |
| 480 for (Handles::const_iterator iter = handles.begin(); | 493 for (Handles::const_iterator iter = handles.begin(); |
| 481 iter != handles.end(); | 494 iter != handles.end(); |
| 482 ++iter) { | 495 ++iter) { |
| 483 scoped_ptr<NaClDescWrapper> nacl_desc; | 496 scoped_ptr<NaClDescWrapper> nacl_desc; |
| 484 switch (iter->type()) { | 497 switch (iter->type()) { |
| 485 case ppapi::proxy::SerializedHandle::SHARED_MEMORY: { | 498 case ppapi::proxy::SerializedHandle::SHARED_MEMORY: { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 void NaClIPCAdapter::ConnectChannelOnIOThread() { | 652 void NaClIPCAdapter::ConnectChannelOnIOThread() { |
| 640 if (!io_thread_data_.channel_->Connect()) | 653 if (!io_thread_data_.channel_->Connect()) |
| 641 NOTREACHED(); | 654 NOTREACHED(); |
| 642 } | 655 } |
| 643 | 656 |
| 644 void NaClIPCAdapter::CloseChannelOnIOThread() { | 657 void NaClIPCAdapter::CloseChannelOnIOThread() { |
| 645 io_thread_data_.channel_->Close(); | 658 io_thread_data_.channel_->Close(); |
| 646 } | 659 } |
| 647 | 660 |
| 648 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) { | 661 void NaClIPCAdapter::SendMessageOnIOThread(scoped_ptr<IPC::Message> message) { |
| 662 int id = IPC::SyncMessage::GetMessageId(*message.get()); | |
| 663 DCHECK(io_thread_data_.pending_sync_msgs_.find(id) == | |
| 664 io_thread_data_.pending_sync_msgs_.end()); | |
| 665 | |
| 666 io_thread_data_.pending_sync_msgs_[id] = message->type(); | |
|
dmichael (off chromium)
2014/08/18 20:06:09
It kind of looks like you are adding the id to the
| |
| 649 io_thread_data_.channel_->Send(message.release()); | 667 io_thread_data_.channel_->Send(message.release()); |
| 650 } | 668 } |
| 651 | 669 |
| 652 void NaClIPCAdapter::SaveMessage(const IPC::Message& msg, | 670 void NaClIPCAdapter::SaveMessage(const IPC::Message& msg, |
| 653 RewrittenMessage* rewritten_msg) { | 671 RewrittenMessage* rewritten_msg) { |
| 654 lock_.AssertAcquired(); | 672 lock_.AssertAcquired(); |
| 655 // There is some padding in this structure (the "padding" member is 16 | 673 // There is some padding in this structure (the "padding" member is 16 |
| 656 // bits but this then gets padded to 32 bits). We want to be sure not to | 674 // bits but this then gets padded to 32 bits). We want to be sure not to |
| 657 // leak data to the untrusted plugin, so zero everything out first. | 675 // leak data to the untrusted plugin, so zero everything out first. |
| 658 NaClMessageHeader header; | 676 NaClMessageHeader header; |
| 659 memset(&header, 0, sizeof(NaClMessageHeader)); | 677 memset(&header, 0, sizeof(NaClMessageHeader)); |
| 660 | 678 |
| 661 header.payload_size = static_cast<uint32>(msg.payload_size()); | 679 header.payload_size = static_cast<uint32>(msg.payload_size()); |
| 662 header.routing = msg.routing_id(); | 680 header.routing = msg.routing_id(); |
| 663 header.type = msg.type(); | 681 header.type = msg.type(); |
| 664 header.flags = msg.flags(); | 682 header.flags = msg.flags(); |
| 665 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); | 683 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); |
| 666 | 684 |
| 667 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); | 685 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); |
| 668 locked_data_.to_be_received_.push(rewritten_msg); | 686 locked_data_.to_be_received_.push(rewritten_msg); |
| 669 } | 687 } |
| 670 | 688 |
| 671 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { | 689 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags) { |
| 672 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); | 690 return TranslatePepperFileReadWriteOpenFlags(pp_open_flags); |
| 673 } | 691 } |
| OLD | NEW |