Clean up some minor white space issues in trans-decl.c and trans-expr.c
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_libignore.h
blob84419d14fed9aa2ba90f408c56449fbc061c1f1f
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 can be initialized with several templates
10 // of names of libraries to be ignored. It 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_atomic.h"
21 #include "sanitizer_mutex.h"
23 namespace __sanitizer {
25 class LibIgnore {
26 public:
27 explicit LibIgnore(LinkerInitialized);
29 // Must be called during initialization.
30 void AddIgnoredLibrary(const char *name_templ);
32 // Must be called after a new dynamic library is loaded.
33 void OnLibraryLoaded(const char *name);
35 // Must be called after a dynamic library is unloaded.
36 void OnLibraryUnloaded();
38 // Checks whether the provided PC belongs to one of the ignored libraries.
39 bool IsIgnored(uptr pc) const;
41 private:
42 struct Lib {
43 char *templ;
44 char *name;
45 char *real_name; // target of symlink
46 bool loaded;
49 struct LibCodeRange {
50 uptr begin;
51 uptr end;
54 static const uptr kMaxLibs = 128;
56 // Hot part:
57 atomic_uintptr_t loaded_count_;
58 LibCodeRange code_ranges_[kMaxLibs];
60 // Cold part:
61 BlockingMutex mutex_;
62 uptr count_;
63 Lib libs_[kMaxLibs];
65 // Disallow copying of LibIgnore objects.
66 LibIgnore(const LibIgnore&); // not implemented
67 void operator = (const LibIgnore&); // not implemented
70 inline bool LibIgnore::IsIgnored(uptr pc) const {
71 const uptr n = atomic_load(&loaded_count_, memory_order_acquire);
72 for (uptr i = 0; i < n; i++) {
73 if (pc >= code_ranges_[i].begin && pc < code_ranges_[i].end)
74 return true;
76 return false;
79 } // namespace __sanitizer
81 #endif // SANITIZER_LIBIGNORE_H