]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h
MFV: r283965
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / lib / sanitizer_common / sanitizer_stackdepot.h
1 //===-- sanitizer_stackdepot.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 shared between AddressSanitizer and ThreadSanitizer
11 // run-time libraries.
12 //===----------------------------------------------------------------------===//
13 #ifndef SANITIZER_STACKDEPOT_H
14 #define SANITIZER_STACKDEPOT_H
15
16 #include "sanitizer_common.h"
17 #include "sanitizer_internal_defs.h"
18 #include "sanitizer_stacktrace.h"
19
20 namespace __sanitizer {
21
22 // StackDepot efficiently stores huge amounts of stack traces.
23 struct StackDepotNode;
24 struct StackDepotHandle {
25   StackDepotNode *node_;
26   StackDepotHandle() : node_(0) {}
27   explicit StackDepotHandle(StackDepotNode *node) : node_(node) {}
28   bool valid() { return node_; }
29   u32 id();
30   int use_count();
31   void inc_use_count_unsafe();
32 };
33
34 const int kStackDepotMaxUseCount = 1U << 20;
35
36 StackDepotStats *StackDepotGetStats();
37 u32 StackDepotPut(StackTrace stack);
38 StackDepotHandle StackDepotPut_WithHandle(StackTrace stack);
39 // Retrieves a stored stack trace by the id.
40 StackTrace StackDepotGet(u32 id);
41
42 void StackDepotLockAll();
43 void StackDepotUnlockAll();
44
45 // Instantiating this class creates a snapshot of StackDepot which can be
46 // efficiently queried with StackDepotGet(). You can use it concurrently with
47 // StackDepot, but the snapshot is only guaranteed to contain those stack traces
48 // which were stored before it was instantiated.
49 class StackDepotReverseMap {
50  public:
51   StackDepotReverseMap();
52   StackTrace Get(u32 id);
53
54  private:
55   struct IdDescPair {
56     u32 id;
57     StackDepotNode *desc;
58
59     static bool IdComparator(const IdDescPair &a, const IdDescPair &b);
60   };
61
62   InternalMmapVector<IdDescPair> map_;
63
64   // Disallow evil constructors.
65   StackDepotReverseMap(const StackDepotReverseMap&);
66   void operator=(const StackDepotReverseMap&);
67 };
68
69 }  // namespace __sanitizer
70
71 #endif  // SANITIZER_STACKDEPOT_H