2012-11-12 16:53:47 +01:00
|
|
|
//===-- asan_rtl.cc -------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// Main file of the ASan run-time library.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
#include "asan_activation.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "asan_allocator.h"
|
|
|
|
#include "asan_interceptors.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "asan_interface_internal.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "asan_internal.h"
|
|
|
|
#include "asan_mapping.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "asan_poisoning.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "asan_report.h"
|
|
|
|
#include "asan_stack.h"
|
|
|
|
#include "asan_stats.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "asan_suppressions.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "asan_thread.h"
|
|
|
|
#include "sanitizer_common/sanitizer_atomic.h"
|
|
|
|
#include "sanitizer_common/sanitizer_flags.h"
|
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
|
|
|
#include "sanitizer_common/sanitizer_symbolizer.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
#include "lsan/lsan_common.h"
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "ubsan/ubsan_init.h"
|
|
|
|
#include "ubsan/ubsan_platform.h"
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
uptr __asan_shadow_memory_dynamic_address; // Global interface symbol.
|
2013-11-04 22:33:31 +01:00
|
|
|
int __asan_option_detect_stack_use_after_return; // Global interface symbol.
|
2014-05-22 09:09:21 +02:00
|
|
|
uptr *__asan_test_only_reported_buggy_pointer; // Used only for testing asan.
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
|
2013-02-21 11:57:10 +01:00
|
|
|
uptr AsanMappingProfile[kAsanMappingProfileSize];
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
static void AsanDie() {
|
|
|
|
static atomic_uint32_t num_calls;
|
|
|
|
if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
|
|
|
|
// Don't die twice - run a busy loop.
|
|
|
|
while (1) { }
|
|
|
|
}
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
if (common_flags()->print_module_map >= 1) PrintModuleMap();
|
2012-11-12 16:53:47 +01:00
|
|
|
if (flags()->sleep_before_dying) {
|
|
|
|
Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying);
|
|
|
|
SleepForSeconds(flags()->sleep_before_dying);
|
|
|
|
}
|
2013-02-21 11:57:10 +01:00
|
|
|
if (flags()->unmap_shadow_on_exit) {
|
|
|
|
if (kMidMemBeg) {
|
|
|
|
UnmapOrDie((void*)kLowShadowBeg, kMidMemBeg - kLowShadowBeg);
|
|
|
|
UnmapOrDie((void*)kMidMemEnd, kHighShadowEnd - kMidMemEnd);
|
|
|
|
} else {
|
|
|
|
UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg);
|
|
|
|
}
|
|
|
|
}
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void AsanCheckFailed(const char *file, int line, const char *cond,
|
|
|
|
u64 v1, u64 v2) {
|
2014-05-22 09:09:21 +02:00
|
|
|
Report("AddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file,
|
|
|
|
line, cond, (uptr)v1, (uptr)v2);
|
2012-11-12 16:53:47 +01:00
|
|
|
// FIXME: check for infinite recursion without a thread-local counter here.
|
2014-11-13 21:41:38 +01:00
|
|
|
PRINT_CURRENT_STACK_CHECK();
|
2013-01-10 13:44:08 +01:00
|
|
|
Die();
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------- Globals --------------------- {{{1
|
|
|
|
int asan_inited;
|
|
|
|
bool asan_init_is_running;
|
2013-02-21 11:57:10 +01:00
|
|
|
|
|
|
|
#if !ASAN_FIXED_MAPPING
|
|
|
|
uptr kHighMemEnd, kMidMemBeg, kMidMemEnd;
|
|
|
|
#endif
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// -------------------------- Misc ---------------- {{{1
|
|
|
|
void ShowStatsAndAbort() {
|
|
|
|
__asan_print_accumulated_stats();
|
|
|
|
Die();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------- LowLevelAllocateCallbac ---------- {{{1
|
|
|
|
static void OnLowLevelAllocate(uptr ptr, uptr size) {
|
|
|
|
PoisonShadow(ptr, size, kAsanInternalHeapMagic);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------- Run-time entry ------------------- {{{1
|
|
|
|
// exported functions
|
|
|
|
#define ASAN_REPORT_ERROR(type, is_write, size) \
|
2015-10-21 09:32:45 +02:00
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_report_ ## type ## size(uptr addr) { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, is_write, size, 0, true); \
|
2015-10-21 09:32:45 +02:00
|
|
|
} \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_report_exp_ ## type ## size(uptr addr, u32 exp) { \
|
2012-11-12 16:53:47 +01:00
|
|
|
GET_CALLER_PC_BP_SP; \
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, is_write, size, exp, true); \
|
|
|
|
} \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_report_ ## type ## size ## _noabort(uptr addr) { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
|
|
|
ReportGenericError(pc, bp, sp, addr, is_write, size, 0, false); \
|
|
|
|
} \
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
ASAN_REPORT_ERROR(load, false, 1)
|
|
|
|
ASAN_REPORT_ERROR(load, false, 2)
|
|
|
|
ASAN_REPORT_ERROR(load, false, 4)
|
|
|
|
ASAN_REPORT_ERROR(load, false, 8)
|
|
|
|
ASAN_REPORT_ERROR(load, false, 16)
|
|
|
|
ASAN_REPORT_ERROR(store, true, 1)
|
|
|
|
ASAN_REPORT_ERROR(store, true, 2)
|
|
|
|
ASAN_REPORT_ERROR(store, true, 4)
|
|
|
|
ASAN_REPORT_ERROR(store, true, 8)
|
|
|
|
ASAN_REPORT_ERROR(store, true, 16)
|
|
|
|
|
2015-11-23 10:07:18 +01:00
|
|
|
#define ASAN_REPORT_ERROR_N(type, is_write) \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_report_ ## type ## _n(uptr addr, uptr size) { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
|
|
|
ReportGenericError(pc, bp, sp, addr, is_write, size, 0, true); \
|
|
|
|
} \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
2015-10-21 09:32:45 +02:00
|
|
|
void __asan_report_exp_ ## type ## _n(uptr addr, uptr size, u32 exp) { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, is_write, size, exp, true); \
|
|
|
|
} \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_report_ ## type ## _n_noabort(uptr addr, uptr size) { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
|
|
|
ReportGenericError(pc, bp, sp, addr, is_write, size, 0, false); \
|
|
|
|
} \
|
2013-02-21 11:57:10 +01:00
|
|
|
|
|
|
|
ASAN_REPORT_ERROR_N(load, false)
|
|
|
|
ASAN_REPORT_ERROR_N(store, true)
|
|
|
|
|
2015-11-23 10:07:18 +01:00
|
|
|
#define ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, exp_arg, fatal) \
|
2014-05-22 09:09:21 +02:00
|
|
|
uptr sp = MEM_TO_SHADOW(addr); \
|
|
|
|
uptr s = size <= SHADOW_GRANULARITY ? *reinterpret_cast<u8 *>(sp) \
|
|
|
|
: *reinterpret_cast<u16 *>(sp); \
|
|
|
|
if (UNLIKELY(s)) { \
|
|
|
|
if (UNLIKELY(size >= SHADOW_GRANULARITY || \
|
|
|
|
((s8)((addr & (SHADOW_GRANULARITY - 1)) + size - 1)) >= \
|
|
|
|
(s8)s)) { \
|
|
|
|
if (__asan_test_only_reported_buggy_pointer) { \
|
|
|
|
*__asan_test_only_reported_buggy_pointer = addr; \
|
|
|
|
} else { \
|
|
|
|
GET_CALLER_PC_BP_SP; \
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, is_write, size, exp_arg, \
|
|
|
|
fatal); \
|
2014-05-22 09:09:21 +02:00
|
|
|
} \
|
|
|
|
} \
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ASAN_MEMORY_ACCESS_CALLBACK(type, is_write, size) \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_##type##size(uptr addr) { \
|
2015-11-23 10:07:18 +01:00
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, 0, true) \
|
2015-10-21 09:32:45 +02:00
|
|
|
} \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_exp_##type##size(uptr addr, u32 exp) { \
|
2015-11-23 10:07:18 +01:00
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, exp, true) \
|
|
|
|
} \
|
|
|
|
extern "C" NOINLINE INTERFACE_ATTRIBUTE \
|
|
|
|
void __asan_##type##size ## _noabort(uptr addr) { \
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, 0, false) \
|
|
|
|
} \
|
2014-05-22 09:09:21 +02:00
|
|
|
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(load, false, 1)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(load, false, 2)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(load, false, 4)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(load, false, 8)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(load, false, 16)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(store, true, 1)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(store, true, 2)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(store, true, 4)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(store, true, 8)
|
|
|
|
ASAN_MEMORY_ACCESS_CALLBACK(store, true, 16)
|
|
|
|
|
|
|
|
extern "C"
|
2015-10-21 09:32:45 +02:00
|
|
|
NOINLINE INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_loadN(uptr addr, uptr size) {
|
2014-05-22 09:09:21 +02:00
|
|
|
if (__asan_region_is_poisoned(addr, size)) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, false, size, 0, true);
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
2015-10-21 09:32:45 +02:00
|
|
|
NOINLINE INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_exp_loadN(uptr addr, uptr size, u32 exp) {
|
2014-05-22 09:09:21 +02:00
|
|
|
if (__asan_region_is_poisoned(addr, size)) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, false, size, exp, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
NOINLINE INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_loadN_noabort(uptr addr, uptr size) {
|
|
|
|
if (__asan_region_is_poisoned(addr, size)) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
ReportGenericError(pc, bp, sp, addr, false, size, 0, false);
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
NOINLINE INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_storeN(uptr addr, uptr size) {
|
|
|
|
if (__asan_region_is_poisoned(addr, size)) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, true, size, 0, true);
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
NOINLINE INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_exp_storeN(uptr addr, uptr size, u32 exp) {
|
|
|
|
if (__asan_region_is_poisoned(addr, size)) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
2015-11-23 10:07:18 +01:00
|
|
|
ReportGenericError(pc, bp, sp, addr, true, size, exp, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
NOINLINE INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_storeN_noabort(uptr addr, uptr size) {
|
|
|
|
if (__asan_region_is_poisoned(addr, size)) {
|
|
|
|
GET_CALLER_PC_BP_SP;
|
|
|
|
ReportGenericError(pc, bp, sp, addr, true, size, 0, false);
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
// Force the linker to keep the symbols for various ASan interface functions.
|
|
|
|
// We want to keep those in the executable in order to let the instrumented
|
|
|
|
// dynamic libraries access the symbol even if it is not used by the executable
|
|
|
|
// itself. This should help if the build system is removing dead code at link
|
|
|
|
// time.
|
|
|
|
static NOINLINE void force_interface_symbols() {
|
|
|
|
volatile int fake_condition = 0; // prevent dead condition elimination.
|
|
|
|
// __asan_report_* functions are noreturn, so we need a switch to prevent
|
|
|
|
// the compiler from removing any of them.
|
2016-11-08 23:04:09 +01:00
|
|
|
// clang-format off
|
2012-11-12 16:53:47 +01:00
|
|
|
switch (fake_condition) {
|
|
|
|
case 1: __asan_report_load1(0); break;
|
|
|
|
case 2: __asan_report_load2(0); break;
|
|
|
|
case 3: __asan_report_load4(0); break;
|
|
|
|
case 4: __asan_report_load8(0); break;
|
|
|
|
case 5: __asan_report_load16(0); break;
|
2015-10-21 09:32:45 +02:00
|
|
|
case 6: __asan_report_load_n(0, 0); break;
|
|
|
|
case 7: __asan_report_store1(0); break;
|
|
|
|
case 8: __asan_report_store2(0); break;
|
|
|
|
case 9: __asan_report_store4(0); break;
|
|
|
|
case 10: __asan_report_store8(0); break;
|
|
|
|
case 11: __asan_report_store16(0); break;
|
|
|
|
case 12: __asan_report_store_n(0, 0); break;
|
|
|
|
case 13: __asan_report_exp_load1(0, 0); break;
|
|
|
|
case 14: __asan_report_exp_load2(0, 0); break;
|
|
|
|
case 15: __asan_report_exp_load4(0, 0); break;
|
|
|
|
case 16: __asan_report_exp_load8(0, 0); break;
|
|
|
|
case 17: __asan_report_exp_load16(0, 0); break;
|
|
|
|
case 18: __asan_report_exp_load_n(0, 0, 0); break;
|
|
|
|
case 19: __asan_report_exp_store1(0, 0); break;
|
|
|
|
case 20: __asan_report_exp_store2(0, 0); break;
|
|
|
|
case 21: __asan_report_exp_store4(0, 0); break;
|
|
|
|
case 22: __asan_report_exp_store8(0, 0); break;
|
|
|
|
case 23: __asan_report_exp_store16(0, 0); break;
|
|
|
|
case 24: __asan_report_exp_store_n(0, 0, 0); break;
|
|
|
|
case 25: __asan_register_globals(nullptr, 0); break;
|
|
|
|
case 26: __asan_unregister_globals(nullptr, 0); break;
|
|
|
|
case 27: __asan_set_death_callback(nullptr); break;
|
|
|
|
case 28: __asan_set_error_report_callback(nullptr); break;
|
|
|
|
case 29: __asan_handle_no_return(); break;
|
|
|
|
case 30: __asan_address_is_poisoned(nullptr); break;
|
|
|
|
case 31: __asan_poison_memory_region(nullptr, 0); break;
|
|
|
|
case 32: __asan_unpoison_memory_region(nullptr, 0); break;
|
|
|
|
case 34: __asan_before_dynamic_init(nullptr); break;
|
|
|
|
case 35: __asan_after_dynamic_init(); break;
|
|
|
|
case 36: __asan_poison_stack_memory(0, 0); break;
|
|
|
|
case 37: __asan_unpoison_stack_memory(0, 0); break;
|
|
|
|
case 38: __asan_region_is_poisoned(0, 0); break;
|
|
|
|
case 39: __asan_describe_address(0); break;
|
2016-11-08 23:04:09 +01:00
|
|
|
case 40: __asan_set_shadow_00(0, 0); break;
|
|
|
|
case 41: __asan_set_shadow_f1(0, 0); break;
|
|
|
|
case 42: __asan_set_shadow_f2(0, 0); break;
|
|
|
|
case 43: __asan_set_shadow_f3(0, 0); break;
|
|
|
|
case 44: __asan_set_shadow_f5(0, 0); break;
|
|
|
|
case 45: __asan_set_shadow_f8(0, 0); break;
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
// clang-format on
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void asan_atexit() {
|
|
|
|
Printf("AddressSanitizer exit stats:\n");
|
|
|
|
__asan_print_accumulated_stats();
|
2013-02-21 11:57:10 +01:00
|
|
|
// Print AsanMappingProfile.
|
|
|
|
for (uptr i = 0; i < kAsanMappingProfileSize; i++) {
|
|
|
|
if (AsanMappingProfile[i] == 0) continue;
|
|
|
|
Printf("asan_mapping.h:%zd -- %zd\n", i, AsanMappingProfile[i]);
|
|
|
|
}
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2013-02-13 11:46:01 +01:00
|
|
|
static void InitializeHighMemEnd() {
|
2013-02-21 11:57:10 +01:00
|
|
|
#if !ASAN_FIXED_MAPPING
|
2013-11-04 22:33:31 +01:00
|
|
|
kHighMemEnd = GetMaxVirtualAddress();
|
|
|
|
// Increase kHighMemEnd to make sure it's properly
|
|
|
|
// aligned together with kHighMemBeg:
|
2016-11-08 23:04:09 +01:00
|
|
|
kHighMemEnd |= SHADOW_GRANULARITY * GetMmapGranularity() - 1;
|
2013-02-21 11:57:10 +01:00
|
|
|
#endif // !ASAN_FIXED_MAPPING
|
2016-11-08 23:04:09 +01:00
|
|
|
CHECK_EQ((kHighMemBeg % GetMmapGranularity()), 0);
|
2013-02-21 11:57:10 +01:00
|
|
|
}
|
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
void PrintAddressSpaceLayout() {
|
2013-02-21 11:57:10 +01:00
|
|
|
Printf("|| `[%p, %p]` || HighMem ||\n",
|
|
|
|
(void*)kHighMemBeg, (void*)kHighMemEnd);
|
|
|
|
Printf("|| `[%p, %p]` || HighShadow ||\n",
|
|
|
|
(void*)kHighShadowBeg, (void*)kHighShadowEnd);
|
|
|
|
if (kMidMemBeg) {
|
|
|
|
Printf("|| `[%p, %p]` || ShadowGap3 ||\n",
|
|
|
|
(void*)kShadowGap3Beg, (void*)kShadowGap3End);
|
|
|
|
Printf("|| `[%p, %p]` || MidMem ||\n",
|
|
|
|
(void*)kMidMemBeg, (void*)kMidMemEnd);
|
|
|
|
Printf("|| `[%p, %p]` || ShadowGap2 ||\n",
|
|
|
|
(void*)kShadowGap2Beg, (void*)kShadowGap2End);
|
|
|
|
Printf("|| `[%p, %p]` || MidShadow ||\n",
|
|
|
|
(void*)kMidShadowBeg, (void*)kMidShadowEnd);
|
|
|
|
}
|
|
|
|
Printf("|| `[%p, %p]` || ShadowGap ||\n",
|
|
|
|
(void*)kShadowGapBeg, (void*)kShadowGapEnd);
|
|
|
|
if (kLowShadowBeg) {
|
|
|
|
Printf("|| `[%p, %p]` || LowShadow ||\n",
|
|
|
|
(void*)kLowShadowBeg, (void*)kLowShadowEnd);
|
|
|
|
Printf("|| `[%p, %p]` || LowMem ||\n",
|
|
|
|
(void*)kLowMemBeg, (void*)kLowMemEnd);
|
|
|
|
}
|
|
|
|
Printf("MemToShadow(shadow): %p %p %p %p",
|
|
|
|
(void*)MEM_TO_SHADOW(kLowShadowBeg),
|
|
|
|
(void*)MEM_TO_SHADOW(kLowShadowEnd),
|
|
|
|
(void*)MEM_TO_SHADOW(kHighShadowBeg),
|
|
|
|
(void*)MEM_TO_SHADOW(kHighShadowEnd));
|
|
|
|
if (kMidMemBeg) {
|
|
|
|
Printf(" %p %p",
|
|
|
|
(void*)MEM_TO_SHADOW(kMidShadowBeg),
|
|
|
|
(void*)MEM_TO_SHADOW(kMidShadowEnd));
|
|
|
|
}
|
|
|
|
Printf("\n");
|
2014-05-22 09:09:21 +02:00
|
|
|
Printf("redzone=%zu\n", (uptr)flags()->redzone);
|
|
|
|
Printf("max_redzone=%zu\n", (uptr)flags()->max_redzone);
|
2015-10-21 09:32:45 +02:00
|
|
|
Printf("quarantine_size_mb=%zuM\n", (uptr)flags()->quarantine_size_mb);
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
Printf("thread_local_quarantine_size_kb=%zuK\n",
|
|
|
|
(uptr)flags()->thread_local_quarantine_size_kb);
|
2013-11-04 22:33:31 +01:00
|
|
|
Printf("malloc_context_size=%zu\n",
|
|
|
|
(uptr)common_flags()->malloc_context_size);
|
2013-02-21 11:57:10 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
Printf("SHADOW_SCALE: %d\n", (int)SHADOW_SCALE);
|
|
|
|
Printf("SHADOW_GRANULARITY: %d\n", (int)SHADOW_GRANULARITY);
|
|
|
|
Printf("SHADOW_OFFSET: 0x%zx\n", (uptr)SHADOW_OFFSET);
|
2013-02-21 11:57:10 +01:00
|
|
|
CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7);
|
|
|
|
if (kMidMemBeg)
|
|
|
|
CHECK(kMidShadowBeg > kLowShadowEnd &&
|
|
|
|
kMidMemBeg > kMidShadowEnd &&
|
|
|
|
kHighShadowBeg > kMidMemEnd);
|
2013-02-13 11:46:01 +01:00
|
|
|
}
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
static void AsanInitInternal() {
|
|
|
|
if (LIKELY(asan_inited)) return;
|
2013-02-13 11:46:01 +01:00
|
|
|
SanitizerToolName = "AddressSanitizer";
|
2012-11-12 16:53:47 +01:00
|
|
|
CHECK(!asan_init_is_running && "ASan init calls itself!");
|
|
|
|
asan_init_is_running = true;
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
CacheBinaryName();
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
// Initialize flags. This must be done early, because most of the
|
|
|
|
// initialization steps look at flags().
|
2015-10-21 09:32:45 +02:00
|
|
|
InitializeFlags();
|
|
|
|
|
|
|
|
AsanCheckIncompatibleRT();
|
|
|
|
AsanCheckDynamicRTPrereqs();
|
2016-11-08 23:04:09 +01:00
|
|
|
AvoidCVE_2016_2143();
|
2015-10-21 09:32:45 +02:00
|
|
|
|
|
|
|
SetCanPoisonMemory(flags()->poison_heap);
|
|
|
|
SetMallocContextSize(common_flags()->malloc_context_size);
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
InitializePlatformExceptionHandlers();
|
|
|
|
|
2013-02-13 11:46:01 +01:00
|
|
|
InitializeHighMemEnd();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// Make sure we are not statically linked.
|
|
|
|
AsanDoesNotSupportStaticLinkage();
|
|
|
|
|
|
|
|
// Install tool-specific callbacks in sanitizer_common.
|
2015-10-21 09:32:45 +02:00
|
|
|
AddDieCallback(AsanDie);
|
2012-11-12 16:53:47 +01:00
|
|
|
SetCheckFailedCallback(AsanCheckFailed);
|
|
|
|
SetPrintfAndReportCallback(AppendToErrorMessageBuffer);
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
__sanitizer_set_report_path(common_flags()->log_path);
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
__asan_option_detect_stack_use_after_return =
|
|
|
|
flags()->detect_stack_use_after_return;
|
2014-05-22 09:09:21 +02:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
// Re-exec ourselves if we need to set additional env or command line args.
|
|
|
|
MaybeReexec();
|
|
|
|
|
|
|
|
// Setup internal allocator callback.
|
|
|
|
SetLowLevelAllocateCallback(OnLowLevelAllocate);
|
|
|
|
|
|
|
|
InitializeAsanInterceptors();
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
// Enable system log ("adb logcat") on Android.
|
|
|
|
// Doing this before interceptors are initialized crashes in:
|
|
|
|
// AsanInitInternal -> android_log_write -> __interceptor_strcmp
|
|
|
|
AndroidLogInit();
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
ReplaceSystemMalloc();
|
|
|
|
|
2014-09-23 19:59:53 +02:00
|
|
|
DisableCoreDumperIfNecessary();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
InitializeShadowMemory();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
AsanTSDInit(PlatformTSDDtor);
|
2015-10-21 09:32:45 +02:00
|
|
|
InstallDeadlySignalHandlers(AsanOnDeadlySignal);
|
|
|
|
|
|
|
|
AllocatorOptions allocator_options;
|
|
|
|
allocator_options.SetFrom(flags(), common_flags());
|
|
|
|
InitializeAllocator(allocator_options);
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
MaybeStartBackgroudThread();
|
|
|
|
SetSoftRssLimitExceededCallback(AsanSoftRssLimitExceededCallback);
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
// On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited
|
|
|
|
// should be set to 1 prior to initializing the threads.
|
|
|
|
asan_inited = 1;
|
|
|
|
asan_init_is_running = false;
|
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
if (flags()->atexit)
|
|
|
|
Atexit(asan_atexit);
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
|
|
|
|
|
|
|
|
// Now that ASan runtime is (mostly) initialized, deactivate it if
|
|
|
|
// necessary, so that it can be re-activated when requested.
|
|
|
|
if (flags()->start_deactivated)
|
|
|
|
AsanDeactivate();
|
2013-12-05 10:18:38 +01:00
|
|
|
|
|
|
|
// interceptors
|
2013-11-04 22:33:31 +01:00
|
|
|
InitTlsSize();
|
|
|
|
|
|
|
|
// Create main thread.
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
AsanThread *main_thread = CreateMainThread();
|
2015-10-21 09:32:45 +02:00
|
|
|
CHECK_EQ(0, main_thread->tid());
|
2012-11-12 16:53:47 +01:00
|
|
|
force_interface_symbols(); // no-op.
|
2014-05-22 09:09:21 +02:00
|
|
|
SanitizerInitializeUnwinder();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
if (CAN_SANITIZE_LEAKS) {
|
|
|
|
__lsan::InitCommonLsan();
|
|
|
|
if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
if (flags()->halt_on_error)
|
|
|
|
Atexit(__lsan::DoLeakCheck);
|
|
|
|
else
|
|
|
|
Atexit(__lsan::DoRecoverableLeakCheckVoid);
|
2016-11-08 23:04:09 +01:00
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
}
|
2013-02-13 11:46:01 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#if CAN_SANITIZE_UB
|
|
|
|
__ubsan::InitAsPlugin();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
InitializeSuppressions();
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
if (CAN_SANITIZE_LEAKS) {
|
|
|
|
// LateInitialize() calls dlsym, which can allocate an error string buffer
|
|
|
|
// in the TLS. Let's ignore the allocation to avoid reporting a leak.
|
|
|
|
__lsan::ScopedInterceptorDisabler disabler;
|
|
|
|
Symbolizer::LateInitialize();
|
|
|
|
} else {
|
|
|
|
Symbolizer::LateInitialize();
|
|
|
|
}
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
VReport(1, "AddressSanitizer Init done\n");
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
|
|
|
|
if (flags()->sleep_after_init) {
|
|
|
|
Report("Sleeping for %d second(s)\n", flags()->sleep_after_init);
|
|
|
|
SleepForSeconds(flags()->sleep_after_init);
|
|
|
|
}
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize as requested from some part of ASan runtime library (interceptors,
|
|
|
|
// allocator, etc).
|
|
|
|
void AsanInitFromRtl() {
|
|
|
|
AsanInitInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ASAN_DYNAMIC
|
|
|
|
// Initialize runtime in case it's LD_PRELOAD-ed into unsanitized executable
|
2015-10-21 09:32:45 +02:00
|
|
|
// (and thus normal initializers from .preinit_array or modules haven't run).
|
2014-05-22 09:09:21 +02:00
|
|
|
|
|
|
|
class AsanInitializer {
|
|
|
|
public: // NOLINT
|
|
|
|
AsanInitializer() {
|
2015-10-21 09:32:45 +02:00
|
|
|
AsanInitFromRtl();
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2014-05-22 09:09:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static AsanInitializer asan_initializer;
|
|
|
|
#endif // ASAN_DYNAMIC
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
} // namespace __asan
|
2014-05-22 09:09:21 +02:00
|
|
|
|
|
|
|
// ---------------------- Interface ---------------- {{{1
|
|
|
|
using namespace __asan; // NOLINT
|
|
|
|
|
|
|
|
void NOINLINE __asan_handle_no_return() {
|
2016-11-08 23:04:09 +01:00
|
|
|
if (asan_init_is_running)
|
|
|
|
return;
|
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
int local_stack;
|
|
|
|
AsanThread *curr_thread = GetCurrentThread();
|
|
|
|
uptr PageSize = GetPageSizeCached();
|
2015-10-21 09:32:45 +02:00
|
|
|
uptr top, bottom;
|
|
|
|
if (curr_thread) {
|
|
|
|
top = curr_thread->stack_top();
|
|
|
|
bottom = ((uptr)&local_stack - PageSize) & ~(PageSize - 1);
|
|
|
|
} else {
|
ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch builtins...
* ubsan.c (ubsan_expand_null_ifn): Use _v1 suffixed type mismatch
builtins, store max (log2 (align), 0) into uchar field instead of
align into uptr field.
(ubsan_expand_objsize_ifn): Use _v1 suffixed type mismatch builtins,
store uchar 0 field instead of uptr 0 field.
(instrument_nonnull_return): Use _v1 suffixed nonnull return builtin,
instead of passing one address of struct with 2 locations pass
two addresses of structs with 1 location each.
* sanitizer.def (BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_ABORT): Removed.
(BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1,
BUILT_IN_UBSAN_HANDLE_TYPE_MISMATCH_V1_ABORT,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1,
BUILT_IN_UBSAN_HANDLE_NONNULL_RETURN_V1_ABORT): New builtins.
* c-c++-common/ubsan/float-cast-overflow-1.c: Drop value keyword
from expected output regexps.
* c-c++-common/ubsan/float-cast-overflow-2.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-3.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-4.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-5.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-6.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-8.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-9.c: Likewise.
* c-c++-common/ubsan/float-cast-overflow-10.c: Likewise.
* g++.dg/ubsan/float-cast-overflow-bf.C: Likewise.
* gcc.dg/ubsan/float-cast-overflow-bf.c: Likewise.
* g++.dg/asan/default-options-1.C (__asan_default_options): Add
used attribute.
* g++.dg/asan/asan_test.C: Run with ASAN_OPTIONS=handle_segv=2
in the environment.
* All source files: Merge from upstream 315899.
* asan/Makefile.am (nodist_saninclude_HEADERS): Add
include/sanitizer/tsan_interface.h.
* asan/libtool-version: Bump the libasan SONAME.
* lsan/Makefile.am (sanitizer_lsan_files): Add lsan_common_mac.cc.
(lsan_files): Add lsan_linux.cc, lsan_mac.cc and lsan_malloc_mac.cc.
* sanitizer_common/Makefile.am (sanitizer_common_files): Add
sancov_flags.cc, sanitizer_allocator_checks.cc,
sanitizer_coverage_libcdep_new.cc, sanitizer_errno.cc,
sanitizer_file.cc, sanitizer_mac_libcdep.cc and
sanitizer_stoptheworld_mac.cc. Remove sanitizer_coverage_libcdep.cc
and sanitizer_coverage_mapping_libcdep.cc.
* tsan/Makefile.am (tsan_files): Add tsan_external.cc.
* ubsan/Makefile.am (DEFS): Add -DUBSAN_CAN_USE_CXXABI=1.
(ubsan_files): Add ubsan_init_standalone.cc and
ubsan_signals_standalone.cc.
* ubsan/libtool-version: Bump the libubsan SONAME.
* asan/Makefile.in: Regenerate.
* lsan/Makefile.in: Regenerate.
* sanitizer_common/Makefile.in: Regenerate.
* tsan/Makefile.in: Regenerate.
* ubsan/Makefile.in: Regenerate.
From-SVN: r253887
2017-10-19 13:23:59 +02:00
|
|
|
CHECK(!SANITIZER_FUCHSIA);
|
2015-10-21 09:32:45 +02:00
|
|
|
// If we haven't seen this thread, try asking the OS for stack bounds.
|
|
|
|
uptr tls_addr, tls_size, stack_size;
|
|
|
|
GetThreadStackAndTls(/*main=*/false, &bottom, &stack_size, &tls_addr,
|
|
|
|
&tls_size);
|
|
|
|
top = bottom + stack_size;
|
|
|
|
}
|
2014-05-22 09:09:21 +02:00
|
|
|
static const uptr kMaxExpectedCleanupSize = 64 << 20; // 64M
|
|
|
|
if (top - bottom > kMaxExpectedCleanupSize) {
|
|
|
|
static bool reported_warning = false;
|
|
|
|
if (reported_warning)
|
|
|
|
return;
|
|
|
|
reported_warning = true;
|
|
|
|
Report("WARNING: ASan is ignoring requested __asan_handle_no_return: "
|
|
|
|
"stack top: %p; bottom %p; size: %p (%zd)\n"
|
|
|
|
"False positive error reports may follow\n"
|
|
|
|
"For details see "
|
2016-11-08 23:04:09 +01:00
|
|
|
"https://github.com/google/sanitizers/issues/189\n",
|
2014-05-22 09:09:21 +02:00
|
|
|
top, bottom, top - bottom, top - bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PoisonShadow(bottom, top - bottom, 0);
|
2015-10-21 09:32:45 +02:00
|
|
|
if (curr_thread && curr_thread->has_fake_stack())
|
2014-05-22 09:09:21 +02:00
|
|
|
curr_thread->fake_stack()->HandleNoReturn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NOINLINE __asan_set_death_callback(void (*callback)(void)) {
|
2015-10-21 09:32:45 +02:00
|
|
|
SetUserDieCallback(callback);
|
2014-05-22 09:09:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize as requested from instrumented application code.
|
|
|
|
// We use this call as a trigger to wake up ASan from deactivated state.
|
|
|
|
void __asan_init() {
|
|
|
|
AsanActivate();
|
|
|
|
AsanInitInternal();
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
|
|
|
|
void __asan_version_mismatch_check() {
|
|
|
|
// Do nothing.
|
|
|
|
}
|