| 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 "mojo/edk/platform/aligned_alloc.h" | 13 #include "mojo/edk/platform/aligned_alloc.h" |
| 14 #include "mojo/edk/platform/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/edk/system/handle.h" |
| 17 #include "mojo/public/c/system/handle.h" |
| 16 #include "mojo/public/cpp/system/macros.h" | 18 #include "mojo/public/cpp/system/macros.h" |
| 17 | 19 |
| 18 namespace mojo { | 20 namespace mojo { |
| 19 namespace system { | 21 namespace system { |
| 20 | 22 |
| 21 class Channel; | 23 class Channel; |
| 22 | 24 |
| 23 // This class is used by |MessageInTransit| to represent handles (|Dispatcher|s) | 25 // This class is used by |MessageInTransit| to represent handles (|Dispatcher|s) |
| 24 // in various stages of serialization. | 26 // in various stages of serialization. |
| 25 // | 27 // |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // dispatcher. | 82 // dispatcher. |
| 81 static const size_t kMaxSerializedDispatcherPlatformHandles = 2; | 83 static const size_t kMaxSerializedDispatcherPlatformHandles = 2; |
| 82 | 84 |
| 83 // The maximum possible size of a valid transport data buffer. | 85 // The maximum possible size of a valid transport data buffer. |
| 84 static size_t GetMaxBufferSize(); | 86 static size_t GetMaxBufferSize(); |
| 85 | 87 |
| 86 // The maximum total number of platform handles that may be attached. | 88 // The maximum total number of platform handles that may be attached. |
| 87 static size_t GetMaxPlatformHandles(); | 89 static size_t GetMaxPlatformHandles(); |
| 88 | 90 |
| 89 TransportData(std::unique_ptr<HandleVector> handles, Channel* channel); | 91 TransportData(std::unique_ptr<HandleVector> handles, Channel* channel); |
| 90 // TODO(vtl): Remove this, once |TransportData| really supports handles. | |
| 91 TransportData(std::unique_ptr<DispatcherVector> dispatchers, | |
| 92 Channel* channel); | |
| 93 | 92 |
| 94 // This is used for users of |MessageInTransit|/|TransportData|/|RawChannel| | 93 // This is used for users of |MessageInTransit|/|TransportData|/|RawChannel| |
| 95 // that want to simply transport data and platform handles, and not | 94 // that want to simply transport data and platform handles, and not |
| 96 // |Dispatcher|s. (|Header| will be present, and zero except for | 95 // |Dispatcher|s. (|Header| will be present, and zero except for |
| 97 // |num_platform_handles|, and |platform_handle_table_offset| if necessary.) | 96 // |num_platform_handles|, and |platform_handle_table_offset| if necessary.) |
| 98 explicit TransportData( | 97 explicit TransportData( |
| 99 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> | 98 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> |
| 100 platform_handles, | 99 platform_handles, |
| 101 size_t serialized_platform_handle_size); | 100 size_t serialized_platform_handle_size); |
| 102 | 101 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 131 static const char* ValidateBuffer(size_t serialized_platform_handle_size, | 130 static const char* ValidateBuffer(size_t serialized_platform_handle_size, |
| 132 const void* buffer, | 131 const void* buffer, |
| 133 size_t buffer_size); | 132 size_t buffer_size); |
| 134 | 133 |
| 135 // Gets the platform handle table from a (valid) |TransportData| buffer (which | 134 // Gets the platform handle table from a (valid) |TransportData| buffer (which |
| 136 // should have been validated using |ValidateBuffer()| first). | 135 // should have been validated using |ValidateBuffer()| first). |
| 137 static void GetPlatformHandleTable(const void* transport_data_buffer, | 136 static void GetPlatformHandleTable(const void* transport_data_buffer, |
| 138 size_t* num_platform_handles, | 137 size_t* num_platform_handles, |
| 139 const void** platform_handle_table); | 138 const void** platform_handle_table); |
| 140 | 139 |
| 141 // Deserializes dispatchers from the given (serialized) transport data buffer | 140 // Deserializes handles from the given (serialized) transport data buffer |
| 142 // (typically from a |MessageInTransit::View|) and vector of platform handles. | 141 // (typically from a |MessageInTransit::View|) and vector of platform handles. |
| 143 // |buffer| should be non-null and |buffer_size| should be nonzero. | 142 // |buffer| should be non-null and |buffer_size| should be nonzero. |
| 144 static std::unique_ptr<DispatcherVector> DeserializeDispatchers( | 143 static std::unique_ptr<HandleVector> DeserializeHandles( |
| 145 const void* buffer, | 144 const void* buffer, |
| 146 size_t buffer_size, | 145 size_t buffer_size, |
| 147 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> | 146 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> |
| 148 platform_handles, | 147 platform_handles, |
| 149 Channel* channel); | 148 Channel* channel); |
| 150 | 149 |
| 151 private: | 150 private: |
| 152 // To allow us to make compile-assertions about |Header|, etc. in the .cc | 151 // To allow us to make compile-assertions about |Header|, etc. in the .cc |
| 153 // file. | 152 // file. |
| 154 struct PrivateStructForCompileAsserts; | 153 struct PrivateStructForCompileAsserts; |
| 155 | 154 |
| 156 // Header for the "secondary buffer"/"transport data". Must be a multiple of | 155 // Header for the "secondary buffer"/"transport data". Must be a multiple of |
| 157 // |MessageInTransit::kMessageAlignment| in size. Must be POD. | 156 // |MessageInTransit::kMessageAlignment| in size. Must be POD. |
| 158 struct Header { | 157 struct Header { |
| 159 uint32_t num_handles; | 158 uint32_t num_handles; |
| 160 // TODO(vtl): Not used yet: | 159 // TODO(vtl): Not used yet: |
| 161 uint32_t platform_handle_table_offset; | 160 uint32_t platform_handle_table_offset; |
| 162 uint32_t num_platform_handles; | 161 uint32_t num_platform_handles; |
| 163 uint32_t unused; | 162 uint32_t unused; |
| 164 }; | 163 }; |
| 165 | 164 |
| 166 struct HandleTableEntry { | 165 struct HandleTableEntry { |
| 167 // TODO(vtl): Should I make |Dispatcher::Type| an |int32_t| enum class? | 166 // TODO(vtl): Should I make |Dispatcher::Type| an |int32_t| enum class? |
| 168 int32_t type; // From |Dispatcher::Type| (|UNKNOWN| for "invalid"). | 167 int32_t type; // From |Dispatcher::Type| (|UNKNOWN| for "invalid"). |
| 169 uint32_t offset; // Relative to the start of the "secondary buffer". | 168 uint32_t offset; // Relative to the start of the "secondary buffer". |
| 170 uint32_t size; // (Not including any padding.) | 169 uint32_t size; // (Not including any padding.) |
| 171 uint32_t unused; | 170 MojoHandleRights rights; |
| 172 }; | 171 }; |
| 173 | 172 |
| 174 const Header* header() const { | 173 const Header* header() const { |
| 175 return reinterpret_cast<const Header*>(buffer_.get()); | 174 return reinterpret_cast<const Header*>(buffer_.get()); |
| 176 } | 175 } |
| 177 | 176 |
| 178 size_t buffer_size_; | 177 size_t buffer_size_; |
| 179 platform::AlignedUniquePtr<char> buffer_; // Never null. | 178 platform::AlignedUniquePtr<char> buffer_; // Never null. |
| 180 | 179 |
| 181 // Any platform-specific handles attached to this message (for inter-process | 180 // Any platform-specific handles attached to this message (for inter-process |
| 182 // transport). The vector (if any) owns the handles that it contains (and is | 181 // transport). The vector (if any) owns the handles that it contains (and is |
| 183 // responsible for closing them). | 182 // responsible for closing them). |
| 184 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandle|s. | 183 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandle|s. |
| 185 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> | 184 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> |
| 186 platform_handles_; | 185 platform_handles_; |
| 187 | 186 |
| 188 MOJO_DISALLOW_COPY_AND_ASSIGN(TransportData); | 187 MOJO_DISALLOW_COPY_AND_ASSIGN(TransportData); |
| 189 }; | 188 }; |
| 190 | 189 |
| 191 } // namespace system | 190 } // namespace system |
| 192 } // namespace mojo | 191 } // namespace mojo |
| 193 | 192 |
| 194 #endif // MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ | 193 #endif // MOJO_EDK_SYSTEM_TRANSPORT_DATA_H_ |
| OLD | NEW |