Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: mojo/public/c/bindings/struct.h

Issue 2163793002: C bindings: Implement _Validate(), and some pre-requisites (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/public/c/bindings/message.h ('k') | mojo/public/c/bindings/tests/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_STRUCT_H_ 5 #ifndef MOJO_PUBLIC_C_BINDINGS_STRUCT_H_
6 #define MOJO_PUBLIC_C_BINDINGS_STRUCT_H_ 6 #define MOJO_PUBLIC_C_BINDINGS_STRUCT_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include "mojo/public/c/bindings/buffer.h" 11 #include "mojo/public/c/bindings/buffer.h"
12 #include "mojo/public/c/bindings/lib/type_descriptor.h" 12 #include "mojo/public/c/bindings/lib/type_descriptor.h"
13 #include "mojo/public/c/bindings/lib/util.h"
13 #include "mojo/public/c/system/macros.h" 14 #include "mojo/public/c/system/macros.h"
14 15
15 MOJO_BEGIN_EXTERN_C 16 MOJO_BEGIN_EXTERN_C
16 17
17 struct MojomStructHeader { 18 struct MojomStructHeader {
18 // |num_bytes| includes the size of this struct header along with the 19 // |num_bytes| includes the size of this struct header along with the
19 // accompanying struct data. |num_bytes| must be rounded up to 8 bytes. 20 // accompanying struct data. |num_bytes| must be rounded up to 8 bytes.
20 uint32_t num_bytes; 21 uint32_t num_bytes;
21 uint32_t version; 22 uint32_t version;
22 }; 23 };
(...skipping 26 matching lines...) Expand all
49 uint32_t in_struct_size, 50 uint32_t in_struct_size,
50 struct MojomHandleBuffer* inout_handles_buffer); 51 struct MojomHandleBuffer* inout_handles_buffer);
51 52
52 // Decodes the mojom struct described by the |inout_struct| buffer; note that 53 // Decodes the mojom struct described by the |inout_struct| buffer; note that
53 // any references from the struct are also in |inout_struct|, and they are 54 // any references from the struct are also in |inout_struct|, and they are
54 // recursively decoded. Decodes all offsets to pointers, and decodes all handles 55 // recursively decoded. Decodes all offsets to pointers, and decodes all handles
55 // by moving them out of |inout_handles| array using the encoded index into the 56 // by moving them out of |inout_handles| array using the encoded index into the
56 // array. 57 // array.
57 // |in_type_desc|: Describes the pointer and handle fields of the mojom struct. 58 // |in_type_desc|: Describes the pointer and handle fields of the mojom struct.
58 // |inout_struct|: Contains the struct, and any other references outside of the 59 // |inout_struct|: Contains the struct, and any other references outside of the
59 // struct. 60 // struct.
60 // |in_struct_size|: Contains the struct, and any other references outside of 61 // |in_struct_size|: Size of the buffer backed by |inout_struct| in bytes.
61 // the struct.
62 // |inout_handles|: Mojo handles are in this array, and are referenced by index 62 // |inout_handles|: Mojo handles are in this array, and are referenced by index
63 // in |inout_buf|. 63 // in |inout_buf|.
64 // |in_num_handles|: Size in # of number elements available in |inout_handles|. 64 // |in_num_handles|: Size in # of number elements available in |inout_handles|.
65 void MojomStruct_DecodePointersAndHandles( 65 void MojomStruct_DecodePointersAndHandles(
66 const struct MojomTypeDescriptorStruct* in_type_desc, 66 const struct MojomTypeDescriptorStruct* in_type_desc,
67 struct MojomStructHeader* inout_struct, 67 struct MojomStructHeader* inout_struct,
68 uint32_t in_struct_size, 68 uint32_t in_struct_size,
69 MojoHandle* inout_handles, 69 MojoHandle* inout_handles,
70 uint32_t in_num_handles); 70 uint32_t in_num_handles);
71 71
72 // Validates the mojom struct described by the |in_struct| buffer. Any
73 // references from the struct are also recursively validated, and are expected
74 // to be in the same buffer backing |in_struct|.
75 // |in_type_desc|: Describes the pointer and handle fields of the mojom struct.
76 // |inout_struct|: Buffer containing the struct, and any other references
77 // outside of the struct.
78 // |in_struct_size|: Size of the buffer backed by |inout_struct| in bytes.
79 // |in_num_handles|: Number of valid handles expected to be referenced from
80 // |in_struct|.
81 // |inout_context|: An initialized context that contains the expected location
82 // of the next pointer and next offset. This is used to
83 // validate that no two pointers or handles are shared.
84 MojomValidationResult MojomStruct_Validate(
85 const struct MojomTypeDescriptorStruct* in_type_desc,
86 const struct MojomStructHeader* in_struct,
87 uint32_t in_struct_size,
88 uint32_t in_num_handles,
89 struct MojomValidationContext* inout_context);
90
72 MOJO_END_EXTERN_C 91 MOJO_END_EXTERN_C
73 92
74 #endif // MOJO_PUBLIC_C_BINDINGS_STRUCT_H_ 93 #endif // MOJO_PUBLIC_C_BINDINGS_STRUCT_H_
OLDNEW
« no previous file with comments | « mojo/public/c/bindings/message.h ('k') | mojo/public/c/bindings/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698