summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerInternal.h
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-02-13 02:39:30 +0000
committerKostya Serebryany <kcc@google.com>2016-02-13 02:39:30 +0000
commitecab57b3ceaa823c05a06ec818ce35d0bf91dfe8 (patch)
treea0d6a9e87b43ae88fdd761f90fcdccc7bc3770ef /llvm/lib/Fuzzer/FuzzerInternal.h
parente43ae19b312ae07f850f72b67f6f45dc084c1fdf (diff)
downloadbcm5719-llvm-ecab57b3ceaa823c05a06ec818ce35d0bf91dfe8.tar.gz
bcm5719-llvm-ecab57b3ceaa823c05a06ec818ce35d0bf91dfe8.zip
[libFuzzer] remove UserSuppliedFuzzer from the interface (it was a bad idea).
llvm-svn: 260796
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerInternal.h')
-rw-r--r--llvm/lib/Fuzzer/FuzzerInternal.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerInternal.h b/llvm/lib/Fuzzer/FuzzerInternal.h
index 07f45af08ff..f57e24f739f 100644
--- a/llvm/lib/Fuzzer/FuzzerInternal.h
+++ b/llvm/lib/Fuzzer/FuzzerInternal.h
@@ -98,6 +98,41 @@ bool IsASCII(const Unit &U);
int NumberOfCpuCores();
int GetPid();
+class FuzzerRandomBase {
+ public:
+ FuzzerRandomBase(){}
+ virtual ~FuzzerRandomBase(){};
+ virtual void ResetSeed(unsigned int seed) = 0;
+ // Return a random number.
+ virtual size_t Rand() = 0;
+ // Return a random number in range [0,n).
+ size_t operator()(size_t n) { return n ? Rand() % n : 0; }
+ bool RandBool() { return Rand() % 2; }
+};
+
+// Using libc's stand/rand.
+class FuzzerRandomLibc : public FuzzerRandomBase {
+ public:
+ FuzzerRandomLibc(unsigned int seed) { ResetSeed(seed); }
+ void ResetSeed(unsigned int seed) override;
+ ~FuzzerRandomLibc() override {};
+ size_t Rand() override;
+};
+
+// Using std::mt19937
+class FuzzerRandom_mt19937 : public FuzzerRandomBase {
+ public:
+ FuzzerRandom_mt19937(unsigned int seed) { ResetSeed(seed); }
+ void ResetSeed(unsigned int seed) override;
+ ~FuzzerRandom_mt19937() override;
+ size_t Rand() override;
+ private:
+ struct Impl;
+ Impl *R = nullptr;
+};
+
+
+
// Dictionary.
// Parses one dictionary entry.
@@ -169,6 +204,31 @@ private:
Impl *MDImpl;
};
+class UserSuppliedFuzzer {
+ public:
+ UserSuppliedFuzzer(FuzzerRandomBase *Rand);
+ /// Executes the target function on 'Size' bytes of 'Data'.
+ virtual int TargetFunction(const uint8_t *Data, size_t Size) = 0;
+ /// Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
+ /// returns the new size of the data, which should be positive.
+ virtual size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize);
+ /// Crosses 'Data1' and 'Data2', writes up to 'MaxOutSize' bytes into Out,
+ /// returns the number of bytes written, which should be positive.
+ virtual size_t CrossOver(const uint8_t *Data1, size_t Size1,
+ const uint8_t *Data2, size_t Size2,
+ uint8_t *Out, size_t MaxOutSize);
+ virtual ~UserSuppliedFuzzer();
+
+ FuzzerRandomBase &GetRand() { return *Rand; }
+
+ MutationDispatcher &GetMD() { return *MD; }
+
+ private:
+ bool OwnRand = false;
+ FuzzerRandomBase *Rand;
+ MutationDispatcher *MD;
+};
+
class Fuzzer {
public:
struct FuzzingOptions {
OpenPOWER on IntegriCloud