1 // Based on https://github.com/llvm-mirror/compiler-rt/blob/master/lib/fuzzer/FuzzerInterface.h
3 //===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===//
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
10 // Define the interface between libFuzzer and the library being tested.
11 //===----------------------------------------------------------------------===//
13 // NOTE: the libFuzzer interface is thin and in the majority of cases
14 // you should not include this file into your target. In 95% of cases
15 // all you need is to define the following function in your file:
16 // extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
18 // WARNING: keep the interface in C.
20 #ifndef LLVM_FUZZER_INTERFACE_H
21 #define LLVM_FUZZER_INTERFACE_H
30 // Define FUZZER_INTERFACE_VISIBILITY to set default visibility in a way that
31 // doesn't break MSVC.
33 #define FUZZER_INTERFACE_VISIBILITY __declspec(dllexport)
35 #define FUZZER_INTERFACE_VISIBILITY __attribute__((visibility("default")))
38 // Mandatory user-provided target function.
39 // Executes the code under test with [Data, Data+Size) as the input.
40 // libFuzzer will invoke this function *many* times with different inputs.
42 FUZZER_INTERFACE_VISIBILITY int
43 LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
45 // Optional user-provided initialization function.
46 // If provided, this function will be called by libFuzzer once at startup.
47 // It may read and modify argc/argv.
49 FUZZER_INTERFACE_VISIBILITY int LLVMFuzzerInitialize(int *argc, char ***argv);
51 // Optional user-provided custom mutator.
52 // Mutates raw data in [Data, Data+Size) inplace.
53 // Returns the new size, which is not greater than MaxSize.
54 // Given the same Seed produces the same mutation.
55 FUZZER_INTERFACE_VISIBILITY size_t
56 LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,
59 // Optional user-provided custom cross-over function.
60 // Combines pieces of Data1 & Data2 together into Out.
61 // Returns the new size, which is not greater than MaxOutSize.
62 // Should produce the same mutation given the same Seed.
63 FUZZER_INTERFACE_VISIBILITY size_t
64 LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,
65 const uint8_t *Data2, size_t Size2, uint8_t *Out,
66 size_t MaxOutSize, unsigned int Seed);
68 // Experimental, may go away in future.
69 // libFuzzer-provided function to be used inside LLVMFuzzerCustomMutator.
70 // Mutates raw data in [Data, Data+Size) inplace.
71 // Returns the new size, which is not greater than MaxSize.
72 FUZZER_INTERFACE_VISIBILITY size_t
73 LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);
75 #undef FUZZER_INTERFACE_VISIBILITY
81 #endif // LLVM_FUZZER_INTERFACE_H