OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 SANDBOX_SRC_CROSSCALL_PARAMS_H__ | 5 #ifndef SANDBOX_SRC_CROSSCALL_PARAMS_H__ |
6 #define SANDBOX_SRC_CROSSCALL_PARAMS_H__ | 6 #define SANDBOX_SRC_CROSSCALL_PARAMS_H__ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <lmaccess.h> | 9 #include <lmaccess.h> |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // storage allocation that the packed parameters should need. | 162 // storage allocation that the packed parameters should need. |
163 // NUMBER_PARAMS: the number of parameters, valid from 1 to N | 163 // NUMBER_PARAMS: the number of parameters, valid from 1 to N |
164 // BLOCK_SIZE: the total storage that the NUMBER_PARAMS parameters can take, | 164 // BLOCK_SIZE: the total storage that the NUMBER_PARAMS parameters can take, |
165 // typically the block size is defined by the channel size of the underlying | 165 // typically the block size is defined by the channel size of the underlying |
166 // ipc mechanism. | 166 // ipc mechanism. |
167 // In practice this class is used to levergage C++ capacity to properly | 167 // In practice this class is used to levergage C++ capacity to properly |
168 // calculate sizes and displacements given the possibility of the packed params | 168 // calculate sizes and displacements given the possibility of the packed params |
169 // blob to be complex. | 169 // blob to be complex. |
170 // | 170 // |
171 // As is, this class assumes that the layout of the blob is as follows. Assume | 171 // As is, this class assumes that the layout of the blob is as follows. Assume |
172 // that NUMBER_PARAMS = 2: | 172 // that NUMBER_PARAMS = 2 and a 32-bit build: |
173 // | 173 // |
174 // [ tag 4 bytes] | 174 // [ tag 4 bytes] |
175 // [ IsOnOut 4 bytes] | 175 // [ IsOnOut 4 bytes] |
176 // [ call return 52 bytes] | 176 // [ call return 52 bytes] |
177 // [ params count 4 bytes] | 177 // [ params count 4 bytes] |
178 // [ parameter 0 type 4 bytes] | 178 // [ parameter 0 type 4 bytes] |
179 // [ parameter 0 /\ 4 bytes] ---delta to ---\ | 179 // [ parameter 0 offset 4 bytes] ---delta to ---\ |
180 // [ parameter 0 size 4 bytes] | | 180 // [ parameter 0 size 4 bytes] | |
181 // [ parameter 1 type 4 bytes] | | 181 // [ parameter 1 type 4 bytes] | |
182 // [ parameter 1 /\ 4 bytes] | | 182 // [ parameter 1 offset 4 bytes] ---------------|--\ |
183 // [ parameter 1 size 4 bytes] | | 183 // [ parameter 1 size 4 bytes] | | |
184 // [ parameter 2 type 4 bytes] | | 184 // [ parameter 2 type 4 bytes] | | |
185 // [ parameter 2 /\ 4 bytes] ----------------------\ | 185 // [ parameter 2 offset 4 bytes] ----------------------\ |
186 // [ parameter 2 size 4 bytes] | | | 186 // [ parameter 2 size 4 bytes] | | | |
187 // |-------------------------| | | | 187 // |---------------------------| | | | |
188 // | | <--------------/ | | 188 // | value 0 (x bytes) | <--------------/ | | |
189 // | | | | 189 // | value 1 (y bytes) | <-----------------/ | |
190 // | | <---------------------/ | 190 // | | | |
191 // |-------------------------| | 191 // | end of buffer | <---------------------/ |
| 192 // |---------------------------| |
192 // | 193 // |
193 // Note that the actual number of params is NUMBER_PARAMS + 1 | 194 // Note that the actual number of params is NUMBER_PARAMS + 1 |
194 // so that the size of each actual param can be computed from the difference | 195 // so that the size of each actual param can be computed from the difference |
195 // between one parameter and the next down | 196 // between one parameter and the next down. The offset of the last param |
| 197 // points to the end of the buffer and the type and size are undefined. |
| 198 // |
196 template <size_t NUMBER_PARAMS, size_t BLOCK_SIZE> | 199 template <size_t NUMBER_PARAMS, size_t BLOCK_SIZE> |
197 class ActualCallParams : public CrossCallParams { | 200 class ActualCallParams : public CrossCallParams { |
198 public: | 201 public: |
199 // constructor. Pass the ipc unique tag as input | 202 // constructor. Pass the ipc unique tag as input |
200 explicit ActualCallParams(uint32 tag) | 203 explicit ActualCallParams(uint32 tag) |
201 : CrossCallParams(tag, NUMBER_PARAMS) { | 204 : CrossCallParams(tag, NUMBER_PARAMS) { |
202 param_info_[0].offset_ = parameters_ - reinterpret_cast<char*>(this); | 205 param_info_[0].offset_ = parameters_ - reinterpret_cast<char*>(this); |
203 } | 206 } |
204 | 207 |
205 // Testing-only constructor. Allows setting the |number_params| to a | 208 // Testing-only constructor. Allows setting the |number_params| to a |
206 // wrong value. | 209 // wrong value. |
207 ActualCallParams(uint32 tag, uint32 number_params) | 210 ActualCallParams(uint32 tag, uint32 number_params) |
208 : CrossCallParams(tag, number_params) { | 211 : CrossCallParams(tag, number_params) { |
209 param_info_[0].offset_ = parameters_ - reinterpret_cast<char*>(this); | 212 param_info_[0].offset_ = parameters_ - reinterpret_cast<char*>(this); |
210 } | 213 } |
211 | 214 |
| 215 // Testing-only method. Allows setting the apparent size to a wrong value. |
| 216 // returns the previous size. |
| 217 size_t OverrideSize(size_t new_size) { |
| 218 size_t previous_size = param_info_[NUMBER_PARAMS].offset_; |
| 219 param_info_[NUMBER_PARAMS].offset_ = new_size; |
| 220 return previous_size; |
| 221 } |
| 222 |
212 // Copies each paramter into the internal buffer. For each you must supply: | 223 // Copies each paramter into the internal buffer. For each you must supply: |
213 // index: 0 for the first param, 1 for the next an so on | 224 // index: 0 for the first param, 1 for the next an so on |
214 bool CopyParamIn(size_t index, const void* parameter_address, size_t size, | 225 bool CopyParamIn(size_t index, const void* parameter_address, size_t size, |
215 bool is_in_out, ArgType type) { | 226 bool is_in_out, ArgType type) { |
216 if (index >= NUMBER_PARAMS) { | 227 if (index >= NUMBER_PARAMS) { |
217 return false; | 228 return false; |
218 } | 229 } |
219 | 230 |
220 if (kuint32max == size) { | 231 if (kuint32max == size) { |
221 // Memory error while getting the size. | 232 // Memory error while getting the size. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 DISALLOW_COPY_AND_ASSIGN(ActualCallParams); | 286 DISALLOW_COPY_AND_ASSIGN(ActualCallParams); |
276 }; | 287 }; |
277 | 288 |
278 COMPILE_ASSERT(sizeof(ActualCallParams<1, 1024>) == 1024, bad_size_buffer); | 289 COMPILE_ASSERT(sizeof(ActualCallParams<1, 1024>) == 1024, bad_size_buffer); |
279 COMPILE_ASSERT(sizeof(ActualCallParams<2, 1024>) == 1024, bad_size_buffer); | 290 COMPILE_ASSERT(sizeof(ActualCallParams<2, 1024>) == 1024, bad_size_buffer); |
280 COMPILE_ASSERT(sizeof(ActualCallParams<3, 1024>) == 1024, bad_size_buffer); | 291 COMPILE_ASSERT(sizeof(ActualCallParams<3, 1024>) == 1024, bad_size_buffer); |
281 | 292 |
282 } // namespace sandbox | 293 } // namespace sandbox |
283 | 294 |
284 #endif // SANDBOX_SRC_CROSSCALL_PARAMS_H__ | 295 #endif // SANDBOX_SRC_CROSSCALL_PARAMS_H__ |
OLD | NEW |