Debian Codegraph @

tools/fuzzing/interface/FuzzingInterface.h

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 * Interface definitions for the unified fuzzing interface
8 */
9
10 #ifndef FuzzingInterface_h__
11 #define FuzzingInterface_h__
12
13 #include <fstream>
14
15 #ifdef LIBFUZZER
16 # include "FuzzerExtFunctions.h"
17 #endif
18
19 #include "FuzzerRegistry.h"
20 #include "mozilla/Assertions.h"
21
22 #ifndef JS_STANDALONE
23 # include "mozilla/Logging.h"
24 #endif
25
26 namespace mozilla {
27
28 #ifdef JS_STANDALONE
29 void fuzzing_log(const char* aFmt, ...);
30 # define MOZ_LOG_EXPAND_ARGS(...) __VA_ARGS__
31
32 # define FUZZING_LOG(args) fuzzing_log(MOZ_LOG_EXPAND_ARGS args);
33 #else
34 extern LazyLogModule gFuzzingLog;
35
36 # define FUZZING_LOG(args) \
37 MOZ_LOG(mozilla::gFuzzingLog, mozilla::LogLevel::Verbose, args)
38 #endif // JS_STANDALONE
39
40 } // namespace mozilla
41
42 typedef int (*FuzzingTestFuncRaw)(const uint8_t*, size_t);
43
44 #ifdef AFLFUZZ
45
46 int afl_interface_raw(FuzzingTestFuncRaw testFunc);
47
48 # define MOZ_AFL_INTERFACE_RAW(initFunc, testFunc, moduleName) \
49 static int afl_fuzz_##moduleName(const uint8_t* data, size_t size) { \
50 return afl_interface_raw(testFunc); \
51 } \
52 static void __attribute__((constructor)) AFLRegister##moduleName() { \
53 ::mozilla::FuzzerRegistry::getInstance().registerModule( \
54 #moduleName, initFunc, afl_fuzz_##moduleName); \
55 }
56 #else
57 # define MOZ_AFL_INTERFACE_RAW(initFunc, testFunc, moduleName) /* Nothing */
58 #endif // AFLFUZZ
59
60 #ifdef LIBFUZZER
61 # define MOZ_LIBFUZZER_INTERFACE_RAW(initFunc, testFunc, moduleName) \
62 static void __attribute__((constructor)) LibFuzzerRegister##moduleName() { \
63 ::mozilla::FuzzerRegistry::getInstance().registerModule( \
64 #moduleName, initFunc, testFunc); \
65 }
66 #else
67 # define MOZ_LIBFUZZER_INTERFACE_RAW(initFunc, testFunc, \
68 moduleName) /* Nothing */
69 #endif
70
71 #define MOZ_FUZZING_INTERFACE_RAW(initFunc, testFunc, moduleName) \
72 MOZ_LIBFUZZER_INTERFACE_RAW(initFunc, testFunc, moduleName); \
73 MOZ_AFL_INTERFACE_RAW(initFunc, testFunc, moduleName);
74
75 #endif // FuzzingInterface_h__