OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/process/launch.h" | 5 #include "base/process/launch.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <windows.h> | 10 #include <windows.h> |
11 #include <userenv.h> | 11 #include <userenv.h> |
12 #include <psapi.h> | 12 #include <psapi.h> |
13 | 13 |
14 #include <ios> | 14 #include <ios> |
15 #include <limits> | 15 #include <limits> |
16 | 16 |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/debug/stack_trace.h" | 20 #include "base/debug/stack_trace.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
23 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
24 #include "base/process/kill.h" | 24 #include "base/process/kill.h" |
25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
26 #include "base/sys_info.h" | 26 #include "base/sys_info.h" |
27 #include "base/win/object_watcher.h" | |
28 #include "base/win/scoped_handle.h" | 27 #include "base/win/scoped_handle.h" |
29 #include "base/win/scoped_process_information.h" | 28 #include "base/win/scoped_process_information.h" |
30 #include "base/win/startup_information.h" | 29 #include "base/win/startup_information.h" |
31 #include "base/win/windows_version.h" | 30 #include "base/win/windows_version.h" |
32 | 31 |
33 namespace base { | 32 namespace base { |
34 | 33 |
35 namespace { | 34 namespace { |
36 | 35 |
37 // This exit code is used by the Windows task manager when it kills a | 36 // This exit code is used by the Windows task manager when it kills a |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // by this process. These IDs could have been reused by the time | 139 // by this process. These IDs could have been reused by the time |
141 // this function is called. The CRT checks the validity of | 140 // this function is called. The CRT checks the validity of |
142 // stdout/stderr on startup (before the handle IDs can be reused). | 141 // stdout/stderr on startup (before the handle IDs can be reused). |
143 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was | 142 // _fileno(stdout) will return -2 (_NO_CONSOLE_FILENO) if stdout was |
144 // invalid. | 143 // invalid. |
145 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) { | 144 if (_fileno(stdout) >= 0 || _fileno(stderr) >= 0) { |
146 // _fileno was broken for SUBSYSTEM:WINDOWS from VS2010 to VS2012/2013. | 145 // _fileno was broken for SUBSYSTEM:WINDOWS from VS2010 to VS2012/2013. |
147 // http://crbug.com/358267. Confirm that the underlying HANDLE is valid | 146 // http://crbug.com/358267. Confirm that the underlying HANDLE is valid |
148 // before aborting. | 147 // before aborting. |
149 | 148 |
150 // This causes NaCl tests to hang on XP for reasons unclear, perhaps due | |
151 // to not being able to inherit handles. Since it's only for debugging, | |
152 // and redirecting still works, punt for now. | |
153 if (base::win::GetVersion() < base::win::VERSION_VISTA) | |
154 return; | |
155 | |
156 intptr_t stdout_handle = _get_osfhandle(_fileno(stdout)); | 149 intptr_t stdout_handle = _get_osfhandle(_fileno(stdout)); |
157 intptr_t stderr_handle = _get_osfhandle(_fileno(stderr)); | 150 intptr_t stderr_handle = _get_osfhandle(_fileno(stderr)); |
158 if (stdout_handle >= 0 || stderr_handle >= 0) | 151 if (stdout_handle >= 0 || stderr_handle >= 0) |
159 return; | 152 return; |
160 } | 153 } |
161 | 154 |
162 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { | 155 if (!AttachConsole(ATTACH_PARENT_PROCESS)) { |
163 unsigned int result = GetLastError(); | 156 unsigned int result = GetLastError(); |
164 // Was probably already attached. | 157 // Was probably already attached. |
165 if (result == ERROR_ACCESS_DENIED) | 158 if (result == ERROR_ACCESS_DENIED) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 const LaunchOptions& options) { | 203 const LaunchOptions& options) { |
211 win::StartupInformation startup_info_wrapper; | 204 win::StartupInformation startup_info_wrapper; |
212 STARTUPINFO* startup_info = startup_info_wrapper.startup_info(); | 205 STARTUPINFO* startup_info = startup_info_wrapper.startup_info(); |
213 | 206 |
214 bool inherit_handles = options.inherit_handles; | 207 bool inherit_handles = options.inherit_handles; |
215 DWORD flags = 0; | 208 DWORD flags = 0; |
216 if (options.handles_to_inherit) { | 209 if (options.handles_to_inherit) { |
217 if (options.handles_to_inherit->empty()) { | 210 if (options.handles_to_inherit->empty()) { |
218 inherit_handles = false; | 211 inherit_handles = false; |
219 } else { | 212 } else { |
220 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | |
221 DLOG(ERROR) << "Specifying handles to inherit requires Vista or later."; | |
222 return Process(); | |
223 } | |
224 | |
225 if (options.handles_to_inherit->size() > | 213 if (options.handles_to_inherit->size() > |
226 std::numeric_limits<DWORD>::max() / sizeof(HANDLE)) { | 214 std::numeric_limits<DWORD>::max() / sizeof(HANDLE)) { |
227 DLOG(ERROR) << "Too many handles to inherit."; | 215 DLOG(ERROR) << "Too many handles to inherit."; |
228 return Process(); | 216 return Process(); |
229 } | 217 } |
230 | 218 |
231 // Ensure the handles can be inherited. | 219 // Ensure the handles can be inherited. |
232 for (HANDLE handle : *options.handles_to_inherit) { | 220 for (HANDLE handle : *options.handles_to_inherit) { |
233 BOOL result = SetHandleInformation(handle, HANDLE_FLAG_INHERIT, | 221 BOOL result = SetHandleInformation(handle, HANDLE_FLAG_INHERIT, |
234 HANDLE_FLAG_INHERIT); | 222 HANDLE_FLAG_INHERIT); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 374 |
387 bool GetAppOutput(const StringPiece16& cl, std::string* output) { | 375 bool GetAppOutput(const StringPiece16& cl, std::string* output) { |
388 return GetAppOutputInternal(cl, false, output); | 376 return GetAppOutputInternal(cl, false, output); |
389 } | 377 } |
390 | 378 |
391 void RaiseProcessToHighPriority() { | 379 void RaiseProcessToHighPriority() { |
392 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); | 380 SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); |
393 } | 381 } |
394 | 382 |
395 } // namespace base | 383 } // namespace base |
OLD | NEW |