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
|
|
|
|
[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 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
|
2016-02-02 10:01:17 +08:00
|
|
|
# if SANITIZER_IOS || (SANITIZER_WORDSIZE == 32)
|
2012-09-28 18:07:53 +08:00
|
|
|
# define ASAN_LOW_MEMORY 1
|
2016-02-02 10:01: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
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
#ifndef ASAN_DYNAMIC
|
2014-05-12 17:45:39 +08:00
|
|
|
# ifdef PIC
|
|
|
|
# define ASAN_DYNAMIC 1
|
|
|
|
# else
|
|
|
|
# define ASAN_DYNAMIC 0
|
|
|
|
# endif
|
2014-04-01 21:16:30 +08:00
|
|
|
#endif
|
|
|
|
|
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.
|
2014-05-15 10:22:34 +08:00
|
|
|
// Separate namespace also makes it simpler to distinguish the asan run-time
|
2011-11-30 09:07:02 +08:00
|
|
|
// 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
|
|
|
|
2014-01-16 20:31:50 +08:00
|
|
|
void AsanInitFromRtl();
|
|
|
|
|
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
|
|
|
|
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();
|
2014-04-01 21:16:30 +08:00
|
|
|
void AsanCheckDynamicRTPrereqs();
|
|
|
|
void AsanCheckIncompatibleRT();
|
2011-12-29 06:58:01 +08:00
|
|
|
|
2015-08-07 01:52:54 +08:00
|
|
|
void AsanOnDeadlySignal(int, void *siginfo, void *context);
|
2012-01-06 10:12:25 +08:00
|
|
|
|
2013-01-17 23:45:28 +08:00
|
|
|
void ReadContextStack(void *context, uptr *stack, uptr *ssize);
|
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
|
|
|
|
2014-06-06 18:57:21 +08:00
|
|
|
void *AsanDlSymNext(const char *sym);
|
|
|
|
|
2015-05-30 06:31:28 +08:00
|
|
|
void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name);
|
2015-01-21 10:05:31 +08:00
|
|
|
|
2014-05-15 10:22:34 +08:00
|
|
|
// Platform-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) \
|
2014-07-08 01:39:31 +08:00
|
|
|
if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(ptr, size)
|
2012-12-08 06:01:28 +08:00
|
|
|
#define ASAN_FREE_HOOK(ptr) \
|
2014-07-08 01:39:31 +08:00
|
|
|
if (&__sanitizer_free_hook) __sanitizer_free_hook(ptr)
|
2012-12-08 06:01:28 +08:00
|
|
|
#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;
|
2014-08-04 20:43:13 +08:00
|
|
|
const int kAsanArrayCookieMagic = 0xac;
|
2014-10-17 09:22:37 +08:00
|
|
|
const int kAsanIntraObjectRedzone = 0xbb;
|
2014-11-21 18:32:05 +08:00
|
|
|
const int kAsanAllocaLeftMagic = 0xca;
|
|
|
|
const int kAsanAllocaRightMagic = 0xcb;
|
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
|