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 /* Startup handshake */
85 void (*StartupInitializationComplete)(
86 struct NaClReverseInterface *self);
91 * Some of these functions require that the actual operation be done
92 * in a different thread, so that the implementation of the
93 * interface will have to block the requesting thread. However, on
94 * surf away, the thread switch may get cancelled, and the
95 * implementation will have to reply with a failure indication.
97 * The bool functions returns false if the service thread unblocked
98 * because of surf-away, shutdown, or other issues. The plugin,
99 * when it tells sel_ldr to shut down, will also signal all threads
100 * that are waiting for main thread callbacks to wake up and abandon
101 * their vigil after the callbacks are all cancelled (by abandoning
102 * the WeakRefAnchor or by bombing their CompletionCallbackFactory).
103 * Since shutdown/surfaway is the only admissible error, we use bool
104 * as the return type.
108 * Stores the manifest keys into the |buffer| of size |nbytes|.
109 * Returns the number of bytes copied if successful, otherwise
110 * returns the size required if |buffer| is not large enough.
112 size_t (*EnumerateManifestKeys)(
113 struct NaClReverseInterface *self,
115 size_t buffer_bytes);
118 * Opens manifest entry specified by |url_key|. Returns 1 if
119 * successful and stores the file descriptor in |out_desc|, otherwise
122 int (*OpenManifestEntry)(
123 struct NaClReverseInterface *self,
125 struct NaClFileInfo *info);
128 * Closes manifest entry with file descriptor |desc|. Returns 1 if
129 * successful, 0 otherwise.
131 int (*CloseManifestEntry)(
132 struct NaClReverseInterface *self,
136 * Reports the client crash.
139 struct NaClReverseInterface *self);
142 * The low-order 8 bits of the |exit_status| should be reported to
143 * any interested parties.
145 void (*ReportExitStatus)(
146 struct NaClReverseInterface *self,
150 * Standard output and standard error redirection, via setting
151 * NACL_EXE_STDOUT to the string "DEBUG_ONLY:dev://postmessage" (see
152 * native_client/src/trusted/nacl_resource.* and sel_ldr). NB: the
153 * contents of |message| is arbitrary bytes and not an Unicode
154 * string, so the implementation should take care to handle this
157 void (*DoPostMessage)(
158 struct NaClReverseInterface *self,
160 size_t message_bytes);
163 * Create new service runtime process and return secure command
164 * channel and untrusted application channel socket addresses. Returns
165 * 0 if successful or negative ABI error value otherwise (see
166 * service_runtime/include/sys/errno.h). DEPRECATED.
168 int (*CreateProcess)(
169 struct NaClReverseInterface *self,
170 struct NaClDesc **out_sock_addr,
171 struct NaClDesc **out_app_addr);
174 * Create new service runtime process and return secure command
175 * channel, untrusted application channel socket addresses, and pid
176 * via a result delivery functor. Returns negated ABI errno value
177 * in pid if there were errors (see the header file
178 * service_runtime/include/sys/errno.h). The |out_pid_or_errno|
179 * functor argument is also used to allow the "init" process to
180 * inform the embedding environment, via FinalizeProcess, that it is
181 * okay to finalize any resources associated with the identified
182 * subprocess when the subprocess has exited.
184 void (*CreateProcessFunctorResult)(
185 struct NaClReverseInterface *self,
186 void (*result_functor)(void *functor_state,
187 struct NaClDesc *out_sock_addr,
188 struct NaClDesc *out_app_addr,
189 int32_t out_pid_or_errno),
190 void *functor_state);
192 void (*FinalizeProcess)(
193 struct NaClReverseInterface *self,
197 * Quota checking for files that were sent to the untrusted module.
198 * TODO(sehr): remove the stub interface once the plugin provides one.
200 int64_t (*RequestQuotaForWrite)(
201 struct NaClReverseInterface *self,
208 * The protected Ctor is intended for use by subclasses of
209 * NaClReverseInterface.
211 int NaClReverseInterfaceCtor_protected(
212 struct NaClReverseInterface *self);
214 void NaClReverseInterfaceDtor(struct NaClRefCount *vself);
216 void NaClReverseInterfaceLog(
217 struct NaClReverseInterface *self,
218 char const *message);
220 void NaClReverseInterfaceStartupInitializationComplete(
221 struct NaClReverseInterface *self);
223 size_t NaClReverseInterfaceEnumerateManifestKeys(
224 struct NaClReverseInterface *self,
226 size_t buffer_bytes);
228 int NaClReverseInterfaceOpenManifestEntry(
229 struct NaClReverseInterface *self,
231 struct NaClFileInfo *info);
233 int NaClReverseInterfaceCloseManifestEntry(
234 struct NaClReverseInterface *self,
237 void NaClReverseInterfaceReportCrash(
238 struct NaClReverseInterface *self);
240 void NaClReverseInterfaceReportExitStatus(
241 struct NaClReverseInterface *self,
244 void NaClReverseInterfaceDoPostMessage(
245 struct NaClReverseInterface *self,
247 size_t message_bytes);
249 void NaClReverseInterfaceCreateProcessFunctorResult(
250 struct NaClReverseInterface *self,
251 void (*result_functor)(void *functor_state,
252 struct NaClDesc *out_sock_addr,
253 struct NaClDesc *out_app_addr,
254 int32_t out_pid_or_errno),
255 void *functor_state);
257 void NaClReverseInterfaceFinalizeProcess(struct NaClReverseInterface *self,
260 int NaClReverseInterfaceCreateProcess(
261 struct NaClReverseInterface *self,
262 struct NaClDesc **out_sock_addr,
263 struct NaClDesc **out_app_addr);
265 int64_t NaClReverseInterfaceRequestQuotaForWrite(
266 struct NaClReverseInterface *self,
271 extern struct NaClReverseInterfaceVtbl const kNaClReverseInterfaceVtbl;
275 #endif /* NATIVE_CLIENT_SRC_TRUSTED_REVERSE_SERVICE_REVERSE_SERVICE_C_H_ */