#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "base/process/launch.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <setjmp.h>
#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/resource.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <iterator>
#include <limits>
#include <memory>
#include <set>
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/debug/debugger.h"
#include "base/debug/stack_trace.h"
#include "base/files/dir_reader_posix.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/process/environment_internal.h"
#include "base/process/process.h"
#include "base/process/process_metrics.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/threading/platform_thread_internal_posix.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/trace_event/base_tracing.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX)
#include <sys/prctl.h>
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include <sys/ioctl.h>
#endif
#if BUILDFLAG(IS_FREEBSD)
#include <sys/event.h>
#include <sys/ucontext.h>
#endif
#if BUILDFLAG(IS_MAC)
#error "macOS should use launch_mac.cc"
#endif
extern char** environ;
namespace base {
namespace {
char** GetEnvironment() { … }
void SetEnvironment(char** env) { … }
sigset_t SetSignalMask(const sigset_t& new_sigmask) { … }
#if (!BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_AIX) && !BUILDFLAG(IS_CHROMEOS)) || \
(!defined(__i386__) && !defined(__x86_64__) && !defined(__arm__))
void ResetChildSignalHandlersToDefaults() {
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGABRT, SIG_DFL);
signal(SIGFPE, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGSYS, SIG_DFL);
signal(SIGTERM, SIG_DFL);
}
#else
kernel_sigset_t;
struct kernel_sigaction { … };
long sys_rt_sigaction(int sig,
const struct kernel_sigaction* act,
struct kernel_sigaction* oact) { … }
void ResetChildSignalHandlersToDefaults(void) { … }
#endif
}
struct ScopedDIRClose { … };
ScopedDIR;
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX)
static const char kFDDir[] = …;
#elif BUILDFLAG(IS_SOLARIS)
static const char kFDDir[] = "/dev/fd";
#elif BUILDFLAG(IS_FREEBSD)
static const char kFDDir[] = "/dev/fd";
#elif BUILDFLAG(IS_OPENBSD)
static const char kFDDir[] = "/dev/fd";
#elif BUILDFLAG(IS_ANDROID)
static const char kFDDir[] = "/proc/self/fd";
#endif
void CloseSuperfluousFds(const base::InjectiveMultimap& saved_mapping) { … }
Process LaunchProcess(const CommandLine& cmdline,
const LaunchOptions& options) { … }
Process LaunchProcess(const std::vector<std::string>& argv,
const LaunchOptions& options) { … }
void RaiseProcessToHighPriority() { … }
static bool GetAppOutputInternal(
const std::vector<std::string>& argv,
char* const envp[],
bool include_stderr,
std::string* output,
bool do_search_path,
int* exit_code) { … }
bool GetAppOutput(const CommandLine& cl, std::string* output) { … }
bool GetAppOutput(const std::vector<std::string>& argv, std::string* output) { … }
bool GetAppOutputAndError(const CommandLine& cl, std::string* output) { … }
bool GetAppOutputAndError(const std::vector<std::string>& argv,
std::string* output) { … }
bool GetAppOutputWithExitCode(const CommandLine& cl,
std::string* output,
int* exit_code) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_AIX)
namespace {
int CloneHelper(void* arg) { … }
#if defined(ADDRESS_SANITIZER)
NOINLINE __attribute__((no_sanitize_address)) pid_t
CloneAndLongjmpInChild(int flags, pid_t* ptid, pid_t* ctid, jmp_buf* env) {
#else
NOINLINE pid_t CloneAndLongjmpInChild(int flags,
pid_t* ptid,
pid_t* ctid,
jmp_buf* env) { … }
}
pid_t ForkWithFlags(int flags, pid_t* ptid, pid_t* ctid) { … }
#endif
}