Path: blob/main/contrib/llvm-project/compiler-rt/lib/memprof/memprof_stack.cpp
35236 views
//===-- memprof_stack.cpp ------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of MemProfiler, a memory profiler.9//10// Code for MemProf stack trace.11//===----------------------------------------------------------------------===//12#include "memprof_stack.h"13#include "memprof_internal.h"14#include "sanitizer_common/sanitizer_atomic.h"1516namespace __memprof {1718static atomic_uint32_t malloc_context_size;1920void SetMallocContextSize(u32 size) {21atomic_store(&malloc_context_size, size, memory_order_release);22}2324u32 GetMallocContextSize() {25return atomic_load(&malloc_context_size, memory_order_acquire);26}2728} // namespace __memprof2930void __sanitizer::BufferedStackTrace::UnwindImpl(uptr pc, uptr bp,31void *context,32bool request_fast,33u32 max_depth) {34using namespace __memprof;35size = 0;36if (UNLIKELY(!memprof_inited))37return;38request_fast = StackTrace::WillUseFastUnwind(request_fast);39MemprofThread *t = GetCurrentThread();40if (request_fast) {41if (t) {42Unwind(max_depth, pc, bp, nullptr, t->stack_top(), t->stack_bottom(),43true);44}45return;46}47Unwind(max_depth, pc, bp, context, 0, 0, false);48}4950// ------------------ Interface -------------- {{{15152extern "C" {53SANITIZER_INTERFACE_ATTRIBUTE54void __sanitizer_print_stack_trace() {55using namespace __memprof;56PRINT_CURRENT_STACK();57}58} // extern "C"596061