• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 #ifndef SANITIZER_STACKDEPOT_H
15 #define SANITIZER_STACKDEPOT_H
16 
17 #include "sanitizer_common.h"
18 #include "sanitizer_internal_defs.h"
19 #include "sanitizer_stacktrace.h"
20 
21 namespace __sanitizer {
22 
23 // StackDepot efficiently stores huge amounts of stack traces.
24 struct StackDepotNode;
25 struct StackDepotHandle {
26   StackDepotNode *node_;
StackDepotHandleStackDepotHandle27   StackDepotHandle() : node_(nullptr) {}
StackDepotHandleStackDepotHandle28   explicit StackDepotHandle(StackDepotNode *node) : node_(node) {}
validStackDepotHandle29   bool valid() { return node_; }
30   u32 id();
31   int use_count();
32   void inc_use_count_unsafe();
33 };
34 
35 const int kStackDepotMaxUseCount = 1U << 20;
36 
37 StackDepotStats *StackDepotGetStats();
38 u32 StackDepotPut(StackTrace stack);
39 StackDepotHandle StackDepotPut_WithHandle(StackTrace stack);
40 // Retrieves a stored stack trace by the id.
41 StackTrace StackDepotGet(u32 id);
42 
43 void StackDepotLockAll();
44 void StackDepotUnlockAll();
45 
46 // Instantiating this class creates a snapshot of StackDepot which can be
47 // efficiently queried with StackDepotGet(). You can use it concurrently with
48 // StackDepot, but the snapshot is only guaranteed to contain those stack traces
49 // which were stored before it was instantiated.
50 class StackDepotReverseMap {
51  public:
52   StackDepotReverseMap();
53   StackTrace Get(u32 id);
54 
55  private:
56   struct IdDescPair {
57     u32 id;
58     StackDepotNode *desc;
59 
60     static bool IdComparator(const IdDescPair &a, const IdDescPair &b);
61   };
62 
63   InternalMmapVector<IdDescPair> map_;
64 
65   // Disallow evil constructors.
66   StackDepotReverseMap(const StackDepotReverseMap&);
67   void operator=(const StackDepotReverseMap&);
68 };
69 
70 } // namespace __sanitizer
71 
72 #endif // SANITIZER_STACKDEPOT_H
73