|
OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
Brad Chen (chromium)
2011/09/11 17:35:37
Someplace, perhaps here, it would be nice to have
jam
2011/09/11 22:51:37
that sounds like a good idea. Is there no other do
| |
4 | |
5 #include "base/at_exit.h" | |
6 #include "base/command_line.h" | |
7 #include "base/logging.h" | |
8 #include "base/message_loop.h" | |
9 #include "base/process_util.h" | |
10 #include "base/string_util.h" | |
11 #include "base/system_monitor/system_monitor.h" | |
12 #include "chrome/common/chrome_result_codes.h" | |
13 #include "chrome/common/chrome_switches.h" | |
14 #include "chrome/common/logging_chrome.h" | |
15 #include "chrome/nacl/nacl_broker_listener.h" | |
16 #include "chrome/nacl/nacl_listener.h" | |
17 #include "chrome/nacl/nacl_main_platform_delegate.h" | |
18 #include "content/app/startup_helper_win.h" | |
19 #include "content/common/hi_res_timer_manager.h" | |
20 #include "content/common/main_function_params.h" | |
21 #include "content/common/sandbox_init_wrapper.h" | |
22 #include "content/common/sandbox_policy.h" | |
23 #include "sandbox/src/sandbox.h" | |
24 | |
25 // main() routine for the NaCl broker process. | |
26 // This is necessary for supporting NaCl in Chrome on Win64. | |
27 int NaClBrokerMain(const MainFunctionParams& parameters) { | |
28 const CommandLine& parsed_command_line = parameters.command_line_; | |
29 | |
30 // NOTE: this code is duplicated from browser_main.cc | |
31 // IMPORTANT: This piece of code needs to run as early as possible in the | |
32 // process because it will initialize the sandbox broker, which requires the | |
33 // process to swap its window station. During this time all the UI will be | |
34 // broken. This has to run before threads and windows are created. | |
35 sandbox::BrokerServices* broker_services = | |
36 parameters.sandbox_info_.BrokerServices(); | |
37 if (broker_services) { | |
38 sandbox::InitBrokerServices(broker_services); | |
39 if (!parsed_command_line.HasSwitch(switches::kNoSandbox)) { | |
40 bool use_winsta = !parsed_command_line.HasSwitch( | |
41 switches::kDisableAltWinstation); | |
42 // Precreate the desktop and window station used by the renderers. | |
43 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | |
44 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | |
45 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | |
46 policy->Release(); | |
47 } | |
48 } | |
49 | |
50 NaClBrokerListener listener; | |
51 listener.Listen(); | |
52 | |
53 return 0; | |
54 } | |
55 | |
56 // main() routine for the NaCl loader process. | |
57 int NaClMain(const MainFunctionParams& parameters) { | |
58 const CommandLine& parsed_command_line = parameters.command_line_; | |
59 | |
60 NaClMainPlatformDelegate platform(parameters); | |
61 | |
62 platform.PlatformInitialize(); | |
63 bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox); | |
64 platform.InitSandboxTests(no_sandbox); | |
65 if (!no_sandbox) | |
66 platform.EnableSandbox(); | |
67 | |
68 bool sandbox_test_result = platform.RunSandboxTests(); | |
69 if (sandbox_test_result) { | |
70 bool debug = parsed_command_line.HasSwitch(switches::kEnableNaClDebug); | |
Brad Chen (chromium)
2011/09/11 17:35:37
If you are unclear about how this debug support wo
| |
71 NaClListener listener; | |
72 listener.set_debug_enabled(debug); | |
73 listener.Listen(); | |
74 } else { | |
75 // This indirectly prevents the test-harness-success-cookie from being set, | |
76 // as a way of communicating test failure, because the nexe won't reply. | |
77 // TODO(jvoung): find a better way to indicate failure that doesn't | |
78 // require waiting for a timeout. | |
79 VLOG(1) << "Sandbox test failed: Not launching NaCl process"; | |
80 } | |
81 | |
82 platform.PlatformUninitialize(); | |
83 return 0; | |
84 } | |
85 | |
86 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. | |
87 extern "C" { | |
88 | |
89 __declspec(dllexport) int __cdecl ChromeMain( | |
Brad Chen (chromium)
2011/09/11 17:35:37
Can you add some sort of comment that explains why
jam
2011/09/11 22:51:37
The code in MainDllLoader (called from nacl_exe_wi
| |
90 HINSTANCE instance, sandbox::SandboxInterfaceInfo* sandbox_info) { | |
91 base::AtExitManager exit_manager; | |
92 CommandLine::Init(0, NULL); | |
93 | |
94 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
95 std::string process_type = | |
96 command_line.GetSwitchValueASCII(switches::kProcessType); | |
97 | |
98 // Copy what ContentMain() does. | |
99 base::EnableTerminationOnHeapCorruption(); | |
100 base::EnableTerminationOnOutOfMemory(); | |
101 content::RegisterInvalidParamHandler(); | |
102 content::SetupCRT(command_line); | |
103 | |
104 // Initialize the sandbox for this process. | |
105 SandboxInitWrapper sandbox_wrapper; | |
106 sandbox_wrapper.SetServices(sandbox_info); | |
107 bool sandbox_initialized_ok = | |
108 sandbox_wrapper.InitializeSandbox(command_line, process_type); | |
109 // Die if the sandbox can't be enabled. | |
110 CHECK(sandbox_initialized_ok) << "Error initializing sandbox for " | |
111 << process_type; | |
112 MainFunctionParams main_params(command_line, sandbox_wrapper, NULL); | |
113 | |
114 MessageLoopForIO main_message_loop; | |
115 base::PlatformThread::SetName("CrNaCl64Main"); | |
116 | |
117 base::SystemMonitor system_monitor; | |
118 HighResolutionTimerManager hi_res_timer_manager; | |
119 | |
120 if (process_type == switches::kNaClLoaderProcess) | |
121 return NaClMain(main_params); | |
122 | |
123 if (process_type == switches::kNaClBrokerProcess) | |
124 return NaClBrokerMain(main_params); | |
125 | |
126 CHECK(false) << "Unknown NaCl 64 process."; | |
127 return -1; | |
128 } | |
129 | |
130 } // extern "C" | |
OLD | NEW |