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

Side by Side Diff: ipc/ipc_message_utils.h

Issue 1619363002: Add compile time checks against longs being used in IPC structs on 32 bit Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 4 years, 10 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/pickle_unittest.cc ('k') | ipc/ipc_message_utils.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 #ifndef IPC_IPC_MESSAGE_UTILS_H_ 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_
6 #define IPC_IPC_MESSAGE_UTILS_H_ 6 #define IPC_IPC_MESSAGE_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); } 176 static void Write(base::Pickle* m, const param_type& p) { m->WriteInt(p); }
177 static bool Read(const base::Pickle* m, 177 static bool Read(const base::Pickle* m,
178 base::PickleIterator* iter, 178 base::PickleIterator* iter,
179 param_type* r) { 179 param_type* r) {
180 return iter->ReadInt(reinterpret_cast<int*>(r)); 180 return iter->ReadInt(reinterpret_cast<int*>(r));
181 } 181 }
182 IPC_EXPORT static void Log(const param_type& p, std::string* l); 182 IPC_EXPORT static void Log(const param_type& p, std::string* l);
183 }; 183 };
184 184
185 // long isn't safe to send over IPC because it's 4 bytes on 32 bit builds but
186 // 8 bytes on 64 bit builds. So if a 32 bit and 64 bit process have a channel
187 // that would cause problem.
188 // We need to keep this on for a few configs:
189 // 1) Windows because DWORD is typedef'd to it, which is fine because we have
190 // very few IPCs that cross this boundary.
191 // 2) We also need to keep it for Linux for two reasons: int64_t is typedef'd
192 // to long, and gfx::PluginWindow is long and is used in one GPU IPC.
193 // 3) Android 64 bit also has int64_t typedef'd to long.
194 // Since we want to support Android 32<>64 bit IPC, as long as we don't have
195 // these traits for 32 bit ARM then that'll catch any errors.
196 #if defined(OS_WIN) || defined(OS_LINUX) || defined(ARCH_CPU_ARM64)
Tom Sepez 2016/02/10 18:00:07 nit: you might want to define a IPC_ALLOW_LONG her
jam 2016/02/10 18:19:41 i think in practice this won't really change. if i
185 template <> 197 template <>
186 struct ParamTraits<long> { 198 struct ParamTraits<long> {
187 typedef long param_type; 199 typedef long param_type;
188 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 200 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
189 sizer->AddLongUsingDangerousNonPortableLessPersistableForm(); 201 sizer->AddLong();
190 } 202 }
191 static void Write(base::Pickle* m, const param_type& p) { 203 static void Write(base::Pickle* m, const param_type& p) {
192 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); 204 m->WriteLong(p);
193 } 205 }
194 static bool Read(const base::Pickle* m, 206 static bool Read(const base::Pickle* m,
195 base::PickleIterator* iter, 207 base::PickleIterator* iter,
196 param_type* r) { 208 param_type* r) {
197 return iter->ReadLong(r); 209 return iter->ReadLong(r);
198 } 210 }
199 IPC_EXPORT static void Log(const param_type& p, std::string* l); 211 IPC_EXPORT static void Log(const param_type& p, std::string* l);
200 }; 212 };
201 213
202 template <> 214 template <>
203 struct ParamTraits<unsigned long> { 215 struct ParamTraits<unsigned long> {
204 typedef unsigned long param_type; 216 typedef unsigned long param_type;
205 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 217 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
206 sizer->AddLongUsingDangerousNonPortableLessPersistableForm(); 218 sizer->AddLong();
207 } 219 }
208 static void Write(base::Pickle* m, const param_type& p) { 220 static void Write(base::Pickle* m, const param_type& p) {
209 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); 221 m->WriteLong(p);
210 } 222 }
211 static bool Read(const base::Pickle* m, 223 static bool Read(const base::Pickle* m,
212 base::PickleIterator* iter, 224 base::PickleIterator* iter,
213 param_type* r) { 225 param_type* r) {
214 return iter->ReadLong(reinterpret_cast<long*>(r)); 226 return iter->ReadLong(reinterpret_cast<long*>(r));
215 } 227 }
216 IPC_EXPORT static void Log(const param_type& p, std::string* l); 228 IPC_EXPORT static void Log(const param_type& p, std::string* l);
217 }; 229 };
230 #endif
218 231
219 template <> 232 template <>
220 struct ParamTraits<long long> { 233 struct ParamTraits<long long> {
221 typedef long long param_type; 234 typedef long long param_type;
222 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 235 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
223 sizer->AddInt64(); 236 sizer->AddInt64();
224 } 237 }
225 static void Write(base::Pickle* m, const param_type& p) { 238 static void Write(base::Pickle* m, const param_type& p) {
226 m->WriteInt64(static_cast<int64_t>(p)); 239 m->WriteInt64(static_cast<int64_t>(p));
227 } 240 }
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 template <class ReplyParamType> 1083 template <class ReplyParamType>
1071 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, 1084 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1072 const Message* msg) {} 1085 const Message* msg) {}
1073 1086
1074 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} 1087 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
1075 #endif 1088 #endif
1076 1089
1077 } // namespace IPC 1090 } // namespace IPC
1078 1091
1079 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1092 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW
« no previous file with comments | « base/pickle_unittest.cc ('k') | ipc/ipc_message_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698