summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorgregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 18:57:09 +0000
committergregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-01 18:57:09 +0000
commit103607e7bb3d18c9c5b78cf8dc558c2504047b1d (patch)
tree650fd33a0dfeded9eec339c24856307de5a86248 /chrome/common
parent20c01928492aca53ee6ba6e1c84a199e889cb74d (diff)
downloadchromium_src-103607e7bb3d18c9c5b78cf8dc558c2504047b1d.zip
chromium_src-103607e7bb3d18c9c5b78cf8dc558c2504047b1d.tar.gz
chromium_src-103607e7bb3d18c9c5b78cf8dc558c2504047b1d.tar.bz2
Implement the broker process that launches NaCl loader processes on 64-bit Windows systems.
BUG=28176 TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=37578 Review URL: http://codereview.chromium.org/542030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37720 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/child_process_host.cc8
-rw-r--r--chrome/common/child_process_host.h2
-rw-r--r--chrome/common/child_process_info.cc4
-rw-r--r--chrome/common/child_process_info.h3
-rw-r--r--chrome/common/chrome_constants.cc1
-rw-r--r--chrome/common/chrome_constants.h1
-rw-r--r--chrome/common/chrome_switches.cc8
-rw-r--r--chrome/common/chrome_switches.h3
-rw-r--r--chrome/common/nacl_cmd_line.cc44
-rw-r--r--chrome/common/nacl_cmd_line.h16
-rw-r--r--chrome/common/nacl_messages_internal.h11
-rw-r--r--chrome/common/nacl_types.h20
-rw-r--r--chrome/common/sandbox_init_wrapper_mac.cc2
-rw-r--r--chrome/common/sandbox_init_wrapper_win.cc2
-rw-r--r--chrome/common/sandbox_policy.cc20
15 files changed, 126 insertions, 19 deletions
diff --git a/chrome/common/child_process_host.cc b/chrome/common/child_process_host.cc
index 9fb6b52..51c6de4 100644
--- a/chrome/common/child_process_host.cc
+++ b/chrome/common/child_process_host.cc
@@ -177,9 +177,13 @@ void ChildProcessHost::Notify(NotificationType type) {
ChromeThread::UI, FROM_HERE, new ChildNotificationTask(type, this));
}
+bool ChildProcessHost::DidChildCrash() {
+ return child_process_->DidProcessCrash();
+}
+
void ChildProcessHost::OnChildDied() {
- if (child_process_->GetHandle()) {
- bool did_crash = child_process_->DidProcessCrash();
+ if (handle() != base::kNullProcessHandle) {
+ bool did_crash = DidChildCrash();
if (did_crash) {
OnProcessCrashed();
// Report that this child process crashed.
diff --git a/chrome/common/child_process_host.h b/chrome/common/child_process_host.h
index ec6e86d..22d5cc3 100644
--- a/chrome/common/child_process_host.h
+++ b/chrome/common/child_process_host.h
@@ -116,6 +116,8 @@ class ChildProcessHost : public ResourceDispatcherHost::Receiver,
bool opening_channel() { return opening_channel_; }
const std::string& channel_id() { return channel_id_; }
+ virtual bool DidChildCrash();
+
private:
// Sends the given notification to the notification service on the UI thread.
void Notify(NotificationType type);
diff --git a/chrome/common/child_process_info.cc b/chrome/common/child_process_info.cc
index c915e80..473512f 100644
--- a/chrome/common/child_process_info.cc
+++ b/chrome/common/child_process_info.cc
@@ -54,7 +54,7 @@ std::wstring ChildProcessInfo::GetTypeNameInEnglish(
return L"Zygote";
case SANDBOX_HELPER_PROCESS:
return L"Sandbox helper";
- case NACL_PROCESS:
+ case NACL_LOADER_PROCESS:
return L"Native Client module";
case UNKNOWN_PROCESS:
default:
@@ -77,7 +77,7 @@ std::wstring ChildProcessInfo::GetLocalizedTitle() const {
message_id = IDS_TASK_MANAGER_UTILITY_PREFIX;
} else if (type_ == ChildProcessInfo::PROFILE_IMPORT_PROCESS) {
message_id = IDS_TASK_MANAGER_PROFILE_IMPORT_PREFIX;
- } else if (type_ == ChildProcessInfo::NACL_PROCESS) {
+ } else if (type_ == ChildProcessInfo::NACL_LOADER_PROCESS) {
message_id = IDS_TASK_MANAGER_NACL_PREFIX;
} else {
DCHECK(false) << "Need localized name for child process type.";
diff --git a/chrome/common/child_process_info.h b/chrome/common/child_process_info.h
index 5726675..1607417 100644
--- a/chrome/common/child_process_info.h
+++ b/chrome/common/child_process_info.h
@@ -20,11 +20,12 @@ class ChildProcessInfo {
RENDER_PROCESS,
PLUGIN_PROCESS,
WORKER_PROCESS,
- NACL_PROCESS,
+ NACL_LOADER_PROCESS,
UTILITY_PROCESS,
PROFILE_IMPORT_PROCESS,
ZYGOTE_PROCESS,
SANDBOX_HELPER_PROCESS,
+ NACL_BROKER_PROCESS,
GPU_PROCESS
};
diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc
index c75ab65..8226cd8 100644
--- a/chrome/common/chrome_constants.cc
+++ b/chrome/common/chrome_constants.cc
@@ -52,6 +52,7 @@ const FilePath::CharType kHelperProcessExecutablePath[] =
const FilePath::CharType kFrameworkName[] =
FPL(PRODUCT_STRING " Framework.framework");
#endif // OS_MACOSX
+const wchar_t kNaClAppName[] = L"nacl";
#if defined(GOOGLE_CHROME_BUILD)
const wchar_t kBrowserAppName[] = L"Chrome";
const char kStatsFilename[] = "ChromeStats2";
diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h
index c8121d0..fc271e0 100644
--- a/chrome/common/chrome_constants.h
+++ b/chrome/common/chrome_constants.h
@@ -31,6 +31,7 @@ extern const wchar_t kNotSignedInProfile[];
extern const wchar_t kNotSignedInID[];
extern const char kStatsFilename[];
extern const wchar_t kBrowserResourcesDll[];
+extern const wchar_t kNaClAppName[];
extern const FilePath::CharType kExtensionFileExtension[];
// filenames
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 85739da..3d207a3 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -380,8 +380,12 @@ const char kMessageLoopHistogrammer[] = "message-loop-histogrammer";
// and performance tests.
const char kMetricsRecordingOnly[] = "metrics-recording-only";
-// Causes the process to run as a NativeClient's sel_ldr subprocess.
-const char kNaClProcess[] = "nacl";
+// Causes the process to run as a NativeClient broker
+// (used for launching NaCl loader processes on 64-bit Windows).
+const char kNaClBrokerProcess[] = "nacl-broker";
+
+// Causes the process to run as a NativeClient loader.
+const char kNaClLoaderProcess[] = "nacl-loader";
// Causes the Native Client process to display a dialog on launch.
const char kNaClStartupDialog[] = "nacl-startup-dialog";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 69db6fa..8363517 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -120,7 +120,8 @@ extern const char kMediaCacheSize[];
extern const char kMemoryProfiling[];
extern const char kMessageLoopHistogrammer[];
extern const char kMetricsRecordingOnly[];
-extern const char kNaClProcess[];
+extern const char kNaClBrokerProcess[];
+extern const char kNaClLoaderProcess[];
extern const char kNaClStartupDialog[];
extern const char kNewTabPage[];
extern const char kNoDefaultBrowserCheck[];
diff --git a/chrome/common/nacl_cmd_line.cc b/chrome/common/nacl_cmd_line.cc
new file mode 100644
index 0000000..2212c68
--- /dev/null
+++ b/chrome/common/nacl_cmd_line.cc
@@ -0,0 +1,44 @@
+// 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 "base/command_line.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/logging_chrome.h"
+
+namespace nacl {
+ void CopyNaClCommandLineArguments(CommandLine* cmd_line) {
+ const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
+ if (logging::DialogsAreSuppressed())
+ cmd_line->AppendSwitch(switches::kNoErrorDialogs);
+
+ // 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 switch_names[] = {
+ switches::kNoSandbox,
+ switches::kTestSandbox,
+ switches::kDisableBreakpad,
+ switches::kFullMemoryCrashReport,
+ switches::kEnableLogging,
+ switches::kDisableLogging,
+ switches::kLoggingLevel,
+ switches::kEnableDCHECK,
+ switches::kSilentDumpOnDCHECK,
+ switches::kMemoryProfiling,
+#if defined(OS_MACOSX)
+ // TODO(dspringer): remove this when NaCl x86-32 security issues are fixed
+ switches::kEnableNaClOnMac,
+#endif
+ };
+
+ for (size_t i = 0; i < arraysize(switch_names); ++i) {
+ if (browser_command_line.HasSwitch(switch_names[i])) {
+ cmd_line->AppendSwitchWithValue(
+ switch_names[i],
+ browser_command_line.GetSwitchValueASCII(switch_names[i]));
+ }
+ }
+ }
+}
diff --git a/chrome/common/nacl_cmd_line.h b/chrome/common/nacl_cmd_line.h
new file mode 100644
index 0000000..1091e11
--- /dev/null
+++ b/chrome/common/nacl_cmd_line.h
@@ -0,0 +1,16 @@
+// 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_COMMON_NACL_CMD_LINE_H_
+#define CHROME_COMMON_NACL_CMD_LINE_H_
+
+#include "base/command_line.h"
+
+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 // CHROME_COMMON_NACL_CMD_LINE_H_
diff --git a/chrome/common/nacl_messages_internal.h b/chrome/common/nacl_messages_internal.h
index 3794255..11dfba7 100644
--- a/chrome/common/nacl_messages_internal.h
+++ b/chrome/common/nacl_messages_internal.h
@@ -14,5 +14,16 @@ IPC_BEGIN_MESSAGES(NaClProcess)
int /* descriptor id */,
nacl::FileDescriptor /* handle value */)
+ // Tells the NaCl broker to launch a NaCl loader process.
+ IPC_MESSAGE_CONTROL1(NaClProcessMsg_LaunchLoaderThroughBroker,
+ std::wstring /* channel ID for the loader */)
+
+ // Notify the browser process that the loader was launched successfully.
+ IPC_MESSAGE_CONTROL2(NaClProcessMsg_LoaderLaunched,
+ std::wstring, /* channel ID for the loader */
+ base::ProcessHandle /* loader process handle */)
+
+ // Notify the browser process that the broker is ready (sent by the broker)
+ IPC_MESSAGE_CONTROL0(NaClProcessMsg_BrokerReady)
IPC_END_MESSAGES(NaClProcess)
diff --git a/chrome/common/nacl_types.h b/chrome/common/nacl_types.h
index 394edd3..5c5f5dc 100644
--- a/chrome/common/nacl_types.h
+++ b/chrome/common/nacl_types.h
@@ -6,15 +6,23 @@
#ifndef CHROME_COMMON_NACL_TYPES_H_
#define CHROME_COMMON_NACL_TYPES_H_
-// TODO(gregoryd): add a Windows definition for base::FileDescriptor,
-// replace the macros with inline functions.
+#if defined(OS_POSIX)
+#include "base/file_descriptor_posix.h"
+#endif
+
+// TODO(gregoryd): add a Windows definition for base::FileDescriptor
namespace nacl {
#if defined(OS_WIN)
-typedef HANDLE FileDescriptor;
-#define NATIVE_HANDLE(desc) (desc)
+ // We assume that HANDLE always uses less than 32 bits
+ typedef int FileDescriptor;
+ inline HANDLE ToNativeHandle(const FileDescriptor& desc) {
+ return reinterpret_cast<HANDLE>(desc);
+ }
#elif defined(OS_POSIX)
-typedef base::FileDescriptor FileDescriptor;
-#define NATIVE_HANDLE(desc) ((desc).fd)
+ typedef base::FileDescriptor FileDescriptor;
+ inline int ToNativeHandle(const FileDescriptor& desc) {
+ return desc.fd;
+ }
#endif
}
diff --git a/chrome/common/sandbox_init_wrapper_mac.cc b/chrome/common/sandbox_init_wrapper_mac.cc
index 3341b08..a47240d 100644
--- a/chrome/common/sandbox_init_wrapper_mac.cc
+++ b/chrome/common/sandbox_init_wrapper_mac.cc
@@ -39,7 +39,7 @@ bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line,
} else if (process_type == switches::kWorkerProcess) {
// Worker process sandbox.
sandbox_process_type = sandbox::SANDBOX_TYPE_WORKER;
- } else if ((process_type == switches::kNaClProcess) ||
+ } else if ((process_type == switches::kNaClLoaderProcess) ||
(process_type == switches::kPluginProcess) ||
(process_type == switches::kProfileImportProcess)) {
return true;
diff --git a/chrome/common/sandbox_init_wrapper_win.cc b/chrome/common/sandbox_init_wrapper_win.cc
index 0bfba24..5d4399a 100644
--- a/chrome/common/sandbox_init_wrapper_win.cc
+++ b/chrome/common/sandbox_init_wrapper_win.cc
@@ -21,7 +21,7 @@ bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line,
if ((process_type == switches::kRendererProcess) ||
(process_type == switches::kExtensionProcess) ||
(process_type == switches::kWorkerProcess) ||
- (process_type == switches::kNaClProcess) ||
+ (process_type == switches::kNaClLoaderProcess) ||
(process_type == switches::kUtilityProcess) ||
(process_type == switches::kPluginProcess &&
command_line.HasSwitch(switches::kSafePlugins))) {
diff --git a/chrome/common/sandbox_policy.cc b/chrome/common/sandbox_policy.cc
index 7acb513..ba9b76d 100644
--- a/chrome/common/sandbox_policy.cc
+++ b/chrome/common/sandbox_policy.cc
@@ -23,6 +23,13 @@
#include "sandbox/src/sandbox.h"
#include "webkit/glue/plugins/plugin_list.h"
+#ifdef NACL_WIN64
+ // The sandbox can be used also by the NaCl broker process. In this case we
+ // define a global variable g_broker_services instead of g_browser_process.
+ // This can be changed if we discover that the broker process needs to be more
+ // similar to the browser process.
+ extern sandbox::BrokerServices* g_broker_services;
+#endif
namespace {
// The DLLs listed here are known (or under strong suspicion) of causing crashes
@@ -372,10 +379,12 @@ base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line,
type = ChildProcessInfo::PLUGIN_PROCESS;
} else if (type_str == switches::kWorkerProcess) {
type = ChildProcessInfo::WORKER_PROCESS;
- } else if (type_str == switches::kNaClProcess) {
- type = ChildProcessInfo::NACL_PROCESS;
+ } else if (type_str == switches::kNaClLoaderProcess) {
+ type = ChildProcessInfo::NACL_LOADER_PROCESS;
} else if (type_str == switches::kUtilityProcess) {
type = ChildProcessInfo::UTILITY_PROCESS;
+ } else if (type_str == switches::kNaClBrokerProcess) {
+ type = ChildProcessInfo::NACL_BROKER_PROCESS;
} else if (type_str == switches::kGpuProcess) {
type = ChildProcessInfo::GPU_PROCESS;
} else {
@@ -409,10 +418,15 @@ base::ProcessHandle StartProcessWithAccess(CommandLine* cmd_line,
return process;
}
+#ifdef NACL_WIN64
+ // When running in the broker we get the BrokerServices pointer from a global
+ // variable. It is initialized in NaClBrokerMain.
+ sandbox::BrokerServices* broker_service = g_broker_services;
+#else
// spawn the child process in the sandbox
sandbox::BrokerServices* broker_service =
g_browser_process->broker_services();
-
+#endif
sandbox::ResultCode result;
PROCESS_INFORMATION target = {0};
sandbox::TargetPolicy* policy = broker_service->CreatePolicy();