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