]>
Commit | Line | Data |
---|---|---|
f35db108 WM |
1 | //===-- asan_stack.h --------------------------------------------*- C++ -*-===// |
2 | // | |
b667dd70 ML |
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-exception | |
f35db108 WM |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // This file is a part of AddressSanitizer, an address sanity checker. | |
10 | // | |
b667dd70 | 11 | // ASan-private header for asan_stack.cpp. |
f35db108 | 12 | //===----------------------------------------------------------------------===// |
696d846a | 13 | |
f35db108 WM |
14 | #ifndef ASAN_STACK_H |
15 | #define ASAN_STACK_H | |
16 | ||
e9772e16 | 17 | #include "asan_flags.h" |
ef1b3fda KS |
18 | #include "asan_thread.h" |
19 | #include "sanitizer_common/sanitizer_flags.h" | |
20 | #include "sanitizer_common/sanitizer_stacktrace.h" | |
f35db108 WM |
21 | |
22 | namespace __asan { | |
23 | ||
696d846a MO |
24 | static const u32 kDefaultMallocContextSize = 30; |
25 | ||
26 | void SetMallocContextSize(u32 size); | |
27 | u32 GetMallocContextSize(); | |
28 | ||
696d846a | 29 | } // namespace __asan |
f35db108 WM |
30 | |
31 | // NOTE: A Rule of thumb is to retrieve stack trace in the interceptors | |
32 | // as early as possible (in functions exposed to the user), as we generally | |
33 | // don't want stack trace to contain functions from ASan internals. | |
34 | ||
28219f7f JJ |
35 | #define GET_STACK_TRACE(max_size, fast) \ |
36 | UNINITIALIZED BufferedStackTrace stack; \ | |
37 | if (max_size <= 2) { \ | |
38 | stack.size = max_size; \ | |
39 | if (max_size > 0) { \ | |
40 | stack.top_frame_bp = GET_CURRENT_FRAME(); \ | |
41 | stack.trace_buffer[0] = StackTrace::GetCurrentPc(); \ | |
42 | if (max_size > 1) \ | |
43 | stack.trace_buffer[1] = GET_CALLER_PC(); \ | |
44 | } \ | |
45 | } else { \ | |
46 | stack.Unwind(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), nullptr, \ | |
47 | fast, max_size); \ | |
dee5ea7a | 48 | } |
f35db108 | 49 | |
28219f7f JJ |
50 | #define GET_STACK_TRACE_FATAL(pc, bp) \ |
51 | UNINITIALIZED BufferedStackTrace stack; \ | |
52 | stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal) | |
dee5ea7a | 53 | |
ef1b3fda KS |
54 | #define GET_STACK_TRACE_FATAL_HERE \ |
55 | GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal) | |
e9772e16 | 56 | |
ef1b3fda | 57 | #define GET_STACK_TRACE_THREAD \ |
e9772e16 KS |
58 | GET_STACK_TRACE(kStackTraceMax, true) |
59 | ||
696d846a MO |
60 | #define GET_STACK_TRACE_MALLOC \ |
61 | GET_STACK_TRACE(GetMallocContextSize(), common_flags()->fast_unwind_on_malloc) | |
e9772e16 KS |
62 | |
63 | #define GET_STACK_TRACE_FREE GET_STACK_TRACE_MALLOC | |
f35db108 | 64 | |
c4c16f74 KS |
65 | #define PRINT_CURRENT_STACK() \ |
66 | { \ | |
67 | GET_STACK_TRACE_FATAL_HERE; \ | |
dee5ea7a | 68 | stack.Print(); \ |
f35db108 WM |
69 | } |
70 | ||
696d846a | 71 | #endif // ASAN_STACK_H |