#include "llvm/Support/Program.h"
#include "Unix.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h"
#include "llvm/Support/AutoConvert.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/SystemZ/zOSSupport.h"
#include "llvm/Support/raw_ostream.h"
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_POSIX_SPAWN
#include <spawn.h>
#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
#if defined(__APPLE__) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#define USE_NSGETENVIRON …
#else
#define USE_NSGETENVIRON …
#endif
#if !USE_NSGETENVIRON
extern char **environ;
#else
#include <crt_externs.h>
#endif
#endif
usingnamespacellvm;
usingnamespacesys;
ProcessInfo::ProcessInfo() : … { … }
ErrorOr<std::string> sys::findProgramByName(StringRef Name,
ArrayRef<StringRef> Paths) { … }
static bool RedirectIO(std::optional<StringRef> Path, int FD, std::string *ErrMsg) { … }
#ifdef HAVE_POSIX_SPAWN
static bool RedirectIO_PS(const std::string *Path, int FD, std::string *ErrMsg,
posix_spawn_file_actions_t *FileActions) { … }
#endif
static void TimeOutHandler(int Sig) { … }
static void SetMemoryLimits(unsigned size) { … }
static std::vector<const char *>
toNullTerminatedCStringArray(ArrayRef<StringRef> Strings, StringSaver &Saver) { … }
static bool Execute(ProcessInfo &PI, StringRef Program,
ArrayRef<StringRef> Args,
std::optional<ArrayRef<StringRef>> Env,
ArrayRef<std::optional<StringRef>> Redirects,
unsigned MemoryLimit, std::string *ErrMsg,
BitVector *AffinityMask, bool DetachProcess) { … }
namespace llvm {
namespace sys {
#if defined(_AIX)
static pid_t(wait4)(pid_t pid, int *status, int options, struct rusage *usage);
#elif !defined(__Fuchsia__)
wait4;
#endif
}
}
#ifdef _AIX
#ifndef _ALL_SOURCE
extern "C" pid_t(wait4)(pid_t pid, int *status, int options,
struct rusage *usage);
#endif
pid_t(llvm::sys::wait4)(pid_t pid, int *status, int options,
struct rusage *usage) {
assert(pid > 0 && "Only expecting to handle actual PID values!");
assert((options & ~WNOHANG) == 0 && "Expecting WNOHANG at most!");
assert(usage && "Expecting usage collection!");
if (!(options & WNOHANG))
return ::wait4(pid, status, options, usage);
siginfo_t WaitIdInfo;
WaitIdInfo.si_pid = 0;
int WaitIdRetVal =
waitid(P_PID, pid, &WaitIdInfo, WNOWAIT | WEXITED | options);
if (WaitIdRetVal == -1 || WaitIdInfo.si_pid == 0)
return WaitIdRetVal;
assert(WaitIdInfo.si_pid == pid);
return ::wait4(pid, status, options & ~WNOHANG, usage);
}
#endif
ProcessInfo llvm::sys::Wait(const ProcessInfo &PI,
std::optional<unsigned> SecondsToWait,
std::string *ErrMsg,
std::optional<ProcessStatistics> *ProcStat,
bool Polling) { … }
std::error_code llvm::sys::ChangeStdinMode(fs::OpenFlags Flags) { … }
std::error_code llvm::sys::ChangeStdoutMode(fs::OpenFlags Flags) { … }
std::error_code llvm::sys::ChangeStdinToBinary() { … }
std::error_code llvm::sys::ChangeStdoutToBinary() { … }
std::error_code
llvm::sys::writeFileWithEncoding(StringRef FileName, StringRef Contents,
WindowsEncodingMethod Encoding ) { … }
bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
ArrayRef<StringRef> Args) { … }