2015-02-20 02:45:37 +08:00
|
|
|
//===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2016-05-14 02:04:35 +08:00
|
|
|
// Define the interface between libFuzzer and the library being tested.
|
2015-02-20 02:45:37 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-05-14 02:04:35 +08:00
|
|
|
// NOTE: the libFuzzer interface is thin and in the majority of cases
|
|
|
|
// you should not include this file into your target. In 95% of cases
|
|
|
|
// all you need is to define the following function in your file:
|
|
|
|
// extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
|
|
|
|
|
|
|
// WARNING: keep the interface in C.
|
2015-05-23 06:35:31 +08:00
|
|
|
|
2015-02-20 02:45:37 +08:00
|
|
|
#ifndef LLVM_FUZZER_INTERFACE_H
|
|
|
|
#define LLVM_FUZZER_INTERFACE_H
|
|
|
|
|
2016-05-14 02:04:35 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
2015-02-20 02:45:37 +08:00
|
|
|
|
2016-05-14 02:04:35 +08:00
|
|
|
#ifdef __cplusplus
|
2016-02-13 10:29:38 +08:00
|
|
|
extern "C" {
|
2016-05-14 02:04:35 +08:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
// Mandatory user-provided target function.
|
|
|
|
// Executes the code under test with [Data, Data+Size) as the input.
|
|
|
|
// libFuzzer will invoke this function *many* times with different inputs.
|
2016-02-13 10:29:38 +08:00
|
|
|
// Must return 0.
|
|
|
|
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
|
2016-05-14 02:04:35 +08:00
|
|
|
|
|
|
|
// Optional user-provided initialization function.
|
|
|
|
// If provided, this function will be called by libFuzzer once at startup.
|
|
|
|
// It may read and modify argc/argv.
|
|
|
|
// Must return 0.
|
2016-02-13 10:29:38 +08:00
|
|
|
int LLVMFuzzerInitialize(int *argc, char ***argv);
|
2016-05-14 02:04:35 +08:00
|
|
|
|
|
|
|
// Optional user-provided custom mutator.
|
|
|
|
// Mutates raw data in [Data, Data+Size) inplace.
|
2016-02-13 10:29:38 +08:00
|
|
|
// Returns the new size, which is not greater than MaxSize.
|
|
|
|
// Given the same Seed produces the same mutation.
|
|
|
|
size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,
|
|
|
|
unsigned int Seed);
|
|
|
|
|
2016-06-08 04:22:15 +08:00
|
|
|
// Optional user-provided custom cross-over function.
|
|
|
|
// Combines pieces of Data1 & Data2 together into Out.
|
|
|
|
// Returns the new size, which is not greater than MaxOutSize.
|
|
|
|
// Should produce the same mutation given the same Seed.
|
|
|
|
size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,
|
|
|
|
const uint8_t *Data2, size_t Size2,
|
|
|
|
uint8_t *Out, size_t MaxOutSize,
|
|
|
|
unsigned int Seed);
|
|
|
|
|
2016-05-14 02:04:35 +08:00
|
|
|
// Experimental, may go away in future.
|
2017-01-18 07:09:05 +08:00
|
|
|
// libFuzzer-provided function to be used inside LLVMFuzzerCustomMutator.
|
2016-05-14 02:04:35 +08:00
|
|
|
// Mutates raw data in [Data, Data+Size) inplace.
|
2016-02-13 14:24:18 +08:00
|
|
|
// Returns the new size, which is not greater than MaxSize.
|
2016-05-14 02:04:35 +08:00
|
|
|
size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);
|
2016-02-13 10:39:30 +08:00
|
|
|
|
2016-05-14 02:04:35 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif // __cplusplus
|
2015-02-20 02:45:37 +08:00
|
|
|
|
|
|
|
#endif // LLVM_FUZZER_INTERFACE_H
|