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