diff options
Diffstat (limited to 'chromium/components/nacl/common')
21 files changed, 942 insertions, 0 deletions
diff --git a/chromium/components/nacl/common/DEPS b/chromium/components/nacl/common/DEPS new file mode 100644 index 00000000000..9583dc6ba82 --- /dev/null +++ b/chromium/components/nacl/common/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+native_client/src", +] diff --git a/chromium/components/nacl/common/OWNERS b/chromium/components/nacl/common/OWNERS new file mode 100644 index 00000000000..6a8067ecf2f --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_browser_delegate.h b/chromium/components/nacl/common/nacl_browser_delegate.h new file mode 100644 index 00000000000..6cff071716e --- /dev/null +++ b/chromium/components/nacl/common/nacl_browser_delegate.h @@ -0,0 +1,66 @@ +// 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_BROWSER_DELEGATE_H_ +#define COMPONENTS_NACL_COMMON_NACL_BROWSER_DELEGATE_H_ + +#include <string> + +#include "base/callback_forward.h" + +namespace base { +class FilePath; +} + +namespace ppapi { +namespace host { +class HostFactory; +} +} + +namespace content { +class BrowserPpapiHost; +} + +// Encapsulates the dependencies of NaCl code on chrome/, to avoid a direct +// dependency on chrome/. +class NaClBrowserDelegate { + public: + virtual ~NaClBrowserDelegate() {} + + // Show an infobar to the user. + virtual void ShowNaClInfobar(int render_process_id, int render_view_id, + int error_id) = 0; + // Returns whether dialogs are allowed. This is used to decide if to add the + // command line switch kNoErrorDialogs. + virtual bool DialogsAreSuppressed() = 0; + // Returns true on success, false otherwise. On success |cache_dir| contains + // the cache directory. On failure, it is not changed. + virtual bool GetCacheDirectory(base::FilePath* cache_dir) = 0; + // Returns true on success, false otherwise. On success |plugin_dir| contains + // the directory where the plugins are located. On failure, it is not + // changed. + virtual bool GetPluginDirectory(base::FilePath* plugin_dir) = 0; + // Returns true on success, false otherwise. On success |pnacl_dir| contains + // the directory where the PNaCl files are located. On failure, it is not + // changed. + virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) = 0; + // Returns true on success, false otherwise. On success |user_dir| contains + // the user data directory. On failure, it is not changed. + virtual bool GetUserDirectory(base::FilePath* user_dir) = 0; + // Returns the version as a string. This string is used to invalidate + // validator cache entries when Chromium is upgraded + virtual std::string GetVersionString() const = 0; + // Returns a HostFactory that hides the details of its embedder. + virtual ppapi::host::HostFactory* CreatePpapiHostFactory( + content::BrowserPpapiHost* ppapi_host) = 0; + // Install PNaCl if this operation is supported. On success, the |installed| + // callback should be called with true, and on failure (or not supported), + // the |installed| callback should be called with false. + // TODO(jvoung): Add the progress callback as well. + virtual void TryInstallPnacl( + const base::Callback<void(bool)>& installed) = 0; +}; + +#endif // COMPONENTS_NACL_COMMON_NACL_BROWSER_DELEGATE_H_ diff --git a/chromium/components/nacl/common/nacl_cmd_line.cc b/chromium/components/nacl/common/nacl_cmd_line.cc new file mode 100644 index 00000000000..d9bbd6557f4 --- /dev/null +++ b/chromium/components/nacl/common/nacl_cmd_line.cc @@ -0,0 +1,36 @@ +// 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 "base/base_switches.h" +#include "base/basictypes.h" +#include "base/command_line.h" +#include "components/nacl/common/nacl_switches.h" +#include "content/public/common/content_switches.h" + +namespace nacl { + +void CopyNaClCommandLineArguments(CommandLine* cmd_line) { + const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); + + // Propagate the following switches to the NaCl loader command line (along + // with any associated values) if present in the browser command line. + // TODO(gregoryd): check which flags of those below can be supported. + static const char* const kSwitchNames[] = { + switches::kNoSandbox, + switches::kDisableBreakpad, + switches::kFullMemoryCrashReport, + switches::kEnableLogging, + switches::kDisableLogging, + switches::kLoggingLevel, + switches::kEnableDCHECK, + switches::kNoErrorDialogs, +#if defined(OS_MACOSX) + switches::kEnableSandboxLogging, +#endif + }; + cmd_line->CopySwitchesFrom(browser_command_line, kSwitchNames, + arraysize(kSwitchNames)); +} + +} // namespace nacl diff --git a/chromium/components/nacl/common/nacl_cmd_line.h b/chromium/components/nacl/common/nacl_cmd_line.h new file mode 100644 index 00000000000..4e4e7536135 --- /dev/null +++ b/chromium/components/nacl/common/nacl_cmd_line.h @@ -0,0 +1,16 @@ +// 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_CMD_LINE_H_ +#define COMPONENTS_NACL_COMMON_NACL_CMD_LINE_H_ + +class CommandLine; + +namespace nacl { + // Copy all the relevant arguments from the command line of the current + // process to cmd_line that will be used for launching the NaCl loader/broker. + void CopyNaClCommandLineArguments(CommandLine* cmd_line); +} + +#endif // COMPONENTS_NACL_COMMON_NACL_CMD_LINE_H_ diff --git a/chromium/components/nacl/common/nacl_debug_exception_handler_win.cc b/chromium/components/nacl/common/nacl_debug_exception_handler_win.cc new file mode 100644 index 00000000000..f661391c4f4 --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_debug_exception_handler_win.h b/chromium/components/nacl/common/nacl_debug_exception_handler_win.h new file mode 100644 index 00000000000..42beefe8514 --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_helper_linux.h b/chromium/components/nacl/common/nacl_helper_linux.h new file mode 100644 index 00000000000..732b21570a9 --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_host_messages.h b/chromium/components/nacl/common/nacl_host_messages.h new file mode 100644 index 00000000000..d9a835ba28c --- /dev/null +++ b/chromium/components/nacl/common/nacl_host_messages.h @@ -0,0 +1,110 @@ +// 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 +// ensure that PNaCl is installed. +IPC_MESSAGE_CONTROL1(NaClHostMsg_EnsurePnaclInstalled, + int /* pp_instance */) + +// The browser replies to the renderer's request to ensure that +// PNaCl is installed. +IPC_MESSAGE_CONTROL2(NaClViewMsg_EnsurePnaclInstalledReply, + int /* pp_instance */, + bool /* success */) + +// 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_CONTROL2(NaClHostMsg_ReportTranslationFinished, + int /* instance */, + bool /* success */) + +// 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/chromium/components/nacl/common/nacl_messages.cc b/chromium/components/nacl/common/nacl_messages.cc new file mode 100644 index 00000000000..21407368aef --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_messages.h b/chromium/components/nacl/common/nacl_messages.h new file mode 100644 index 00000000000..068a0f9cc5e --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_paths.cc b/chromium/components/nacl/common/nacl_paths.cc new file mode 100644 index 00000000000..cb046c23eac --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_paths.h b/chromium/components/nacl/common/nacl_paths.h new file mode 100644 index 00000000000..424d8bdb487 --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_process_type.h b/chromium/components/nacl/common/nacl_process_type.h new file mode 100644 index 00000000000..779cc80546a --- /dev/null +++ b/chromium/components/nacl/common/nacl_process_type.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_PROCESS_TYPE_H_ +#define COMPONENTS_NACL_COMMON_NACL_PROCESS_TYPE_H_ + +#include "content/public/common/process_type.h" + +// Defines the process types that are custom to NaCl. +enum NaClProcessType { + // Start at +1 because we removed an unused value and didn't want to change + // the IDs as they're used in UMA (see the comment for ProcessType). + PROCESS_TYPE_NACL_LOADER = content::PROCESS_TYPE_CONTENT_END + 1, + PROCESS_TYPE_NACL_BROKER, +}; + +#endif // COMPONENTS_NACL_COMMON_NACL_PROCESS_TYPE_H_ diff --git a/chromium/components/nacl/common/nacl_sandbox_type_mac.h b/chromium/components/nacl/common/nacl_sandbox_type_mac.h new file mode 100644 index 00000000000..b1817f30d4e --- /dev/null +++ b/chromium/components/nacl/common/nacl_sandbox_type_mac.h @@ -0,0 +1,16 @@ +// 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_SANDBOX_TYPE_MAC_H_ +#define COMPONENTS_NACL_COMMON_NACL_SANDBOX_TYPE_MAC_H_ + +#include "content/public/common/sandbox_type_mac.h" + +enum NaClSandboxType { + NACL_SANDBOX_TYPE_FIRST_TYPE = content::SANDBOX_TYPE_AFTER_LAST_TYPE, + + NACL_SANDBOX_TYPE_NACL_LOADER = NACL_SANDBOX_TYPE_FIRST_TYPE, +}; + +#endif // COMPONENTS_NACL_COMMON_NACL_SANDBOX_TYPE_MAC_H_ diff --git a/chromium/components/nacl/common/nacl_switches.cc b/chromium/components/nacl/common/nacl_switches.cc new file mode 100644 index 00000000000..0dfdc949857 --- /dev/null +++ b/chromium/components/nacl/common/nacl_switches.cc @@ -0,0 +1,39 @@ +// 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_switches.h" + +namespace switches { + +// Enables debugging via RSP over a socket. +const char kEnableNaClDebug[] = "enable-nacl-debug"; + +// Causes the process to run as a NativeClient broker +// (used for launching NaCl loader processes on 64-bit Windows). +const char kNaClBrokerProcess[] = "nacl-broker"; + +// Uses NaCl manifest URL to choose whether NaCl program will be debugged by +// debug stub. +// Switch value format: [!]pattern1,pattern2,...,patternN. Each pattern uses +// the same syntax as patterns in Chrome extension manifest. The only difference +// is that * scheme matches all schemes instead of matching only http and https. +// If the value doesn't start with !, a program will be debugged if manifest URL +// matches any pattern. If the value starts with !, a program will be debugged +// if manifest URL does not match any pattern. +const char kNaClDebugMask[] = "nacl-debug-mask"; + +// Native Client GDB debugger that will be launched automatically when needed. +const char kNaClGdb[] = "nacl-gdb"; + +// GDB script to pass to the nacl-gdb debugger at startup. +const char kNaClGdbScript[] = "nacl-gdb-script"; + +// On POSIX only: the contents of this flag are prepended to the nacl-loader +// command line. Useful values might be "valgrind" or "xterm -e gdb --args". +const char kNaClLoaderCmdPrefix[] = "nacl-loader-cmd-prefix"; + +// Causes the process to run as a NativeClient loader. +const char kNaClLoaderProcess[] = "nacl-loader"; + +} // namespace switches diff --git a/chromium/components/nacl/common/nacl_switches.h b/chromium/components/nacl/common/nacl_switches.h new file mode 100644 index 00000000000..9bc1bcb4697 --- /dev/null +++ b/chromium/components/nacl/common/nacl_switches.h @@ -0,0 +1,24 @@ +// 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 all the command-line switches used by Chrome. + +#ifndef COMPONENTS_NACL_COMMON_NACL_SWITCHES_H_ +#define COMPONENTS_NACL_COMMON_NACL_SWITCHES_H_ + +namespace switches { + +// All switches in alphabetical order. The switches should be documented +// alongside the definition of their values in the .cc file. +extern const char kEnableNaClDebug[]; +extern const char kNaClBrokerProcess[]; +extern const char kNaClDebugMask[]; +extern const char kNaClGdb[]; +extern const char kNaClGdbScript[]; +extern const char kNaClLoaderCmdPrefix[]; +extern const char kNaClLoaderProcess[]; + +} // namespace switches + +#endif // COMPONENTS_NACL_COMMON_NACL_SWITCHES_H_ diff --git a/chromium/components/nacl/common/nacl_types.cc b/chromium/components/nacl/common/nacl_types.cc new file mode 100644 index 00000000000..dea02391125 --- /dev/null +++ b/chromium/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/chromium/components/nacl/common/nacl_types.h b/chromium/components/nacl/common/nacl_types.h new file mode 100644 index 00000000000..b3fee25c869 --- /dev/null +++ b/chromium/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/process_handle.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/chromium/components/nacl/common/pnacl_types.cc b/chromium/components/nacl/common/pnacl_types.cc new file mode 100644 index 00000000000..6c43319c6b2 --- /dev/null +++ b/chromium/components/nacl/common/pnacl_types.cc @@ -0,0 +1,28 @@ +// 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() {} + +// static +bool PnaclInstallProgress::progress_known(const PnaclInstallProgress& p) { + return p.total_size >= 0; +} + +// static +PnaclInstallProgress PnaclInstallProgress::Unknown() { + PnaclInstallProgress p; + p.current = 0; + // Use -1 to indicate that total is not determined. + // This matches the -1 of the OnURLFetchDownloadProgress interface in + // net/url_request/url_fetcher_delegate.h + p.total_size = -1; + return p; +} + +} // namespace nacl diff --git a/chromium/components/nacl/common/pnacl_types.h b/chromium/components/nacl/common/pnacl_types.h new file mode 100644 index 00000000000..3fc405a980d --- /dev/null +++ b/chromium/components/nacl/common/pnacl_types.h @@ -0,0 +1,48 @@ +// 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/basictypes.h" +#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; +}; + +// Progress information for PNaCl on-demand installs. +struct PnaclInstallProgress { + int64 current; + int64 total_size; + + // Returns an instance of PnaclInstallProgress where the + // total is marked as unknown. + static PnaclInstallProgress Unknown(); + + // Returns true if the given instance of PnaclInstallProgress has + // an unknown total. + static bool progress_known(const PnaclInstallProgress& p); +}; + +} // namespace nacl + +#endif // COMPONENTS_NACL_COMMON_PNACL_TYPES_H_ |