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