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