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