summaryrefslogtreecommitdiffstats
path: root/chrome/browser/nacl_process_host.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/nacl_process_host.cc')
-rw-r--r--chrome/browser/nacl_process_host.cc110
1 files changed, 66 insertions, 44 deletions
diff --git a/chrome/browser/nacl_process_host.cc b/chrome/browser/nacl_process_host.cc
index f736ab7..c82b06d 100644
--- a/chrome/browser/nacl_process_host.cc
+++ b/chrome/browser/nacl_process_host.cc
@@ -10,9 +10,12 @@
#include <fcntl.h>
#endif
+#include "base/command_line.h"
+#include "chrome/browser/nacl_host/nacl_broker_service.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
+#include "chrome/common/nacl_cmd_line.h"
#include "chrome/common/nacl_messages.h"
#include "chrome/common/render_messages.h"
#include "ipc/ipc_switches.h"
@@ -24,11 +27,15 @@
NaClProcessHost::NaClProcessHost(
ResourceDispatcherHost *resource_dispatcher_host,
const std::wstring& url)
- : ChildProcessHost(NACL_PROCESS, resource_dispatcher_host),
+ : ChildProcessHost(NACL_LOADER_PROCESS, resource_dispatcher_host),
resource_dispatcher_host_(resource_dispatcher_host),
reply_msg_(NULL),
- descriptor_(0) {
+ descriptor_(0),
+ running_on_wow64_(false) {
set_name(url);
+#if defined(OS_WIN)
+ CheckIsWow64();
+#endif
}
NaClProcessHost::~NaClProcessHost() {
@@ -77,73 +84,67 @@ bool NaClProcessHost::LaunchSelLdr() {
return false;
CommandLine* cmd_line = new CommandLine(exe_path);
- if (logging::DialogsAreSuppressed())
- cmd_line->AppendSwitch(switches::kNoErrorDialogs);
-
- // Propagate the following switches to the plugin 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
- };
-
- const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
+ nacl::CopyNaClCommandLineArguments(cmd_line);
#if defined(OS_MACOSX)
-// TODO(dspringer): NaCl is temporalrily disabled on the Mac by default, but it
-// can be enabled with the --enable-nacl cmd-line switch. Remove this check
-// when the security issues in the Mac PIC code are resolved.
- if (!browser_command_line.HasSwitch(switches::kEnableNaClOnMac))
+ // TODO(dspringer): NaCl is temporalrily disabled on the Mac by default, but
+ // it can be enabled with the --enable-nacl cmd-line switch. Remove this check
+ // when the security issues in the Mac PIC code are resolved.
+ if (!cmd_line->HasSwitch(switches::kEnableNaClOnMac))
return false;
#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]));
- }
- }
-
cmd_line->AppendSwitchWithValue(switches::kProcessType,
- switches::kNaClProcess);
+ switches::kNaClLoaderProcess);
cmd_line->AppendSwitchWithValue(switches::kProcessChannelID,
ASCIIToWide(channel_id()));
- ChildProcessHost::Launch(
+ // On Windows we might need to start the broker process to launch a new loader
#if defined(OS_WIN)
- FilePath(),
+ if (running_on_wow64_) {
+ NaClBrokerService::GetInstance()->Init(resource_dispatcher_host_);
+ NaClBrokerService::GetInstance()->LaunchLoader(this,
+ ASCIIToWide(channel_id()));
+ } else
+#endif
+ ChildProcessHost::Launch(
+#if defined(OS_WIN)
+ FilePath(),
#elif defined(OS_POSIX)
- false,
- base::environment_vector(),
+ false,
+ base::environment_vector(),
#endif
- cmd_line);
+ cmd_line);
return true;
}
+void NaClProcessHost::OnProcessLaunchedByBroker(base::ProcessHandle handle) {
+ set_handle(handle);
+ OnProcessLaunched();
+}
+
+bool NaClProcessHost::DidChildCrash() {
+ if (running_on_wow64_) {
+ bool child_exited;
+ return base::DidProcessCrash(&child_exited, handle());
+ }
+ return ChildProcessHost::DidChildCrash();
+}
+
void NaClProcessHost::OnProcessLaunched() {
nacl::FileDescriptor imc_handle;
base::ProcessHandle nacl_process_handle;
#if NACL_WINDOWS
// Duplicate the IMC handle
+ // We assume the size of imc_handle has the same size as HANDLE, so the cast
+ // below is safe.
+ DCHECK(sizeof(HANDLE) == sizeof(imc_handle));
DuplicateHandle(base::GetCurrentProcessHandle(),
reinterpret_cast<HANDLE>(pair_[0]),
resource_message_filter_->handle(),
- &imc_handle,
+ reinterpret_cast<HANDLE*>(&imc_handle),
GENERIC_READ | GENERIC_WRITE,
FALSE,
DUPLICATE_CLOSE_SOURCE);
@@ -212,3 +213,24 @@ URLRequestContext* NaClProcessHost::GetRequestContext(
const ViewHostMsg_Resource_Request& request_data) {
return NULL;
}
+
+#if defined(OS_WIN)
+// TODO(gregoryd): invoke CheckIsWow64 only once, not for each NaClProcessHost
+typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
+void NaClProcessHost::CheckIsWow64() {
+ LPFN_ISWOW64PROCESS fnIsWow64Process;
+
+ fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
+ GetModuleHandle(TEXT("kernel32")),
+ "IsWow64Process");
+
+ if (fnIsWow64Process != NULL) {
+ BOOL bIsWow64 = FALSE;
+ if (fnIsWow64Process(GetCurrentProcess(),&bIsWow64)) {
+ if (bIsWow64) {
+ running_on_wow64_ = true;
+ }
+ }
+ }
+}
+#endif