Home | History | Annotate | Download | only in private
      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 Fri Jun 13 15:14:51 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  * @}
    209  */
    210 
    211 /**
    212  * @addtogroup Structs
    213  * @{
    214  */
    215 /* Corresponds to NaClFileInfo in
    216  * native_client/src/trusted/validator/nacl_file_info.h */
    217 struct PP_NaClFileInfo {
    218   PP_FileHandle handle;
    219   /* See NaClFileToken comment in nacl_file_info.h */
    220   uint64_t token_lo;
    221   uint64_t token_hi;
    222 };
    223 /**
    224  * @}
    225  */
    226 
    227 /**
    228  * @addtogroup Interfaces
    229  * @{
    230  */
    231 /* PPB_NaCl_Private */
    232 struct PPB_NaCl_Private_1_0 {
    233   /* Launches NaCl's sel_ldr process.  Returns PP_EXTERNAL_PLUGIN_OK on success
    234    * and writes a NaClHandle to imc_handle. Returns PP_EXTERNAL_PLUGIN_FAILED on
    235    * failure. The |enable_ppapi_dev| parameter controls whether GetInterface
    236    * returns 'Dev' interfaces to the NaCl plugin.  The |uses_ppapi| flag
    237    * indicates that the nexe run by sel_ldr will use the PPAPI APIs.
    238    * This implies that LaunchSelLdr is run from the main thread.  If a nexe
    239    * does not need PPAPI, then it can run off the main thread.
    240    * The |uses_irt| flag indicates whether the IRT should be loaded in this
    241    * NaCl process.  This is true for ABI stable nexes.
    242    * The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
    243    * be used with the binary pointed by the url.
    244    * The |enable_dyncode_syscalls| flag indicates whether or not the nexe
    245    * will be able to use dynamic code system calls (e.g., mmap with PROT_EXEC).
    246    * The |enable_exception_handling| flag indicates whether or not the nexe
    247    * will be able to use hardware exception handling.
    248    * The |enable_crash_throttling| flag indicates whether or not crashes of
    249    * the nexe contribute to crash throttling statisics and whether nexe starts
    250    * are throttled by crash throttling.
    251    */
    252   void (*LaunchSelLdr)(
    253       PP_Instance instance,
    254       PP_Bool main_service_runtime,
    255       const char* alleged_url,
    256       PP_Bool uses_irt,
    257       PP_Bool uses_ppapi,
    258       PP_Bool uses_nonsfi_mode,
    259       PP_Bool enable_ppapi_dev,
    260       PP_Bool enable_dyncode_syscalls,
    261       PP_Bool enable_exception_handling,
    262       PP_Bool enable_crash_throttling,
    263       const struct PPP_ManifestService_1_0* manifest_service_interface,
    264       void* manifest_service_user_data,
    265       void* imc_handle,
    266       struct PP_CompletionCallback callback);
    267   /* This function starts the IPC proxy so the nexe can communicate with the
    268    * browser.
    269    */
    270   PP_Bool (*StartPpapiProxy)(PP_Instance instance);
    271   /* On POSIX systems, this function returns the file descriptor of
    272    * /dev/urandom.  On non-POSIX systems, this function returns 0.
    273    */
    274   int32_t (*UrandomFD)(void);
    275   /* Whether the Pepper 3D interfaces should be disabled in the NaCl PPAPI
    276    * proxy. This is so paranoid admins can effectively prevent untrusted shader
    277    * code to be processed by the graphics stack.
    278    */
    279   PP_Bool (*Are3DInterfacesDisabled)(void);
    280   /* This is Windows-specific.  This is a replacement for DuplicateHandle() for
    281    * use inside the Windows sandbox.  Note that we provide this via dependency
    282    * injection only to avoid the linkage problems that occur because the NaCl
    283    * plugin is built as a separate DLL/DSO
    284    * (see http://code.google.com/p/chromium/issues/detail?id=114439#c8).
    285    */
    286   int32_t (*BrokerDuplicateHandle)(PP_FileHandle source_handle,
    287                                    uint32_t process_id,
    288                                    PP_FileHandle* target_handle,
    289                                    uint32_t desired_access,
    290                                    uint32_t options);
    291   /* Returns a read-only file descriptor for a url for pnacl translator tools,
    292    * or an invalid handle on failure.
    293    */
    294   PP_FileHandle (*GetReadonlyPnaclFd)(const char* url);
    295   /* This creates a temporary file that will be deleted by the time
    296    * the last handle is closed (or earlier on POSIX systems), and
    297    * returns a posix handle to that temporary file.
    298    */
    299   PP_FileHandle (*CreateTemporaryFile)(PP_Instance instance);
    300   /* Return the number of processors in the system as reported by the OS */
    301   int32_t (*GetNumberOfProcessors)(void);
    302   /* Return whether the non-SFI mode is enabled. */
    303   PP_Bool (*IsNonSFIModeEnabled)(void);
    304   /* Create a temporary file, which will be deleted by the time the
    305    * last handle is closed (or earlier on POSIX systems), to use for
    306    * the nexe with the cache information given by |pexe_url|,
    307    * |abi_version|, |opt_level|, and |headers|.  If the nexe is already present
    308    * in the cache, |is_hit| is set to PP_TRUE and the contents of the nexe will
    309    * be copied into the temporary file. Otherwise |is_hit| is set to PP_FALSE
    310    * and the temporary file will be writeable.  Currently the implementation is
    311    * a stub, which always sets is_hit to false and calls the implementation of
    312    * CreateTemporaryFile. In a subsequent CL it will call into the browser
    313    * which will remember the association between the cache key and the fd, and
    314    * copy the nexe into the cache after the translation finishes.
    315    */
    316   int32_t (*GetNexeFd)(PP_Instance instance,
    317                        const char* pexe_url,
    318                        uint32_t abi_version,
    319                        uint32_t opt_level,
    320                        const char* headers,
    321                        const char* extra_flags,
    322                        PP_Bool* is_hit,
    323                        PP_FileHandle* nexe_handle,
    324                        struct PP_CompletionCallback callback);
    325   /* Report to the browser that translation of the pexe for |instance|
    326    * has finished, or aborted with an error. If |success| is true, the
    327    * browser may then store the translation in the cache. The renderer
    328    * must first have called GetNexeFd for the same instance. (The browser is
    329    * not guaranteed to store the nexe even if |success| is true; if there is
    330    * an error on the browser side, or the file is too big for the cache, or
    331    * the browser is in incognito mode, no notification will be delivered to
    332    * the plugin.)
    333    */
    334   void (*ReportTranslationFinished)(PP_Instance instance,
    335                                     PP_Bool success,
    336                                     int32_t opt_level,
    337                                     int64_t pexe_size,
    338                                     int64_t compile_time_us,
    339                                     int64_t total_time_us);
    340   /* Dispatch a progress event on the DOM element where the given instance is
    341    * embedded.
    342    */
    343   void (*DispatchEvent)(PP_Instance instance,
    344                         PP_NaClEventType event_type,
    345                         const char* resource_url,
    346                         PP_Bool length_is_computable,
    347                         uint64_t loaded_bytes,
    348                         uint64_t total_bytes);
    349   /* Report that the nexe loaded successfully. */
    350   void (*ReportLoadSuccess)(PP_Instance instance,
    351                             const char* url,
    352                             uint64_t loaded_bytes,
    353                             uint64_t total_bytes);
    354   /* Report an error that occured while attempting to load a nexe. */
    355   void (*ReportLoadError)(PP_Instance instance,
    356                           PP_NaClError error,
    357                           const char* error_message);
    358   /* Reports that loading a nexe was aborted. */
    359   void (*ReportLoadAbort)(PP_Instance instance);
    360   /* Reports that the nexe has crashed. */
    361   void (*NexeDidCrash)(PP_Instance instance, const char* crash_log);
    362   /* Performs internal setup when an instance is created. */
    363   void (*InstanceCreated)(PP_Instance instance);
    364   /* Performs internal cleanup when an instance is destroyed. */
    365   void (*InstanceDestroyed)(PP_Instance instance);
    366   /* Return true if the NaCl debug stub is enabled and the app loaded from
    367    * alleged_nmf_url will be attached to a debugger.
    368    */
    369   PP_Bool (*NaClDebugEnabledForURL)(const char* alleged_nmf_url);
    370   /* Returns the kind of SFI sandbox implemented by NaCl on this
    371    * platform.
    372    */
    373   const char* (*GetSandboxArch)(void);
    374   /* Logs the message to the console. */
    375   void (*LogToConsole)(PP_Instance instance, const char* message);
    376   /* Returns the NaCl readiness status for this instance. */
    377   PP_NaClReadyState (*GetNaClReadyState)(PP_Instance instance);
    378   /* Returns the exit status of the plugin process. */
    379   int32_t (*GetExitStatus)(PP_Instance instance);
    380   /* Sets the exit status of the plugin process. */
    381   void (*SetExitStatus)(PP_Instance instance, int32_t exit_status);
    382   /* Logs the message via VLOG. */
    383   void (*Vlog)(const char* message);
    384   /* Initializes internal state for a NaCl plugin. */
    385   void (*InitializePlugin)(PP_Instance instance,
    386                            uint32_t argc,
    387                            const char* argn[],
    388                            const char* argv[]);
    389   /* Returns the size of the nexe. */
    390   int64_t (*GetNexeSize)(PP_Instance instance);
    391   /* Requests the NaCl manifest specified in the plugin arguments. */
    392   void (*RequestNaClManifest)(PP_Instance instance,
    393                               struct PP_CompletionCallback callback);
    394   struct PP_Var (*GetManifestBaseURL)(PP_Instance instance);
    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   PP_Bool (*DevInterfacesEnabled)(PP_Instance instance);
    401   PP_Bool (*GetManifestProgramURL)(PP_Instance instance,
    402                                    struct PP_Var* full_url,
    403                                    struct PP_PNaClOptions* pnacl_options,
    404                                    PP_Bool* uses_nonsfi_mode);
    405   PP_Bool (*ManifestResolveKey)(PP_Instance instance,
    406                                 PP_Bool helper_process,
    407                                 const char* key,
    408                                 struct PP_Var* full_url,
    409                                 struct PP_PNaClOptions* pnacl_options);
    410   /* Returns the filenames for the llc and ld tools, parsing that information
    411    * from the file given in |filename|.
    412    */
    413   PP_Bool (*GetPnaclResourceInfo)(PP_Instance instance,
    414                                   const char* filename,
    415                                   struct PP_Var* llc_tool_name,
    416                                   struct PP_Var* ld_tool_name);
    417   /* PP_Var string of attributes describing the CPU features supported
    418    * by the current architecture. The string is a comma-delimited list
    419    * of attributes supported by LLVM in its -mattr= option:
    420    *   http://llvm.org/docs/CommandGuide/llc.html#cmdoption-mattr */
    421   struct PP_Var (*GetCpuFeatureAttrs)(void);
    422   /* Posts a message to the JavaScript object for the given instance.
    423    * This method may be called on any thread.
    424    */
    425   void (*PostMessageToJavaScript)(PP_Instance instance, const char* message);
    426   /* Downloads the .nexe file at the given URL to a file, and sets |file_info|
    427    * to information for a handle to a file containing its contents.
    428    * If metadata for identity-based validation caching is available
    429    * then it sets token information in |file_info| (otherwise left untouched).
    430    */
    431   void (*DownloadNexe)(PP_Instance instance,
    432                        const char* url,
    433                        struct PP_NaClFileInfo* file_info,
    434                        struct PP_CompletionCallback callback);
    435   /* Downloads a non-nexe file specified in the manifest, and sets |file_info|
    436    * to corresponding information about the file. */
    437   void (*DownloadFile)(PP_Instance instance,
    438                        const char* url,
    439                        struct PP_NaClFileInfo* file_info,
    440                        struct PP_CompletionCallback callback);
    441   /* Reports the status of sel_ldr for UMA reporting.
    442    * |max_status| has to be provided because the implementation of this
    443    * interface can't access the NaClErrorCode enum.
    444    */
    445   void (*ReportSelLdrStatus)(PP_Instance instance,
    446                              int32_t load_status,
    447                              int32_t max_status);
    448   /* Logs time taken by an operation to UMA histograms.
    449    * This function is safe to call on any thread.
    450    */
    451   void (*LogTranslateTime)(const char* histogram_name, int64_t time_us);
    452 };
    453 
    454 typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private;
    455 /**
    456  * @}
    457  */
    458 
    459 #endif  /* PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ */
    460 
    461