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
6/* From private/ppb_nacl_private.idl modified Thu Sep  4 07:46:02 2014. */
7
8#ifndef PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_
9#define PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_
10
11#include "ppapi/c/pp_bool.h"
12#include "ppapi/c/pp_completion_callback.h"
13#include "ppapi/c/pp_instance.h"
14#include "ppapi/c/pp_macros.h"
15#include "ppapi/c/pp_stdint.h"
16#include "ppapi/c/pp_var.h"
17#include "ppapi/c/private/ppp_pexe_stream_handler.h"
18
19#define PPB_NACL_PRIVATE_INTERFACE_1_0 "PPB_NaCl_Private;1.0"
20#define PPB_NACL_PRIVATE_INTERFACE PPB_NACL_PRIVATE_INTERFACE_1_0
21
22/**
23 * @file
24 * This file contains NaCl private interfaces. This interface is not versioned
25 * and is for internal Chrome use. It may change without notice. */
26
27
28#include "ppapi/c/private/pp_file_handle.h"
29#include "ppapi/c/private/ppb_instance_private.h"
30
31/**
32 * @addtogroup Enums
33 * @{
34 */
35/** NaCl-specific errors that should be reported to the user.
36 *  These error codes are reported via UMA so, if you edit them:
37 *   1) make sure you understand UMA first.
38 *   2) update src/tools/metrics/histograms/histograms.xml
39 *  Values are explicitly specified to make sure they don't shift around when
40 *  edited, and also to make reading about:histograms easier.
41 */
42typedef enum {
43  PP_NACL_ERROR_LOAD_SUCCESS = 0,
44  PP_NACL_ERROR_LOAD_ABORTED = 1,
45  PP_NACL_ERROR_UNKNOWN = 2,
46  PP_NACL_ERROR_MANIFEST_RESOLVE_URL = 3,
47  PP_NACL_ERROR_MANIFEST_LOAD_URL = 4,
48  PP_NACL_ERROR_MANIFEST_STAT = 5,
49  PP_NACL_ERROR_MANIFEST_TOO_LARGE = 6,
50  PP_NACL_ERROR_MANIFEST_OPEN = 7,
51  PP_NACL_ERROR_MANIFEST_MEMORY_ALLOC = 8,
52  PP_NACL_ERROR_MANIFEST_READ = 9,
53  PP_NACL_ERROR_MANIFEST_PARSING = 10,
54  PP_NACL_ERROR_MANIFEST_SCHEMA_VALIDATE = 11,
55  PP_NACL_ERROR_MANIFEST_GET_NEXE_URL = 12,
56  PP_NACL_ERROR_NEXE_LOAD_URL = 13,
57  PP_NACL_ERROR_NEXE_ORIGIN_PROTOCOL = 14,
58  PP_NACL_ERROR_NEXE_FH_DUP = 15,
59  PP_NACL_ERROR_NEXE_STAT = 16,
60  PP_NACL_ERROR_ELF_CHECK_IO = 17,
61  PP_NACL_ERROR_ELF_CHECK_FAIL = 18,
62  PP_NACL_ERROR_SEL_LDR_INIT = 19,
63  PP_NACL_ERROR_SEL_LDR_CREATE_LAUNCHER = 20,
64  PP_NACL_ERROR_SEL_LDR_FD = 21,
65  PP_NACL_ERROR_SEL_LDR_LAUNCH = 22,
66  /* Deprecated, safe to reuse the value because it's never logged in UMA.
67   */
68  PP_NACL_ERROR_SEL_LDR_SEND_NEXE = 24,
69  PP_NACL_ERROR_SEL_LDR_HANDLE_PASSING = 25,
70  PP_NACL_ERROR_SEL_LDR_START_MODULE = 26,
71  PP_NACL_ERROR_SEL_LDR_START_STATUS = 27,
72  PP_NACL_ERROR_SRPC_CONNECTION_FAIL = 28,
73  PP_NACL_ERROR_START_PROXY_CHECK_PPP = 29,
74  PP_NACL_ERROR_START_PROXY_ALLOC = 30,
75  PP_NACL_ERROR_START_PROXY_MODULE = 31,
76  PP_NACL_ERROR_START_PROXY_INSTANCE = 32,
77  PP_NACL_ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL = 33,
78  PP_NACL_ERROR_SEL_LDR_COMMUNICATION_REV_SETUP = 34,
79  PP_NACL_ERROR_SEL_LDR_COMMUNICATION_WRAPPER = 35,
80  PP_NACL_ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE = 36,
81  PP_NACL_ERROR_START_PROXY_CRASH = 37,
82  PP_NACL_ERROR_MANIFEST_PROGRAM_MISSING_ARCH = 38,
83  PP_NACL_ERROR_PNACL_CACHE_OPEN_INPROGRESS = 39,
84  PP_NACL_ERROR_PNACL_CACHE_OPEN_NOACCESS = 40,
85  PP_NACL_ERROR_PNACL_CACHE_OPEN_NOQUOTA = 41,
86  PP_NACL_ERROR_PNACL_CACHE_OPEN_NOSPACE = 42,
87  PP_NACL_ERROR_PNACL_CACHE_OPEN_OTHER = 43,
88  PP_NACL_ERROR_PNACL_CACHE_DIRECTORY_CREATE = 44,
89  PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOACCESS = 45,
90  PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOQUOTA = 46,
91  PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOSPACE = 47,
92  PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOTAFILE = 48,
93  PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_OTHER = 49,
94  PP_NACL_ERROR_PNACL_CACHE_FETCH_NOACCESS = 50,
95  PP_NACL_ERROR_PNACL_CACHE_FETCH_NOTFOUND = 51,
96  PP_NACL_ERROR_PNACL_CACHE_FETCH_OTHER = 52,
97  PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_NOQUOTA = 53,
98  PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_NOSPACE = 54,
99  PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_OTHER = 55,
100  PP_NACL_ERROR_PNACL_CACHE_FINALIZE_RENAME_NOACCESS = 56,
101  PP_NACL_ERROR_PNACL_CACHE_FINALIZE_RENAME_OTHER = 57,
102  PP_NACL_ERROR_PNACL_RESOURCE_FETCH = 58,
103  PP_NACL_ERROR_PNACL_PEXE_FETCH_ABORTED = 59,
104  PP_NACL_ERROR_PNACL_PEXE_FETCH_NOACCESS = 60,
105  PP_NACL_ERROR_PNACL_PEXE_FETCH_OTHER = 61,
106  PP_NACL_ERROR_PNACL_THREAD_CREATE = 62,
107  PP_NACL_ERROR_PNACL_LLC_SETUP = 63,
108  PP_NACL_ERROR_PNACL_LD_SETUP = 64,
109  PP_NACL_ERROR_PNACL_LLC_INTERNAL = 65,
110  PP_NACL_ERROR_PNACL_LD_INTERNAL = 66,
111  PP_NACL_ERROR_PNACL_CREATE_TEMP = 67,
112  /* This entry is no longer used, but should not be removed, because UMA
113   */
114  PP_NACL_ERROR_PNACL_NOT_ENABLED = 68,
115  PP_NACL_ERROR_MANIFEST_NOACCESS_URL = 69,
116  PP_NACL_ERROR_NEXE_NOACCESS_URL = 70,
117  PP_NACL_ERROR_PNACL_CRASH_THROTTLED = 71,
118  /* If you add a code, read the enum comment above on how to update
119   */
120  PP_NACL_ERROR_MAX
121} PP_NaClError;
122
123/** Event types that NaCl may use when reporting load progress or errors. */
124typedef enum {
125  PP_NACL_EVENT_LOADSTART,
126  PP_NACL_EVENT_PROGRESS,
127  PP_NACL_EVENT_ERROR,
128  PP_NACL_EVENT_ABORT,
129  PP_NACL_EVENT_LOAD,
130  PP_NACL_EVENT_LOADEND,
131  PP_NACL_EVENT_CRASH
132} PP_NaClEventType;
133
134typedef enum {
135  PP_SCHEME_CHROME_EXTENSION,
136  PP_SCHEME_DATA,
137  PP_SCHEME_OTHER
138} PP_UrlSchemeType;
139
140typedef enum {
141  /* The trusted plugin begins in this ready state. */
142  PP_NACL_READY_STATE_UNSENT = 0,
143  /* The manifest file has been requested, but not yet received. */
144  PP_NACL_READY_STATE_OPENED = 1,
145  /* The manifest file has been received and the nexe successfully requested. */
146  PP_NACL_READY_STATE_LOADING = 3,
147  /* The nexe has been loaded and the proxy started, so it is ready for
148   */
149  PP_NACL_READY_STATE_DONE = 4
150} PP_NaClReadyState;
151/**
152 * @}
153 */
154
155/**
156 * @addtogroup Structs
157 * @{
158 */
159struct PP_PNaClOptions {
160  PP_Bool translate;
161  PP_Bool is_debug;
162  int32_t opt_level;
163};
164/**
165 * @}
166 */
167
168/**
169 * @addtogroup Typedefs
170 * @{
171 */
172/* Callback invoked upon completion of PPP_ManifestService::OpenResource(). */
173typedef void (*PP_OpenResourceCompletionCallback)(void* user_data,
174                                                  PP_FileHandle file_handle);
175/**
176 * @}
177 */
178
179/**
180 * @addtogroup Structs
181 * @{
182 */
183/* Corresponds to NaClFileInfo in
184 * native_client/src/trusted/validator/nacl_file_info.h */
185struct PP_NaClFileInfo {
186  PP_FileHandle handle;
187  /* See NaClFileToken comment in nacl_file_info.h */
188  uint64_t token_lo;
189  uint64_t token_hi;
190};
191/**
192 * @}
193 */
194
195/**
196 * @addtogroup Interfaces
197 * @{
198 */
199/* PPB_NaCl_Private */
200struct PPB_NaCl_Private_1_0 {
201  /* Launches NaCl's sel_ldr process.  Returns PP_EXTERNAL_PLUGIN_OK on success
202   * and writes a NaClHandle to imc_handle. Returns PP_EXTERNAL_PLUGIN_FAILED on
203   * failure. The |enable_ppapi_dev| parameter controls whether GetInterface
204   * returns 'Dev' interfaces to the NaCl plugin.  The |uses_ppapi| flag
205   * indicates that the nexe run by sel_ldr will use the PPAPI APIs.
206   * This implies that LaunchSelLdr is run from the main thread.  If a nexe
207   * does not need PPAPI, then it can run off the main thread.
208   * The |nexe_file_info| is currently used only in non-SFI mode. It is the
209   * file handle for the main nexe file, which should be initially loaded.
210   * LaunchSelLdr takes the ownership of the file handle.
211   * The |uses_irt| flag indicates whether the IRT should be loaded in this
212   * NaCl process.  This is true for ABI stable nexes.
213   * The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
214   * be used with the binary pointed by the url.
215   * The |enable_dyncode_syscalls| flag indicates whether or not the nexe
216   * will be able to use dynamic code system calls (e.g., mmap with PROT_EXEC).
217   * The |enable_exception_handling| flag indicates whether or not the nexe
218   * will be able to use hardware exception handling.
219   * The |enable_crash_throttling| flag indicates whether or not crashes of
220   * the nexe contribute to crash throttling statisics and whether nexe starts
221   * are throttled by crash throttling.
222   */
223  void (*LaunchSelLdr)(PP_Instance instance,
224                       PP_Bool main_service_runtime,
225                       const char* alleged_url,
226                       const struct PP_NaClFileInfo* nexe_file_info,
227                       PP_Bool uses_irt,
228                       PP_Bool uses_ppapi,
229                       PP_Bool uses_nonsfi_mode,
230                       PP_Bool enable_ppapi_dev,
231                       PP_Bool enable_dyncode_syscalls,
232                       PP_Bool enable_exception_handling,
233                       PP_Bool enable_crash_throttling,
234                       void* imc_handle,
235                       struct PP_CompletionCallback callback);
236  /* This function starts the IPC proxy so the nexe can communicate with the
237   * browser.
238   */
239  PP_Bool (*StartPpapiProxy)(PP_Instance instance);
240  /* On POSIX systems, this function returns the file descriptor of
241   * /dev/urandom.  On non-POSIX systems, this function returns 0.
242   */
243  int32_t (*UrandomFD)(void);
244  /* Whether the Pepper 3D interfaces should be disabled in the NaCl PPAPI
245   * proxy. This is so paranoid admins can effectively prevent untrusted shader
246   * code to be processed by the graphics stack.
247   */
248  PP_Bool (*Are3DInterfacesDisabled)(void);
249  /* This is Windows-specific.  This is a replacement for DuplicateHandle() for
250   * use inside the Windows sandbox.  Note that we provide this via dependency
251   * injection only to avoid the linkage problems that occur because the NaCl
252   * plugin is built as a separate DLL/DSO
253   * (see http://code.google.com/p/chromium/issues/detail?id=114439#c8).
254   */
255  int32_t (*BrokerDuplicateHandle)(PP_FileHandle source_handle,
256                                   uint32_t process_id,
257                                   PP_FileHandle* target_handle,
258                                   uint32_t desired_access,
259                                   uint32_t options);
260  /* Returns a read-only (but executable) file descriptor / file info for
261   * a url for pnacl translator tools. Returns an invalid handle on failure.
262   */
263  void (*GetReadExecPnaclFd)(const char* url,
264                             struct PP_NaClFileInfo* out_file_info);
265  /* This creates a temporary file that will be deleted by the time
266   * the last handle is closed (or earlier on POSIX systems), and
267   * returns a posix handle to that temporary file.
268   */
269  PP_FileHandle (*CreateTemporaryFile)(PP_Instance instance);
270  /* Return the number of processors in the system as reported by the OS */
271  int32_t (*GetNumberOfProcessors)(void);
272  /* Return whether the non-SFI mode is enabled. */
273  PP_Bool (*IsNonSFIModeEnabled)(void);
274  /* Report to the browser that translation of the pexe for |instance|
275   * has finished, or aborted with an error. If |success| is true, the
276   * browser may then store the translation in the cache. The renderer
277   * must first have called GetNexeFd for the same instance. (The browser is
278   * not guaranteed to store the nexe even if |success| is true; if there is
279   * an error on the browser side, or the file is too big for the cache, or
280   * the browser is in incognito mode, no notification will be delivered to
281   * the plugin.)
282   */
283  void (*ReportTranslationFinished)(PP_Instance instance,
284                                    PP_Bool success,
285                                    int32_t opt_level,
286                                    int64_t pexe_size,
287                                    int64_t compile_time_us);
288  /* Dispatch a progress event on the DOM element where the given instance is
289   * embedded.
290   */
291  void (*DispatchEvent)(PP_Instance instance,
292                        PP_NaClEventType event_type,
293                        const char* resource_url,
294                        PP_Bool length_is_computable,
295                        uint64_t loaded_bytes,
296                        uint64_t total_bytes);
297  /* Report that the nexe loaded successfully. */
298  void (*ReportLoadSuccess)(PP_Instance instance,
299                            uint64_t loaded_bytes,
300                            uint64_t total_bytes);
301  /* Report an error that occured while attempting to load a nexe. */
302  void (*ReportLoadError)(PP_Instance instance,
303                          PP_NaClError error,
304                          const char* error_message);
305  /* Reports that loading a nexe was aborted. */
306  void (*ReportLoadAbort)(PP_Instance instance);
307  /* Performs internal setup when an instance is created. */
308  void (*InstanceCreated)(PP_Instance instance);
309  /* Performs internal cleanup when an instance is destroyed. */
310  void (*InstanceDestroyed)(PP_Instance instance);
311  /* Return true if the NaCl debug stub is enabled and the app loaded from
312   * alleged_nmf_url will be attached to a debugger.
313   */
314  PP_Bool (*NaClDebugEnabledForURL)(const char* alleged_nmf_url);
315  /* Returns the kind of SFI sandbox implemented by NaCl on this
316   * platform.
317   */
318  const char* (*GetSandboxArch)(void);
319  /* Logs the message to the console. */
320  void (*LogToConsole)(PP_Instance instance, const char* message);
321  /* Returns the NaCl readiness status for this instance. */
322  PP_NaClReadyState (*GetNaClReadyState)(PP_Instance instance);
323  /* Logs the message via VLOG. */
324  void (*Vlog)(const char* message);
325  /* Initializes internal state for a NaCl plugin. */
326  void (*InitializePlugin)(PP_Instance instance,
327                           uint32_t argc,
328                           const char* argn[],
329                           const char* argv[]);
330  /* Returns the size of the nexe. */
331  int64_t (*GetNexeSize)(PP_Instance instance);
332  /* Requests the NaCl manifest specified in the plugin arguments. */
333  void (*RequestNaClManifest)(PP_Instance instance,
334                              struct PP_CompletionCallback callback);
335  struct PP_Var (*GetManifestBaseURL)(PP_Instance instance);
336  /* Processes the NaCl manifest once it's been retrieved.
337   * TODO(teravest): Move the rest of the supporting logic out of the trusted
338   * plugin.
339   */
340  void (*ProcessNaClManifest)(PP_Instance instance, const char* program_url);
341  PP_Bool (*DevInterfacesEnabled)(PP_Instance instance);
342  PP_Bool (*GetManifestProgramURL)(PP_Instance instance,
343                                   struct PP_Var* full_url,
344                                   struct PP_PNaClOptions* pnacl_options,
345                                   PP_Bool* uses_nonsfi_mode);
346  /* Returns the filenames for the llc and ld tools. */
347  PP_Bool (*GetPnaclResourceInfo)(PP_Instance instance,
348                                  struct PP_Var* llc_tool_name,
349                                  struct PP_Var* ld_tool_name);
350  /* PP_Var string of attributes describing the CPU features supported
351   * by the current architecture. The string is a comma-delimited list
352   * of attributes supported by LLVM in its -mattr= option:
353   *   http://llvm.org/docs/CommandGuide/llc.html#cmdoption-mattr */
354  struct PP_Var (*GetCpuFeatureAttrs)(void);
355  /* Downloads the .nexe file at the given URL to a file, and sets |file_info|
356   * to information for a handle to a file containing its contents.
357   * If metadata for identity-based validation caching is available
358   * then it sets token information in |file_info| (otherwise left untouched).
359   */
360  void (*DownloadNexe)(PP_Instance instance,
361                       const char* url,
362                       struct PP_NaClFileInfo* file_info,
363                       struct PP_CompletionCallback callback);
364  /* Reports the status of sel_ldr for UMA reporting.
365   * |max_status| has to be provided because the implementation of this
366   * interface can't access the NaClErrorCode enum.
367   */
368  void (*ReportSelLdrStatus)(PP_Instance instance,
369                             int32_t load_status,
370                             int32_t max_status);
371  /* Logs time taken by an operation to UMA histograms.
372   * This function is safe to call on any thread.
373   */
374  void (*LogTranslateTime)(const char* histogram_name, int64_t time_us);
375  /* Opens a manifest entry for the given instance. If this is for a helper
376   * process, we consult our internal pnacl.json instead of the user-supplied
377   * NMF.
378   * Fails for files which require PNaCl translation.
379   */
380  void (*OpenManifestEntry)(PP_Instance instance,
381                            PP_Bool is_helper_process,
382                            const char* key,
383                            struct PP_NaClFileInfo* file_info,
384                            struct PP_CompletionCallback callback);
385  /* Sets the start time for PNaCl downloading and translation to the current
386   * time.
387   */
388  void (*SetPNaClStartTime)(PP_Instance instance);
389  /* Downloads and streams a pexe file for PNaCl translation.
390   * Fetches the content at |pexe_url| for the given instance and opt_level.
391   * If a translated cached nexe is already available, |cache_hit_handle|
392   * is set and |cache_hit_callback| is called.
393   * Otherwise, |stream_callback| is called repeatedly with blocks of data
394   * as they are received. |stream_finished_callback| is called after all
395   * data has been received and dispatched to |stream_callback|.
396   */
397  void (*StreamPexe)(PP_Instance instance,
398                     const char* pexe_url,
399                     int32_t opt_level,
400                     const struct PPP_PexeStreamHandler_1_0* stream_handler,
401                     void* stream_handler_user_data);
402};
403
404typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private;
405/**
406 * @}
407 */
408
409#endif  /* PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ */
410
411