1 //===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is shared between AddressSanitizer and ThreadSanitizer
10 //===----------------------------------------------------------------------===//
11 #ifndef SANITIZER_STACKDEPOT_H
12 #define SANITIZER_STACKDEPOT_H
14 #include "sanitizer_common.h"
15 #include "sanitizer_internal_defs.h"
16 #include "sanitizer_stacktrace.h"
18 namespace __sanitizer
{
20 // StackDepot efficiently stores huge amounts of stack traces.
21 struct StackDepotNode
;
22 struct StackDepotHandle
{
23 StackDepotNode
*node_
;
24 StackDepotHandle() : node_(0) {}
25 explicit StackDepotHandle(StackDepotNode
*node
) : node_(node
) {}
26 bool valid() { return node_
; }
29 void inc_use_count_unsafe();
32 const int kStackDepotMaxUseCount
= 1U << 20;
34 StackDepotStats
*StackDepotGetStats();
35 u32
StackDepotPut(StackTrace stack
);
36 StackDepotHandle
StackDepotPut_WithHandle(StackTrace stack
);
37 // Retrieves a stored stack trace by the id.
38 StackTrace
StackDepotGet(u32 id
);
40 void StackDepotLockAll();
41 void StackDepotUnlockAll();
43 // Instantiating this class creates a snapshot of StackDepot which can be
44 // efficiently queried with StackDepotGet(). You can use it concurrently with
45 // StackDepot, but the snapshot is only guaranteed to contain those stack traces
46 // which were stored before it was instantiated.
47 class StackDepotReverseMap
{
49 StackDepotReverseMap();
50 StackTrace
Get(u32 id
);
57 static bool IdComparator(const IdDescPair
&a
, const IdDescPair
&b
);
60 InternalMmapVector
<IdDescPair
> map_
;
62 // Disallow evil constructors.
63 StackDepotReverseMap(const StackDepotReverseMap
&);
64 void operator=(const StackDepotReverseMap
&);
67 } // namespace __sanitizer
69 #endif // SANITIZER_STACKDEPOT_H