1 // Copyright (c) 2012 The Chromium 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 // Instances of NaCl modules spun up within the plugin as a subprocess. 6 // This may represent the "main" nacl module, or it may represent helpers 7 // that perform various tasks within the plugin, for example, 8 // a NaCl module for a compiler could be loaded to translate LLVM bitcode 9 // into native code. 10 11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ 12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ 13 14 #include <stdarg.h> 15 16 #include "native_client/src/include/nacl_macros.h" 17 #include "native_client/src/include/portability.h" 18 19 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" 20 #include "ppapi/native_client/src/trusted/plugin/srpc_client.h" 21 22 namespace plugin { 23 24 class Plugin; 25 class ServiceRuntime; 26 class SrpcParams; 27 28 29 // A class representing an instance of a NaCl module, loaded by the plugin. 30 class NaClSubprocess { 31 public: 32 NaClSubprocess(const std::string& description, 33 ServiceRuntime* service_runtime, 34 SrpcClient* srpc_client) 35 : description_(description), 36 service_runtime_(service_runtime), 37 srpc_client_(srpc_client) { 38 } 39 virtual ~NaClSubprocess(); 40 41 ServiceRuntime* service_runtime() const { return service_runtime_.get(); } 42 void set_service_runtime(ServiceRuntime* service_runtime) { 43 service_runtime_.reset(service_runtime); 44 } 45 46 // The socket used for communicating w/ the NaCl module. 47 SrpcClient* srpc_client() const { return srpc_client_.get(); } 48 49 // A basic description of the subprocess. 50 std::string description() const { return description_; } 51 52 // A detailed description of the subprocess that may contain addresses. 53 // Only use for debugging, but do not expose this to untrusted webapps. 54 std::string detailed_description() const; 55 56 // Start up interfaces. 57 bool StartSrpcServices(); 58 59 // Invoke an Srpc Method. |out_params| must be allocated and cleaned up 60 // outside of this function, but it will be initialized by this function, and 61 // on success any out-params (if any) will be placed in |out_params|. 62 // Input types must be listed in |input_signature|, with the actual 63 // arguments passed in as var-args. Returns |true| on success. 64 bool InvokeSrpcMethod(const std::string& method_name, 65 const std::string& input_signature, 66 SrpcParams* out_params, 67 ...); 68 69 // Fully shut down the subprocess. 70 void Shutdown(); 71 72 private: 73 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess); 74 75 bool VInvokeSrpcMethod(const std::string& method_name, 76 const std::string& signature, 77 SrpcParams* params, 78 va_list vl); 79 80 std::string description_; 81 82 // The service runtime representing the NaCl module instance. 83 nacl::scoped_ptr<ServiceRuntime> service_runtime_; 84 // Ownership of srpc_client taken from the service runtime. 85 nacl::scoped_ptr<SrpcClient> srpc_client_; 86 }; 87 88 } // namespace plugin 89 90 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ 91