dfsan.h revision 2d1fdb26e458c4ddc04155c1d421bced3ba90cd0
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.
21typedef u16 dfsan_label;
22
23struct dfsan_label_info {
24  dfsan_label l1;
25  dfsan_label l2;
26  const char *desc;
27  void *userdata;
28};
29
30extern "C" {
31void dfsan_set_label(dfsan_label label, void *addr, uptr size);
32dfsan_label dfsan_read_label(const void *addr, uptr size);
33dfsan_label dfsan_union(dfsan_label l1, dfsan_label l2);
34}  // extern "C"
35
36template <typename T>
37void dfsan_set_label(dfsan_label label, T &data) {  // NOLINT
38  dfsan_set_label(label, (void *)&data, sizeof(T));
39}
40
41namespace __dfsan {
42
43void InitializeInterceptors();
44
45inline dfsan_label *shadow_for(void *ptr) {
46  return (dfsan_label *) ((((uptr) ptr) & ~0x700000000000) << 1);
47}
48
49inline const dfsan_label *shadow_for(const void *ptr) {
50  return shadow_for(const_cast<void *>(ptr));
51}
52
53struct Flags {
54  // Whether to warn on unimplemented functions.
55  bool warn_unimplemented;
56  // Whether to warn on non-zero labels.
57  bool warn_nonzero_labels;
58  // Whether to propagate labels only when there is an obvious data dependency
59  // (e.g., when comparing strings, ignore the fact that the output of the
60  // comparison might be data-dependent on the content of the strings). This
61  // applies only to the custom functions defined in 'custom.c'.
62  bool strict_data_dependencies;
63};
64
65extern Flags flags_data;
66inline Flags &flags() {
67  return flags_data;
68}
69
70}  // namespace __dfsan
71
72#endif  // DFSAN_H
73