Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 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 | |
Kostya Serebryany | 7575968 | 2012-08-28 14:11:57 +0000 | [diff] [blame] | 17 | #include "sanitizer_common/sanitizer_stacktrace.h" |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 18 | #include "asan_flags.h" |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 19 | |
| 20 | namespace __asan { |
| 21 | |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 22 | void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, bool fast); |
Kostya Serebryany | a57b4e8 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 23 | void PrintStack(StackTrace *stack); |
Kostya Serebryany | ee92877 | 2012-08-28 13:25:55 +0000 | [diff] [blame] | 24 | |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 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. |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 31 | #define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \ |
Kostya Serebryany | 6b0d775 | 2012-08-28 11:54:30 +0000 | [diff] [blame] | 32 | StackTrace stack; \ |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 33 | GetStackTrace(&stack, max_s, pc, bp, fast) |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 34 | |
Alexey Samsonov | 2d3a67b | 2012-01-17 06:35:31 +0000 | [diff] [blame] | 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 | |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 39 | #define GET_STACK_TRACE(max_size, fast) \ |
Evgeniy Stepanov | 84c44a8 | 2012-01-19 11:34:18 +0000 | [diff] [blame] | 40 | GET_STACK_TRACE_WITH_PC_AND_BP(max_size, \ |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 41 | StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), fast) |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 42 | |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 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) |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 46 | |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 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 |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 58 | |
| 59 | #define PRINT_CURRENT_STACK() \ |
| 60 | { \ |
Kostya Serebryany | baf583c | 2012-12-13 09:34:23 +0000 | [diff] [blame^] | 61 | GET_STACK_TRACE(kStackTraceMax, \ |
| 62 | flags()->fast_unwind_on_fatal); \ |
Kostya Serebryany | a57b4e8 | 2012-08-28 13:49:49 +0000 | [diff] [blame] | 63 | PrintStack(&stack); \ |
Chandler Carruth | bbff278 | 2012-06-25 06:53:10 +0000 | [diff] [blame] | 64 | } |
Kostya Serebryany | 019b76f | 2011-11-30 01:07:02 +0000 | [diff] [blame] | 65 | |
| 66 | #endif // ASAN_STACK_H |