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 "ipc/ipc_message_utils.h" | 5 #include "ipc/ipc_message_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); | 683 l->append(base::StringPrintf("FD(%d auto-close)", p.fd)); |
684 } else { | 684 } else { |
685 l->append(base::StringPrintf("FD(%d)", p.fd)); | 685 l->append(base::StringPrintf("FD(%d)", p.fd)); |
686 } | 686 } |
687 } | 687 } |
688 #endif // defined(OS_POSIX) | 688 #endif // defined(OS_POSIX) |
689 | 689 |
690 #if defined(OS_MACOSX) && !defined(OS_IOS) | 690 #if defined(OS_MACOSX) && !defined(OS_IOS) |
691 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, | 691 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
692 const param_type& p) { | 692 const param_type& p) { |
693 m->WriteInt(p.GetType()); | 693 MachPortMac mach_port_mac(p.GetMemoryObject()); |
| 694 ParamTraits<MachPortMac>::Write(m, mach_port_mac); |
| 695 size_t size = 0; |
| 696 bool result = p.GetSize(&size); |
| 697 DCHECK(result); |
| 698 ParamTraits<uint32_t>::Write(m, static_cast<uint32_t>(size)); |
694 | 699 |
695 switch (p.GetType()) { | 700 // If the caller intended to pass ownership to the IPC stack, release a |
696 case base::SharedMemoryHandle::POSIX: | 701 // reference. |
697 ParamTraits<base::FileDescriptor>::Write(m, p.GetFileDescriptor()); | 702 if (p.OwnershipPassesToIPC()) |
698 break; | 703 p.Close(); |
699 case base::SharedMemoryHandle::MACH: | |
700 MachPortMac mach_port_mac(p.GetMemoryObject()); | |
701 ParamTraits<MachPortMac>::Write(m, mach_port_mac); | |
702 size_t size = 0; | |
703 bool result = p.GetSize(&size); | |
704 DCHECK(result); | |
705 ParamTraits<uint32_t>::Write(m, static_cast<uint32_t>(size)); | |
706 | |
707 // If the caller intended to pass ownership to the IPC stack, release a | |
708 // reference. | |
709 if (p.OwnershipPassesToIPC()) | |
710 p.Close(); | |
711 | |
712 break; | |
713 } | |
714 } | 704 } |
715 | 705 |
716 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, | 706 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
717 base::PickleIterator* iter, | 707 base::PickleIterator* iter, |
718 param_type* r) { | 708 param_type* r) { |
719 base::SharedMemoryHandle::TypeWireFormat type; | 709 MachPortMac mach_port_mac; |
720 if (!iter->ReadInt(&type)) | 710 if (!ParamTraits<MachPortMac>::Read(m, iter, &mach_port_mac)) |
721 return false; | 711 return false; |
722 | 712 |
723 base::SharedMemoryHandle::Type shm_type = base::SharedMemoryHandle::POSIX; | 713 uint32_t size; |
724 switch (type) { | 714 if (!ParamTraits<uint32_t>::Read(m, iter, &size)) |
725 case base::SharedMemoryHandle::POSIX: | 715 return false; |
726 case base::SharedMemoryHandle::MACH: { | |
727 shm_type = static_cast<base::SharedMemoryHandle::Type>(type); | |
728 break; | |
729 } | |
730 default: { | |
731 return false; | |
732 } | |
733 } | |
734 | 716 |
735 switch (shm_type) { | 717 *r = base::SharedMemoryHandle(mach_port_mac.get_mach_port(), |
736 case base::SharedMemoryHandle::POSIX: { | 718 static_cast<size_t>(size), |
737 base::FileDescriptor file_descriptor; | 719 base::GetCurrentProcId()); |
738 | 720 return true; |
739 bool success = | |
740 ParamTraits<base::FileDescriptor>::Read(m, iter, &file_descriptor); | |
741 if (!success) | |
742 return false; | |
743 | |
744 *r = base::SharedMemoryHandle(file_descriptor.fd, | |
745 file_descriptor.auto_close); | |
746 return true; | |
747 } | |
748 case base::SharedMemoryHandle::MACH: { | |
749 MachPortMac mach_port_mac; | |
750 if (!ParamTraits<MachPortMac>::Read(m, iter, &mach_port_mac)) | |
751 return false; | |
752 | |
753 uint32_t size; | |
754 if (!ParamTraits<uint32_t>::Read(m, iter, &size)) | |
755 return false; | |
756 | |
757 *r = base::SharedMemoryHandle(mach_port_mac.get_mach_port(), | |
758 static_cast<size_t>(size), | |
759 base::GetCurrentProcId()); | |
760 return true; | |
761 } | |
762 } | |
763 } | 721 } |
764 | 722 |
765 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, | 723 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
766 std::string* l) { | 724 std::string* l) { |
767 switch (p.GetType()) { | 725 l->append("Mach port: "); |
768 case base::SharedMemoryHandle::POSIX: | 726 LogParam(p.GetMemoryObject(), l); |
769 l->append("POSIX Fd: "); | |
770 ParamTraits<base::FileDescriptor>::Log(p.GetFileDescriptor(), l); | |
771 break; | |
772 case base::SharedMemoryHandle::MACH: | |
773 l->append("Mach port: "); | |
774 LogParam(p.GetMemoryObject(), l); | |
775 break; | |
776 } | |
777 } | 727 } |
778 | 728 |
779 #elif defined(OS_WIN) | 729 #elif defined(OS_WIN) |
780 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, | 730 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
781 const param_type& p) { | 731 const param_type& p) { |
782 m->WriteBool(p.NeedsBrokering()); | 732 m->WriteBool(p.NeedsBrokering()); |
783 | 733 |
784 if (p.NeedsBrokering()) { | 734 if (p.NeedsBrokering()) { |
785 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); | 735 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); |
786 ParamTraits<HandleWin>::Write(m, handle_win); | 736 ParamTraits<HandleWin>::Write(m, handle_win); |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 return result; | 1175 return result; |
1226 } | 1176 } |
1227 | 1177 |
1228 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { | 1178 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { |
1229 l->append("<MSG>"); | 1179 l->append("<MSG>"); |
1230 } | 1180 } |
1231 | 1181 |
1232 #endif // OS_WIN | 1182 #endif // OS_WIN |
1233 | 1183 |
1234 } // namespace IPC | 1184 } // namespace IPC |
OLD | NEW |