• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- FuzzerUtil.h - Internal header for the Fuzzer Utils ------*- C++ -* ===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Util functions.
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_FUZZER_UTIL_H
13 #define LLVM_FUZZER_UTIL_H
14 
15 #include "FuzzerDefs.h"
16 
17 namespace fuzzer {
18 
19 void PrintHexArray(const Unit &U, const char *PrintAfter = "");
20 
21 void PrintHexArray(const uint8_t *Data, size_t Size,
22                    const char *PrintAfter = "");
23 
24 void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = "");
25 
26 void PrintASCII(const Unit &U, const char *PrintAfter = "");
27 
28 // Changes U to contain only ASCII (isprint+isspace) characters.
29 // Returns true iff U has been changed.
30 bool ToASCII(uint8_t *Data, size_t Size);
31 
32 bool IsASCII(const Unit &U);
33 
34 bool IsASCII(const uint8_t *Data, size_t Size);
35 
36 std::string Base64(const Unit &U);
37 
38 void PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC);
39 
40 std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC);
41 
42 unsigned NumberOfCpuCores();
43 
44 bool ExecuteCommandAndReadOutput(const std::string &Command, std::string *Out);
45 
46 // Platform specific functions.
47 void SetSignalHandler(const FuzzingOptions& Options);
48 
49 void SleepSeconds(int Seconds);
50 
51 unsigned long GetPid();
52 
53 size_t GetPeakRSSMb();
54 
55 int ExecuteCommand(const std::string &Command);
56 
57 FILE *OpenProcessPipe(const char *Command, const char *Mode);
58 
59 const void *SearchMemory(const void *haystack, size_t haystacklen,
60                          const void *needle, size_t needlelen);
61 
62 std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
63                               const char *X1, const char *X2);
64 
CloneArgsWithoutX(const std::vector<std::string> & Args,const char * X)65 inline std::string CloneArgsWithoutX(const std::vector<std::string> &Args,
66                                      const char *X) {
67   return CloneArgsWithoutX(Args, X, X);
68 }
69 
70 }  // namespace fuzzer
71 
72 #endif  // LLVM_FUZZER_UTIL_H
73