1 //===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is shared between AddressSanitizer and ThreadSanitizer
11 // run-time libraries.
12 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_STACKDEPOT_H
15 #define SANITIZER_STACKDEPOT_H
17 #include "sanitizer_common.h"
18 #include "sanitizer_internal_defs.h"
19 #include "sanitizer_stacktrace.h"
21 namespace __sanitizer {
23 // StackDepot efficiently stores huge amounts of stack traces.
24 struct StackDepotNode;
25 struct StackDepotHandle {
26 StackDepotNode *node_;
27 StackDepotHandle() : node_(nullptr) {}
28 explicit StackDepotHandle(StackDepotNode *node) : node_(node) {}
29 bool valid() { return node_; }
32 void inc_use_count_unsafe();
35 const int kStackDepotMaxUseCount = 1U << 20;
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);
43 void StackDepotLockAll();
44 void StackDepotUnlockAll();
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 {
52 StackDepotReverseMap();
53 StackTrace Get(u32 id);
60 static bool IdComparator(const IdDescPair &a, const IdDescPair &b);
63 InternalMmapVector<IdDescPair> map_;
65 // Disallow evil constructors.
66 StackDepotReverseMap(const StackDepotReverseMap&);
67 void operator=(const StackDepotReverseMap&);
70 } // namespace __sanitizer
72 #endif // SANITIZER_STACKDEPOT_H