2011-11-30 01:07:02 +00: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 07:41:27 +00:00
|
|
|
#include "asan_flags.h"
|
2013-01-31 13:46:14 +00:00
|
|
|
#include "asan_interface_internal.h"
|
2012-06-06 07:02:44 +00:00
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
2012-06-05 14:25:27 +00:00
|
|
|
#include "sanitizer_common/sanitizer_internal_defs.h"
|
2012-08-28 14:11:57 +00:00
|
|
|
#include "sanitizer_common/sanitizer_stacktrace.h"
|
2012-05-31 13:42:53 +00:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
2012-05-29 12:18:18 +00:00
|
|
|
|
2012-02-22 14:07:06 +00: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 12:00:24 +00:00
|
|
|
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
|
2011-11-30 01:07:02 +00:00
|
|
|
# error "The AddressSanitizer run-time should not be"
|
|
|
|
" instrumented by AddressSanitizer"
|
|
|
|
#endif
|
|
|
|
|
2011-12-08 18:30:42 +00:00
|
|
|
// Build-time configuration options.
|
|
|
|
|
|
|
|
// If set, asan will intercept C++ exception api call(s).
|
|
|
|
#ifndef ASAN_HAS_EXCEPTIONS
|
|
|
|
# define ASAN_HAS_EXCEPTIONS 1
|
|
|
|
#endif
|
|
|
|
|
2012-02-27 13:07:29 +00: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 07:17:17 +00:00
|
|
|
#if SANITIZER_WORDSIZE == 32
|
2012-09-28 10:07:53 +00:00
|
|
|
# define ASAN_LOW_MEMORY 1
|
2012-12-25 07:17:17 +00:00
|
|
|
#else
|
2012-09-28 10:07:53 +00:00
|
|
|
# define ASAN_LOW_MEMORY 0
|
|
|
|
# endif
|
2012-02-27 13:07:29 +00:00
|
|
|
#endif
|
2013-02-20 14:28:08 +00:00
|
|
|
|
2014-04-01 13:16:30 +00:00
|
|
|
#ifndef ASAN_DYNAMIC
|
2014-05-12 09:45:39 +00:00
|
|
|
# ifdef PIC
|
|
|
|
# define ASAN_DYNAMIC 1
|
|
|
|
# else
|
|
|
|
# define ASAN_DYNAMIC 0
|
|
|
|
# endif
|
2014-04-01 13:16:30 +00:00
|
|
|
#endif
|
|
|
|
|
2011-11-30 01:07:02 +00:00
|
|
|
// All internal functions in asan reside inside the __asan namespace
|
|
|
|
// to avoid namespace collisions with the user programs.
|
2014-05-15 02:22:34 +00:00
|
|
|
// Separate namespace also makes it simpler to distinguish the asan run-time
|
2011-11-30 01:07:02 +00:00
|
|
|
// functions from the instrumented user code in a profile.
|
|
|
|
namespace __asan {
|
|
|
|
|
|
|
|
class AsanThread;
|
2012-08-28 14:11:57 +00:00
|
|
|
using __sanitizer::StackTrace;
|
2011-11-30 01:07:02 +00:00
|
|
|
|
2014-01-16 12:31:50 +00:00
|
|
|
void AsanInitFromRtl();
|
|
|
|
|
2011-11-30 18:50:23 +00:00
|
|
|
// asan_rtl.cc
|
2012-03-13 16:29:25 +00:00
|
|
|
void NORETURN ShowStatsAndAbort();
|
2011-11-30 01:07:02 +00:00
|
|
|
|
2011-11-30 18:50:23 +00:00
|
|
|
// asan_malloc_linux.cc / asan_malloc_mac.cc
|
2011-11-30 01:07:02 +00:00
|
|
|
void ReplaceSystemMalloc();
|
|
|
|
|
2012-02-13 17:09:40 +00:00
|
|
|
// asan_linux.cc / asan_mac.cc / asan_win.cc
|
2011-11-30 01:07:02 +00:00
|
|
|
void *AsanDoesNotSupportStaticLinkage();
|
2014-04-01 13:16:30 +00:00
|
|
|
void AsanCheckDynamicRTPrereqs();
|
|
|
|
void AsanCheckIncompatibleRT();
|
2011-12-28 22:58:01 +00:00
|
|
|
|
2012-05-31 14:35:53 +00:00
|
|
|
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
|
2014-01-31 13:10:07 +00:00
|
|
|
void AsanOnSIGSEGV(int, void *siginfo, void *context);
|
2012-01-06 02:12:25 +00:00
|
|
|
|
2012-08-24 09:22:05 +00:00
|
|
|
void MaybeReexec();
|
2012-01-09 18:53:15 +00:00
|
|
|
bool AsanInterceptsSignal(int signum);
|
2013-01-17 15:45:28 +00:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize);
|
2012-07-23 14:07:58 +00:00
|
|
|
void AsanPlatformThreadInit();
|
2013-05-24 11:46:56 +00:00
|
|
|
void StopInitOrderChecking();
|
2012-01-11 02:21:06 +00:00
|
|
|
|
|
|
|
// Wrapper for TLS/TSD.
|
2012-02-07 00:27:15 +00:00
|
|
|
void AsanTSDInit(void (*destructor)(void *tsd));
|
2012-01-11 02:21:06 +00:00
|
|
|
void *AsanTSDGet();
|
|
|
|
void AsanTSDSet(void *tsd);
|
2013-10-14 12:01:05 +00:00
|
|
|
void PlatformTSDDtor(void *tsd);
|
2012-01-09 18:53:15 +00:00
|
|
|
|
2012-06-06 13:11:29 +00:00
|
|
|
void AppendToErrorMessageBuffer(const char *buffer);
|
2011-11-30 01:07:02 +00:00
|
|
|
|
2014-01-31 14:36:55 +00:00
|
|
|
void ParseExtraActivationFlags();
|
|
|
|
|
2014-06-06 10:57:21 +00:00
|
|
|
void *AsanDlSymNext(const char *sym);
|
|
|
|
|
2014-05-15 02:22:34 +00:00
|
|
|
// Platform-specific options.
|
2013-03-19 14:54:17 +00:00
|
|
|
#if SANITIZER_MAC
|
2012-03-20 10:54:40 +00:00
|
|
|
bool PlatformHasDifferentMemcpyAndMemmove();
|
|
|
|
# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE \
|
|
|
|
(PlatformHasDifferentMemcpyAndMemmove())
|
|
|
|
#else
|
|
|
|
# define PLATFORM_HAS_DIFFERENT_MEMCPY_AND_MEMMOVE true
|
2013-04-03 07:29:53 +00:00
|
|
|
#endif // SANITIZER_MAC
|
2012-03-20 10:54:40 +00:00
|
|
|
|
2012-12-07 22:01:28 +00:00
|
|
|
// Add convenient macro for interface functions that may be represented as
|
|
|
|
// weak hooks.
|
|
|
|
#define ASAN_MALLOC_HOOK(ptr, size) \
|
2014-07-07 17:39:31 +00:00
|
|
|
if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
|
2012-12-07 22:01:28 +00:00
|
|
|
#define ASAN_FREE_HOOK(ptr) \
|
2014-07-07 17:39:31 +00:00
|
|
|
if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
|
2012-12-07 22:01:28 +00:00
|
|
|
#define ASAN_ON_ERROR() \
|
|
|
|
if (&__asan_on_error) __asan_on_error()
|
|
|
|
|
2011-11-30 01:07:02 +00:00
|
|
|
extern int asan_inited;
|
|
|
|
// Used to avoid infinite recursion in __asan_init().
|
|
|
|
extern bool asan_init_is_running;
|
2012-06-06 07:02:44 +00:00
|
|
|
extern void (*death_callback)(void);
|
2011-11-30 01:07:02 +00: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 14:10:25 +00:00
|
|
|
const int kAsanInitializationOrderMagic = 0xf6;
|
2011-11-30 01:07:02 +00:00
|
|
|
const int kAsanUserPoisonedMemoryMagic = 0xf7;
|
2013-11-19 08:40:07 +00:00
|
|
|
const int kAsanContiguousContainerOOBMagic = 0xfc;
|
2012-12-04 01:38:15 +00:00
|
|
|
const int kAsanStackUseAfterScopeMagic = 0xf8;
|
2011-11-30 01:07:02 +00:00
|
|
|
const int kAsanGlobalRedzoneMagic = 0xf9;
|
2011-12-15 17:41:30 +00:00
|
|
|
const int kAsanInternalHeapMagic = 0xfe;
|
2014-08-04 12:43:13 +00:00
|
|
|
const int kAsanArrayCookieMagic = 0xac;
|
2014-10-17 01:22:37 +00:00
|
|
|
const int kAsanIntraObjectRedzone = 0xbb;
|
2011-11-30 01:07:02 +00:00
|
|
|
|
2012-05-31 14:35:53 +00:00
|
|
|
static const uptr kCurrentStackFrameMagic = 0x41B58AB3;
|
|
|
|
static const uptr kRetiredStackFrameMagic = 0x45E0360E;
|
2011-11-30 01:07:02 +00:00
|
|
|
|
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
#endif // ASAN_INTERNAL_H
|