blob: 8d27f2e7f48e39a87a8b992394b668283de4b1c0 [file] [log] [blame]
Kostya Serebryany016852c2015-02-19 18:45:37 +00001//===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +00009// Define the interface between libFuzzer and the library being tested.
Kostya Serebryany016852c2015-02-19 18:45:37 +000010//===----------------------------------------------------------------------===//
11
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000012// NOTE: the libFuzzer interface is thin and in the majority of cases
13// you should not include this file into your target. In 95% of cases
14// all you need is to define the following function in your file:
15// extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
16
17// WARNING: keep the interface in C.
Kostya Serebryanyf3424592015-05-22 22:35:31 +000018
Kostya Serebryany016852c2015-02-19 18:45:37 +000019#ifndef LLVM_FUZZER_INTERFACE_H
20#define LLVM_FUZZER_INTERFACE_H
21
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000022#include <stddef.h>
23#include <stdint.h>
Kostya Serebryany016852c2015-02-19 18:45:37 +000024
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000025#ifdef __cplusplus
Kostya Serebryany22cc5e22016-02-13 02:29:38 +000026extern "C" {
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000027#endif // __cplusplus
28
29// Mandatory user-provided target function.
30// Executes the code under test with [Data, Data+Size) as the input.
31// libFuzzer will invoke this function *many* times with different inputs.
Kostya Serebryany22cc5e22016-02-13 02:29:38 +000032// Must return 0.
33int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000034
35// Optional user-provided initialization function.
36// If provided, this function will be called by libFuzzer once at startup.
37// It may read and modify argc/argv.
38// Must return 0.
Kostya Serebryany22cc5e22016-02-13 02:29:38 +000039int LLVMFuzzerInitialize(int *argc, char ***argv);
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000040
41// Optional user-provided custom mutator.
42// Mutates raw data in [Data, Data+Size) inplace.
Kostya Serebryany22cc5e22016-02-13 02:29:38 +000043// Returns the new size, which is not greater than MaxSize.
44// Given the same Seed produces the same mutation.
45size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,
46 unsigned int Seed);
47
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000048// Experimental, may go away in future.
49// libFuzzer-provided function to be used inside LLVMFuzzerTestOneInput.
50// Mutates raw data in [Data, Data+Size) inplace.
Kostya Serebryany1deb0492016-02-13 06:24:18 +000051// Returns the new size, which is not greater than MaxSize.
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000052size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);
Kostya Serebryanyecab57b2016-02-13 02:39:30 +000053
Kostya Serebryany8b0d90a2016-05-13 18:04:35 +000054#ifdef __cplusplus
55} // extern "C"
56#endif // __cplusplus
Kostya Serebryany016852c2015-02-19 18:45:37 +000057
58#endif // LLVM_FUZZER_INTERFACE_H