OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_EDK_SYSTEM_TRANSPORT_DATA_H_ | 5 #ifndef MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ |
6 #define MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ | 6 #define MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/aligned_memory.h" | 13 #include "base/memory/aligned_memory.h" |
14 #include "mojo/edk/embedder/scoped_platform_handle.h" | 14 #include "mojo/edk/platform/scoped_platform_handle.h" |
15 #include "mojo/edk/system/dispatcher.h" | 15 #include "mojo/edk/system/dispatcher.h" |
16 #include "mojo/public/cpp/system/macros.h" | 16 #include "mojo/public/cpp/system/macros.h" |
17 | 17 |
18 namespace mojo { | 18 namespace mojo { |
19 namespace system { | 19 namespace system { |
20 | 20 |
21 class Channel; | 21 class Channel; |
22 | 22 |
23 // This class is used by |MessageInTransit| to represent handles (|Dispatcher|s) | 23 // This class is used by |MessageInTransit| to represent handles (|Dispatcher|s) |
24 // in various stages of serialization. | 24 // in various stages of serialization. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 static size_t GetMaxPlatformHandles(); | 87 static size_t GetMaxPlatformHandles(); |
88 | 88 |
89 TransportData(std::unique_ptr<DispatcherVector> dispatchers, | 89 TransportData(std::unique_ptr<DispatcherVector> dispatchers, |
90 Channel* channel); | 90 Channel* channel); |
91 | 91 |
92 // This is used for users of |MessageInTransit|/|TransportData|/|RawChannel| | 92 // This is used for users of |MessageInTransit|/|TransportData|/|RawChannel| |
93 // that want to simply transport data and platform handles, and not | 93 // that want to simply transport data and platform handles, and not |
94 // |Dispatcher|s. (|Header| will be present, and zero except for | 94 // |Dispatcher|s. (|Header| will be present, and zero except for |
95 // |num_platform_handles|, and |platform_handle_table_offset| if necessary.) | 95 // |num_platform_handles|, and |platform_handle_table_offset| if necessary.) |
96 explicit TransportData( | 96 explicit TransportData( |
97 std::unique_ptr<std::vector<embedder::ScopedPlatformHandle>> | 97 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> |
98 platform_handles, | 98 platform_handles, |
99 size_t serialized_platform_handle_size); | 99 size_t serialized_platform_handle_size); |
100 | 100 |
101 ~TransportData(); | 101 ~TransportData(); |
102 | 102 |
103 const void* buffer() const { return buffer_.get(); } | 103 const void* buffer() const { return buffer_.get(); } |
104 void* buffer() { return buffer_.get(); } | 104 void* buffer() { return buffer_.get(); } |
105 size_t buffer_size() const { return buffer_size_; } | 105 size_t buffer_size() const { return buffer_size_; } |
106 | 106 |
107 uint32_t platform_handle_table_offset() const { | 107 uint32_t platform_handle_table_offset() const { |
108 return header()->platform_handle_table_offset; | 108 return header()->platform_handle_table_offset; |
109 } | 109 } |
110 | 110 |
111 // Gets attached platform-specific handles; this may return null if there are | 111 // Gets attached platform-specific handles; this may return null if there are |
112 // none. Note that the caller may mutate the set of platform-specific handles. | 112 // none. Note that the caller may mutate the set of platform-specific handles. |
113 const std::vector<embedder::ScopedPlatformHandle>* platform_handles() const { | 113 const std::vector<platform::ScopedPlatformHandle>* platform_handles() const { |
114 return platform_handles_.get(); | 114 return platform_handles_.get(); |
115 } | 115 } |
116 std::vector<embedder::ScopedPlatformHandle>* platform_handles() { | 116 std::vector<platform::ScopedPlatformHandle>* platform_handles() { |
117 return platform_handles_.get(); | 117 return platform_handles_.get(); |
118 } | 118 } |
119 | 119 |
120 // Receive-side functions: | 120 // Receive-side functions: |
121 | 121 |
122 // Checks if the given buffer (from the "wire") looks like a valid | 122 // Checks if the given buffer (from the "wire") looks like a valid |
123 // |TransportData| buffer. (Should only be called if |buffer_size| is | 123 // |TransportData| buffer. (Should only be called if |buffer_size| is |
124 // nonzero.) Returns null if valid, and a pointer to a human-readable error | 124 // nonzero.) Returns null if valid, and a pointer to a human-readable error |
125 // message (for debug/logging purposes) on error. Note: This checks the | 125 // message (for debug/logging purposes) on error. Note: This checks the |
126 // validity of the handle table entries (i.e., does range checking), but does | 126 // validity of the handle table entries (i.e., does range checking), but does |
127 // not check that the validity of the actual serialized dispatcher | 127 // not check that the validity of the actual serialized dispatcher |
128 // information. | 128 // information. |
129 static const char* ValidateBuffer(size_t serialized_platform_handle_size, | 129 static const char* ValidateBuffer(size_t serialized_platform_handle_size, |
130 const void* buffer, | 130 const void* buffer, |
131 size_t buffer_size); | 131 size_t buffer_size); |
132 | 132 |
133 // Gets the platform handle table from a (valid) |TransportData| buffer (which | 133 // Gets the platform handle table from a (valid) |TransportData| buffer (which |
134 // should have been validated using |ValidateBuffer()| first). | 134 // should have been validated using |ValidateBuffer()| first). |
135 static void GetPlatformHandleTable(const void* transport_data_buffer, | 135 static void GetPlatformHandleTable(const void* transport_data_buffer, |
136 size_t* num_platform_handles, | 136 size_t* num_platform_handles, |
137 const void** platform_handle_table); | 137 const void** platform_handle_table); |
138 | 138 |
139 // Deserializes dispatchers from the given (serialized) transport data buffer | 139 // Deserializes dispatchers from the given (serialized) transport data buffer |
140 // (typically from a |MessageInTransit::View|) and vector of platform handles. | 140 // (typically from a |MessageInTransit::View|) and vector of platform handles. |
141 // |buffer| should be non-null and |buffer_size| should be nonzero. | 141 // |buffer| should be non-null and |buffer_size| should be nonzero. |
142 static std::unique_ptr<DispatcherVector> DeserializeDispatchers( | 142 static std::unique_ptr<DispatcherVector> DeserializeDispatchers( |
143 const void* buffer, | 143 const void* buffer, |
144 size_t buffer_size, | 144 size_t buffer_size, |
145 std::unique_ptr<std::vector<embedder::ScopedPlatformHandle>> | 145 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> |
146 platform_handles, | 146 platform_handles, |
147 Channel* channel); | 147 Channel* channel); |
148 | 148 |
149 private: | 149 private: |
150 // To allow us to make compile-assertions about |Header|, etc. in the .cc | 150 // To allow us to make compile-assertions about |Header|, etc. in the .cc |
151 // file. | 151 // file. |
152 struct PrivateStructForCompileAsserts; | 152 struct PrivateStructForCompileAsserts; |
153 | 153 |
154 // Header for the "secondary buffer"/"transport data". Must be a multiple of | 154 // Header for the "secondary buffer"/"transport data". Must be a multiple of |
155 // |MessageInTransit::kMessageAlignment| in size. Must be POD. | 155 // |MessageInTransit::kMessageAlignment| in size. Must be POD. |
(...skipping 17 matching lines...) Expand all Loading... |
173 return reinterpret_cast<const Header*>(buffer_.get()); | 173 return reinterpret_cast<const Header*>(buffer_.get()); |
174 } | 174 } |
175 | 175 |
176 size_t buffer_size_; | 176 size_t buffer_size_; |
177 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; // Never null. | 177 std::unique_ptr<char, base::AlignedFreeDeleter> buffer_; // Never null. |
178 | 178 |
179 // Any platform-specific handles attached to this message (for inter-process | 179 // Any platform-specific handles attached to this message (for inter-process |
180 // transport). The vector (if any) owns the handles that it contains (and is | 180 // transport). The vector (if any) owns the handles that it contains (and is |
181 // responsible for closing them). | 181 // responsible for closing them). |
182 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandle|s. | 182 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandle|s. |
183 std::unique_ptr<std::vector<embedder::ScopedPlatformHandle>> | 183 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> |
184 platform_handles_; | 184 platform_handles_; |
185 | 185 |
186 MOJO_DISALLOW_COPY_AND_ASSIGN(TransportData); | 186 MOJO_DISALLOW_COPY_AND_ASSIGN(TransportData); |
187 }; | 187 }; |
188 | 188 |
189 } // namespace system | 189 } // namespace system |
190 } // namespace mojo | 190 } // namespace mojo |
191 | 191 |
192 #endif // MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ | 192 #endif // MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ |
OLD | NEW |