Debian Codegraph @

tools/fuzzing/registry/FuzzerRegistry.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 #ifndef _FuzzerRegistry_h__
7 #define _FuzzerRegistry_h__
8
9 #include <cstdint>
10 #include <map>
11 #include <string>
12 #include <utility>
13
14 #include "mozilla/Attributes.h"
15 #include "mozilla/Types.h"
16
17 typedef int (*FuzzerInitFunc)(int*, char***);
18 typedef int (*FuzzerTestingFunc)(const uint8_t*, size_t);
19
20 typedef int (*LibFuzzerDriver)(int*, char***, FuzzerTestingFunc);
21
22 namespace mozilla {
23
24 typedef std::pair<FuzzerInitFunc, FuzzerTestingFunc> FuzzerFunctions;
25
26 class FuzzerRegistry {
27 public:
28 MOZ_EXPORT static FuzzerRegistry& getInstance();
29 MOZ_EXPORT void registerModule(std::string moduleName,
30 FuzzerInitFunc initFunc,
31 FuzzerTestingFunc testingFunc);
32 MOZ_EXPORT FuzzerFunctions getModuleFunctions(std::string& moduleName);
33 MOZ_EXPORT void printModuleNames();
34
35 FuzzerRegistry(FuzzerRegistry const&) = delete;
36 void operator=(FuzzerRegistry const&) = delete;
37
38 private:
39 FuzzerRegistry() {};
40 std::map<std::string, FuzzerFunctions> moduleMap;
41 };
42
43 } // namespace mozilla
44
45 #endif // _FuzzerRegistry_h__