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_SYSTEM_TRANSPORT_DATA_H_ | 5 #ifndef MOJO_SYSTEM_TRANSPORT_DATA_H_ |
6 #define MOJO_SYSTEM_TRANSPORT_DATA_H_ | 6 #define MOJO_SYSTEM_TRANSPORT_DATA_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 class MOJO_SYSTEM_IMPL_EXPORT TransportData { | 72 class MOJO_SYSTEM_IMPL_EXPORT TransportData { |
73 public: | 73 public: |
74 // The maximum size of a single serialized dispatcher. This must be a multiple | 74 // The maximum size of a single serialized dispatcher. This must be a multiple |
75 // of |kMessageAlignment|. | 75 // of |kMessageAlignment|. |
76 static const size_t kMaxSerializedDispatcherSize = 10000; | 76 static const size_t kMaxSerializedDispatcherSize = 10000; |
77 | 77 |
78 // The maximum number of platform handles to attach for a single serialized | 78 // The maximum number of platform handles to attach for a single serialized |
79 // dispatcher. | 79 // dispatcher. |
80 static const size_t kMaxSerializedDispatcherPlatformHandles = 2; | 80 static const size_t kMaxSerializedDispatcherPlatformHandles = 2; |
81 | 81 |
82 // The maximum possible size of a valid transport data buffer. | |
83 static const size_t kMaxBufferSize; | |
84 | |
85 // The maximum total number of platform handles that may be attached. | |
86 static const size_t kMaxPlatformHandles; | |
87 | |
82 TransportData(scoped_ptr<DispatcherVector> dispatchers, Channel* channel); | 88 TransportData(scoped_ptr<DispatcherVector> dispatchers, Channel* channel); |
83 ~TransportData(); | 89 ~TransportData(); |
84 | 90 |
85 const void* buffer() const { return buffer_.get(); } | 91 const void* buffer() const { return buffer_.get(); } |
86 void* buffer() { return buffer_.get(); } | 92 void* buffer() { return buffer_.get(); } |
87 size_t buffer_size() const { return buffer_size_; } | 93 size_t buffer_size() const { return buffer_size_; } |
88 | 94 |
89 uint32_t platform_handle_table_offset() const { | 95 uint32_t platform_handle_table_offset() const { |
90 return header()->platform_handle_table_offset; | 96 return header()->platform_handle_table_offset; |
91 } | 97 } |
92 | 98 |
93 // Gets attached platform-specific handles; this may return null if there are | 99 // Gets attached platform-specific handles; this may return null if there are |
94 // none. Note that the caller may mutate the set of platform-specific handles. | 100 // none. Note that the caller may mutate the set of platform-specific handles. |
95 const std::vector<embedder::PlatformHandle>* platform_handles() const { | 101 const std::vector<embedder::PlatformHandle>* platform_handles() const { |
96 return platform_handles_.get(); | 102 return platform_handles_.get(); |
97 } | 103 } |
98 std::vector<embedder::PlatformHandle>* platform_handles() { | 104 std::vector<embedder::PlatformHandle>* platform_handles() { |
99 return platform_handles_.get(); | 105 return platform_handles_.get(); |
100 } | 106 } |
101 | 107 |
102 // Receive-side functions: | 108 // Receive-side functions: |
103 | 109 |
104 // Checks if the given buffer (from the "wire") looks like a valid | 110 // Checks if the given buffer (from the "wire") looks like a valid |
105 // |TransportData| buffer. (Should only be called if |buffer_size| is | 111 // |TransportData| buffer. (Should only be called if |buffer_size| is |
106 // nonzero.) Returns null if valid, and a pointer to a human-readable error | 112 // nonzero.) Returns null if valid, and a pointer to a human-readable error |
107 // message (for debug/logging purposes) on error. Note: This checks the | 113 // message (for debug/logging purposes) on error. Note: This checks the |
108 // validity of the handle table entries (i.e., does range checking), but does | 114 // validity of the handle table entries (i.e., does range checking), but does |
109 // not check that the validity of the actual serialized dispatcher | 115 // not check that the validity of the actual serialized dispatcher |
110 // information. | 116 // information. |
111 static const char* ValidateBuffer(const void* buffer, size_t buffer_size); | 117 static const char* ValidateBuffer(size_t serialized_platform_handle_size, |
yzshen1
2014/05/11 07:16:59
I don't think I have understood the whole design o
viettrungluu
2014/05/12 17:33:28
It is so RawChannel-specific, that it may vary bet
| |
118 const void* buffer, | |
119 size_t buffer_size); | |
120 | |
121 // Gets the platform handle table from a (valid) |TransportData| buffer (which | |
122 // should have been validated using |ValidateBuffer()| first). | |
123 static void GetPlatformHandleTable(const void* transport_data_buffer, | |
124 size_t* num_platform_handles, | |
125 const void** platform_handle_table); | |
112 | 126 |
113 // Deserializes dispatchers from the given (serialized) transport data buffer | 127 // Deserializes dispatchers from the given (serialized) transport data buffer |
114 // (typically from a |MessageInTransit::View|). |buffer| should be non-null | 128 // (typically from a |MessageInTransit::View|). |buffer| should be non-null |
115 // and |buffer_size| should be nonzero. | 129 // and |buffer_size| should be nonzero. |
116 static scoped_ptr<DispatcherVector> DeserializeDispatchersFromBuffer( | 130 static scoped_ptr<DispatcherVector> DeserializeDispatchersFromBuffer( |
117 const void* buffer, | 131 const void* buffer, |
118 size_t buffer_size, | 132 size_t buffer_size, |
119 Channel* channel); | 133 Channel* channel); |
120 | 134 |
121 private: | 135 private: |
(...skipping 11 matching lines...) Expand all Loading... | |
133 uint32_t unused; | 147 uint32_t unused; |
134 }; | 148 }; |
135 | 149 |
136 struct HandleTableEntry { | 150 struct HandleTableEntry { |
137 int32_t type; // From |Dispatcher::Type| (|kTypeUnknown| for "invalid"). | 151 int32_t type; // From |Dispatcher::Type| (|kTypeUnknown| for "invalid"). |
138 uint32_t offset; // Relative to the start of the "secondary buffer". | 152 uint32_t offset; // Relative to the start of the "secondary buffer". |
139 uint32_t size; // (Not including any padding.) | 153 uint32_t size; // (Not including any padding.) |
140 uint32_t unused; | 154 uint32_t unused; |
141 }; | 155 }; |
142 | 156 |
143 // The maximum possible size of a valid transport data buffer. | |
144 static const size_t kMaxBufferSize; | |
145 | |
146 // The maximum total number of platform handles that may be attached. | |
147 static const size_t kMaxPlatformHandles; | |
148 | |
149 const Header* header() const { | 157 const Header* header() const { |
150 return reinterpret_cast<const Header*>(buffer_.get()); | 158 return reinterpret_cast<const Header*>(buffer_.get()); |
151 } | 159 } |
152 | 160 |
153 size_t buffer_size_; | 161 size_t buffer_size_; |
154 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; // Never null. | 162 scoped_ptr<char, base::AlignedFreeDeleter> buffer_; // Never null. |
155 | 163 |
156 // Any platform-specific handles attached to this message (for inter-process | 164 // Any platform-specific handles attached to this message (for inter-process |
157 // transport). The vector (if any) owns the handles that it contains (and is | 165 // transport). The vector (if any) owns the handles that it contains (and is |
158 // responsible for closing them). | 166 // responsible for closing them). |
159 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandles|. | 167 // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandles|. |
160 scoped_ptr<std::vector<embedder::PlatformHandle> > platform_handles_; | 168 scoped_ptr<std::vector<embedder::PlatformHandle> > platform_handles_; |
161 | 169 |
162 DISALLOW_COPY_AND_ASSIGN(TransportData); | 170 DISALLOW_COPY_AND_ASSIGN(TransportData); |
163 }; | 171 }; |
164 | 172 |
165 } // namespace system | 173 } // namespace system |
166 } // namespace mojo | 174 } // namespace mojo |
167 | 175 |
168 #endif // MOJO_SYSTEM_TRANSPORT_DATA_H_ | 176 #endif // MOJO_SYSTEM_TRANSPORT_DATA_H_ |
OLD | NEW |