2011-11-30 09:07:02 +08:00
|
|
|
//===-- asan_stack.h --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
2019-08-01 21:43:28 +08:00
|
|
|
// ASan-private header for asan_stack.cpp.
|
2011-11-30 09:07:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2015-10-01 08:22:21 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
#ifndef ASAN_STACK_H
|
|
|
|
#define ASAN_STACK_H
|
|
|
|
|
2012-12-13 17:34:23 +08:00
|
|
|
#include "asan_flags.h"
|
2013-05-08 20:45:55 +08:00
|
|
|
#include "asan_thread.h"
|
2013-05-06 19:27:58 +08:00
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2014-03-04 21:12:25 +08:00
|
|
|
namespace __asan {
|
|
|
|
|
2014-12-16 09:23:03 +08:00
|
|
|
static const u32 kDefaultMallocContextSize = 30;
|
|
|
|
|
|
|
|
void SetMallocContextSize(u32 size);
|
|
|
|
u32 GetMallocContextSize();
|
|
|
|
|
2015-10-01 08:22:21 +08:00
|
|
|
} // namespace __asan
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-01-17 14:35:31 +08:00
|
|
|
// NOTE: A Rule of thumb is to retrieve stack trace in the interceptors
|
|
|
|
// as early as possible (in functions exposed to the user), as we generally
|
|
|
|
// don't want stack trace to contain functions from ASan internals.
|
|
|
|
|
2017-11-09 15:53:06 +08:00
|
|
|
#define GET_STACK_TRACE(max_size, fast) \
|
|
|
|
BufferedStackTrace stack; \
|
|
|
|
if (max_size <= 2) { \
|
|
|
|
stack.size = max_size; \
|
|
|
|
if (max_size > 0) { \
|
|
|
|
stack.top_frame_bp = GET_CURRENT_FRAME(); \
|
|
|
|
stack.trace_buffer[0] = StackTrace::GetCurrentPc(); \
|
|
|
|
if (max_size > 1) stack.trace_buffer[1] = GET_CALLER_PC(); \
|
|
|
|
} \
|
|
|
|
} else { \
|
2019-03-01 12:03:38 +08:00
|
|
|
stack.Unwind(StackTrace::GetCurrentPc(), \
|
|
|
|
GET_CURRENT_FRAME(), nullptr, fast, max_size); \
|
2014-03-04 21:12:25 +08:00
|
|
|
}
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2017-11-09 15:53:06 +08:00
|
|
|
#define GET_STACK_TRACE_FATAL(pc, bp) \
|
|
|
|
BufferedStackTrace stack; \
|
2019-03-01 12:03:38 +08:00
|
|
|
stack.Unwind(pc, bp, nullptr, \
|
|
|
|
common_flags()->fast_unwind_on_fatal)
|
2014-02-11 21:38:57 +08:00
|
|
|
|
2017-11-09 15:53:06 +08:00
|
|
|
#define GET_STACK_TRACE_SIGNAL(sig) \
|
|
|
|
BufferedStackTrace stack; \
|
2019-03-01 12:03:38 +08:00
|
|
|
stack.Unwind((sig).pc, (sig).bp, (sig).context, \
|
|
|
|
common_flags()->fast_unwind_on_fatal)
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2013-05-06 19:27:58 +08:00
|
|
|
#define GET_STACK_TRACE_FATAL_HERE \
|
|
|
|
GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_fatal)
|
2012-12-13 17:34:23 +08:00
|
|
|
|
2014-10-14 17:36:24 +08:00
|
|
|
#define GET_STACK_TRACE_CHECK_HERE \
|
|
|
|
GET_STACK_TRACE(kStackTraceMax, common_flags()->fast_unwind_on_check)
|
|
|
|
|
2013-05-06 19:27:58 +08:00
|
|
|
#define GET_STACK_TRACE_THREAD \
|
2012-12-13 17:34:23 +08:00
|
|
|
GET_STACK_TRACE(kStackTraceMax, true)
|
|
|
|
|
2014-12-16 09:23:03 +08:00
|
|
|
#define GET_STACK_TRACE_MALLOC \
|
|
|
|
GET_STACK_TRACE(GetMallocContextSize(), common_flags()->fast_unwind_on_malloc)
|
2012-12-13 17:34:23 +08:00
|
|
|
|
|
|
|
#define GET_STACK_TRACE_FREE GET_STACK_TRACE_MALLOC
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2013-12-04 02:24:28 +08:00
|
|
|
#define PRINT_CURRENT_STACK() \
|
|
|
|
{ \
|
|
|
|
GET_STACK_TRACE_FATAL_HERE; \
|
2013-12-19 19:25:05 +08:00
|
|
|
stack.Print(); \
|
2012-06-25 14:53:10 +08:00
|
|
|
}
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2014-10-14 17:36:24 +08:00
|
|
|
#define PRINT_CURRENT_STACK_CHECK() \
|
|
|
|
{ \
|
|
|
|
GET_STACK_TRACE_CHECK_HERE; \
|
|
|
|
stack.Print(); \
|
|
|
|
}
|
|
|
|
|
2015-10-01 08:22:21 +08:00
|
|
|
#endif // ASAN_STACK_H
|