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 // 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 "native_client/src/include/nacl_string.h" | |
15 #include "native_client/src/trusted/plugin/service_runtime.h" | |
16 #include "native_client/src/trusted/plugin/srpc_client.h" | |
17 | |
18 namespace plugin { | |
19 | |
20 class Plugin; | |
21 class ServiceRuntime; | |
22 | |
23 // Identifier for helper NaCl nexes. Should be non-negative for valid nexes. | |
24 typedef int32_t NaClSubprocessId; | |
25 const NaClSubprocessId kInvalidNaClSubprocessId = -1; | |
26 const NaClSubprocessId kMainSubprocessId = -2; | |
27 | |
28 // A class representing an instance of a NaCl module, loaded by the plugin. | |
29 class NaClSubprocess { | |
30 public: | |
31 NaClSubprocess(NaClSubprocessId assigned_id, | |
32 ServiceRuntime* service_runtime, | |
33 SrpcClient* srpc_client) | |
34 : assigned_id_(assigned_id), | |
35 service_runtime_(service_runtime), | |
36 srpc_client_(srpc_client) { | |
37 } | |
38 virtual ~NaClSubprocess(); | |
39 | |
40 ServiceRuntime* service_runtime() const { return service_runtime_.get(); } | |
41 void set_service_runtime(ServiceRuntime* service_runtime) { | |
42 service_runtime_.reset(service_runtime); | |
43 } | |
44 | |
45 // The socket used for communicating w/ the NaCl module. | |
46 SrpcClient* srpc_client() const { return srpc_client_.get(); } | |
47 void set_socket(SrpcClient* srpc_client) { srpc_client_.reset(srpc_client); } | |
48 | |
49 // A basic description of the subprocess. | |
50 nacl::string description() const; | |
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 nacl::string detailed_description() const; | |
55 | |
56 // Start up interfaces. | |
57 bool StartSrpcServices(); | |
58 bool StartJSObjectProxy(Plugin* plugin, ErrorInfo* error_info); | |
59 | |
60 // Interact. | |
61 bool HasMethod(uintptr_t method_id) const; | |
62 bool InitParams(uintptr_t method_id, SrpcParams* params) const; | |
63 bool Invoke(uintptr_t method_id, SrpcParams* params) const; | |
64 | |
65 // Fully shut down the subprocess. | |
66 void Shutdown(); | |
67 | |
68 private: | |
69 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess); | |
70 | |
71 NaClSubprocessId assigned_id_; | |
72 | |
73 // The service runtime representing the NaCl module instance. | |
74 nacl::scoped_ptr<ServiceRuntime> service_runtime_; | |
75 | |
76 // Ownership of srpc_client taken from the service runtime. | |
77 nacl::scoped_ptr<SrpcClient> srpc_client_; | |
78 }; | |
79 | |
80 } // namespace plugin | |
81 | |
82 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ | |
OLD | NEW |