Home | History | Annotate | Download | only in FuzzMutate
      1 //===-- FuzzerCLI.h - Common logic for CLIs of fuzzers ----------*- 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 //===----------------------------------------------------------------------===//
      9 //
     10 // Common logic needed to implement LLVM's fuzz targets' CLIs - including LLVM
     11 // concepts like cl::opt and libFuzzer concepts like -ignore_remaining_args=1.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_FUZZMUTATE_FUZZER_CLI_H
     16 #define LLVM_FUZZMUTATE_FUZZER_CLI_H
     17 
     18 #include "llvm/ADT/StringRef.h"
     19 #include "llvm/Support/DataTypes.h"
     20 
     21 namespace llvm {
     22 
     23 /// Parse cl::opts from a fuzz target commandline.
     24 ///
     25 /// This handles all arguments after -ignore_remaining_args=1 as cl::opts.
     26 void parseFuzzerCLOpts(int ArgC, char *ArgV[]);
     27 
     28 /// Handle backend options that are encoded in the executable name.
     29 ///
     30 /// Parses some common backend options out of a specially crafted executable
     31 /// name (argv[0]). For example, a name like llvm-foo-fuzzer--aarch64-gisel
     32 /// might set up an AArch64 triple and the Global ISel selector. This should be
     33 /// called *before* parseFuzzerCLOpts if calling both.
     34 ///
     35 /// This is meant to be used for environments like OSS-Fuzz that aren't capable
     36 /// of passing in command line arguments in the normal way.
     37 void handleExecNameEncodedBEOpts(StringRef ExecName);
     38 
     39 using FuzzerTestFun = int (*)(const uint8_t *Data, size_t Size);
     40 using FuzzerInitFun = int (*)(int *argc, char ***argv);
     41 
     42 /// Runs a fuzz target on the inputs specified on the command line.
     43 ///
     44 /// Useful for testing fuzz targets without linking to libFuzzer. Finds inputs
     45 /// in the argument list in a libFuzzer compatible way.
     46 int runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne,
     47                       FuzzerInitFun Init = [](int *, char ***) { return 0; });
     48 
     49 } // end llvm namespace
     50 
     51 #endif // LLVM_FUZZMUTATE_FUZZER_CLI_H
     52