blob: f57e24f739feac2ddc15234e1c4e7e0754d2b856 [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 Serebryanyecab57b2016-02-13 02:39:30 +0000101class FuzzerRandomBase {
102 public:
103 FuzzerRandomBase(){}
104 virtual ~FuzzerRandomBase(){};
105 virtual void ResetSeed(unsigned int seed) = 0;
106 // Return a random number.
107 virtual size_t Rand() = 0;
108 // Return a random number in range [0,n).
109 size_t operator()(size_t n) { return n ? Rand() % n : 0; }
110 bool RandBool() { return Rand() % 2; }
111};
112
113// Using libc's stand/rand.
114class FuzzerRandomLibc : public FuzzerRandomBase {
115 public:
116 FuzzerRandomLibc(unsigned int seed) { ResetSeed(seed); }
117 void ResetSeed(unsigned int seed) override;
118 ~FuzzerRandomLibc() override {};
119 size_t Rand() override;
120};
121
122// Using std::mt19937
123class FuzzerRandom_mt19937 : public FuzzerRandomBase {
124 public:
125 FuzzerRandom_mt19937(unsigned int seed) { ResetSeed(seed); }
126 void ResetSeed(unsigned int seed) override;
127 ~FuzzerRandom_mt19937() override;
128 size_t Rand() override;
129 private:
130 struct Impl;
131 Impl *R = nullptr;
132};
133
134
135
Kostya Serebryany9838b2b2015-09-03 20:23:46 +0000136// Dictionary.
137
138// Parses one dictionary entry.
139// If successfull, write the enty to Unit and returns true,
140// otherwise returns false.
141bool ParseOneDictionaryEntry(const std::string &Str, Unit *U);
142// Parses the dictionary file, fills Units, returns true iff all lines
143// were parsed succesfully.
144bool ParseDictionaryFile(const std::string &Text, std::vector<Unit> *Units);
145
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000146class MutationDispatcher {
Ivan Krasindf919102016-01-22 22:28:27 +0000147public:
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000148 MutationDispatcher(FuzzerRandomBase &Rand);
149 ~MutationDispatcher();
150 /// Indicate that we are about to start a new sequence of mutations.
151 void StartMutationSequence();
152 /// Print the current sequence of mutations.
153 void PrintMutationSequence();
154 /// Indicate that the current sequence of mutations was successfull.
155 void RecordSuccessfulMutationSequence();
156 /// Mutates data by shuffling bytes.
157 size_t Mutate_ShuffleBytes(uint8_t *Data, size_t Size, size_t MaxSize);
158 /// Mutates data by erasing a byte.
159 size_t Mutate_EraseByte(uint8_t *Data, size_t Size, size_t MaxSize);
160 /// Mutates data by inserting a byte.
161 size_t Mutate_InsertByte(uint8_t *Data, size_t Size, size_t MaxSize);
162 /// Mutates data by chanding one byte.
163 size_t Mutate_ChangeByte(uint8_t *Data, size_t Size, size_t MaxSize);
164 /// Mutates data by chanding one bit.
165 size_t Mutate_ChangeBit(uint8_t *Data, size_t Size, size_t MaxSize);
166
167 /// Mutates data by adding a word from the manual dictionary.
168 size_t Mutate_AddWordFromManualDictionary(uint8_t *Data, size_t Size,
169 size_t MaxSize);
170
171 /// Mutates data by adding a word from the temporary automatic dictionary.
172 size_t Mutate_AddWordFromTemporaryAutoDictionary(uint8_t *Data, size_t Size,
173 size_t MaxSize);
174
175 /// Mutates data by adding a word from the persistent automatic dictionary.
176 size_t Mutate_AddWordFromPersistentAutoDictionary(uint8_t *Data, size_t Size,
177 size_t MaxSize);
178
179 /// Tries to find an ASCII integer in Data, changes it to another ASCII int.
180 size_t Mutate_ChangeASCIIInteger(uint8_t *Data, size_t Size, size_t MaxSize);
181
182 /// CrossOver Data with some other element of the corpus.
183 size_t Mutate_CrossOver(uint8_t *Data, size_t Size, size_t MaxSize);
184
185 /// Applies one of the above mutations.
186 /// Returns the new size of data which could be up to MaxSize.
187 size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize);
188
189 /// Creates a cross-over of two pieces of Data, returns its size.
190 size_t CrossOver(const uint8_t *Data1, size_t Size1, const uint8_t *Data2,
191 size_t Size2, uint8_t *Out, size_t MaxOutSize);
192
Kostya Serebryany476f0ce2016-01-16 03:53:32 +0000193 void AddWordToManualDictionary(const Word &W);
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000194
Kostya Serebryany476f0ce2016-01-16 03:53:32 +0000195 void AddWordToAutoDictionary(const Word &W, size_t PositionHint);
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000196 void ClearAutoDictionary();
197 void PrintRecommendedDictionary();
198
199 void SetCorpus(const std::vector<Unit> *Corpus);
200
Ivan Krasindf919102016-01-22 22:28:27 +0000201private:
Kostya Serebryany628bc3e2016-01-16 00:04:36 +0000202 FuzzerRandomBase &Rand;
203 struct Impl;
204 Impl *MDImpl;
205};
206
Kostya Serebryanyecab57b2016-02-13 02:39:30 +0000207class UserSuppliedFuzzer {
208 public:
209 UserSuppliedFuzzer(FuzzerRandomBase *Rand);
210 /// Executes the target function on 'Size' bytes of 'Data'.
211 virtual int TargetFunction(const uint8_t *Data, size_t Size) = 0;
212 /// Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
213 /// returns the new size of the data, which should be positive.
214 virtual size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize);
215 /// Crosses 'Data1' and 'Data2', writes up to 'MaxOutSize' bytes into Out,
216 /// returns the number of bytes written, which should be positive.
217 virtual size_t CrossOver(const uint8_t *Data1, size_t Size1,
218 const uint8_t *Data2, size_t Size2,
219 uint8_t *Out, size_t MaxOutSize);
220 virtual ~UserSuppliedFuzzer();
221
222 FuzzerRandomBase &GetRand() { return *Rand; }
223
224 MutationDispatcher &GetMD() { return *MD; }
225
226 private:
227 bool OwnRand = false;
228 FuzzerRandomBase *Rand;
229 MutationDispatcher *MD;
230};
231
Aaron Ballmanef116982015-01-29 16:58:29 +0000232class Fuzzer {
Ivan Krasindf919102016-01-22 22:28:27 +0000233public:
Aaron Ballmanef116982015-01-29 16:58:29 +0000234 struct FuzzingOptions {
235 int Verbosity = 1;
236 int MaxLen = 0;
Kostya Serebryany490bbd62015-05-19 22:12:57 +0000237 int UnitTimeoutSec = 300;
Kostya Serebryany9768e7f2016-01-23 19:34:19 +0000238 bool AbortOnTimeout = false;
Kostya Serebryany54a63632016-01-29 23:30:07 +0000239 int TimeoutExitCode = 77;
Kostya Serebryanyb85db172015-10-02 20:47:55 +0000240 int MaxTotalTimeSec = 0;
Aaron Ballmanef116982015-01-29 16:58:29 +0000241 bool DoCrossOver = true;
Ivan Krasindf919102016-01-22 22:28:27 +0000242 int MutateDepth = 5;
Aaron Ballmanef116982015-01-29 16:58:29 +0000243 bool ExitOnFirst = false;
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000244 bool UseCounters = false;
Kostya Serebryany2e9fca92015-10-22 23:55:39 +0000245 bool UseIndirCalls = true;
Kostya Serebryany5a99ecb2015-05-11 20:51:19 +0000246 bool UseTraces = false;
Kostya Serebryanyae5b9562016-01-15 06:24:05 +0000247 bool UseMemcmp = true;
Ivan Krasindf919102016-01-22 22:28:27 +0000248 bool UseFullCoverageSet = false;
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000249 bool Reload = true;
Kostya Serebryanyfed509e2015-10-17 04:38:26 +0000250 bool ShuffleAtStartUp = true;
Kostya Serebryany92e04762015-02-04 23:42:42 +0000251 int PreferSmallDuringInitialShuffle = -1;
Kostya Serebryany33f86692015-02-04 22:20:09 +0000252 size_t MaxNumberOfRuns = ULONG_MAX;
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000253 int SyncTimeout = 600;
Kostya Serebryany70926ae2015-08-05 21:43:48 +0000254 int ReportSlowUnits = 10;
Kostya Serebryanybc7c0ad2015-08-11 01:44:42 +0000255 bool OnlyASCII = false;
Aaron Ballmanef116982015-01-29 16:58:29 +0000256 std::string OutputCorpus;
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000257 std::string SyncCommand;
Kostya Serebryanybd5d1cd2015-10-09 03:57:59 +0000258 std::string ArtifactPrefix = "./";
Kostya Serebryany2d0ef142015-11-25 21:40:46 +0000259 std::string ExactArtifactPath;
Kostya Serebryanyb91c62b2015-10-16 22:41:47 +0000260 bool SaveArtifacts = true;
Ivan Krasindf919102016-01-22 22:28:27 +0000261 bool PrintNEW = true; // Print a status line when new units are found;
Mike Aizatskya9c23872015-11-12 04:38:40 +0000262 bool OutputCSV = false;
Mike Aizatsky8b11f872016-01-06 00:21:22 +0000263 bool PrintNewCovPcs = false;
Aaron Ballmanef116982015-01-29 16:58:29 +0000264 };
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000265 Fuzzer(UserSuppliedFuzzer &USF, FuzzingOptions Options);
Ivan Krasindf919102016-01-22 22:28:27 +0000266 void AddToCorpus(const Unit &U) {
267 Corpus.push_back(U);
268 UpdateCorpusDistribution();
269 }
Kostya Serebryanydc3135d2015-11-12 01:02:01 +0000270 size_t ChooseUnitIdxToMutate();
271 const Unit &ChooseUnitToMutate() { return Corpus[ChooseUnitIdxToMutate()]; };
Kostya Serebryany468ed782015-09-08 17:30:35 +0000272 void Loop();
Kostya Serebryanydc3135d2015-11-12 01:02:01 +0000273 void Drill();
Aaron Ballmanef116982015-01-29 16:58:29 +0000274 void ShuffleAndMinimize();
Kostya Serebryany22526252015-05-11 21:16:27 +0000275 void InitializeTraceState();
Kostya Serebryanyd50a3ee2016-01-13 23:02:30 +0000276 void AssignTaintLabels(uint8_t *Data, size_t Size);
Aaron Ballmanef116982015-01-29 16:58:29 +0000277 size_t CorpusSize() const { return Corpus.size(); }
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000278 void ReadDir(const std::string &Path, long *Epoch) {
Kostya Serebryany9cc3b0d2015-10-24 01:16:40 +0000279 Printf("Loading corpus: %s\n", Path.c_str());
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000280 ReadDirToVectorOfUnits(Path.c_str(), &Corpus, Epoch);
Aaron Ballmanef116982015-01-29 16:58:29 +0000281 }
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000282 void RereadOutputCorpus();
Aaron Ballmanef116982015-01-29 16:58:29 +0000283 // Save the current corpus to OutputCorpus.
284 void SaveCorpus();
285
Kostya Serebryany92e04762015-02-04 23:42:42 +0000286 size_t secondsSinceProcessStartUp() {
287 return duration_cast<seconds>(system_clock::now() - ProcessStartTime)
288 .count();
289 }
290
291 size_t getTotalNumberOfRuns() { return TotalNumberOfRuns; }
292
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000293 static void StaticAlarmCallback();
294
Ivan Krasin95e82d52015-10-01 23:23:06 +0000295 void ExecuteCallback(const Unit &U);
Aaron Ballmanef116982015-01-29 16:58:29 +0000296
Kostya Serebryany9cc3b0d2015-10-24 01:16:40 +0000297 // Merge Corpora[1:] into Corpora[0].
298 void Merge(const std::vector<std::string> &Corpora);
299
Ivan Krasindf919102016-01-22 22:28:27 +0000300private:
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000301 void AlarmCallback();
Kostya Serebryany27ab2d72015-12-19 02:49:09 +0000302 void MutateAndTestOne();
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000303 void ReportNewCoverage(const Unit &U);
304 bool RunOne(const Unit &U);
Kostya Serebryanybc7c0ad2015-08-11 01:44:42 +0000305 void RunOneAndUpdateCorpus(Unit &U);
Aaron Ballmanef116982015-01-29 16:58:29 +0000306 void WriteToOutputCorpus(const Unit &U);
Kostya Serebryany2b7d2e92015-07-23 18:37:22 +0000307 void WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix);
Kostya Serebryany09d2a5f2015-10-22 22:56:45 +0000308 void PrintStats(const char *Where, const char *End = "\n");
Kostya Serebryanydc3135d2015-11-12 01:02:01 +0000309 void PrintStatusForNewUnit(const Unit &U);
Ivan Krasindf919102016-01-22 22:28:27 +0000310 // Updates the probability distribution for the units in the corpus.
311 // Must be called whenever the corpus or unit weights are changed.
312 void UpdateCorpusDistribution();
Aaron Ballmanef116982015-01-29 16:58:29 +0000313
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000314 void SyncCorpus();
315
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000316 size_t RecordBlockCoverage();
Kostya Serebryany2e9fca92015-10-22 23:55:39 +0000317 size_t RecordCallerCalleeCoverage();
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000318 void PrepareCoverageBeforeRun();
319 bool CheckCoverageAfterRun();
320
Kostya Serebryanybeb24c32015-05-07 21:02:11 +0000321 // Trace-based fuzzing: we run a unit with some kind of tracing
322 // enabled and record potentially useful mutations. Then
323 // We apply these mutations one by one to the unit and run it again.
324
325 // Start tracing; forget all previously proposed mutations.
326 void StartTraceRecording();
Kostya Serebryanyb65805a2016-01-09 03:08:58 +0000327 // Stop tracing.
328 void StopTraceRecording();
Kostya Serebryanybeb24c32015-05-07 21:02:11 +0000329
Aaron Ballmanef116982015-01-29 16:58:29 +0000330 void SetDeathCallback();
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000331 static void StaticDeathCallback();
332 void DeathCallback();
Kostya Serebryany98abb2c2016-01-13 23:46:01 +0000333
334 uint8_t *CurrentUnitData;
335 size_t CurrentUnitSize;
Aaron Ballmanef116982015-01-29 16:58:29 +0000336
337 size_t TotalNumberOfRuns = 0;
Kostya Serebryany12c78372015-08-12 01:55:37 +0000338 size_t TotalNumberOfExecutedTraceBasedMutations = 0;
Aaron Ballmanef116982015-01-29 16:58:29 +0000339
340 std::vector<Unit> Corpus;
Kostya Serebryanycbb23342015-05-19 01:06:07 +0000341 std::unordered_set<std::string> UnitHashesAddedToCorpus;
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000342
343 // For UseCounters
344 std::vector<uint8_t> CounterBitmap;
Ivan Krasindf919102016-01-22 22:28:27 +0000345 size_t TotalBits() { // Slow. Call it only for printing stats.
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000346 size_t Res = 0;
Ivan Krasindf919102016-01-22 22:28:27 +0000347 for (auto x : CounterBitmap)
348 Res += __builtin_popcount(x);
Kostya Serebryanybe5e0ed2015-03-03 23:27:02 +0000349 return Res;
350 }
351
Ivan Krasindf919102016-01-22 22:28:27 +0000352 // TODO(krasin): remove GetRand from UserSuppliedFuzzer,
353 // and fully rely on the generator and the seed.
354 // The user supplied fuzzer will have a way to access the
355 // generator for its own purposes (like seeding the custom
356 // PRNG).
357 std::mt19937 Generator;
358 std::piecewise_constant_distribution<double> CorpusDistribution;
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000359 UserSuppliedFuzzer &USF;
Aaron Ballmanef116982015-01-29 16:58:29 +0000360 FuzzingOptions Options;
361 system_clock::time_point ProcessStartTime = system_clock::now();
Kostya Serebryany2da7b842015-05-18 21:34:20 +0000362 system_clock::time_point LastExternalSync = system_clock::now();
Kostya Serebryany52a788e2015-03-31 20:13:20 +0000363 system_clock::time_point UnitStartTime;
Kostya Serebryany16901a92015-03-30 23:04:35 +0000364 long TimeOfLongestUnitInSeconds = 0;
Kostya Serebryany1ac80552015-05-08 21:30:55 +0000365 long EpochOfLastReadOfOutputCorpus = 0;
Kostya Serebryany007c9b22015-10-22 22:50:47 +0000366 size_t LastRecordedBlockCoverage = 0;
Kostya Serebryany2e9fca92015-10-22 23:55:39 +0000367 size_t LastRecordedCallerCalleeCoverage = 0;
Mike Aizatsky8b11f872016-01-06 00:21:22 +0000368 size_t LastCoveragePcBufferLen = 0;
Aaron Ballmanef116982015-01-29 16:58:29 +0000369};
370
Ivan Krasindf919102016-01-22 22:28:27 +0000371class SimpleUserSuppliedFuzzer : public UserSuppliedFuzzer {
372public:
Kostya Serebryany404c69f2015-07-24 01:06:40 +0000373 SimpleUserSuppliedFuzzer(FuzzerRandomBase *Rand, UserCallback Callback)
374 : UserSuppliedFuzzer(Rand), Callback(Callback) {}
Kostya Serebryany20bb5e72015-10-02 23:34:06 +0000375
Kostya Serebryany20bb5e72015-10-02 23:34:06 +0000376 virtual int TargetFunction(const uint8_t *Data, size_t Size) override {
Kostya Serebryany94660b32015-10-23 18:37:58 +0000377 return Callback(Data, Size);
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000378 }
379
Ivan Krasindf919102016-01-22 22:28:27 +0000380private:
Kostya Serebryany20bb5e72015-10-02 23:34:06 +0000381 UserCallback Callback = nullptr;
Kostya Serebryanyf3424592015-05-22 22:35:31 +0000382};
383
Ivan Krasindf919102016-01-22 22:28:27 +0000384}; // namespace fuzzer
Yaron Keren347663b2015-08-10 16:37:40 +0000385
386#endif // LLVM_FUZZER_INTERNAL_H