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

Side by Side Diff: src/shared/srpc/invoke.c

Issue 5622003: Restructure the structs/unions involved in SRPC argument passing. This will... (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/shared/srpc/nacl_srpc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2008 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * NaCl SRPC library. A primitive rpc library. 8 * NaCl SRPC library. A primitive rpc library.
9 */ 9 */
10 10
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 */ 139 */
140 /* 140 /*
141 * Some steps involve skipping a parameter in a va_arg list. 141 * Some steps involve skipping a parameter in a va_arg list.
142 */ 142 */
143 #define SKIP(va, impl_type) \ 143 #define SKIP(va, impl_type) \
144 (void) va_arg(va, impl_type); 144 (void) va_arg(va, impl_type);
145 145
146 /* 146 /*
147 * The first phase is the args[] vector construction. 147 * The first phase is the args[] vector construction.
148 */ 148 */
149 #define SCALAR_ARG(arg, field, va, impl_type) \ 149 #define SCALAR_ARG(arg, field, va, impl_type) \
150 (arg)->u.field = va_arg(va, impl_type) 150 (arg)->field = va_arg(va, impl_type)
151 #define ARRAY_ARG(arg, field, array_name, va, impl_type) \ 151 #define ARRAY_ARG(arg, array_name, va, impl_type) \
152 (arg)->u.field.count = va_arg(va, uint32_t); \ 152 (arg)->u.count = va_arg(va, uint32_t); \
153 (arg)->u.field.array_name = va_arg(va, impl_type) 153 (arg)->array_name = va_arg(va, impl_type)
Cliff L. Biffle 2010/12/08 21:51:51 If you wanted, you could have array_name be e.g. "
154 #define BOOL_ARG(arg, field, va, impl_type) \ 154 #define BOOL_ARG(arg, field, va, impl_type) \
155 (arg)->u.bval = (va_arg(va, impl_type) != 0) 155 (arg)->u.bval = (va_arg(va, impl_type) != 0)
156 156
157 /* 157 /*
158 * The second phase is the rets[] vector construction before invocation. 158 * The second phase is the rets[] vector construction before invocation.
159 */ 159 */
160 #define SCALAR_RETINIT(arg, field, va, impl_type) \ 160 #define SCALAR_RETINIT(arg, field, va, impl_type) \
161 (arg)->u.field = (impl_type) 0; \ 161 (arg)->field = (impl_type) 0; \
162 SKIP(va, impl_type *) 162 SKIP(va, impl_type *)
163 #define ARRAY_RETINIT(arg, field, array_name, va, impl_type) \ 163 #define ARRAY_RETINIT(arg, array_name, va, impl_type) \
164 (arg)->u.field.count = *va_arg(va, uint32_t*); \ 164 (arg)->u.count = *va_arg(va, uint32_t*); \
165 (arg)->u.field.array_name = va_arg(va, impl_type) 165 (arg)->array_name = va_arg(va, impl_type)
166 #define BOOL_RETINIT(arg, field, va, impl_type) \ 166 #define BOOL_RETINIT(arg, field, va, impl_type) \
167 SKIP(va, impl_type *) 167 SKIP(va, impl_type *)
168 168
169 /* 169 /*
170 * The third phase is skipping the args[] after invocation. 170 * The third phase is skipping the args[] after invocation.
171 */ 171 */
172 #define SCALAR_SKIP(arg, field, va, impl_type) \ 172 #define SCALAR_SKIP(arg, field, va, impl_type) \
173 SKIP(va, impl_type) 173 SKIP(va, impl_type)
174 #define ARRAY_SKIP(arg, field, array_name, va, impl_type) \ 174 #define ARRAY_SKIP(arg, array_name, va, impl_type) \
175 SKIP(va, uint32_t) \ 175 SKIP(va, uint32_t) \
176 SKIP(va, impl_type) 176 SKIP(va, impl_type)
177 #define BOOL_SKIP(arg, field, va, impl_type) \ 177 #define BOOL_SKIP(arg, field, va, impl_type) \
178 SCALAR_SKIP(arg, field, va, impl_type) 178 SCALAR_SKIP(arg, field, va, impl_type)
179 179
180 /* 180 /*
181 * The fourth phase is copying the rets[] into the va_args after invocation. 181 * The fourth phase is copying the rets[] into the va_args after invocation.
182 */ 182 */
183 #define SCALAR_RET(arg, field, va, impl_type) \ 183 #define SCALAR_RET(arg, field, va, impl_type) \
184 *va_arg(va, impl_type *) = (arg)->u.field 184 *va_arg(va, impl_type *) = (arg)->field
185 #define ARRAY_RET(arg, field, array_name, va, impl_type) \ 185 #define ARRAY_RET(arg, array_name, va, impl_type) \
186 ARRAY_SKIP(arg, field, array_name, va, impl_type) 186 ARRAY_SKIP(arg, array_name, va, impl_type)
187 #define BOOL_RET(arg, field, va, impl_type) \ 187 #define BOOL_RET(arg, field, va, impl_type) \
188 *va_arg(va, impl_type *) = ((arg)->u.field != 0) 188 *va_arg(va, impl_type *) = ((arg)->field != 0)
189 189
190 /* 190 /*
191 * All the phases consist of a loop around a switch enumerating types. 191 * All the phases consist of a loop around a switch enumerating types.
192 */ 192 */
193 #define ARGRET_SWITCH(phase, va, arg) \ 193 #define ARGRET_SWITCH(phase, va, arg) \
194 switch (*p) { \ 194 switch (*p) { \
195 case NACL_SRPC_ARG_TYPE_BOOL: \ 195 case NACL_SRPC_ARG_TYPE_BOOL: \
196 BOOL_##phase(arg, bval, va, int); \ 196 BOOL_##phase(arg, u.bval, va, int); \
197 break; \ 197 break; \
198 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: \ 198 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: \
199 ARRAY_##phase(arg, caval, carr, va, char*); \ 199 ARRAY_##phase(arg, arrays.carr, va, char*); \
200 break; \ 200 break; \
201 case NACL_SRPC_ARG_TYPE_DOUBLE: \ 201 case NACL_SRPC_ARG_TYPE_DOUBLE: \
202 SCALAR_##phase(arg, dval, va, double); \ 202 SCALAR_##phase(arg, u.dval, va, double); \
203 break; \ 203 break; \
204 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: \ 204 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: \
205 ARRAY_##phase(arg, daval, darr, va, double*); \ 205 ARRAY_##phase(arg, arrays.darr, va, double*); \
206 break; \ 206 break; \
207 case NACL_SRPC_ARG_TYPE_HANDLE: \ 207 case NACL_SRPC_ARG_TYPE_HANDLE: \
208 SCALAR_##phase(arg, hval, va, NaClSrpcImcDescType); \ 208 SCALAR_##phase(arg, u.hval, va, NaClSrpcImcDescType); \
209 break; \ 209 break; \
210 case NACL_SRPC_ARG_TYPE_INT: \ 210 case NACL_SRPC_ARG_TYPE_INT: \
211 SCALAR_##phase(arg, ival, va, int32_t); \ 211 SCALAR_##phase(arg, u.ival, va, int32_t); \
212 break; \ 212 break; \
213 case NACL_SRPC_ARG_TYPE_INT_ARRAY: \ 213 case NACL_SRPC_ARG_TYPE_INT_ARRAY: \
214 ARRAY_##phase(arg, iaval, iarr, va, int32_t*); \ 214 ARRAY_##phase(arg, arrays.iarr, va, int32_t*); \
215 break; \ 215 break; \
216 case NACL_SRPC_ARG_TYPE_LONG: \ 216 case NACL_SRPC_ARG_TYPE_LONG: \
217 SCALAR_##phase(arg, lval, va, int64_t); \ 217 SCALAR_##phase(arg, u.lval, va, int64_t); \
218 break; \ 218 break; \
219 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: \ 219 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: \
220 ARRAY_##phase(arg, laval, larr, va, int64_t*); \ 220 ARRAY_##phase(arg, arrays.larr, va, int64_t*); \
221 break; \ 221 break; \
222 case NACL_SRPC_ARG_TYPE_STRING: \ 222 case NACL_SRPC_ARG_TYPE_STRING: \
223 SCALAR_##phase(arg, sval.str, va, char*); \ 223 SCALAR_##phase(arg, arrays.str, va, char*); \
224 break; \ 224 break; \
225 /* \ 225 /* \
226 * The two cases below are added to avoid warnings, \ 226 * The two cases below are added to avoid warnings, \
227 * they are only used in the plugin code \ 227 * they are only used in the plugin code \
228 */ \ 228 */ \
229 case NACL_SRPC_ARG_TYPE_OBJECT: \ 229 case NACL_SRPC_ARG_TYPE_OBJECT: \
230 case NACL_SRPC_ARG_TYPE_VARIANT_ARRAY: \ 230 case NACL_SRPC_ARG_TYPE_VARIANT_ARRAY: \
231 default: \ 231 default: \
232 rv = NACL_SRPC_RESULT_APP_ERROR; \ 232 rv = NACL_SRPC_RESULT_APP_ERROR; \
233 goto abort4; \ 233 goto abort4; \
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 va_start(in_va, rpc_signature); 372 va_start(in_va, rpc_signature);
373 va_start(out_va, rpc_signature); 373 va_start(out_va, rpc_signature);
374 374
375 rv = NaClSrpcInvokeVaList(channel, rpc_num, in_va, out_va); 375 rv = NaClSrpcInvokeVaList(channel, rpc_num, in_va, out_va);
376 376
377 va_end(out_va); 377 va_end(out_va);
378 va_end(in_va); 378 va_end(in_va);
379 379
380 return rv; 380 return rv;
381 } 381 }
OLDNEW
« no previous file with comments | « no previous file | src/shared/srpc/nacl_srpc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698