OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // This file contains functions for launching subprocesses. | 5 // This file contains functions for launching subprocesses. |
6 | 6 |
7 #ifndef BASE_PROCESS_LAUNCH_H_ | 7 #ifndef BASE_PROCESS_LAUNCH_H_ |
8 #define BASE_PROCESS_LAUNCH_H_ | 8 #define BASE_PROCESS_LAUNCH_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // code running in this delegate essentially needs to be async-signal safe | 157 // code running in this delegate essentially needs to be async-signal safe |
158 // (see man 7 signal for a list of allowed functions). | 158 // (see man 7 signal for a list of allowed functions). |
159 PreExecDelegate* pre_exec_delegate; | 159 PreExecDelegate* pre_exec_delegate; |
160 #endif // defined(OS_POSIX) | 160 #endif // defined(OS_POSIX) |
161 | 161 |
162 #if defined(OS_CHROMEOS) | 162 #if defined(OS_CHROMEOS) |
163 // If non-negative, the specified file descriptor will be set as the launched | 163 // If non-negative, the specified file descriptor will be set as the launched |
164 // process' controlling terminal. | 164 // process' controlling terminal. |
165 int ctrl_terminal_fd; | 165 int ctrl_terminal_fd; |
166 #endif // defined(OS_CHROMEOS) | 166 #endif // defined(OS_CHROMEOS) |
167 | |
168 #if defined(OS_MACOSX) | |
169 // If this name is non-empty, the new child, after fork() but before exec(), | |
170 // will look up this server name in the bootstrap namespace. The resulting | |
171 // service port will be replaced as the bootstrap port in the child. Because | |
172 // the process's IPC space is cleared on exec(), any rights to the old | |
173 // bootstrap port will not be transferred to the new process. | |
174 std::string replacement_bootstrap_name; | |
175 #endif | |
176 | |
177 #endif // !defined(OS_WIN) | 167 #endif // !defined(OS_WIN) |
178 }; | 168 }; |
179 | 169 |
180 // Launch a process via the command line |cmdline|. | 170 // Launch a process via the command line |cmdline|. |
181 // See the documentation of LaunchOptions for details on |options|. | 171 // See the documentation of LaunchOptions for details on |options|. |
182 // | 172 // |
183 // Returns a valid Process upon success. | 173 // Returns a valid Process upon success. |
184 // | 174 // |
185 // Unix-specific notes: | 175 // Unix-specific notes: |
186 // - All file descriptors open in the parent process will be closed in the | 176 // - All file descriptors open in the parent process will be closed in the |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 273 |
284 #if defined(OS_MACOSX) | 274 #if defined(OS_MACOSX) |
285 // Restore the default exception handler, setting it to Apple Crash Reporter | 275 // Restore the default exception handler, setting it to Apple Crash Reporter |
286 // (ReportCrash). When forking and execing a new process, the child will | 276 // (ReportCrash). When forking and execing a new process, the child will |
287 // inherit the parent's exception ports, which may be set to the Breakpad | 277 // inherit the parent's exception ports, which may be set to the Breakpad |
288 // instance running inside the parent. The parent's Breakpad instance should | 278 // instance running inside the parent. The parent's Breakpad instance should |
289 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler | 279 // not handle the child's exceptions. Calling RestoreDefaultExceptionHandler |
290 // in the child after forking will restore the standard exception handler. | 280 // in the child after forking will restore the standard exception handler. |
291 // See http://crbug.com/20371/ for more details. | 281 // See http://crbug.com/20371/ for more details. |
292 void RestoreDefaultExceptionHandler(); | 282 void RestoreDefaultExceptionHandler(); |
293 | |
294 // Look up the bootstrap server named |replacement_bootstrap_name| via the | |
295 // current |bootstrap_port|. Then replace the task's bootstrap port with the | |
296 // received right. | |
297 void ReplaceBootstrapPort(const std::string& replacement_bootstrap_name); | |
298 #endif // defined(OS_MACOSX) | 283 #endif // defined(OS_MACOSX) |
299 | 284 |
300 // Creates a LaunchOptions object suitable for launching processes in a test | 285 // Creates a LaunchOptions object suitable for launching processes in a test |
301 // binary. This should not be called in production/released code. | 286 // binary. This should not be called in production/released code. |
302 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); | 287 BASE_EXPORT LaunchOptions LaunchOptionsForTest(); |
303 | 288 |
304 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI) | 289 #if defined(OS_LINUX) || defined(OS_NACL_NONSFI) |
305 // A wrapper for clone with fork-like behavior, meaning that it returns the | 290 // A wrapper for clone with fork-like behavior, meaning that it returns the |
306 // child's pid in the parent and 0 in the child. |flags|, |ptid|, and |ctid| are | 291 // child's pid in the parent and 0 in the child. |flags|, |ptid|, and |ctid| are |
307 // as in the clone system call (the CLONE_VM flag is not supported). | 292 // as in the clone system call (the CLONE_VM flag is not supported). |
308 // | 293 // |
309 // This function uses the libc clone wrapper (which updates libc's pid cache) | 294 // This function uses the libc clone wrapper (which updates libc's pid cache) |
310 // internally, so callers may expect things like getpid() to work correctly | 295 // internally, so callers may expect things like getpid() to work correctly |
311 // after in both the child and parent. An exception is when this code is run | 296 // after in both the child and parent. An exception is when this code is run |
312 // under Valgrind. Valgrind does not support the libc clone wrapper, so the libc | 297 // under Valgrind. Valgrind does not support the libc clone wrapper, so the libc |
313 // pid cache may be incorrect after this function is called under Valgrind. | 298 // pid cache may be incorrect after this function is called under Valgrind. |
314 // | 299 // |
315 // As with fork(), callers should be extremely careful when calling this while | 300 // As with fork(), callers should be extremely careful when calling this while |
316 // multiple threads are running, since at the time the fork happened, the | 301 // multiple threads are running, since at the time the fork happened, the |
317 // threads could have been in any state (potentially holding locks, etc.). | 302 // threads could have been in any state (potentially holding locks, etc.). |
318 // Callers should most likely call execve() in the child soon after calling | 303 // Callers should most likely call execve() in the child soon after calling |
319 // this. | 304 // this. |
320 BASE_EXPORT pid_t ForkWithFlags(unsigned long flags, pid_t* ptid, pid_t* ctid); | 305 BASE_EXPORT pid_t ForkWithFlags(unsigned long flags, pid_t* ptid, pid_t* ctid); |
321 #endif | 306 #endif |
322 | 307 |
323 } // namespace base | 308 } // namespace base |
324 | 309 |
325 #endif // BASE_PROCESS_LAUNCH_H_ | 310 #endif // BASE_PROCESS_LAUNCH_H_ |
OLD | NEW |