blob: fb2ebe5fb6714f24f4013e3265a301dddc626b0e [file] [log] [blame]
[email protected]6b492fd2013-11-14 01:45:501// 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
pmonette18d3ed32015-10-16 21:06:065#include "components/nacl/loader/nacl_helper_win_64.h"
6
7#include <string>
dcheng70c49422016-03-02 23:20:348#include <utility>
pmonette18d3ed32015-10-16 21:06:069
[email protected]6b492fd2013-11-14 01:45:5010#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"
pmonette18d3ed32015-10-16 21:06:0619#include "base/win/process_startup_helper.h"
[email protected]6b492fd2013-11-14 01:45:5020#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"
pmonette18d3ed32015-10-16 21:06:0624#include "content/public/app/sandbox_helper_win.h"
[email protected]6b492fd2013-11-14 01:45:5025#include "content/public/common/content_switches.h"
26#include "content/public/common/main_function_params.h"
27#include "content/public/common/sandbox_init.h"
sammc9e878072016-09-22 02:56:2128#include "mojo/edk/embedder/embedder.h"
[email protected]6b492fd2013-11-14 01:45:5029#include "sandbox/win/src/sandbox_types.h"
30
31extern int NaClMain(const content::MainFunctionParams&);
32
33namespace {
34// main() routine for the NaCl broker process.
35// This is necessary for supporting NaCl in Chrome on Win64.
36int NaClBrokerMain(const content::MainFunctionParams& parameters) {
37 base::MessageLoopForIO main_message_loop;
38 base::PlatformThread::SetName("CrNaClBrokerMain");
39
sammc9e878072016-09-22 02:56:2140 mojo::edk::Init();
sammc9e878072016-09-22 02:56:2141
dcheng24f43a5e92016-04-22 18:29:0942 std::unique_ptr<base::PowerMonitorSource> power_monitor_source(
[email protected]6b492fd2013-11-14 01:45:5043 new base::PowerMonitorDeviceSource());
dcheng70c49422016-03-02 23:20:3444 base::PowerMonitor power_monitor(std::move(power_monitor_source));
[email protected]6b492fd2013-11-14 01:45:5045 base::HighResolutionTimerManager hi_res_timer_manager;
46
47 NaClBrokerListener listener;
48 listener.Listen();
49
50 return 0;
51}
52
53} // namespace
54
55namespace nacl {
56
57int NaClWin64Main() {
58 sandbox::SandboxInterfaceInfo sandbox_info = {0};
59 content::InitializeSandboxInfo(&sandbox_info);
60
kkosztyo.u-szegedb33617c2014-12-04 09:54:3661 const base::CommandLine& command_line =
62 *base::CommandLine::ForCurrentProcess();
[email protected]6b492fd2013-11-14 01:45:5063 std::string process_type =
64 command_line.GetSwitchValueASCII(switches::kProcessType);
65
66 // Copy what ContentMain() does.
67 base::EnableTerminationOnHeapCorruption();
68 base::EnableTerminationOnOutOfMemory();
pmonette18d3ed32015-10-16 21:06:0669 base::win::RegisterInvalidParamHandler();
70 base::win::SetupCRT(command_line);
[email protected]6b492fd2013-11-14 01:45:5071 // Route stdio to parent console (if any) or create one.
72 if (command_line.HasSwitch(switches::kEnableLogging))
jam79dc59a2015-08-17 03:38:1673 base::RouteStdioToConsole(true);
[email protected]6b492fd2013-11-14 01:45:5074
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