FuzzerInterface.h 3.1 KB

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