| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (results->pp_resource && !results->nested_msg_callback.is_null()) { | 136 if (results->pp_resource && !results->nested_msg_callback.is_null()) { |
| 137 SerializedHandle* handle = NULL; | 137 SerializedHandle* handle = NULL; |
| 138 if (results->handles.size() == 1) | 138 if (results->handles.size() == 1) |
| 139 handle = &results->handles[0]; | 139 handle = &results->handles[0]; |
| 140 results->nested_msg_callback.Run(results->pp_resource, param, handle); | 140 results->nested_msg_callback.Run(results->pp_resource, param, handle); |
| 141 } | 141 } |
| 142 if (results->new_msg) | 142 if (results->new_msg) |
| 143 IPC::WriteParam(results->new_msg.get(), param); | 143 IPC::WriteParam(results->new_msg.get(), param); |
| 144 } | 144 } |
| 145 | 145 |
| 146 template <class T> |
| 147 void ScanParam(const std::vector<T>& vec, ScanningResults* results) { |
| 148 if (results->new_msg) |
| 149 IPC::WriteParam(results->new_msg.get(), static_cast<int>(vec.size())); |
| 150 for (const T& element : vec) { |
| 151 ScanParam(element, results); |
| 152 } |
| 153 } |
| 154 |
| 146 // Overload to match all other types. If we need to rewrite the message, write | 155 // Overload to match all other types. If we need to rewrite the message, write |
| 147 // the parameter. | 156 // the parameter. |
| 148 template <class T> | 157 template <class T> |
| 149 void ScanParam(const T& param, ScanningResults* results) { | 158 void ScanParam(const T& param, ScanningResults* results) { |
| 150 if (results->new_msg) | 159 if (results->new_msg) |
| 151 IPC::WriteParam(results->new_msg.get(), param); | 160 IPC::WriteParam(results->new_msg.get(), param); |
| 152 } | 161 } |
| 153 | 162 |
| 154 // These just break apart the given tuple and run ScanParam over each param. | 163 // These just break apart the given tuple and run ScanParam over each param. |
| 155 // The idea is to scan elements in the tuple which require special handling, | 164 // The idea is to scan elements in the tuple which require special handling, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 185 } | 194 } |
| 186 bool ScanMessage(ScanningResults* results) { | 195 bool ScanMessage(ScanningResults* results) { |
| 187 typename base::TupleTypes<typename MessageType::Schema::Param>::ValueTuple | 196 typename base::TupleTypes<typename MessageType::Schema::Param>::ValueTuple |
| 188 params; | 197 params; |
| 189 if (!MessageType::Read(msg_, ¶ms)) | 198 if (!MessageType::Read(msg_, ¶ms)) |
| 190 return false; | 199 return false; |
| 191 ScanTuple(params, results); | 200 ScanTuple(params, results); |
| 192 return true; | 201 return true; |
| 193 } | 202 } |
| 194 | 203 |
| 204 bool ScanSyncMessage(ScanningResults* results) { |
| 205 typename base::TupleTypes<typename MessageType::Schema::SendParam> |
| 206 ::ValueTuple params; |
| 207 if (!MessageType::ReadSendParam(msg_, ¶ms)) |
| 208 return false; |
| 209 // If we need to rewrite the message, write the message id first. |
| 210 if (results->new_msg) { |
| 211 results->new_msg->set_sync(); |
| 212 int id = IPC::SyncMessage::GetMessageId(*msg_); |
| 213 results->new_msg->WriteInt(id); |
| 214 } |
| 215 ScanTuple(params, results); |
| 216 return true; |
| 217 } |
| 218 |
| 195 bool ScanReply(ScanningResults* results) { | 219 bool ScanReply(ScanningResults* results) { |
| 196 typename base::TupleTypes<typename MessageType::Schema::ReplyParam> | 220 typename base::TupleTypes<typename MessageType::Schema::ReplyParam> |
| 197 ::ValueTuple params; | 221 ::ValueTuple params; |
| 198 if (!MessageType::ReadReplyParam(msg_, ¶ms)) | 222 if (!MessageType::ReadReplyParam(msg_, ¶ms)) |
| 199 return false; | 223 return false; |
| 200 // If we need to rewrite the message, write the message id first. | 224 // If we need to rewrite the message, write the message id first. |
| 201 if (results->new_msg) { | 225 if (results->new_msg) { |
| 202 results->new_msg->set_reply(); | 226 results->new_msg->set_reply(); |
| 203 int id = IPC::SyncMessage::GetMessageId(*msg_); | 227 int id = IPC::SyncMessage::GetMessageId(*msg_); |
| 204 results->new_msg->WriteInt(id); | 228 results->new_msg->WriteInt(id); |
| 205 } | 229 } |
| 206 ScanTuple(params, results); | 230 ScanTuple(params, results); |
| 207 return true; | 231 return true; |
| 208 } | 232 } |
| 209 // TODO(dmichael): Add ScanSyncMessage for outgoing sync messages, if we ever | |
| 210 // need to scan those. | |
| 211 | 233 |
| 212 private: | 234 private: |
| 213 const MessageType* msg_; | 235 const MessageType* msg_; |
| 214 }; | 236 }; |
| 215 | 237 |
| 216 } // namespace | 238 } // namespace |
| 217 | 239 |
| 218 #define CASE_FOR_MESSAGE(MESSAGE_TYPE) \ | 240 #define CASE_FOR_MESSAGE(MESSAGE_TYPE) \ |
| 219 case MESSAGE_TYPE::ID: { \ | 241 case MESSAGE_TYPE::ID: { \ |
| 220 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \ | 242 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \ |
| 221 if (rewrite_msg) \ | 243 if (rewrite_msg) \ |
| 222 results.new_msg.reset( \ | 244 results.new_msg.reset( \ |
| 223 new IPC::Message(msg.routing_id(), msg.type(), \ | 245 new IPC::Message(msg.routing_id(), msg.type(), \ |
| 224 IPC::Message::PRIORITY_NORMAL)); \ | 246 IPC::Message::PRIORITY_NORMAL)); \ |
| 225 if (!scanner.ScanMessage(&results)) \ | 247 if (!scanner.ScanMessage(&results)) \ |
| 226 return false; \ | 248 return false; \ |
| 227 break; \ | 249 break; \ |
| 228 } | 250 } |
| 251 #define CASE_FOR_SYNC_MESSAGE(MESSAGE_TYPE) \ |
| 252 case MESSAGE_TYPE::ID: { \ |
| 253 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \ |
| 254 if (rewrite_msg) \ |
| 255 results.new_msg.reset( \ |
| 256 new IPC::Message(msg.routing_id(), msg.type(), \ |
| 257 IPC::Message::PRIORITY_NORMAL)); \ |
| 258 if (!scanner.ScanSyncMessage(&results)) \ |
| 259 return false; \ |
| 260 break; \ |
| 261 } |
| 229 #define CASE_FOR_REPLY(MESSAGE_TYPE) \ | 262 #define CASE_FOR_REPLY(MESSAGE_TYPE) \ |
| 230 case MESSAGE_TYPE::ID: { \ | 263 case MESSAGE_TYPE::ID: { \ |
| 231 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \ | 264 MessageScannerImpl<MESSAGE_TYPE> scanner(&msg); \ |
| 232 if (rewrite_msg) \ | 265 if (rewrite_msg) \ |
| 233 results.new_msg.reset( \ | 266 results.new_msg.reset( \ |
| 234 new IPC::Message(msg.routing_id(), msg.type(), \ | 267 new IPC::Message(msg.routing_id(), msg.type(), \ |
| 235 IPC::Message::PRIORITY_NORMAL)); \ | 268 IPC::Message::PRIORITY_NORMAL)); \ |
| 236 if (!scanner.ScanReply(&results)) \ | 269 if (!scanner.ScanReply(&results)) \ |
| 237 return false; \ | 270 return false; \ |
| 238 break; \ | 271 break; \ |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // that there are no handles, we can cancel the rewriting by clearing the | 357 // that there are no handles, we can cancel the rewriting by clearing the |
| 325 // results.new_msg pointer. | 358 // results.new_msg pointer. |
| 326 ScanningResults results; | 359 ScanningResults results; |
| 327 results.nested_msg_callback = | 360 results.nested_msg_callback = |
| 328 base::Bind(&NaClMessageScanner::AuditNestedMessage, | 361 base::Bind(&NaClMessageScanner::AuditNestedMessage, |
| 329 base::Unretained(this)); | 362 base::Unretained(this)); |
| 330 switch (type) { | 363 switch (type) { |
| 331 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated) | 364 CASE_FOR_MESSAGE(PpapiMsg_PPBAudio_NotifyAudioStreamCreated) |
| 332 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage) | 365 CASE_FOR_MESSAGE(PpapiMsg_PPPMessaging_HandleMessage) |
| 333 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply) | 366 CASE_FOR_MESSAGE(PpapiPluginMsg_ResourceReply) |
| 367 CASE_FOR_SYNC_MESSAGE(PpapiMsg_PnaclTranslatorLink) |
| 334 CASE_FOR_REPLY(PpapiHostMsg_OpenResource) | 368 CASE_FOR_REPLY(PpapiHostMsg_OpenResource) |
| 335 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_Create) | 369 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_Create) |
| 336 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer) | 370 CASE_FOR_REPLY(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer) |
| 337 CASE_FOR_REPLY(PpapiHostMsg_PPBImageData_CreateSimple) | 371 CASE_FOR_REPLY(PpapiHostMsg_PPBImageData_CreateSimple) |
| 338 CASE_FOR_REPLY(PpapiHostMsg_ResourceSyncCall) | 372 CASE_FOR_REPLY(PpapiHostMsg_ResourceSyncCall) |
| 339 CASE_FOR_REPLY(PpapiHostMsg_SharedMemory_CreateSharedMemory) | 373 CASE_FOR_REPLY(PpapiHostMsg_SharedMemory_CreateSharedMemory) |
| 340 default: | 374 default: |
| 341 // Do nothing for messages we don't know. | 375 // Do nothing for messages we don't know. |
| 342 break; | 376 break; |
| 343 } | 377 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 fio_it->second->SetMaxWrittenOffset(offset_it->second); | 558 fio_it->second->SetMaxWrittenOffset(offset_it->second); |
| 525 } | 559 } |
| 526 } | 560 } |
| 527 break; | 561 break; |
| 528 } | 562 } |
| 529 } | 563 } |
| 530 } | 564 } |
| 531 | 565 |
| 532 } // namespace proxy | 566 } // namespace proxy |
| 533 } // namespace ppapi | 567 } // namespace ppapi |
| OLD | NEW |