Pepper_37_C_interfaces
ppb_nacl_private.h
Go to the documentation of this file.
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 Mon Jul 28 18:16:10 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 PPB_NACL_PRIVATE_INTERFACE_1_0 "PPB_NaCl_Private;1.0"
19 #define PPB_NACL_PRIVATE_INTERFACE PPB_NACL_PRIVATE_INTERFACE_1_0
20 
21 /**
22  * @file
23  * This file contains NaCl private interfaces. This interface is not versioned
24  * and is for internal Chrome use. It may change without notice. */
25 
26 
27 #include "ppapi/c/private/pp_file_handle.h"
28 #include "ppapi/c/private/ppb_instance_private.h"
29 
30 /**
31  * @addtogroup Enums
32  * @{
33  */
34 /** NaCl-specific errors that should be reported to the user.
35  * These error codes are reported via UMA so, if you edit them:
36  * 1) make sure you understand UMA first.
37  * 2) update src/tools/metrics/histograms/histograms.xml
38  * Values are explicitly specified to make sure they don't shift around when
39  * edited, and also to make reading about:histograms easier.
40  */
41 typedef enum {
65  /* Deprecated, safe to reuse the value because it's never logged in UMA.
66  */
111  /* This entry is no longer used, but should not be removed, because UMA
112  */
117  /* If you add a code, read the enum comment above on how to update
118  */
120 } PP_NaClError;
121 
122 /** Event types that NaCl may use when reporting load progress or errors. */
123 typedef enum {
132 
133 typedef enum {
138 
139 typedef enum {
140  /* The trusted plugin begins in this ready state. */
142  /* The manifest file has been requested, but not yet received. */
144  /* The manifest file has been received and the nexe successfully requested. */
146  /* The nexe has been loaded and the proxy started, so it is ready for
147  */
150 /**
151  * @}
152  */
153 
154 /**
155  * @addtogroup Structs
156  * @{
157  */
161  int32_t opt_level;
162 };
163 /**
164  * @}
165  */
166 
167 /**
168  * @addtogroup Typedefs
169  * @{
170  */
171 /* Callback invoked upon completion of PPP_ManifestService::OpenResource(). */
172 typedef void (*PP_OpenResourceCompletionCallback)(void* user_data,
173  PP_FileHandle file_handle);
174 /**
175  * @}
176  */
177 
178 /**
179  * @addtogroup Structs
180  * @{
181  */
182 /* Corresponds to NaClFileInfo in
183  * native_client/src/trusted/validator/nacl_file_info.h */
186  /* See NaClFileToken comment in nacl_file_info.h */
187  uint64_t token_lo;
188  uint64_t token_hi;
189 };
190 /**
191  * @}
192  */
193 
194 /**
195  * @addtogroup Interfaces
196  * @{
197  */
198 /* PPB_NaCl_Private */
200  /* Launches NaCl's sel_ldr process. Returns PP_EXTERNAL_PLUGIN_OK on success
201  * and writes a NaClHandle to imc_handle. Returns PP_EXTERNAL_PLUGIN_FAILED on
202  * failure. The |enable_ppapi_dev| parameter controls whether GetInterface
203  * returns 'Dev' interfaces to the NaCl plugin. The |uses_ppapi| flag
204  * indicates that the nexe run by sel_ldr will use the PPAPI APIs.
205  * This implies that LaunchSelLdr is run from the main thread. If a nexe
206  * does not need PPAPI, then it can run off the main thread.
207  * The |nexe_file_info| is currently used only in non-SFI mode. It is the
208  * file handle for the main nexe file, which should be initially loaded.
209  * LaunchSelLdr takes the ownership of the file handle.
210  * The |uses_irt| flag indicates whether the IRT should be loaded in this
211  * NaCl process. This is true for ABI stable nexes.
212  * The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
213  * be used with the binary pointed by the url.
214  * The |enable_dyncode_syscalls| flag indicates whether or not the nexe
215  * will be able to use dynamic code system calls (e.g., mmap with PROT_EXEC).
216  * The |enable_exception_handling| flag indicates whether or not the nexe
217  * will be able to use hardware exception handling.
218  * The |enable_crash_throttling| flag indicates whether or not crashes of
219  * the nexe contribute to crash throttling statisics and whether nexe starts
220  * are throttled by crash throttling.
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_irt,
227  PP_Bool uses_ppapi,
228  PP_Bool uses_nonsfi_mode,
229  PP_Bool enable_ppapi_dev,
230  PP_Bool enable_dyncode_syscalls,
231  PP_Bool enable_exception_handling,
232  PP_Bool enable_crash_throttling,
233  void* imc_handle,
234  struct PP_CompletionCallback callback);
235  /* This function starts the IPC proxy so the nexe can communicate with the
236  * browser.
237  */
239  /* On POSIX systems, this function returns the file descriptor of
240  * /dev/urandom. On non-POSIX systems, this function returns 0.
241  */
242  int32_t (*UrandomFD)(void);
243  /* Whether the Pepper 3D interfaces should be disabled in the NaCl PPAPI
244  * proxy. This is so paranoid admins can effectively prevent untrusted shader
245  * code to be processed by the graphics stack.
246  */
248  /* This is Windows-specific. This is a replacement for DuplicateHandle() for
249  * use inside the Windows sandbox. Note that we provide this via dependency
250  * injection only to avoid the linkage problems that occur because the NaCl
251  * plugin is built as a separate DLL/DSO
252  * (see http://code.google.com/p/chromium/issues/detail?id=114439#c8).
253  */
254  int32_t (*BrokerDuplicateHandle)(PP_FileHandle source_handle,
255  uint32_t process_id,
256  PP_FileHandle* target_handle,
257  uint32_t desired_access,
258  uint32_t options);
259  /* Returns a read-only (but executable) file descriptor / file info for
260  * a url for pnacl translator tools. Returns an invalid handle on failure.
261  */
262  void (*GetReadExecPnaclFd)(const char* url,
263  struct PP_NaClFileInfo* out_file_info);
264  /* This creates a temporary file that will be deleted by the time
265  * the last handle is closed (or earlier on POSIX systems), and
266  * returns a posix handle to that temporary file.
267  */
269  /* Return the number of processors in the system as reported by the OS */
270  int32_t (*GetNumberOfProcessors)(void);
271  /* Return whether the non-SFI mode is enabled. */
273  /* Create a temporary file, which will be deleted by the time the
274  * last handle is closed (or earlier on POSIX systems), to use for
275  * the nexe with the cache information given by |pexe_url|,
276  * |abi_version|, |opt_level|, and |headers|. If the nexe is already present
277  * in the cache, |is_hit| is set to PP_TRUE and the contents of the nexe will
278  * be copied into the temporary file. Otherwise |is_hit| is set to PP_FALSE
279  * and the temporary file will be writeable. Currently the implementation is
280  * a stub, which always sets is_hit to false and calls the implementation of
281  * CreateTemporaryFile. In a subsequent CL it will call into the browser
282  * which will remember the association between the cache key and the fd, and
283  * copy the nexe into the cache after the translation finishes.
284  */
285  int32_t (*GetNexeFd)(PP_Instance instance,
286  const char* pexe_url,
287  uint32_t abi_version,
288  uint32_t opt_level,
289  const char* headers,
290  const char* extra_flags,
291  PP_Bool* is_hit,
292  PP_FileHandle* nexe_handle,
293  struct PP_CompletionCallback callback);
294  /* Report to the browser that translation of the pexe for |instance|
295  * has finished, or aborted with an error. If |success| is true, the
296  * browser may then store the translation in the cache. The renderer
297  * must first have called GetNexeFd for the same instance. (The browser is
298  * not guaranteed to store the nexe even if |success| is true; if there is
299  * an error on the browser side, or the file is too big for the cache, or
300  * the browser is in incognito mode, no notification will be delivered to
301  * the plugin.)
302  */
304  PP_Bool success,
305  int32_t opt_level,
306  int64_t pexe_size,
307  int64_t compile_time_us);
308  /* Dispatch a progress event on the DOM element where the given instance is
309  * embedded.
310  */
311  void (*DispatchEvent)(PP_Instance instance,
312  PP_NaClEventType event_type,
313  const char* resource_url,
314  PP_Bool length_is_computable,
315  uint64_t loaded_bytes,
316  uint64_t total_bytes);
317  /* Report that the nexe loaded successfully. */
318  void (*ReportLoadSuccess)(PP_Instance instance,
319  const char* url,
320  uint64_t loaded_bytes,
321  uint64_t total_bytes);
322  /* Report an error that occured while attempting to load a nexe. */
323  void (*ReportLoadError)(PP_Instance instance,
324  PP_NaClError error,
325  const char* error_message);
326  /* Reports that loading a nexe was aborted. */
327  void (*ReportLoadAbort)(PP_Instance instance);
328  /* Reports that the nexe has crashed. */
329  void (*NexeDidCrash)(PP_Instance instance, const char* crash_log);
330  /* Performs internal setup when an instance is created. */
331  void (*InstanceCreated)(PP_Instance instance);
332  /* Performs internal cleanup when an instance is destroyed. */
333  void (*InstanceDestroyed)(PP_Instance instance);
334  /* Return true if the NaCl debug stub is enabled and the app loaded from
335  * alleged_nmf_url will be attached to a debugger.
336  */
337  PP_Bool (*NaClDebugEnabledForURL)(const char* alleged_nmf_url);
338  /* Returns the kind of SFI sandbox implemented by NaCl on this
339  * platform.
340  */
341  const char* (*GetSandboxArch)(void);
342  /* Logs the message to the console. */
343  void (*LogToConsole)(PP_Instance instance, const char* message);
344  /* Returns the NaCl readiness status for this instance. */
346  /* Returns the exit status of the plugin process. */
347  int32_t (*GetExitStatus)(PP_Instance instance);
348  /* Sets the exit status of the plugin process. */
349  void (*SetExitStatus)(PP_Instance instance, int32_t exit_status);
350  /* Logs the message via VLOG. */
351  void (*Vlog)(const char* message);
352  /* Initializes internal state for a NaCl plugin. */
353  void (*InitializePlugin)(PP_Instance instance,
354  uint32_t argc,
355  const char* argn[],
356  const char* argv[]);
357  /* Returns the size of the nexe. */
358  int64_t (*GetNexeSize)(PP_Instance instance);
359  /* Requests the NaCl manifest specified in the plugin arguments. */
361  struct PP_CompletionCallback callback);
362  struct PP_Var (*GetManifestBaseURL)(PP_Instance instance);
363  /* Processes the NaCl manifest once it's been retrieved.
364  * TODO(teravest): Move the rest of the supporting logic out of the trusted
365  * plugin.
366  */
367  void (*ProcessNaClManifest)(PP_Instance instance, const char* program_url);
370  struct PP_Var* full_url,
371  struct PP_PNaClOptions* pnacl_options,
372  PP_Bool* uses_nonsfi_mode);
373  /* Returns the filenames for the llc and ld tools, parsing that information
374  * from the file given in |filename|.
375  */
377  const char* filename,
378  struct PP_Var* llc_tool_name,
379  struct PP_Var* ld_tool_name);
380  /* PP_Var string of attributes describing the CPU features supported
381  * by the current architecture. The string is a comma-delimited list
382  * of attributes supported by LLVM in its -mattr= option:
383  * http://llvm.org/docs/CommandGuide/llc.html#cmdoption-mattr */
384  struct PP_Var (*GetCpuFeatureAttrs)(void);
385  /* Posts a message to the JavaScript object for the given instance.
386  * This method may be called on any thread.
387  */
388  void (*PostMessageToJavaScript)(PP_Instance instance, const char* message);
389  /* Downloads the .nexe file at the given URL to a file, and sets |file_info|
390  * to information for a handle to a file containing its contents.
391  * If metadata for identity-based validation caching is available
392  * then it sets token information in |file_info| (otherwise left untouched).
393  */
394  void (*DownloadNexe)(PP_Instance instance,
395  const char* url,
396  struct PP_NaClFileInfo* file_info,
397  struct PP_CompletionCallback callback);
398  /* Reports the status of sel_ldr for UMA reporting.
399  * |max_status| has to be provided because the implementation of this
400  * interface can't access the NaClErrorCode enum.
401  */
402  void (*ReportSelLdrStatus)(PP_Instance instance,
403  int32_t load_status,
404  int32_t max_status);
405  /* Logs time taken by an operation to UMA histograms.
406  * This function is safe to call on any thread.
407  */
408  void (*LogTranslateTime)(const char* histogram_name, int64_t time_us);
409  /* Opens a manifest entry for the given instance. If this is for a helper
410  * process, we consult our internal pnacl.json instead of the user-supplied
411  * NMF.
412  * Fails for files which require PNaCl translation.
413  */
414  void (*OpenManifestEntry)(PP_Instance instance,
415  PP_Bool is_helper_process,
416  const char* key,
417  struct PP_NaClFileInfo* file_info,
418  struct PP_CompletionCallback callback);
419  /* Sets the start time for PNaCl downloading and translation to the current
420  * time.
421  */
422  void (*SetPNaClStartTime)(PP_Instance instance);
423  /* If module requests pepper permissions, it will be authenticated here.
424  */
425  void (*AuthenticateModule)(PP_Instance instance,
426  const struct PP_NaClFileInfo* nexe_file_info,
427  struct PP_CompletionCallback callback);
428 };
429 
431 /**
432  * @}
433  */
434 
435 #endif /* PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ */
436 
void(* ReportLoadAbort)(PP_Instance instance)
void(* InstanceDestroyed)(PP_Instance instance)
void(* Vlog)(const char *message)
void(* PostMessageToJavaScript)(PP_Instance instance, const char *message)
void(* InitializePlugin)(PP_Instance instance, uint32_t argc, const char *argn[], const char *argv[])
int32_t(* UrandomFD)(void)
PP_Bool(* IsNonSFIModeEnabled)(void)
int32_t(* BrokerDuplicateHandle)(PP_FileHandle source_handle, uint32_t process_id, PP_FileHandle *target_handle, uint32_t desired_access, uint32_t options)
void(* NexeDidCrash)(PP_Instance instance, const char *crash_log)
PP_NaClReadyState
PP_Bool(* Are3DInterfacesDisabled)(void)
PP_Bool(* GetPnaclResourceInfo)(PP_Instance instance, const char *filename, struct PP_Var *llc_tool_name, struct PP_Var *ld_tool_name)
PP_Bool(* DevInterfacesEnabled)(PP_Instance instance)
int PP_FileHandle
void(* LogTranslateTime)(const char *histogram_name, int64_t time_us)
PP_UrlSchemeType
void(* InstanceCreated)(PP_Instance instance)
PP_Bool(* StartPpapiProxy)(PP_Instance instance)
int32_t(* GetNexeFd)(PP_Instance instance, const char *pexe_url, uint32_t abi_version, uint32_t opt_level, const char *headers, const char *extra_flags, PP_Bool *is_hit, PP_FileHandle *nexe_handle, struct PP_CompletionCallback callback)
void(* RequestNaClManifest)(PP_Instance instance, struct PP_CompletionCallback callback)
void(* ReportLoadSuccess)(PP_Instance instance, const char *url, uint64_t loaded_bytes, uint64_t total_bytes)
void(* LaunchSelLdr)(PP_Instance instance, PP_Bool main_service_runtime, const char *alleged_url, const struct PP_NaClFileInfo *nexe_file_info, PP_Bool uses_irt, PP_Bool uses_ppapi, PP_Bool uses_nonsfi_mode, PP_Bool enable_ppapi_dev, PP_Bool enable_dyncode_syscalls, PP_Bool enable_exception_handling, PP_Bool enable_crash_throttling, void *imc_handle, struct PP_CompletionCallback callback)
void(* ReportSelLdrStatus)(PP_Instance instance, int32_t load_status, int32_t max_status)
PP_FileHandle(* CreateTemporaryFile)(PP_Instance instance)
void(* OpenManifestEntry)(PP_Instance instance, PP_Bool is_helper_process, const char *key, struct PP_NaClFileInfo *file_info, struct PP_CompletionCallback callback)
void(* GetReadExecPnaclFd)(const char *url, struct PP_NaClFileInfo *out_file_info)
void(* PP_OpenResourceCompletionCallback)(void *user_data, PP_FileHandle file_handle)
struct PP_Var(* GetCpuFeatureAttrs)(void)
void(* DownloadNexe)(PP_Instance instance, const char *url, struct PP_NaClFileInfo *file_info, struct PP_CompletionCallback callback)
PP_NaClReadyState(* GetNaClReadyState)(PP_Instance instance)
Definition: pp_var.h:166
int32_t(* GetExitStatus)(PP_Instance instance)
int64_t(* GetNexeSize)(PP_Instance instance)
PP_Bool(* NaClDebugEnabledForURL)(const char *alleged_nmf_url)
void(* AuthenticateModule)(PP_Instance instance, const struct PP_NaClFileInfo *nexe_file_info, struct PP_CompletionCallback callback)
int32_t PP_Instance
Definition: pp_instance.h:34
void(* SetPNaClStartTime)(PP_Instance instance)
PP_NaClError
void(* LogToConsole)(PP_Instance instance, const char *message)
PP_Bool
Definition: pp_bool.h:30
PP_Bool(* GetManifestProgramURL)(PP_Instance instance, struct PP_Var *full_url, struct PP_PNaClOptions *pnacl_options, PP_Bool *uses_nonsfi_mode)
void(* ProcessNaClManifest)(PP_Instance instance, const char *program_url)
void(* ReportLoadError)(PP_Instance instance, PP_NaClError error, const char *error_message)
void(* SetExitStatus)(PP_Instance instance, int32_t exit_status)
PP_NaClEventType
int32_t(* GetNumberOfProcessors)(void)
void(* DispatchEvent)(PP_Instance instance, PP_NaClEventType event_type, const char *resource_url, PP_Bool length_is_computable, uint64_t loaded_bytes, uint64_t total_bytes)
void(* ReportTranslationFinished)(PP_Instance instance, PP_Bool success, int32_t opt_level, int64_t pexe_size, int64_t compile_time_us)
PP_FileHandle handle
struct PP_Var(* GetManifestBaseURL)(PP_Instance instance)