xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.h (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
10b57cec5SDimitry Andric //===-- sanitizer_stackdepot.h ----------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file is shared between AddressSanitizer and ThreadSanitizer
100b57cec5SDimitry Andric // run-time libraries.
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef SANITIZER_STACKDEPOT_H
140b57cec5SDimitry Andric #define SANITIZER_STACKDEPOT_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "sanitizer_common.h"
170b57cec5SDimitry Andric #include "sanitizer_internal_defs.h"
180b57cec5SDimitry Andric #include "sanitizer_stacktrace.h"
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric namespace __sanitizer {
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric // StackDepot efficiently stores huge amounts of stack traces.
230b57cec5SDimitry Andric struct StackDepotNode;
240b57cec5SDimitry Andric struct StackDepotHandle {
25349cc55cSDimitry Andric   StackDepotNode *node_ = nullptr;
26349cc55cSDimitry Andric   u32 id_ = 0;
StackDepotHandleStackDepotHandle27349cc55cSDimitry Andric   StackDepotHandle(StackDepotNode *node, u32 id) : node_(node), id_(id) {}
validStackDepotHandle28349cc55cSDimitry Andric   bool valid() const { return node_; }
idStackDepotHandle29349cc55cSDimitry Andric   u32 id() const { return id_; }
30349cc55cSDimitry Andric   int use_count() const;
310b57cec5SDimitry Andric   void inc_use_count_unsafe();
320b57cec5SDimitry Andric };
330b57cec5SDimitry Andric 
340b57cec5SDimitry Andric const int kStackDepotMaxUseCount = 1U << (SANITIZER_ANDROID ? 16 : 20);
350b57cec5SDimitry Andric 
36349cc55cSDimitry Andric StackDepotStats StackDepotGetStats();
370b57cec5SDimitry Andric u32 StackDepotPut(StackTrace stack);
380b57cec5SDimitry Andric StackDepotHandle StackDepotPut_WithHandle(StackTrace stack);
390b57cec5SDimitry Andric // Retrieves a stored stack trace by the id.
400b57cec5SDimitry Andric StackTrace StackDepotGet(u32 id);
410b57cec5SDimitry Andric 
42*cb14a3feSDimitry Andric void StackDepotLockBeforeFork();
43*cb14a3feSDimitry Andric void StackDepotUnlockAfterFork(bool fork_child);
44e8d8bef9SDimitry Andric void StackDepotPrintAll();
450eae32dcSDimitry Andric void StackDepotStopBackgroundThread();
460b57cec5SDimitry Andric 
47349cc55cSDimitry Andric void StackDepotTestOnlyUnmap();
480b57cec5SDimitry Andric 
490b57cec5SDimitry Andric } // namespace __sanitizer
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric #endif // SANITIZER_STACKDEPOT_H
52