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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 2849243002: Get rid of all pid references from base::SharedMemoryHandle. (Closed)
Patch Set: fix invalid handle Chrome IPC. Created 3 years, 7 months 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 | « base/metrics/field_trial.cc ('k') | mojo/edk/embedder/platform_shared_buffer.cc » ('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 "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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 param_type* r) { 702 param_type* r) {
703 MachPortMac mach_port_mac; 703 MachPortMac mach_port_mac;
704 if (!ParamTraits<MachPortMac>::Read(m, iter, &mach_port_mac)) 704 if (!ParamTraits<MachPortMac>::Read(m, iter, &mach_port_mac))
705 return false; 705 return false;
706 706
707 uint32_t size; 707 uint32_t size;
708 if (!ParamTraits<uint32_t>::Read(m, iter, &size)) 708 if (!ParamTraits<uint32_t>::Read(m, iter, &size))
709 return false; 709 return false;
710 710
711 *r = base::SharedMemoryHandle(mach_port_mac.get_mach_port(), 711 *r = base::SharedMemoryHandle(mach_port_mac.get_mach_port(),
712 static_cast<size_t>(size), 712 static_cast<size_t>(size));
713 base::GetCurrentProcId());
714 return true; 713 return true;
715 } 714 }
716 715
717 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, 716 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
718 std::string* l) { 717 std::string* l) {
719 l->append("Mach port: "); 718 l->append("Mach port: ");
720 LogParam(p.GetMemoryObject(), l); 719 LogParam(p.GetMemoryObject(), l);
721 } 720 }
722 721
723 #elif defined(OS_WIN) 722 #elif defined(OS_WIN)
724 void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* s, 723 void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* s,
725 const param_type& p) { 724 const param_type& p) {
726 GetParamSize(s, p.NeedsBrokering()); 725 GetParamSize(s, p.IsValid());
727 if (p.NeedsBrokering()) { 726 if (p.IsValid())
728 GetParamSize(s, p.GetHandle()); 727 GetParamSize(s, p.GetHandle());
729 } else {
730 GetParamSize(s, HandleToLong(p.GetHandle()));
731 }
732 } 728 }
733 729
734 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, 730 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m,
735 const param_type& p) { 731 const param_type& p) {
736 m->WriteBool(p.NeedsBrokering()); 732 const bool valid = p.IsValid();
733 WriteParam(m, valid);
737 734
738 if (p.NeedsBrokering()) { 735 if (!valid)
739 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE); 736 return;
740 ParamTraits<HandleWin>::Write(m, handle_win);
741 737
742 // If the caller intended to pass ownership to the IPC stack, release a 738 HandleWin handle_win(p.GetHandle(), HandleWin::DUPLICATE);
743 // reference. 739 ParamTraits<HandleWin>::Write(m, handle_win);
744 if (p.OwnershipPassesToIPC() && p.BelongsToCurrentProcess()) 740
745 p.Close(); 741 // If the caller intended to pass ownership to the IPC stack, release a
746 } else { 742 // reference.
747 m->WriteInt(HandleToLong(p.GetHandle())); 743 if (p.OwnershipPassesToIPC())
748 } 744 p.Close();
749 } 745 }
750 746
751 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, 747 bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m,
752 base::PickleIterator* iter, 748 base::PickleIterator* iter,
753 param_type* r) { 749 param_type* r) {
754 bool needs_brokering; 750 *r = base::SharedMemoryHandle();
755 if (!iter->ReadBool(&needs_brokering)) 751
752 bool valid;
753 if (!ReadParam(m, iter, &valid))
756 return false; 754 return false;
755 if (!valid)
756 return true;
757 757
758 if (needs_brokering) { 758 HandleWin handle_win;
759 HandleWin handle_win; 759 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win))
760 if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win))
761 return false;
762 *r = base::SharedMemoryHandle(handle_win.get_handle(),
763 base::GetCurrentProcId());
764 return true;
765 }
766
767 int handle_int;
768 if (!iter->ReadInt(&handle_int))
769 return false; 760 return false;
770 HANDLE handle = LongToHandle(handle_int); 761 *r = base::SharedMemoryHandle(handle_win.get_handle());
771 *r = base::SharedMemoryHandle(handle, base::GetCurrentProcId());
772 return true; 762 return true;
773 } 763 }
774 764
775 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, 765 void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p,
776 std::string* l) { 766 std::string* l) {
777 LogParam(p.GetHandle(), l); 767 LogParam(p.GetHandle(), l);
778 l->append(" needs brokering: ");
779 LogParam(p.NeedsBrokering(), l);
780 } 768 }
781 #elif defined(OS_POSIX) 769 #elif defined(OS_POSIX)
782 void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, 770 void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer,
783 const param_type& p) { 771 const param_type& p) {
784 GetParamSize(sizer, p.IsValid()); 772 GetParamSize(sizer, p.IsValid());
785 if (p.IsValid()) 773 if (p.IsValid())
786 sizer->AddAttachment(); 774 sizer->AddAttachment();
787 } 775 }
788 776
789 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, 777 void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m,
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 return result; 1319 return result;
1332 } 1320 }
1333 1321
1334 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 1322 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
1335 l->append("<MSG>"); 1323 l->append("<MSG>");
1336 } 1324 }
1337 1325
1338 #endif // OS_WIN 1326 #endif // OS_WIN
1339 1327
1340 } // namespace IPC 1328 } // namespace IPC
OLDNEW
« no previous file with comments | « base/metrics/field_trial.cc ('k') | mojo/edk/embedder/platform_shared_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698