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

Side by Side Diff: ppapi/proxy/nacl_message_scanner.cc

Issue 1512733003: PNaCl: Use Chrome IPC to talk to the linker process, instead of SRPC (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase + cleanup Created 5 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ppapi/proxy/nacl_message_scanner.h" 5 #include "ppapi/proxy/nacl_message_scanner.h"
6 6
7 #include <vector> 7 #include <vector>
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "ipc/ipc_message.h" 9 #include "ipc/ipc_message.h"
10 #include "ipc/ipc_message_macros.h" 10 #include "ipc/ipc_message_macros.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (results->pp_resource && !results->nested_msg_callback.is_null()) { 131 if (results->pp_resource && !results->nested_msg_callback.is_null()) {
132 SerializedHandle* handle = NULL; 132 SerializedHandle* handle = NULL;
133 if (results->handles.size() == 1) 133 if (results->handles.size() == 1)
134 handle = &results->handles[0]; 134 handle = &results->handles[0];
135 results->nested_msg_callback.Run(results->pp_resource, param, handle); 135 results->nested_msg_callback.Run(results->pp_resource, param, handle);
136 } 136 }
137 if (results->new_msg) 137 if (results->new_msg)
138 IPC::WriteParam(results->new_msg.get(), param); 138 IPC::WriteParam(results->new_msg.get(), param);
139 } 139 }
140 140
141 template <class T>
142 void ScanParam(const std::vector<T>& vec, ScanningResults* results) {
143 if (results->new_msg)
144 IPC::WriteParam(results->new_msg.get(), static_cast<int>(vec.size()));
145 for (const T& element : vec) {
146 ScanParam(element, results);
147 }
148 }
149
141 // Overload to match all other types. If we need to rewrite the message, write 150 // Overload to match all other types. If we need to rewrite the message, write
142 // the parameter. 151 // the parameter.
143 template <class T> 152 template <class T>
144 void ScanParam(const T& param, ScanningResults* results) { 153 void ScanParam(const T& param, ScanningResults* results) {
145 if (results->new_msg) 154 if (results->new_msg)
146 IPC::WriteParam(results->new_msg.get(), param); 155 IPC::WriteParam(results->new_msg.get(), param);
147 } 156 }
148 157
149 // These just break apart the given tuple and run ScanParam over each param. 158 // These just break apart the given tuple and run ScanParam over each param.
150 // The idea is to scan elements in the tuple which require special handling, 159 // The idea is to scan elements in the tuple which require special handling,
(...skipping 29 matching lines...) Expand all
180 } 189 }
181 bool ScanMessage(ScanningResults* results) { 190 bool ScanMessage(ScanningResults* results) {
182 typename base::TupleTypes<typename MessageType::Schema::Param>::ValueTuple 191 typename base::TupleTypes<typename MessageType::Schema::Param>::ValueTuple
183 params; 192 params;
184 if (!MessageType::Read(msg_, &params)) 193 if (!MessageType::Read(msg_, &params))
185 return false; 194 return false;
186 ScanTuple(params, results); 195 ScanTuple(params, results);
187 return true; 196 return true;
188 } 197 }
189 198
190 bool ScanReply(ScanningResults* results) { 199 bool ScanSyncMessage(ScanningResults* results) {
bbudge 2015/12/16 20:30:06 David Michael has implemented this in a patch we h
Mark Seaborn 2015/12/17 06:09:56 Thanks for pointing that out! I was able to debug
bbudge 2015/12/17 19:10:21 Not at all. Thank you for figuring out the problem
200 typename base::TupleTypes<typename MessageType::Schema::SendParam>
201 ::ValueTuple params;
202 if (!MessageType::ReadSendParam(msg_, &params))
203 return false;
204 // If we need to rewrite the message, write the message id first.
205 if (results->new_msg) {
206 results->new_msg->set_sync();
207 int id = IPC::SyncMessage::GetMessageId(*msg_);
208 results->new_msg->WriteInt(id);
209 }
210 ScanTuple(params, results);
211 return true;
212 }
213
214 bool ScanSyncReply(ScanningResults* results) {
bbudge 2015/12/16 20:30:06 ScanReply?
Mark Seaborn 2015/12/17 06:09:56 I renamed the existing ScanReply() to ScanSyncRepl
bbudge 2015/12/17 19:10:21 It makes the code in CASE_FOR_REPLY confusing thou
Mark Seaborn 2015/12/21 22:58:50 OK, I can just rename this back to ScanReply(). I
191 typename base::TupleTypes<typename MessageType::Schema::ReplyParam> 215 typename base::TupleTypes<typename MessageType::Schema::ReplyParam>
192 ::ValueTuple params; 216 ::ValueTuple params;
193 if (!MessageType::ReadReplyParam(msg_, &params)) 217 if (!MessageType::ReadReplyParam(msg_, &params))
194 return false; 218 return false;
195 // If we need to rewrite the message, write the message id first. 219 // If we need to rewrite the message, write the message id first.
196 if (results->new_msg) { 220 if (results->new_msg) {
197 results->new_msg->set_reply(); 221 results->new_msg->set_reply();
198 int id = IPC::SyncMessage::GetMessageId(*msg_); 222 int id = IPC::SyncMessage::GetMessageId(*msg_);
199 results->new_msg->WriteInt(id); 223 results->new_msg->WriteInt(id);
200 } 224 }
201 ScanTuple(params, results); 225 ScanTuple(params, results);
202 return true; 226 return true;
203 } 227 }
204 // TODO(dmichael): Add ScanSyncMessage for outgoing sync messages, if we ever
205 // need to scan those.
206 228
207 private: 229 private:
208 const MessageType* msg_; 230 const MessageType* msg_;
209 }; 231 };
210 232
211 } // namespace 233 } // namespace
212 234
213 #define CASE_FOR_MESSAGE(MESSAGE_TYPE) \ 235 #define CASE_FOR_MESSAGE(MESSAGE_TYPE) \
214 case MESSAGE_TYPE::ID: { \ 236 case MESSAGE_TYPE::ID: { \
215 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \ 237 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \
216 if (rewrite_msg) \ 238 if (rewrite_msg) \
217 results.new_msg.reset( \ 239 results.new_msg.reset( \
218 new IPC::Message(msg.routing_id(), msg.type(), \ 240 new IPC::Message(msg.routing_id(), msg.type(), \
219 IPC::Message::PRIORITY_NORMAL)); \ 241 IPC::Message::PRIORITY_NORMAL)); \
220 if (!scanner.ScanMessage(&results)) \ 242 if (!scanner.ScanMessage(&results)) \
221 return false; \ 243 return false; \
222 break; \ 244 break; \
223 } 245 }
246 #define CASE_FOR_SYNC_MESSAGE(MESSAGE_TYPE) \
247 case MESSAGE_TYPE::ID: { \
248 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \
249 if (rewrite_msg) \
250 results.new_msg.reset( \
251 new IPC::Message(msg.routing_id(), msg.type(), \
252 IPC::Message::PRIORITY_NORMAL)); \
253 if (!scanner.ScanSyncMessage(&results)) \
254 return false; \
255 break; \
256 }
224 #define CASE_FOR_REPLY(MESSAGE_TYPE) \ 257 #define CASE_FOR_REPLY(MESSAGE_TYPE) \
225 case MESSAGE_TYPE::ID: { \ 258 case MESSAGE_TYPE::ID: { \
226 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \ 259 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \
227 if (rewrite_msg) \ 260 if (rewrite_msg) \
228 results.new_msg.reset( \ 261 results.new_msg.reset( \
229 new IPC::Message(msg.routing_id(), msg.type(), \ 262 new IPC::Message(msg.routing_id(), msg.type(), \
230 IPC::Message::PRIORITY_NORMAL)); \ 263 IPC::Message::PRIORITY_NORMAL)); \
231 if (!scanner.ScanReply(&results)) \ 264 if (!scanner.ScanSyncReply(&results)) \
232 return false; \ 265 return false; \
233 break; \ 266 break; \
234 } 267 }
235 268
236 namespace ppapi { 269 namespace ppapi {
237 namespace proxy { 270 namespace proxy {
238 271
239 class SerializedHandle; 272 class SerializedHandle;
240 273
241 NaClMessageScanner::FileSystem::FileSystem() 274 NaClMessageScanner::FileSystem::FileSystem()
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // that there are no handles, we can cancel the rewriting by clearing the 352 // that there are no handles, we can cancel the rewriting by clearing the
320 // results.new_msg pointer. 353 // results.new_msg pointer.
321 ScanningResults results; 354 ScanningResults results;
322 results.nested_msg_callback = 355 results.nested_msg_callback =
323 base::Bind(&NaClMessageScanner::AuditNestedMessage, 356 base::Bind(&NaClMessageScanner::AuditNestedMessage,
324 base::Unretained(this)); 357 base::Unretained(this));
325 switch (type) { 358 switch (type) {
326 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated) 359 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated)
327 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage) 360 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage)
328 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply) 361 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply)
362 CASE_FOR_SYNC_MESSAGE(PpapiMsg_PnaclTranslatorLink)
329 CASE_FOR_REPLY(PpapiHostMsg_OpenResource) 363 CASE_FOR_REPLY(PpapiHostMsg_OpenResource)
330 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_Create) 364 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_Create)
331 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer) 365 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer)
332 CASE_FOR_REPLY(PpapiHostMsg_PPBImageData_CreateSimple) 366 CASE_FOR_REPLY(PpapiHostMsg_PPBImageData_CreateSimple)
333 CASE_FOR_REPLY(PpapiHostMsg_ResourceSyncCall) 367 CASE_FOR_REPLY(PpapiHostMsg_ResourceSyncCall)
334 CASE_FOR_REPLY(PpapiHostMsg_SharedMemory_CreateSharedMemory) 368 CASE_FOR_REPLY(PpapiHostMsg_SharedMemory_CreateSharedMemory)
335 default: 369 default:
336 // Do nothing for messages we don't know. 370 // Do nothing for messages we don't know.
337 break; 371 break;
338 } 372 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 fio_it->second->SetMaxWrittenOffset(offset_it->second); 553 fio_it->second->SetMaxWrittenOffset(offset_it->second);
520 } 554 }
521 } 555 }
522 break; 556 break;
523 } 557 }
524 } 558 }
525 } 559 }
526 560
527 } // namespace proxy 561 } // namespace proxy
528 } // namespace ppapi 562 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698