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 uint64_t nexe_token_lo
;
67 uint64_t nexe_token_hi
;
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 NaClAppProcessType process_type
;
84 // For NaCl <-> renderer crash information reporting.
85 base::SharedMemoryHandle crash_info_shmem_handle
;
87 // NOTE: Any new fields added here must also be added to the IPC
88 // serialization in nacl_messages.h and (for POD fields) the constructor
92 // Parameters sent to the browser process to have it launch a NaCl process.
94 // If you change this, you will also need to update the IPC serialization in
95 // nacl_host_messages.h.
96 struct NaClLaunchParams
{
98 NaClLaunchParams(const std::string
& manifest_url
,
99 const IPC::PlatformFileForTransit
& nexe_file
,
100 uint64_t nexe_token_lo
,
101 uint64_t nexe_token_hi
,
103 uint32 permission_bits
,
104 bool uses_nonsfi_mode
,
105 NaClAppProcessType process_type
);
108 std::string manifest_url
;
109 // On Windows, the HANDLE passed here is valid in the renderer's context.
110 // It's the responsibility of the browser to duplicate this handle properly
111 // for passing it to the plugin.
112 IPC::PlatformFileForTransit nexe_file
;
113 uint64_t nexe_token_lo
;
114 uint64_t nexe_token_hi
;
117 uint32 permission_bits
;
118 bool uses_nonsfi_mode
;
120 NaClAppProcessType process_type
;
123 struct NaClLaunchResult
{
126 FileDescriptor imc_channel_handle
,
127 const IPC::ChannelHandle
& ppapi_ipc_channel_handle
,
128 const IPC::ChannelHandle
& trusted_ipc_channel_handle
,
129 const IPC::ChannelHandle
& manifest_service_ipc_channel_handle
,
130 base::ProcessId plugin_pid
,
132 base::SharedMemoryHandle crash_info_shmem_handle
);
135 // For plugin loader <-> renderer IMC communication.
136 FileDescriptor imc_channel_handle
;
138 // For plugin <-> renderer PPAPI communication.
139 IPC::ChannelHandle ppapi_ipc_channel_handle
;
141 // For plugin loader <-> renderer control communication (loading and
143 IPC::ChannelHandle trusted_ipc_channel_handle
;
145 // For plugin <-> renderer ManifestService communication.
146 IPC::ChannelHandle manifest_service_ipc_channel_handle
;
148 base::ProcessId plugin_pid
;
151 // For NaCl <-> renderer crash information reporting.
152 base::SharedMemoryHandle crash_info_shmem_handle
;
157 #endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_