| 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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
| 7 | 7 |
| 8 #include <new> | 8 #include <new> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 static bool ValidateElements(const ArrayHeader* header, | 209 static bool ValidateElements(const ArrayHeader* header, |
| 210 const ElementType* elements, | 210 const ElementType* elements, |
| 211 BoundsChecker* bounds_checker) { | 211 BoundsChecker* bounds_checker) { |
| 212 MOJO_COMPILE_ASSERT( | 212 MOJO_COMPILE_ASSERT( |
| 213 (IsSame<ElementValidateParams, NoValidateParams>::value), | 213 (IsSame<ElementValidateParams, NoValidateParams>::value), |
| 214 Handle_type_should_not_have_array_validate_params); | 214 Handle_type_should_not_have_array_validate_params); |
| 215 | 215 |
| 216 for (uint32_t i = 0; i < header->num_elements; ++i) { | 216 for (uint32_t i = 0; i < header->num_elements; ++i) { |
| 217 if (!element_is_nullable && | 217 if (!element_is_nullable && |
| 218 elements[i].value() == kEncodedInvalidHandleValue) { | 218 elements[i].value() == kEncodedInvalidHandleValue) { |
| 219 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE); | 219 ReportValidationError( |
| 220 VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, |
| 221 MakeMessageWithArrayIndex( |
| 222 "invalid handle in array expecting valid handles", |
| 223 header->num_elements, i).c_str()); |
| 220 return false; | 224 return false; |
| 221 } | 225 } |
| 222 if (!bounds_checker->ClaimHandle(elements[i])) { | 226 if (!bounds_checker->ClaimHandle(elements[i])) { |
| 223 ReportValidationError(VALIDATION_ERROR_ILLEGAL_HANDLE); | 227 ReportValidationError(VALIDATION_ERROR_ILLEGAL_HANDLE); |
| 224 return false; | 228 return false; |
| 225 } | 229 } |
| 226 } | 230 } |
| 227 return true; | 231 return true; |
| 228 } | 232 } |
| 229 }; | 233 }; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 for (uint32_t i = 0; i < header->num_elements; ++i) | 277 for (uint32_t i = 0; i < header->num_elements; ++i) |
| 274 Decode(&elements[i], handles); | 278 Decode(&elements[i], handles); |
| 275 } | 279 } |
| 276 | 280 |
| 277 template <bool element_is_nullable, typename ElementValidateParams> | 281 template <bool element_is_nullable, typename ElementValidateParams> |
| 278 static bool ValidateElements(const ArrayHeader* header, | 282 static bool ValidateElements(const ArrayHeader* header, |
| 279 const ElementType* elements, | 283 const ElementType* elements, |
| 280 BoundsChecker* bounds_checker) { | 284 BoundsChecker* bounds_checker) { |
| 281 for (uint32_t i = 0; i < header->num_elements; ++i) { | 285 for (uint32_t i = 0; i < header->num_elements; ++i) { |
| 282 if (!element_is_nullable && !elements[i].offset) { | 286 if (!element_is_nullable && !elements[i].offset) { |
| 283 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_NULL_POINTER); | 287 ReportValidationError( |
| 288 VALIDATION_ERROR_UNEXPECTED_NULL_POINTER, |
| 289 MakeMessageWithArrayIndex( |
| 290 "null in array expecting valid pointers", |
| 291 header->num_elements, i).c_str()); |
| 284 return false; | 292 return false; |
| 285 } | 293 } |
| 286 if (!ValidateEncodedPointer(&elements[i].offset)) { | 294 if (!ValidateEncodedPointer(&elements[i].offset)) { |
| 287 ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER); | 295 ReportValidationError(VALIDATION_ERROR_ILLEGAL_POINTER); |
| 288 return false; | 296 return false; |
| 289 } | 297 } |
| 290 if (!ValidateCaller<P, ElementValidateParams>::Run( | 298 if (!ValidateCaller<P, ElementValidateParams>::Run( |
| 291 DecodePointerRaw(&elements[i].offset), bounds_checker)) { | 299 DecodePointerRaw(&elements[i].offset), bounds_checker)) { |
| 292 return false; | 300 return false; |
| 293 } | 301 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 return false; | 357 return false; |
| 350 } | 358 } |
| 351 const ArrayHeader* header = static_cast<const ArrayHeader*>(data); | 359 const ArrayHeader* header = static_cast<const ArrayHeader*>(data); |
| 352 if (header->num_elements > Traits::kMaxNumElements || | 360 if (header->num_elements > Traits::kMaxNumElements || |
| 353 header->num_bytes < Traits::GetStorageSize(header->num_elements)) { | 361 header->num_bytes < Traits::GetStorageSize(header->num_elements)) { |
| 354 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER); | 362 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER); |
| 355 return false; | 363 return false; |
| 356 } | 364 } |
| 357 if (Params::expected_num_elements != 0 && | 365 if (Params::expected_num_elements != 0 && |
| 358 header->num_elements != Params::expected_num_elements) { | 366 header->num_elements != Params::expected_num_elements) { |
| 359 ReportValidationError(VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER); | 367 ReportValidationError( |
| 368 VALIDATION_ERROR_UNEXPECTED_ARRAY_HEADER, |
| 369 MakeMessageWithExpectedArraySize( |
| 370 "fixed-size array has wrong number of elements", |
| 371 header->num_elements, Params::expected_num_elements).c_str()); |
| 360 return false; | 372 return false; |
| 361 } | 373 } |
| 362 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { | 374 if (!bounds_checker->ClaimMemory(data, header->num_bytes)) { |
| 363 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); | 375 ReportValidationError(VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE); |
| 364 return false; | 376 return false; |
| 365 } | 377 } |
| 366 | 378 |
| 367 const Array_Data<T>* object = static_cast<const Array_Data<T>*>(data); | 379 const Array_Data<T>* object = static_cast<const Array_Data<T>*>(data); |
| 368 return Helper::template ValidateElements< | 380 return Helper::template ValidateElements< |
| 369 Params::element_is_nullable, typename Params::ElementValidateParams>( | 381 Params::element_is_nullable, typename Params::ElementValidateParams>( |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 }; | 502 }; |
| 491 | 503 |
| 492 template <> struct WrapperTraits<String, false> { | 504 template <> struct WrapperTraits<String, false> { |
| 493 typedef String_Data* DataType; | 505 typedef String_Data* DataType; |
| 494 }; | 506 }; |
| 495 | 507 |
| 496 } // namespace internal | 508 } // namespace internal |
| 497 } // namespace mojo | 509 } // namespace mojo |
| 498 | 510 |
| 499 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ | 511 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ARRAY_INTERNAL_H_ |
| OLD | NEW |