1 //===- FuzzerUtil.cpp - Misc utils ----------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
12 #include "FuzzerInternal.h"
21 void Print(const Unit &v, const char *PrintAfter) {
23 std::cerr << "0x" << std::hex << (unsigned) x << std::dec << ",";
24 std::cerr << PrintAfter;
27 void PrintASCII(const Unit &U, const char *PrintAfter) {
32 std::cerr << "\\x" << std::hex << (int)(unsigned)X << std::dec;
34 std::cerr << PrintAfter;
37 std::string Hash(const Unit &in) {
38 size_t h1 = 0, h2 = 0;
45 return std::to_string(h1) + std::to_string(h2);
48 static void AlarmHandler(int, siginfo_t *, void *) {
49 Fuzzer::StaticAlarmCallback();
52 void SetTimer(int Seconds) {
53 struct itimerval T {{Seconds, 0}, {Seconds, 0}};
54 std::cerr << "SetTimer " << Seconds << "\n";
55 int Res = setitimer(ITIMER_REAL, &T, nullptr);
57 struct sigaction sigact;
58 memset(&sigact, 0, sizeof(sigact));
59 sigact.sa_sigaction = AlarmHandler;
60 Res = sigaction(SIGALRM, &sigact, 0);