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 "base/process_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <io.h> | 8 #include <io.h> |
9 #include <windows.h> | 9 #include <windows.h> |
10 #include <userenv.h> | 10 #include <userenv.h> |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 const LaunchOptions& options, | 230 const LaunchOptions& options, |
231 ProcessHandle* process_handle) { | 231 ProcessHandle* process_handle) { |
232 STARTUPINFO startup_info = {}; | 232 STARTUPINFO startup_info = {}; |
233 startup_info.cb = sizeof(startup_info); | 233 startup_info.cb = sizeof(startup_info); |
234 if (options.empty_desktop_name) | 234 if (options.empty_desktop_name) |
235 startup_info.lpDesktop = L""; | 235 startup_info.lpDesktop = L""; |
236 startup_info.dwFlags = STARTF_USESHOWWINDOW; | 236 startup_info.dwFlags = STARTF_USESHOWWINDOW; |
237 startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW; | 237 startup_info.wShowWindow = options.start_hidden ? SW_HIDE : SW_SHOW; |
238 PROCESS_INFORMATION process_info; | 238 PROCESS_INFORMATION process_info; |
239 | 239 |
| 240 DWORD flags = 0; |
| 241 |
| 242 if (options.job_handle) { |
| 243 flags |= CREATE_SUSPENDED; |
| 244 |
| 245 // If this code is run under a debugger, the launched process is |
| 246 // automatically associated with a job object created by the debugger. |
| 247 // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. |
| 248 flags |= CREATE_BREAKAWAY_FROM_JOB; |
| 249 } |
| 250 |
240 if (options.as_user) { | 251 if (options.as_user) { |
241 DWORD flags = CREATE_UNICODE_ENVIRONMENT; | 252 flags |= CREATE_UNICODE_ENVIRONMENT; |
242 void* enviroment_block = NULL; | 253 void* enviroment_block = NULL; |
243 | 254 |
244 if (!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE)) | 255 if (!CreateEnvironmentBlock(&enviroment_block, options.as_user, FALSE)) |
245 return false; | 256 return false; |
246 | 257 |
247 BOOL launched = | 258 BOOL launched = |
248 CreateProcessAsUser(options.as_user, NULL, | 259 CreateProcessAsUser(options.as_user, NULL, |
249 const_cast<wchar_t*>(cmdline.c_str()), | 260 const_cast<wchar_t*>(cmdline.c_str()), |
250 NULL, NULL, options.inherit_handles, flags, | 261 NULL, NULL, options.inherit_handles, flags, |
251 enviroment_block, NULL, &startup_info, | 262 enviroment_block, NULL, &startup_info, |
252 &process_info); | 263 &process_info); |
253 DestroyEnvironmentBlock(enviroment_block); | 264 DestroyEnvironmentBlock(enviroment_block); |
254 if (!launched) | 265 if (!launched) |
255 return false; | 266 return false; |
256 } else { | 267 } else { |
257 if (!CreateProcess(NULL, | 268 if (!CreateProcess(NULL, |
258 const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, | 269 const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, |
259 options.inherit_handles, 0, NULL, NULL, | 270 options.inherit_handles, flags, NULL, NULL, |
260 &startup_info, &process_info)) { | 271 &startup_info, &process_info)) { |
261 return false; | 272 return false; |
262 } | 273 } |
263 } | 274 } |
264 | 275 |
| 276 if (options.job_handle) { |
| 277 if (0 == AssignProcessToJobObject(options.job_handle, |
| 278 process_info.hProcess)) { |
| 279 LOG(ERROR) << "Could not AssignProcessToObject."; |
| 280 KillProcess(process_info.hProcess, kProcessKilledExitCode, true); |
| 281 return false; |
| 282 } |
| 283 |
| 284 ResumeThread(process_info.hThread); |
| 285 } |
| 286 |
265 // Handles must be closed or they will leak. | 287 // Handles must be closed or they will leak. |
266 CloseHandle(process_info.hThread); | 288 CloseHandle(process_info.hThread); |
267 | 289 |
268 if (options.wait) | 290 if (options.wait) |
269 WaitForSingleObject(process_info.hProcess, INFINITE); | 291 WaitForSingleObject(process_info.hProcess, INFINITE); |
270 | 292 |
271 // If the caller wants the process handle, we won't close it. | 293 // If the caller wants the process handle, we won't close it. |
272 if (process_handle) { | 294 if (process_handle) { |
273 *process_handle = process_info.hProcess; | 295 *process_handle = process_info.hProcess; |
274 } else { | 296 } else { |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 | 902 |
881 PERFORMANCE_INFORMATION info; | 903 PERFORMANCE_INFORMATION info; |
882 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { | 904 if (!InternalGetPerformanceInfo(&info, sizeof(info))) { |
883 LOG(ERROR) << "Failed to fetch internal performance info."; | 905 LOG(ERROR) << "Failed to fetch internal performance info."; |
884 return 0; | 906 return 0; |
885 } | 907 } |
886 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 908 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
887 } | 909 } |
888 | 910 |
889 } // namespace base | 911 } // namespace base |
OLD | NEW |