blob: c966b2677865c8c168421bbe25b82724f8944d18 [file] [log] [blame]
Aaron Ballmanef116982015-01-29 16:58:29 +00001//===- FuzzerInternal.h - Internal header for the Fuzzer --------*- 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// Define the main class fuzzer::Fuzzer and most functions.
10//===----------------------------------------------------------------------===//
Yaron Keren347663b2015-08-10 16:37:40 +000011
12#ifndef LLVM_FUZZER_INTERNAL_H
13#define LLVM_FUZZER_INTERNAL_H
14
Aaron Ballmanef116982015-01-29 16:58:29 +000015#include <cassert>
16#include <chrono>
Ivan Krasindf919102016-01-22 22:28:27 +000017#include <climits>
Aaron Ballmanef116982015-01-29 16:58:29 +000018#include <cstddef>
19#include <cstdlib>
Ivan Krasindf919102016-01-22 22:28:27 +000020#include <random>
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000021#include <string.h>
Ivan Krasindf919102016-01-22 22:28:27 +000022#include <string>
Kostya Serebryany2c1b33b2015-01-29 23:01:07 +000023#include <unordered_set>
Ivan Krasindf919102016-01-22 22:28:27 +000024#include <vector>
Aaron Ballmanef116982015-01-29 16:58:29 +000025
Kostya Serebryany016852c2015-02-19 18:45:37 +000026#include "FuzzerInterface.h"
27
Aaron Ballmanef116982015-01-29 16:58:29 +000028namespace fuzzer {
Aaron Ballmanef116982015-01-29 16:58:29 +000029using namespace std::chrono;
Kostya Serebryanyaca76962016-01-16 01:23:12 +000030typedef std::vector<uint8_t> Unit;
Aaron Ballmanef116982015-01-29 16:58:29 +000031
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000032// A simple POD sized array of bytes.
Ivan Krasindf919102016-01-22 22:28:27 +000033template <size_t kMaxSize> class FixedWord {
34public:
Kostya Serebryany160dcba2016-01-22 23:55:14 +000035 FixedWord() {}
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000036 FixedWord(const uint8_t *B, uint8_t S) { Set(B, S); }
37
38 void Set(const uint8_t *B, uint8_t S) {
39 assert(S <= kMaxSize);
40 memcpy(Data, B, S);
41 Size = S;
42 }
43
Ivan Krasindf919102016-01-22 22:28:27 +000044 bool operator==(const FixedWord<kMaxSize> &w) const {
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000045 return Size == w.Size && 0 == memcmp(Data, w.Data, Size);
46 }
47
Ivan Krasindf919102016-01-22 22:28:27 +000048 bool operator<(const FixedWord<kMaxSize> &w) const {
49 if (Size != w.Size)
50 return Size < w.Size;
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000051 return memcmp(Data, w.Data, Size) < 0;
52 }
53
54 static size_t GetMaxSize() { return kMaxSize; }
55 const uint8_t *data() const { return Data; }
56 uint8_t size() const { return Size; }
57
Ivan Krasindf919102016-01-22 22:28:27 +000058private:
Kostya Serebryany160dcba2016-01-22 23:55:14 +000059 uint8_t Size = 0;
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000060 uint8_t Data[kMaxSize];
61};
62
Ivan Krasindf919102016-01-22 22:28:27 +000063typedef FixedWord<27> Word; // 28 bytes.
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000064
Kostya Serebryanybfbe7fc2016-02-02 03:03:47 +000065bool IsFile(const std::string &Path);
Kostya Serebryany52a788e2015-03-31 20:13:20 +000066std::string FileToString(const std::string &Path);
67Unit FileToVector(const std::string &Path);
Kostya Serebryany1ac80552015-05-08 21:30:55 +000068void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V,
69 long *Epoch);
Aaron Ballmanef116982015-01-29 16:58:29 +000070void WriteToFile(const Unit &U, const std::string &Path);
Kostya Serebryany5b266a82015-02-04 19:10:20 +000071void CopyFileToErr(const std::string &Path);
Aaron Ballmanef116982015-01-29 16:58:29 +000072// Returns "Dir/FileName" or equivalent for the current OS.
73std::string DirPlusFile(const std::string &DirPath,
74 const std::string &FileName);
75
Kostya Serebryany20e9bcb2015-05-23 01:07:46 +000076void Printf(const char *Fmt, ...);
Kostya Serebryany98abb2c2016-01-13 23:46:01 +000077void PrintHexArray(const Unit &U, const char *PrintAfter = "");
78void PrintHexArray(const uint8_t *Data, size_t Size,
79 const char *PrintAfter = "");
Kostya Serebryany41740052016-01-12 02:36:59 +000080void PrintASCII(const uint8_t *Data, size_t Size, const char *PrintAfter = "");
Aaron Ballmanef116982015-01-29 16:58:29 +000081void PrintASCII(const Unit &U, const char *PrintAfter = "");
Kostya Serebryany476f0ce2016-01-16 03:53:32 +000082void PrintASCII(const Word &W, const char *PrintAfter = "");
Aaron Ballmanef116982015-01-29 16:58:29 +000083std::string Hash(const Unit &U);
84void SetTimer(int Seconds);
Kostya Serebryany9e48cda2015-12-04 22:29:39 +000085std::string Base64(const Unit &U);
Kostya Serebryanydc3135d2015-11-12 01:02:01 +000086int ExecuteCommand(const std::string &Command);
Aaron Ballmanef116982015-01-29 16:58:29 +000087
Kostya Serebryany96eab652015-05-14 22:41:49 +000088// Private copy of SHA1 implementation.
89static const int kSHA1NumBytes = 20;
90// Computes SHA1 hash of 'Len' bytes in 'Data', writes kSHA1NumBytes to 'Out'.
91void ComputeSHA1(const uint8_t *Data, size_t Len, uint8_t *Out);
92
Kostya Serebryanybc7c0ad2015-08-11 01:44:42 +000093// Changes U to contain only ASCII (isprint+isspace) characters.
94// Returns true iff U has been changed.
95bool ToASCII(Unit &U);
Kostya Serebryanya9346c22015-09-02 19:08:08 +000096bool IsASCII(const Unit &U);
Kostya Serebryanybc7c0ad2015-08-11 01:44:42 +000097
Kostya Serebryany9690fcf2015-05-12 18:51:57 +000098int NumberOfCpuCores();
Kostya Serebryanyd6edce92015-10-16 23:04:31 +000099int GetPid();
Kostya Serebryany9690fcf2015-05-12 18:51:57 +0000100
Kostya Serebryanya3992212016-02-13 03:00:53 +0000101class Random {
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000102 public:
Kostya Serebryanya3992212016-02-13 03:00:53 +0000103 Random(unsigned int seed) : R(seed) {}
104 size_t Rand() { return R(); }
105 size_t RandBool() { return Rand() % 2; }
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000106 size_t operator()(size_t n) { return n ? Rand() % n : 0; }
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000107 private:
Kostya Serebryanya3992212016-02-13 03:00:53 +0000108 std::mt19937 R;
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000109};
110
Kostya Serebryany9838b2b2015-09-03 20:23:46 +0000111// Dictionary.
112
113// Parses one dictionary entry.
114// If successfull, write the enty to Unit and returns true,
115// otherwise returns false.
116bool ParseOneDictionaryEntry(const std::string &Str, Unit *U);
117// Parses the dictionary file, fills Units, returns true iff all lines
118// were parsed succesfully.
119bool ParseDictionaryFile(const std::string &Text, std::vector<Unit> *Units);
120
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000121class MutationDispatcher {
Ivan Krasindf919102016-01-22 22:28:27 +0000122public:
Kostya Serebryanya3992212016-02-13 03:00:53 +0000123 MutationDispatcher(Random &Rand);
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000124 ~MutationDispatcher();
125 /// Indicate that we are about to start a new sequence of mutations.
126 void StartMutationSequence();
127 /// Print the current sequence of mutations.
128 void PrintMutationSequence();
129 /// Indicate that the current sequence of mutations was successfull.
130 void RecordSuccessfulMutationSequence();
131 /// Mutates data by shuffling bytes.
132 size_t Mutate_ShuffleBytes(uint8_t *Data, size_t Size, size_t MaxSize);
133 /// Mutates data by erasing a byte.
134 size_t Mutate_EraseByte(uint8_t *Data, size_t Size, size_t MaxSize);
135 /// Mutates data by inserting a byte.
136 size_t Mutate_InsertByte(uint8_t *Data, size_t Size, size_t MaxSize);
137 /// Mutates data by chanding one byte.
138 size_t Mutate_ChangeByte(uint8_t *Data, size_t Size, size_t MaxSize);
139 /// Mutates data by chanding one bit.
140 size_t Mutate_ChangeBit(uint8_t *Data, size_t Size, size_t MaxSize);
141
142 /// Mutates data by adding a word from the manual dictionary.
143 size_t Mutate_AddWordFromManualDictionary(uint8_t *Data, size_t Size,
144 size_t MaxSize);
145
146 /// Mutates data by adding a word from the temporary automatic dictionary.
147 size_t Mutate_AddWordFromTemporaryAutoDictionary(uint8_t *Data, size_t Size,
148 size_t MaxSize);
149
150 /// Mutates data by adding a word from the persistent automatic dictionary.
151 size_t Mutate_AddWordFromPersistentAutoDictionary(uint8_t *Data, size_t Size,
152 size_t MaxSize);
153
154 /// Tries to find an ASCII integer in Data, changes it to another ASCII int.
155 size_t Mutate_ChangeASCIIInteger(uint8_t *Data, size_t Size, size_t MaxSize);
156
157 /// CrossOver Data with some other element of the corpus.
158 size_t Mutate_CrossOver(uint8_t *Data, size_t Size, size_t MaxSize);
159
160 /// Applies one of the above mutations.
161 /// Returns the new size of data which could be up to MaxSize.
162 size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize);
163
164 /// Creates a cross-over of two pieces of Data, returns its size.
165 size_t CrossOver(const uint8_t *Data1, size_t Size1, const uint8_t *Data2,
166 size_t Size2, uint8_t *Out, size_t MaxOutSize);
167
Kostya Serebryany476f0ce2016-01-16 03:53:32 +0000168 void AddWordToManualDictionary(const Word &W);
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000169
Kostya Serebryany476f0ce2016-01-16 03:53:32 +0000170 void AddWordToAutoDictionary(const Word &W, size_t PositionHint);
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000171 void ClearAutoDictionary();
172 void PrintRecommendedDictionary();
173
174 void SetCorpus(const std::vector<Unit> *Corpus);
175
Ivan Krasindf919102016-01-22 22:28:27 +0000176private:
Kostya Serebryanya3992212016-02-13 03:00:53 +0000177 Random &Rand;
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000178 struct Impl;
179 Impl *MDImpl;
180};
181
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000182class UserSuppliedFuzzer {
183 public:
Kostya Serebryanya3992212016-02-13 03:00:53 +0000184 UserSuppliedFuzzer(Random *Rand);
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000185 /// Executes the target function on 'Size' bytes of 'Data'.
186 virtual int TargetFunction(const uint8_t *Data, size_t Size) = 0;
187 /// Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
188 /// returns the new size of the data, which should be positive.
189 virtual size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize);
190 /// Crosses 'Data1' and 'Data2', writes up to 'MaxOutSize' bytes into Out,
191 /// returns the number of bytes written, which should be positive.
192 virtual size_t CrossOver(const uint8_t *Data1, size_t Size1,
193 const uint8_t *Data2, size_t Size2,
194 uint8_t *Out, size_t MaxOutSize);
195 virtual ~UserSuppliedFuzzer();
196
Kostya Serebryanya3992212016-02-13 03:00:53 +0000197 Random &GetRand() { return *Rand; }
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000198
199 MutationDispatcher &GetMD() { return *MD; }
200
201 private:
202 bool OwnRand = false;
Kostya Serebryanya3992212016-02-13 03:00:53 +0000203 Random *Rand;
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000204 MutationDispatcher *MD;
205};
206
Aaron Ballmanef116982015-01-29 16:58:29 +0000207class Fuzzer {
Ivan Krasindf919102016-01-22 22:28:27 +0000208public:
Aaron Ballmanef116982015-01-29 16:58:29 +0000209 struct FuzzingOptions {
210 int Verbosity = 1;
211 int MaxLen = 0;
Kostya Serebryany490bbd62015-05-19 22:12:57 +0000212 int UnitTimeoutSec = 300;
Kostya Serebryany9768e7f2016-01-23 19:34:19 +0000213 bool AbortOnTimeout = false;
Kostya Serebryany54a63632016-01-29 23:30:07 +0000214 int TimeoutExitCode = 77;
Kostya Serebryanyb85db172015-10-02 20:47:55 +0000215 int MaxTotalTimeSec = 0;
Aaron Ballmanef116982015-01-29 16:58:29 +0000216 bool DoCrossOver = true;
Ivan Krasindf919102016-01-22 22:28:27 +0000217 int MutateDepth = 5;
Aaron Ballmanef116982015-01-29 16:58:29 +0000218 bool ExitOnFirst = false;
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000219 bool UseCounters = false;
Kostya Serebryany2e9fca92015-10-22 23:55:39 +0000220 bool UseIndirCalls = true;
Kostya Serebryany5a99ecb2015-05-11 20:51:19 +0000221 bool UseTraces = false;
Kostya Serebryanyae5b9562016-01-15 06:24:05 +0000222 bool UseMemcmp = true;
Ivan Krasindf919102016-01-22 22:28:27 +0000223 bool UseFullCoverageSet = false;
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000224 bool Reload = true;
Kostya Serebryanyfed509e2015-10-17 04:38:26 +0000225 bool ShuffleAtStartUp = true;
Kostya Serebryany92e04762015-02-04 23:42:42 +0000226 int PreferSmallDuringInitialShuffle = -1;
Kostya Serebryany33f86692015-02-04 22:20:09 +0000227 size_t MaxNumberOfRuns = ULONG_MAX;
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000228 int SyncTimeout = 600;
Kostya Serebryany70926ae2015-08-05 21:43:48 +0000229 int ReportSlowUnits = 10;
Kostya Serebryanybc7c0ad2015-08-11 01:44:42 +0000230 bool OnlyASCII = false;
Aaron Ballmanef116982015-01-29 16:58:29 +0000231 std::string OutputCorpus;
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000232 std::string SyncCommand;
Kostya Serebryanybd5d1cd2015-10-09 03:57:59 +0000233 std::string ArtifactPrefix = "./";
Kostya Serebryany2d0ef142015-11-25 21:40:46 +0000234 std::string ExactArtifactPath;
Kostya Serebryanyb91c62b2015-10-16 22:41:47 +0000235 bool SaveArtifacts = true;
Ivan Krasindf919102016-01-22 22:28:27 +0000236 bool PrintNEW = true; // Print a status line when new units are found;
Mike Aizatskya9c23872015-11-12 04:38:40 +0000237 bool OutputCSV = false;
Mike Aizatsky8b11f872016-01-06 00:21:22 +0000238 bool PrintNewCovPcs = false;
Aaron Ballmanef116982015-01-29 16:58:29 +0000239 };
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000240 Fuzzer(UserSuppliedFuzzer &USF, FuzzingOptions Options);
Ivan Krasindf919102016-01-22 22:28:27 +0000241 void AddToCorpus(const Unit &U) {
242 Corpus.push_back(U);
243 UpdateCorpusDistribution();
244 }
Kostya Serebryanydc3135d2015-11-12 01:02:01 +0000245 size_t ChooseUnitIdxToMutate();
246 const Unit &ChooseUnitToMutate() { return Corpus[ChooseUnitIdxToMutate()]; };
Kostya Serebryany468ed782015-09-08 17:30:35 +0000247 void Loop();
Kostya Serebryanydc3135d2015-11-12 01:02:01 +0000248 void Drill();
Aaron Ballmanef116982015-01-29 16:58:29 +0000249 void ShuffleAndMinimize();
Kostya Serebryany22526252015-05-11 21:16:27 +0000250 void InitializeTraceState();
Kostya Serebryanyd50a3ee2016-01-13 23:02:30 +0000251 void AssignTaintLabels(uint8_t *Data, size_t Size);
Aaron Ballmanef116982015-01-29 16:58:29 +0000252 size_t CorpusSize() const { return Corpus.size(); }
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000253 void ReadDir(const std::string &Path, long *Epoch) {
Kostya Serebryany9cc3b0d2015-10-24 01:16:40 +0000254 Printf("Loading corpus: %s\n", Path.c_str());
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000255 ReadDirToVectorOfUnits(Path.c_str(), &Corpus, Epoch);
Aaron Ballmanef116982015-01-29 16:58:29 +0000256 }
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000257 void RereadOutputCorpus();
Aaron Ballmanef116982015-01-29 16:58:29 +0000258 // Save the current corpus to OutputCorpus.
259 void SaveCorpus();
260
Kostya Serebryany92e04762015-02-04 23:42:42 +0000261 size_t secondsSinceProcessStartUp() {
262 return duration_cast<seconds>(system_clock::now() - ProcessStartTime)
263 .count();
264 }
265
266 size_t getTotalNumberOfRuns() { return TotalNumberOfRuns; }
267
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000268 static void StaticAlarmCallback();
269
Ivan Krasin95e82d52015-10-01 23:23:06 +0000270 void ExecuteCallback(const Unit &U);
Aaron Ballmanef116982015-01-29 16:58:29 +0000271
Kostya Serebryany9cc3b0d2015-10-24 01:16:40 +0000272 // Merge Corpora[1:] into Corpora[0].
273 void Merge(const std::vector<std::string> &Corpora);
274
Ivan Krasindf919102016-01-22 22:28:27 +0000275private:
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000276 void AlarmCallback();
Kostya Serebryany27ab2d72015-12-19 02:49:09 +0000277 void MutateAndTestOne();
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000278 void ReportNewCoverage(const Unit &U);
279 bool RunOne(const Unit &U);
Kostya Serebryanybc7c0ad2015-08-11 01:44:42 +0000280 void RunOneAndUpdateCorpus(Unit &U);
Aaron Ballmanef116982015-01-29 16:58:29 +0000281 void WriteToOutputCorpus(const Unit &U);
Kostya Serebryany2b7d2e92015-07-23 18:37:22 +0000282 void WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix);
Kostya Serebryany09d2a5f2015-10-22 22:56:45 +0000283 void PrintStats(const char *Where, const char *End = "\n");
Kostya Serebryanydc3135d2015-11-12 01:02:01 +0000284 void PrintStatusForNewUnit(const Unit &U);
Ivan Krasindf919102016-01-22 22:28:27 +0000285 // Updates the probability distribution for the units in the corpus.
286 // Must be called whenever the corpus or unit weights are changed.
287 void UpdateCorpusDistribution();
Aaron Ballmanef116982015-01-29 16:58:29 +0000288
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000289 void SyncCorpus();
290
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000291 size_t RecordBlockCoverage();
Kostya Serebryany2e9fca92015-10-22 23:55:39 +0000292 size_t RecordCallerCalleeCoverage();
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000293 void PrepareCoverageBeforeRun();
294 bool CheckCoverageAfterRun();
295
Kostya Serebryanybeb24c32015-05-07 21:02:11 +0000296 // Trace-based fuzzing: we run a unit with some kind of tracing
297 // enabled and record potentially useful mutations. Then
298 // We apply these mutations one by one to the unit and run it again.
299
300 // Start tracing; forget all previously proposed mutations.
301 void StartTraceRecording();
Kostya Serebryanyb65805a2016-01-09 03:08:58 +0000302 // Stop tracing.
303 void StopTraceRecording();
Kostya Serebryanybeb24c32015-05-07 21:02:11 +0000304
Aaron Ballmanef116982015-01-29 16:58:29 +0000305 void SetDeathCallback();
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000306 static void StaticDeathCallback();
307 void DeathCallback();
Kostya Serebryany98abb2c2016-01-13 23:46:01 +0000308
309 uint8_t *CurrentUnitData;
310 size_t CurrentUnitSize;
Aaron Ballmanef116982015-01-29 16:58:29 +0000311
312 size_t TotalNumberOfRuns = 0;
Kostya Serebryany12c78372015-08-12 01:55:37 +0000313 size_t TotalNumberOfExecutedTraceBasedMutations = 0;
Aaron Ballmanef116982015-01-29 16:58:29 +0000314
315 std::vector<Unit> Corpus;
Kostya Serebryanycbb23342015-05-19 01:06:07 +0000316 std::unordered_set<std::string> UnitHashesAddedToCorpus;
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000317
318 // For UseCounters
319 std::vector<uint8_t> CounterBitmap;
Ivan Krasindf919102016-01-22 22:28:27 +0000320 size_t TotalBits() { // Slow. Call it only for printing stats.
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000321 size_t Res = 0;
Ivan Krasindf919102016-01-22 22:28:27 +0000322 for (auto x : CounterBitmap)
323 Res += __builtin_popcount(x);
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000324 return Res;
325 }
326
Ivan Krasindf919102016-01-22 22:28:27 +0000327 // TODO(krasin): remove GetRand from UserSuppliedFuzzer,
328 // and fully rely on the generator and the seed.
329 // The user supplied fuzzer will have a way to access the
330 // generator for its own purposes (like seeding the custom
331 // PRNG).
332 std::mt19937 Generator;
333 std::piecewise_constant_distribution<double> CorpusDistribution;
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000334 UserSuppliedFuzzer &USF;
Aaron Ballmanef116982015-01-29 16:58:29 +0000335 FuzzingOptions Options;
336 system_clock::time_point ProcessStartTime = system_clock::now();
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000337 system_clock::time_point LastExternalSync = system_clock::now();
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000338 system_clock::time_point UnitStartTime;
Kostya Serebryany16901a92015-03-30 23:04:35 +0000339 long TimeOfLongestUnitInSeconds = 0;
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000340 long EpochOfLastReadOfOutputCorpus = 0;
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000341 size_t LastRecordedBlockCoverage = 0;
Kostya Serebryany2e9fca92015-10-22 23:55:39 +0000342 size_t LastRecordedCallerCalleeCoverage = 0;
Mike Aizatsky8b11f872016-01-06 00:21:22 +0000343 size_t LastCoveragePcBufferLen = 0;
Aaron Ballmanef116982015-01-29 16:58:29 +0000344};
345
Ivan Krasindf919102016-01-22 22:28:27 +0000346class SimpleUserSuppliedFuzzer : public UserSuppliedFuzzer {
347public:
Kostya Serebryanya3992212016-02-13 03:00:53 +0000348 SimpleUserSuppliedFuzzer(Random *Rand, UserCallback Callback)
Kostya Serebryany404c69f2015-07-24 01:06:40 +0000349 : UserSuppliedFuzzer(Rand), Callback(Callback) {}
Kostya Serebryany20bb5e72015-10-02 23:34:06 +0000350
Kostya Serebryany20bb5e72015-10-02 23:34:06 +0000351 virtual int TargetFunction(const uint8_t *Data, size_t Size) override {
Kostya Serebryany94660b32015-10-23 18:37:58 +0000352 return Callback(Data, Size);
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000353 }
354
Ivan Krasindf919102016-01-22 22:28:27 +0000355private:
Kostya Serebryany20bb5e72015-10-02 23:34:06 +0000356 UserCallback Callback = nullptr;
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000357};
358
Ivan Krasindf919102016-01-22 22:28:27 +0000359}; // namespace fuzzer
Yaron Keren347663b2015-08-10 16:37:40 +0000360
361#endif // LLVM_FUZZER_INTERNAL_H