blob: 99f2cac1485b418ff44a2e7a40a1049996872d38 [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 Serebryany75759682012-08-28 14:11:57 +000017#include "sanitizer_common/sanitizer_stacktrace.h"
Kostya Serebryany019b76f2011-11-30 01:07:02 +000018
19namespace __asan {
20
Kostya Serebryanya57b4e82012-08-28 13:49:49 +000021void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp);
22void PrintStack(StackTrace *stack);
Kostya Serebryanyee928772012-08-28 13:25:55 +000023
Kostya Serebryany019b76f2011-11-30 01:07:02 +000024} // 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.
Evgeniy Stepanov84c44a82012-01-19 11:34:18 +000030#define GET_STACK_TRACE_WITH_PC_AND_BP(max_s, pc, bp) \
Kostya Serebryany6b0d7752012-08-28 11:54:30 +000031 StackTrace stack; \
Kostya Serebryanyee928772012-08-28 13:25:55 +000032 GetStackTrace(&stack, max_s, pc, bp)
Kostya Serebryany019b76f2011-11-30 01:07:02 +000033
Alexey Samsonov2d3a67b2012-01-17 06:35:31 +000034// 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
Evgeniy Stepanov84c44a82012-01-19 11:34:18 +000038#define GET_STACK_TRACE_HERE(max_size) \
39 GET_STACK_TRACE_WITH_PC_AND_BP(max_size, \
Kostya Serebryany6b0d7752012-08-28 11:54:30 +000040 StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
Kostya Serebryany019b76f2011-11-30 01:07:02 +000041
Evgeniy Stepanov84c44a82012-01-19 11:34:18 +000042#define GET_STACK_TRACE_HERE_FOR_MALLOC \
Alexey Samsonov34efb8e2012-07-09 14:36:04 +000043 GET_STACK_TRACE_HERE(flags()->malloc_context_size)
Kostya Serebryany019b76f2011-11-30 01:07:02 +000044
Evgeniy Stepanov84c44a82012-01-19 11:34:18 +000045#define GET_STACK_TRACE_HERE_FOR_FREE(ptr) \
Alexey Samsonov34efb8e2012-07-09 14:36:04 +000046 GET_STACK_TRACE_HERE(flags()->malloc_context_size)
Kostya Serebryany019b76f2011-11-30 01:07:02 +000047
48#define PRINT_CURRENT_STACK() \
49 { \
Evgeniy Stepanov84c44a82012-01-19 11:34:18 +000050 GET_STACK_TRACE_HERE(kStackTraceMax); \
Kostya Serebryanya57b4e82012-08-28 13:49:49 +000051 PrintStack(&stack); \
Chandler Carruthbbff2782012-06-25 06:53:10 +000052 }
Kostya Serebryany019b76f2011-11-30 01:07:02 +000053
54#endif // ASAN_STACK_H