1 // Copyright 2013 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_COMMON_NACL_TYPES_H_
6 #define COMPONENTS_NACL_COMMON_NACL_TYPES_H_
11 #include "base/basictypes.h"
12 #include "base/memory/shared_memory.h"
13 #include "base/process/process_handle.h"
14 #include "build/build_config.h"
15 #include "ipc/ipc_channel.h"
16 #include "ipc/ipc_platform_file.h"
19 #include "base/file_descriptor_posix.h"
23 #include <windows.h> // for HANDLE
26 // TODO(gregoryd): add a Windows definition for base::FileDescriptor
30 typedef HANDLE FileDescriptor
;
31 inline HANDLE
ToNativeHandle(const FileDescriptor
& desc
) {
34 #elif defined(OS_POSIX)
35 typedef base::FileDescriptor FileDescriptor
;
36 inline int ToNativeHandle(const FileDescriptor
& desc
) {
41 // We allocate a page of shared memory for sharing crash information from
42 // trusted code in the NaCl process to the renderer.
43 static const int kNaClCrashInfoShmemSize
= 4096;
44 static const int kNaClCrashInfoMaxLogSize
= 1024;
46 // Types of untrusted NaCl processes.
47 enum NaClAppProcessType
{
48 kUnknownNaClProcessType
,
49 // Runs user-provided *native* code. Enabled for Chrome Web Store apps.
50 kNativeNaClProcessType
,
51 // Runs user-provided code that is translated from *bitcode* by an
52 // in-browser PNaCl translator.
54 // Runs pnacl-llc/linker *native* code. These nexes are browser-provided
55 // (not user-provided).
56 kPNaClTranslatorProcessType
,
60 // Parameters sent to the NaCl process when we start it.
61 struct NaClStartParams
{
65 IPC::PlatformFileForTransit nexe_file
;
66 // Used only as a key for validation caching.
67 base::FilePath nexe_file_path_metadata
;
69 std::vector
<FileDescriptor
> handles
;
70 FileDescriptor debug_stub_server_bound_socket
;
72 bool validation_cache_enabled
;
73 std::string validation_cache_key
;
74 // Chrome version string. Sending the version string over IPC avoids linkage
75 // issues in cases where NaCl is not compiled into the main Chromium
79 bool enable_debug_stub
;
80 bool enable_ipc_proxy
;
82 // Enables plugin code to use Mojo APIs. See mojo/nacl for details.
85 NaClAppProcessType process_type
;
87 // For NaCl <-> renderer crash information reporting.
88 base::SharedMemoryHandle crash_info_shmem_handle
;
90 // NOTE: Any new fields added here must also be added to the IPC
91 // serialization in nacl_messages.h and (for POD fields) the constructor
95 // Parameters sent to the browser process to have it launch a NaCl process.
97 // If you change this, you will also need to update the IPC serialization in
98 // nacl_host_messages.h.
99 struct NaClLaunchParams
{
101 NaClLaunchParams(const std::string
& manifest_url
,
102 const IPC::PlatformFileForTransit
& nexe_file
,
103 uint64_t nexe_token_lo
,
104 uint64_t nexe_token_hi
,
106 uint32 permission_bits
,
107 bool uses_nonsfi_mode
,
108 NaClAppProcessType process_type
);
111 std::string manifest_url
;
112 // On Windows, the HANDLE passed here is valid in the renderer's context.
113 // It's the responsibility of the browser to duplicate this handle properly
114 // for passing it to the plugin.
115 IPC::PlatformFileForTransit nexe_file
;
116 uint64_t nexe_token_lo
;
117 uint64_t nexe_token_hi
;
120 uint32 permission_bits
;
121 bool uses_nonsfi_mode
;
123 NaClAppProcessType process_type
;
126 struct NaClLaunchResult
{
129 FileDescriptor imc_channel_handle
,
130 const IPC::ChannelHandle
& ppapi_ipc_channel_handle
,
131 const IPC::ChannelHandle
& trusted_ipc_channel_handle
,
132 const IPC::ChannelHandle
& manifest_service_ipc_channel_handle
,
133 base::ProcessId plugin_pid
,
135 base::SharedMemoryHandle crash_info_shmem_handle
);
138 // For plugin loader <-> renderer IMC communication.
139 FileDescriptor imc_channel_handle
;
141 // For plugin <-> renderer PPAPI communication.
142 IPC::ChannelHandle ppapi_ipc_channel_handle
;
144 // For plugin loader <-> renderer control communication (loading and
146 IPC::ChannelHandle trusted_ipc_channel_handle
;
148 // For plugin <-> renderer ManifestService communication.
149 IPC::ChannelHandle manifest_service_ipc_channel_handle
;
151 base::ProcessId plugin_pid
;
154 // For NaCl <-> renderer crash information reporting.
155 base::SharedMemoryHandle crash_info_shmem_handle
;
160 #endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_