Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / components / nacl / renderer / ppb_nacl_private.h
blob7953461bac2de29967b26af4dcf2ba4ab6aacd6b
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.
5 #ifndef COMPONENTS_NACL_RENDERER_PPB_NACL_PRIVATE_H_
6 #define COMPONENTS_NACL_RENDERER_PPB_NACL_PRIVATE_H_
8 #include "ppapi/c/pp_bool.h"
9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_instance.h"
11 #include "ppapi/c/pp_macros.h"
12 #include "ppapi/c/pp_stdint.h"
13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/c/private/pp_file_handle.h"
15 #include "ppapi/c/private/ppb_instance_private.h"
16 #include "ppapi/c/private/ppp_pexe_stream_handler.h"
18 // This file defines an interface that is used by the code in
19 // components/nacl/renderer/plugin/. It is defined as a PPAPI PPB_*
20 // interface for historical reasons: The code in plugin/ used to live
21 // outside the Chromium repo.
23 // In the future, we may integrate the code in nacl/renderer/plugin/ more
24 // closely with nacl/renderer/. This could include having plugin/ call the
25 // functions below directly, rather than providing these functions via the
26 // PPB_NaCl_Private interface struct.
28 #define PPB_NACL_PRIVATE_INTERFACE "PPB_NaCl_Private"
30 /**
31 * @addtogroup Enums
32 * @{
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.
41 typedef enum {
42 PP_NACL_ERROR_LOAD_SUCCESS = 0,
43 PP_NACL_ERROR_LOAD_ABORTED = 1,
44 PP_NACL_ERROR_UNKNOWN = 2,
45 PP_NACL_ERROR_MANIFEST_RESOLVE_URL = 3,
46 PP_NACL_ERROR_MANIFEST_LOAD_URL = 4,
47 PP_NACL_ERROR_MANIFEST_STAT = 5,
48 PP_NACL_ERROR_MANIFEST_TOO_LARGE = 6,
49 PP_NACL_ERROR_MANIFEST_OPEN = 7,
50 PP_NACL_ERROR_MANIFEST_MEMORY_ALLOC = 8,
51 PP_NACL_ERROR_MANIFEST_READ = 9,
52 PP_NACL_ERROR_MANIFEST_PARSING = 10,
53 PP_NACL_ERROR_MANIFEST_SCHEMA_VALIDATE = 11,
54 PP_NACL_ERROR_MANIFEST_GET_NEXE_URL = 12,
55 PP_NACL_ERROR_NEXE_LOAD_URL = 13,
56 PP_NACL_ERROR_NEXE_ORIGIN_PROTOCOL = 14,
57 PP_NACL_ERROR_NEXE_FH_DUP = 15,
58 PP_NACL_ERROR_NEXE_STAT = 16,
59 PP_NACL_ERROR_ELF_CHECK_IO = 17,
60 PP_NACL_ERROR_ELF_CHECK_FAIL = 18,
61 PP_NACL_ERROR_SEL_LDR_INIT = 19,
62 PP_NACL_ERROR_SEL_LDR_CREATE_LAUNCHER = 20,
63 PP_NACL_ERROR_SEL_LDR_FD = 21,
64 PP_NACL_ERROR_SEL_LDR_LAUNCH = 22,
65 /* Deprecated, safe to reuse the value because it's never logged in UMA.
67 PP_NACL_ERROR_SEL_LDR_SEND_NEXE = 24,
68 PP_NACL_ERROR_SEL_LDR_HANDLE_PASSING = 25,
69 PP_NACL_ERROR_SEL_LDR_START_MODULE = 26,
70 PP_NACL_ERROR_SEL_LDR_START_STATUS = 27,
71 PP_NACL_ERROR_SRPC_CONNECTION_FAIL = 28,
72 PP_NACL_ERROR_START_PROXY_CHECK_PPP = 29,
73 PP_NACL_ERROR_START_PROXY_ALLOC = 30,
74 PP_NACL_ERROR_START_PROXY_MODULE = 31,
75 PP_NACL_ERROR_START_PROXY_INSTANCE = 32,
76 PP_NACL_ERROR_SEL_LDR_COMMUNICATION_CMD_CHANNEL = 33,
77 PP_NACL_ERROR_SEL_LDR_COMMUNICATION_REV_SETUP = 34,
78 PP_NACL_ERROR_SEL_LDR_COMMUNICATION_WRAPPER = 35,
79 PP_NACL_ERROR_SEL_LDR_COMMUNICATION_REV_SERVICE = 36,
80 PP_NACL_ERROR_START_PROXY_CRASH = 37,
81 PP_NACL_ERROR_MANIFEST_PROGRAM_MISSING_ARCH = 38,
82 PP_NACL_ERROR_PNACL_CACHE_OPEN_INPROGRESS = 39,
83 PP_NACL_ERROR_PNACL_CACHE_OPEN_NOACCESS = 40,
84 PP_NACL_ERROR_PNACL_CACHE_OPEN_NOQUOTA = 41,
85 PP_NACL_ERROR_PNACL_CACHE_OPEN_NOSPACE = 42,
86 PP_NACL_ERROR_PNACL_CACHE_OPEN_OTHER = 43,
87 PP_NACL_ERROR_PNACL_CACHE_DIRECTORY_CREATE = 44,
88 PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOACCESS = 45,
89 PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOQUOTA = 46,
90 PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOSPACE = 47,
91 PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_NOTAFILE = 48,
92 PP_NACL_ERROR_PNACL_CACHE_FILEOPEN_OTHER = 49,
93 PP_NACL_ERROR_PNACL_CACHE_FETCH_NOACCESS = 50,
94 PP_NACL_ERROR_PNACL_CACHE_FETCH_NOTFOUND = 51,
95 PP_NACL_ERROR_PNACL_CACHE_FETCH_OTHER = 52,
96 PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_NOQUOTA = 53,
97 PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_NOSPACE = 54,
98 PP_NACL_ERROR_PNACL_CACHE_FINALIZE_COPY_OTHER = 55,
99 PP_NACL_ERROR_PNACL_CACHE_FINALIZE_RENAME_NOACCESS = 56,
100 PP_NACL_ERROR_PNACL_CACHE_FINALIZE_RENAME_OTHER = 57,
101 PP_NACL_ERROR_PNACL_RESOURCE_FETCH = 58,
102 PP_NACL_ERROR_PNACL_PEXE_FETCH_ABORTED = 59,
103 PP_NACL_ERROR_PNACL_PEXE_FETCH_NOACCESS = 60,
104 PP_NACL_ERROR_PNACL_PEXE_FETCH_OTHER = 61,
105 PP_NACL_ERROR_PNACL_THREAD_CREATE = 62,
106 PP_NACL_ERROR_PNACL_LLC_SETUP = 63,
107 PP_NACL_ERROR_PNACL_LD_SETUP = 64,
108 PP_NACL_ERROR_PNACL_LLC_INTERNAL = 65,
109 PP_NACL_ERROR_PNACL_LD_INTERNAL = 66,
110 PP_NACL_ERROR_PNACL_CREATE_TEMP = 67,
111 /* This entry is no longer used, but should not be removed, because UMA
113 PP_NACL_ERROR_PNACL_NOT_ENABLED = 68,
114 PP_NACL_ERROR_MANIFEST_NOACCESS_URL = 69,
115 PP_NACL_ERROR_NEXE_NOACCESS_URL = 70,
116 PP_NACL_ERROR_PNACL_CRASH_THROTTLED = 71,
117 /* If you add a code, read the enum comment above on how to update
119 PP_NACL_ERROR_MAX
120 } PP_NaClError;
122 /** Event types that NaCl may use when reporting load progress or errors. */
123 typedef enum {
124 PP_NACL_EVENT_LOADSTART,
125 PP_NACL_EVENT_PROGRESS,
126 PP_NACL_EVENT_ERROR,
127 PP_NACL_EVENT_ABORT,
128 PP_NACL_EVENT_LOAD,
129 PP_NACL_EVENT_LOADEND,
130 PP_NACL_EVENT_CRASH
131 } PP_NaClEventType;
133 typedef enum {
134 PP_SCHEME_CHROME_EXTENSION,
135 PP_SCHEME_DATA,
136 PP_SCHEME_OTHER
137 } PP_UrlSchemeType;
139 typedef enum {
140 /* The trusted plugin begins in this ready state. */
141 PP_NACL_READY_STATE_UNSENT = 0,
142 /* The manifest file has been requested, but not yet received. */
143 PP_NACL_READY_STATE_OPENED = 1,
144 /* The manifest file has been received and the nexe successfully requested. */
145 PP_NACL_READY_STATE_LOADING = 3,
146 /* The nexe has been loaded and the proxy started, so it is ready for
148 PP_NACL_READY_STATE_DONE = 4
149 } PP_NaClReadyState;
151 /** Types of untrusted NaCl processes. Mirrors NaClAppProcessType from
152 * components/nacl/common/nacl_types.h.
154 typedef enum {
155 PP_UNKNOWN_NACL_PROCESS_TYPE,
156 PP_NATIVE_NACL_PROCESS_TYPE,
157 PP_PNACL_PROCESS_TYPE,
158 PP_PNACL_TRANSLATOR_PROCESS_TYPE,
159 PP_NUM_NACL_PROCESS_TYPES
160 } PP_NaClAppProcessType;
162 * @}
166 * @addtogroup Structs
167 * @{
169 struct PP_PNaClOptions {
170 PP_Bool translate;
171 PP_Bool is_debug;
172 PP_Bool use_subzero;
173 int32_t opt_level;
176 * @}
180 * @addtogroup Typedefs
181 * @{
183 /* Callback invoked upon completion of PPP_ManifestService::OpenResource(). */
184 typedef void (*PP_OpenResourceCompletionCallback)(void* user_data,
185 PP_FileHandle file_handle);
187 * @}
191 * @addtogroup Structs
192 * @{
194 struct PP_NaClFileInfo {
195 PP_FileHandle handle;
196 /* See NaClFileToken comment in nacl_process_host.h */
197 uint64_t token_lo;
198 uint64_t token_hi;
201 * @}
205 * @addtogroup Interfaces
206 * @{
208 struct PPB_NaCl_Private {
209 /* Launches NaCl's sel_ldr process. Returns PP_EXTERNAL_PLUGIN_OK on success
210 * and writes a NaClHandle to imc_handle. Returns PP_EXTERNAL_PLUGIN_FAILED on
211 * failure.
212 * The |nexe_file_info| is currently used only in non-SFI mode. It is the
213 * file handle for the main nexe file, which should be initially loaded.
214 * LaunchSelLdr takes the ownership of the file handle.
215 * The |uses_nonsfi_mode| flag indicates whether or not nonsfi-mode should
216 * be used with the binary pointed by the url.
218 void (*LaunchSelLdr)(PP_Instance instance,
219 PP_Bool main_service_runtime,
220 const char* alleged_url,
221 const struct PP_NaClFileInfo* nexe_file_info,
222 PP_Bool uses_nonsfi_mode,
223 PP_NaClAppProcessType process_type,
224 void* imc_handle,
225 struct PP_CompletionCallback callback);
226 /* On POSIX systems, this function returns the file descriptor of
227 * /dev/urandom. On non-POSIX systems, this function returns 0.
229 int32_t (*UrandomFD)(void);
230 /* This is Windows-specific. This is a replacement for DuplicateHandle() for
231 * use inside the Windows sandbox. Note that we provide this via dependency
232 * injection only to avoid the linkage problems that occur because the NaCl
233 * plugin is built as a separate DLL/DSO
234 * (see http://code.google.com/p/chromium/issues/detail?id=114439#c8).
236 int32_t (*BrokerDuplicateHandle)(PP_FileHandle source_handle,
237 uint32_t process_id,
238 PP_FileHandle* target_handle,
239 uint32_t desired_access,
240 uint32_t options);
241 /* Returns a read-only (but executable) file descriptor / file info for
242 * a url for pnacl translator tools. Returns an invalid handle on failure.
244 void (*GetReadExecPnaclFd)(const char* url,
245 struct PP_NaClFileInfo* out_file_info);
246 /* This creates a temporary file that will be deleted by the time
247 * the last handle is closed (or earlier on POSIX systems), and
248 * returns a posix handle to that temporary file.
250 PP_FileHandle (*CreateTemporaryFile)(PP_Instance instance);
251 /* Return the number of processors in the system as reported by the OS */
252 int32_t (*GetNumberOfProcessors)(void);
253 /* Report to the browser that translation of the pexe for |instance|
254 * has finished, or aborted with an error. If |success| is true, the
255 * browser may then store the translation in the cache. The renderer
256 * must first have called StreamPexe for the same instance. (The browser is
257 * not guaranteed to store the nexe even if |success| is true; if there is
258 * an error on the browser side, or the file is too big for the cache, or
259 * the browser is in incognito mode, no notification will be delivered to
260 * the plugin.)
262 void (*ReportTranslationFinished)(PP_Instance instance,
263 PP_Bool success,
264 int32_t opt_level,
265 PP_Bool use_subzero,
266 int64_t nexe_size,
267 int64_t pexe_size,
268 int64_t compile_time_us);
269 /* Dispatch a progress event on the DOM element where the given instance is
270 * embedded.
272 void (*DispatchEvent)(PP_Instance instance,
273 PP_NaClEventType event_type,
274 const char* resource_url,
275 PP_Bool length_is_computable,
276 uint64_t loaded_bytes,
277 uint64_t total_bytes);
278 /* Report an error that occured while attempting to load a nexe. */
279 void (*ReportLoadError)(PP_Instance instance,
280 PP_NaClError error,
281 const char* error_message);
282 /* Performs internal setup when an instance is created. */
283 void (*InstanceCreated)(PP_Instance instance);
284 /* Performs internal cleanup when an instance is destroyed. */
285 void (*InstanceDestroyed)(PP_Instance instance);
286 /* Returns the kind of SFI sandbox implemented by NaCl on this
287 * platform.
289 const char* (*GetSandboxArch)(void);
290 /* Logs the message via VLOG. */
291 void (*Vlog)(const char* message);
292 /* Initializes internal state for a NaCl plugin. */
293 void (*InitializePlugin)(PP_Instance instance,
294 uint32_t argc,
295 const char* argn[],
296 const char* argv[]);
297 /* Requests the NaCl manifest specified in the plugin arguments. */
298 void (*RequestNaClManifest)(PP_Instance instance,
299 struct PP_CompletionCallback callback);
300 struct PP_Var (*GetManifestBaseURL)(PP_Instance instance);
301 /* Processes the NaCl manifest once it's been retrieved.
302 * TODO(teravest): Move the rest of the supporting logic out of the trusted
303 * plugin.
305 void (*ProcessNaClManifest)(PP_Instance instance, const char* program_url);
306 PP_Bool (*GetManifestProgramURL)(PP_Instance instance,
307 struct PP_Var* full_url,
308 struct PP_PNaClOptions* pnacl_options,
309 PP_Bool* uses_nonsfi_mode);
310 /* Returns the filenames for the llc and ld tools. */
311 PP_Bool (*GetPnaclResourceInfo)(PP_Instance instance,
312 struct PP_Var* llc_tool_name,
313 struct PP_Var* ld_tool_name,
314 struct PP_Var* subzero_tool_name);
315 /* PP_Var string of attributes describing the CPU features supported
316 * by the current architecture. The string is a comma-delimited list
317 * of attributes supported by LLVM in its -mattr= option:
318 * http://llvm.org/docs/CommandGuide/llc.html#cmdoption-mattr */
319 struct PP_Var (*GetCpuFeatureAttrs)(void);
320 /* Downloads the .nexe file at the given URL to a file, and sets |file_info|
321 * to information for a handle to a file containing its contents.
322 * If metadata for identity-based validation caching is available
323 * then it sets token information in |file_info| (otherwise left untouched).
325 void (*DownloadNexe)(PP_Instance instance,
326 const char* url,
327 struct PP_NaClFileInfo* file_info,
328 struct PP_CompletionCallback callback);
329 /* Reports the status of sel_ldr for UMA reporting.
330 * |max_status| has to be provided because the implementation of this
331 * interface can't access the NaClErrorCode enum.
333 void (*ReportSelLdrStatus)(PP_Instance instance,
334 int32_t load_status,
335 int32_t max_status);
336 /* Logs time taken by an operation to UMA histograms.
337 * This function is safe to call on any thread.
339 void (*LogTranslateTime)(const char* histogram_name, int64_t time_us);
340 /* Logs amount of pexe bytes compiled when download is complete. */
341 void (*LogBytesCompiledVsDownloaded)(PP_Bool use_subzero,
342 int64_t pexe_bytes_compiled,
343 int64_t pexe_bytes_downloaded);
344 /* Sets the start time for PNaCl downloading and translation to the current
345 * time.
347 void (*SetPNaClStartTime)(PP_Instance instance);
348 /* Downloads and streams a pexe file for PNaCl translation.
349 * Fetches the content at |pexe_url| for the given instance and opt_level.
350 * If a translated cached nexe is already available,
351 * the |stream_handler|'s |DidCacheHit| is called. Otherwise, |DidCacheMiss|
352 * is called and |DidStreamData| is called repeatedly with blocks of data
353 * as they are received. |DidFinishStream| is called after all
354 * data has been received and dispatched to |DidStreamData|.
356 void (*StreamPexe)(PP_Instance instance,
357 const char* pexe_url,
358 int32_t opt_level,
359 PP_Bool use_subzero,
360 const struct PPP_PexeStreamHandler_1_0* stream_handler,
361 void* stream_handler_user_data);
364 * @}
367 #endif /* COMPONENTS_NACL_RENDERER_PPB_NACL_PRIVATE_H_ */