diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-12 21:14:44 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-12 21:14:44 +0000 |
commit | 93156cecb487ad7f1d7e307618cd58bd6546da29 (patch) | |
tree | ab60b7a310d1f8b2abae34e0b7c7703cf4dd2ced /chrome/nacl | |
parent | fd5633b12e0ed15c62e6e0001b52bd53b895299c (diff) | |
download | chromium_src-93156cecb487ad7f1d7e307618cd58bd6546da29.zip chromium_src-93156cecb487ad7f1d7e307618cd58bd6546da29.tar.gz chromium_src-93156cecb487ad7f1d7e307618cd58bd6546da29.tar.bz2 |
Make the NaCl windows 64 bit binaries not depend on chrome targets. These targets are very simple and used little code from chrome targets. However their dependency on chrome targets was problematic because a lot of code wasn't being built for 64 bit on Windows, and so there were a lot of "dummy" files being added with stub functions and code was also being compiled out in random places for NACL_WIN64.
I've made the NaCl 64 bit windows targets self contained. They do use a few files from common, but those files are self-contained. In the future, we could move these to be in the same 64 bit target as the constants from common. However that won't make a maintenance difference since someone could still introduce link dependencies to other files in common.
Additionally, since we're not using chrome code anymore, we can avoid having both nacl.exe and nacl.dll. nacl.exe is sufficient, and this saves 1.4MB of uncompresed binaries in the installer.
BUG=86322
Review URL: http://codereview.chromium.org/7863024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/nacl')
-rw-r--r-- | chrome/nacl/nacl_broker_listener.cc (renamed from chrome/nacl/broker_thread.cc) | 53 | ||||
-rw-r--r-- | chrome/nacl/nacl_broker_listener.h (renamed from chrome/nacl/broker_thread.h) | 29 | ||||
-rw-r--r-- | chrome/nacl/nacl_exe_win_64.cc | 105 | ||||
-rw-r--r-- | chrome/nacl/nacl_helper_linux.cc | 4 | ||||
-rw-r--r-- | chrome/nacl/nacl_listener.h | 6 | ||||
-rw-r--r-- | chrome/nacl/nacl_main.cc | 69 | ||||
-rw-r--r-- | chrome/nacl/nacl_main_platform_delegate_win.cc | 1 |
7 files changed, 156 insertions, 111 deletions
diff --git a/chrome/nacl/broker_thread.cc b/chrome/nacl/nacl_broker_listener.cc index dad7f3a..cf2b8a0 100644 --- a/chrome/nacl/broker_thread.cc +++ b/chrome/nacl/nacl_broker_listener.cc @@ -2,35 +2,45 @@ // 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 "chrome/nacl/nacl_broker_listener.h" #include "base/base_switches.h" #include "base/command_line.h" +#include "base/message_loop.h" #include "base/path_service.h" #include "base/process_util.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/nacl_cmd_line.h" #include "chrome/common/nacl_messages.h" -#include "content/common/child_process.h" +#include "content/common/content_switches.h" #include "content/common/sandbox_policy.h" #include "ipc/ipc_switches.h" -NaClBrokerThread::NaClBrokerThread() - : browser_handle_(0), - broker_services_(NULL) { +NaClBrokerListener::NaClBrokerListener() + : browser_handle_(base::kNullProcessHandle) { } -NaClBrokerThread::~NaClBrokerThread() { +NaClBrokerListener::~NaClBrokerListener() { base::CloseProcessHandle(browser_handle_); } -NaClBrokerThread* NaClBrokerThread::current() { - return static_cast<NaClBrokerThread*>(ChildThread::current()); +void NaClBrokerListener::Listen() { + std::string channel_name = + CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kProcessChannelID); + channel_.reset(new IPC::Channel( + channel_name, IPC::Channel::MODE_CLIENT, this)); + CHECK(channel_->Connect()); + MessageLoop::current()->Run(); } -bool NaClBrokerThread::OnControlMessageReceived(const IPC::Message& msg) { +void NaClBrokerListener::OnChannelConnected(int32 peer_pid) { + bool res = base::OpenProcessHandle(peer_pid, &browser_handle_); + CHECK(res); +} + +bool NaClBrokerListener::OnMessageReceived(const IPC::Message& msg) { bool handled = true; - IPC_BEGIN_MESSAGE_MAP(NaClBrokerThread, msg) + IPC_BEGIN_MESSAGE_MAP(NaClBrokerListener, msg) IPC_MESSAGE_HANDLER(NaClProcessMsg_LaunchLoaderThroughBroker, OnLaunchLoaderThroughBroker) IPC_MESSAGE_HANDLER(NaClProcessMsg_StopBroker, OnStopBroker) @@ -39,7 +49,7 @@ bool NaClBrokerThread::OnControlMessageReceived(const IPC::Message& msg) { return handled; } -void NaClBrokerThread::OnLaunchLoaderThroughBroker( +void NaClBrokerListener::OnLaunchLoaderThroughBroker( const std::wstring& loader_channel_id) { base::ProcessHandle loader_process = 0; base::ProcessHandle loader_handle_in_browser = 0; @@ -62,21 +72,14 @@ void NaClBrokerThread::OnLaunchLoaderThroughBroker( loader_process = sandbox::StartProcessWithAccess(cmd_line, FilePath()); if (loader_process) { DuplicateHandle(::GetCurrentProcess(), loader_process, - browser_handle_, &loader_handle_in_browser, - PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION , FALSE, 0); + browser_handle_, &loader_handle_in_browser, + PROCESS_DUP_HANDLE | PROCESS_QUERY_INFORMATION , FALSE, 0); } } - Send(new NaClProcessMsg_LoaderLaunched(loader_channel_id, - loader_handle_in_browser)); + channel_->Send(new NaClProcessMsg_LoaderLaunched(loader_channel_id, + loader_handle_in_browser)); } -void NaClBrokerThread::OnStopBroker() { - ChildProcess::current()->ReleaseProcess(); +void NaClBrokerListener::OnStopBroker() { + MessageLoop::current()->Quit(); } - -void NaClBrokerThread::OnChannelConnected(int32 peer_pid) { - bool res = base::OpenProcessHandle(peer_pid, &browser_handle_); - DCHECK(res); - ChildProcess::current()->AddRefProcess(); -} - diff --git a/chrome/nacl/broker_thread.h b/chrome/nacl/nacl_broker_listener.h index b0a05b9..1581c6d 100644 --- a/chrome/nacl/broker_thread.h +++ b/chrome/nacl/nacl_broker_listener.h @@ -2,40 +2,37 @@ // 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_ +#ifndef CHROME_NACL_NACL_BROKER_LISTENER_H_ +#define CHROME_NACL_NACL_BROKER_LISTENER_H_ #pragma once +#include "base/memory/scoped_ptr.h" #include "base/process.h" #include "chrome/common/nacl_types.h" -#include "content/common/child_thread.h" - -#if defined(OS_WIN) -#include "sandbox/src/sandbox.h" -#endif +#include "ipc/ipc_channel.h" // The BrokerThread class represents the thread that handles the messages from // the browser process and starts NaCl loader processes. -class NaClBrokerThread : public ChildThread { +class NaClBrokerListener : public IPC::Channel::Listener { public: - NaClBrokerThread(); - ~NaClBrokerThread(); - // Returns the one NaCl thread. - static NaClBrokerThread* current(); + NaClBrokerListener(); + ~NaClBrokerListener(); + + void Listen(); // IPC::Channel::Listener implementation. virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; private: - virtual bool OnControlMessageReceived(const IPC::Message& msg); void OnLaunchLoaderThroughBroker(const std::wstring& loader_channel_id); void OnShareBrowserHandle(int browser_handle); void OnStopBroker(); base::ProcessHandle browser_handle_; - sandbox::BrokerServices* broker_services_; + scoped_ptr<IPC::Channel> channel_; - DISALLOW_COPY_AND_ASSIGN(NaClBrokerThread); + DISALLOW_COPY_AND_ASSIGN(NaClBrokerListener); }; -#endif // CHROME_NACL_BROKER_THREAD_H_ +#endif // CHROME_NACL_NACL_BROKER_LISTENER_H_ diff --git a/chrome/nacl/nacl_exe_win_64.cc b/chrome/nacl/nacl_exe_win_64.cc new file mode 100644 index 0000000..834fc37 --- /dev/null +++ b/chrome/nacl/nacl_exe_win_64.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2011 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/at_exit.h" +#include "base/command_line.h" +#include "base/logging.h" +#include "base/message_loop.h" +#include "base/process_util.h" +#include "base/string_util.h" +#include "base/system_monitor/system_monitor.h" +#include "chrome/app/breakpad_win.h" +#include "chrome/common/chrome_result_codes.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/logging_chrome.h" +#include "chrome/nacl/nacl_broker_listener.h" +#include "chrome/nacl/nacl_listener.h" +#include "chrome/nacl/nacl_main_platform_delegate.h" +#include "content/app/startup_helper_win.h" +#include "content/common/hi_res_timer_manager.h" +#include "content/common/main_function_params.h" +#include "content/common/sandbox_init_wrapper.h" +#include "content/common/sandbox_policy.h" +#include "sandbox/src/sandbox.h" +#include "sandbox/src/sandbox_types.h" + +extern int NaClMain(const MainFunctionParams&); + +// main() routine for the NaCl broker process. +// This is necessary for supporting NaCl in Chrome on Win64. +int NaClBrokerMain(const MainFunctionParams& parameters) { + const CommandLine& parsed_command_line = parameters.command_line_; + + MessageLoopForIO main_message_loop; + base::PlatformThread::SetName("CrNaClBrokerMain"); + + base::SystemMonitor system_monitor; + HighResolutionTimerManager hi_res_timer_manager; + + // 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) { + sandbox::InitBrokerServices(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(); + } + } + + NaClBrokerListener listener; + listener.Listen(); + + return 0; +} + +int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { + sandbox::SandboxInterfaceInfo sandbox_info = {0}; + content::InitializeSandboxInfo(&sandbox_info); + + base::AtExitManager exit_manager; + CommandLine::Init(0, NULL); + + wchar_t path[MAX_PATH]; + ::GetModuleFileNameW(NULL, path, MAX_PATH); + InitCrashReporterWithDllPath(std::wstring(path)); + + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + std::string process_type = + command_line.GetSwitchValueASCII(switches::kProcessType); + + // Copy what ContentMain() does. + base::EnableTerminationOnHeapCorruption(); + base::EnableTerminationOnOutOfMemory(); + content::RegisterInvalidParamHandler(); + content::SetupCRT(command_line); + + // Initialize the sandbox for this process. + SandboxInitWrapper sandbox_wrapper; + sandbox_wrapper.SetServices(&sandbox_info); + bool sandbox_initialized_ok = + sandbox_wrapper.InitializeSandbox(command_line, process_type); + // Die if the sandbox can't be enabled. + CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " + << process_type; + MainFunctionParams main_params(command_line, sandbox_wrapper, NULL); + + if (process_type == switches::kNaClLoaderProcess) + return NaClMain(main_params); + + if (process_type == switches::kNaClBrokerProcess) + return NaClBrokerMain(main_params); + + CHECK(false) << "Unknown NaCl 64 process."; + return -1; +} diff --git a/chrome/nacl/nacl_helper_linux.cc b/chrome/nacl/nacl_helper_linux.cc index 7ffeadb..3f8646f 100644 --- a/chrome/nacl/nacl_helper_linux.cc +++ b/chrome/nacl/nacl_helper_linux.cc @@ -47,8 +47,8 @@ void BecomeNaClLoader(const std::vector<int>& child_fds) { } MessageLoopForIO main_message_loop; - NaClListener *listener = new NaClListener(); - listener->Listen(); + NaClListener listener; + listener.Listen(); _exit(0); } diff --git a/chrome/nacl/nacl_listener.h b/chrome/nacl/nacl_listener.h index 336cb59..f0d275e 100644 --- a/chrome/nacl/nacl_listener.h +++ b/chrome/nacl/nacl_listener.h @@ -15,17 +15,19 @@ // request to start a NaCl module. class NaClListener : public IPC::Channel::Listener { public: - explicit NaClListener(); + NaClListener(); virtual ~NaClListener(); // Listen for a request to launch a NaCl module. void Listen(); void set_debug_enabled(bool value) {debug_enabled_ = value;} + private: - bool debug_enabled_; void OnStartSelLdr(std::vector<nacl::FileDescriptor> handles, bool have_irt_file); virtual bool OnMessageReceived(const IPC::Message& msg); + bool debug_enabled_; + DISALLOW_COPY_AND_ASSIGN(NaClListener); }; diff --git a/chrome/nacl/nacl_main.cc b/chrome/nacl/nacl_main.cc index 92f26ee..4b3caae 100644 --- a/chrome/nacl/nacl_main.cc +++ b/chrome/nacl/nacl_main.cc @@ -4,89 +4,28 @@ #include "build/build_config.h" -#if defined(OS_WIN) -#include <windows.h> -#endif - #include "base/command_line.h" #include "base/message_loop.h" -#include "base/string_util.h" #include "base/system_monitor/system_monitor.h" -#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_result_codes.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/logging_chrome.h" #include "chrome/nacl/nacl_listener.h" #include "chrome/nacl/nacl_main_platform_delegate.h" #include "content/common/child_process.h" -#include "content/common/child_process_info.h" #include "content/common/hi_res_timer_manager.h" #include "content/common/main_function_params.h" -#include "content/common/sandbox_policy.h" -#include "ipc/ipc_switches.h" - -#if defined(OS_WIN) -#include "chrome/nacl/broker_thread.h" -#include "sandbox/src/sandbox.h" -#endif - -#ifdef _WIN64 - -// 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; - base::PlatformThread::SetName("CrNaClBrokerMain"); - - base::SystemMonitor system_monitor; - HighResolutionTimerManager hi_res_timer_manager; - - const CommandLine& parsed_command_line = parameters.command_line_; - - DVLOG(1) << "Started NaCL broker with " - << parsed_command_line.GetCommandLineString(); - - // 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) { - sandbox::InitBrokerServices(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 chrome::RESULT_CODE_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) { +// The message box doesn't work in the 64 bit binaries anyways, so no need to +// link to it since the 64 bit binary doesn't link with chrome or content. +#if !defined(NACL_WIN64) if (command_line.HasSwitch(switches::kNaClStartupDialog)) { ChildProcess::WaitForDebugger("NativeClient"); } +#endif } // main() routine for the NaCl loader process. diff --git a/chrome/nacl/nacl_main_platform_delegate_win.cc b/chrome/nacl/nacl_main_platform_delegate_win.cc index aba8481..97ba3af 100644 --- a/chrome/nacl/nacl_main_platform_delegate_win.cc +++ b/chrome/nacl/nacl_main_platform_delegate_win.cc @@ -8,7 +8,6 @@ #include "base/file_path.h" #include "base/logging.h" #include "base/native_library.h" -#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" #include "sandbox/src/sandbox.h" |