[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 1 | // Copyright 2013 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 | |
pmonette | 18d3ed3 | 2015-10-16 21:06:06 | [diff] [blame] | 5 | #include "components/nacl/loader/nacl_helper_win_64.h" |
| 6 | |
| 7 | #include <string> |
dcheng | 70c4942 | 2016-03-02 23:20:34 | [diff] [blame] | 8 | #include <utility> |
pmonette | 18d3ed3 | 2015-10-16 21:06:06 | [diff] [blame] | 9 | |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 10 | #include "base/command_line.h" |
| 11 | #include "base/logging.h" |
| 12 | #include "base/message_loop/message_loop.h" |
| 13 | #include "base/power_monitor/power_monitor.h" |
| 14 | #include "base/power_monitor/power_monitor_device_source.h" |
| 15 | #include "base/process/launch.h" |
| 16 | #include "base/process/memory.h" |
| 17 | #include "base/strings/string_util.h" |
| 18 | #include "base/timer/hi_res_timer_manager.h" |
pmonette | 18d3ed3 | 2015-10-16 21:06:06 | [diff] [blame] | 19 | #include "base/win/process_startup_helper.h" |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 20 | #include "components/nacl/broker/nacl_broker_listener.h" |
| 21 | #include "components/nacl/common/nacl_switches.h" |
| 22 | #include "components/nacl/loader/nacl_listener.h" |
| 23 | #include "components/nacl/loader/nacl_main_platform_delegate.h" |
pmonette | 18d3ed3 | 2015-10-16 21:06:06 | [diff] [blame] | 24 | #include "content/public/app/sandbox_helper_win.h" |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 25 | #include "content/public/common/content_switches.h" |
| 26 | #include "content/public/common/main_function_params.h" |
| 27 | #include "content/public/common/sandbox_init.h" |
sammc | 9e87807 | 2016-09-22 02:56:21 | [diff] [blame] | 28 | #include "mojo/edk/embedder/embedder.h" |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 29 | #include "sandbox/win/src/sandbox_types.h" |
| 30 | |
| 31 | extern int NaClMain(const content::MainFunctionParams&); |
| 32 | |
| 33 | namespace { |
| 34 | // main() routine for the NaCl broker process. |
| 35 | // This is necessary for supporting NaCl in Chrome on Win64. |
| 36 | int NaClBrokerMain(const content::MainFunctionParams& parameters) { |
| 37 | base::MessageLoopForIO main_message_loop; |
| 38 | base::PlatformThread::SetName("CrNaClBrokerMain"); |
| 39 | |
sammc | 9e87807 | 2016-09-22 02:56:21 | [diff] [blame] | 40 | mojo::edk::Init(); |
sammc | 9e87807 | 2016-09-22 02:56:21 | [diff] [blame] | 41 | |
dcheng | 24f43a5e9 | 2016-04-22 18:29:09 | [diff] [blame] | 42 | std::unique_ptr<base::PowerMonitorSource> power_monitor_source( |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 43 | new base::PowerMonitorDeviceSource()); |
dcheng | 70c4942 | 2016-03-02 23:20:34 | [diff] [blame] | 44 | base::PowerMonitor power_monitor(std::move(power_monitor_source)); |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 45 | base::HighResolutionTimerManager hi_res_timer_manager; |
| 46 | |
| 47 | NaClBrokerListener listener; |
| 48 | listener.Listen(); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | } // namespace |
| 54 | |
| 55 | namespace nacl { |
| 56 | |
| 57 | int NaClWin64Main() { |
| 58 | sandbox::SandboxInterfaceInfo sandbox_info = {0}; |
| 59 | content::InitializeSandboxInfo(&sandbox_info); |
| 60 | |
kkosztyo.u-szeged | b33617c | 2014-12-04 09:54:36 | [diff] [blame] | 61 | const base::CommandLine& command_line = |
| 62 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 63 | std::string process_type = |
| 64 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 65 | |
| 66 | // Copy what ContentMain() does. |
| 67 | base::EnableTerminationOnHeapCorruption(); |
| 68 | base::EnableTerminationOnOutOfMemory(); |
pmonette | 18d3ed3 | 2015-10-16 21:06:06 | [diff] [blame] | 69 | base::win::RegisterInvalidParamHandler(); |
| 70 | base::win::SetupCRT(command_line); |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 71 | // Route stdio to parent console (if any) or create one. |
| 72 | if (command_line.HasSwitch(switches::kEnableLogging)) |
jam | 79dc59a | 2015-08-17 03:38:16 | [diff] [blame] | 73 | base::RouteStdioToConsole(true); |
[email protected] | 6b492fd | 2013-11-14 01:45:50 | [diff] [blame] | 74 | |
| 75 | // Initialize the sandbox for this process. |
| 76 | bool sandbox_initialized_ok = content::InitializeSandbox(&sandbox_info); |
| 77 | // Die if the sandbox can't be enabled. |
| 78 | CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " |
| 79 | << process_type; |
| 80 | content::MainFunctionParams main_params(command_line); |
| 81 | main_params.sandbox_info = &sandbox_info; |
| 82 | |
| 83 | if (process_type == switches::kNaClLoaderProcess) |
| 84 | return NaClMain(main_params); |
| 85 | |
| 86 | if (process_type == switches::kNaClBrokerProcess) |
| 87 | return NaClBrokerMain(main_params); |
| 88 | |
| 89 | CHECK(false) << "Unknown NaCl 64 process."; |
| 90 | return -1; |
| 91 | } |
| 92 | |
| 93 | } // namespace nacl |