#include "Unix.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
#include "llvm/Config/llvm-config.h"
#include <mutex>
#include <optional>
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#if defined(HAVE_MALLINFO) || defined(HAVE_MALLINFO2)
#include <malloc.h>
#endif
#if defined(HAVE_MALLCTL)
#include <malloc_np.h>
#endif
#ifdef HAVE_MALLOC_MALLOC_H
#include <malloc/malloc.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
usingnamespacellvm;
usingnamespacesys;
static std::pair<std::chrono::microseconds, std::chrono::microseconds>
getRUsageTimes() { … }
Process::Pid Process::getProcessId() { … }
Expected<unsigned> Process::getPageSize() { … }
size_t Process::GetMallocUsage() { … }
void Process::GetTimeUsage(TimePoint<> &elapsed,
std::chrono::nanoseconds &user_time,
std::chrono::nanoseconds &sys_time) { … }
#if defined(HAVE_MACH_MACH_H) && !defined(__GNU__)
#include <mach/mach.h>
#endif
void Process::PreventCoreFiles() { … }
std::optional<std::string> Process::GetEnv(StringRef Name) { … }
namespace {
class FDCloser { … };
}
std::error_code Process::FixupStandardFileDescriptors() { … }
std::error_code Process::SafelyCloseFileDescriptor(int FD) { … }
bool Process::StandardInIsUserInput() { … }
bool Process::StandardOutIsDisplayed() { … }
bool Process::StandardErrIsDisplayed() { … }
bool Process::FileDescriptorIsDisplayed(int fd) { … }
static unsigned getColumns() { … }
unsigned Process::StandardOutColumns() { … }
unsigned Process::StandardErrColumns() { … }
static bool terminalHasColors() { … }
bool Process::FileDescriptorHasColors(int fd) { … }
bool Process::StandardOutHasColors() { … }
bool Process::StandardErrHasColors() { … }
void Process::UseANSIEscapeCodes(bool ) { … }
bool Process::ColorNeedsFlush() { … }
const char *Process::OutputColor(char code, bool bold, bool bg) { … }
const char *Process::OutputBold(bool bg) { … }
const char *Process::OutputReverse() { … }
const char *Process::ResetColor() { … }
#if !HAVE_DECL_ARC4RANDOM
static unsigned GetRandomNumberSeed() {
int urandomFD = open("/dev/urandom", O_RDONLY);
if (urandomFD != -1) {
unsigned seed;
int count = read(urandomFD, (void *)&seed, sizeof(seed));
close(urandomFD);
if (count == sizeof(seed))
return seed;
}
const auto Now = std::chrono::high_resolution_clock::now();
return hash_combine(Now.time_since_epoch().count(), ::getpid());
}
#endif
unsigned llvm::sys::Process::GetRandomNumber() { … }
[[noreturn]] void Process::ExitNoCleanup(int RetCode) { … }