Path: blob/main/contrib/llvm-project/compiler-rt/lib/nsan/nsan_stats.h
35233 views
//===-- nsan_stats.h --------------------------------------------*- C++- *-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of NumericalStabilitySanitizer.9//10// NSan statistics. This class counts the number of checks per code location,11// and is used to output statistics (typically when using12// `disable_warnings=1,enable_check_stats=1,enable_warning_stats=1`).13//===----------------------------------------------------------------------===//1415#ifndef NSAN_STATS_H16#define NSAN_STATS_H1718#include "sanitizer_common/sanitizer_addrhashmap.h"19#include "sanitizer_common/sanitizer_internal_defs.h"20#include "sanitizer_common/sanitizer_mutex.h"2122namespace __nsan {2324enum class CheckTypeT {25kUnknown = 0,26kRet,27kArg,28kLoad,29kStore,30kInsert,31kUser, // User initiated.32kFcmp,33kMaxCheckType,34};3536class Stats {37public:38Stats();39~Stats();4041// Signal that we checked the instruction at the given address.42void AddCheck(CheckTypeT check_ty, __sanitizer::uptr pc, __sanitizer::uptr bp,43double rel_err);44// Signal that we warned for the instruction at the given address.45void AddWarning(CheckTypeT check_ty, __sanitizer::uptr pc,46__sanitizer::uptr bp, double rel_err);4748// Signal that we detected a floating-point load where the shadow type was49// invalid.50void AddInvalidLoadTrackingEvent(__sanitizer::uptr pc, __sanitizer::uptr bp);51// Signal that we detected a floating-point load where the shadow type was52// unknown but the value was nonzero.53void AddUnknownLoadTrackingEvent(__sanitizer::uptr pc, __sanitizer::uptr bp);5455void Print() const;5657private:58using IndexMap = __sanitizer::AddrHashMap<__sanitizer::uptr, 11>;5960struct CheckAndWarningsValue {61CheckTypeT check_ty;62__sanitizer::u32 stack_id = 0;63__sanitizer::u64 num_checks = 0;64__sanitizer::u64 num_warnings = 0;65// This is a bitcasted double. Doubles have the nice idea to be ordered as66// ints.67double max_relative_err = 0;68};69// Map Key(check_ty, StackId) to indices in CheckAndWarnings.70IndexMap CheckAndWarningsMap;71__sanitizer::InternalMmapVectorNoCtor<CheckAndWarningsValue>72check_and_warnings;73mutable __sanitizer::Mutex check_and_warning_mutex;7475struct LoadTrackingValue {76CheckTypeT check_ty;77__sanitizer::u32 stack_id = 0;78__sanitizer::u64 num_invalid = 0;79__sanitizer::u64 num_unknown = 0;80};81// Map Key(CheckTypeT::kLoad, StackId) to indices in TrackedLoads.82IndexMap LoadTrackingMap;83__sanitizer::InternalMmapVectorNoCtor<LoadTrackingValue> TrackedLoads;84mutable __sanitizer::Mutex TrackedLoadsMutex;85};8687extern Stats *nsan_stats;88void InitializeStats();8990} // namespace __nsan9192#endif // NSAN_STATS_H939495