Debian Codegraph @

tests/thirdparty/Fuzzer/FuzzerDefs.h

raw symbols SCIP
1 //===- FuzzerDefs.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 // Basic definitions.
10 //===----------------------------------------------------------------------===//
11
12 #ifndef LLVM_FUZZER_DEFS_H
13 #define LLVM_FUZZER_DEFS_H
14
15 #include <cassert>
16 #include <cstddef>
17 #include <cstdint>
18 #include <cstring>
19 #include <string>
20 #include <vector>
21
22 // Platform detection.
23 #ifdef __linux__
24 #define LIBFUZZER_APPLE 0
25 #define LIBFUZZER_LINUX 1
26 #define LIBFUZZER_WINDOWS 0
27 #elif __APPLE__
28 #define LIBFUZZER_APPLE 1
29 #define LIBFUZZER_LINUX 0
30 #define LIBFUZZER_WINDOWS 0
31 #elif _WIN32
32 #define LIBFUZZER_APPLE 0
33 #define LIBFUZZER_LINUX 0
34 #define LIBFUZZER_WINDOWS 1
35 #else
36 #error "Support for your platform has not been implemented"
37 #endif
38
39 #define LIBFUZZER_POSIX LIBFUZZER_APPLE || LIBFUZZER_LINUX
40
41 #ifdef __x86_64
42 #define ATTRIBUTE_TARGET_POPCNT __attribute__((target("popcnt")))
43 #else
44 #define ATTRIBUTE_TARGET_POPCNT
45 #endif
46
47
48 #ifdef __clang__ // avoid gcc warning.
49 # define ATTRIBUTE_NO_SANITIZE_MEMORY __attribute__((no_sanitize("memory")))
50 #else
51 # define ATTRIBUTE_NO_SANITIZE_MEMORY
52 #endif
53
54 namespace fuzzer {
55
56 template <class T> T Min(T a, T b) { return a < b ? a : b; }
57 template <class T> T Max(T a, T b) { return a > b ? a : b; }
58
59 class Random;
60 class Dictionary;
61 class DictionaryEntry;
62 class MutationDispatcher;
63 struct FuzzingOptions;
64 class InputCorpus;
65 struct InputInfo;
66 struct ExternalFunctions;
67
68 // Global interface to functions that may or may not be available.
69 extern ExternalFunctions *EF;
70
71 typedef std::vector<uint8_t> Unit;
72 typedef std::vector<Unit> UnitVector;
73 typedef int (*UserCallback)(const uint8_t *Data, size_t Size);
74
75 int FuzzerDriver(int *argc, char ***argv, UserCallback Callback);
76
77 struct ScopedDoingMyOwnMemmem {
78 ScopedDoingMyOwnMemmem();
79 ~ScopedDoingMyOwnMemmem();
80 };
81
82 inline uint8_t Bswap(uint8_t x) { return x; }
83 inline uint16_t Bswap(uint16_t x) { return __builtin_bswap16(x); }
84 inline uint32_t Bswap(uint32_t x) { return __builtin_bswap32(x); }
85 inline uint64_t Bswap(uint64_t x) { return __builtin_bswap64(x); }
86
87 } // namespace fuzzer
88
89 #endif // LLVM_FUZZER_DEFS_H