Home | History | Annotate | Download | only in sanitizer_common
      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 #ifndef SANITIZER_STACKDEPOT_H
     14 #define SANITIZER_STACKDEPOT_H
     15 
     16 #include "sanitizer_common.h"
     17 #include "sanitizer_internal_defs.h"
     18 
     19 namespace __sanitizer {
     20 
     21 // StackDepot efficiently stores huge amounts of stack traces.
     22 struct StackDepotNode;
     23 struct StackDepotHandle {
     24   StackDepotNode *node_;
     25   StackDepotHandle() : node_(0) {}
     26   explicit StackDepotHandle(StackDepotNode *node) : node_(node) {}
     27   bool valid() { return node_; }
     28   u32 id();
     29   int use_count();
     30   void inc_use_count_unsafe();
     31   uptr size();
     32   uptr *stack();
     33 };
     34 
     35 const int kStackDepotMaxUseCount = 1U << 20;
     36 
     37 StackDepotStats *StackDepotGetStats();
     38 u32 StackDepotPut(const uptr *stack, uptr size);
     39 StackDepotHandle StackDepotPut_WithHandle(const uptr *stack, uptr size);
     40 // Retrieves a stored stack trace by the id.
     41 const uptr *StackDepotGet(u32 id, uptr *size);
     42 
     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 {
     48  public:
     49   StackDepotReverseMap();
     50   const uptr *Get(u32 id, uptr *size);
     51 
     52  private:
     53   struct IdDescPair {
     54     u32 id;
     55     StackDepotNode *desc;
     56 
     57     static bool IdComparator(const IdDescPair &a, const IdDescPair &b);
     58   };
     59 
     60   InternalMmapVector<IdDescPair> map_;
     61 
     62   // Disallow evil constructors.
     63   StackDepotReverseMap(const StackDepotReverseMap&);
     64   void operator=(const StackDepotReverseMap&);
     65 };
     66 
     67 }  // namespace __sanitizer
     68 
     69 #endif  // SANITIZER_STACKDEPOT_H
     70