diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 00:05:04 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-29 00:05:04 +0000 |
commit | 34d4861069f6528aac208a3268f8c4946d301a16 (patch) | |
tree | 0efd4735b9912a93b220f9e312d7ca14cf281360 /ipc/ipc_message_utils.cc | |
parent | b9ef2965a07ca50fd94f1ab1d22ffcfdf62a2b6d (diff) | |
download | chromium_src-34d4861069f6528aac208a3268f8c4946d301a16.zip chromium_src-34d4861069f6528aac208a3268f8c4946d301a16.tar.gz chromium_src-34d4861069f6528aac208a3268f8c4946d301a16.tar.bz2 |
Make the serialization of IPC::Messages inside other IPC::Messages independent
of the platform.
This is necessary for sending nested messages between nacl (which the IPC
system thinks is posix and so has extra header goo) and a Windows client app
(which doesn't have this stuff).
BUG=
Review URL: https://chromiumcodereview.appspot.com/10667002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144840 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message_utils.cc')
-rw-r--r-- | ipc/ipc_message_utils.cc | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/ipc/ipc_message_utils.cc b/ipc/ipc_message_utils.cc index a8392cf..66a6877 100644 --- a/ipc/ipc_message_utils.cc +++ b/ipc/ipc_message_utils.cc @@ -730,22 +730,43 @@ void ParamTraits<LogData>::Log(const param_type& p, std::string* l) { } void ParamTraits<Message>::Write(Message* m, const Message& p) { - DCHECK(p.size() <= INT_MAX); - int message_size = static_cast<int>(p.size()); - m->WriteInt(message_size); - m->WriteData(reinterpret_cast<const char*>(p.data()), message_size); +#if defined(OS_POSIX) + // We don't serialize the file descriptors in the nested message, so there + // better not be any. + DCHECK(!p.HasFileDescriptors()); +#endif + + // Don't just write out the message. This is used to send messages between + // NaCl (Posix environment) and the browser (could be on Windows). The message + // header formats differ between these systems (so does handle sharing, but + // we already asserted we don't have any handles). So just write out the + // parts of the header we use. + // + // Be careful also to use only explicitly-sized types. The NaCl environment + // could be 64-bit and the host browser could be 32-bits. The nested message + // may or may not be safe to send between 32-bit and 64-bit systems, but we + // leave that up to the code sending the message to ensure. + m->WriteUInt32(static_cast<uint32>(p.routing_id())); + m->WriteUInt32(p.type()); + m->WriteUInt32(p.flags()); + m->WriteData(p.payload(), static_cast<uint32>(p.payload_size())); } bool ParamTraits<Message>::Read(const Message* m, PickleIterator* iter, Message* r) { - int size; - if (!m->ReadInt(iter, &size)) + uint32 routing_id, type, flags; + if (!m->ReadUInt32(iter, &routing_id) || + !m->ReadUInt32(iter, &type) || + !m->ReadUInt32(iter, &flags)) return false; - const char* data; - if (!m->ReadData(iter, &data, &size)) + + int payload_size; + const char* payload; + if (!m->ReadData(iter, &payload, &payload_size)) return false; - *r = Message(data, size); - return true; + + r->SetHeaderValues(static_cast<int32>(routing_id), type, flags); + return r->WriteBytes(payload, payload_size); } void ParamTraits<Message>::Log(const Message& p, std::string* l) { |