54 lines · c
1//===-- backtrace.h ---------------------------------------------*- C++ -*-===//2//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef GWP_ASAN_OPTIONAL_BACKTRACE_H_10#define GWP_ASAN_OPTIONAL_BACKTRACE_H_11 12#include "gwp_asan/optional/printf.h"13#include "gwp_asan/options.h"14 15namespace gwp_asan {16namespace backtrace {17// ================================ Description ================================18// This function shall take the backtrace provided in `TraceBuffer`, and print19// it in a human-readable format using `Print`. Generally, this function shall20// resolve raw pointers to section offsets and print them with the following21// sanitizer-common format:22// " #{frame_number} {pointer} in {function name} ({binary name}+{offset}"23// e.g. " #5 0x420459 in _start (/tmp/uaf+0x420459)"24// This format allows the backtrace to be symbolized offline successfully using25// llvm-symbolizer.26// =================================== Notes ===================================27// This function may directly or indirectly call malloc(), as the28// GuardedPoolAllocator contains a reentrancy barrier to prevent infinite29// recursion. Any allocation made inside this function will be served by the30// supporting allocator, and will not have GWP-ASan protections.31typedef void (*PrintBacktrace_t)(uintptr_t *TraceBuffer, size_t TraceLength,32 Printf_t Print);33 34// Returns a function pointer to a backtrace function that's suitable for35// unwinding through a signal handler. This is important primarily for frame-36// pointer based unwinders, DWARF or other unwinders can simply provide the37// normal backtrace function as the implementation here. On POSIX, SignalContext38// should be the `ucontext_t` from the signal handler.39typedef size_t (*SegvBacktrace_t)(uintptr_t *TraceBuffer, size_t Size,40 void *SignalContext);41 42// Returns platform-specific provided implementations of Backtrace_t for use43// inside the GWP-ASan core allocator.44options::Backtrace_t getBacktraceFunction();45 46// Returns platform-specific provided implementations of PrintBacktrace_t and47// SegvBacktrace_t for use in the optional SEGV handler.48PrintBacktrace_t getPrintBacktraceFunction();49SegvBacktrace_t getSegvBacktraceFunction();50} // namespace backtrace51} // namespace gwp_asan52 53#endif // GWP_ASAN_OPTIONAL_BACKTRACE_H_54