Imported Upstream version 2.6.1
[platform/upstream/cryptsetup.git] / tests / fuzz / FuzzerInterface.h
1 // Based on https://github.com/llvm-mirror/compiler-rt/blob/master/lib/fuzzer/FuzzerInterface.h
2 //
3 //===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===//
4 //
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
8 //
9 //===----------------------------------------------------------------------===//
10 // Define the interface between libFuzzer and the library being tested.
11 //===----------------------------------------------------------------------===//
12
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);
17
18 // WARNING: keep the interface in C.
19
20 #ifndef LLVM_FUZZER_INTERFACE_H
21 #define LLVM_FUZZER_INTERFACE_H
22
23 #include <stddef.h>
24 #include <stdint.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif  // __cplusplus
29
30 // Define FUZZER_INTERFACE_VISIBILITY to set default visibility in a way that
31 // doesn't break MSVC.
32 #if defined(_WIN32)
33 #define FUZZER_INTERFACE_VISIBILITY __declspec(dllexport)
34 #else
35 #define FUZZER_INTERFACE_VISIBILITY __attribute__((visibility("default")))
36 #endif
37
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.
41 // Must return 0.
42 FUZZER_INTERFACE_VISIBILITY int
43 LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
44
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.
48 // Must return 0.
49 FUZZER_INTERFACE_VISIBILITY int LLVMFuzzerInitialize(int *argc, char ***argv);
50
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,
57                         unsigned int Seed);
58
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);
67
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);
74
75 #undef FUZZER_INTERFACE_VISIBILITY
76
77 #ifdef __cplusplus
78 }  // extern "C"
79 #endif  // __cplusplus
80
81 #endif  // LLVM_FUZZER_INTERFACE_H