blob: cd30abbb4b21e59465212550bb211e00829745f5 [file] [log] [blame]
Kostya Serebryany019b76f2011-11-30 01:07:02 +00001//===-- 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 Serebryanybaf583c2012-12-13 09:34:23 +000017#include "asan_flags.h"
Sergey Matveev0c8ed9c2013-05-06 11:27:58 +000018#include "sanitizer_common/sanitizer_flags.h"
19#include "sanitizer_common/sanitizer_stacktrace.h"
Kostya Serebryany019b76f2011-11-30 01:07:02 +000020
21namespace __asan {
22
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000023void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, bool fast);
Kostya Serebryanya57b4e82012-08-28 13:49:49 +000024void PrintStack(StackTrace *stack);
Kostya Serebryanyee928772012-08-28 13:25:55 +000025
Kostya Serebryany019b76f2011-11-30 01:07:02 +000026} // namespace __asan
27
28// Get the stack trace with the given pc and bp.
29// The pc will be in the position 0 of the resulting stack trace.
30// The bp may refer to the current frame or to the caller's frame.
31// fast_unwind is currently unused.
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000032#define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp, fast) \
Kostya Serebryany6b0d7752012-08-28 11:54:30 +000033 StackTrace stack; \
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000034 GetStackTrace(&stack, max_s, pc, bp, fast)
Kostya Serebryany019b76f2011-11-30 01:07:02 +000035
Alexey Samsonov2d3a67b2012-01-17 06:35:31 +000036// NOTE: A Rule of thumb is to retrieve stack trace in the interceptors
37// as early as possible (in functions exposed to the user), as we generally
38// don't want stack trace to contain functions from ASan internals.
39
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000040#define GET_STACK_TRACE(max_size, fast) \
Evgeniy Stepanov84c44a82012-01-19 11:34:18 +000041 GET_STACK_TRACE_WITH_PC_AND_BP(max_size, \
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000042 StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), fast)
Kostya Serebryany019b76f2011-11-30 01:07:02 +000043
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000044#define GET_STACK_TRACE_FATAL(pc, bp) \
45 GET_STACK_TRACE_WITH_PC_AND_BP(kStackTraceMax, pc, bp, \
Sergey Matveev0c8ed9c2013-05-06 11:27:58 +000046 common_flags()->fast_unwind_on_fatal)
Kostya Serebryany019b76f2011-11-30 01:07:02 +000047
Sergey Matveev0c8ed9c2013-05-06 11:27:58 +000048#define GET_STACK_TRACE_FATAL_HERE \
49 GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal)
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000050
Sergey Matveev0c8ed9c2013-05-06 11:27:58 +000051#define GET_STACK_TRACE_THREAD \
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000052 GET_STACK_TRACE(kStackTraceMax, true)
53
Sergey Matveev0c8ed9c2013-05-06 11:27:58 +000054#define GET_STACK_TRACE_MALLOC \
55 GET_STACK_TRACE(common_flags()->malloc_context_size, \
56 common_flags()->fast_unwind_on_malloc)
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000057
58#define GET_STACK_TRACE_FREE GET_STACK_TRACE_MALLOC
Kostya Serebryany019b76f2011-11-30 01:07:02 +000059
60#define PRINT_CURRENT_STACK() \
61 { \
Kostya Serebryanybaf583c2012-12-13 09:34:23 +000062 GET_STACK_TRACE(kStackTraceMax, \
Sergey Matveev0c8ed9c2013-05-06 11:27:58 +000063 common_flags()->fast_unwind_on_fatal); \
Kostya Serebryanya57b4e82012-08-28 13:49:49 +000064 PrintStack(&stack); \
Chandler Carruthbbff2782012-06-25 06:53:10 +000065 }
Kostya Serebryany019b76f2011-11-30 01:07:02 +000066
67#endif // ASAN_STACK_H