Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ppapi / c / private / ppb_nacl_private.h
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 Wed Oct  1 15:54:15 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  */
42 typedef 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. */
124 typedef 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
134 typedef enum {
135   PP_SCHEME_CHROME_EXTENSION,
136   PP_SCHEME_DATA,
137   PP_SCHEME_OTHER
138 } PP_UrlSchemeType;
139
140 typedef 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 /** Types of untrusted NaCl processes. Mirrors NaClAppProcessType from
153  *  components/nacl/common/nacl_types.h.
154  */
155 typedef enum {
156   PP_UNKNOWN_NACL_PROCESS_TYPE,
157   PP_NATIVE_NACL_PROCESS_TYPE,
158   PP_PNACL_PROCESS_TYPE,
159   PP_PNACL_TRANSLATOR_PROCESS_TYPE,
160   PP_NUM_NACL_PROCESS_TYPES
161 } PP_NaClAppProcessType;
162 /**
163  * @}
164  */
165
166 /**
167  * @addtogroup Structs
168  * @{
169  */
170 struct PP_PNaClOptions {
171   PP_Bool translate;
172   PP_Bool is_debug;
173   int32_t opt_level;
174 };
175 /**
176  * @}
177  */
178
179 /**
180  * @addtogroup Typedefs
181  * @{
182  */
183 /* Callback invoked upon completion of PPP_ManifestService::OpenResource(). */
184 typedef void (*PP_OpenResourceCompletionCallback)(void* user_data,
185                                                   PP_FileHandle file_handle);
186 /**
187  * @}
188  */
189
190 /**
191  * @addtogroup Structs
192  * @{
193  */
194 /* Corresponds to NaClFileInfo in
195  * native_client/src/trusted/validator/nacl_file_info.h */
196 struct PP_NaClFileInfo {
197   PP_FileHandle handle;
198   /* See NaClFileToken comment in nacl_file_info.h */
199   uint64_t token_lo;
200   uint64_t token_hi;
201 };
202 /**
203  * @}
204  */
205
206 /**
207  * @addtogroup Interfaces
208  * @{
209  */
210 /* PPB_NaCl_Private */
211 struct PPB_NaCl_Private_1_0 {
212   /* Launches NaCl's sel_ldr process.  Returns PP_EXTERNAL_PLUGIN_OK on success
213    * and writes a NaClHandle to imc_handle. Returns PP_EXTERNAL_PLUGIN_FAILED on
214    * failure. The |enable_ppapi_dev| parameter controls whether GetInterface
215    * returns 'Dev' interfaces to the NaCl plugin.
216    * The |nexe_file_info| is currently used only in non-SFI mode. It is the
217    * file handle for the main nexe file, which should be initially loaded.
218    * LaunchSelLdr takes the ownership of the file handle.
219    * The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
220    * be used with the binary pointed by the url.
221    */
222   void (*LaunchSelLdr)(PP_Instance instance,
223                        PP_Bool main_service_runtime,
224                        const char* alleged_url,
225                        const struct PP_NaClFileInfo* nexe_file_info,
226                        PP_Bool uses_nonsfi_mode,
227                        PP_Bool enable_ppapi_dev,
228                        PP_NaClAppProcessType process_type,
229                        void* imc_handle,
230                        struct PP_CompletionCallback callback);
231   /* This function starts the IPC proxy so the nexe can communicate with the
232    * browser.
233    */
234   PP_Bool (*StartPpapiProxy)(PP_Instance instance);
235   /* On POSIX systems, this function returns the file descriptor of
236    * /dev/urandom.  On non-POSIX systems, this function returns 0.
237    */
238   int32_t (*UrandomFD)(void);
239   /* Whether the Pepper 3D interfaces should be disabled in the NaCl PPAPI
240    * proxy. This is so paranoid admins can effectively prevent untrusted shader
241    * code to be processed by the graphics stack.
242    */
243   PP_Bool (*Are3DInterfacesDisabled)(void);
244   /* This is Windows-specific.  This is a replacement for DuplicateHandle() for
245    * use inside the Windows sandbox.  Note that we provide this via dependency
246    * injection only to avoid the linkage problems that occur because the NaCl
247    * plugin is built as a separate DLL/DSO
248    * (see http://code.google.com/p/chromium/issues/detail?id=114439#c8).
249    */
250   int32_t (*BrokerDuplicateHandle)(PP_FileHandle source_handle,
251                                    uint32_t process_id,
252                                    PP_FileHandle* target_handle,
253                                    uint32_t desired_access,
254                                    uint32_t options);
255   /* Returns a read-only (but executable) file descriptor / file info for
256    * a url for pnacl translator tools. Returns an invalid handle on failure.
257    */
258   void (*GetReadExecPnaclFd)(const char* url,
259                              struct PP_NaClFileInfo* out_file_info);
260   /* This creates a temporary file that will be deleted by the time
261    * the last handle is closed (or earlier on POSIX systems), and
262    * returns a posix handle to that temporary file.
263    */
264   PP_FileHandle (*CreateTemporaryFile)(PP_Instance instance);
265   /* Return the number of processors in the system as reported by the OS */
266   int32_t (*GetNumberOfProcessors)(void);
267   /* Return whether the non-SFI mode is enabled. */
268   PP_Bool (*IsNonSFIModeEnabled)(void);
269   /* Report to the browser that translation of the pexe for |instance|
270    * has finished, or aborted with an error. If |success| is true, the
271    * browser may then store the translation in the cache. The renderer
272    * must first have called GetNexeFd for the same instance. (The browser is
273    * not guaranteed to store the nexe even if |success| is true; if there is
274    * an error on the browser side, or the file is too big for the cache, or
275    * the browser is in incognito mode, no notification will be delivered to
276    * the plugin.)
277    */
278   void (*ReportTranslationFinished)(PP_Instance instance,
279                                     PP_Bool success,
280                                     int32_t opt_level,
281                                     int64_t pexe_size,
282                                     int64_t compile_time_us);
283   /* Dispatch a progress event on the DOM element where the given instance is
284    * embedded.
285    */
286   void (*DispatchEvent)(PP_Instance instance,
287                         PP_NaClEventType event_type,
288                         const char* resource_url,
289                         PP_Bool length_is_computable,
290                         uint64_t loaded_bytes,
291                         uint64_t total_bytes);
292   /* Report that the nexe loaded successfully. */
293   void (*ReportLoadSuccess)(PP_Instance instance,
294                             uint64_t loaded_bytes,
295                             uint64_t total_bytes);
296   /* Report an error that occured while attempting to load a nexe. */
297   void (*ReportLoadError)(PP_Instance instance,
298                           PP_NaClError error,
299                           const char* error_message);
300   /* Reports that loading a nexe was aborted. */
301   void (*ReportLoadAbort)(PP_Instance instance);
302   /* Performs internal setup when an instance is created. */
303   void (*InstanceCreated)(PP_Instance instance);
304   /* Performs internal cleanup when an instance is destroyed. */
305   void (*InstanceDestroyed)(PP_Instance instance);
306   /* Return true if the NaCl debug stub is enabled and the app loaded from
307    * alleged_nmf_url will be attached to a debugger.
308    */
309   PP_Bool (*NaClDebugEnabledForURL)(const char* alleged_nmf_url);
310   /* Returns the kind of SFI sandbox implemented by NaCl on this
311    * platform.
312    */
313   const char* (*GetSandboxArch)(void);
314   /* Logs the message to the console. */
315   void (*LogToConsole)(PP_Instance instance, const char* message);
316   /* Returns the NaCl readiness status for this instance. */
317   PP_NaClReadyState (*GetNaClReadyState)(PP_Instance instance);
318   /* Logs the message via VLOG. */
319   void (*Vlog)(const char* message);
320   /* Initializes internal state for a NaCl plugin. */
321   void (*InitializePlugin)(PP_Instance instance,
322                            uint32_t argc,
323                            const char* argn[],
324                            const char* argv[]);
325   /* Returns the size of the nexe. */
326   int64_t (*GetNexeSize)(PP_Instance instance);
327   /* Requests the NaCl manifest specified in the plugin arguments. */
328   void (*RequestNaClManifest)(PP_Instance instance,
329                               struct PP_CompletionCallback callback);
330   struct PP_Var (*GetManifestBaseURL)(PP_Instance instance);
331   /* Processes the NaCl manifest once it's been retrieved.
332    * TODO(teravest): Move the rest of the supporting logic out of the trusted
333    * plugin.
334    */
335   void (*ProcessNaClManifest)(PP_Instance instance, const char* program_url);
336   PP_Bool (*DevInterfacesEnabled)(PP_Instance instance);
337   PP_Bool (*GetManifestProgramURL)(PP_Instance instance,
338                                    struct PP_Var* full_url,
339                                    struct PP_PNaClOptions* pnacl_options,
340                                    PP_Bool* uses_nonsfi_mode);
341   /* Returns the filenames for the llc and ld tools. */
342   PP_Bool (*GetPnaclResourceInfo)(PP_Instance instance,
343                                   struct PP_Var* llc_tool_name,
344                                   struct PP_Var* ld_tool_name);
345   /* PP_Var string of attributes describing the CPU features supported
346    * by the current architecture. The string is a comma-delimited list
347    * of attributes supported by LLVM in its -mattr= option:
348    *   http://llvm.org/docs/CommandGuide/llc.html#cmdoption-mattr */
349   struct PP_Var (*GetCpuFeatureAttrs)(void);
350   /* Downloads the .nexe file at the given URL to a file, and sets |file_info|
351    * to information for a handle to a file containing its contents.
352    * If metadata for identity-based validation caching is available
353    * then it sets token information in |file_info| (otherwise left untouched).
354    */
355   void (*DownloadNexe)(PP_Instance instance,
356                        const char* url,
357                        struct PP_NaClFileInfo* file_info,
358                        struct PP_CompletionCallback callback);
359   /* Reports the status of sel_ldr for UMA reporting.
360    * |max_status| has to be provided because the implementation of this
361    * interface can't access the NaClErrorCode enum.
362    */
363   void (*ReportSelLdrStatus)(PP_Instance instance,
364                              int32_t load_status,
365                              int32_t max_status);
366   /* Logs time taken by an operation to UMA histograms.
367    * This function is safe to call on any thread.
368    */
369   void (*LogTranslateTime)(const char* histogram_name, int64_t time_us);
370   /* Opens a manifest entry for the given instance. If this is for a helper
371    * process, we consult our internal pnacl.json instead of the user-supplied
372    * NMF.
373    * Fails for files which require PNaCl translation.
374    */
375   void (*OpenManifestEntry)(PP_Instance instance,
376                             PP_Bool is_helper_process,
377                             const char* key,
378                             struct PP_NaClFileInfo* file_info,
379                             struct PP_CompletionCallback callback);
380   /* Sets the start time for PNaCl downloading and translation to the current
381    * time.
382    */
383   void (*SetPNaClStartTime)(PP_Instance instance);
384   /* Downloads and streams a pexe file for PNaCl translation.
385    * Fetches the content at |pexe_url| for the given instance and opt_level.
386    * If a translated cached nexe is already available, |cache_hit_handle|
387    * is set and |cache_hit_callback| is called.
388    * Otherwise, |stream_callback| is called repeatedly with blocks of data
389    * as they are received. |stream_finished_callback| is called after all
390    * data has been received and dispatched to |stream_callback|.
391    */
392   void (*StreamPexe)(PP_Instance instance,
393                      const char* pexe_url,
394                      int32_t opt_level,
395                      const struct PPP_PexeStreamHandler_1_0* stream_handler,
396                      void* stream_handler_user_data);
397 };
398
399 typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private;
400 /**
401  * @}
402  */
403
404 #endif  /* PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ */
405