]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/dfsan/dfsan.h
Reintegrate head revisions r273096-r277147
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / dfsan / dfsan.h
1 //===-- dfsan.h -------------------------------------------------*- 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 //
10 // This file is a part of DataFlowSanitizer.
11 //
12 // Private DFSan header.
13 //===----------------------------------------------------------------------===//
14
15 #ifndef DFSAN_H
16 #define DFSAN_H
17
18 #include "sanitizer_common/sanitizer_internal_defs.h"
19
20 // Copy declarations from public sanitizer/dfsan_interface.h header here.
21 typedef u16 dfsan_label;
22
23 struct dfsan_label_info {
24   dfsan_label l1;
25   dfsan_label l2;
26   const char *desc;
27   void *userdata;
28 };
29
30 extern "C" {
31 void dfsan_add_label(dfsan_label label, void *addr, uptr size);
32 void dfsan_set_label(dfsan_label label, void *addr, uptr size);
33 dfsan_label dfsan_read_label(const void *addr, uptr size);
34 dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
35 }  // extern "C"
36
37 template <typename T>
38 void dfsan_set_label(dfsan_label label, T &data) {  // NOLINT
39   dfsan_set_label(label, (void *)&data, sizeof(T));
40 }
41
42 namespace __dfsan {
43
44 void InitializeInterceptors();
45
46 inline dfsan_label *shadow_for(void *ptr) {
47 #if defined(__x86_64__)
48   return (dfsan_label *) ((((uptr) ptr) & ~0x700000000000) << 1);
49 #elif defined(__mips64)
50   return (dfsan_label *) ((((uptr) ptr) & ~0xF000000000) << 1);
51 #endif
52 }
53
54 inline const dfsan_label *shadow_for(const void *ptr) {
55   return shadow_for(const_cast<void *>(ptr));
56 }
57
58 struct Flags {
59   // Whether to warn on unimplemented functions.
60   bool warn_unimplemented;
61   // Whether to warn on non-zero labels.
62   bool warn_nonzero_labels;
63   // Whether to propagate labels only when there is an obvious data dependency
64   // (e.g., when comparing strings, ignore the fact that the output of the
65   // comparison might be data-dependent on the content of the strings). This
66   // applies only to the custom functions defined in 'custom.c'.
67   bool strict_data_dependencies;
68   // The path of the file where to dump the labels when the program terminates.
69   const char* dump_labels_at_exit;
70 };
71
72 extern Flags flags_data;
73 inline Flags &flags() {
74   return flags_data;
75 }
76
77 }  // namespace __dfsan
78
79 #endif  // DFSAN_H