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 request to prefetch a file that's listed in the "files" section
62 // of a NaCl manifest file.
63 struct NaClResourcePrefetchRequest
{
64 NaClResourcePrefetchRequest();
65 NaClResourcePrefetchRequest(const std::string
& file_key
,
66 const std::string
& resource_url
);
67 ~NaClResourcePrefetchRequest();
69 std::string file_key
; // a key for open_resource.
70 std::string resource_url
;
73 // Represents a single prefetched file that's listed in the "files" section of
74 // a NaCl manifest file.
75 struct NaClResourcePrefetchResult
{
76 NaClResourcePrefetchResult();
77 NaClResourcePrefetchResult(IPC::PlatformFileForTransit file
,
78 const base::FilePath
& file_path
,
79 const std::string
& file_key
);
80 ~NaClResourcePrefetchResult();
82 IPC::PlatformFileForTransit file
;
83 base::FilePath file_path_metadata
; // a key for validation caching
84 std::string file_key
; // a key for open_resource
87 // Parameters sent to the NaCl process when we start it.
88 struct NaClStartParams
{
92 IPC::PlatformFileForTransit nexe_file
;
93 // Used only as a key for validation caching.
94 base::FilePath nexe_file_path_metadata
;
96 std::vector
<NaClResourcePrefetchResult
> prefetched_resource_files
;
97 IPC::PlatformFileForTransit imc_bootstrap_handle
;
98 IPC::PlatformFileForTransit irt_handle
;
99 #if defined(OS_MACOSX)
100 IPC::PlatformFileForTransit mac_shm_fd
;
102 #if defined(OS_POSIX)
103 IPC::PlatformFileForTransit debug_stub_server_bound_socket
;
106 bool validation_cache_enabled
;
107 std::string validation_cache_key
;
108 // Chrome version string. Sending the version string over IPC avoids linkage
109 // issues in cases where NaCl is not compiled into the main Chromium
110 // executable or DLL.
113 bool enable_debug_stub
;
114 bool enable_ipc_proxy
;
116 NaClAppProcessType process_type
;
118 // For NaCl <-> renderer crash information reporting.
119 base::SharedMemoryHandle crash_info_shmem_handle
;
121 // NOTE: Any new fields added here must also be added to the IPC
122 // serialization in nacl_messages.h and (for POD fields) the constructor
126 // Parameters sent to the browser process to have it launch a NaCl process.
128 // If you change this, you will also need to update the IPC serialization in
129 // nacl_host_messages.h.
130 struct NaClLaunchParams
{
133 const std::string
& manifest_url
,
134 const IPC::PlatformFileForTransit
& nexe_file
,
135 uint64_t nexe_token_lo
,
136 uint64_t nexe_token_hi
,
138 NaClResourcePrefetchRequest
>& resource_prefetch_request_list
,
140 uint32 permission_bits
,
141 bool uses_nonsfi_mode
,
142 NaClAppProcessType process_type
);
145 std::string manifest_url
;
146 // On Windows, the HANDLE passed here is valid in the renderer's context.
147 // It's the responsibility of the browser to duplicate this handle properly
148 // for passing it to the plugin.
149 IPC::PlatformFileForTransit nexe_file
;
150 uint64_t nexe_token_lo
;
151 uint64_t nexe_token_hi
;
152 std::vector
<NaClResourcePrefetchRequest
> resource_prefetch_request_list
;
155 uint32 permission_bits
;
156 bool uses_nonsfi_mode
;
158 NaClAppProcessType process_type
;
161 struct NaClLaunchResult
{
164 FileDescriptor imc_channel_handle
,
165 const IPC::ChannelHandle
& ppapi_ipc_channel_handle
,
166 const IPC::ChannelHandle
& trusted_ipc_channel_handle
,
167 const IPC::ChannelHandle
& manifest_service_ipc_channel_handle
,
168 base::ProcessId plugin_pid
,
170 base::SharedMemoryHandle crash_info_shmem_handle
);
173 // For plugin loader <-> renderer IMC communication.
174 FileDescriptor imc_channel_handle
;
176 // For plugin <-> renderer PPAPI communication.
177 IPC::ChannelHandle ppapi_ipc_channel_handle
;
179 // For plugin loader <-> renderer control communication (loading and
181 IPC::ChannelHandle trusted_ipc_channel_handle
;
183 // For plugin <-> renderer ManifestService communication.
184 IPC::ChannelHandle manifest_service_ipc_channel_handle
;
186 base::ProcessId plugin_pid
;
189 // For NaCl <-> renderer crash information reporting.
190 base::SharedMemoryHandle crash_info_shmem_handle
;
195 #endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_