Index: ipc/ipc_message_utils.cc |
diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc |
index a173226180bbaaac51b926fba76ca9962c0a80b6..c6b40a34a91e48fefed1c614b9dd686348b0a61b 100644 |
--- a/ipc/ipc_message_utils.cc |
+++ b/ipc/ipc_message_utils.cc |
@@ -678,7 +678,12 @@ void ParamTraits<base::FileDescriptor>::Log(const param_type& p, |
void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, |
const param_type& p) { |
GetParamSize(sizer, p.GetMemoryObject()); |
- uint32_t dummy = 0; |
+ ParamTraits<base::UnguessableToken>::GetSize(sizer, p.GetGUID()); |
+ |
+ // Size of p.GetSize(). |
+ uint64_t dummy = 0; |
+ static_assert(sizeof(dummy) == sizeof(size_t), |
+ "The dummy size must match the size written in ::Write"); |
GetParamSize(sizer, dummy); |
} |
@@ -686,6 +691,8 @@ void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
const param_type& p) { |
MachPortMac mach_port_mac(p.GetMemoryObject()); |
ParamTraits<MachPortMac>::Write(m, mach_port_mac); |
+ ParamTraits<base::UnguessableToken>::Write(m, p.GetGUID()); |
Will Harris
2017/05/04 17:50:51
should there be a DCHECK here that guid is not emp
erikchen
2017/05/04 19:21:13
Yes, done.
|
+ |
size_t size = 0; |
bool result = p.GetSize(&size); |
DCHECK(result); |
@@ -704,12 +711,16 @@ bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
if (!ParamTraits<MachPortMac>::Read(m, iter, &mach_port_mac)) |
return false; |
+ base::UnguessableToken guid; |
+ if (!ParamTraits<base::UnguessableToken>::Read(m, iter, &guid)) |
Ken Rockot(use gerrit already)
2017/05/04 17:54:50
We have templated helper functions for this in ipc
erikchen
2017/05/04 19:21:13
Done.
|
+ return false; |
+ |
uint32_t size; |
if (!ParamTraits<uint32_t>::Read(m, iter, &size)) |
return false; |
*r = base::SharedMemoryHandle(mach_port_mac.get_mach_port(), |
- static_cast<size_t>(size)); |
+ static_cast<size_t>(size), guid); |
return true; |
} |
@@ -717,14 +728,18 @@ void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
std::string* l) { |
l->append("Mach port: "); |
LogParam(p.GetMemoryObject(), l); |
+ l->append("GUID: "); |
+ ParamTraits<base::UnguessableToken>::Log(p.GetGUID(), l); |
} |
#elif defined(OS_WIN) |
void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* s, |
const param_type& p) { |
GetParamSize(s, p.IsValid()); |
- if (p.IsValid()) |
+ if (p.IsValid()) { |
GetParamSize(s, p.GetHandle()); |
+ ParamTraits<base::UnguessableToken>::GetSize(sizer, p.GetGUID()); |
+ } |
} |
void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
@@ -742,6 +757,8 @@ void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
// reference. |
if (p.OwnershipPassesToIPC()) |
p.Close(); |
+ |
+ ParamTraits<base::UnguessableToken>::Write(m, p.GetGUID()); |
} |
bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
@@ -758,20 +775,30 @@ bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
HandleWin handle_win; |
if (!ParamTraits<HandleWin>::Read(m, iter, &handle_win)) |
return false; |
- *r = base::SharedMemoryHandle(handle_win.get_handle()); |
+ |
+ base::UnguessableToken guid; |
+ if (!ParamTraits<base::UnguessableToken>::Read(m, iter, &guid)) |
+ return false; |
+ |
+ *r = base::SharedMemoryHandle(handle_win.get_handle(), guid); |
return true; |
} |
void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
std::string* l) { |
+ l->append("HANDLE: "); |
LogParam(p.GetHandle(), l); |
+ l->append("GUID: "); |
+ ParamTraits<base::UnguessableToken>::Log(p.GetGUID(), l); |
} |
#elif defined(OS_POSIX) |
void ParamTraits<base::SharedMemoryHandle>::GetSize(base::PickleSizer* sizer, |
const param_type& p) { |
GetParamSize(sizer, p.IsValid()); |
- if (p.IsValid()) |
+ if (p.IsValid()) { |
sizer->AddAttachment(); |
+ ParamTraits<base::UnguessableToken>::GetSize(sizer, p.GetGUID()); |
+ } |
} |
void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
@@ -791,6 +818,7 @@ void ParamTraits<base::SharedMemoryHandle>::Write(base::Pickle* m, |
new internal::PlatformFileAttachment(p.GetHandle()))) |
NOTREACHED(); |
} |
+ ParamTraits<base::UnguessableToken>::Write(m, p.GetGUID()); |
} |
bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
@@ -814,10 +842,16 @@ bool ParamTraits<base::SharedMemoryHandle>::Read(const base::Pickle* m, |
return false; |
} |
- *r = base::SharedMemoryHandle(base::FileDescriptor( |
- static_cast<internal::PlatformFileAttachment*>(attachment.get()) |
- ->TakePlatformFile(), |
- true)); |
+ base::UnguessableToken guid; |
+ if (!ParamTraits<base::UnguessableToken>::Read(m, iter, &guid)) |
+ return false; |
+ |
+ *r = base::SharedMemoryHandle( |
+ base::FileDescriptor( |
+ static_cast<internal::PlatformFileAttachment*>(attachment.get()) |
+ ->TakePlatformFile(), |
+ true), |
+ guid); |
return true; |
} |
@@ -828,6 +862,8 @@ void ParamTraits<base::SharedMemoryHandle>::Log(const param_type& p, |
} else { |
l->append(base::StringPrintf("FD(%d)", p.GetHandle())); |
} |
+ l->append("GUID: "); |
+ ParamTraits<base::UnguessableToken>::Log(p.GetGUID(), l); |
} |
#endif // defined(OS_MACOSX) && !defined(OS_IOS) |