nacl_exe_win_64.cc revision 558790d6acca3451cf3a6b497803a5f07d0bec58
1// Copyright (c) 2012 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 5#include "base/at_exit.h" 6#include "base/command_line.h" 7#include "base/lazy_instance.h" 8#include "base/logging.h" 9#include "base/message_loop/message_loop.h" 10#include "base/power_monitor/power_monitor.h" 11#include "base/process/launch.h" 12#include "base/process/memory.h" 13#include "base/strings/string_util.h" 14#include "base/timer/hi_res_timer_manager.h" 15#include "chrome/app/breakpad_win.h" 16#include "chrome/app/chrome_breakpad_client.h" 17#include "chrome/common/chrome_result_codes.h" 18#include "chrome/common/logging_chrome.h" 19#include "chrome/nacl/nacl_listener.h" 20#include "chrome/nacl/nacl_main_platform_delegate.h" 21#include "components/breakpad/breakpad_client.h" 22#include "components/nacl/broker/nacl_broker_listener.h" 23#include "components/nacl/common/nacl_switches.h" 24#include "content/public/app/startup_helper_win.h" 25#include "content/public/common/content_switches.h" 26#include "content/public/common/main_function_params.h" 27#include "content/public/common/sandbox_init.h" 28#include "sandbox/win/src/sandbox_types.h" 29 30extern int NaClMain(const content::MainFunctionParams&); 31 32namespace { 33 34base::LazyInstance<chrome::ChromeBreakpadClient>::Leaky 35 g_chrome_breakpad_client = LAZY_INSTANCE_INITIALIZER; 36 37} // namespace 38 39// main() routine for the NaCl broker process. 40// This is necessary for supporting NaCl in Chrome on Win64. 41int NaClBrokerMain(const content::MainFunctionParams& parameters) { 42 const CommandLine& parsed_command_line = parameters.command_line; 43 44 base::MessageLoopForIO main_message_loop; 45 base::PlatformThread::SetName("CrNaClBrokerMain"); 46 47 base::PowerMonitor power_monitor; 48 base::HighResolutionTimerManager hi_res_timer_manager; 49 50 NaClBrokerListener listener; 51 listener.Listen(); 52 53 return 0; 54} 55 56int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) { 57 sandbox::SandboxInterfaceInfo sandbox_info = {0}; 58 content::InitializeSandboxInfo(&sandbox_info); 59 60 base::AtExitManager exit_manager; 61 CommandLine::Init(0, NULL); 62 63 breakpad::SetBreakpadClient(g_chrome_breakpad_client.Pointer()); 64 InitCrashReporter(); 65 66 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 67 std::string process_type = 68 command_line.GetSwitchValueASCII(switches::kProcessType); 69 70 // Copy what ContentMain() does. 71 base::EnableTerminationOnHeapCorruption(); 72 base::EnableTerminationOnOutOfMemory(); 73 content::RegisterInvalidParamHandler(); 74 content::SetupCRT(command_line); 75 // Route stdio to parent console (if any) or create one. 76 if (command_line.HasSwitch(switches::kEnableLogging)) 77 base::RouteStdioToConsole(); 78 79 // Initialize the sandbox for this process. 80 bool sandbox_initialized_ok = content::InitializeSandbox(&sandbox_info); 81 // Die if the sandbox can't be enabled. 82 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " 83 << process_type; 84 content::MainFunctionParams main_params(command_line); 85 main_params.sandbox_info = &sandbox_info; 86 87 if (process_type == switches::kNaClLoaderProcess) 88 return NaClMain(main_params); 89 90 if (process_type == switches::kNaClBrokerProcess) 91 return NaClBrokerMain(main_params); 92 93 CHECK(false) << "Unknown NaCl 64 process."; 94 return -1; 95} 96