diff options
author | yael.aharon@intel.com <yael.aharon@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 20:24:00 +0000 |
---|---|---|
committer | yael.aharon@intel.com <yael.aharon@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 20:24:00 +0000 |
commit | 512b5bd88c595d07b361c50cad628ca461e3357d (patch) | |
tree | fa5a6078f1db6344c19908ea0b1c6e6e3cecc17b /components | |
parent | 19e9de23d24e0831f19291fd449c7760a6c1ec13 (diff) | |
download | chromium_src-512b5bd88c595d07b361c50cad628ca461e3357d.zip chromium_src-512b5bd88c595d07b361c50cad628ca461e3357d.tar.gz chromium_src-512b5bd88c595d07b361c50cad628ca461e3357d.tar.bz2 |
Move common files from chrome/common to components/nacl/common.
This is part of an effort to componentize nacl code.
BUG=244791
Review URL: https://chromiumcodereview.appspot.com/19833004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r-- | components/nacl/common/DEPS | 3 | ||||
-rw-r--r-- | components/nacl/common/OWNERS | 10 | ||||
-rw-r--r-- | components/nacl/common/nacl_debug_exception_handler_win.cc | 78 | ||||
-rw-r--r-- | components/nacl/common/nacl_debug_exception_handler_win.h | 18 | ||||
-rw-r--r-- | components/nacl/common/nacl_helper_linux.h | 42 | ||||
-rw-r--r-- | components/nacl/common/nacl_host_messages.h | 98 | ||||
-rw-r--r-- | components/nacl/common/nacl_messages.cc | 34 | ||||
-rw-r--r-- | components/nacl/common/nacl_messages.h | 94 | ||||
-rw-r--r-- | components/nacl/common/nacl_paths.cc | 53 | ||||
-rw-r--r-- | components/nacl/common/nacl_paths.h | 31 | ||||
-rw-r--r-- | components/nacl/common/nacl_types.cc | 77 | ||||
-rw-r--r-- | components/nacl/common/nacl_types.h | 101 | ||||
-rw-r--r-- | components/nacl/common/pnacl_types.cc | 12 | ||||
-rw-r--r-- | components/nacl/common/pnacl_types.h | 33 | ||||
-rw-r--r-- | components/nacl_common.gyp | 8 |
15 files changed, 692 insertions, 0 deletions
diff --git a/components/nacl/common/DEPS b/components/nacl/common/DEPS new file mode 100644 index 0000000..9583dc6 --- /dev/null +++ b/components/nacl/common/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+native_client/src", +] diff --git a/components/nacl/common/OWNERS b/components/nacl/common/OWNERS new file mode 100644 index 0000000..6a8067ec --- /dev/null +++ b/components/nacl/common/OWNERS @@ -0,0 +1,10 @@ +# Changes to IPC messages require a security review to avoid introducing +# new sandbox escapes. +per-file *_messages*.h=set noparent +per-file *_messages*.h=cdn@chromium.org +per-file *_messages*.h=cevans@chromium.org +per-file *_messages*.h=jln@chromium.org +per-file *_messages*.h=jschuh@chromium.org +per-file *_messages*.h=palmer@chromium.org +per-file *_messages*.h=tsepez@chromium.org + diff --git a/components/nacl/common/nacl_debug_exception_handler_win.cc b/components/nacl/common/nacl_debug_exception_handler_win.cc new file mode 100644 index 0000000..f661391 --- /dev/null +++ b/components/nacl/common/nacl_debug_exception_handler_win.cc @@ -0,0 +1,78 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/nacl/common/nacl_debug_exception_handler_win.h" + +#include "base/bind.h" +#include "base/threading/platform_thread.h" +#include "base/win/scoped_handle.h" +#include "native_client/src/trusted/service_runtime/win/debug_exception_handler.h" + +namespace { + +class DebugExceptionHandler : public base::PlatformThread::Delegate { + public: + DebugExceptionHandler(base::ProcessHandle nacl_process, + const std::string& startup_info, + base::MessageLoopProxy* message_loop, + const base::Callback<void(bool)>& on_connected) + : nacl_process_(nacl_process), + startup_info_(startup_info), + message_loop_(message_loop), + on_connected_(on_connected) { + } + + virtual void ThreadMain() OVERRIDE { + // In the Windows API, the set of processes being debugged is + // thread-local, so we have to attach to the process (using + // DebugActiveProcess()) on the same thread on which + // NaClDebugExceptionHandlerRun() receives debug events for the + // process. + bool attached = false; + int pid = GetProcessId(nacl_process_); + if (pid == 0) { + LOG(ERROR) << "Invalid process handle"; + } else { + if (!DebugActiveProcess(pid)) { + LOG(ERROR) << "Failed to connect to the process"; + } else { + attached = true; + } + } + message_loop_->PostTask(FROM_HERE, base::Bind(on_connected_, attached)); + + if (attached) { + NaClDebugExceptionHandlerRun( + nacl_process_, + reinterpret_cast<const void*>(startup_info_.data()), + startup_info_.size()); + } + delete this; + } + + private: + base::win::ScopedHandle nacl_process_; + std::string startup_info_; + base::MessageLoopProxy* message_loop_; + base::Callback<void(bool)> on_connected_; + + DISALLOW_COPY_AND_ASSIGN(DebugExceptionHandler); +}; + +} // namespace + +void NaClStartDebugExceptionHandlerThread( + base::ProcessHandle nacl_process, + const std::string& startup_info, + base::MessageLoopProxy* message_loop, + const base::Callback<void(bool)>& on_connected) { + // The new PlatformThread will take ownership of the + // DebugExceptionHandler object, which will delete itself on exit. + DebugExceptionHandler* handler = new DebugExceptionHandler( + nacl_process, startup_info, message_loop, on_connected); + if (!base::PlatformThread::CreateNonJoinable(0, handler)) { + on_connected.Run(false); + delete handler; + } +} diff --git a/components/nacl/common/nacl_debug_exception_handler_win.h b/components/nacl/common/nacl_debug_exception_handler_win.h new file mode 100644 index 0000000..42beefe --- /dev/null +++ b/components/nacl/common/nacl_debug_exception_handler_win.h @@ -0,0 +1,18 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_NACL_COMMON_NACL_DEBUG_EXCEPTION_HANDLER_WIN_H_ +#define COMPONENTS_NACL_COMMON_NACL_DEBUG_EXCEPTION_HANDLER_WIN_H_ + +#include "base/callback.h" +#include "base/message_loop/message_loop.h" +#include "base/process/process.h" + +void NaClStartDebugExceptionHandlerThread( + base::ProcessHandle nacl_process, + const std::string& startup_info, + base::MessageLoopProxy* message_loop, + const base::Callback<void(bool)>& on_connected); + +#endif // COMPONENTS_NACL_COMMON_NACL_DEBUG_EXCEPTION_HANDLER_WIN_H_ diff --git a/components/nacl/common/nacl_helper_linux.h b/components/nacl/common/nacl_helper_linux.h new file mode 100644 index 0000000..732b215 --- /dev/null +++ b/components/nacl/common/nacl_helper_linux.h @@ -0,0 +1,42 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_NACL_COMMON_NACL_HELPER_LINUX_H_ +#define COMPONENTS_NACL_COMMON_NACL_HELPER_LINUX_H_ + +// A mini-zygote specifically for Native Client. This file defines +// constants used to implement communication between the nacl_helper +// process and the Chrome zygote. + +// Used by Helper to tell Zygote it has started successfully. +#define kNaClHelperStartupAck "NACLHELPER_OK" +// Used by Zygote to ask Helper to fork a new NaCl loader. +#define kNaClForkRequest "NACLFORK" + +// The next set of constants define global Linux file descriptors. +// For communications between NaCl loader and browser. +// See also content/common/zygote_main_linux.cc and +// http://code.google.com/p/chromium/wiki/LinuxZygote + +// For communications between NaCl loader and zygote. +#define kNaClZygoteDescriptor 3 +// For communications between the NaCl loader process and +// the SUID sandbox. +#define kNaClSandboxDescriptor 5 +// NOTE: kNaClSandboxDescriptor must match +// content/browser/zygote_main_linux.cc +// kMagicSandboxIPCDescriptor. + +// A fork request from the Zygote to the helper includes an array +// of three file descriptors. These constants are used as indicies +// into the array. +// Used to pass in the descriptor for talking to the Browser +#define kNaClBrowserFDIndex 0 +// The next two are used in the protocol for discovering the +// child processes real PID from within the SUID sandbox. See +// http://code.google.com/p/chromium/wiki/LinuxZygote +#define kNaClDummyFDIndex 1 +#define kNaClParentFDIndex 2 + +#endif // COMPONENTS_NACL_COMMON_NACL_HELPER_LINUX_H_ diff --git a/components/nacl/common/nacl_host_messages.h b/components/nacl/common/nacl_host_messages.h new file mode 100644 index 0000000..0f3df7e --- /dev/null +++ b/components/nacl/common/nacl_host_messages.h @@ -0,0 +1,98 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Multiply-included file, no traditional include guard. + +#include <string> + +#include "base/basictypes.h" +#include "base/process/process.h" +#include "build/build_config.h" +#include "components/nacl/common/nacl_types.h" +#include "components/nacl/common/pnacl_types.h" +#include "content/public/common/common_param_traits.h" +#include "ipc/ipc_channel_handle.h" +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_platform_file.h" +#include "url/gurl.h" + +#define IPC_MESSAGE_START NaClHostMsgStart + +IPC_STRUCT_TRAITS_BEGIN(nacl::NaClLaunchParams) + IPC_STRUCT_TRAITS_MEMBER(manifest_url) + IPC_STRUCT_TRAITS_MEMBER(render_view_id) + IPC_STRUCT_TRAITS_MEMBER(permission_bits) + IPC_STRUCT_TRAITS_MEMBER(uses_irt) + IPC_STRUCT_TRAITS_MEMBER(enable_dyncode_syscalls) + IPC_STRUCT_TRAITS_MEMBER(enable_exception_handling) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(nacl::NaClLaunchResult) + IPC_STRUCT_TRAITS_MEMBER(imc_channel_handle) + IPC_STRUCT_TRAITS_MEMBER(ipc_channel_handle) + IPC_STRUCT_TRAITS_MEMBER(plugin_pid) + IPC_STRUCT_TRAITS_MEMBER(plugin_child_id) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(nacl::PnaclCacheInfo) + IPC_STRUCT_TRAITS_MEMBER(pexe_url) + IPC_STRUCT_TRAITS_MEMBER(abi_version) + IPC_STRUCT_TRAITS_MEMBER(opt_level) + IPC_STRUCT_TRAITS_MEMBER(last_modified) + IPC_STRUCT_TRAITS_MEMBER(etag) +IPC_STRUCT_TRAITS_END() + +// A renderer sends this to the browser process when it wants to start +// a new instance of the Native Client process. The browser will launch +// the process and return an IPC channel handle. This handle will only +// be valid if the NaCl IPC proxy is enabled. +IPC_SYNC_MESSAGE_CONTROL1_2(NaClHostMsg_LaunchNaCl, + nacl::NaClLaunchParams /* launch_params */, + nacl::NaClLaunchResult /* launch_result */, + std::string /* error_message */) + +// A renderer sends this to the browser process when it wants to +// open a file for from the Pnacl component directory. +IPC_SYNC_MESSAGE_CONTROL1_1(NaClHostMsg_GetReadonlyPnaclFD, + std::string /* name of requested PNaCl file */, + IPC::PlatformFileForTransit /* output file */) + +// A renderer sends this to the browser process when it wants to +// create a temporary file. +IPC_SYNC_MESSAGE_CONTROL0_1(NaClHostMsg_NaClCreateTemporaryFile, + IPC::PlatformFileForTransit /* out file */) + +// A renderer sends this to the browser to request a file descriptor for +// a translated nexe. +IPC_MESSAGE_CONTROL3(NaClHostMsg_NexeTempFileRequest, + int /* render_view_id */, + int /* instance */, + nacl::PnaclCacheInfo /* cache info */) + +// The browser replies to a renderer's temp file request with output_file, +// which is either a writeable temp file to use for translation, or a +// read-only file containing the translated nexe from the cache. +IPC_MESSAGE_CONTROL3(NaClViewMsg_NexeTempFileReply, + int /* instance */, + bool /* is_cache_hit */, + IPC::PlatformFileForTransit /* output file */) + +// A renderer sends this to the browser to report that its translation has +// finished and its temp file contains the translated nexe. +IPC_MESSAGE_CONTROL1(NaClHostMsg_ReportTranslationFinished, + int /* instance */) + +// A renderer sends this to the browser process to report an error. +IPC_MESSAGE_CONTROL2(NaClHostMsg_NaClErrorStatus, + int /* render_view_id */, + int /* Error ID */) + +// A renderer sends this to the browser process when it wants to +// open a NaCl executable file from an installed application directory. +IPC_SYNC_MESSAGE_CONTROL2_3(NaClHostMsg_OpenNaClExecutable, + int /* render_view_id */, + GURL /* URL of NaCl executable file */, + IPC::PlatformFileForTransit /* output file */, + uint64 /* file_token_lo */, + uint64 /* file_token_hi */) diff --git a/components/nacl/common/nacl_messages.cc b/components/nacl/common/nacl_messages.cc new file mode 100644 index 0000000..2140736 --- /dev/null +++ b/components/nacl/common/nacl_messages.cc @@ -0,0 +1,34 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "components/nacl/common/nacl_messages.h" + +// Generate constructors. +#include "ipc/struct_constructor_macros.h" +#include "components/nacl/common/nacl_messages.h" + +// Generate destructors. +#include "ipc/struct_destructor_macros.h" +#include "components/nacl/common/nacl_messages.h" + +// Generate param traits write methods. +#include "ipc/param_traits_write_macros.h" +namespace IPC { +#include "components/nacl/common/nacl_messages.h" +} // namespace IPC + +// Generate param traits read methods. +#include "ipc/param_traits_read_macros.h" +namespace IPC { +#include "components/nacl/common/nacl_messages.h" +} // namespace IPC + +// Generate param traits log methods. +#include "ipc/param_traits_log_macros.h" +namespace IPC { +#include "components/nacl/common/nacl_messages.h" +} // namespace IPC + diff --git a/components/nacl/common/nacl_messages.h b/components/nacl/common/nacl_messages.h new file mode 100644 index 0000000..068a0f9 --- /dev/null +++ b/components/nacl/common/nacl_messages.h @@ -0,0 +1,94 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Defines messages between the browser and NaCl process. + +// Multiply-included message file, no traditional include guard. +#include "base/process/process.h" +#include "components/nacl/common/nacl_types.h" +#include "ipc/ipc_channel_handle.h" +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_platform_file.h" + +#define IPC_MESSAGE_START NaClMsgStart + +IPC_STRUCT_TRAITS_BEGIN(nacl::NaClStartParams) + IPC_STRUCT_TRAITS_MEMBER(handles) + IPC_STRUCT_TRAITS_MEMBER(debug_stub_server_bound_socket) + IPC_STRUCT_TRAITS_MEMBER(validation_cache_enabled) + IPC_STRUCT_TRAITS_MEMBER(validation_cache_key) + IPC_STRUCT_TRAITS_MEMBER(version) + IPC_STRUCT_TRAITS_MEMBER(enable_exception_handling) + IPC_STRUCT_TRAITS_MEMBER(enable_debug_stub) + IPC_STRUCT_TRAITS_MEMBER(enable_ipc_proxy) + IPC_STRUCT_TRAITS_MEMBER(uses_irt) + IPC_STRUCT_TRAITS_MEMBER(enable_dyncode_syscalls) +IPC_STRUCT_TRAITS_END() + +//----------------------------------------------------------------------------- +// NaClProcess messages +// These are messages sent between the browser and the NaCl process. +// Tells the NaCl process to start. +IPC_MESSAGE_CONTROL1(NaClProcessMsg_Start, + nacl::NaClStartParams /* params */) + +#if defined(OS_WIN) +// Tells the NaCl broker to launch a NaCl loader process. +IPC_MESSAGE_CONTROL1(NaClProcessMsg_LaunchLoaderThroughBroker, + std::string /* channel ID for the loader */) + +// Notify the browser process that the loader was launched successfully. +IPC_MESSAGE_CONTROL2(NaClProcessMsg_LoaderLaunched, + std::string, /* channel ID for the loader */ + base::ProcessHandle /* loader process handle */) + +// Tells the NaCl broker to attach a debug exception handler to the +// given NaCl loader process. +IPC_MESSAGE_CONTROL3(NaClProcessMsg_LaunchDebugExceptionHandler, + int32 /* pid of the NaCl process */, + base::ProcessHandle /* handle of the NaCl process */, + std::string /* NaCl internal process layout info */) + +// Notify the browser process that the broker process finished +// attaching a debug exception handler to the given NaCl loader +// process. +IPC_MESSAGE_CONTROL2(NaClProcessMsg_DebugExceptionHandlerLaunched, + int32 /* pid */, + bool /* success */) + +// Notify the broker that all loader processes have been terminated and it +// should shutdown. +IPC_MESSAGE_CONTROL0(NaClProcessMsg_StopBroker) + +// Used by the NaCl process to request that a Windows debug exception +// handler be attached to it. +IPC_SYNC_MESSAGE_CONTROL1_1(NaClProcessMsg_AttachDebugExceptionHandler, + std::string, /* Internal process info */ + bool /* Result */) +#endif + +// Used by the NaCl process to query a database in the browser. The database +// contains the signatures of previously validated code chunks. +IPC_SYNC_MESSAGE_CONTROL1_1(NaClProcessMsg_QueryKnownToValidate, + std::string, /* A validation signature */ + bool /* Can validation be skipped? */) + +// Used by the NaCl process to add a validation signature to the validation +// database in the browser. +IPC_MESSAGE_CONTROL1(NaClProcessMsg_SetKnownToValidate, + std::string /* A validation signature */) + +// Used by the NaCl process to acquire trusted information about a file directly +// from the browser, including the file's path as well as a fresh version of the +// file handle. +IPC_SYNC_MESSAGE_CONTROL2_2(NaClProcessMsg_ResolveFileToken, + uint64, /* file_token_lo */ + uint64, /* file_token_hi */ + IPC::PlatformFileForTransit, /* fd */ + base::FilePath /* Path opened to get fd */) + +// Notify the browser process that the server side of the PPAPI channel was +// created successfully. +IPC_MESSAGE_CONTROL1(NaClProcessHostMsg_PpapiChannelCreated, + IPC::ChannelHandle /* channel_handle */) diff --git a/components/nacl/common/nacl_paths.cc b/components/nacl/common/nacl_paths.cc new file mode 100644 index 0000000..cb046c2 --- /dev/null +++ b/components/nacl/common/nacl_paths.cc @@ -0,0 +1,53 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/nacl/common/nacl_paths.h" + +#include "base/file_util.h" +#include "base/path_service.h" + +namespace { + +#if defined(OS_POSIX) && !defined(OS_MACOSX) +// File name of the nacl_helper and nacl_helper_bootstrap, Linux only. +const base::FilePath::CharType kInternalNaClHelperFileName[] = + FILE_PATH_LITERAL("nacl_helper"); +const base::FilePath::CharType kInternalNaClHelperBootstrapFileName[] = + FILE_PATH_LITERAL("nacl_helper_bootstrap"); +#endif + +} // namespace + +namespace nacl { + +bool PathProvider(int key, base::FilePath* result) { + base::FilePath cur; + switch (key) { +#if defined(OS_LINUX) + case FILE_NACL_HELPER: + if (!PathService::Get(base::DIR_MODULE, &cur)) + return false; + cur = cur.Append(kInternalNaClHelperFileName); + break; + case FILE_NACL_HELPER_BOOTSTRAP: + if (!PathService::Get(base::DIR_MODULE, &cur)) + return false; + cur = cur.Append(kInternalNaClHelperBootstrapFileName); + break; +#endif + default: + return false; + } + + *result = cur; + return true; +} + +// This cannot be done as a static initializer sadly since Visual Studio will +// eliminate this object file if there is no direct entry point into it. +void RegisterPathProvider() { + PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); +} + +} // namespace nacl diff --git a/components/nacl/common/nacl_paths.h b/components/nacl/common/nacl_paths.h new file mode 100644 index 0000000..424d8bd --- /dev/null +++ b/components/nacl/common/nacl_paths.h @@ -0,0 +1,31 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_NACL_COMMON_NACL_PATHS_H_ +#define COMPONENTS_NACL_COMMON_NACL_PATHS_H_ + +#include "build/build_config.h" + +// This file declares path keys for the chrome module. These can be used with +// the PathService to access various special directories and files. + +namespace nacl { + +enum { + PATH_START = 9000, + +#if defined(OS_LINUX) + FILE_NACL_HELPER = PATH_START, // Full path to Linux nacl_helper executable. + FILE_NACL_HELPER_BOOTSTRAP, // ... and nacl_helper_bootstrap executable. +#endif + + PATH_END +}; + +// Call once to register the provider for the path keys defined above. +void RegisterPathProvider(); + +} // namespace nacl + +#endif // COMPONENTS_NACL_COMMON_NACL_PATHS_H_ diff --git a/components/nacl/common/nacl_types.cc b/components/nacl/common/nacl_types.cc new file mode 100644 index 0000000..dea02391 --- /dev/null +++ b/components/nacl/common/nacl_types.cc @@ -0,0 +1,77 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/nacl/common/nacl_types.h" +#include "ipc/ipc_platform_file.h" + +namespace nacl { + +NaClStartParams::NaClStartParams() + : validation_cache_enabled(false), + enable_exception_handling(false), + enable_debug_stub(false), + enable_ipc_proxy(false), + uses_irt(false), + enable_dyncode_syscalls(false) { +} + +NaClStartParams::~NaClStartParams() { +} + +NaClLaunchParams::NaClLaunchParams() + : render_view_id(0), + permission_bits(0), + uses_irt(false), + enable_dyncode_syscalls(false), + enable_exception_handling(false) { +} + +NaClLaunchParams::NaClLaunchParams(const std::string& manifest_url, + int render_view_id, + uint32 permission_bits, + bool uses_irt, + bool enable_dyncode_syscalls, + bool enable_exception_handling) + : manifest_url(manifest_url), + render_view_id(render_view_id), + permission_bits(permission_bits), + uses_irt(uses_irt), + enable_dyncode_syscalls(enable_dyncode_syscalls), + enable_exception_handling(enable_exception_handling) { +} + +NaClLaunchParams::NaClLaunchParams(const NaClLaunchParams& l) { + manifest_url = l.manifest_url; + render_view_id = l.render_view_id; + permission_bits = l.permission_bits; + uses_irt = l.uses_irt; + enable_dyncode_syscalls = l.enable_dyncode_syscalls; + enable_exception_handling = l.enable_exception_handling; +} + +NaClLaunchParams::~NaClLaunchParams() { +} + +NaClLaunchResult::NaClLaunchResult() + : imc_channel_handle(IPC::InvalidPlatformFileForTransit()), + ipc_channel_handle(), + plugin_pid(base::kNullProcessId), + plugin_child_id(0) { +} + +NaClLaunchResult::NaClLaunchResult( + FileDescriptor imc_channel_handle, + const IPC::ChannelHandle& ipc_channel_handle, + base::ProcessId plugin_pid, + int plugin_child_id) + : imc_channel_handle(imc_channel_handle), + ipc_channel_handle(ipc_channel_handle), + plugin_pid(plugin_pid), + plugin_child_id(plugin_child_id) { +} + +NaClLaunchResult::~NaClLaunchResult() { +} + +} // namespace nacl diff --git a/components/nacl/common/nacl_types.h b/components/nacl/common/nacl_types.h new file mode 100644 index 0000000..c1f6943 --- /dev/null +++ b/components/nacl/common/nacl_types.h @@ -0,0 +1,101 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_NACL_COMMON_NACL_TYPES_H_ +#define COMPONENTS_NACL_COMMON_NACL_TYPES_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/process.h" +#include "build/build_config.h" +#include "ipc/ipc_channel.h" + +#if defined(OS_POSIX) +#include "base/file_descriptor_posix.h" +#endif + +#if defined(OS_WIN) +#include <windows.h> // for HANDLE +#endif + +// TODO(gregoryd): add a Windows definition for base::FileDescriptor +namespace nacl { + +#if defined(OS_WIN) +typedef HANDLE FileDescriptor; +inline HANDLE ToNativeHandle(const FileDescriptor& desc) { + return desc; +} +#elif defined(OS_POSIX) +typedef base::FileDescriptor FileDescriptor; +inline int ToNativeHandle(const FileDescriptor& desc) { + return desc.fd; +} +#endif + + +// Parameters sent to the NaCl process when we start it. +// +// If you change this, you will also need to update the IPC serialization in +// nacl_messages.h. +struct NaClStartParams { + NaClStartParams(); + ~NaClStartParams(); + + std::vector<FileDescriptor> handles; + FileDescriptor debug_stub_server_bound_socket; + + bool validation_cache_enabled; + std::string validation_cache_key; + // Chrome version string. Sending the version string over IPC avoids linkage + // issues in cases where NaCl is not compiled into the main Chromium + // executable or DLL. + std::string version; + + bool enable_exception_handling; + bool enable_debug_stub; + bool enable_ipc_proxy; + bool uses_irt; + bool enable_dyncode_syscalls; +}; + +// Parameters sent to the browser process to have it launch a NaCl process. +// +// If you change this, you will also need to update the IPC serialization in +// nacl_host_messages.h. +struct NaClLaunchParams { + NaClLaunchParams(); + NaClLaunchParams(const std::string& u, int r, uint32 p, bool uses_irt, + bool enable_dyncode_syscalls, + bool enable_exception_handling); + NaClLaunchParams(const NaClLaunchParams& l); + ~NaClLaunchParams(); + + std::string manifest_url; + int render_view_id; + uint32 permission_bits; + bool uses_irt; + bool enable_dyncode_syscalls; + bool enable_exception_handling; +}; + +struct NaClLaunchResult { + NaClLaunchResult(); + NaClLaunchResult(FileDescriptor imc_channel_handle, + const IPC::ChannelHandle& ipc_channel_handle, + base::ProcessId plugin_pid, + int plugin_child_id); + ~NaClLaunchResult(); + + FileDescriptor imc_channel_handle; + IPC::ChannelHandle ipc_channel_handle; + base::ProcessId plugin_pid; + int plugin_child_id; +}; + +} // namespace nacl + +#endif // COMPONENTS_NACL_COMMON_NACL_TYPES_H_ diff --git a/components/nacl/common/pnacl_types.cc b/components/nacl/common/pnacl_types.cc new file mode 100644 index 0000000..f6302bc --- /dev/null +++ b/components/nacl/common/pnacl_types.cc @@ -0,0 +1,12 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "components/nacl/common/pnacl_types.h" + +namespace nacl { + +PnaclCacheInfo::PnaclCacheInfo() {} +PnaclCacheInfo::~PnaclCacheInfo() {} + +} // namespace nacl diff --git a/components/nacl/common/pnacl_types.h b/components/nacl/common/pnacl_types.h new file mode 100644 index 0000000..802319b --- /dev/null +++ b/components/nacl/common/pnacl_types.h @@ -0,0 +1,33 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_NACL_COMMON_PNACL_TYPES_H_ +#define COMPONENTS_NACL_COMMON_PNACL_TYPES_H_ + +// This file exists (instead of putting this type into nacl_types.h) because +// nacl_types is built into nacl_helper in addition to chrome, and we don't +// want to pull src/url/ into there, since it would be unnecessary bloat. + +#include "base/time/time.h" +#include "url/gurl.h" + +namespace nacl { +// Cache-related information about pexe files, sent from the plugin/renderer +// to the browser. +// +// If you change this, you will also need to update the IPC serialization in +// nacl_host_messages.h. +struct PnaclCacheInfo { + PnaclCacheInfo(); + ~PnaclCacheInfo(); + GURL pexe_url; + int abi_version; + int opt_level; + base::Time last_modified; + std::string etag; +}; + +} // namespace nacl + +#endif // COMPONENTS_NACL_COMMON_PNACL_TYPES_H_ diff --git a/components/nacl_common.gyp b/components/nacl_common.gyp index 642d61a..1364ef2 100644 --- a/components/nacl_common.gyp +++ b/components/nacl_common.gyp @@ -21,6 +21,10 @@ 'sources': [ 'nacl/common/nacl_cmd_line.cc', 'nacl/common/nacl_cmd_line.h', + 'nacl/common/nacl_messages.cc', + 'nacl/common/nacl_messages.h', + 'nacl/common/nacl_types.cc', + 'nacl/common/nacl_types.h', ], 'include_dirs': [ '..', @@ -52,6 +56,10 @@ 'sources': [ 'nacl/common/nacl_cmd_line.cc', 'nacl/common/nacl_cmd_line.h', + 'nacl/common/nacl_messages.cc', + 'nacl/common/nacl_messages.h', + 'nacl/common/nacl_types.cc', + 'nacl/common/nacl_types.h', ], 'include_dirs': [ '..', |