23 #ifdef HAVE_SYS_TIME_H
26 #ifdef HAVE_SYS_RESOURCE_H
27 #include <sys/resource.h>
29 #ifdef HAVE_SYS_STAT_H
37 #if defined(HAVE_MALLOC_H) && !defined(__DragonFly__) && \
38 !defined(__OpenBSD__) && !defined(__Bitrig__)
41 #if defined(HAVE_MALLCTL)
42 #include <malloc_np.h>
44 #ifdef HAVE_MALLOC_MALLOC_H
45 #include <malloc/malloc.h>
47 #ifdef HAVE_SYS_IOCTL_H
48 # include <sys/ioctl.h>
62 static std::pair<std::chrono::microseconds, std::chrono::microseconds> getRUsageTimes() {
63 #if defined(HAVE_GETRUSAGE)
65 ::getrusage(RUSAGE_SELF, &RU);
68 #warning Cannot get usage times on this platform
76 #if defined(HAVE_GETPAGESIZE)
77 static const int page_size = ::getpagesize();
78 #elif defined(HAVE_SYSCONF)
79 static long page_size = ::sysconf(_SC_PAGE_SIZE);
81 #warning Cannot get the page size on this machine
83 return static_cast<unsigned>(page_size);
87 #if defined(HAVE_MALLINFO)
91 #elif defined(HAVE_MALLOC_ZONE_STATISTICS) && defined(HAVE_MALLOC_MALLOC_H)
92 malloc_statistics_t
Stats;
93 malloc_zone_statistics(malloc_default_zone(), &Stats);
94 return Stats.size_in_use;
95 #elif defined(HAVE_MALLCTL)
98 if (mallctl(
"stats.allocated", &alloc, &sz, NULL, 0) == 0)
101 #elif defined(HAVE_SBRK)
104 static char *StartOfMemory =
reinterpret_cast<char*
>(::sbrk(0));
105 char *EndOfMemory = (
char*)sbrk(0);
106 if (EndOfMemory != ((
char*)-1) && StartOfMemory != ((
char*)-1))
107 return EndOfMemory - StartOfMemory;
110 #warning Cannot get malloc info on this platform
116 std::chrono::nanoseconds &sys_time) {
118 std::tie(user_time, sys_time) = getRUsageTimes();
121 #if defined(HAVE_MACH_MACH_H) && !defined(__GNU__)
122 #include <mach/mach.h>
131 rlim.rlim_cur = rlim.rlim_max = 0;
132 setrlimit(RLIMIT_CORE, &rlim);
135 #if defined(HAVE_MACH_MACH_H) && !defined(__GNU__)
139 mach_msg_type_number_t Count = 0;
140 exception_mask_t OriginalMasks[EXC_TYPES_COUNT];
141 exception_port_t OriginalPorts[EXC_TYPES_COUNT];
142 exception_behavior_t OriginalBehaviors[EXC_TYPES_COUNT];
143 thread_state_flavor_t OriginalFlavors[EXC_TYPES_COUNT];
145 task_get_exception_ports(mach_task_self(), EXC_MASK_ALL, OriginalMasks,
146 &Count, OriginalPorts, OriginalBehaviors,
148 if (err == KERN_SUCCESS) {
150 for (
unsigned i = 0;
i != Count; ++
i)
151 task_set_exception_ports(mach_task_self(), OriginalMasks[
i],
152 MACH_PORT_NULL, OriginalBehaviors[i],
157 signal(SIGABRT, _exit);
158 signal(SIGILL, _exit);
159 signal(SIGFPE, _exit);
160 signal(SIGSEGV, _exit);
161 signal(SIGBUS, _exit);
168 std::string NameStr = Name.
str();
169 const char *Val = ::getenv(NameStr.c_str());
172 return std::string(Val);
181 return std::error_code();
187 FDCloser(
int &FD) : FD(FD), KeepOpen(
false) {}
188 void keepOpen() { KeepOpen =
true; }
190 if (!KeepOpen && FD >= 0)
195 FDCloser(
const FDCloser &) =
delete;
196 void operator=(
const FDCloser &) =
delete;
205 FDCloser FDC(NullFD);
206 const int StandardFDs[] = {STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO};
207 for (
int StandardFD : StandardFDs) {
210 while (fstat(StandardFD, &st) < 0) {
211 assert(errno &&
"expected errno to be set if fstat failed!");
217 return std::error_code(errno, std::generic_category());
222 assert(errno == EBADF &&
"expected errno to have EBADF at this point!");
225 while ((NullFD = open(
"/dev/null", O_RDWR)) < 0) {
228 return std::error_code(errno, std::generic_category());
232 if (NullFD == StandardFD)
234 else if (dup2(NullFD, StandardFD) < 0)
235 return std::error_code(errno, std::generic_category());
237 return std::error_code();
243 if (sigfillset(&FullSet) < 0)
244 return std::error_code(errno, std::generic_category());
247 #if LLVM_ENABLE_THREADS
248 if (
int EC = pthread_sigmask(SIG_SETMASK, &FullSet, &SavedSet))
249 return std::error_code(EC, std::generic_category());
251 if (sigprocmask(SIG_SETMASK, &FullSet, &SavedSet) < 0)
252 return std::error_code(errno, std::generic_category());
257 int ErrnoFromClose = 0;
259 ErrnoFromClose = errno;
262 #if LLVM_ENABLE_THREADS
263 EC = pthread_sigmask(SIG_SETMASK, &SavedSet,
nullptr);
265 if (sigprocmask(SIG_SETMASK, &SavedSet,
nullptr) < 0)
271 return std::error_code(ErrnoFromClose, std::generic_category());
272 return std::error_code(EC, std::generic_category());
296 static unsigned getColumns(
int FileID) {
298 if (
const char *ColumnsStr = std::getenv(
"COLUMNS")) {
299 int Columns = std::atoi(ColumnsStr);
304 unsigned Columns = 0;
306 #if defined(HAVE_SYS_IOCTL_H) && defined(HAVE_TERMIOS_H)
309 if (ioctl(FileID, TIOCGWINSZ, &ws) == 0)
320 return getColumns(1);
327 return getColumns(2);
334 extern "C" int setupterm(
char *term,
int filedes,
int *errret);
335 extern "C" struct term *set_curterm(
struct term *termp);
336 extern "C" int del_curterm(
struct term *termp);
337 extern "C" int tigetnum(
char *capname);
344 static bool terminalHasColors(
int fd) {
350 if (setupterm((
char *)
nullptr, fd, &errret) != 0)
368 bool HasColors = tigetnum(const_cast<char *>(
"colors")) > 0;
372 struct term *termp = set_curterm((
struct term *)
nullptr);
373 (void)del_curterm(termp);
423 #if !HAVE_DECL_ARC4RANDOM
424 static unsigned GetRandomNumberSeed() {
426 int urandomFD = open(
"/dev/urandom", O_RDONLY);
428 if (urandomFD != -1) {
432 int count =
read(urandomFD, (
void *)&seed,
sizeof(seed));
437 if (count ==
sizeof(seed))
444 return hash_combine(Now.time_since_epoch().count(), ::getpid());
449 #if HAVE_DECL_ARC4RANDOM
452 static int x = (
static_cast<void>(::srand(GetRandomNumberSeed())), 0);
value_type read(const void *memory)
Read a value of a particular endianness from memory.
static const char * ResetColor()
Resets the terminals colors, or returns an escape sequence to do so.
static const char * OutputColor(char c, bool bold, bool bg)
This function returns the colorcode escape sequences.
static bool StandardErrHasColors()
This function determines whether the terminal connected to standard error supports colors...
static bool FileDescriptorHasColors(int fd)
This function determines if the given file descriptor is displayd and supports colors.
static bool FileDescriptorIsDisplayed(int fd)
This function determines if the given file descriptor is connected to a "tty" or "console" window...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If zero
static std::error_code FixupStandardFileDescriptors()
static bool ColorNeedsFlush()
Whether changing colors requires the output to be flushed.
static const char * OutputReverse()
This function returns the escape sequence to reverse forground and background colors.
static const char colorcodes[2][2][8][10]
block placement Basic Block Placement Stats
Function Alias Analysis false
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static bool StandardInIsUserInput()
This function determines if the standard input is connected directly to a user's input (keyboard prob...
auto count(R &&Range, const E &Element) -> typename std::iterator_traits< decltype(std::begin(Range))>::difference_type
Wrapper function around std::count to count the number of times an element Element occurs in the give...
static bool StandardOutIsDisplayed()
This function determines if the standard output is connected to a "tty" or "console" window...
static void UseANSIEscapeCodes(bool enable)
Enables or disables whether ANSI escape sequences are used to output colors.
Instances of this class acquire a given Mutex Lock when constructed and hold that lock until destruct...
static unsigned StandardOutColumns()
This function determines the number of columns in the window if standard output is connected to a "tt...
static std::error_code GetArgumentVector(SmallVectorImpl< const char * > &Args, ArrayRef< const char * > ArgsFromMain, SpecificBumpPtrAllocator< char > &ArgAllocator)
This function returns a SmallVector containing the arguments passed from the operating system to the ...
static sys::TimePoint< std::chrono::seconds > now(bool Deterministic)
static bool coreFilesPrevented
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static size_t GetMallocUsage()
Return process memory usage.
static unsigned getPageSize()
static bool StandardErrIsDisplayed()
This function determines if the standard error is connected to a "tty" or "console" window...
static void PreventCoreFiles()
This function makes the necessary calls to the operating system to prevent core files or any other ki...
static unsigned StandardErrColumns()
This function determines the number of columns in the window if standard error is connected to a "tty...
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
static bool StandardOutHasColors()
This function determines whether the terminal connected to standard output supports colors...
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static unsigned GetRandomNumber()
Get the result of a process wide random number generator.
std::chrono::microseconds toDuration(const struct timeval &TV)
Convert a struct timeval to a duration.
static void GetTimeUsage(TimePoint<> &elapsed, std::chrono::nanoseconds &user_time, std::chrono::nanoseconds &sys_time)
This static function will set user_time to the amount of CPU time spent in user (non-kernel) mode and...
static const char * OutputBold(bool bg)
Same as OutputColor, but only enables the bold attribute.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static std::error_code SafelyCloseFileDescriptor(int FD)
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
static Optional< std::string > GetEnv(StringRef name)