1//===- FuzzerDefs.h - Internal header for the Fuzzer ------------*- C++ -* ===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// Basic definitions. 9//===----------------------------------------------------------------------===// 10 11#ifndef LLVM_FUZZER_DEFS_H 12#define LLVM_FUZZER_DEFS_H 13 14#include <cassert> 15#include <cstddef> 16#include <cstdint> 17#include <cstring> 18#include <memory> 19#include <set> 20#include <string> 21#include <vector> 22 23 24namespace fuzzer { 25 26template <class T> T Min(T a, T b) { return a < b ? a : b; } 27template <class T> T Max(T a, T b) { return a > b ? a : b; } 28 29class Random; 30class Dictionary; 31class DictionaryEntry; 32class MutationDispatcher; 33struct FuzzingOptions; 34class InputCorpus; 35struct InputInfo; 36struct ExternalFunctions; 37 38// Global interface to functions that may or may not be available. 39extern ExternalFunctions *EF; 40 41// We are using a custom allocator to give a different symbol name to STL 42// containers in order to avoid ODR violations. 43template<typename T> 44 class fuzzer_allocator: public std::allocator<T> { 45 public: 46 fuzzer_allocator() = default; 47 48 template<class U> 49 fuzzer_allocator(const fuzzer_allocator<U>&) {} 50 51 template<class Other> 52 struct rebind { typedef fuzzer_allocator<Other> other; }; 53 }; 54 55template<typename T> 56using Vector = std::vector<T, fuzzer_allocator<T>>; 57 58template<typename T> 59using Set = std::set<T, std::less<T>, fuzzer_allocator<T>>; 60 61typedef Vector<uint8_t> Unit; 62typedef Vector<Unit> UnitVector; 63typedef int (*UserCallback)(const uint8_t *Data, size_t Size); 64 65int FuzzerDriver(int *argc, char ***argv, UserCallback Callback); 66 67uint8_t *ExtraCountersBegin(); 68uint8_t *ExtraCountersEnd(); 69void ClearExtraCounters(); 70 71extern bool RunningUserCallback; 72 73} // namespace fuzzer 74 75#endif // LLVM_FUZZER_DEFS_H 76