diff options
author | gregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-30 00:10:10 +0000 |
---|---|---|
committer | gregoryd@google.com <gregoryd@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-30 00:10:10 +0000 |
commit | 08aab35037965c2d7d71263b453fda74fa48b378 (patch) | |
tree | 45eabab475f9137125bc74a45062a78d9e7f0cc5 /chrome/nacl/nacl_main.cc | |
parent | 7946a0ca0347117c1f8870eb441f31ba185fc5ab (diff) | |
download | chromium_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/nacl_main.cc')
-rw-r--r-- | chrome/nacl/nacl_main.cc | 67 |
1 files changed, 65 insertions, 2 deletions
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; |