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 #include <mojo/bindings/map.h> | |
6 | |
7 #include <mojo/macros.h> | |
8 | |
9 struct MojomMapLayout { | |
10 struct MojomStructHeader header_; | |
11 union MojomArrayHeaderPtr keys; | |
12 union MojomArrayHeaderPtr values; | |
13 }; | |
14 MOJO_STATIC_ASSERT(sizeof(struct MojomMapLayout) == 24u, | |
15 "MojomMapLayout is an invalid size."); | |
16 | |
17 MojomValidationResult MojomMap_Validate( | |
18 const struct MojomTypeDescriptorStruct* in_type_desc, | |
19 const struct MojomStructHeader* in_struct, | |
20 uint32_t in_buf_size, | |
21 uint32_t in_num_handles, | |
22 struct MojomValidationContext* inout_context) { | |
23 // A mojom map consists of 2 arrays (pointers), both of equal size. | |
24 const struct MojomMapLayout* map = (const struct MojomMapLayout*)in_struct; | |
25 struct MojomArrayHeader* keys_arr = | |
26 (struct MojomArrayHeader*)((char*)map + | |
27 (offsetof(struct MojomMapLayout, keys) + | |
28 map->keys.offset)); | |
29 struct MojomArrayHeader* values_arr = | |
30 (struct MojomArrayHeader*)((char*)map + | |
31 (offsetof(struct MojomMapLayout, values) + | |
32 map->values.offset)); | |
33 | |
34 if (keys_arr->num_elements != values_arr->num_elements) | |
35 return MOJOM_VALIDATION_DIFFERENT_SIZED_ARRAYS_IN_MAP; | |
36 | |
37 return MOJOM_VALIDATION_ERROR_NONE; | |
38 } | |
OLD | NEW |