2012-11-12 16:53:47 +01:00
|
|
|
//===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-08-14 10:47:11 +02:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-11-12 16:53:47 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer
|
|
|
|
// run-time libraries.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
#ifndef SANITIZER_STACKDEPOT_H
|
|
|
|
#define SANITIZER_STACKDEPOT_H
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "sanitizer_common.h"
|
2013-02-13 11:46:01 +01:00
|
|
|
#include "sanitizer_internal_defs.h"
|
2014-11-13 21:41:38 +01:00
|
|
|
#include "sanitizer_stacktrace.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
// StackDepot efficiently stores huge amounts of stack traces.
|
2014-09-23 19:59:53 +02:00
|
|
|
struct StackDepotNode;
|
|
|
|
struct StackDepotHandle {
|
|
|
|
StackDepotNode *node_;
|
2015-10-21 09:32:45 +02:00
|
|
|
StackDepotHandle() : node_(nullptr) {}
|
2014-09-23 19:59:53 +02:00
|
|
|
explicit StackDepotHandle(StackDepotNode *node) : node_(node) {}
|
|
|
|
bool valid() { return node_; }
|
|
|
|
u32 id();
|
|
|
|
int use_count();
|
|
|
|
void inc_use_count_unsafe();
|
|
|
|
};
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
const int kStackDepotMaxUseCount = 1U << (SANITIZER_ANDROID ? 16 : 20);
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
StackDepotStats *StackDepotGetStats();
|
2014-11-13 21:41:38 +01:00
|
|
|
u32 StackDepotPut(StackTrace stack);
|
|
|
|
StackDepotHandle StackDepotPut_WithHandle(StackTrace stack);
|
2012-11-12 16:53:47 +01:00
|
|
|
// Retrieves a stored stack trace by the id.
|
2014-11-13 21:41:38 +01:00
|
|
|
StackTrace StackDepotGet(u32 id);
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
void StackDepotLockAll();
|
|
|
|
void StackDepotUnlockAll();
|
2020-10-16 10:03:04 +02:00
|
|
|
void StackDepotPrintAll();
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
// Instantiating this class creates a snapshot of StackDepot which can be
|
|
|
|
// efficiently queried with StackDepotGet(). You can use it concurrently with
|
|
|
|
// StackDepot, but the snapshot is only guaranteed to contain those stack traces
|
|
|
|
// which were stored before it was instantiated.
|
|
|
|
class StackDepotReverseMap {
|
|
|
|
public:
|
|
|
|
StackDepotReverseMap();
|
2014-11-13 21:41:38 +01:00
|
|
|
StackTrace Get(u32 id);
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct IdDescPair {
|
|
|
|
u32 id;
|
2014-09-23 19:59:53 +02:00
|
|
|
StackDepotNode *desc;
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
static bool IdComparator(const IdDescPair &a, const IdDescPair &b);
|
|
|
|
};
|
|
|
|
|
|
|
|
InternalMmapVector<IdDescPair> map_;
|
|
|
|
|
|
|
|
// Disallow evil constructors.
|
|
|
|
StackDepotReverseMap(const StackDepotReverseMap&);
|
|
|
|
void operator=(const StackDepotReverseMap&);
|
|
|
|
};
|
2014-09-23 19:59:53 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
} // namespace __sanitizer
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#endif // SANITIZER_STACKDEPOT_H
|