2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_REVERSE_SERVICE_REVERSE_SERVICE_C_H_
8 #define NATIVE_CLIENT_SRC_TRUSTED_REVERSE_SERVICE_REVERSE_SERVICE_C_H_
10 #include "native_client/src/include/nacl_base.h"
11 #include "native_client/src/include/portability.h"
13 #include "native_client/src/trusted/desc/nacl_desc_base.h"
15 #include "native_client/src/trusted/nacl_base/nacl_refcount.h"
16 #include "native_client/src/trusted/threading/nacl_thread_interface.h"
18 #include "native_client/src/trusted/simple_service/nacl_simple_rservice.h"
23 struct NaClReverseInterface;
24 struct NaClReverseInterfaceVtbl;
26 struct NaClReverseService {
27 struct NaClSimpleRevService base NACL_IS_REFCOUNT_SUBCLASS;
29 struct NaClReverseInterface *iface;
32 struct NaClCondVar cv;
34 * |mu| protects the thread count access.
36 uint32_t thread_count;
39 int NaClReverseServiceCtor(struct NaClReverseService *self,
40 struct NaClReverseInterface *iface,
41 struct NaClDesc *conn_cap);
43 void NaClReverseServiceDtor(struct NaClRefCount *vself);
45 struct NaClReverseServiceVtbl {
46 struct NaClSimpleRevServiceVtbl vbase;
49 struct NaClReverseService *self,
52 void (*WaitForServiceThreadsToExit)(
53 struct NaClReverseService *self);
55 void (*ThreadCountIncr)(
56 struct NaClReverseService *self);
58 void (*ThreadCountDecr)(
59 struct NaClReverseService *self);
62 int NaClReverseServiceStart(
63 struct NaClReverseService *self,
66 void NaClReverseServiceWaitForServiceThreadsToExit(
67 struct NaClReverseService *self);
69 void NaClReverseServiceThreadCountIncr(
70 struct NaClReverseService *self);
72 void NaClReverseServiceThreadCountDecr(
73 struct NaClReverseService *self);
75 extern struct NaClReverseServiceVtbl const kNaClReverseServiceVtbl;
77 struct NaClReverseInterface {
78 struct NaClRefCount base NACL_IS_REFCOUNT_SUBCLASS;
81 struct NaClReverseInterfaceVtbl {
82 struct NaClRefCountVtbl vbase;
84 /* For debugging, messaging. |message| goes to console. */
86 struct NaClReverseInterface *self,
89 /* Startup handshake */
90 void (*StartupInitializationComplete)(
91 struct NaClReverseInterface *self);
96 * Some of these functions require that the actual operation be done
97 * in a different thread, so that the implementation of the
98 * interface will have to block the requesting thread. However, on
99 * surf away, the thread switch may get cancelled, and the
100 * implementation will have to reply with a failure indication.
102 * The bool functions returns false if the service thread unblocked
103 * because of surf-away, shutdown, or other issues. The plugin,
104 * when it tells sel_ldr to shut down, will also signal all threads
105 * that are waiting for main thread callbacks to wake up and abandon
106 * their vigil after the callbacks are all cancelled (by abandoning
107 * the WeakRefAnchor or by bombing their CompletionCallbackFactory).
108 * Since shutdown/surfaway is the only admissible error, we use bool
109 * as the return type.
113 * Stores the manifest keys into the |buffer| of size |nbytes|.
114 * Returns the number of bytes copied if successful, otherwise
115 * returns the size required if |buffer| is not large enough.
117 size_t (*EnumerateManifestKeys)(
118 struct NaClReverseInterface *self,
120 size_t buffer_bytes);
123 * Opens manifest entry specified by |url_key|. Returns 1 if
124 * successful and stores the file descriptor in |out_desc|, otherwise
127 int (*OpenManifestEntry)(
128 struct NaClReverseInterface *self,
130 struct NaClFileInfo *info);
133 * Closes manifest entry with file descriptor |desc|. Returns 1 if
134 * successful, 0 otherwise.
136 int (*CloseManifestEntry)(
137 struct NaClReverseInterface *self,
141 * Reports the client crash.
144 struct NaClReverseInterface *self);
147 * The low-order 8 bits of the |exit_status| should be reported to
148 * any interested parties.
150 void (*ReportExitStatus)(
151 struct NaClReverseInterface *self,
155 * Standard output and standard error redirection, via setting
156 * NACL_EXE_STDOUT to the string "DEBUG_ONLY:dev://postmessage" (see
157 * native_client/src/trusted/nacl_resource.* and sel_ldr). NB: the
158 * contents of |message| is arbitrary bytes and not an Unicode
159 * string, so the implementation should take care to handle this
162 void (*DoPostMessage)(
163 struct NaClReverseInterface *self,
165 size_t message_bytes);
168 * Create new service runtime process and return secure command
169 * channel and untrusted application channel socket addresses. Returns
170 * 0 if successful or negative ABI error value otherwise (see
171 * service_runtime/include/sys/errno.h). DEPRECATED.
173 int (*CreateProcess)(
174 struct NaClReverseInterface *self,
175 struct NaClDesc **out_sock_addr,
176 struct NaClDesc **out_app_addr);
179 * Create new service runtime process and return secure command
180 * channel, untrusted application channel socket addresses, and pid
181 * via a result delivery functor. Returns negated ABI errno value
182 * in pid if there were errors (see the header file
183 * service_runtime/include/sys/errno.h). The |out_pid_or_errno|
184 * functor argument is also used to allow the "init" process to
185 * inform the embedding environment, via FinalizeProcess, that it is
186 * okay to finalize any resources associated with the identified
187 * subprocess when the subprocess has exited.
189 void (*CreateProcessFunctorResult)(
190 struct NaClReverseInterface *self,
191 void (*result_functor)(void *functor_state,
192 struct NaClDesc *out_sock_addr,
193 struct NaClDesc *out_app_addr,
194 int32_t out_pid_or_errno),
195 void *functor_state);
197 void (*FinalizeProcess)(
198 struct NaClReverseInterface *self,
202 * Quota checking for files that were sent to the untrusted module.
203 * TODO(sehr): remove the stub interface once the plugin provides one.
205 int64_t (*RequestQuotaForWrite)(
206 struct NaClReverseInterface *self,
213 * The protected Ctor is intended for use by subclasses of
214 * NaClReverseInterface.
216 int NaClReverseInterfaceCtor_protected(
217 struct NaClReverseInterface *self);
219 void NaClReverseInterfaceDtor(struct NaClRefCount *vself);
221 void NaClReverseInterfaceLog(
222 struct NaClReverseInterface *self,
223 char const *message);
225 void NaClReverseInterfaceStartupInitializationComplete(
226 struct NaClReverseInterface *self);
228 size_t NaClReverseInterfaceEnumerateManifestKeys(
229 struct NaClReverseInterface *self,
231 size_t buffer_bytes);
233 int NaClReverseInterfaceOpenManifestEntry(
234 struct NaClReverseInterface *self,
236 struct NaClFileInfo *info);
238 int NaClReverseInterfaceCloseManifestEntry(
239 struct NaClReverseInterface *self,
242 void NaClReverseInterfaceReportCrash(
243 struct NaClReverseInterface *self);
245 void NaClReverseInterfaceReportExitStatus(
246 struct NaClReverseInterface *self,
249 void NaClReverseInterfaceDoPostMessage(
250 struct NaClReverseInterface *self,
252 size_t message_bytes);
254 void NaClReverseInterfaceCreateProcessFunctorResult(
255 struct NaClReverseInterface *self,
256 void (*result_functor)(void *functor_state,
257 struct NaClDesc *out_sock_addr,
258 struct NaClDesc *out_app_addr,
259 int32_t out_pid_or_errno),
260 void *functor_state);
262 void NaClReverseInterfaceFinalizeProcess(struct NaClReverseInterface *self,
265 int NaClReverseInterfaceCreateProcess(
266 struct NaClReverseInterface *self,
267 struct NaClDesc **out_sock_addr,
268 struct NaClDesc **out_app_addr);
270 int64_t NaClReverseInterfaceRequestQuotaForWrite(
271 struct NaClReverseInterface *self,
276 extern struct NaClReverseInterfaceVtbl const kNaClReverseInterfaceVtbl;
280 #endif /* NATIVE_CLIENT_SRC_TRUSTED_REVERSE_SERVICE_REVERSE_SERVICE_C_H_ */