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"
17 namespace __sanitizer
{
19 // StackDepot efficiently stores huge amounts of stack traces.
20 struct StackDepotNode
;
21 struct StackDepotHandle
{
22 StackDepotNode
*node_
;
23 StackDepotHandle() : node_(0) {}
24 explicit StackDepotHandle(StackDepotNode
*node
) : node_(node
) {}
25 bool valid() { return node_
; }
28 void inc_use_count_unsafe();
33 const int kStackDepotMaxUseCount
= 1U << 20;
35 StackDepotStats
*StackDepotGetStats();
36 u32
StackDepotPut(const uptr
*stack
, uptr size
);
37 StackDepotHandle
StackDepotPut_WithHandle(const uptr
*stack
, uptr size
);
38 // Retrieves a stored stack trace by the id.
39 const uptr
*StackDepotGet(u32 id
, uptr
*size
);
41 void StackDepotLockAll();
42 void StackDepotUnlockAll();
44 // Instantiating this class creates a snapshot of StackDepot which can be
45 // efficiently queried with StackDepotGet(). You can use it concurrently with
46 // StackDepot, but the snapshot is only guaranteed to contain those stack traces
47 // which were stored before it was instantiated.
48 class StackDepotReverseMap
{
50 StackDepotReverseMap();
51 const uptr
*Get(u32 id
, uptr
*size
);
58 static bool IdComparator(const IdDescPair
&a
, const IdDescPair
&b
);
61 InternalMmapVector
<IdDescPair
> map_
;
63 // Disallow evil constructors.
64 StackDepotReverseMap(const StackDepotReverseMap
&);
65 void operator=(const StackDepotReverseMap
&);
68 } // namespace __sanitizer
70 #endif // SANITIZER_STACKDEPOT_H