Path: blob/main/contrib/llvm-project/compiler-rt/lib/fuzzer/FuzzerInterface.h
35262 views
//===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7// Define the interface between libFuzzer and the library being tested.8//===----------------------------------------------------------------------===//910// NOTE: the libFuzzer interface is thin and in the majority of cases11// you should not include this file into your target. In 95% of cases12// all you need is to define the following function in your file:13// extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);1415// WARNING: keep the interface in C.1617#ifndef LLVM_FUZZER_INTERFACE_H18#define LLVM_FUZZER_INTERFACE_H1920#include <stddef.h>21#include <stdint.h>2223#ifdef __cplusplus24extern "C" {25#endif // __cplusplus2627// Define FUZZER_INTERFACE_VISIBILITY to set default visibility in a way that28// doesn't break MSVC.29#if defined(_WIN32)30#define FUZZER_INTERFACE_VISIBILITY __declspec(dllexport)31#else32#define FUZZER_INTERFACE_VISIBILITY __attribute__((visibility("default")))33#endif3435// Mandatory user-provided target function.36// Executes the code under test with [Data, Data+Size) as the input.37// libFuzzer will invoke this function *many* times with different inputs.38// Must return 0.39FUZZER_INTERFACE_VISIBILITY int40LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);4142// Optional user-provided initialization function.43// If provided, this function will be called by libFuzzer once at startup.44// It may read and modify argc/argv.45// Must return 0.46FUZZER_INTERFACE_VISIBILITY int LLVMFuzzerInitialize(int *argc, char ***argv);4748// Optional user-provided custom mutator.49// Mutates raw data in [Data, Data+Size) inplace.50// Returns the new size, which is not greater than MaxSize.51// Given the same Seed produces the same mutation.52FUZZER_INTERFACE_VISIBILITY size_t53LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,54unsigned int Seed);5556// Optional user-provided custom cross-over function.57// Combines pieces of Data1 & Data2 together into Out.58// Returns the new size, which is not greater than MaxOutSize.59// Should produce the same mutation given the same Seed.60FUZZER_INTERFACE_VISIBILITY size_t61LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,62const uint8_t *Data2, size_t Size2, uint8_t *Out,63size_t MaxOutSize, unsigned int Seed);6465// Experimental, may go away in future.66// libFuzzer-provided function to be used inside LLVMFuzzerCustomMutator.67// Mutates raw data in [Data, Data+Size) inplace.68// Returns the new size, which is not greater than MaxSize.69FUZZER_INTERFACE_VISIBILITY size_t70LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);7172#undef FUZZER_INTERFACE_VISIBILITY7374#ifdef __cplusplus75} // extern "C"76#endif // __cplusplus7778#endif // LLVM_FUZZER_INTERFACE_H798081