• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 namespace __asan {
20 
21 void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp);
22 void PrintStack(StackTrace *stack);
23 
24 }  // namespace __asan
25 
26 // Get the stack trace with the given pc and bp.
27 // The pc will be in the position 0 of the resulting stack trace.
28 // The bp may refer to the current frame or to the caller's frame.
29 // fast_unwind is currently unused.
30 #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp)               \
31   StackTrace stack;                                             \
32   GetStackTrace(&stack, max_s, pc, bp)
33 
34 // NOTE: A Rule of thumb is to retrieve stack trace in the interceptors
35 // as early as possible (in functions exposed to the user), as we generally
36 // don't want stack trace to contain functions from ASan internals.
37 
38 #define GET_STACK_TRACE_HERE(max_size)                        \
39   GET_STACK_TRACE_WITH_PC_AND_BP(max_size,                    \
40       StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
41 
42 #define GET_STACK_TRACE_HERE_FOR_MALLOC                             \
43   GET_STACK_TRACE_HERE(flags()->malloc_context_size)
44 
45 #define GET_STACK_TRACE_HERE_FOR_FREE(ptr)                          \
46   GET_STACK_TRACE_HERE(flags()->malloc_context_size)
47 
48 #define PRINT_CURRENT_STACK()                    \
49   {                                              \
50     GET_STACK_TRACE_HERE(kStackTraceMax);        \
51     PrintStack(&stack);                          \
52   }
53 
54 #endif  // ASAN_STACK_H
55