Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1105)

Unified Diff: include/llvm/Bitcode/NaCl/NaClRandNumGen.h

Issue 1156103003: Initial implementation of a record-level bitcode fuzzer. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@fuzz
Patch Set: Fix issues in last patch. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClFuzz.h ('k') | lib/Bitcode/NaCl/TestUtils/CMakeLists.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/llvm/Bitcode/NaCl/NaClRandNumGen.h
diff --git a/include/llvm/Bitcode/NaCl/NaClRandNumGen.h b/include/llvm/Bitcode/NaCl/NaClRandNumGen.h
new file mode 100644
index 0000000000000000000000000000000000000000..6e09a4b9af8214e50a5465759881870db7e7de3e
--- /dev/null
+++ b/include/llvm/Bitcode/NaCl/NaClRandNumGen.h
@@ -0,0 +1,64 @@
+//===- NaClRandNumGen.h - random number generator ---------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines a random number generator API for 64-bit unsigned
+// values, and a corresponding default implementation.
+//
+// *** WARNING *** One should assume that random number generators are not
+// thread safe.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_BITCODE_NACL_NACLRANDNUMGEN_H
+#define LLVM_BITCODE_NACL_NACLRANDNUMGEN_H
+
+#include "llvm/ADT/StringRef.h"
+#include <random>
+
+namespace naclfuzz {
+
+/// Defines API for a random number generator to use with fuzzing.
+class RandomNumberGenerator {
+ RandomNumberGenerator(const RandomNumberGenerator&) = delete;
+ void operator=(const RandomNumberGenerator&) = delete;
+public:
+ virtual ~RandomNumberGenerator();
+ /// Returns a random number.
+ virtual uint64_t operator()() = 0;
+ // Returns a random value in [0..Limit)
+ uint64_t chooseInRange(uint64_t Limit) {
+ return (*this)() % Limit;
+ }
+protected:
+ RandomNumberGenerator() {}
+};
+
+/// Defines a random number generator based on C++ generator std::mt19937_64.
+class DefaultRandomNumberGenerator : public RandomNumberGenerator {
+ DefaultRandomNumberGenerator(const DefaultRandomNumberGenerator&) = delete;
+ void operator=(const DefaultRandomNumberGenerator&) = delete;
+public:
+ DefaultRandomNumberGenerator(llvm::StringRef Seed);
+ uint64_t operator()() final;
+ ~DefaultRandomNumberGenerator() final {}
+ // Resets random number seed by salting the seed of constructor with Salt.
+ void saltSeed(uint64_t Salt);
+private:
+ // 64-bit Mersenne Twister by Matsumoto and Nishimura, 2000
+ // http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine
+ // This RNG is deterministically portable across C++11
+ // implementations.
+ std::mt19937_64 Generator;
+ // Seed for the random number generator.
+ std::string Seed;
+};
+
+} // end of namespace naclfuzz
+
+#endif // LLVM_BITCODE_NACL_NACLRANDNUMGEN_H
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClFuzz.h ('k') | lib/Bitcode/NaCl/TestUtils/CMakeLists.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698