| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "native_client/src/trusted/plugin/pnacl_srpc_lib.h" | |
| 6 | |
| 7 #include <stdarg.h> | |
| 8 | |
| 9 #include "native_client/src/trusted/plugin/browser_interface.h" | |
| 10 #include "native_client/src/trusted/plugin/method_map.h" | |
| 11 #include "native_client/src/trusted/plugin/nacl_subprocess.h" | |
| 12 | |
| 13 namespace plugin { | |
| 14 | |
| 15 bool PnaclSrpcLib::InvokeSrpcMethod(BrowserInterface* browser_interface, | |
| 16 const NaClSubprocess* subprocess, | |
| 17 const nacl::string& method_name, | |
| 18 const nacl::string& input_signature, | |
| 19 SrpcParams* params, | |
| 20 ...) { | |
| 21 va_list vl; | |
| 22 va_start(vl, params); | |
| 23 bool result = VInvokeSrpcMethod(browser_interface, | |
| 24 subprocess, | |
| 25 method_name, | |
| 26 input_signature, | |
| 27 params, | |
| 28 vl); | |
| 29 va_end(vl); | |
| 30 return result; | |
| 31 } | |
| 32 | |
| 33 bool PnaclSrpcLib::VInvokeSrpcMethod(BrowserInterface* browser_interface, | |
| 34 const NaClSubprocess* subprocess, | |
| 35 const nacl::string& method_name, | |
| 36 const nacl::string& input_signature, | |
| 37 SrpcParams* params, | |
| 38 va_list vl) { | |
| 39 uintptr_t kMethodIdent; | |
| 40 if (!SetupSrpcInvocation(browser_interface, | |
| 41 subprocess, | |
| 42 method_name, | |
| 43 params, | |
| 44 &kMethodIdent)) { | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 // Set up inputs. | |
| 49 for (size_t i = 0; i < input_signature.length(); ++i) { | |
| 50 char c = input_signature[i]; | |
| 51 // Only handle the limited number of SRPC types used for PNaCl. | |
| 52 // Add more as needed. | |
| 53 switch (c) { | |
| 54 default: | |
| 55 PLUGIN_PRINTF(("PnaclSrpcLib::InvokeSrpcMethod unhandled type: %c\n", | |
| 56 c)); | |
| 57 return false; | |
| 58 case NACL_SRPC_ARG_TYPE_BOOL: { | |
| 59 int input = va_arg(vl, int); | |
| 60 params->ins()[i]->u.bval = input; | |
| 61 break; | |
| 62 } | |
| 63 case NACL_SRPC_ARG_TYPE_DOUBLE: { | |
| 64 double input = va_arg(vl, double); | |
| 65 params->ins()[i]->u.dval = input; | |
| 66 break; | |
| 67 } | |
| 68 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: { | |
| 69 // SrpcParam's destructor *should* free the dup'ed string. | |
| 70 const char* orig_str = va_arg(vl, const char*); | |
| 71 char* input = strdup(orig_str); | |
| 72 params->ins()[i]->arrays.str = input; | |
| 73 break; | |
| 74 } | |
| 75 case NACL_SRPC_ARG_TYPE_HANDLE: { | |
| 76 NaClSrpcImcDescType input = va_arg(vl, NaClSrpcImcDescType); | |
| 77 params->ins()[i]->u.hval = input; | |
| 78 break; | |
| 79 } | |
| 80 case NACL_SRPC_ARG_TYPE_INT: { | |
| 81 int32_t input = va_arg(vl, int32_t); | |
| 82 params->ins()[i]->u.ival = input; | |
| 83 break; | |
| 84 } | |
| 85 case NACL_SRPC_ARG_TYPE_LONG: { | |
| 86 int64_t input = va_arg(vl, int64_t); | |
| 87 params->ins()[i]->u.lval = input; | |
| 88 break; | |
| 89 } | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 return subprocess->Invoke(kMethodIdent, params); | |
| 94 } | |
| 95 | |
| 96 | |
| 97 bool PnaclSrpcLib::SetupSrpcInvocation(BrowserInterface* browser_interface, | |
| 98 const NaClSubprocess* subprocess, | |
| 99 const nacl::string& method_name, | |
| 100 SrpcParams* params, | |
| 101 uintptr_t* kMethodIdent) { | |
| 102 *kMethodIdent = browser_interface->StringToIdentifier(method_name); | |
| 103 if (!(subprocess->HasMethod(*kMethodIdent))) { | |
| 104 PLUGIN_PRINTF(("SetupSrpcInvocation (no %s method found)\n", | |
| 105 method_name.c_str())); | |
| 106 return false; | |
| 107 } | |
| 108 return subprocess->InitParams(*kMethodIdent, params); | |
| 109 } | |
| 110 | |
| 111 } // namespace plugin | |
| OLD | NEW |