OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/runner/host/child_process_host.h" | 5 #include "mojo/runner/host/child_process_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/process/kill.h" | 13 #include "base/process/kill.h" |
14 #include "base/process/launch.h" | 14 #include "base/process/launch.h" |
15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 17 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
18 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
19 #include "mojo/runner/host/switches.h" | 19 #include "mojo/runner/host/switches.h" |
20 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | 20 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" |
21 | 21 |
22 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 22 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
23 #include "sandbox/linux/services/namespace_sandbox.h" | 23 #include "sandbox/linux/services/namespace_sandbox.h" |
24 #endif | 24 #endif |
25 | 25 |
| 26 #if defined(OS_WIN) |
| 27 #include "base/win/windows_version.h" |
| 28 #endif |
| 29 |
26 namespace mojo { | 30 namespace mojo { |
27 namespace runner { | 31 namespace runner { |
28 | 32 |
29 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, | 33 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, |
30 bool start_sandboxed, | 34 bool start_sandboxed, |
31 const base::FilePath& app_path) | 35 const base::FilePath& app_path) |
32 : launch_process_runner_(launch_process_runner), | 36 : launch_process_runner_(launch_process_runner), |
33 start_sandboxed_(start_sandboxed), | 37 start_sandboxed_(start_sandboxed), |
34 app_path_(app_path), | 38 app_path_(app_path), |
35 channel_info_(nullptr), | 39 channel_info_(nullptr), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 132 |
129 if (start_sandboxed_) | 133 if (start_sandboxed_) |
130 child_command_line.AppendSwitch(switches::kEnableSandbox); | 134 child_command_line.AppendSwitch(switches::kEnableSandbox); |
131 | 135 |
132 embedder::HandlePassingInformation handle_passing_info; | 136 embedder::HandlePassingInformation handle_passing_info; |
133 platform_channel_pair_.PrepareToPassClientHandleToChildProcess( | 137 platform_channel_pair_.PrepareToPassClientHandleToChildProcess( |
134 &child_command_line, &handle_passing_info); | 138 &child_command_line, &handle_passing_info); |
135 | 139 |
136 base::LaunchOptions options; | 140 base::LaunchOptions options; |
137 #if defined(OS_WIN) | 141 #if defined(OS_WIN) |
138 options.handles_to_inherit = &handle_passing_info; | 142 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 143 options.handles_to_inherit = &handle_passing_info; |
| 144 } else { |
| 145 #if defined(OFFICIAL_BUILD) |
| 146 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; |
| 147 #endif |
| 148 options.inherit_handles = true; |
| 149 } |
139 options.stdin_handle = INVALID_HANDLE_VALUE; | 150 options.stdin_handle = INVALID_HANDLE_VALUE; |
140 options.stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); | 151 options.stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); |
141 options.stderr_handle = GetStdHandle(STD_ERROR_HANDLE); | 152 options.stderr_handle = GetStdHandle(STD_ERROR_HANDLE); |
142 | 153 |
143 // Pseudo handles are used when stdout and stderr redirect to the console. In | 154 // Pseudo handles are used when stdout and stderr redirect to the console. In |
144 // that case, they're automatically inherited by child processes. See | 155 // that case, they're automatically inherited by child processes. See |
145 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682075.aspx | 156 // https://msdn.microsoft.com/en-us/library/windows/desktop/ms682075.aspx |
146 // Trying to add them to the list of handles to inherit causes CreateProcess | 157 // Trying to add them to the list of handles to inherit causes CreateProcess |
147 // to fail. When this process is launched from Python | 158 // to fail. When this process is launched from Python |
148 // (i.e. by apptest_runner.py) then a real handle is used. In that case, we do | 159 // (i.e. by apptest_runner.py) then a real handle is used. In that case, we do |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { | 200 void ChildProcessHost::DidCreateChannel(embedder::ChannelInfo* channel_info) { |
190 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; | 201 DVLOG(2) << "AppChildProcessHost::DidCreateChannel()"; |
191 | 202 |
192 DCHECK(channel_info || | 203 DCHECK(channel_info || |
193 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); | 204 base::CommandLine::ForCurrentProcess()->HasSwitch("use-new-edk")); |
194 channel_info_ = channel_info; | 205 channel_info_ = channel_info; |
195 } | 206 } |
196 | 207 |
197 } // namespace runner | 208 } // namespace runner |
198 } // namespace mojo | 209 } // namespace mojo |
OLD | NEW |