| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_C_BINDINGS_LIB_UTIL_H_ | 5 #ifndef MOJO_PUBLIC_C_BINDINGS_LIB_UTIL_H_ |
| 6 #define MOJO_PUBLIC_C_BINDINGS_LIB_UTIL_H_ | 6 #define MOJO_PUBLIC_C_BINDINGS_LIB_UTIL_H_ |
| 7 | 7 |
| 8 #include "mojo/public/c/system/macros.h" | 8 #include "mojo/public/c/system/macros.h" |
| 9 | 9 |
| 10 // Rounds-up |num| to 8. The result is undefined if this results in an overflow. | 10 // Rounds-up |num| to 8. The result is undefined if this results in an overflow. |
| 11 #define MOJOM_INTERNAL_ROUND_TO_8(num) (((num) + 7) & ~7) | 11 #define MOJOM_INTERNAL_ROUND_TO_8(num) (((num) + 7) & ~7) |
| 12 | 12 |
| 13 // Represents the memory layout of a mojom pointer; it is a |ptr| (pointer to | 13 // Represents the memory layout of a mojom pointer; it is a |ptr| (pointer to |
| 14 // some memory) when unencoded, and refers to a relative |offset| when encoded. | 14 // some memory) when unencoded, and refers to a relative |offset| when encoded. |
| 15 union MojomPointer { | 15 union MojomPointer { |
| 16 void* ptr; | 16 void* ptr; |
| 17 uint64_t offset; | 17 uint64_t offset; |
| 18 }; | 18 }; |
| 19 MOJO_STATIC_ASSERT(sizeof(union MojomPointer) == 8, | 19 MOJO_STATIC_ASSERT(sizeof(union MojomPointer) == 8, |
| 20 "union MojomPointer must be 8 bytes"); | 20 "union MojomPointer must be 8 bytes"); |
| 21 | 21 |
| 22 // This struct represents the state we need to keep when validating an encoded |
| 23 // mojom type. |
| 24 struct MojomValidationContext { |
| 25 // |next_handle_index| is a counter that represents the next-available index |
| 26 // into the handle array. Previous indices have already been used up. This |
| 27 // counter is non-decreasing as it is used throughout validation. |
| 28 uint32_t next_handle_index; |
| 29 |
| 30 // As we validate, we keep track of the point where pointers can point to, |
| 31 // since two pointers may not point to the same memory region. |
| 32 char* next_pointer; |
| 33 |
| 34 // TODO(vardhan): Include an error string? How big should it be? |
| 35 }; |
| 36 |
| 22 #endif // MOJO_PUBLIC_C_BINDINGS_LIB_UTIL_H_ | 37 #endif // MOJO_PUBLIC_C_BINDINGS_LIB_UTIL_H_ |
| OLD | NEW |