summaryrefslogtreecommitdiffstats
path: root/chrome/nacl
diff options
context:
space:
mode:
authorgregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-30 00:10:10 +0000
committergregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-30 00:10:10 +0000
commit08aab35037965c2d7d71263b453fda74fa48b378 (patch)
tree45eabab475f9137125bc74a45062a78d9e7f0cc5 /chrome/nacl
parent7946a0ca0347117c1f8870eb441f31ba185fc5ab (diff)
downloadchromium_src-08aab35037965c2d7d71263b453fda74fa48b378.zip
chromium_src-08aab35037965c2d7d71263b453fda74fa48b378.tar.gz
chromium_src-08aab35037965c2d7d71263b453fda74fa48b378.tar.bz2
Implement the broker process that launches NaCl loader processes on 64-bit Windows systems.
BUG=28176 TEST=none Review URL: http://codereview.chromium.org/542030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37578 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/nacl')
-rw-r--r--chrome/nacl/broker_thread.cc72
-rw-r--r--chrome/nacl/broker_thread.h37
-rw-r--r--chrome/nacl/nacl_main.cc67
-rw-r--r--chrome/nacl/nacl_thread.cc2
-rw-r--r--chrome/nacl/nacl_thread.h2
5 files changed, 175 insertions, 5 deletions
diff --git a/chrome/nacl/broker_thread.cc b/chrome/nacl/broker_thread.cc
new file mode 100644
index 0000000..0b4bbd2
--- /dev/null
+++ b/chrome/nacl/broker_thread.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2010 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 "chrome/nacl/broker_thread.h"
+
+#include "base/base_switches.h"
+#include "base/command_line.h"
+#include "base/path_service.h"
+#include "base/process_util.h"
+#include "chrome/common/sandbox_policy.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/nacl_cmd_line.h"
+#include "chrome/common/nacl_messages.h"
+#include "ipc/ipc_switches.h"
+
+NaClBrokerThread::NaClBrokerThread()
+ : browser_handle_(0),
+ broker_services_(NULL) {
+}
+
+NaClBrokerThread::~NaClBrokerThread() {
+ base::CloseProcessHandle(browser_handle_);
+}
+
+NaClBrokerThread* NaClBrokerThread::current() {
+ return static_cast<NaClBrokerThread*>(ChildThread::current());
+}
+
+void NaClBrokerThread::OnControlMessageReceived(const IPC::Message& msg) {
+ IPC_BEGIN_MESSAGE_MAP(NaClBrokerThread, msg)
+ IPC_MESSAGE_HANDLER(NaClProcessMsg_LaunchLoaderThroughBroker,
+ OnLaunchLoaderThroughBroker)
+ IPC_END_MESSAGE_MAP()
+}
+
+void NaClBrokerThread::OnLaunchLoaderThroughBroker(
+ const std::wstring& loader_channel_id) {
+ base::ProcessHandle loader_process = 0;
+ base::ProcessHandle loader_handle_in_browser = 0;
+
+ // Create the path to the nacl broker/loader executable - it's the executable
+ // this code is running in.
+ FilePath exe_path;
+ PathService::Get(base::FILE_EXE, &exe_path);
+ if (!exe_path.empty()) {
+ CommandLine* cmd_line = new CommandLine(exe_path);
+ nacl::CopyNaClCommandLineArguments(cmd_line);
+
+ cmd_line->AppendSwitchWithValue(switches::kProcessType,
+ switches::kNaClLoaderProcess);
+
+ cmd_line->AppendSwitchWithValue(switches::kProcessChannelID,
+ loader_channel_id);
+
+ loader_process = sandbox::StartProcessWithAccess(cmd_line, FilePath());
+ if (loader_process) {
+ DuplicateHandle(::GetCurrentProcess(), loader_process,
+ browser_handle_, &loader_handle_in_browser,
+ PROCESS_DUP_HANDLE, FALSE, 0);
+ }
+ }
+ Send(new NaClProcessMsg_LoaderLaunched(loader_channel_id,
+ loader_handle_in_browser));
+}
+
+void NaClBrokerThread::OnChannelConnected(int32 peer_pid) {
+ bool res = base::OpenProcessHandle(peer_pid, &browser_handle_);
+ DCHECK(res);
+ Send(new NaClProcessMsg_BrokerReady());
+}
+
diff --git a/chrome/nacl/broker_thread.h b/chrome/nacl/broker_thread.h
new file mode 100644
index 0000000..d88919f
--- /dev/null
+++ b/chrome/nacl/broker_thread.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2010 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 CHROME_NACL_BROKER_THREAD_H_
+#define CHROME_NACL_BROKER_THREAD_H_
+
+#include "chrome/common/child_thread.h"
+#include "chrome/common/nacl_types.h"
+
+#if defined(OS_WIN)
+#include "sandbox/src/sandbox.h"
+#endif
+
+// The BrokerThread class represents the thread that handles the messages from
+// the browser process and starts NaCl loader processes.
+class NaClBrokerThread : public ChildThread {
+ public:
+ NaClBrokerThread();
+ ~NaClBrokerThread();
+ // Returns the one NaCl thread.
+ static NaClBrokerThread* current();
+
+ virtual void OnChannelConnected(int32 peer_pid);
+
+ private:
+ virtual void OnControlMessageReceived(const IPC::Message& msg);
+ void OnLaunchLoaderThroughBroker(const std::wstring& loader_channel_id);
+ void OnShareBrowserHandle(int browser_handle);
+
+ base::ProcessHandle browser_handle_;
+ sandbox::BrokerServices* broker_services_;
+
+ DISALLOW_COPY_AND_ASSIGN(NaClBrokerThread);
+};
+
+#endif // CHROME_NACL_BROKER_THREAD_H_
diff --git a/chrome/nacl/nacl_main.cc b/chrome/nacl/nacl_main.cc
index 72bc8a2..ffda8ab 100644
--- a/chrome/nacl/nacl_main.cc
+++ b/chrome/nacl/nacl_main.cc
@@ -20,8 +20,66 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/main_function_params.h"
+#include "chrome/common/result_codes.h"
+#if defined(OS_WIN)
+#include "chrome/nacl/broker_thread.h"
+#endif
#include "chrome/nacl/nacl_thread.h"
+#ifdef _WIN64
+
+sandbox::BrokerServices* g_broker_services = NULL;
+
+// main() routine for the NaCl broker process.
+// This is necessary for supporting NaCl in Chrome on Win64.
+int NaClBrokerMain(const MainFunctionParams& parameters) {
+ // The main thread of the broker.
+ MessageLoopForIO main_message_loop;
+ std::wstring app_name = chrome::kNaClAppName;
+ PlatformThread::SetName(WideToASCII(app_name + L"_NaClBrokerMain").c_str());
+
+ SystemMonitor system_monitor;
+ HighResolutionTimerManager hi_res_timer_manager;
+
+ const CommandLine& parsed_command_line = parameters.command_line_;
+
+ DLOG(INFO) << "Started NaCL broker with " <<
+ parsed_command_line.command_line_string();
+
+ // NOTE: this code is duplicated from browser_main.cc
+ // IMPORTANT: This piece of code needs to run as early as possible in the
+ // process because it will initialize the sandbox broker, which requires the
+ // process to swap its window station. During this time all the UI will be
+ // broken. This has to run before threads and windows are created.
+ sandbox::BrokerServices* broker_services =
+ parameters.sandbox_info_.BrokerServices();
+ if (broker_services) {
+ g_broker_services = broker_services;
+ if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) {
+ bool use_winsta = !parsed_command_line.HasSwitch(
+ switches::kDisableAltWinstation);
+ // Precreate the desktop and window station used by the renderers.
+ sandbox::TargetPolicy* policy = broker_services->CreatePolicy();
+ sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta);
+ CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result);
+ policy->Release();
+ }
+ }
+
+ {
+ ChildProcess broker_process;
+ broker_process.set_main_thread(new NaClBrokerThread());
+ MessageLoop::current()->Run();
+ }
+
+ return 0;
+}
+#else
+int NaClBrokerMain(const MainFunctionParams& parameters) {
+ return ResultCodes::BAD_PROCESS_TYPE;
+}
+#endif // _WIN64
+
// This function provides some ways to test crash and assertion handling
// behavior of the renderer.
static void HandleNaClTestParameters(const CommandLine& command_line) {
@@ -48,7 +106,7 @@ static void LaunchNaClChildProcess() {
}
#endif
-// main() routine for running as the sel_ldr process.
+// main() routine for the NaCl loader process.
int NaClMain(const MainFunctionParams& parameters) {
const CommandLine& parsed_command_line = parameters.command_line_;
@@ -60,7 +118,12 @@ int NaClMain(const MainFunctionParams& parameters) {
// The main thread of the plugin services IO.
MessageLoopForIO main_message_loop;
+ // NaCl code runs in a different binary on Win64.
+#ifdef _WIN64
+ std::wstring app_name = chrome::kNaClAppName;
+#else
std::wstring app_name = chrome::kBrowserAppName;
+#endif
PlatformThread::SetName(WideToASCII(app_name + L"_NaClMain").c_str());
SystemMonitor system_monitor;
@@ -70,7 +133,7 @@ int NaClMain(const MainFunctionParams& parameters) {
sandbox::TargetServices* target_services =
parameters.sandbox_info_.TargetServices();
- DLOG(INFO) << "Started plugin with " <<
+ DLOG(INFO) << "Started NaCl loader with " <<
parsed_command_line.command_line_string();
HMODULE sandbox_test_module = NULL;
diff --git a/chrome/nacl/nacl_thread.cc b/chrome/nacl/nacl_thread.cc
index 4c9dd5f05..0f05f06 100644
--- a/chrome/nacl/nacl_thread.cc
+++ b/chrome/nacl/nacl_thread.cc
@@ -36,5 +36,5 @@ void NaClThread::OnControlMessageReceived(const IPC::Message& msg) {
void NaClThread::OnStartSelLdr(int channel_descriptor,
nacl::FileDescriptor handle) {
- SelMain(channel_descriptor, NATIVE_HANDLE(handle));
+ SelMain(channel_descriptor, nacl::ToNativeHandle(handle));
}
diff --git a/chrome/nacl/nacl_thread.h b/chrome/nacl/nacl_thread.h
index fd8fe76..8893819 100644
--- a/chrome/nacl/nacl_thread.h
+++ b/chrome/nacl/nacl_thread.h
@@ -10,8 +10,6 @@
#include "chrome/common/child_thread.h"
#include "chrome/common/nacl_types.h"
-class NotificationService;
-
// The NaClThread class represents a background thread where NaCl app gets
// started.
class NaClThread : public ChildThread {