[AArch64] Add cost handling of CALLER_SAVE_REGS and POINTER_REGS
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_libignore.h
blob2089c4bbeeb44341ca67d75a07ba377c28532502
1 //===-- sanitizer_libignore.h -----------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // LibIgnore allows to ignore all interceptors called from a particular set
9 // of dynamic libraries. LibIgnore remembers all "called_from_lib" suppressions
10 // from the provided SuppressionContext; finds code ranges for the libraries;
11 // and checks whether the provided PC value belongs to the code ranges.
13 //===----------------------------------------------------------------------===//
15 #ifndef SANITIZER_LIBIGNORE_H
16 #define SANITIZER_LIBIGNORE_H
18 #include "sanitizer_internal_defs.h"
19 #include "sanitizer_common.h"
20 #include "sanitizer_suppressions.h"
21 #include "sanitizer_atomic.h"
22 #include "sanitizer_mutex.h"
24 namespace __sanitizer {
26 class LibIgnore {
27 public:
28 explicit LibIgnore(LinkerInitialized);
30 // Fetches all "called_from_lib" suppressions from the SuppressionContext.
31 void Init(const SuppressionContext &supp);
33 // Must be called after a new dynamic library is loaded.
34 void OnLibraryLoaded(const char *name);
36 // Must be called after a dynamic library is unloaded.
37 void OnLibraryUnloaded();
39 // Checks whether the provided PC belongs to one of the ignored libraries.
40 bool IsIgnored(uptr pc) const;
42 private:
43 struct Lib {
44 char *templ;
45 char *name;
46 char *real_name; // target of symlink
47 bool loaded;
50 struct LibCodeRange {
51 uptr begin;
52 uptr end;
55 static const uptr kMaxLibs = 128;
57 // Hot part:
58 atomic_uintptr_t loaded_count_;
59 LibCodeRange code_ranges_[kMaxLibs];
61 // Cold part:
62 BlockingMutex mutex_;
63 uptr count_;
64 Lib libs_[kMaxLibs];
66 // Disallow copying of LibIgnore objects.
67 LibIgnore(const LibIgnore&); // not implemented
68 void operator = (const LibIgnore&); // not implemented
71 inline bool LibIgnore::IsIgnored(uptr pc) const {
72 const uptr n = atomic_load(&loaded_count_, memory_order_acquire);
73 for (uptr i = 0; i < n; i++) {
74 if (pc >= code_ranges_[i].begin && pc < code_ranges_[i].end)
75 return true;
77 return false;
80 } // namespace __sanitizer
82 #endif // SANITIZER_LIBIGNORE_H