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_
12 #include "base/basictypes.h"
13 #include "base/memory/shared_memory.h"
14 #include "base/process/process_handle.h"
15 #include "build/build_config.h"
16 #include "ipc/ipc_channel.h"
17 #include "ipc/ipc_platform_file.h"
20 #include "base/file_descriptor_posix.h"
24 #include <windows.h> // for HANDLE
27 // TODO(gregoryd): add a Windows definition for base::FileDescriptor
31 typedef HANDLE FileDescriptor
;
32 inline HANDLE
ToNativeHandle(const FileDescriptor
& desc
) {
35 #elif defined(OS_POSIX)
36 typedef base::FileDescriptor FileDescriptor
;
37 inline int ToNativeHandle(const FileDescriptor
& desc
) {
42 // We allocate a page of shared memory for sharing crash information from
43 // trusted code in the NaCl process to the renderer.
44 static const int kNaClCrashInfoShmemSize
= 4096;
45 static const int kNaClCrashInfoMaxLogSize
= 1024;
47 // Types of untrusted NaCl processes.
48 enum NaClAppProcessType
{
49 kUnknownNaClProcessType
,
50 // Runs user-provided *native* code. Enabled for Chrome Web Store apps.
51 kNativeNaClProcessType
,
52 // Runs user-provided code that is translated from *bitcode* by an
53 // in-browser PNaCl translator.
55 // Runs pnacl-llc/linker *native* code. These nexes are browser-provided
56 // (not user-provided).
57 kPNaClTranslatorProcessType
,
61 // Represents a single prefetched file that's listed in the "files" section of
62 // a NaCl manifest file.
63 struct NaClResourceFileInfo
{
64 NaClResourceFileInfo();
65 NaClResourceFileInfo(IPC::PlatformFileForTransit file
,
66 const base::FilePath
& file_path
,
67 const std::string
& file_key
);
68 ~NaClResourceFileInfo();
70 IPC::PlatformFileForTransit file
;
71 base::FilePath file_path_metadata
; // a key for validation caching
72 std::string file_key
; // a key for open_resource
75 // Parameters sent to the NaCl process when we start it.
76 struct NaClStartParams
{
80 IPC::PlatformFileForTransit nexe_file
;
81 // Used only as a key for validation caching.
82 base::FilePath nexe_file_path_metadata
;
84 std::vector
<NaClResourceFileInfo
> prefetched_resource_files
;
85 std::vector
<FileDescriptor
> handles
;
86 FileDescriptor debug_stub_server_bound_socket
;
88 bool validation_cache_enabled
;
89 std::string validation_cache_key
;
90 // Chrome version string. Sending the version string over IPC avoids linkage
91 // issues in cases where NaCl is not compiled into the main Chromium
95 bool enable_debug_stub
;
96 bool enable_ipc_proxy
;
98 // Enables plugin code to use Mojo APIs. See mojo/nacl for details.
101 NaClAppProcessType process_type
;
103 // For NaCl <-> renderer crash information reporting.
104 base::SharedMemoryHandle crash_info_shmem_handle
;
106 // NOTE: Any new fields added here must also be added to the IPC
107 // serialization in nacl_messages.h and (for POD fields) the constructor
111 // Parameters sent to the browser process to have it launch a NaCl process.
113 // If you change this, you will also need to update the IPC serialization in
114 // nacl_host_messages.h.
115 struct NaClLaunchParams
{
118 const std::string
& manifest_url
,
119 const IPC::PlatformFileForTransit
& nexe_file
,
120 uint64_t nexe_token_lo
,
121 uint64_t nexe_token_hi
,
122 // A pair of a manifest key and its resource URL.
124 std::pair
<std::string
, std::string
> >& resource_files_to_prefetch
,
126 uint32 permission_bits
,
127 bool uses_nonsfi_mode
,
128 NaClAppProcessType process_type
);
131 std::string manifest_url
;
132 // On Windows, the HANDLE passed here is valid in the renderer's context.
133 // It's the responsibility of the browser to duplicate this handle properly
134 // for passing it to the plugin.
135 IPC::PlatformFileForTransit nexe_file
;
136 uint64_t nexe_token_lo
;
137 uint64_t nexe_token_hi
;
138 std::vector
<std::pair
<std::string
, std::string
> > resource_files_to_prefetch
;
141 uint32 permission_bits
;
142 bool uses_nonsfi_mode
;
144 NaClAppProcessType process_type
;
147 struct NaClLaunchResult
{
150 FileDescriptor imc_channel_handle
,
151 const IPC::ChannelHandle
& ppapi_ipc_channel_handle
,
152 const IPC::ChannelHandle
& trusted_ipc_channel_handle
,
153 const IPC::ChannelHandle
& manifest_service_ipc_channel_handle
,
154 base::ProcessId plugin_pid
,
156 base::SharedMemoryHandle crash_info_shmem_handle
);
159 // For plugin loader <-> renderer IMC communication.
160 FileDescriptor imc_channel_handle
;
162 // For plugin <-> renderer PPAPI communication.
163 IPC::ChannelHandle ppapi_ipc_channel_handle
;
165 // For plugin loader <-> renderer control communication (loading and
167 IPC::ChannelHandle trusted_ipc_channel_handle
;
169 // For plugin <-> renderer ManifestService communication.
170 IPC::ChannelHandle manifest_service_ipc_channel_handle
;
172 base::ProcessId plugin_pid
;
175 // For NaCl <-> renderer crash information reporting.
176 base::SharedMemoryHandle crash_info_shmem_handle
;
181 #endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_