OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | |
8 #include <windows.h> | |
9 #endif | |
10 | |
11 #include "base/command_line.h" | 7 #include "base/command_line.h" |
12 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
13 #include "base/string_util.h" | |
14 #include "base/system_monitor/system_monitor.h" | 9 #include "base/system_monitor/system_monitor.h" |
15 #include "chrome/common/chrome_constants.h" | |
16 #include "chrome/common/chrome_result_codes.h" | 10 #include "chrome/common/chrome_result_codes.h" |
17 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/logging_chrome.h" | 12 #include "chrome/common/logging_chrome.h" |
19 #include "chrome/nacl/nacl_listener.h" | 13 #include "chrome/nacl/nacl_listener.h" |
20 #include "chrome/nacl/nacl_main_platform_delegate.h" | 14 #include "chrome/nacl/nacl_main_platform_delegate.h" |
21 #include "content/common/child_process.h" | 15 #include "content/common/child_process.h" |
22 #include "content/common/child_process_info.h" | |
23 #include "content/common/hi_res_timer_manager.h" | 16 #include "content/common/hi_res_timer_manager.h" |
24 #include "content/common/main_function_params.h" | 17 #include "content/common/main_function_params.h" |
25 #include "content/common/sandbox_policy.h" | |
26 #include "ipc/ipc_switches.h" | |
27 | |
28 #if defined(OS_WIN) | |
29 #include "chrome/nacl/broker_thread.h" | |
30 #include "sandbox/src/sandbox.h" | |
31 #endif | |
32 | |
33 #ifdef _WIN64 | |
34 | |
35 // main() routine for the NaCl broker process. | |
36 // This is necessary for supporting NaCl in Chrome on Win64. | |
37 int NaClBrokerMain(const MainFunctionParams& parameters) { | |
38 // The main thread of the broker. | |
39 MessageLoopForIO main_message_loop; | |
40 base::PlatformThread::SetName("CrNaClBrokerMain"); | |
41 | |
42 base::SystemMonitor system_monitor; | |
43 HighResolutionTimerManager hi_res_timer_manager; | |
44 | |
45 const CommandLine& parsed_command_line = parameters.command_line_; | |
46 | |
47 DVLOG(1) << "Started NaCL broker with " | |
48 << parsed_command_line.GetCommandLineString(); | |
49 | |
50 // NOTE: this code is duplicated from browser_main.cc | |
51 // IMPORTANT: This piece of code needs to run as early as possible in the | |
52 // process because it will initialize the sandbox broker, which requires the | |
53 // process to swap its window station. During this time all the UI will be | |
54 // broken. This has to run before threads and windows are created. | |
55 sandbox::BrokerServices* broker_services = | |
56 parameters.sandbox_info_.BrokerServices(); | |
57 if (broker_services) { | |
58 sandbox::InitBrokerServices(broker_services); | |
59 if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) { | |
60 bool use_winsta = !parsed_command_line.HasSwitch( | |
61 switches::kDisableAltWinstation); | |
62 // Precreate the desktop and window station used by the renderers. | |
63 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | |
64 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | |
65 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | |
66 policy->Release(); | |
67 } | |
68 } | |
69 | |
70 { | |
71 ChildProcess broker_process; | |
72 broker_process.set_main_thread(new NaClBrokerThread()); | |
73 MessageLoop::current()->Run(); | |
74 } | |
75 | |
76 return 0; | |
77 } | |
78 #else | |
79 int NaClBrokerMain(const MainFunctionParams& parameters) { | |
80 return chrome::RESULT_CODE_BAD_PROCESS_TYPE; | |
81 } | |
82 #endif // _WIN64 | |
83 | 18 |
84 // This function provides some ways to test crash and assertion handling | 19 // This function provides some ways to test crash and assertion handling |
85 // behavior of the renderer. | 20 // behavior of the renderer. |
86 static void HandleNaClTestParameters(const CommandLine& command_line) { | 21 static void HandleNaClTestParameters(const CommandLine& command_line) { |
| 22 // The message box doesn't work in the 64 bit binaries anyways, so no need to |
| 23 // link to it since the 64 bit binary doesn't link with chrome or content. |
| 24 #if !defined(NACL_WIN64) |
87 if (command_line.HasSwitch(switches::kNaClStartupDialog)) { | 25 if (command_line.HasSwitch(switches::kNaClStartupDialog)) { |
88 ChildProcess::WaitForDebugger("NativeClient"); | 26 ChildProcess::WaitForDebugger("NativeClient"); |
89 } | 27 } |
| 28 #endif |
90 } | 29 } |
91 | 30 |
92 // main() routine for the NaCl loader process. | 31 // main() routine for the NaCl loader process. |
93 int NaClMain(const MainFunctionParams& parameters) { | 32 int NaClMain(const MainFunctionParams& parameters) { |
94 const CommandLine& parsed_command_line = parameters.command_line_; | 33 const CommandLine& parsed_command_line = parameters.command_line_; |
95 | 34 |
96 // This function allows pausing execution using the --nacl-startup-dialog | 35 // This function allows pausing execution using the --nacl-startup-dialog |
97 // flag allowing us to attach a debugger. | 36 // flag allowing us to attach a debugger. |
98 // Do not move this function down since that would mean we can't easily debug | 37 // Do not move this function down since that would mean we can't easily debug |
99 // whatever occurs before it. | 38 // whatever occurs before it. |
(...skipping 30 matching lines...) Expand all Loading... |
130 // require waiting for a timeout. | 69 // require waiting for a timeout. |
131 VLOG(1) << "Sandbox test failed: Not launching NaCl process"; | 70 VLOG(1) << "Sandbox test failed: Not launching NaCl process"; |
132 } | 71 } |
133 #else | 72 #else |
134 NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc."; | 73 NOTIMPLEMENTED() << " not implemented startup, plugin startup dialog etc."; |
135 #endif | 74 #endif |
136 | 75 |
137 platform.PlatformUninitialize(); | 76 platform.PlatformUninitialize(); |
138 return 0; | 77 return 0; |
139 } | 78 } |
OLD | NEW |