Home | History | Annotate | Download | only in asan
      1 //===-- asan_stack.h --------------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file is a part of AddressSanitizer, an address sanity checker.
     11 //
     12 // ASan-private header for asan_stack.cc.
     13 //===----------------------------------------------------------------------===//
     14 #ifndef ASAN_STACK_H
     15 #define ASAN_STACK_H
     16 
     17 #include "sanitizer_common/sanitizer_stacktrace.h"
     18 #include "asan_flags.h"
     19 
     20 namespace __asan {
     21 
     22 void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, bool fast);
     23 void PrintStack(StackTrace *stack);
     24 
     25 }  // namespace __asan
     26 
     27 // Get the stack trace with the given pc and bp.
     28 // The pc will be in the position 0 of the resulting stack trace.
     29 // The bp may refer to the current frame or to the caller's frame.
     30 // fast_unwind is currently unused.
     31 #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast)     \
     32   StackTrace stack;                                             \
     33   GetStackTrace(&stack, max_s, pc, bp, fast)
     34 
     35 // NOTE: A Rule of thumb is to retrieve stack trace in the interceptors
     36 // as early as possible (in functions exposed to the user), as we generally
     37 // don't want stack trace to contain functions from ASan internals.
     38 
     39 #define GET_STACK_TRACE(max_size, fast)                       \
     40   GET_STACK_TRACE_WITH_PC_AND_BP(max_size,                    \
     41       StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), fast)
     42 
     43 #define GET_STACK_TRACE_FATAL(pc, bp)                                 \
     44   GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp,              \
     45                                  flags()->fast_unwind_on_fatal)
     46 
     47 #define GET_STACK_TRACE_FATAL_HERE                           \
     48   GET_STACK_TRACE(kStackTraceMax, flags()->fast_unwind_on_fatal)
     49 
     50 #define GET_STACK_TRACE_THREAD                              \
     51   GET_STACK_TRACE(kStackTraceMax, true)
     52 
     53 #define GET_STACK_TRACE_MALLOC                             \
     54   GET_STACK_TRACE(flags()->malloc_context_size,            \
     55                   flags()->fast_unwind_on_malloc)
     56 
     57 #define GET_STACK_TRACE_FREE GET_STACK_TRACE_MALLOC
     58 
     59 #define PRINT_CURRENT_STACK()                    \
     60   {                                              \
     61     GET_STACK_TRACE(kStackTraceMax,              \
     62       flags()->fast_unwind_on_fatal);            \
     63     PrintStack(&stack);                          \
     64   }
     65 
     66 #endif  // ASAN_STACK_H
     67