blob: 01d1aa74c8f975fbe614074e816dacc92f6a2073 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2013 The Chromium Authors
[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"
Chris Sharp7840c582019-08-02 15:45:328#include "base/message_loop/message_pump_type.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"
Alex Clarkef7fb8a82019-06-06 15:41:5311#include "base/task/single_thread_task_executor.h"
[email protected]89bf27e2013-06-27 18:04:5612#include "base/timer/hi_res_timer_manager.h"
dcheng51ace48a2015-12-26 22:45:1713#include "build/build_config.h"
[email protected]6fdb60c2013-07-31 05:06:5914#include "components/nacl/loader/nacl_listener.h"
15#include "components/nacl/loader/nacl_main_platform_delegate.h"
[email protected]4573fbd2011-10-31 20:25:1816#include "content/public/common/main_function_params.h"
Ken Rockot9b26bc52018-07-04 19:57:4917#include "mojo/core/embedder/embedder.h"
Robert Sesek7d0b49b2020-07-08 18:31:2718#include "sandbox/policy/switches.h"
[email protected]103607e2010-02-01 18:57:0919
Xiaohan Wangb45377c82022-01-14 15:40:2620#if BUILDFLAG(IS_WIN)
Gabriel Charettefbeeb1c2021-11-10 20:50:0621#include "base/win/win_util.h"
22#endif
23
[email protected]103607e2010-02-01 18:57:0924// main() routine for the NaCl loader process.
Gabriel Charettefbeeb1c2021-11-10 20:50:0625int NaClMain(content::MainFunctionParams parameters) {
26 const base::CommandLine& parsed_command_line = *parameters.command_line;
[email protected]599e6642010-01-27 18:52:1327
rockot6d7be622016-06-15 18:25:1928 // The Mojo EDK must be initialized before using IPC.
Ken Rockot9b26bc52018-07-04 19:57:4929 mojo::core::Init();
rockot6d7be622016-06-15 18:25:1930
[email protected]08a3ef62009-09-26 01:22:1031 // The main thread of the plugin services IO.
Chris Sharp7840c582019-08-02 15:45:3232 base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::IO);
[email protected]ce072a72010-12-31 20:02:1633 base::PlatformThread::SetName("CrNaClMain");
[email protected]08a3ef62009-09-26 01:22:1034
Matt Menkedb9fc40b2019-06-19 17:57:3535 base::PowerMonitor::Initialize(
36 std::make_unique<base::PowerMonitorDeviceSource>());
[email protected]89bf27e2013-06-27 18:04:5637 base::HighResolutionTimerManager hi_res_timer_manager;
[email protected]08a3ef62009-09-26 01:22:1038
Xiaohan Wangb45377c82022-01-14 15:40:2639#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \
40 BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
mlamouric5317ce2015-07-06 22:57:0141 NaClMainPlatformDelegate platform;
Jay Civelli3ae893e2018-04-17 20:07:0542 bool no_sandbox =
Robert Sesek7d0b49b2020-07-08 18:31:2743 parsed_command_line.HasSwitch(sandbox::policy::switches::kNoSandbox);
[email protected]599e6642010-01-27 18:52:1344
Xiaohan Wangb45377c82022-01-14 15:40:2645#if BUILDFLAG(IS_WIN)
Derek Schuff7b657932020-04-10 23:43:0646 // NaCl processes exit differently from other Chromium processes (see NaClExit
47 // in native_client/src/shared/platform/win/nacl_exit.c) and so do not want
48 // default Chromium process exit behavior.
49 base::win::SetShouldCrashOnProcessDetach(false);
50#endif
51
Xiaohan Wangb45377c82022-01-14 15:40:2652#if BUILDFLAG(IS_POSIX)
[email protected]4e7199b2013-06-21 03:57:5853 // The number of cores must be obtained before the invocation of
54 // platform.EnableSandbox(), so cannot simply be inlined below.
55 int number_of_cores = sysconf(_SC_NPROCESSORS_ONLN);
56#endif
57
[email protected]23acfc02010-07-15 23:02:5258 if (!no_sandbox) {
mlamouric5317ce2015-07-06 22:57:0159 platform.EnableSandbox(parameters);
[email protected]23acfc02010-07-15 23:02:5260 }
[email protected]913d2062013-08-13 05:39:5561 NaClListener listener;
Xiaohan Wangb45377c82022-01-14 15:40:2662#if BUILDFLAG(IS_POSIX)
[email protected]913d2062013-08-13 05:39:5563 listener.set_number_of_cores(number_of_cores);
[email protected]4e7199b2013-06-21 03:57:5864#endif
[email protected]913d2062013-08-13 05:39:5565
66 listener.Listen();
[email protected]08a3ef62009-09-26 01:22:1067#else
[email protected]599e6642010-01-27 18:52:1368 NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc.";
[email protected]08a3ef62009-09-26 01:22:1069#endif
[email protected]08a3ef62009-09-26 01:22:1070 return 0;
71}