2019-08-14 10:47:11 +02:00
|
|
|
//===-- asan_interceptors.cpp ---------------------------------------------===//
|
2012-11-12 16:53:47 +01:00
|
|
|
//
|
2019-08-14 10:47:11 +02: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
|
2012-11-12 16:53:47 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Intercept various libc functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#include "asan_interceptors.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "asan_allocator.h"
|
|
|
|
#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"
|
2016-11-08 23:04:09 +01:00
|
|
|
#include "lsan/lsan_common.h"
|
2012-11-12 16:53:47 +01:00
|
|
|
#include "sanitizer_common/sanitizer_libc.h"
|
|
|
|
|
2021-07-20 19:44:37 +02:00
|
|
|
// There is no general interception at all on Fuchsia.
|
2019-08-14 10:47:11 +02:00
|
|
|
// Only the functions in asan_interceptors_memintrinsics.cpp are
|
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
|
|
|
// really defined to replace libc functions.
|
2021-07-20 19:44:37 +02:00
|
|
|
#if !SANITIZER_FUCHSIA
|
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
|
|
|
|
2021-07-20 19:44:37 +02:00
|
|
|
# if SANITIZER_POSIX
|
|
|
|
# include "sanitizer_common/sanitizer_posix.h"
|
|
|
|
# endif
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2021-07-20 19:44:37 +02:00
|
|
|
# if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION || \
|
|
|
|
ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
|
|
|
|
# include <unwind.h>
|
|
|
|
# endif
|
2018-10-31 12:14:23 +01:00
|
|
|
|
2021-07-20 19:44:37 +02:00
|
|
|
# if defined(__i386) && SANITIZER_LINUX
|
|
|
|
# define ASAN_PTHREAD_CREATE_VERSION "GLIBC_2.1"
|
|
|
|
# elif defined(__mips__) && SANITIZER_LINUX
|
|
|
|
# define ASAN_PTHREAD_CREATE_VERSION "GLIBC_2.2"
|
|
|
|
# endif
|
2015-10-21 09:32:45 +02:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
namespace __asan {
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#define ASAN_READ_STRING_OF_LEN(ctx, s, len, n) \
|
|
|
|
ASAN_READ_RANGE((ctx), (s), \
|
|
|
|
common_flags()->strict_string_checks ? (len) + 1 : (n))
|
|
|
|
|
|
|
|
#define ASAN_READ_STRING(ctx, s, n) \
|
|
|
|
ASAN_READ_STRING_OF_LEN((ctx), (s), REAL(strlen)(s), (n))
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
|
2016-11-08 23:04:09 +01:00
|
|
|
#if SANITIZER_INTERCEPT_STRNLEN
|
2015-10-21 09:32:45 +02:00
|
|
|
if (REAL(strnlen)) {
|
2012-11-12 16:53:47 +01:00
|
|
|
return REAL(strnlen)(s, maxlen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return internal_strnlen(s, maxlen);
|
|
|
|
}
|
|
|
|
|
2013-01-23 12:41:33 +01:00
|
|
|
void SetThreadName(const char *name) {
|
2013-11-04 22:33:31 +01:00
|
|
|
AsanThread *t = GetCurrentThread();
|
2013-01-23 12:41:33 +01:00
|
|
|
if (t)
|
2013-11-04 22:33:31 +01:00
|
|
|
asanThreadRegistry().SetThreadName(t->tid(), name);
|
2013-01-23 12:41:33 +01:00
|
|
|
}
|
|
|
|
|
2013-12-05 10:18:38 +01:00
|
|
|
int OnExit() {
|
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 (CAN_SANITIZE_LEAKS && common_flags()->detect_leaks &&
|
|
|
|
__lsan::HasReportedLeaks()) {
|
|
|
|
return common_flags()->exitcode;
|
|
|
|
}
|
2013-12-05 10:18:38 +01:00
|
|
|
// FIXME: ask frontend whether we need to return failure.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
} // namespace __asan
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// ---------------------- Wrappers ---------------- {{{1
|
2019-11-05 14:54:57 +01:00
|
|
|
using namespace __asan;
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr)
|
|
|
|
DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
#define ASAN_INTERCEPTOR_ENTER(ctx, func) \
|
|
|
|
AsanInterceptorContext _ctx = {#func}; \
|
|
|
|
ctx = (void *)&_ctx; \
|
|
|
|
(void) ctx; \
|
2013-12-05 10:18:38 +01:00
|
|
|
|
|
|
|
#define COMMON_INTERCEPT_FUNCTION(name) ASAN_INTERCEPT_FUNC(name)
|
2021-03-08 15:52:03 +01:00
|
|
|
#define COMMON_INTERCEPT_FUNCTION_VER(name, ver) \
|
2016-11-08 23:04:09 +01:00
|
|
|
ASAN_INTERCEPT_FUNC_VER(name, ver)
|
2021-03-08 15:52:03 +01:00
|
|
|
#define COMMON_INTERCEPT_FUNCTION_VER_UNVERSIONED_FALLBACK(name, ver) \
|
|
|
|
ASAN_INTERCEPT_FUNC_VER_UNVERSIONED_FALLBACK(name, ver)
|
2013-01-23 12:41:33 +01:00
|
|
|
#define COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ptr, size) \
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_WRITE_RANGE(ctx, ptr, size)
|
|
|
|
#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) \
|
|
|
|
ASAN_READ_RANGE(ctx, ptr, size)
|
2014-05-22 09:09:21 +02:00
|
|
|
#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, func); \
|
2014-05-22 09:09:21 +02:00
|
|
|
do { \
|
|
|
|
if (asan_init_is_running) \
|
|
|
|
return REAL(func)(__VA_ARGS__); \
|
|
|
|
if (SANITIZER_MAC && UNLIKELY(!asan_inited)) \
|
|
|
|
return REAL(func)(__VA_ARGS__); \
|
|
|
|
ENSURE_ASAN_INITED(); \
|
2013-11-04 22:33:31 +01:00
|
|
|
} while (false)
|
2015-10-21 09:32:45 +02:00
|
|
|
#define COMMON_INTERCEPTOR_DIR_ACQUIRE(ctx, path) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
2013-11-04 22:33:31 +01:00
|
|
|
#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
|
|
|
#define COMMON_INTERCEPTOR_FD_RELEASE(ctx, fd) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
|
|
|
#define COMMON_INTERCEPTOR_FD_SOCKET_ACCEPT(ctx, fd, newfd) \
|
|
|
|
do { \
|
2013-01-23 12:41:33 +01:00
|
|
|
} while (false)
|
|
|
|
#define COMMON_INTERCEPTOR_SET_THREAD_NAME(ctx, name) SetThreadName(name)
|
2013-12-05 10:18:38 +01:00
|
|
|
// Should be asanThreadRegistry().SetThreadNameByUserId(thread, name)
|
|
|
|
// But asan does not remember UserId's for threads (pthread_t);
|
|
|
|
// and remembers all ever existed threads, so the linear search by UserId
|
|
|
|
// can be slow.
|
|
|
|
#define COMMON_INTERCEPTOR_SET_PTHREAD_NAME(ctx, thread, name) \
|
|
|
|
do { \
|
|
|
|
} while (false)
|
2013-11-04 22:33:31 +01:00
|
|
|
#define COMMON_INTERCEPTOR_BLOCK_REAL(name) REAL(name)
|
2015-10-21 09:32:45 +02:00
|
|
|
// Strict init-order checking is dlopen-hostile:
|
2016-11-08 23:04:09 +01:00
|
|
|
// https://github.com/google/sanitizers/issues/178
|
2015-10-21 09:32:45 +02:00
|
|
|
#define COMMON_INTERCEPTOR_ON_DLOPEN(filename, flag) \
|
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
|
|
|
do { \
|
|
|
|
if (flags()->strict_init_order) \
|
|
|
|
StopInitOrderChecking(); \
|
|
|
|
CheckNoDeepBind(filename, flag); \
|
|
|
|
} while (false)
|
2013-12-05 10:18:38 +01:00
|
|
|
#define COMMON_INTERCEPTOR_ON_EXIT(ctx) OnExit()
|
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
|
|
|
#define COMMON_INTERCEPTOR_LIBRARY_LOADED(filename, handle)
|
|
|
|
#define COMMON_INTERCEPTOR_LIBRARY_UNLOADED()
|
2014-09-23 19:59:53 +02:00
|
|
|
#define COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED (!asan_inited)
|
2015-10-21 09:32:45 +02:00
|
|
|
#define COMMON_INTERCEPTOR_GET_TLS_RANGE(begin, end) \
|
|
|
|
if (AsanThread *t = GetCurrentThread()) { \
|
|
|
|
*begin = t->tls_begin(); \
|
|
|
|
*end = t->tls_end(); \
|
|
|
|
} else { \
|
|
|
|
*begin = *end = 0; \
|
|
|
|
}
|
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
|
|
|
|
|
|
|
#define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size) \
|
|
|
|
do { \
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, memmove); \
|
|
|
|
ASAN_MEMMOVE_IMPL(ctx, to, from, size); \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size) \
|
|
|
|
do { \
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, memcpy); \
|
|
|
|
ASAN_MEMCPY_IMPL(ctx, to, from, size); \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size) \
|
|
|
|
do { \
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, memset); \
|
|
|
|
ASAN_MEMSET_IMPL(ctx, block, c, size); \
|
|
|
|
} while (false)
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
#if CAN_SANITIZE_LEAKS
|
|
|
|
#define COMMON_INTERCEPTOR_STRERROR() \
|
|
|
|
__lsan::ScopedInterceptorDisabler disabler
|
|
|
|
#endif
|
|
|
|
|
2013-01-23 12:41:33 +01:00
|
|
|
#include "sanitizer_common/sanitizer_common_interceptors.inc"
|
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
|
|
|
#include "sanitizer_common/sanitizer_signal_interceptors.inc"
|
2013-01-10 13:44:08 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
// Syscall interceptors don't have contexts, we don't support suppressions
|
|
|
|
// for them.
|
|
|
|
#define COMMON_SYSCALL_PRE_READ_RANGE(p, s) ASAN_READ_RANGE(nullptr, p, s)
|
|
|
|
#define COMMON_SYSCALL_PRE_WRITE_RANGE(p, s) ASAN_WRITE_RANGE(nullptr, p, s)
|
2013-11-04 22:33:31 +01:00
|
|
|
#define COMMON_SYSCALL_POST_READ_RANGE(p, s) \
|
|
|
|
do { \
|
2013-12-05 10:18:38 +01:00
|
|
|
(void)(p); \
|
|
|
|
(void)(s); \
|
2013-11-04 22:33:31 +01:00
|
|
|
} while (false)
|
|
|
|
#define COMMON_SYSCALL_POST_WRITE_RANGE(p, s) \
|
|
|
|
do { \
|
2013-12-05 10:18:38 +01:00
|
|
|
(void)(p); \
|
|
|
|
(void)(s); \
|
2013-11-04 22:33:31 +01:00
|
|
|
} while (false)
|
|
|
|
#include "sanitizer_common/sanitizer_common_syscalls.inc"
|
2018-10-31 12:14:23 +01:00
|
|
|
#include "sanitizer_common/sanitizer_syscalls_netbsd.inc"
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if ASAN_INTERCEPT_PTHREAD_CREATE
|
2012-11-12 16:53:47 +01:00
|
|
|
static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) {
|
2021-05-12 14:37:22 +02:00
|
|
|
AsanThread *t = (AsanThread *)arg;
|
2013-11-04 22:33:31 +01:00
|
|
|
SetCurrentThread(t);
|
2021-05-12 14:37:22 +02:00
|
|
|
return t->ThreadStart(GetTid());
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(int, pthread_create, void *thread,
|
|
|
|
void *attr, void *(*start_routine)(void*), void *arg) {
|
2013-11-04 22:33:31 +01:00
|
|
|
EnsureMainThreadIDIsCorrect();
|
2015-10-21 09:32:45 +02:00
|
|
|
// Strict init-order checking is thread-hostile.
|
2013-11-04 22:33:31 +01:00
|
|
|
if (flags()->strict_init_order)
|
|
|
|
StopInitOrderChecking();
|
2013-01-10 13:44:08 +01:00
|
|
|
GET_STACK_TRACE_THREAD;
|
2013-11-04 22:33:31 +01:00
|
|
|
int detached = 0;
|
2015-10-21 09:32:45 +02:00
|
|
|
if (attr)
|
2013-12-05 10:18:38 +01:00
|
|
|
REAL(pthread_attr_getdetachstate)(attr, &detached);
|
2021-05-12 14:37:22 +02:00
|
|
|
|
|
|
|
u32 current_tid = GetCurrentTidOrInvalid();
|
|
|
|
AsanThread *t =
|
|
|
|
AsanThread::Create(start_routine, arg, current_tid, &stack, detached);
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
int result;
|
|
|
|
{
|
|
|
|
// Ignore all allocations made by pthread_create: thread stack/TLS may be
|
|
|
|
// stored by pthread for future reuse even after thread destruction, and
|
|
|
|
// the linked list it's stored in doesn't even hold valid pointers to the
|
|
|
|
// objects, the latter are calculated by obscure pointer arithmetic.
|
|
|
|
#if CAN_SANITIZE_LEAKS
|
|
|
|
__lsan::ScopedInterceptorDisabler disabler;
|
|
|
|
#endif
|
2021-05-12 14:37:22 +02:00
|
|
|
result = REAL(pthread_create)(thread, attr, asan_thread_start, t);
|
2016-11-08 23:04:09 +01:00
|
|
|
}
|
2021-05-12 14:37:22 +02:00
|
|
|
if (result != 0) {
|
|
|
|
// If the thread didn't start delete the AsanThread to avoid leaking it.
|
|
|
|
// Note AsanThreadContexts never get destroyed so the AsanThreadContext
|
|
|
|
// that was just created for the AsanThread is wasted.
|
|
|
|
t->Destroy();
|
2015-10-21 09:32:45 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
INTERCEPTOR(int, pthread_join, void *t, void **arg) {
|
|
|
|
return real_pthread_join(t, arg);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2015-10-21 09:32:45 +02:00
|
|
|
|
|
|
|
DEFINE_REAL_PTHREAD_FUNCTIONS
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif // ASAN_INTERCEPT_PTHREAD_CREATE
|
|
|
|
|
2012-11-23 15:46:25 +01:00
|
|
|
#if ASAN_INTERCEPT_SWAPCONTEXT
|
2013-01-23 12:41:33 +01:00
|
|
|
static void ClearShadowMemoryForContextStack(uptr stack, uptr ssize) {
|
|
|
|
// Align to page size.
|
|
|
|
uptr PageSize = GetPageSizeCached();
|
|
|
|
uptr bottom = stack & ~(PageSize - 1);
|
|
|
|
ssize += stack - bottom;
|
|
|
|
ssize = RoundUpTo(ssize, PageSize);
|
|
|
|
static const uptr kMaxSaneContextStackSize = 1 << 22; // 4 Mb
|
2015-10-21 09:32:45 +02:00
|
|
|
if (AddrIsInMem(bottom) && ssize && ssize <= kMaxSaneContextStackSize) {
|
2013-01-23 12:41:33 +01:00
|
|
|
PoisonShadow(bottom, ssize, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-23 15:46:25 +01:00
|
|
|
INTERCEPTOR(int, swapcontext, struct ucontext_t *oucp,
|
|
|
|
struct ucontext_t *ucp) {
|
|
|
|
static bool reported_warning = false;
|
|
|
|
if (!reported_warning) {
|
|
|
|
Report("WARNING: ASan doesn't fully support makecontext/swapcontext "
|
|
|
|
"functions and may produce false positives in some cases!\n");
|
|
|
|
reported_warning = true;
|
|
|
|
}
|
|
|
|
// Clear shadow memory for new context (it may share stack
|
|
|
|
// with current context).
|
2013-01-23 12:41:33 +01:00
|
|
|
uptr stack, ssize;
|
|
|
|
ReadContextStack(ucp, &stack, &ssize);
|
|
|
|
ClearShadowMemoryForContextStack(stack, ssize);
|
2018-07-26 16:48:55 +02:00
|
|
|
#if __has_attribute(__indirect_return__) && \
|
|
|
|
(defined(__x86_64__) || defined(__i386__))
|
|
|
|
int (*real_swapcontext)(struct ucontext_t *, struct ucontext_t *)
|
|
|
|
__attribute__((__indirect_return__))
|
|
|
|
= REAL(swapcontext);
|
|
|
|
int res = real_swapcontext(oucp, ucp);
|
|
|
|
#else
|
2012-11-23 15:46:25 +01:00
|
|
|
int res = REAL(swapcontext)(oucp, ucp);
|
2018-07-26 16:48:55 +02:00
|
|
|
#endif
|
2012-11-23 15:46:25 +01:00
|
|
|
// swapcontext technically does not return, but program may swap context to
|
|
|
|
// "oucp" later, that would look as if swapcontext() returned 0.
|
|
|
|
// We need to clear shadow for ucp once again, as it may be in arbitrary
|
|
|
|
// state.
|
2013-01-23 12:41:33 +01:00
|
|
|
ClearShadowMemoryForContextStack(stack, ssize);
|
2012-11-23 15:46:25 +01:00
|
|
|
return res;
|
|
|
|
}
|
2013-01-23 12:41:33 +01:00
|
|
|
#endif // ASAN_INTERCEPT_SWAPCONTEXT
|
2012-11-23 15:46:25 +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
|
|
|
#if SANITIZER_NETBSD
|
|
|
|
#define longjmp __longjmp14
|
|
|
|
#define siglongjmp __siglongjmp14
|
|
|
|
#endif
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
INTERCEPTOR(void, longjmp, void *env, int val) {
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(longjmp)(env, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ASAN_INTERCEPT__LONGJMP
|
|
|
|
INTERCEPTOR(void, _longjmp, void *env, int val) {
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(_longjmp)(env, val);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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 ASAN_INTERCEPT___LONGJMP_CHK
|
|
|
|
INTERCEPTOR(void, __longjmp_chk, void *env, int val) {
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(__longjmp_chk)(env, val);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
#if ASAN_INTERCEPT_SIGLONGJMP
|
|
|
|
INTERCEPTOR(void, siglongjmp, void *env, int val) {
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(siglongjmp)(env, val);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ASAN_INTERCEPT___CXA_THROW
|
|
|
|
INTERCEPTOR(void, __cxa_throw, void *a, void *b, void *c) {
|
|
|
|
CHECK(REAL(__cxa_throw));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(__cxa_throw)(a, b, c);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
|
|
|
|
INTERCEPTOR(void, __cxa_rethrow_primary_exception, void *a) {
|
|
|
|
CHECK(REAL(__cxa_rethrow_primary_exception));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
REAL(__cxa_rethrow_primary_exception)(a);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION
|
|
|
|
INTERCEPTOR(_Unwind_Reason_Code, _Unwind_RaiseException,
|
|
|
|
_Unwind_Exception *object) {
|
|
|
|
CHECK(REAL(_Unwind_RaiseException));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
return REAL(_Unwind_RaiseException)(object);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
|
|
|
|
INTERCEPTOR(_Unwind_Reason_Code, _Unwind_SjLj_RaiseException,
|
|
|
|
_Unwind_Exception *object) {
|
|
|
|
CHECK(REAL(_Unwind_SjLj_RaiseException));
|
|
|
|
__asan_handle_no_return();
|
|
|
|
return REAL(_Unwind_SjLj_RaiseException)(object);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
#if ASAN_INTERCEPT_INDEX
|
|
|
|
# if ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
|
|
|
|
INTERCEPTOR(char*, index, const char *string, int c)
|
|
|
|
ALIAS(WRAPPER_NAME(strchr));
|
|
|
|
# else
|
2013-11-04 22:33:31 +01:00
|
|
|
# if SANITIZER_MAC
|
|
|
|
DECLARE_REAL(char*, index, const char *string, int c)
|
|
|
|
OVERRIDE_FUNCTION(index, strchr);
|
|
|
|
# else
|
2012-11-12 16:53:47 +01:00
|
|
|
DEFINE_REAL(char*, index, const char *string, int c)
|
2013-11-04 22:33:31 +01:00
|
|
|
# endif
|
2012-11-12 16:53:47 +01:00
|
|
|
# endif
|
|
|
|
#endif // ASAN_INTERCEPT_INDEX
|
|
|
|
|
|
|
|
// For both strcat() and strncat() we need to check the validity of |to|
|
|
|
|
// argument irrespective of the |from| length.
|
2019-11-05 14:54:57 +01:00
|
|
|
INTERCEPTOR(char *, strcat, char *to, const char *from) {
|
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strcat);
|
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (flags()->replace_str) {
|
|
|
|
uptr from_length = REAL(strlen)(from);
|
|
|
|
ASAN_READ_RANGE(ctx, from, from_length + 1);
|
|
|
|
uptr to_length = REAL(strlen)(to);
|
|
|
|
ASAN_READ_STRING_OF_LEN(ctx, to, to_length, to_length);
|
|
|
|
ASAN_WRITE_RANGE(ctx, to + to_length, from_length + 1);
|
|
|
|
// If the copying actually happens, the |from| string should not overlap
|
|
|
|
// with the resulting string starting at |to|, which has a length of
|
|
|
|
// to_length + from_length + 1.
|
|
|
|
if (from_length > 0) {
|
|
|
|
CHECK_RANGES_OVERLAP("strcat", to, from_length + to_length + 1, from,
|
|
|
|
from_length + 1);
|
|
|
|
}
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2019-11-05 14:54:57 +01:00
|
|
|
return REAL(strcat)(to, from);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strncat);
|
2012-11-12 16:53:47 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (flags()->replace_str) {
|
|
|
|
uptr from_length = MaybeRealStrnlen(from, size);
|
|
|
|
uptr copy_length = Min(size, from_length + 1);
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_RANGE(ctx, from, copy_length);
|
2012-11-12 16:53:47 +01:00
|
|
|
uptr to_length = REAL(strlen)(to);
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_STRING_OF_LEN(ctx, to, to_length, to_length);
|
|
|
|
ASAN_WRITE_RANGE(ctx, to + to_length, from_length + 1);
|
2012-11-12 16:53:47 +01:00
|
|
|
if (from_length > 0) {
|
|
|
|
CHECK_RANGES_OVERLAP("strncat", to, to_length + copy_length + 1,
|
|
|
|
from, copy_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return REAL(strncat)(to, from, size);
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
INTERCEPTOR(char *, strcpy, char *to, const char *from) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
2019-11-05 14:54:57 +01:00
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strcpy);
|
2013-11-04 22:33:31 +01:00
|
|
|
#if SANITIZER_MAC
|
2019-11-05 14:54:57 +01:00
|
|
|
if (UNLIKELY(!asan_inited))
|
|
|
|
return REAL(strcpy)(to, from);
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif
|
|
|
|
// strcpy is called from malloc_default_purgeable_zone()
|
|
|
|
// in __asan::ReplaceSystemAlloc() on Mac.
|
|
|
|
if (asan_init_is_running) {
|
2019-11-05 14:54:57 +01:00
|
|
|
return REAL(strcpy)(to, from);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (flags()->replace_str) {
|
|
|
|
uptr from_size = REAL(strlen)(from) + 1;
|
|
|
|
CHECK_RANGES_OVERLAP("strcpy", to, from_size, from, from_size);
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_RANGE(ctx, from, from_size);
|
|
|
|
ASAN_WRITE_RANGE(ctx, to, from_size);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2019-11-05 14:54:57 +01:00
|
|
|
return REAL(strcpy)(to, from);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(char*, strdup, const char *s) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
|
2014-05-22 09:09:21 +02:00
|
|
|
if (UNLIKELY(!asan_inited)) return internal_strdup(s);
|
2012-11-12 16:53:47 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
2013-11-04 22:33:31 +01:00
|
|
|
uptr length = REAL(strlen)(s);
|
2012-11-12 16:53:47 +01:00
|
|
|
if (flags()->replace_str) {
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_RANGE(ctx, s, length + 1);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2013-11-04 22:33:31 +01:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
|
|
|
void *new_mem = asan_malloc(length + 1, &stack);
|
|
|
|
REAL(memcpy)(new_mem, s, length + 1);
|
|
|
|
return reinterpret_cast<char*>(new_mem);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2016-11-08 23:04:09 +01:00
|
|
|
#if ASAN_INTERCEPT___STRDUP
|
|
|
|
INTERCEPTOR(char*, __strdup, const char *s) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
2016-11-08 23:04:09 +01:00
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strdup);
|
|
|
|
if (UNLIKELY(!asan_inited)) return internal_strdup(s);
|
2012-11-12 16:53:47 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
2016-11-08 23:04:09 +01:00
|
|
|
uptr length = REAL(strlen)(s);
|
2012-11-12 16:53:47 +01:00
|
|
|
if (flags()->replace_str) {
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_RANGE(ctx, s, length + 1);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
GET_STACK_TRACE_MALLOC;
|
|
|
|
void *new_mem = asan_malloc(length + 1, &stack);
|
|
|
|
REAL(memcpy)(new_mem, s, length + 1);
|
|
|
|
return reinterpret_cast<char*>(new_mem);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
#endif // ASAN_INTERCEPT___STRDUP
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
|
2012-11-12 16:53:47 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (flags()->replace_str) {
|
|
|
|
uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
|
|
|
|
CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size);
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_RANGE(ctx, from, from_size);
|
|
|
|
ASAN_WRITE_RANGE(ctx, to, size);
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
return REAL(strncpy)(to, from, size);
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
INTERCEPTOR(long, strtol, const char *nptr, char **endptr, int base) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strtol);
|
2012-11-12 16:53:47 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (!flags()->replace_str) {
|
|
|
|
return REAL(strtol)(nptr, endptr, base);
|
|
|
|
}
|
|
|
|
char *real_endptr;
|
2019-11-05 14:54:57 +01:00
|
|
|
long result = REAL(strtol)(nptr, &real_endptr, base);
|
2015-10-21 09:32:45 +02:00
|
|
|
StrtolFixAndCheck(ctx, nptr, endptr, real_endptr, base);
|
2012-11-12 16:53:47 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERCEPTOR(int, atoi, const char *nptr) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, atoi);
|
2013-11-04 22:33:31 +01:00
|
|
|
#if SANITIZER_MAC
|
2014-05-22 09:09:21 +02:00
|
|
|
if (UNLIKELY(!asan_inited)) return REAL(atoi)(nptr);
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif
|
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (!flags()->replace_str) {
|
|
|
|
return REAL(atoi)(nptr);
|
|
|
|
}
|
|
|
|
char *real_endptr;
|
|
|
|
// "man atoi" tells that behavior of atoi(nptr) is the same as
|
|
|
|
// strtol(nptr, 0, 10), i.e. it sets errno to ERANGE if the
|
|
|
|
// parsed integer can't be stored in *long* type (even if it's
|
|
|
|
// different from int). So, we just imitate this behavior.
|
|
|
|
int result = REAL(strtol)(nptr, &real_endptr, 10);
|
|
|
|
FixRealStrtolEndptr(nptr, &real_endptr);
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_STRING(ctx, nptr, (real_endptr - nptr) + 1);
|
2012-11-12 16:53:47 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
INTERCEPTOR(long, atol, const char *nptr) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, atol);
|
2013-11-04 22:33:31 +01:00
|
|
|
#if SANITIZER_MAC
|
2014-05-22 09:09:21 +02:00
|
|
|
if (UNLIKELY(!asan_inited)) return REAL(atol)(nptr);
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif
|
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (!flags()->replace_str) {
|
|
|
|
return REAL(atol)(nptr);
|
|
|
|
}
|
|
|
|
char *real_endptr;
|
2019-11-05 14:54:57 +01:00
|
|
|
long result = REAL(strtol)(nptr, &real_endptr, 10);
|
2012-11-12 16:53:47 +01:00
|
|
|
FixRealStrtolEndptr(nptr, &real_endptr);
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_STRING(ctx, nptr, (real_endptr - nptr) + 1);
|
2012-11-12 16:53:47 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ASAN_INTERCEPT_ATOLL_AND_STRTOLL
|
2019-11-05 14:54:57 +01:00
|
|
|
INTERCEPTOR(long long, strtoll, const char *nptr, char **endptr, int base) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, strtoll);
|
2012-11-12 16:53:47 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (!flags()->replace_str) {
|
|
|
|
return REAL(strtoll)(nptr, endptr, base);
|
|
|
|
}
|
|
|
|
char *real_endptr;
|
2019-11-05 14:54:57 +01:00
|
|
|
long long result = REAL(strtoll)(nptr, &real_endptr, base);
|
2015-10-21 09:32:45 +02:00
|
|
|
StrtolFixAndCheck(ctx, nptr, endptr, real_endptr, base);
|
2012-11-12 16:53:47 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
INTERCEPTOR(long long, atoll, const char *nptr) {
|
2015-10-21 09:32:45 +02:00
|
|
|
void *ctx;
|
|
|
|
ASAN_INTERCEPTOR_ENTER(ctx, atoll);
|
2012-11-12 16:53:47 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
if (!flags()->replace_str) {
|
|
|
|
return REAL(atoll)(nptr);
|
|
|
|
}
|
|
|
|
char *real_endptr;
|
2019-11-05 14:54:57 +01:00
|
|
|
long long result = REAL(strtoll)(nptr, &real_endptr, 10);
|
2012-11-12 16:53:47 +01:00
|
|
|
FixRealStrtolEndptr(nptr, &real_endptr);
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_READ_STRING(ctx, nptr, (real_endptr - nptr) + 1);
|
2012-11-12 16:53:47 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif // ASAN_INTERCEPT_ATOLL_AND_STRTOLL
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
#if ASAN_INTERCEPT___CXA_ATEXIT || ASAN_INTERCEPT_ATEXIT
|
2013-11-04 22:33:31 +01:00
|
|
|
static void AtCxaAtexit(void *unused) {
|
|
|
|
(void)unused;
|
|
|
|
StopInitOrderChecking();
|
|
|
|
}
|
2019-11-05 14:54:57 +01:00
|
|
|
#endif
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
#if ASAN_INTERCEPT___CXA_ATEXIT
|
2013-11-04 22:33:31 +01:00
|
|
|
INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
|
|
|
|
void *dso_handle) {
|
2013-11-15 11:31:14 +01:00
|
|
|
#if SANITIZER_MAC
|
2014-05-22 09:09:21 +02:00
|
|
|
if (UNLIKELY(!asan_inited)) return REAL(__cxa_atexit)(func, arg, dso_handle);
|
2013-11-15 11:31:14 +01:00
|
|
|
#endif
|
2013-11-04 22:33:31 +01:00
|
|
|
ENSURE_ASAN_INITED();
|
2019-11-05 14:54:57 +01:00
|
|
|
#if CAN_SANITIZE_LEAKS
|
|
|
|
__lsan::ScopedInterceptorDisabler disabler;
|
|
|
|
#endif
|
2013-11-04 22:33:31 +01:00
|
|
|
int res = REAL(__cxa_atexit)(func, arg, dso_handle);
|
2015-10-21 09:32:45 +02:00
|
|
|
REAL(__cxa_atexit)(AtCxaAtexit, nullptr, nullptr);
|
2013-11-04 22:33:31 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif // ASAN_INTERCEPT___CXA_ATEXIT
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
#if ASAN_INTERCEPT_ATEXIT
|
|
|
|
INTERCEPTOR(int, atexit, void (*func)()) {
|
|
|
|
ENSURE_ASAN_INITED();
|
|
|
|
#if CAN_SANITIZE_LEAKS
|
|
|
|
__lsan::ScopedInterceptorDisabler disabler;
|
|
|
|
#endif
|
|
|
|
// Avoid calling real atexit as it is unrechable on at least on Linux.
|
|
|
|
int res = REAL(__cxa_atexit)((void (*)(void *a))func, nullptr, nullptr);
|
|
|
|
REAL(__cxa_atexit)(AtCxaAtexit, nullptr, nullptr);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ASAN_INTERCEPT_PTHREAD_ATFORK
|
|
|
|
extern "C" {
|
|
|
|
extern int _pthread_atfork(void (*prepare)(), void (*parent)(),
|
|
|
|
void (*child)());
|
|
|
|
};
|
|
|
|
|
|
|
|
INTERCEPTOR(int, pthread_atfork, void (*prepare)(), void (*parent)(),
|
|
|
|
void (*child)()) {
|
|
|
|
#if CAN_SANITIZE_LEAKS
|
|
|
|
__lsan::ScopedInterceptorDisabler disabler;
|
|
|
|
#endif
|
|
|
|
// REAL(pthread_atfork) cannot be called due to symbol indirections at least
|
|
|
|
// on NetBSD
|
|
|
|
return _pthread_atfork(prepare, parent, child);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
#if ASAN_INTERCEPT_VFORK
|
|
|
|
DEFINE_REAL(int, vfork)
|
|
|
|
DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork)
|
|
|
|
#endif
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
// ---------------------- InitializeAsanInterceptors ---------------- {{{1
|
|
|
|
namespace __asan {
|
|
|
|
void InitializeAsanInterceptors() {
|
|
|
|
static bool was_called_once;
|
2016-11-08 23:04:09 +01:00
|
|
|
CHECK(!was_called_once);
|
2012-11-12 16:53:47 +01:00
|
|
|
was_called_once = true;
|
2014-05-22 09:09:21 +02:00
|
|
|
InitializeCommonInterceptors();
|
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
|
|
|
InitializeSignalInterceptors();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// Intercept str* functions.
|
2019-11-05 14:54:57 +01:00
|
|
|
ASAN_INTERCEPT_FUNC(strcat);
|
|
|
|
ASAN_INTERCEPT_FUNC(strcpy);
|
2012-11-12 16:53:47 +01:00
|
|
|
ASAN_INTERCEPT_FUNC(strncat);
|
|
|
|
ASAN_INTERCEPT_FUNC(strncpy);
|
|
|
|
ASAN_INTERCEPT_FUNC(strdup);
|
2016-11-08 23:04:09 +01:00
|
|
|
#if ASAN_INTERCEPT___STRDUP
|
|
|
|
ASAN_INTERCEPT_FUNC(__strdup);
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif
|
2013-02-13 11:46:01 +01:00
|
|
|
#if ASAN_INTERCEPT_INDEX && ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
|
2012-11-12 16:53:47 +01:00
|
|
|
ASAN_INTERCEPT_FUNC(index);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ASAN_INTERCEPT_FUNC(atoi);
|
|
|
|
ASAN_INTERCEPT_FUNC(atol);
|
|
|
|
ASAN_INTERCEPT_FUNC(strtol);
|
|
|
|
#if ASAN_INTERCEPT_ATOLL_AND_STRTOLL
|
|
|
|
ASAN_INTERCEPT_FUNC(atoll);
|
|
|
|
ASAN_INTERCEPT_FUNC(strtoll);
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
// Intecept jump-related functions.
|
2012-11-12 16:53:47 +01:00
|
|
|
ASAN_INTERCEPT_FUNC(longjmp);
|
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
|
|
|
|
2012-11-23 15:46:25 +01:00
|
|
|
#if ASAN_INTERCEPT_SWAPCONTEXT
|
|
|
|
ASAN_INTERCEPT_FUNC(swapcontext);
|
|
|
|
#endif
|
2012-11-12 16:53:47 +01:00
|
|
|
#if ASAN_INTERCEPT__LONGJMP
|
|
|
|
ASAN_INTERCEPT_FUNC(_longjmp);
|
|
|
|
#endif
|
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 ASAN_INTERCEPT___LONGJMP_CHK
|
|
|
|
ASAN_INTERCEPT_FUNC(__longjmp_chk);
|
|
|
|
#endif
|
2012-11-12 16:53:47 +01:00
|
|
|
#if ASAN_INTERCEPT_SIGLONGJMP
|
|
|
|
ASAN_INTERCEPT_FUNC(siglongjmp);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Intercept exception handling functions.
|
|
|
|
#if ASAN_INTERCEPT___CXA_THROW
|
2014-09-23 19:59:53 +02:00
|
|
|
ASAN_INTERCEPT_FUNC(__cxa_throw);
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif
|
2018-10-31 12:14:23 +01:00
|
|
|
#if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
|
|
|
|
ASAN_INTERCEPT_FUNC(__cxa_rethrow_primary_exception);
|
|
|
|
#endif
|
|
|
|
// Indirectly intercept std::rethrow_exception.
|
|
|
|
#if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION
|
|
|
|
INTERCEPT_FUNCTION(_Unwind_RaiseException);
|
|
|
|
#endif
|
|
|
|
// Indirectly intercept std::rethrow_exception.
|
|
|
|
#if ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION
|
|
|
|
INTERCEPT_FUNCTION(_Unwind_SjLj_RaiseException);
|
|
|
|
#endif
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// Intercept threading-related functions
|
|
|
|
#if ASAN_INTERCEPT_PTHREAD_CREATE
|
2021-03-08 15:52:03 +01:00
|
|
|
// TODO: this should probably have an unversioned fallback for newer arches?
|
2015-10-21 09:32:45 +02:00
|
|
|
#if defined(ASAN_PTHREAD_CREATE_VERSION)
|
|
|
|
ASAN_INTERCEPT_FUNC_VER(pthread_create, ASAN_PTHREAD_CREATE_VERSION);
|
|
|
|
#else
|
2012-11-12 16:53:47 +01:00
|
|
|
ASAN_INTERCEPT_FUNC(pthread_create);
|
|
|
|
#endif
|
2015-10-21 09:32:45 +02:00
|
|
|
ASAN_INTERCEPT_FUNC(pthread_join);
|
|
|
|
#endif
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// Intercept atexit function.
|
|
|
|
#if ASAN_INTERCEPT___CXA_ATEXIT
|
|
|
|
ASAN_INTERCEPT_FUNC(__cxa_atexit);
|
|
|
|
#endif
|
|
|
|
|
2019-11-05 14:54:57 +01:00
|
|
|
#if ASAN_INTERCEPT_ATEXIT
|
|
|
|
ASAN_INTERCEPT_FUNC(atexit);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ASAN_INTERCEPT_PTHREAD_ATFORK
|
|
|
|
ASAN_INTERCEPT_FUNC(pthread_atfork);
|
|
|
|
#endif
|
|
|
|
|
2019-08-14 10:47:11 +02:00
|
|
|
#if ASAN_INTERCEPT_VFORK
|
|
|
|
ASAN_INTERCEPT_FUNC(vfork);
|
|
|
|
#endif
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
InitializePlatformInterceptors();
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2014-05-22 09:09:21 +02:00
|
|
|
VReport(1, "AddressSanitizer: libc interceptors initialized\n");
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
|
2015-10-21 09:32:45 +02:00
|
|
|
} // namespace __asan
|
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
|
|
|
|
|
|
|
#endif // !SANITIZER_FUCHSIA
|