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. 4 5#ifndef COMPONENTS_NACL_COMMON_NACL_TYPES_H_ 6#define COMPONENTS_NACL_COMMON_NACL_TYPES_H_ 7 8#include <string> 9#include <vector> 10 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" 17 18#if defined(OS_POSIX) 19#include "base/file_descriptor_posix.h" 20#endif 21 22#if defined(OS_WIN) 23#include <windows.h> // for HANDLE 24#endif 25 26// TODO(gregoryd): add a Windows definition for base::FileDescriptor 27namespace nacl { 28 29#if defined(OS_WIN) 30typedef HANDLE FileDescriptor; 31inline HANDLE ToNativeHandle(const FileDescriptor& desc) { 32 return desc; 33} 34#elif defined(OS_POSIX) 35typedef base::FileDescriptor FileDescriptor; 36inline int ToNativeHandle(const FileDescriptor& desc) { 37 return desc.fd; 38} 39#endif 40 41// We allocate a page of shared memory for sharing crash information from 42// trusted code in the NaCl process to the renderer. 43static const int kNaClCrashInfoShmemSize = 4096; 44static const int kNaClCrashInfoMaxLogSize = 1024; 45 46// Parameters sent to the NaCl process when we start it. 47struct NaClStartParams { 48 NaClStartParams(); 49 ~NaClStartParams(); 50 51 IPC::PlatformFileForTransit nexe_file; 52 uint64_t nexe_token_lo; 53 uint64_t nexe_token_hi; 54 55 std::vector<FileDescriptor> handles; 56 FileDescriptor debug_stub_server_bound_socket; 57 58 bool validation_cache_enabled; 59 std::string validation_cache_key; 60 // Chrome version string. Sending the version string over IPC avoids linkage 61 // issues in cases where NaCl is not compiled into the main Chromium 62 // executable or DLL. 63 std::string version; 64 65 bool enable_exception_handling; 66 bool enable_debug_stub; 67 bool enable_ipc_proxy; 68 bool uses_irt; 69 bool enable_dyncode_syscalls; 70 71 // For NaCl <-> renderer crash information reporting. 72 base::SharedMemoryHandle crash_info_shmem_handle; 73 74 // NOTE: Any new fields added here must also be added to the IPC 75 // serialization in nacl_messages.h and (for POD fields) the constructor 76 // in nacl_types.cc. 77}; 78 79// Parameters sent to the browser process to have it launch a NaCl process. 80// 81// If you change this, you will also need to update the IPC serialization in 82// nacl_host_messages.h. 83struct NaClLaunchParams { 84 NaClLaunchParams(); 85 NaClLaunchParams(const std::string& manifest_url, 86 const IPC::PlatformFileForTransit& nexe_file, 87 uint64_t nexe_token_lo, 88 uint64_t nexe_token_hi, 89 int render_view_id, 90 uint32 permission_bits, 91 bool uses_irt, 92 bool uses_nonsfi_mode, 93 bool enable_dyncode_syscalls, 94 bool enable_exception_handling, 95 bool enable_crash_throttling); 96 ~NaClLaunchParams(); 97 98 std::string manifest_url; 99 // On Windows, the HANDLE passed here is valid in the renderer's context. 100 // It's the responsibility of the browser to duplicate this handle properly 101 // for passing it to the plugin. 102 IPC::PlatformFileForTransit nexe_file; 103 uint64_t nexe_token_lo; 104 uint64_t nexe_token_hi; 105 106 int render_view_id; 107 uint32 permission_bits; 108 bool uses_irt; 109 bool uses_nonsfi_mode; 110 bool enable_dyncode_syscalls; 111 bool enable_exception_handling; 112 bool enable_crash_throttling; 113}; 114 115struct NaClLaunchResult { 116 NaClLaunchResult(); 117 NaClLaunchResult( 118 FileDescriptor imc_channel_handle, 119 const IPC::ChannelHandle& ppapi_ipc_channel_handle, 120 const IPC::ChannelHandle& trusted_ipc_channel_handle, 121 const IPC::ChannelHandle& manifest_service_ipc_channel_handle, 122 base::ProcessId plugin_pid, 123 int plugin_child_id, 124 base::SharedMemoryHandle crash_info_shmem_handle); 125 ~NaClLaunchResult(); 126 127 // For plugin loader <-> renderer IMC communication. 128 FileDescriptor imc_channel_handle; 129 130 // For plugin <-> renderer PPAPI communication. 131 IPC::ChannelHandle ppapi_ipc_channel_handle; 132 133 // For plugin loader <-> renderer control communication (loading and 134 // starting nexe). 135 IPC::ChannelHandle trusted_ipc_channel_handle; 136 137 // For plugin <-> renderer ManifestService communication. 138 IPC::ChannelHandle manifest_service_ipc_channel_handle; 139 140 base::ProcessId plugin_pid; 141 int plugin_child_id; 142 143 // For NaCl <-> renderer crash information reporting. 144 base::SharedMemoryHandle crash_info_shmem_handle; 145}; 146 147} // namespace nacl 148 149#endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_ 150