1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <utility> 6 7 #include "base/command_line.h" 8 #include "base/feature_list.h" 9 #include "base/message_loop/message_pump_type.h" 10 #include "base/power_monitor/power_monitor.h" 11 #include "base/power_monitor/power_monitor_source.h" 12 #include "base/task/single_thread_task_executor.h" 13 #include "base/timer/hi_res_timer_manager.h" 14 #include "build/build_config.h" 15 #include "components/nacl/loader/nacl_listener.h" 16 #include "components/nacl/loader/nacl_main_platform_delegate.h" 17 #include "components/power_monitor/make_power_monitor_device_source.h" 18 #include "content/public/common/main_function_params.h" 19 #include "mojo/core/embedder/embedder.h" 20 #include "sandbox/policy/switches.h" 21 22 #if BUILDFLAG(IS_WIN) 23 #include "base/win/win_util.h" 24 #endif 25 26 // main() routine for the NaCl loader process. NaClMain(content::MainFunctionParams parameters)27int NaClMain(content::MainFunctionParams parameters) { 28 const base::CommandLine& parsed_command_line = *parameters.command_line; 29 30 // The Mojo EDK must be initialized before using IPC. 31 mojo::core::InitFeatures(); 32 mojo::core::Init(); 33 34 // The main thread of the plugin services IO. 35 base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::IO); 36 base::PlatformThread::SetName("CrNaClMain"); 37 38 base::PowerMonitor::Initialize(MakePowerMonitorDeviceSource()); 39 base::HighResolutionTimerManager hi_res_timer_manager; 40 41 #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_LINUX) || \ 42 BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) 43 NaClMainPlatformDelegate platform; 44 bool no_sandbox = 45 parsed_command_line.HasSwitch(sandbox::policy::switches::kNoSandbox); 46 47 #if BUILDFLAG(IS_WIN) 48 // NaCl processes exit differently from other Chromium processes (see NaClExit 49 // in native_client/src/shared/platform/win/nacl_exit.c) and so do not want 50 // default Chromium process exit behavior. 51 base::win::SetShouldCrashOnProcessDetach(false); 52 #endif 53 54 #if BUILDFLAG(IS_POSIX) 55 // The number of cores must be obtained before the invocation of 56 // platform.EnableSandbox(), so cannot simply be inlined below. 57 int number_of_cores = sysconf(_SC_NPROCESSORS_ONLN); 58 #endif 59 60 if (!no_sandbox) { 61 platform.EnableSandbox(parameters); 62 } 63 NaClListener listener; 64 #if BUILDFLAG(IS_POSIX) 65 listener.set_number_of_cores(number_of_cores); 66 #endif 67 68 listener.Listen(); 69 #else 70 NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc."; 71 #endif 72 return 0; 73 } 74