blob: cdd74caee848fcbed840881f1bae036f77ff9bdb [file] [log] [blame]
[email protected]6fdb60c2013-07-31 05:06:591// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]08a3ef62009-09-26 01:22:102// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
dcheng51ace48a2015-12-26 22:45:175#include <utility>
[email protected]08a3ef62009-09-26 01:22:106
[email protected]08a3ef62009-09-26 01:22:107#include "base/command_line.h"
[email protected]68275102013-07-17 23:54:208#include "base/message_loop/message_loop.h"
[email protected]6c5905b72013-04-03 19:06:519#include "base/power_monitor/power_monitor.h"
[email protected]9dd90152013-08-02 22:09:1310#include "base/power_monitor/power_monitor_device_source.h"
[email protected]89bf27e2013-06-27 18:04:5611#include "base/timer/hi_res_timer_manager.h"
dcheng51ace48a2015-12-26 22:45:1712#include "build/build_config.h"
[email protected]6fdb60c2013-07-31 05:06:5913#include "components/nacl/loader/nacl_listener.h"
14#include "components/nacl/loader/nacl_main_platform_delegate.h"
[email protected]4573fbd2011-10-31 20:25:1815#include "content/public/common/main_function_params.h"
rockot6d7be622016-06-15 18:25:1916#include "mojo/edk/embedder/embedder.h"
Jay Civelli3ae893e2018-04-17 20:07:0517#include "services/service_manager/sandbox/switches.h"
[email protected]103607e2010-02-01 18:57:0918
[email protected]103607e2010-02-01 18:57:0919// main() routine for the NaCl loader process.
[email protected]4573fbd2011-10-31 20:25:1820int NaClMain(const content::MainFunctionParams& parameters) {
kkosztyo.u-szegedb33617c2014-12-04 09:54:3621 const base::CommandLine& parsed_command_line = parameters.command_line;
[email protected]599e6642010-01-27 18:52:1322
rockot6d7be622016-06-15 18:25:1923 // The Mojo EDK must be initialized before using IPC.
24 mojo::edk::Init();
25
[email protected]08a3ef62009-09-26 01:22:1026 // The main thread of the plugin services IO.
[email protected]bb024fe2013-05-10 21:33:2627 base::MessageLoopForIO main_message_loop;
[email protected]ce072a72010-12-31 20:02:1628 base::PlatformThread::SetName("CrNaClMain");
[email protected]08a3ef62009-09-26 01:22:1029
dcheng24f43a5e92016-04-22 18:29:0930 std::unique_ptr<base::PowerMonitorSource> power_monitor_source(
[email protected]9dd90152013-08-02 22:09:1331 new base::PowerMonitorDeviceSource());
dcheng51ace48a2015-12-26 22:45:1732 base::PowerMonitor power_monitor(std::move(power_monitor_source));
[email protected]89bf27e2013-06-27 18:04:5633 base::HighResolutionTimerManager hi_res_timer_manager;
[email protected]08a3ef62009-09-26 01:22:1034
[email protected]d33d2222014-06-04 15:39:5835#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) || \
36 defined(OS_ANDROID)
mlamouric5317ce2015-07-06 22:57:0137 NaClMainPlatformDelegate platform;
Jay Civelli3ae893e2018-04-17 20:07:0538 bool no_sandbox =
39 parsed_command_line.HasSwitch(service_manager::switches::kNoSandbox);
[email protected]599e6642010-01-27 18:52:1340
[email protected]4e7199b2013-06-21 03:57:5841#if defined(OS_POSIX)
42 // The number of cores must be obtained before the invocation of
43 // platform.EnableSandbox(), so cannot simply be inlined below.
44 int number_of_cores = sysconf(_SC_NPROCESSORS_ONLN);
45#endif
46
[email protected]23acfc02010-07-15 23:02:5247 if (!no_sandbox) {
mlamouric5317ce2015-07-06 22:57:0148 platform.EnableSandbox(parameters);
[email protected]23acfc02010-07-15 23:02:5249 }
[email protected]913d2062013-08-13 05:39:5550 NaClListener listener;
[email protected]4e7199b2013-06-21 03:57:5851#if defined(OS_POSIX)
[email protected]913d2062013-08-13 05:39:5552 listener.set_number_of_cores(number_of_cores);
[email protected]4e7199b2013-06-21 03:57:5853#endif
[email protected]913d2062013-08-13 05:39:5554
55 listener.Listen();
[email protected]08a3ef62009-09-26 01:22:1056#else
[email protected]599e6642010-01-27 18:52:1357 NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc.";
[email protected]08a3ef62009-09-26 01:22:1058#endif
[email protected]08a3ef62009-09-26 01:22:1059 return 0;
60}