sanitizer_stackdepot.h 2.0 KB

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