• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- FuzzerDFSan.h - Internal header for the Fuzzer -----------*- 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 // DFSan interface.
10 //===----------------------------------------------------------------------===//
11 
12 #ifndef LLVM_FUZZER_DFSAN_H
13 #define LLVM_FUZZER_DFSAN_H
14 
15 #define LLVM_FUZZER_SUPPORTS_DFSAN 0
16 #if defined(__has_include)
17 # if __has_include(<sanitizer/dfsan_interface.h>)
18 #  if defined (__linux__)
19 #   undef LLVM_FUZZER_SUPPORTS_DFSAN
20 #   define LLVM_FUZZER_SUPPORTS_DFSAN 1
21 #   include <sanitizer/dfsan_interface.h>
22 #  endif  // __linux__
23 # endif
24 #endif  // defined(__has_include)
25 
26 #if LLVM_FUZZER_SUPPORTS_DFSAN
27 
28 extern "C" {
29 __attribute__((weak))
30 dfsan_label dfsan_create_label(const char *desc, void *userdata);
31 __attribute__((weak))
32 void dfsan_set_label(dfsan_label label, void *addr, size_t size);
33 __attribute__((weak))
34 void dfsan_add_label(dfsan_label label, void *addr, size_t size);
35 __attribute__((weak))
36 const struct dfsan_label_info *dfsan_get_label_info(dfsan_label label);
37 __attribute__((weak))
38 dfsan_label dfsan_read_label(const void *addr, size_t size);
39 }  // extern "C"
40 
41 namespace fuzzer {
ReallyHaveDFSan()42 static bool ReallyHaveDFSan() {
43   return &dfsan_create_label != nullptr;
44 }
45 }  // namespace fuzzer
46 #else
47 // When compiling with a compiler which does not support dfsan,
48 // this code is still expected to build (but not necessary work).
49 typedef unsigned short dfsan_label;
50 struct dfsan_label_info {
51   dfsan_label l1, l2;
52   const char *desc;
53   void *userdata;
54 };
55 namespace fuzzer {
ReallyHaveDFSan()56 static bool ReallyHaveDFSan() { return false; }
57 }  // namespace fuzzer
58 
59 #endif
60 
61 #endif // LLVM_FUZZER_DFSAN_H
62