Path: blob/main/contrib/llvm-project/compiler-rt/lib/gwp_asan/optional/backtrace.h
35271 views
//===-- backtrace.h ---------------------------------------------*- C++ -*-===//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//===----------------------------------------------------------------------===//78#ifndef GWP_ASAN_OPTIONAL_BACKTRACE_H_9#define GWP_ASAN_OPTIONAL_BACKTRACE_H_1011#include "gwp_asan/optional/printf.h"12#include "gwp_asan/options.h"1314namespace gwp_asan {15namespace backtrace {16// ================================ Description ================================17// This function shall take the backtrace provided in `TraceBuffer`, and print18// it in a human-readable format using `Print`. Generally, this function shall19// resolve raw pointers to section offsets and print them with the following20// sanitizer-common format:21// " #{frame_number} {pointer} in {function name} ({binary name}+{offset}"22// e.g. " #5 0x420459 in _start (/tmp/uaf+0x420459)"23// This format allows the backtrace to be symbolized offline successfully using24// llvm-symbolizer.25// =================================== Notes ===================================26// This function may directly or indirectly call malloc(), as the27// GuardedPoolAllocator contains a reentrancy barrier to prevent infinite28// recursion. Any allocation made inside this function will be served by the29// supporting allocator, and will not have GWP-ASan protections.30typedef void (*PrintBacktrace_t)(uintptr_t *TraceBuffer, size_t TraceLength,31Printf_t Print);3233// Returns a function pointer to a backtrace function that's suitable for34// unwinding through a signal handler. This is important primarily for frame-35// pointer based unwinders, DWARF or other unwinders can simply provide the36// normal backtrace function as the implementation here. On POSIX, SignalContext37// should be the `ucontext_t` from the signal handler.38typedef size_t (*SegvBacktrace_t)(uintptr_t *TraceBuffer, size_t Size,39void *SignalContext);4041// Returns platform-specific provided implementations of Backtrace_t for use42// inside the GWP-ASan core allocator.43options::Backtrace_t getBacktraceFunction();4445// Returns platform-specific provided implementations of PrintBacktrace_t and46// SegvBacktrace_t for use in the optional SEGV handler.47PrintBacktrace_t getPrintBacktraceFunction();48SegvBacktrace_t getSegvBacktraceFunction();49} // namespace backtrace50} // namespace gwp_asan5152#endif // GWP_ASAN_OPTIONAL_BACKTRACE_H_535455