File: nsan_stats.h

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,999,616 kB
  • sloc: cpp: 6,951,724; ansic: 1,486,157; asm: 913,598; python: 232,059; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,079; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,430; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (93 lines) | stat: -rw-r--r-- 2,990 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//===-- nsan_stats.h --------------------------------------------*- C++- *-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is a part of NumericalStabilitySanitizer.
//
// NSan statistics. This class counts the number of checks per code location,
// and is used to output statistics (typically when using
// `disable_warnings=1,enable_check_stats=1,enable_warning_stats=1`).
//===----------------------------------------------------------------------===//

#ifndef NSAN_STATS_H
#define NSAN_STATS_H

#include "sanitizer_common/sanitizer_addrhashmap.h"
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_mutex.h"

namespace __nsan {

enum class CheckTypeT {
  kUnknown = 0,
  kRet,
  kArg,
  kLoad,
  kStore,
  kInsert,
  kUser, // User initiated.
  kFcmp,
  kMaxCheckType,
};

class Stats {
public:
  Stats();
  ~Stats();

  // Signal that we checked the instruction at the given address.
  void AddCheck(CheckTypeT check_ty, __sanitizer::uptr pc, __sanitizer::uptr bp,
                double rel_err);
  // Signal that we warned for the instruction at the given address.
  void AddWarning(CheckTypeT check_ty, __sanitizer::uptr pc,
                  __sanitizer::uptr bp, double rel_err);

  // Signal that we detected a floating-point load where the shadow type was
  // invalid.
  void AddInvalidLoadTrackingEvent(__sanitizer::uptr pc, __sanitizer::uptr bp);
  // Signal that we detected a floating-point load where the shadow type was
  // unknown but the value was nonzero.
  void AddUnknownLoadTrackingEvent(__sanitizer::uptr pc, __sanitizer::uptr bp);

  void Print() const;

private:
  using IndexMap = __sanitizer::AddrHashMap<__sanitizer::uptr, 11>;

  struct CheckAndWarningsValue {
    CheckTypeT check_ty;
    __sanitizer::u32 stack_id = 0;
    __sanitizer::u64 num_checks = 0;
    __sanitizer::u64 num_warnings = 0;
    // This is a bitcasted double. Doubles have the nice idea to be ordered as
    // ints.
    double max_relative_err = 0;
  };
  // Map Key(check_ty, StackId) to indices in CheckAndWarnings.
  IndexMap CheckAndWarningsMap;
  __sanitizer::InternalMmapVectorNoCtor<CheckAndWarningsValue>
      check_and_warnings;
  mutable __sanitizer::Mutex check_and_warning_mutex;

  struct LoadTrackingValue {
    CheckTypeT check_ty;
    __sanitizer::u32 stack_id = 0;
    __sanitizer::u64 num_invalid = 0;
    __sanitizer::u64 num_unknown = 0;
  };
  // Map Key(CheckTypeT::kLoad, StackId) to indices in TrackedLoads.
  IndexMap LoadTrackingMap;
  __sanitizer::InternalMmapVectorNoCtor<LoadTrackingValue> TrackedLoads;
  mutable __sanitizer::Mutex TrackedLoadsMutex;
};

extern Stats *nsan_stats;
void InitializeStats();

} // namespace __nsan

#endif // NSAN_STATS_H