1 1.1 kamil //===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===// 2 1.1 kamil // 3 1.1 kamil // The LLVM Compiler Infrastructure 4 1.1 kamil // 5 1.1 kamil // This file is distributed under the University of Illinois Open Source 6 1.1 kamil // License. See LICENSE.TXT for details. 7 1.1 kamil // 8 1.1 kamil //===----------------------------------------------------------------------===// 9 1.1 kamil // Define the interface between libFuzzer and the library being tested. 10 1.1 kamil //===----------------------------------------------------------------------===// 11 1.1 kamil 12 1.1 kamil // NOTE: the libFuzzer interface is thin and in the majority of cases 13 1.1 kamil // you should not include this file into your target. In 95% of cases 14 1.1 kamil // all you need is to define the following function in your file: 15 1.1 kamil // extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); 16 1.1 kamil 17 1.1 kamil // WARNING: keep the interface in C. 18 1.1 kamil 19 1.1 kamil #ifndef LLVM_FUZZER_INTERFACE_H 20 1.1 kamil #define LLVM_FUZZER_INTERFACE_H 21 1.1 kamil 22 1.1 kamil #include <stddef.h> 23 1.1 kamil #include <stdint.h> 24 1.1 kamil 25 1.1 kamil #ifdef __cplusplus 26 1.1 kamil extern "C" { 27 1.1 kamil #endif // __cplusplus 28 1.1 kamil 29 1.1 kamil // Mandatory user-provided target function. 30 1.1 kamil // Executes the code under test with [Data, Data+Size) as the input. 31 1.1 kamil // libFuzzer will invoke this function *many* times with different inputs. 32 1.1 kamil // Must return 0. 33 1.1 kamil __attribute__((visibility("default"))) int 34 1.1 kamil LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); 35 1.1 kamil 36 1.1 kamil // Optional user-provided initialization function. 37 1.1 kamil // If provided, this function will be called by libFuzzer once at startup. 38 1.1 kamil // It may read and modify argc/argv. 39 1.1 kamil // Must return 0. 40 1.1 kamil __attribute__((visibility("default"))) int LLVMFuzzerInitialize(int *argc, 41 1.1 kamil char ***argv); 42 1.1 kamil 43 1.1 kamil // Optional user-provided custom mutator. 44 1.1 kamil // Mutates raw data in [Data, Data+Size) inplace. 45 1.1 kamil // Returns the new size, which is not greater than MaxSize. 46 1.1 kamil // Given the same Seed produces the same mutation. 47 1.1 kamil __attribute__((visibility("default"))) size_t 48 1.1 kamil LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize, 49 1.1 kamil unsigned int Seed); 50 1.1 kamil 51 1.1 kamil // Optional user-provided custom cross-over function. 52 1.1 kamil // Combines pieces of Data1 & Data2 together into Out. 53 1.1 kamil // Returns the new size, which is not greater than MaxOutSize. 54 1.1 kamil // Should produce the same mutation given the same Seed. 55 1.1 kamil __attribute__((visibility("default"))) size_t 56 1.1 kamil LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1, 57 1.1 kamil const uint8_t *Data2, size_t Size2, uint8_t *Out, 58 1.1 kamil size_t MaxOutSize, unsigned int Seed); 59 1.1 kamil 60 1.1 kamil // Experimental, may go away in future. 61 1.1 kamil // libFuzzer-provided function to be used inside LLVMFuzzerCustomMutator. 62 1.1 kamil // Mutates raw data in [Data, Data+Size) inplace. 63 1.1 kamil // Returns the new size, which is not greater than MaxSize. 64 1.1 kamil __attribute__((visibility("default"))) size_t 65 1.1 kamil LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize); 66 1.1 kamil 67 1.1 kamil #ifdef __cplusplus 68 1.1 kamil } // extern "C" 69 1.1 kamil #endif // __cplusplus 70 1.1 kamil 71 1.1 kamil #endif // LLVM_FUZZER_INTERFACE_H 72