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