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"
21 // We allocate a page of shared memory for sharing crash information from
22 // trusted code in the NaCl process to the renderer.
23 static const int kNaClCrashInfoShmemSize
= 4096;
24 static const int kNaClCrashInfoMaxLogSize
= 1024;
26 // Types of untrusted NaCl processes.
27 enum NaClAppProcessType
{
28 kUnknownNaClProcessType
,
29 // Runs user-provided *native* code. Enabled for Chrome Web Store apps.
30 kNativeNaClProcessType
,
31 // Runs user-provided code that is translated from *bitcode* by an
32 // in-browser PNaCl translator.
34 // Runs pnacl-llc/linker *native* code. These nexes are browser-provided
35 // (not user-provided).
36 kPNaClTranslatorProcessType
,
40 // Represents a request to prefetch a file that's listed in the "files" section
41 // of a NaCl manifest file.
42 struct NaClResourcePrefetchRequest
{
43 NaClResourcePrefetchRequest();
44 NaClResourcePrefetchRequest(const std::string
& file_key
,
45 const std::string
& resource_url
);
46 ~NaClResourcePrefetchRequest();
48 std::string file_key
; // a key for open_resource.
49 std::string resource_url
;
52 // Represents a single prefetched file that's listed in the "files" section of
53 // a NaCl manifest file.
54 struct NaClResourcePrefetchResult
{
55 NaClResourcePrefetchResult();
56 NaClResourcePrefetchResult(const IPC::PlatformFileForTransit
& file
,
57 const base::FilePath
& file_path
,
58 const std::string
& file_key
);
59 ~NaClResourcePrefetchResult();
61 IPC::PlatformFileForTransit file
;
62 base::FilePath file_path_metadata
; // a key for validation caching
63 std::string file_key
; // a key for open_resource
66 // Parameters sent to the NaCl process when we start it.
67 struct NaClStartParams
{
71 IPC::PlatformFileForTransit nexe_file
;
72 // Used only as a key for validation caching.
73 base::FilePath nexe_file_path_metadata
;
75 IPC::PlatformFileForTransit imc_bootstrap_handle
;
76 IPC::PlatformFileForTransit irt_handle
;
77 #if defined(OS_MACOSX)
78 IPC::PlatformFileForTransit mac_shm_fd
;
81 IPC::PlatformFileForTransit debug_stub_server_bound_socket
;
84 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI)
85 // These are for Non-SFI mode IPC channels.
86 // For security hardening, unlike in SFI mode, we cannot create socket pairs
87 // in a NaCl loader process. Thus, the browser process creates the
88 // ChannelHandle instances, and passes them to the NaCl loader process.
89 // SFI mode uses NaClProcessHostMsg_PpapiChannelsCreated instead.
90 IPC::ChannelHandle ppapi_browser_channel_handle
;
91 IPC::ChannelHandle ppapi_renderer_channel_handle
;
92 IPC::ChannelHandle trusted_service_channel_handle
;
93 IPC::ChannelHandle manifest_service_channel_handle
;
96 bool validation_cache_enabled
;
97 std::string validation_cache_key
;
98 // Chrome version string. Sending the version string over IPC avoids linkage
99 // issues in cases where NaCl is not compiled into the main Chromium
100 // executable or DLL.
103 bool enable_debug_stub
;
104 bool enable_ipc_proxy
;
106 NaClAppProcessType process_type
;
108 // For NaCl <-> renderer crash information reporting.
109 base::SharedMemoryHandle crash_info_shmem_handle
;
111 // NOTE: Any new fields added here must also be added to the IPC
112 // serialization in nacl_messages.h and (for POD fields) the constructor
116 // Parameters sent to the browser process to have it launch a NaCl process.
118 // If you change this, you will also need to update the IPC serialization in
119 // nacl_host_messages.h.
120 struct NaClLaunchParams
{
123 const std::string
& manifest_url
,
124 const IPC::PlatformFileForTransit
& nexe_file
,
125 uint64_t nexe_token_lo
,
126 uint64_t nexe_token_hi
,
128 NaClResourcePrefetchRequest
>& resource_prefetch_request_list
,
130 uint32 permission_bits
,
131 bool uses_nonsfi_mode
,
132 NaClAppProcessType process_type
);
135 std::string manifest_url
;
136 // On Windows, the HANDLE passed here is valid in the renderer's context.
137 // It's the responsibility of the browser to duplicate this handle properly
138 // for passing it to the plugin.
139 IPC::PlatformFileForTransit nexe_file
;
140 uint64_t nexe_token_lo
;
141 uint64_t nexe_token_hi
;
142 std::vector
<NaClResourcePrefetchRequest
> resource_prefetch_request_list
;
145 uint32 permission_bits
;
146 bool uses_nonsfi_mode
;
148 NaClAppProcessType process_type
;
151 struct NaClLaunchResult
{
154 const IPC::PlatformFileForTransit
& imc_channel_handle
,
155 const IPC::ChannelHandle
& ppapi_ipc_channel_handle
,
156 const IPC::ChannelHandle
& trusted_ipc_channel_handle
,
157 const IPC::ChannelHandle
& manifest_service_ipc_channel_handle
,
158 base::ProcessId plugin_pid
,
160 base::SharedMemoryHandle crash_info_shmem_handle
);
163 // For plugin loader <-> renderer IMC communication.
164 IPC::PlatformFileForTransit imc_channel_handle
;
166 // For plugin <-> renderer PPAPI communication.
167 IPC::ChannelHandle ppapi_ipc_channel_handle
;
169 // For plugin loader <-> renderer control communication (loading and
171 IPC::ChannelHandle trusted_ipc_channel_handle
;
173 // For plugin <-> renderer ManifestService communication.
174 IPC::ChannelHandle manifest_service_ipc_channel_handle
;
176 base::ProcessId plugin_pid
;
179 // For NaCl <-> renderer crash information reporting.
180 base::SharedMemoryHandle crash_info_shmem_handle
;
185 #endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_