]>
Commit | Line | Data |
---|---|---|
f35db108 WM |
1 | //===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===// |
2 | // | |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
f35db108 WM |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is shared between AddressSanitizer and ThreadSanitizer | |
10 | // run-time libraries. | |
11 | //===----------------------------------------------------------------------===// | |
696d846a | 12 | |
f35db108 WM |
13 | #ifndef SANITIZER_STACKDEPOT_H |
14 | #define SANITIZER_STACKDEPOT_H | |
15 | ||
ef1b3fda | 16 | #include "sanitizer_common.h" |
b4ab7d34 | 17 | #include "sanitizer_internal_defs.h" |
c5be964a | 18 | #include "sanitizer_stacktrace.h" |
f35db108 WM |
19 | |
20 | namespace __sanitizer { | |
21 | ||
22 | // StackDepot efficiently stores huge amounts of stack traces. | |
866e32ad KS |
23 | struct StackDepotNode; |
24 | struct StackDepotHandle { | |
25 | StackDepotNode *node_; | |
696d846a | 26 | StackDepotHandle() : node_(nullptr) {} |
866e32ad KS |
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(); | |
866e32ad KS |
32 | }; |
33 | ||
b667dd70 | 34 | const int kStackDepotMaxUseCount = 1U << (SANITIZER_ANDROID ? 16 : 20); |
f35db108 | 35 | |
866e32ad | 36 | StackDepotStats *StackDepotGetStats(); |
c5be964a KS |
37 | u32 StackDepotPut(StackTrace stack); |
38 | StackDepotHandle StackDepotPut_WithHandle(StackTrace stack); | |
f35db108 | 39 | // Retrieves a stored stack trace by the id. |
c5be964a | 40 | StackTrace StackDepotGet(u32 id); |
f35db108 | 41 | |
866e32ad KS |
42 | void StackDepotLockAll(); |
43 | void StackDepotUnlockAll(); | |
0b997f6e | 44 | void StackDepotPrintAll(); |
ef1b3fda KS |
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(); | |
c5be964a | 53 | StackTrace Get(u32 id); |
ef1b3fda KS |
54 | |
55 | private: | |
56 | struct IdDescPair { | |
57 | u32 id; | |
866e32ad | 58 | StackDepotNode *desc; |
ef1b3fda KS |
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 | }; | |
866e32ad | 69 | |
696d846a | 70 | } // namespace __sanitizer |
f35db108 | 71 | |
696d846a | 72 | #endif // SANITIZER_STACKDEPOT_H |