1 /* based on http://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/fuzzer/FuzzerInterface.h r321218 (20 Dec 2017) */
2 
3 /* http://llvm.org/svn/llvm-project/compiler-rt/trunk/LICENSE.TXT follows */
4 
5 /*
6 ==============================================================================
7 compiler_rt License
8 ==============================================================================
9 
10 The compiler_rt library is dual licensed under both the University of Illinois
11 "BSD-Like" license and the MIT license.  As a user of this code you may choose
12 to use it under either license.  As a contributor, you agree to allow your code
13 to be used under both.
14 
15 Full text of the relevant licenses is included below.
16 
17 ==============================================================================
18 
19 University of Illinois/NCSA
20 Open Source License
21 
22 Copyright (c) 2009-2016 by the contributors listed in CREDITS.TXT
23 
24 All rights reserved.
25 
26 Developed by:
27 
28     LLVM Team
29 
30     University of Illinois at Urbana-Champaign
31 
32     http://llvm.org
33 
34 Permission is hereby granted, free of charge, to any person obtaining a copy of
35 this software and associated documentation files (the "Software"), to deal with
36 the Software without restriction, including without limitation the rights to
37 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 of the Software, and to permit persons to whom the Software is furnished to do
39 so, subject to the following conditions:
40 
41     * Redistributions of source code must retain the above copyright notice,
42       this list of conditions and the following disclaimers.
43 
44     * Redistributions in binary form must reproduce the above copyright notice,
45       this list of conditions and the following disclaimers in the
46       documentation and/or other materials provided with the distribution.
47 
48     * Neither the names of the LLVM Team, University of Illinois at
49       Urbana-Champaign, nor the names of its contributors may be used to
50       endorse or promote products derived from this Software without specific
51       prior written permission.
52 
53 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
55 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
56 CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
59 SOFTWARE.
60 
61 ==============================================================================
62 
63 Copyright (c) 2009-2015 by the contributors listed in CREDITS.TXT
64 
65 SPDX-License-Identifier: MIT
66 
67 ==============================================================================
68 Copyrights and Licenses for Third Party Software Distributed with LLVM:
69 ==============================================================================
70 The LLVM software contains code written by third parties.  Such software will
71 have its own individual LICENSE.TXT file in the directory in which it appears.
72 This file will describe the copyrights, license, and restrictions which apply
73 to that code.
74 
75 The disclaimer of warranty in the University of Illinois Open Source License
76 applies to all code in the LLVM Distribution, and nothing in any of the
77 other licenses gives permission to use the names of the LLVM Team or the
78 University of Illinois to endorse or promote products derived from this
79 Software.
80 */
81 //===- FuzzerInterface.h - Interface header for the Fuzzer ------*- C++ -* ===//
82 //
83 //                     The LLVM Compiler Infrastructure
84 //
85 // This file is distributed under the University of Illinois Open Source
86 // License. See LICENSE.TXT for details.
87 //
88 //===----------------------------------------------------------------------===//
89 // Define the interface between libFuzzer and the library being tested.
90 //===----------------------------------------------------------------------===//
91 
92 // NOTE: the libFuzzer interface is thin and in the majority of cases
93 // you should not include this file into your target. In 95% of cases
94 // all you need is to define the following function in your file:
95 // extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
96 
97 // WARNING: keep the interface in C.
98 
99 #ifndef LLVM_FUZZER_INTERFACE_H
100 #define LLVM_FUZZER_INTERFACE_H
101 
102 #include <stddef.h>
103 #include <stdint.h>
104 
105 #ifdef __cplusplus
106 extern "C" {
107 #endif  // __cplusplus
108 
109 // Mandatory user-provided target function.
110 // Executes the code under test with [Data, Data+Size) as the input.
111 // libFuzzer will invoke this function *many* times with different inputs.
112 // Must return 0.
113 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
114 
115 // Optional user-provided initialization function.
116 // If provided, this function will be called by libFuzzer once at startup.
117 // It may read and modify argc/argv.
118 // Must return 0.
119 int LLVMFuzzerInitialize(int *argc, char ***argv);
120 
121 // Optional user-provided custom mutator.
122 // Mutates raw data in [Data, Data+Size) inplace.
123 // Returns the new size, which is not greater than MaxSize.
124 // Given the same Seed produces the same mutation.
125 size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,
126                                unsigned int Seed);
127 
128 // Optional user-provided custom cross-over function.
129 // Combines pieces of Data1 & Data2 together into Out.
130 // Returns the new size, which is not greater than MaxOutSize.
131 // Should produce the same mutation given the same Seed.
132 size_t LLVMFuzzerCustomCrossOver(const uint8_t *Data1, size_t Size1,
133                                  const uint8_t *Data2, size_t Size2,
134                                  uint8_t *Out, size_t MaxOutSize,
135                                  unsigned int Seed);
136 
137 // Experimental, may go away in future.
138 // libFuzzer-provided function to be used inside LLVMFuzzerCustomMutator.
139 // Mutates raw data in [Data, Data+Size) inplace.
140 // Returns the new size, which is not greater than MaxSize.
141 size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);
142 
143 #ifdef __cplusplus
144 }  // extern "C"
145 #endif  // __cplusplus
146 
147 #endif  // LLVM_FUZZER_INTERFACE_H
148