2011-11-30 09:07:02 +08:00
|
|
|
//===-- asan_internal.h -----------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// ASan-private header which defines various general utilities.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef ASAN_INTERNAL_H
|
|
|
|
#define ASAN_INTERNAL_H
|
|
|
|
|
2012-07-10 15:41:27 +08:00
|
|
|
#include "asan_flags.h"
|
2013-01-31 21:46:14 +08:00
|
|
|
#include "asan_interface_internal.h"
|
2012-06-06 15:02:44 +08:00
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2012-06-05 22:25:27 +08:00
|
|
|
#include "sanitizer_common/sanitizer_internal_defs.h"
|
2012-08-28 22:11:57 +08:00
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
2012-05-31 21:42:53 +08:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2012-05-29 20:18:18 +08:00
|
|
|
|
2012-02-22 22:07:06 +08:00
|
|
|
#define ASAN_DEFAULT_FAILURE_EXITCODE 1
|
|
|
|
|
[asan] make asan work with 7fff8000 offset and prelink
When prelink is installed in the system, prelink-ed
libraries map between 0x003000000000 and 0x004000000000 thus occupying the shadow Gap,
so we need so split the address space even further, like this:
|| [0x10007fff8000, 0x7fffffffffff] || HighMem ||
|| [0x02008fff7000, 0x10007fff7fff] || HighShadow ||
|| [0x004000000000, 0x02008fff6fff] || ShadowGap3 ||
|| [0x003000000000, 0x003fffffffff] || MidMem ||
|| [0x00087fff8000, 0x002fffffffff] || ShadowGap2 ||
|| [0x00067fff8000, 0x00087fff7fff] || MidShadow ||
|| [0x00008fff7000, 0x00067fff7fff] || ShadowGap ||
|| [0x00007fff8000, 0x00008fff6fff] || LowShadow ||
|| [0x000000000000, 0x00007fff7fff] || LowMem ||
Do it only if necessary.
Also added a bit of profiling code to make sure that the
mapping code is efficient.
Added a lit test to simulate prelink-ed libraries.
Unfortunately, this test does not work with binutils-gold linker.
If gold is the default linker the test silently passes.
Also replaced
__has_feature(address_sanitizer)
with
__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
in two places.
Patch partially by Jakub Jelinek.
llvm-svn: 175263
2013-02-15 20:00:24 +08:00
|
|
|
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
|
2011-11-30 09:07:02 +08:00
|
|
|
# error "The AddressSanitizer run-time should not be"
|
|
|
|
" instrumented by AddressSanitizer"
|
|
|
|
#endif
|
|
|
|
|
2011-12-09 02:30:42 +08:00
|
|
|
// Build-time configuration options.
|
|
|
|
|
|
|
|
// If set, asan will install its own SEGV signal handler.
|
|
|
|
#ifndef ASAN_NEEDS_SEGV
|
2013-03-19 21:54:41 +08:00
|
|
|
# if SANITIZER_ANDROID == 1
|
2012-09-28 18:07:53 +08:00
|
|
|
# define ASAN_NEEDS_SEGV 0
|
|
|
|
# else
|
|
|
|
# define ASAN_NEEDS_SEGV 1
|
|
|
|
# endif
|
2011-12-09 02:30:42 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// If set, asan will intercept C++ exception api call(s).
|
|
|
|
#ifndef ASAN_HAS_EXCEPTIONS
|
|
|
|
# define ASAN_HAS_EXCEPTIONS 1
|
|
|
|
#endif
|
|
|
|
|
2012-02-27 21:07:29 +08:00
|
|
|
// If set, values like allocator chunk size, as well as defaults for some flags
|
|
|
|
// will be changed towards less memory overhead.
|
|
|
|
#ifndef ASAN_LOW_MEMORY
|
2012-12-25 15:17:17 +08:00
|
|
|
#if SANITIZER_WORDSIZE == 32
|
2012-09-28 18:07:53 +08:00
|
|
|
# define ASAN_LOW_MEMORY 1
|
2012-12-25 15:17:17 +08:00
|
|
|
#else
|
2012-09-28 18:07:53 +08:00
|
|
|
# define ASAN_LOW_MEMORY 0
|
|
|
|
# endif
|
2012-02-27 21:07:29 +08:00
|
|
|
#endif
|
2013-02-20 22:28:08 +08:00
|
|
|
|
|
|
|
#ifndef ASAN_USE_PREINIT_ARRAY
|
2013-03-19 21:54:41 +08:00
|
|
|
# define ASAN_USE_PREINIT_ARRAY (SANITIZER_LINUX && !SANITIZER_ANDROID)
|
2013-02-20 22:28:08 +08:00
|
|
|
#endif
|
2012-02-27 21:07:29 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
// All internal functions in asan reside inside the __asan namespace
|
|
|
|
// to avoid namespace collisions with the user programs.
|
|
|
|
// Seperate namespace also makes it simpler to distinguish the asan run-time
|
|
|
|
// functions from the instrumented user code in a profile.
|
|
|
|
namespace __asan {
|
|
|
|
|
|
|
|
class AsanThread;
|
2012-08-28 22:11:57 +08:00
|
|
|
using __sanitizer::StackTrace;
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2011-12-01 02:50:23 +08:00
|
|
|
// asan_rtl.cc
|
2012-03-14 00:29:25 +08:00
|
|
|
void NORETURN ShowStatsAndAbort();
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-04-06 16:21:08 +08:00
|
|
|
void ReplaceOperatorsNewAndDelete();
|
2011-12-01 02:50:23 +08:00
|
|
|
// asan_malloc_linux.cc / asan_malloc_mac.cc
|
2011-11-30 09:07:02 +08:00
|
|
|
void ReplaceSystemMalloc();
|
|
|
|
|
2012-02-14 01:09:40 +08:00
|
|
|
// asan_linux.cc / asan_mac.cc / asan_win.cc
|
2011-11-30 09:07:02 +08:00
|
|
|
void *AsanDoesNotSupportStaticLinkage();
|
2011-12-29 06:58:01 +08:00
|
|
|
|
2012-05-31 22:35:53 +08:00
|
|
|
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
|
2012-01-06 10:12:25 +08:00
|
|
|
|
2012-08-24 17:22:05 +08:00
|
|
|
void MaybeReexec();
|
2012-01-10 02:53:15 +08:00
|
|
|
bool AsanInterceptsSignal(int signum);
|
2012-04-05 18:54:52 +08:00
|
|
|
void SetAlternateSignalStack();
|
|
|
|
void UnsetAlternateSignalStack();
|
2012-01-10 03:18:27 +08:00
|
|
|
void InstallSignalHandlers();
|
2013-01-17 23:45:28 +08:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize);
|
2012-07-23 22:07:58 +08:00
|
|
|
void AsanPlatformThreadInit();
|
2013-05-24 19:46:56 +08:00
|
|
|
void StopInitOrderChecking();
|
2012-01-11 10:21:06 +08:00
|
|
|
|
|
|
|
// Wrapper for TLS/TSD.
|
2012-02-07 08:27:15 +08:00
|
|
|
void AsanTSDInit(void (*destructor)(void *tsd));
|
2012-01-11 10:21:06 +08:00
|
|
|
void *AsanTSDGet();
|
|
|
|
void AsanTSDSet(void *tsd);
|
2013-10-14 20:01:05 +08:00
|
|
|
void PlatformTSDDtor(void *tsd);
|
2012-01-10 02:53:15 +08:00
|
|
|
|
2012-06-06 21:11:29 +08:00
|
|
|
void AppendToErrorMessageBuffer(const char *buffer);
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-03-20 18:54:40 +08:00
|
|
|
// Platfrom-specific options.
|
2013-03-19 22:54:17 +08:00
|
|
|
#if SANITIZER_MAC
|
2012-03-20 18:54:40 +08:00
|
|
|
bool PlatformHasDifferentMemcpyAndMemmove();
|
|
|
|
# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
|
|
|
|
(PlatformHasDifferentMemcpyAndMemmove())
|
|
|
|
#else
|
|
|
|
# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
|
2013-04-03 15:29:53 +08:00
|
|
|
#endif // SANITIZER_MAC
|
2012-03-20 18:54:40 +08:00
|
|
|
|
2012-12-08 06:01:28 +08:00
|
|
|
// Add convenient macro for interface functions that may be represented as
|
|
|
|
// weak hooks.
|
|
|
|
#define ASAN_MALLOC_HOOK(ptr, size) \
|
|
|
|
if (&__asan_malloc_hook) __asan_malloc_hook(ptr, size)
|
|
|
|
#define ASAN_FREE_HOOK(ptr) \
|
|
|
|
if (&__asan_free_hook) __asan_free_hook(ptr)
|
|
|
|
#define ASAN_ON_ERROR() \
|
|
|
|
if (&__asan_on_error) __asan_on_error()
|
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
extern int asan_inited;
|
|
|
|
// Used to avoid infinite recursion in __asan_init().
|
|
|
|
extern bool asan_init_is_running;
|
2012-06-06 15:02:44 +08:00
|
|
|
extern void (*death_callback)(void);
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
// These magic values are written to shadow for better error reporting.
|
|
|
|
const int kAsanHeapLeftRedzoneMagic = 0xfa;
|
|
|
|
const int kAsanHeapRightRedzoneMagic = 0xfb;
|
|
|
|
const int kAsanHeapFreeMagic = 0xfd;
|
|
|
|
const int kAsanStackLeftRedzoneMagic = 0xf1;
|
|
|
|
const int kAsanStackMidRedzoneMagic = 0xf2;
|
|
|
|
const int kAsanStackRightRedzoneMagic = 0xf3;
|
|
|
|
const int kAsanStackPartialRedzoneMagic = 0xf4;
|
|
|
|
const int kAsanStackAfterReturnMagic = 0xf5;
|
2012-08-21 22:10:25 +08:00
|
|
|
const int kAsanInitializationOrderMagic = 0xf6;
|
2011-11-30 09:07:02 +08:00
|
|
|
const int kAsanUserPoisonedMemoryMagic = 0xf7;
|
2013-11-19 16:40:07 +08:00
|
|
|
const int kAsanContiguousContainerOOBMagic = 0xfc;
|
2012-12-04 09:38:15 +08:00
|
|
|
const int kAsanStackUseAfterScopeMagic = 0xf8;
|
2011-11-30 09:07:02 +08:00
|
|
|
const int kAsanGlobalRedzoneMagic = 0xf9;
|
2011-12-16 01:41:30 +08:00
|
|
|
const int kAsanInternalHeapMagic = 0xfe;
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-05-31 22:35:53 +08:00
|
|
|
static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
|
|
|
|
static const uptr kRetiredStackFrameMagic = 0x45E0360E;
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
#endif // ASAN_INTERNAL_H
|