tools/fuzzing/libfuzzer/harness/LibFuzzerRegistry.cpp
author Wes Kocher <wkocher@mozilla.com>
Tue, 17 Jan 2017 17:55:24 -0800
changeset 374858 93ffc3c44ee31192f6080f37d82994ca348e4148
parent 374832 1c2f51ce3faff9c2ecd9d6c09ac49de975946185
child 375009 a5aa102e8f0ff015d21ac4057fa4d47f47192204
permissions -rw-r--r--
Backed out 4 changesets (bug 1306329) for 3000+ hazards a=backout Backed out changeset 1c2f51ce3faf (bug 1306329) Backed out changeset 6bb17b9a62d8 (bug 1306329) Backed out changeset 377ca1419f1a (bug 1306329) Backed out changeset ad4e531c7070 (bug 1306329) MozReview-Commit-ID: KJAxdyJeJ6J

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * * This Source Code Form is subject to the terms of the Mozilla Public
 * * License, v. 2.0. If a copy of the MPL was not distributed with this
 * * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "LibFuzzerRegistry.h"

extern "C" {
    void MOZ_EXPORT XRE_LibFuzzerGetFuncs(const char* moduleName, LibFuzzerInitFunc* initFunc, LibFuzzerTestingFunc* testingFunc) {
        std::string moduleNameStr(moduleName);
        mozilla::LibFuzzerFunctions funcs = mozilla::LibFuzzerRegistry::getInstance().getModuleFunctions(moduleNameStr);
        *initFunc = funcs.first;
        *testingFunc = funcs.second;
    }
}

namespace mozilla {

LibFuzzerRegistry& LibFuzzerRegistry::getInstance() {
    static LibFuzzerRegistry instance;
    return instance;
}

void LibFuzzerRegistry::registerModule(std::string moduleName, LibFuzzerInitFunc initFunc, LibFuzzerTestingFunc testingFunc) {
    moduleMap.insert(std::pair<std::string, LibFuzzerFunctions>(moduleName,LibFuzzerFunctions(initFunc, testingFunc)));
}

LibFuzzerFunctions LibFuzzerRegistry::getModuleFunctions(std::string& moduleName) {
    return moduleMap[moduleName];
}

} // namespace mozilla