llvm/llvm/lib/Support/Unix/Process.inc

//===- Unix/Process.cpp - Unix Process Implementation --------- -*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file provides the generic Unix implementation of the Process class.
//
//===----------------------------------------------------------------------===//

#include "Unix.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
#include "llvm/Config/llvm-config.h" // for LLVM_ENABLE_THREADS
#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

//===----------------------------------------------------------------------===//
//=== WARNING: Implementation here must contain only generic UNIX code that
//===          is guaranteed to work on *all* UNIX variants.
//===----------------------------------------------------------------------===//

usingnamespacellvm;
usingnamespacesys;

static std::pair<std::chrono::microseconds, std::chrono::microseconds>
getRUsageTimes() {}

Process::Pid Process::getProcessId() {}

// On Cygwin, getpagesize() returns 64k(AllocationGranularity) and
// offset in mmap(3) should be aligned to the AllocationGranularity.
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

// Some LLVM programs such as bugpoint produce core files as a normal part of
// their operation. To prevent the disk from filling up, this function
// does what's necessary to prevent their generation.
void Process::PreventCoreFiles() {}

std::optional<std::string> Process::GetEnv(StringRef Name) {}

namespace {
class FDCloser {};
} // namespace

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 /*enable*/) {}

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() {
  // Attempt to get the initial seed from /dev/urandom, if possible.
  int urandomFD = open("/dev/urandom", O_RDONLY);

  if (urandomFD != -1) {
    unsigned seed;
    // Don't use a buffered read to avoid reading more data
    // from /dev/urandom than we need.
    int count = read(urandomFD, (void *)&seed, sizeof(seed));

    close(urandomFD);

    // Return the seed if the read was successful.
    if (count == sizeof(seed))
      return seed;
  }

  // Otherwise, swizzle the current time and the process ID to form a reasonable
  // 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) {}