OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/at_exit.h" |
| 6 #include "base/command_line.h" |
| 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" |
| 9 #include "base/process_util.h" |
| 10 #include "base/string_util.h" |
| 11 #include "base/system_monitor/system_monitor.h" |
| 12 #include "chrome/app/breakpad_win.h" |
| 13 #include "chrome/common/chrome_result_codes.h" |
| 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/logging_chrome.h" |
| 16 #include "chrome/nacl/nacl_broker_listener.h" |
| 17 #include "chrome/nacl/nacl_listener.h" |
| 18 #include "chrome/nacl/nacl_main_platform_delegate.h" |
| 19 #include "content/app/startup_helper_win.h" |
| 20 #include "content/common/hi_res_timer_manager.h" |
| 21 #include "content/common/main_function_params.h" |
| 22 #include "content/common/sandbox_init_wrapper.h" |
| 23 #include "content/common/sandbox_policy.h" |
| 24 #include "sandbox/src/sandbox.h" |
| 25 #include "sandbox/src/sandbox_types.h" |
| 26 |
| 27 extern int NaClMain(const MainFunctionParams&); |
| 28 |
| 29 // main() routine for the NaCl broker process. |
| 30 // This is necessary for supporting NaCl in Chrome on Win64. |
| 31 int NaClBrokerMain(const MainFunctionParams& parameters) { |
| 32 const CommandLine& parsed_command_line = parameters.command_line_; |
| 33 |
| 34 MessageLoopForIO main_message_loop; |
| 35 base::PlatformThread::SetName("CrNaClBrokerMain"); |
| 36 |
| 37 base::SystemMonitor system_monitor; |
| 38 HighResolutionTimerManager hi_res_timer_manager; |
| 39 |
| 40 // NOTE: this code is duplicated from browser_main.cc |
| 41 // IMPORTANT: This piece of code needs to run as early as possible in the |
| 42 // process because it will initialize the sandbox broker, which requires the |
| 43 // process to swap its window station. During this time all the UI will be |
| 44 // broken. This has to run before threads and windows are created. |
| 45 sandbox::BrokerServices* broker_services = |
| 46 parameters.sandbox_info_.BrokerServices(); |
| 47 if (broker_services) { |
| 48 sandbox::InitBrokerServices(broker_services); |
| 49 if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) { |
| 50 bool use_winsta = !parsed_command_line.HasSwitch( |
| 51 switches::kDisableAltWinstation); |
| 52 // Precreate the desktop and window station used by the renderers. |
| 53 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
| 54 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); |
| 55 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
| 56 policy->Release(); |
| 57 } |
| 58 } |
| 59 |
| 60 NaClBrokerListener listener; |
| 61 listener.Listen(); |
| 62 |
| 63 return 0; |
| 64 } |
| 65 |
| 66 int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { |
| 67 sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 68 content::InitializeSandboxInfo(&sandbox_info); |
| 69 |
| 70 base::AtExitManager exit_manager; |
| 71 CommandLine::Init(0, NULL); |
| 72 |
| 73 wchar_t path[MAX_PATH]; |
| 74 ::GetModuleFileNameW(NULL, path, MAX_PATH); |
| 75 InitCrashReporterWithDllPath(std::wstring(path)); |
| 76 |
| 77 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 78 std::string process_type = |
| 79 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 80 |
| 81 // Copy what ContentMain() does. |
| 82 base::EnableTerminationOnHeapCorruption(); |
| 83 base::EnableTerminationOnOutOfMemory(); |
| 84 content::RegisterInvalidParamHandler(); |
| 85 content::SetupCRT(command_line); |
| 86 |
| 87 // Initialize the sandbox for this process. |
| 88 SandboxInitWrapper sandbox_wrapper; |
| 89 sandbox_wrapper.SetServices(&sandbox_info); |
| 90 bool sandbox_initialized_ok = |
| 91 sandbox_wrapper.InitializeSandbox(command_line, process_type); |
| 92 // Die if the sandbox can't be enabled. |
| 93 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " |
| 94 << process_type; |
| 95 MainFunctionParams main_params(command_line, sandbox_wrapper, NULL); |
| 96 |
| 97 if (process_type == switches::kNaClLoaderProcess) |
| 98 return NaClMain(main_params); |
| 99 |
| 100 if (process_type == switches::kNaClBrokerProcess) |
| 101 return NaClBrokerMain(main_params); |
| 102 |
| 103 CHECK(false) << "Unknown NaCl 64 process."; |
| 104 return -1; |
| 105 } |
OLD | NEW |