summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer/FuzzerInterface.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/FuzzerInterface.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/FuzzerInterface.h')
-rw-r--r--llvm/lib/Fuzzer/FuzzerInterface.h98
1 files changed, 5 insertions, 93 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerInterface.h b/llvm/lib/Fuzzer/FuzzerInterface.h
index 663cd5e7fdb..04e9b8350b9 100644
--- a/llvm/lib/Fuzzer/FuzzerInterface.h
+++ b/llvm/lib/Fuzzer/FuzzerInterface.h
@@ -64,6 +64,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) {
}
// Implement your own main() or use the one from FuzzerMain.cpp.
+// *NOT* recommended for most cases.
int main(int argc, char **argv) {
InitializeMeIfNeeded();
return fuzzer::FuzzerDriver(argc, argv, LLVMFuzzerTestOneInput);
@@ -72,102 +73,13 @@ int main(int argc, char **argv) {
*/
int FuzzerDriver(int argc, char **argv, UserCallback Callback);
-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;
-};
-
-// For backward compatibility only, deprecated.
-size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize,
- FuzzerRandomBase &Rand);
-
-size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed);
-
-class MutationDispatcher;
-
-/** An abstract class that allows to use user-supplied mutators with libFuzzer.
-
-Usage:
-
-#\code
-#include "FuzzerInterface.h"
-class MyFuzzer : public fuzzer::UserSuppliedFuzzer {
- public:
- MyFuzzer(fuzzer::FuzzerRandomBase *Rand);
- // Must define the target function.
- int TargetFunction(...) { ...; return 0; }
- // Optionally define the mutator.
- size_t Mutate(...) { ... }
- // Optionally define the CrossOver method.
- size_t CrossOver(...) { ... }
-};
-
-int main(int argc, char **argv) {
- MyFuzzer F;
- fuzzer::FuzzerDriver(argc, argv, F);
-}
-#\endcode
-*/
-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;
-};
-
-/// Runs the fuzzing with the UserSuppliedFuzzer.
-int FuzzerDriver(int argc, char **argv, UserSuppliedFuzzer &USF);
-
/// More C++-ish interface.
-int FuzzerDriver(const std::vector<std::string> &Args, UserSuppliedFuzzer &USF);
int FuzzerDriver(const std::vector<std::string> &Args, UserCallback Callback);
+// Same interface as LLVMFuzzerTestOneInput.
+// Can be used inside the user-supplied LLVMFuzzerTestOneInput.
+size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed);
+
} // namespace fuzzer
#endif // LLVM_FUZZER_INTERFACE_H
OpenPOWER on IntegriCloud