Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame^] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
dcheng | 51ace48a | 2015-12-26 22:45:17 | [diff] [blame] | 5 | #include <utility> |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 6 | |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 7 | #include "base/command_line.h" |
Chris Sharp | 7840c58 | 2019-08-02 15:45:32 | [diff] [blame] | 8 | #include "base/message_loop/message_pump_type.h" |
[email protected] | 6c5905b7 | 2013-04-03 19:06:51 | [diff] [blame] | 9 | #include "base/power_monitor/power_monitor.h" |
[email protected] | 9dd9015 | 2013-08-02 22:09:13 | [diff] [blame] | 10 | #include "base/power_monitor/power_monitor_device_source.h" |
Alex Clarke | f7fb8a8 | 2019-06-06 15:41:53 | [diff] [blame] | 11 | #include "base/task/single_thread_task_executor.h" |
[email protected] | 89bf27e | 2013-06-27 18:04:56 | [diff] [blame] | 12 | #include "base/timer/hi_res_timer_manager.h" |
dcheng | 51ace48a | 2015-12-26 22:45:17 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 6fdb60c | 2013-07-31 05:06:59 | [diff] [blame] | 14 | #include "components/nacl/loader/nacl_listener.h" |
15 | #include "components/nacl/loader/nacl_main_platform_delegate.h" | ||||
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 16 | #include "content/public/common/main_function_params.h" |
Ken Rockot | 9b26bc5 | 2018-07-04 19:57:49 | [diff] [blame] | 17 | #include "mojo/core/embedder/embedder.h" |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 18 | #include "sandbox/policy/switches.h" |
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 19 | |
Xiaohan Wang | b45377c8 | 2022-01-14 15:40:26 | [diff] [blame] | 20 | #if BUILDFLAG(IS_WIN) |
Gabriel Charette | fbeeb1c | 2021-11-10 20:50:06 | [diff] [blame] | 21 | #include "base/win/win_util.h" |
22 | #endif | ||||
23 | |||||
[email protected] | 103607e | 2010-02-01 18:57:09 | [diff] [blame] | 24 | // main() routine for the NaCl loader process. |
Gabriel Charette | fbeeb1c | 2021-11-10 20:50:06 | [diff] [blame] | 25 | int NaClMain(content::MainFunctionParams parameters) { |
26 | const base::CommandLine& parsed_command_line = *parameters.command_line; | ||||
[email protected] | 599e664 | 2010-01-27 18:52:13 | [diff] [blame] | 27 | |
rockot | 6d7be62 | 2016-06-15 18:25:19 | [diff] [blame] | 28 | // The Mojo EDK must be initialized before using IPC. |
Ken Rockot | 9b26bc5 | 2018-07-04 19:57:49 | [diff] [blame] | 29 | mojo::core::Init(); |
rockot | 6d7be62 | 2016-06-15 18:25:19 | [diff] [blame] | 30 | |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 31 | // The main thread of the plugin services IO. |
Chris Sharp | 7840c58 | 2019-08-02 15:45:32 | [diff] [blame] | 32 | base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::IO); |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 33 | base::PlatformThread::SetName("CrNaClMain"); |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 34 | |
Matt Menke | db9fc40b | 2019-06-19 17:57:35 | [diff] [blame] | 35 | base::PowerMonitor::Initialize( |
36 | std::make_unique<base::PowerMonitorDeviceSource>()); | ||||
[email protected] | 89bf27e | 2013-06-27 18:04:56 | [diff] [blame] | 37 | base::HighResolutionTimerManager hi_res_timer_manager; |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 38 | |
Xiaohan Wang | b45377c8 | 2022-01-14 15:40:26 | [diff] [blame] | 39 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \ |
40 | BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) | ||||
mlamouri | c5317ce | 2015-07-06 22:57:01 | [diff] [blame] | 41 | NaClMainPlatformDelegate platform; |
Jay Civelli | 3ae893e | 2018-04-17 20:07:05 | [diff] [blame] | 42 | bool no_sandbox = |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 43 | parsed_command_line.HasSwitch(sandbox::policy::switches::kNoSandbox); |
[email protected] | 599e664 | 2010-01-27 18:52:13 | [diff] [blame] | 44 | |
Xiaohan Wang | b45377c8 | 2022-01-14 15:40:26 | [diff] [blame] | 45 | #if BUILDFLAG(IS_WIN) |
Derek Schuff | 7b65793 | 2020-04-10 23:43:06 | [diff] [blame] | 46 | // 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 Wang | b45377c8 | 2022-01-14 15:40:26 | [diff] [blame] | 52 | #if BUILDFLAG(IS_POSIX) |
[email protected] | 4e7199b | 2013-06-21 03:57:58 | [diff] [blame] | 53 | // 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] | 23acfc0 | 2010-07-15 23:02:52 | [diff] [blame] | 58 | if (!no_sandbox) { |
mlamouri | c5317ce | 2015-07-06 22:57:01 | [diff] [blame] | 59 | platform.EnableSandbox(parameters); |
[email protected] | 23acfc0 | 2010-07-15 23:02:52 | [diff] [blame] | 60 | } |
[email protected] | 913d206 | 2013-08-13 05:39:55 | [diff] [blame] | 61 | NaClListener listener; |
Xiaohan Wang | b45377c8 | 2022-01-14 15:40:26 | [diff] [blame] | 62 | #if BUILDFLAG(IS_POSIX) |
[email protected] | 913d206 | 2013-08-13 05:39:55 | [diff] [blame] | 63 | listener.set_number_of_cores(number_of_cores); |
[email protected] | 4e7199b | 2013-06-21 03:57:58 | [diff] [blame] | 64 | #endif |
[email protected] | 913d206 | 2013-08-13 05:39:55 | [diff] [blame] | 65 | |
66 | listener.Listen(); | ||||
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 67 | #else |
[email protected] | 599e664 | 2010-01-27 18:52:13 | [diff] [blame] | 68 | NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc."; |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 69 | #endif |
[email protected] | 08a3ef6 | 2009-09-26 01:22:10 | [diff] [blame] | 70 | return 0; |
71 | } |