1 //===-- memprof_stack.cpp ------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of MemProfiler, a memory profiler.
11 // Code for MemProf stack trace.
12 //===----------------------------------------------------------------------===//
13 #include "memprof_stack.h"
14 #include "memprof_internal.h"
15 #include "sanitizer_common/sanitizer_atomic.h"
19 static atomic_uint32_t malloc_context_size
;
21 void SetMallocContextSize(u32 size
) {
22 atomic_store(&malloc_context_size
, size
, memory_order_release
);
25 u32
GetMallocContextSize() {
26 return atomic_load(&malloc_context_size
, memory_order_acquire
);
29 } // namespace __memprof
31 void __sanitizer::BufferedStackTrace::UnwindImpl(uptr pc
, uptr bp
,
35 using namespace __memprof
;
37 if (UNLIKELY(!memprof_inited
))
39 request_fast
= StackTrace::WillUseFastUnwind(request_fast
);
40 MemprofThread
*t
= GetCurrentThread();
43 Unwind(max_depth
, pc
, bp
, nullptr, t
->stack_top(), t
->stack_bottom(),
48 Unwind(max_depth
, pc
, bp
, context
, 0, 0, false);
51 // ------------------ Interface -------------- {{{1
54 SANITIZER_INTERFACE_ATTRIBUTE
55 void __sanitizer_print_stack_trace() {
56 using namespace __memprof
;
57 PRINT_CURRENT_STACK();