| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" | 7 #include "native_client/src/shared/ppapi_proxy/object_serialize.h" |
| 8 | 8 |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 default: | 205 default: |
| 206 return false; | 206 return false; |
| 207 } | 207 } |
| 208 offset += element_size; | 208 offset += element_size; |
| 209 } | 209 } |
| 210 return true; | 210 return true; |
| 211 } | 211 } |
| 212 | 212 |
| 213 bool DeserializeString(char* p, | 213 bool DeserializeString(char* p, |
| 214 PP_Var* var, | 214 PP_Var* var, |
| 215 uint32_t* element_size) { | 215 uint32_t* element_size, |
| 216 NaClSrpcChannel* channel) { |
| 216 SerializedString* ss = reinterpret_cast<SerializedString*>(p); | 217 SerializedString* ss = reinterpret_cast<SerializedString*>(p); |
| 217 uint32_t string_length = ss->fixed.u.string_length; | 218 uint32_t string_length = ss->fixed.u.string_length; |
| 218 if (AddWouldOverflow(string_length, kStringRoundBase - 1)) { | 219 if (AddWouldOverflow(string_length, kStringRoundBase - 1)) { |
| 219 // Rounding to the next 8 would overflow. | 220 // Rounding to the next 8 would overflow. |
| 220 return false; | 221 return false; |
| 221 } | 222 } |
| 222 uint32_t rounded_length = RoundedStringBytes(string_length); | 223 uint32_t rounded_length = RoundedStringBytes(string_length); |
| 223 if (0 == string_length) { | 224 if (0 == string_length) { |
| 224 // Zero-length string. Rely on what the PPB_Var does. | 225 // Zero-length string. Rely on what the PPB_Var does. |
| 225 *var = VarInterface()->VarFromUtf8(ss->string_bytes, 0); | 226 *var = VarInterface()->VarFromUtf8(LookupModuleIdForSrpcChannel(channel), |
| 227 ss->string_bytes, |
| 228 0); |
| 226 } else { | 229 } else { |
| 227 // We need to copy the string payload using memory allocated by | 230 // We need to copy the string payload using memory allocated by |
| 228 // NPN_MemAlloc. | 231 // NPN_MemAlloc. |
| 229 void* copy = CoreInterface()->MemAlloc(string_length + 1); | 232 void* copy = CoreInterface()->MemAlloc(string_length + 1); |
| 230 if (NULL == copy) { | 233 if (NULL == copy) { |
| 231 // Memory allocation failed. | 234 // Memory allocation failed. |
| 232 return false; | 235 return false; |
| 233 } else { | 236 } else { |
| 234 memmove(copy, ss->string_bytes, string_length); | 237 memmove(copy, ss->string_bytes, string_length); |
| 235 } | 238 } |
| 236 *var = VarInterface()->VarFromUtf8(reinterpret_cast<const char*>(copy), | 239 *var = VarInterface()->VarFromUtf8(LookupModuleIdForSrpcChannel(channel), |
| 240 reinterpret_cast<const char*>(copy), |
| 237 string_length); | 241 string_length); |
| 238 } | 242 } |
| 239 // Compute the "element_size", or offset in the serialized form from | 243 // Compute the "element_size", or offset in the serialized form from |
| 240 // the serialized string that we just read. | 244 // the serialized string that we just read. |
| 241 if (AddWouldOverflow(rounded_length, sizeof(SerializedFixed))) { | 245 if (AddWouldOverflow(rounded_length, sizeof(SerializedFixed))) { |
| 242 return false; | 246 return false; |
| 243 } | 247 } |
| 244 *element_size = sizeof(SerializedFixed) + rounded_length; | 248 *element_size = sizeof(SerializedFixed) + rounded_length; |
| 245 return true; | 249 return true; |
| 246 } | 250 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 274 vars[i].value.as_int = s->u.int32_value; | 278 vars[i].value.as_int = s->u.int32_value; |
| 275 element_size = sizeof(SerializedFixed); | 279 element_size = sizeof(SerializedFixed); |
| 276 break; | 280 break; |
| 277 case PP_VARTYPE_DOUBLE: { | 281 case PP_VARTYPE_DOUBLE: { |
| 278 SerializedDouble* sd = reinterpret_cast<SerializedDouble*>(p); | 282 SerializedDouble* sd = reinterpret_cast<SerializedDouble*>(p); |
| 279 vars[i].value.as_double = sd->double_value; | 283 vars[i].value.as_double = sd->double_value; |
| 280 element_size = sizeof(SerializedDouble); | 284 element_size = sizeof(SerializedDouble); |
| 281 break; | 285 break; |
| 282 } | 286 } |
| 283 case PP_VARTYPE_STRING: | 287 case PP_VARTYPE_STRING: |
| 284 if (!DeserializeString(p, &vars[i], &element_size)) { | 288 if (!DeserializeString(p, &vars[i], &element_size, channel)) { |
| 285 return false; | 289 return false; |
| 286 } | 290 } |
| 287 break; | 291 break; |
| 288 case PP_VARTYPE_OBJECT: { | 292 case PP_VARTYPE_OBJECT: { |
| 289 SerializedObject* so = reinterpret_cast<SerializedObject*>(p); | 293 SerializedObject* so = reinterpret_cast<SerializedObject*>(p); |
| 290 ObjectCapability capability = so->capability; | 294 ObjectCapability capability = so->capability; |
| 291 vars[i] = ObjectProxy::New(capability, channel); | 295 vars[i] = ObjectProxy::New(capability, channel); |
| 292 element_size = sizeof(SerializedObject); | 296 element_size = sizeof(SerializedObject); |
| 293 break; | 297 break; |
| 294 } | 298 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 return false; | 375 return false; |
| 372 } | 376 } |
| 373 // Read the serialized PP_Vars into the allocated memory. | 377 // Read the serialized PP_Vars into the allocated memory. |
| 374 if (!DeserializePpVar(channel, bytes, length, vars, argc)) { | 378 if (!DeserializePpVar(channel, bytes, length, vars, argc)) { |
| 375 return false; | 379 return false; |
| 376 } | 380 } |
| 377 return true; | 381 return true; |
| 378 } | 382 } |
| 379 | 383 |
| 380 } // namespace ppapi_proxy | 384 } // namespace ppapi_proxy |
| OLD | NEW |