| OLD | NEW |
| 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 #ifndef NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_ | 7 #ifndef NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_ |
| 8 #define NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_ | 8 #define NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_ |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 NACL_SRPC_ARG_TYPE_HANDLE = 'h', /**< a descriptor (handle) */ | 120 NACL_SRPC_ARG_TYPE_HANDLE = 'h', /**< a descriptor (handle) */ |
| 121 NACL_SRPC_ARG_TYPE_INT = 'i', /**< scalar int32_t */ | 121 NACL_SRPC_ARG_TYPE_INT = 'i', /**< scalar int32_t */ |
| 122 NACL_SRPC_ARG_TYPE_INT_ARRAY = 'I', /**< array of int32_t */ | 122 NACL_SRPC_ARG_TYPE_INT_ARRAY = 'I', /**< array of int32_t */ |
| 123 NACL_SRPC_ARG_TYPE_LONG = 'l', /**< scalar int64_t */ | 123 NACL_SRPC_ARG_TYPE_LONG = 'l', /**< scalar int64_t */ |
| 124 NACL_SRPC_ARG_TYPE_LONG_ARRAY = 'L', /**< array of int64_t */ | 124 NACL_SRPC_ARG_TYPE_LONG_ARRAY = 'L', /**< array of int64_t */ |
| 125 NACL_SRPC_ARG_TYPE_STRING = 's', /**< NUL-terminated string */ | 125 NACL_SRPC_ARG_TYPE_STRING = 's', /**< NUL-terminated string */ |
| 126 NACL_SRPC_ARG_TYPE_OBJECT = 'o', /**< scriptable object */ | 126 NACL_SRPC_ARG_TYPE_OBJECT = 'o', /**< scriptable object */ |
| 127 NACL_SRPC_ARG_TYPE_VARIANT_ARRAY = 'A' /**< array of NaClSrpcArg structs */ | 127 NACL_SRPC_ARG_TYPE_VARIANT_ARRAY = 'A' /**< array of NaClSrpcArg structs */ |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 /** | |
| 131 * Argument data type for passing arrays of NaClSrpcArg. | |
| 132 */ | |
| 133 struct NaClSrpcVariantArray { | |
| 134 /** The number of elements in the array */ | |
| 135 nacl_abi_size_t count; | |
| 136 /** A chunk of memory containing <code>count</code> NaClSrpcArg structures */ | |
| 137 struct NaClSrpcArg *varr; | |
| 138 }; | |
| 139 | |
| 140 /** | |
| 141 * Argument data type for passing arrays of char. | |
| 142 * @see NaClSrpcArg | |
| 143 */ | |
| 144 struct NaClSrpcCharArray { | |
| 145 /** The number of characters in the array */ | |
| 146 nacl_abi_size_t count; | |
| 147 /** A chunk of memory containing <code>count</code> characters */ | |
| 148 char *carr; | |
| 149 }; | |
| 150 | |
| 151 /** | |
| 152 * Argument data type for passing arrays of double. | |
| 153 * @see NaClSrpcArg | |
| 154 */ | |
| 155 struct NaClSrpcDoubleArray { | |
| 156 /** The number of doubles in the array */ | |
| 157 nacl_abi_size_t count; | |
| 158 /** A chunk of memory containing <code>count</code> doubles */ | |
| 159 double *darr; | |
| 160 }; | |
| 161 | |
| 162 /** | |
| 163 * Argument data type for passing arrays of int32_t. | |
| 164 * @see NaClSrpcArg | |
| 165 */ | |
| 166 struct NaClSrpcIntArray { | |
| 167 /** The number of integers in the array */ | |
| 168 nacl_abi_size_t count; | |
| 169 /** A chunk of memory containing <code>count</code> int32_t */ | |
| 170 int32_t *iarr; | |
| 171 }; | |
| 172 | |
| 173 /** | |
| 174 * Argument data type for passing arrays of int64_t. | |
| 175 * @see NaClSrpcArg | |
| 176 */ | |
| 177 struct NaClSrpcLongArray { | |
| 178 /** The number of doubles in the array */ | |
| 179 nacl_abi_size_t count; | |
| 180 /** A chunk of memory containing <code>count</code> int64_t */ | |
| 181 int64_t *larr; | |
| 182 }; | |
| 183 | |
| 184 /** | |
| 185 * Argument data type for passing character strings. | |
| 186 * @see NaClSrpcArg | |
| 187 */ | |
| 188 struct NaClSrpcString { | |
| 189 /** The number of characters in the string. | |
| 190 * (Only guaranteed to be valid during serialization.) | |
| 191 */ | |
| 192 nacl_abi_size_t count; | |
| 193 /** A chunk of memory containing <code>count</code> char */ | |
| 194 char *str; | |
| 195 }; | |
| 196 | |
| 197 #ifdef __cplusplus | 130 #ifdef __cplusplus |
| 198 namespace nacl_srpc { | 131 namespace nacl_srpc { |
| 199 class ScriptableHandleBase; | 132 class ScriptableHandleBase; |
| 200 } | 133 } |
| 201 #endif | 134 #endif |
| 202 | 135 |
| 136 #define NACL_SRPC_ARG_SERIALIZED_FIELDS \ |
| 137 /** \ |
| 138 * Determines which type this argument contains. Its value determines \ |
| 139 * which element of union <code>u</code> may be validly referred to. \ |
| 140 */ \ |
| 141 enum NaClSrpcArgType tag; \ |
| 142 /** \ |
| 143 * Padding (unused) to ensure 8-byte alignment of the union u. \ |
| 144 */ \ |
| 145 uint32_t reserved_pad; \ |
| 146 /* \ |
| 147 * For efficiency, doubles should be 8-byte aligned so that \ |
| 148 * loading them would require a single bus cycle, and arrays of \ |
| 149 * NaClSrpcArgs will have to be 8-byte aligned as well, so it's \ |
| 150 * either a 4 byte padding between the tag and the union or \ |
| 151 * (implicitly) at the end. gcc does not (by default) enforce \ |
| 152 * 8-byte alignment but visual studio does, so we explicitly pad \ |
| 153 * so that both compilers will use the same memory layout, even if \ |
| 154 * the gcc -malign-double flag were omitted. \ |
| 155 */ \ |
| 156 /** \ |
| 157 * A union containing the value of the argument. The element containing \ |
| 158 * the valid data is determined by <code>tag</code>. \ |
| 159 */ \ |
| 160 union { \ |
| 161 /** A boolean scalar value */ \ |
| 162 int bval; \ |
| 163 /** An array size (count) value */ \ |
| 164 nacl_abi_size_t count; \ |
| 165 /** A double-precision floating point scalar value */ \ |
| 166 double dval; \ |
| 167 /** A handle used to pass descriptors */ \ |
| 168 NaClSrpcImcDescType hval; \ |
| 169 /** An integer scalar value */ \ |
| 170 int32_t ival; \ |
| 171 /** A int64_t scalar value */ \ |
| 172 int64_t lval; \ |
| 173 /** An object value that can be exported to the browser as is */ \ |
| 174 } u |
| 175 |
| 203 /** | 176 /** |
| 204 * Used to convey parameters to and from RPC invocations. It is a variant | 177 * Used to convey parameters to and from RPC invocations. It is a variant |
| 205 * type, with the <code>tag</code> telling whether to treat the parameter as | 178 * type, with the <code>tag</code> telling whether to treat the parameter as |
| 206 * a bool or an array of characters, etc. | 179 * a bool or an array of characters, etc. |
| 207 */ | 180 */ |
| 208 struct NaClSrpcArg { | 181 struct NaClSrpcArg { |
| 209 /** | 182 /* Data that is serialized for a value or template, regardless of type. */ |
| 210 * Determines which type this argument contains. Its value determines | 183 NACL_SRPC_ARG_SERIALIZED_FIELDS; |
| 211 * which element of union <code>u</code> may be validly referred to. | 184 /* Data that used to represent an array value, but is not serialized. */ |
| 212 */ | |
| 213 enum NaClSrpcArgType tag; | |
| 214 /** | |
| 215 * Padding (unused) to ensure 8-byte alignment of the union u. | |
| 216 */ | |
| 217 uint32_t reserved_pad; | |
| 218 /* | |
| 219 * For efficiency, doubles should be 8-byte aligned so that | |
| 220 * loading them would require a single bus cycle, and arrays of | |
| 221 * NaClSrpcArgs will have to be 8-byte aligned as well, so it's | |
| 222 * either a 4 byte padding between the tag and the union or | |
| 223 * (implicitly) at the end. gcc does not (by default) enforce | |
| 224 * 8-byte alignment but visual studio does, so we explicitly pad | |
| 225 * so that both compilers will use the same memory layout, even if | |
| 226 * the gcc -malign-double flag were omitted. | |
| 227 */ | |
| 228 /** | |
| 229 * A union containing the value of the argument. The element containing | |
| 230 * the valid data is determined by <code>tag</code>. | |
| 231 */ | |
| 232 union { | 185 union { |
| 233 /** A boolean value */ | 186 char *carr; |
| 234 int bval; | 187 double *darr; |
| 235 /** An integer value */ | 188 int32_t *iarr; |
| 236 int32_t ival; | 189 int64_t *larr; |
| 237 /** A int64_t value */ | 190 /** This field is ordinarily used with predeclared methods, and is never |
| 238 int64_t lval; | 191 * used directly for communicating with nexes. It usually points to an |
| 239 /** A double-precision floating point value */ | 192 * object scriptable by the browser, i.e. NPAPI's NPObject or PPAPI's |
| 240 double dval; | 193 * ScriptableObject. Declaring it as void* to avoid including browser |
| 241 /** An array of character values */ | 194 * specific types here. |
| 242 struct NaClSrpcCharArray caval; | 195 * TODO(polina): where can one assert for this? |
| 243 /** An array of double-precision floating point values */ | 196 * Also, as these pointers are overlaid, oval is used in array object |
| 244 struct NaClSrpcDoubleArray daval; | 197 * serialization to avoid repeated type checks. |
| 245 /** An array of int32_t values */ | |
| 246 struct NaClSrpcIntArray iaval; | |
| 247 /** An array of int64_t values */ | |
| 248 struct NaClSrpcLongArray laval; | |
| 249 /** A string value */ | |
| 250 struct NaClSrpcString sval; | |
| 251 /** A handle used to pass descriptors */ | |
| 252 NaClSrpcImcDescType hval; | |
| 253 /** An object value that can be exported to the browser as is */ | |
| 254 /** This field is only used with predeclared methods, never for | |
| 255 * communicating with nexes. TODO(polina): where can one assert for this? | |
| 256 * This usually points to an object scriptable by | |
| 257 * the browser, i.e. NPAPI's NPObject or PPAPI's ScriptableObject. | |
| 258 * Declaring it as void* to avoid including browser specific stuff here. | |
| 259 */ | 198 */ |
| 260 void *oval; | 199 void *oval; |
| 261 /** An array of variant type values. @see NaClSrpcArg */ | 200 char *str; |
| 262 struct NaClSrpcVariantArray vaval; | 201 struct NaClSrpcArg *varr; |
| 263 } u; | 202 } arrays; |
| 264 }; | 203 }; |
| 265 | 204 |
| 266 /** | 205 /** |
| 267 * A typedef for struct NaClSrpcArg for use in C. | 206 * A typedef for struct NaClSrpcArg for use in C. |
| 268 */ | 207 */ |
| 269 typedef struct NaClSrpcArg NaClSrpcArg; | 208 typedef struct NaClSrpcArg NaClSrpcArg; |
| 270 | 209 |
| 210 #define NACL_SRPC_RPC_SERIALIZED_FIELDS \ |
| 211 uint32_t protocol_version; \ |
| 212 uint64_t request_id; \ |
| 213 uint8_t is_request; \ |
| 214 uint32_t rpc_number; \ |
| 215 NaClSrpcError result \ |
| 216 |
| 271 /** | 217 /** |
| 272 * Remote procedure call state structure. | 218 * Remote procedure call state structure. |
| 273 */ | 219 */ |
| 274 struct NaClSrpcRpc { | 220 struct NaClSrpcRpc { |
| 275 uint32_t protocol_version; | 221 /* State that is serialized. */ |
| 276 uint64_t request_id; | 222 NACL_SRPC_RPC_SERIALIZED_FIELDS; |
| 277 uint8_t is_request; | |
| 278 uint32_t rpc_number; | |
| 279 NaClSrpcError result; | |
| 280 /* State maintained for transmission/reception, but not serialized */ | 223 /* State maintained for transmission/reception, but not serialized */ |
| 281 struct NaClSrpcChannel* channel; | 224 struct NaClSrpcChannel* channel; |
| 282 const char* ret_types; | 225 const char* ret_types; |
| 283 NaClSrpcArg** rets; | 226 NaClSrpcArg** rets; |
| 284 uint8_t ret_send_succeeded; | 227 uint8_t ret_send_succeeded; |
| 285 uint8_t dispatch_loop_should_continue; | 228 uint8_t dispatch_loop_should_continue; |
| 286 /* TODO(sehr): buffer is actually part of the channel struct. Remove it. */ | 229 /* TODO(sehr): buffer is actually part of the channel struct. Remove it. */ |
| 287 struct NaClSrpcImcBuffer* buffer; | 230 struct NaClSrpcImcBuffer* buffer; |
| 288 }; | 231 }; |
| 289 | 232 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 int NaClSrpcCommandLoopMain(const struct NaClSrpcHandlerDesc *methods); | 749 int NaClSrpcCommandLoopMain(const struct NaClSrpcHandlerDesc *methods); |
| 807 | 750 |
| 808 EXTERN_C_END | 751 EXTERN_C_END |
| 809 | 752 |
| 810 /** | 753 /** |
| 811 * @} | 754 * @} |
| 812 * End of System Calls group | 755 * End of System Calls group |
| 813 */ | 756 */ |
| 814 | 757 |
| 815 #endif /* NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_ */ | 758 #endif /* NATIVE_CLIENT_SRC_SHARED_SRPC_NACL_SRPC_H_ */ |
| OLD | NEW |