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

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: one more per Dmitry 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
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 param_type* r) { 185 param_type* r) {
186 return iter->ReadInt(reinterpret_cast<int*>(r)); 186 return iter->ReadInt(reinterpret_cast<int*>(r));
187 } 187 }
188 IPC_EXPORT static void Log(const param_type& p, std::string* l); 188 IPC_EXPORT static void Log(const param_type& p, std::string* l);
189 }; 189 };
190 190
191 template <> 191 template <>
192 struct ParamTraits<long> { 192 struct ParamTraits<long> {
193 typedef long param_type; 193 typedef long param_type;
194 static void Write(Message* m, const param_type& p) { 194 static void Write(Message* m, const param_type& p) {
195 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); 195 // To ensure compatibility between 32-bit and 64-bit processes, send as
196 // 64 bit size. We can't check on the writing side if reading may overflow
197 // if sending from 64-bit process and reading from 32-bit process, since we
198 // don't know if this IPC parameter is 64 bit always (i.e. from an int64_t
199 // typedef) or if it's from a size_t.
200 m->WriteLong(p);
196 } 201 }
197 static bool Read(const Message* m, 202 static bool Read(const Message* m,
198 base::PickleIterator* iter, 203 base::PickleIterator* iter,
199 param_type* r) { 204 param_type* r) {
200 return iter->ReadLong(r); 205 return iter->ReadLong(r);
201 } 206 }
202 IPC_EXPORT static void Log(const param_type& p, std::string* l); 207 IPC_EXPORT static void Log(const param_type& p, std::string* l);
203 }; 208 };
204 209
205 template <> 210 template <>
206 struct ParamTraits<unsigned long> { 211 struct ParamTraits<unsigned long> {
207 typedef unsigned long param_type; 212 typedef unsigned long param_type;
208 static void Write(Message* m, const param_type& p) { 213 static void Write(Message* m, const param_type& p) {
209 m->WriteLongUsingDangerousNonPortableLessPersistableForm(p); 214 // See comment in ParamTraits<long>::Write.
215 m->WriteLong(p);
210 } 216 }
211 static bool Read(const Message* m, 217 static bool Read(const Message* m,
212 base::PickleIterator* iter, 218 base::PickleIterator* iter,
213 param_type* r) { 219 param_type* r) {
214 return iter->ReadLong(reinterpret_cast<long*>(r)); 220 return iter->ReadLong(reinterpret_cast<long*>(r));
215 } 221 }
216 IPC_EXPORT static void Log(const param_type& p, std::string* l); 222 IPC_EXPORT static void Log(const param_type& p, std::string* l);
217 }; 223 };
218 224
219 template <> 225 template <>
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 template <typename... Ts> 1064 template <typename... Ts>
1059 static void WriteReplyParams(Message* reply, Ts... args) { 1065 static void WriteReplyParams(Message* reply, Ts... args) {
1060 ReplyParam p(args...); 1066 ReplyParam p(args...);
1061 WriteParam(reply, p); 1067 WriteParam(reply, p);
1062 } 1068 }
1063 }; 1069 };
1064 1070
1065 } // namespace IPC 1071 } // namespace IPC
1066 1072
1067 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1073 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698