Upstream version 7.36.149.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 Tue May  6 21:29:20 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
18 #define PPP_MANIFESTSERVICE_INTERFACE_1_0 "PPP_ManifestService;1.0"
19 #define PPP_MANIFESTSERVICE_INTERFACE PPP_MANIFESTSERVICE_INTERFACE_1_0
20
21 #define PPB_NACL_PRIVATE_INTERFACE_1_0 "PPB_NaCl_Private;1.0"
22 #define PPB_NACL_PRIVATE_INTERFACE PPB_NACL_PRIVATE_INTERFACE_1_0
23
24 /**
25  * @file
26  * This file contains NaCl private interfaces. This interface is not versioned
27  * and is for internal Chrome use. It may change without notice. */
28
29
30 #include "ppapi/c/private/pp_file_handle.h"
31 #include "ppapi/c/private/ppb_instance_private.h"
32
33 /**
34  * @addtogroup Enums
35  * @{
36  */
37 /** NaCl-specific errors that should be reported to the user.
38  *  These error codes are reported via UMA so, if you edit them:
39  *   1) make sure you understand UMA first.
40  *   2) update src/tools/metrics/histograms/histograms.xml
41  *  Values are explicitly specified to make sure they don't shift around when
42  *  edited, and also to make reading about:histograms easier.
43  */
44 typedef enum {
45   PP_NACL_ERROR_LOAD_SUCCESS = 0,
46   PP_NACL_ERROR_LOAD_ABORTED = 1,
47   PP_NACL_ERROR_UNKNOWN = 2,
48   PP_NACL_ERROR_MANIFEST_RESOLVE_URL = 3,
49   PP_NACL_ERROR_MANIFEST_LOAD_URL = 4,
50   PP_NACL_ERROR_MANIFEST_STAT = 5,
51   PP_NACL_ERROR_MANIFEST_TOO_LARGE = 6,
52   PP_NACL_ERROR_MANIFEST_OPEN = 7,
53   PP_NACL_ERROR_MANIFEST_MEMORY_ALLOC = 8,
54   PP_NACL_ERROR_MANIFEST_READ = 9,
55   PP_NACL_ERROR_MANIFEST_PARSING = 10,
56   PP_NACL_ERROR_MANIFEST_SCHEMA_VALIDATE = 11,
57   PP_NACL_ERROR_MANIFEST_GET_NEXE_URL = 12,
58   PP_NACL_ERROR_NEXE_LOAD_URL = 13,
59   PP_NACL_ERROR_NEXE_ORIGIN_PROTOCOL = 14,
60   PP_NACL_ERROR_NEXE_FH_DUP = 15,
61   PP_NACL_ERROR_NEXE_STAT = 16,
62   PP_NACL_ERROR_ELF_CHECK_IO = 17,
63   PP_NACL_ERROR_ELF_CHECK_FAIL = 18,
64   PP_NACL_ERROR_SEL_LDR_INIT = 19,
65   PP_NACL_ERROR_SEL_LDR_CREATE_LAUNCHER = 20,
66   PP_NACL_ERROR_SEL_LDR_FD = 21,
67   PP_NACL_ERROR_SEL_LDR_LAUNCH = 22,
68   /* Deprecated, safe to reuse the value because it's never logged in UMA.
69    */
70   PP_NACL_ERROR_SEL_LDR_SEND_NEXE = 24,
71   PP_NACL_ERROR_SEL_LDR_HANDLE_PASSING = 25,
72   PP_NACL_ERROR_SEL_LDR_START_MODULE = 26,
73   PP_NACL_ERROR_SEL_LDR_START_STATUS = 27,
74   PP_NACL_ERROR_SRPC_CONNECTION_FAIL = 28,
75   PP_NACL_ERROR_START_PROXY_CHECK_PPP = 29,
76   PP_NACL_ERROR_START_PROXY_ALLOC = 30,
77   PP_NACL_ERROR_START_PROXY_MODULE = 31,
78   PP_NACL_ERROR_START_PROXY_INSTANCE = 32,
79   PP_NACL_ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL = 33,
80   PP_NACL_ERROR_SEL_LDR_COMMUNICATION_REV_SETUP = 34,
81   PP_NACL_ERROR_SEL_LDR_COMMUNICATION_WRAPPER = 35,
82   PP_NACL_ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE = 36,
83   PP_NACL_ERROR_START_PROXY_CRASH = 37,
84   PP_NACL_ERROR_MANIFEST_PROGRAM_MISSING_ARCH = 38,
85   PP_NACL_ERROR_PNACL_CACHE_OPEN_INPROGRESS = 39,
86   PP_NACL_ERROR_PNACL_CACHE_OPEN_NOACCESS = 40,
87   PP_NACL_ERROR_PNACL_CACHE_OPEN_NOQUOTA = 41,
88   PP_NACL_ERROR_PNACL_CACHE_OPEN_NOSPACE = 42,
89   PP_NACL_ERROR_PNACL_CACHE_OPEN_OTHER = 43,
90   PP_NACL_ERROR_PNACL_CACHE_DIRECTORY_CREATE = 44,
91   PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOACCESS = 45,
92   PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOQUOTA = 46,
93   PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOSPACE = 47,
94   PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOTAFILE = 48,
95   PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_OTHER = 49,
96   PP_NACL_ERROR_PNACL_CACHE_FETCH_NOACCESS = 50,
97   PP_NACL_ERROR_PNACL_CACHE_FETCH_NOTFOUND = 51,
98   PP_NACL_ERROR_PNACL_CACHE_FETCH_OTHER = 52,
99   PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_NOQUOTA = 53,
100   PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_NOSPACE = 54,
101   PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_OTHER = 55,
102   PP_NACL_ERROR_PNACL_CACHE_FINALIZE_RENAME_NOACCESS = 56,
103   PP_NACL_ERROR_PNACL_CACHE_FINALIZE_RENAME_OTHER = 57,
104   PP_NACL_ERROR_PNACL_RESOURCE_FETCH = 58,
105   PP_NACL_ERROR_PNACL_PEXE_FETCH_ABORTED = 59,
106   PP_NACL_ERROR_PNACL_PEXE_FETCH_NOACCESS = 60,
107   PP_NACL_ERROR_PNACL_PEXE_FETCH_OTHER = 61,
108   PP_NACL_ERROR_PNACL_THREAD_CREATE = 62,
109   PP_NACL_ERROR_PNACL_LLC_SETUP = 63,
110   PP_NACL_ERROR_PNACL_LD_SETUP = 64,
111   PP_NACL_ERROR_PNACL_LLC_INTERNAL = 65,
112   PP_NACL_ERROR_PNACL_LD_INTERNAL = 66,
113   PP_NACL_ERROR_PNACL_CREATE_TEMP = 67,
114   /* This entry is no longer used, but should not be removed, because UMA
115    */
116   PP_NACL_ERROR_PNACL_NOT_ENABLED = 68,
117   PP_NACL_ERROR_MANIFEST_NOACCESS_URL = 69,
118   PP_NACL_ERROR_NEXE_NOACCESS_URL = 70,
119   PP_NACL_ERROR_PNACL_CRASH_THROTTLED = 71,
120   /* If you add a code, read the enum comment above on how to update
121    */
122   PP_NACL_ERROR_MAX
123 } PP_NaClError;
124
125 /** Event types that NaCl may use when reporting load progress or errors. */
126 typedef enum {
127   PP_NACL_EVENT_LOADSTART,
128   PP_NACL_EVENT_PROGRESS,
129   PP_NACL_EVENT_ERROR,
130   PP_NACL_EVENT_ABORT,
131   PP_NACL_EVENT_LOAD,
132   PP_NACL_EVENT_LOADEND,
133   PP_NACL_EVENT_CRASH
134 } PP_NaClEventType;
135
136 typedef enum {
137   PP_SCHEME_CHROME_EXTENSION,
138   PP_SCHEME_DATA,
139   PP_SCHEME_OTHER
140 } PP_UrlSchemeType;
141
142 typedef enum {
143   /* The trusted plugin begins in this ready state. */
144   PP_NACL_READY_STATE_UNSENT = 0,
145   /* The manifest file has been requested, but not yet received. */
146   PP_NACL_READY_STATE_OPENED = 1,
147   /* The manifest file has been received and the nexe successfully requested. */
148   PP_NACL_READY_STATE_LOADING = 3,
149   /* The nexe has been loaded and the proxy started, so it is ready for
150    */
151   PP_NACL_READY_STATE_DONE = 4
152 } PP_NaClReadyState;
153 /**
154  * @}
155  */
156
157 /**
158  * @addtogroup Structs
159  * @{
160  */
161 struct PP_PNaClOptions {
162   PP_Bool translate;
163   PP_Bool is_debug;
164   int32_t opt_level;
165 };
166 /**
167  * @}
168  */
169
170 /**
171  * @addtogroup Typedefs
172  * @{
173  */
174 /* Callback invoked upon completion of PPP_ManifestService::OpenResource(). */
175 typedef void (*PP_OpenResourceCompletionCallback)(void* user_data,
176                                                   PP_FileHandle file_handle);
177 /**
178  * @}
179  */
180
181 /**
182  * @addtogroup Interfaces
183  * @{
184  */
185 /* ManifestService to support irt_open_resource() function.
186  * All functions of the service should have PP_Bool return value. It represents
187  * whether the service is still alive or not. Trivially Quit() should always
188  * return false. However, other functions also can return false.
189  * Once false is called, as the service has been destructed, all functions
190  * should never be called afterwords.
191  */
192 struct PPP_ManifestService_1_0 {
193   /* Called when ManifestService should be destructed. */
194   PP_Bool (*Quit)(void* user_data);
195   /* Called when PPAPI initialization in the NaCl plugin is finished. */
196   PP_Bool (*StartupInitializationComplete)(void* user_data);
197   /* Called when irt_open_resource() is invoked in the NaCl plugin.
198    * Upon completion, callback will be invoked with given callback_user_data
199    * and the result file handle (or PP_kInvalidFileHandle on error). */
200   PP_Bool (*OpenResource)(void* user_data,
201                           const char* entry_key,
202                           PP_OpenResourceCompletionCallback callback,
203                           void* callback_user_data);
204 };
205
206 typedef struct PPP_ManifestService_1_0 PPP_ManifestService;
207
208 /* PPB_NaCl_Private */
209 struct PPB_NaCl_Private_1_0 {
210   /* Launches NaCl's sel_ldr process.  Returns PP_EXTERNAL_PLUGIN_OK on success
211    * and writes a NaClHandle to imc_handle. Returns PP_EXTERNAL_PLUGIN_FAILED on
212    * failure. The |enable_ppapi_dev| parameter controls whether GetInterface
213    * returns 'Dev' interfaces to the NaCl plugin.  The |uses_ppapi| flag
214    * indicates that the nexe run by sel_ldr will use the PPAPI APIs.
215    * This implies that LaunchSelLdr is run from the main thread.  If a nexe
216    * does not need PPAPI, then it can run off the main thread.
217    * The |uses_irt| flag indicates whether the IRT should be loaded in this
218    * NaCl process.  This is true for ABI stable nexes.
219    * The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
220    * be used with the binary pointed by the url.
221    * The |enable_dyncode_syscalls| flag indicates whether or not the nexe
222    * will be able to use dynamic code system calls (e.g., mmap with PROT_EXEC).
223    * The |enable_exception_handling| flag indicates whether or not the nexe
224    * will be able to use hardware exception handling.
225    * The |enable_crash_throttling| flag indicates whether or not crashes of
226    * the nexe contribute to crash throttling statisics and whether nexe starts
227    * are throttled by crash throttling.
228    */
229   void (*LaunchSelLdr)(
230       PP_Instance instance,
231       const char* alleged_url,
232       PP_Bool uses_irt,
233       PP_Bool uses_ppapi,
234       PP_Bool uses_nonsfi_mode,
235       PP_Bool enable_ppapi_dev,
236       PP_Bool enable_dyncode_syscalls,
237       PP_Bool enable_exception_handling,
238       PP_Bool enable_crash_throttling,
239       const struct PPP_ManifestService_1_0* manifest_service_interface,
240       void* manifest_service_user_data,
241       void* imc_handle,
242       struct PP_Var* error_message,
243       struct PP_CompletionCallback callback);
244   /* This function starts the IPC proxy so the nexe can communicate with the
245    * browser.
246    */
247   PP_Bool (*StartPpapiProxy)(PP_Instance instance);
248   /* On POSIX systems, this function returns the file descriptor of
249    * /dev/urandom.  On non-POSIX systems, this function returns 0.
250    */
251   int32_t (*UrandomFD)(void);
252   /* Whether the Pepper 3D interfaces should be disabled in the NaCl PPAPI
253    * proxy. This is so paranoid admins can effectively prevent untrusted shader
254    * code to be processed by the graphics stack.
255    */
256   PP_Bool (*Are3DInterfacesDisabled)(void);
257   /* This is Windows-specific.  This is a replacement for DuplicateHandle() for
258    * use inside the Windows sandbox.  Note that we provide this via dependency
259    * injection only to avoid the linkage problems that occur because the NaCl
260    * plugin is built as a separate DLL/DSO
261    * (see http://code.google.com/p/chromium/issues/detail?id=114439#c8).
262    */
263   int32_t (*BrokerDuplicateHandle)(PP_FileHandle source_handle,
264                                    uint32_t process_id,
265                                    PP_FileHandle* target_handle,
266                                    uint32_t desired_access,
267                                    uint32_t options);
268   /* Returns a read-only file descriptor of a file rooted in the Pnacl
269    * component directory, or an invalid handle on failure.
270    */
271   PP_FileHandle (*GetReadonlyPnaclFd)(const char* filename);
272   /* This creates a temporary file that will be deleted by the time
273    * the last handle is closed (or earlier on POSIX systems), and
274    * returns a posix handle to that temporary file.
275    */
276   PP_FileHandle (*CreateTemporaryFile)(PP_Instance instance);
277   /* Return the number of processors in the system as reported by the OS */
278   int32_t (*GetNumberOfProcessors)(void);
279   /* Return whether the non-SFI mode is enabled. */
280   PP_Bool (*IsNonSFIModeEnabled)(void);
281   /* Create a temporary file, which will be deleted by the time the
282    * last handle is closed (or earlier on POSIX systems), to use for
283    * the nexe with the cache information given by |pexe_url|,
284    * |abi_version|, |opt_level|, and |headers|.  If the nexe is already present
285    * in the cache, |is_hit| is set to PP_TRUE and the contents of the nexe will
286    * be copied into the temporary file. Otherwise |is_hit| is set to PP_FALSE
287    * and the temporary file will be writeable.  Currently the implementation is
288    * a stub, which always sets is_hit to false and calls the implementation of
289    * CreateTemporaryFile. In a subsequent CL it will call into the browser
290    * which will remember the association between the cache key and the fd, and
291    * copy the nexe into the cache after the translation finishes.
292    */
293   int32_t (*GetNexeFd)(PP_Instance instance,
294                        const char* pexe_url,
295                        uint32_t abi_version,
296                        uint32_t opt_level,
297                        const char* headers,
298                        const char* extra_flags,
299                        PP_Bool* is_hit,
300                        PP_FileHandle* nexe_handle,
301                        struct PP_CompletionCallback callback);
302   /* Report to the browser that translation of the pexe for |instance|
303    * has finished, or aborted with an error. If |success| is true, the
304    * browser may then store the translation in the cache. The renderer
305    * must first have called GetNexeFd for the same instance. (The browser is
306    * not guaranteed to store the nexe even if |success| is true; if there is
307    * an error on the browser side, or the file is too big for the cache, or
308    * the browser is in incognito mode, no notification will be delivered to
309    * the plugin.)
310    */
311   void (*ReportTranslationFinished)(PP_Instance instance, PP_Bool success);
312   /* Opens a NaCl executable file in the application's extension directory
313    * corresponding to the file URL and returns a file descriptor, or an invalid
314    * handle on failure. |metadata| is left unchanged on failure.
315    */
316   PP_FileHandle (*OpenNaClExecutable)(PP_Instance instance,
317                                       const char* file_url,
318                                       uint64_t* file_token_lo,
319                                       uint64_t* file_token_hi);
320   /* Dispatch a progress event on the DOM element where the given instance is
321    * embedded.
322    */
323   void (*DispatchEvent)(PP_Instance instance,
324                         PP_NaClEventType event_type,
325                         const char* resource_url,
326                         PP_Bool length_is_computable,
327                         uint64_t loaded_bytes,
328                         uint64_t total_bytes);
329   /* Report that the attempt to open the nexe has finished. Opening the file
330    * may have failed, as indicated by a pp_error value that is not PP_OK or an
331    * fd of -1. Failure to stat the file to determine its length results in
332    * nexe_bytes_read being -1.
333    */
334   void (*NexeFileDidOpen)(PP_Instance instance,
335                           int32_t pp_error,
336                           int32_t fd,
337                           int32_t http_status,
338                           int64_t nexe_bytes_read,
339                           const char* url,
340                           int64_t time_since_open);
341   /* Report that the nexe loaded successfully. */
342   void (*ReportLoadSuccess)(PP_Instance instance,
343                             const char* url,
344                             uint64_t loaded_bytes,
345                             uint64_t total_bytes);
346   /* Report an error that occured while attempting to load a nexe. */
347   void (*ReportLoadError)(PP_Instance instance,
348                           PP_NaClError error,
349                           const char* error_message,
350                           const char* console_message);
351   /* Reports that loading a nexe was aborted. */
352   void (*ReportLoadAbort)(PP_Instance instance);
353   /* Reports that the nexe has crashed. */
354   void (*NexeDidCrash)(PP_Instance instance, const char* crash_log);
355   /* Performs internal setup when an instance is created. */
356   void (*InstanceCreated)(PP_Instance instance);
357   /* Performs internal cleanup when an instance is destroyed. */
358   void (*InstanceDestroyed)(PP_Instance instance);
359   /* Return true if the NaCl debug stub is enabled and the app loaded from
360    * alleged_nmf_url will be attached to a debugger.
361    */
362   PP_Bool (*NaClDebugEnabledForURL)(const char* alleged_nmf_url);
363   /* Returns the kind of SFI sandbox implemented by NaCl on this
364    * platform.
365    */
366   const char* (*GetSandboxArch)(void);
367   /* Logs the message to the console. */
368   void (*LogToConsole)(PP_Instance instance, const char* message);
369   /* Returns the NaCl readiness status for this instance. */
370   PP_NaClReadyState (*GetNaClReadyState)(PP_Instance instance);
371   /* Returns true if the plugin is an installed app. */
372   PP_Bool (*GetIsInstalled)(PP_Instance instance);
373   /* Returns the exit status of the plugin process. */
374   int32_t (*GetExitStatus)(PP_Instance instance);
375   /* Sets the exit status of the plugin process. */
376   void (*SetExitStatus)(PP_Instance instance, int32_t exit_status);
377   /* Logs the message via VLOG. */
378   void (*Vlog)(const char* message);
379   /* Initializes internal state for a NaCl plugin. */
380   void (*InitializePlugin)(PP_Instance instance,
381                            uint32_t argc,
382                            const char* argn[],
383                            const char* argv[]);
384   /* Returns the size of the nexe. */
385   int64_t (*GetNexeSize)(PP_Instance instance);
386   /* Performs accounting for requesting the NaCl manifest at the given URL. */
387   PP_Bool (*RequestNaClManifest)(PP_Instance instance,
388                                  const char* manifest_url,
389                                  PP_Bool* is_data_uri);
390   struct PP_Var (*GetManifestBaseURL)(PP_Instance instance);
391   PP_Bool (*ResolvesRelativeToPluginBaseUrl)(PP_Instance instance,
392                                              const char* url);
393   /* Returns the parsed contents of a data URL. */
394   struct PP_Var (*ParseDataURL)(const char* data_url);
395   /* Processes the NaCl manifest once it's been retrieved.
396    * TODO(teravest): Move the rest of the supporting logic out of the trusted
397    * plugin.
398    */
399   void (*ProcessNaClManifest)(PP_Instance instance, const char* program_url);
400   /* Returns the manifest url as passed as a plugin argument. */
401   struct PP_Var (*GetManifestURLArgument)(PP_Instance instance);
402   PP_Bool (*IsPNaCl)(PP_Instance instance);
403   PP_Bool (*DevInterfacesEnabled)(PP_Instance instance);
404   /* Downloads the manifest into the buffer |data|, invoking
405    * |callback| when finished.
406    * TODO(teravest): Merge data URL parsing into this. */
407   void (*DownloadManifestToBuffer)(PP_Instance instance,
408                                    struct PP_Var* data,
409                                    struct PP_CompletionCallback callback);
410   int32_t (*CreatePnaclManifest)(PP_Instance instance);
411   int32_t (*CreateJsonManifest)(PP_Instance instance,
412                                 const char* manifest_base_url,
413                                 const char* sandbox_isa,
414                                 const char* manifest_data);
415   void (*DestroyManifest)(PP_Instance instance, int32_t manifest_id);
416   PP_Bool (*GetManifestProgramURL)(PP_Instance instance,
417                                    int32_t manifest_id,
418                                    struct PP_Var* full_url,
419                                    struct PP_PNaClOptions* pnacl_options,
420                                    PP_Bool* uses_nonsfi_mode);
421   PP_Bool (*ManifestResolveKey)(PP_Instance instance,
422                                 int32_t manifest_id,
423                                 const char* key,
424                                 struct PP_Var* full_url,
425                                 struct PP_PNaClOptions* pnacl_options);
426   /* Returns the filenames for the llc and ld tools, parsing that information
427    * from the file given in |filename|.
428    */
429   PP_Bool (*GetPnaclResourceInfo)(PP_Instance instance,
430                                   const char* filename,
431                                   struct PP_Var* llc_tool_name,
432                                   struct PP_Var* ld_tool_name);
433   /* PP_Var string of attributes describing the CPU features supported
434    * by the current architecture. The string is a comma-delimited list
435    * of attributes supported by LLVM in its -mattr= option:
436    *   http://llvm.org/docs/CommandGuide/llc.html#cmdoption-mattr */
437   struct PP_Var (*GetCpuFeatureAttrs)(void);
438 };
439
440 typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private;
441 /**
442  * @}
443  */
444
445 #endif  /* PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ */
446