2012-11-12 16:53:47 +01:00
|
|
|
//===-- interception.h ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
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.
|
|
|
|
//
|
|
|
|
// Machinery for providing replacements/wrappers for system functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef INTERCEPTION_H
|
|
|
|
#define INTERCEPTION_H
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#include "sanitizer_common/sanitizer_internal_defs.h"
|
|
|
|
|
2021-07-20 19:44:37 +02:00
|
|
|
#if !SANITIZER_LINUX && !SANITIZER_FREEBSD && !SANITIZER_MAC && \
|
|
|
|
!SANITIZER_NETBSD && !SANITIZER_WINDOWS && !SANITIZER_FUCHSIA && \
|
|
|
|
!SANITIZER_SOLARIS
|
|
|
|
# error "Interception doesn't work on this operating system."
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif
|
|
|
|
|
2013-01-10 13:44:08 +01:00
|
|
|
// These typedefs should be used only in the interceptor definitions to replace
|
|
|
|
// the standard system types (e.g. SSIZE_T instead of ssize_t)
|
2013-11-04 22:33:31 +01:00
|
|
|
typedef __sanitizer::uptr SIZE_T;
|
|
|
|
typedef __sanitizer::sptr SSIZE_T;
|
|
|
|
typedef __sanitizer::sptr PTRDIFF_T;
|
|
|
|
typedef __sanitizer::s64 INTMAX_T;
|
2018-10-31 12:14:23 +01:00
|
|
|
typedef __sanitizer::u64 UINTMAX_T;
|
2013-11-04 22:33:31 +01:00
|
|
|
typedef __sanitizer::OFF_T OFF_T;
|
|
|
|
typedef __sanitizer::OFF64_T OFF64_T;
|
2013-01-10 13:44:08 +01:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
// How to add an interceptor:
|
|
|
|
// Suppose you need to wrap/replace system function (generally, from libc):
|
|
|
|
// int foo(const char *bar, double baz);
|
|
|
|
// You'll need to:
|
|
|
|
// 1) define INTERCEPTOR(int, foo, const char *bar, double baz) { ... } in
|
2013-11-04 22:33:31 +01:00
|
|
|
// your source file. See the notes below for cases when
|
|
|
|
// INTERCEPTOR_WITH_SUFFIX(...) should be used instead.
|
2012-11-12 16:53:47 +01:00
|
|
|
// 2) Call "INTERCEPT_FUNCTION(foo)" prior to the first call of "foo".
|
|
|
|
// INTERCEPT_FUNCTION(foo) evaluates to "true" iff the function was
|
|
|
|
// intercepted successfully.
|
|
|
|
// You can access original function by calling REAL(foo)(bar, baz).
|
|
|
|
// By default, REAL(foo) will be visible only inside your interceptor, and if
|
|
|
|
// you want to use it in other parts of RTL, you'll need to:
|
|
|
|
// 3a) add DECLARE_REAL(int, foo, const char*, double) to a
|
|
|
|
// header file.
|
|
|
|
// However, if the call "INTERCEPT_FUNCTION(foo)" and definition for
|
|
|
|
// INTERCEPTOR(..., foo, ...) are in different files, you'll instead need to:
|
|
|
|
// 3b) add DECLARE_REAL_AND_INTERCEPTOR(int, foo, const char*, double)
|
|
|
|
// to a header file.
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// Notes: 1. Things may not work properly if macro INTERCEPTOR(...) {...} or
|
2012-11-12 16:53:47 +01:00
|
|
|
// DECLARE_REAL(...) are located inside namespaces.
|
2013-11-04 22:33:31 +01:00
|
|
|
// 2. On Mac you can also use: "OVERRIDE_FUNCTION(foo, zoo)" to
|
2012-11-12 16:53:47 +01:00
|
|
|
// effectively redirect calls from "foo" to "zoo". In this case
|
|
|
|
// you aren't required to implement
|
|
|
|
// INTERCEPTOR(int, foo, const char *bar, double baz) {...}
|
|
|
|
// but instead you'll have to add
|
2013-11-04 22:33:31 +01:00
|
|
|
// DECLARE_REAL(int, foo, const char *bar, double baz) in your
|
2012-11-12 16:53:47 +01:00
|
|
|
// source file (to define a pointer to overriden function).
|
2013-11-04 22:33:31 +01:00
|
|
|
// 3. Some Mac functions have symbol variants discriminated by
|
|
|
|
// additional suffixes, e.g. _$UNIX2003 (see
|
|
|
|
// https://developer.apple.com/library/mac/#releasenotes/Darwin/SymbolVariantsRelNotes/index.html
|
|
|
|
// for more details). To intercept such functions you need to use the
|
|
|
|
// INTERCEPTOR_WITH_SUFFIX(...) macro.
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// How it works:
|
|
|
|
// To replace system functions on Linux we just need to declare functions
|
|
|
|
// with same names in our library and then obtain the real function pointers
|
|
|
|
// using dlsym().
|
|
|
|
// There is one complication. A user may also intercept some of the functions
|
|
|
|
// we intercept. To resolve this we declare our interceptors with __interceptor_
|
|
|
|
// prefix, and then make actual interceptors weak aliases to __interceptor_
|
|
|
|
// functions.
|
2013-11-04 22:33:31 +01:00
|
|
|
//
|
2012-11-12 16:53:47 +01:00
|
|
|
// This is not so on Mac OS, where the two-level namespace makes
|
|
|
|
// our replacement functions invisible to other libraries. This may be overcomed
|
|
|
|
// using the DYLD_FORCE_FLAT_NAMESPACE, but some errors loading the shared
|
2013-02-13 11:46:01 +01:00
|
|
|
// libraries in Chromium were noticed when doing so.
|
|
|
|
// Instead we create a dylib containing a __DATA,__interpose section that
|
|
|
|
// associates library functions with their wrappers. When this dylib is
|
|
|
|
// preloaded before an executable using DYLD_INSERT_LIBRARIES, it routes all
|
|
|
|
// the calls to interposed functions done through stubs to the wrapper
|
|
|
|
// functions.
|
2013-11-04 22:33:31 +01:00
|
|
|
// As it's decided at compile time which functions are to be intercepted on Mac,
|
|
|
|
// INTERCEPT_FUNCTION() is effectively a no-op on this system.
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#if SANITIZER_MAC
|
2013-11-04 22:33:31 +01:00
|
|
|
#include <sys/cdefs.h> // For __DARWIN_ALIAS_C().
|
|
|
|
|
|
|
|
// Just a pair of pointers.
|
|
|
|
struct interpose_substitution {
|
2016-11-08 23:04:09 +01:00
|
|
|
const __sanitizer::uptr replacement;
|
|
|
|
const __sanitizer::uptr original;
|
2013-11-04 22:33:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// For a function foo() create a global pair of pointers { wrap_foo, foo } in
|
|
|
|
// the __DATA,__interpose section.
|
|
|
|
// As a result all the calls to foo() will be routed to wrap_foo() at runtime.
|
|
|
|
#define INTERPOSER(func_name) __attribute__((used)) \
|
|
|
|
const interpose_substitution substitution_##func_name[] \
|
|
|
|
__attribute__((section("__DATA, __interpose"))) = { \
|
|
|
|
{ reinterpret_cast<const uptr>(WRAP(func_name)), \
|
|
|
|
reinterpret_cast<const uptr>(func_name) } \
|
|
|
|
}
|
|
|
|
|
|
|
|
// For a function foo() and a wrapper function bar() create a global pair
|
|
|
|
// of pointers { bar, foo } in the __DATA,__interpose section.
|
|
|
|
// As a result all the calls to foo() will be routed to bar() at runtime.
|
|
|
|
#define INTERPOSER_2(func_name, wrapper_name) __attribute__((used)) \
|
|
|
|
const interpose_substitution substitution_##func_name[] \
|
|
|
|
__attribute__((section("__DATA, __interpose"))) = { \
|
|
|
|
{ reinterpret_cast<const uptr>(wrapper_name), \
|
|
|
|
reinterpret_cast<const uptr>(func_name) } \
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
# define WRAP(x) wrap_##x
|
|
|
|
# define WRAPPER_NAME(x) "wrap_"#x
|
|
|
|
# define INTERCEPTOR_ATTRIBUTE
|
|
|
|
# define DECLARE_WRAPPER(ret_type, func, ...)
|
2013-11-04 22:33:31 +01:00
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#elif SANITIZER_WINDOWS
|
2014-09-23 19:59:53 +02:00
|
|
|
# define WRAP(x) __asan_wrap_##x
|
|
|
|
# define WRAPPER_NAME(x) "__asan_wrap_"#x
|
|
|
|
# define INTERCEPTOR_ATTRIBUTE __declspec(dllexport)
|
2013-11-04 22:33:31 +01:00
|
|
|
# define DECLARE_WRAPPER(ret_type, func, ...) \
|
|
|
|
extern "C" ret_type func(__VA_ARGS__);
|
|
|
|
# define DECLARE_WRAPPER_WINAPI(ret_type, func, ...) \
|
|
|
|
extern "C" __declspec(dllimport) ret_type __stdcall func(__VA_ARGS__);
|
2018-10-31 12:14:23 +01:00
|
|
|
#elif SANITIZER_FREEBSD || SANITIZER_NETBSD
|
2014-09-23 19:59:53 +02:00
|
|
|
# define WRAP(x) __interceptor_ ## x
|
|
|
|
# define WRAPPER_NAME(x) "__interceptor_" #x
|
|
|
|
# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
|
|
|
|
// FreeBSD's dynamic linker (incompliantly) gives non-weak symbols higher
|
|
|
|
// priority than weak ones so weak aliases won't work for indirect calls
|
|
|
|
// in position-independent (-fPIC / -fPIE) mode.
|
|
|
|
# define DECLARE_WRAPPER(ret_type, func, ...) \
|
|
|
|
extern "C" ret_type func(__VA_ARGS__) \
|
|
|
|
__attribute__((alias("__interceptor_" #func), visibility("default")));
|
2018-10-31 12:14:23 +01:00
|
|
|
#elif !SANITIZER_FUCHSIA
|
2012-11-12 16:53:47 +01:00
|
|
|
# define WRAP(x) __interceptor_ ## x
|
|
|
|
# define WRAPPER_NAME(x) "__interceptor_" #x
|
|
|
|
# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
|
|
|
|
# define DECLARE_WRAPPER(ret_type, func, ...) \
|
|
|
|
extern "C" ret_type func(__VA_ARGS__) \
|
|
|
|
__attribute__((weak, alias("__interceptor_" #func), visibility("default")));
|
|
|
|
#endif
|
|
|
|
|
2018-10-31 12:14:23 +01: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
|
|
|
// There is no general interception at all on Fuchsia.
|
|
|
|
// Sanitizer runtimes just define functions directly to preempt them,
|
|
|
|
// and have bespoke ways to access the underlying libc functions.
|
|
|
|
# include <zircon/sanitizer.h>
|
|
|
|
# define INTERCEPTOR_ATTRIBUTE __attribute__((visibility("default")))
|
|
|
|
# define REAL(x) __unsanitized_##x
|
|
|
|
# define DECLARE_REAL(ret_type, func, ...)
|
2018-10-31 12:14:23 +01:00
|
|
|
#elif !SANITIZER_MAC
|
2012-11-12 16:53:47 +01:00
|
|
|
# define PTR_TO_REAL(x) real_##x
|
|
|
|
# define REAL(x) __interception::PTR_TO_REAL(x)
|
2018-10-31 12:14:23 +01:00
|
|
|
# define FUNC_TYPE(x) x##_type
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
# define DECLARE_REAL(ret_type, func, ...) \
|
|
|
|
typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \
|
|
|
|
namespace __interception { \
|
|
|
|
extern FUNC_TYPE(func) PTR_TO_REAL(func); \
|
|
|
|
}
|
2016-11-08 23:04:09 +01:00
|
|
|
# define ASSIGN_REAL(dst, src) REAL(dst) = REAL(src)
|
2018-10-31 12:14:23 +01:00
|
|
|
#else // SANITIZER_MAC
|
2012-11-12 16:53:47 +01:00
|
|
|
# define REAL(x) x
|
|
|
|
# define DECLARE_REAL(ret_type, func, ...) \
|
|
|
|
extern "C" ret_type func(__VA_ARGS__);
|
2016-11-08 23:04:09 +01:00
|
|
|
# define ASSIGN_REAL(x, y)
|
2018-10-31 12:14:23 +01:00
|
|
|
#endif // SANITIZER_MAC
|
2012-11-12 16:53:47 +01:00
|
|
|
|
2021-07-20 19:44:37 +02:00
|
|
|
#if !SANITIZER_FUCHSIA
|
|
|
|
# define DECLARE_REAL_AND_INTERCEPTOR(ret_type, func, ...) \
|
|
|
|
DECLARE_REAL(ret_type, func, __VA_ARGS__) \
|
|
|
|
extern "C" ret_type WRAP(func)(__VA_ARGS__);
|
2019-08-14 10:47:11 +02:00
|
|
|
// Declare an interceptor and its wrapper defined in a different translation
|
|
|
|
// unit (ex. asm).
|
|
|
|
# define DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(ret_type, func, ...) \
|
|
|
|
extern "C" ret_type WRAP(func)(__VA_ARGS__); \
|
|
|
|
extern "C" ret_type func(__VA_ARGS__);
|
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
|
|
|
#else
|
2019-08-14 10:47:11 +02:00
|
|
|
# define DECLARE_REAL_AND_INTERCEPTOR(ret_type, func, ...)
|
|
|
|
# define DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(ret_type, func, ...)
|
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
|
2012-11-12 16:53:47 +01:00
|
|
|
|
|
|
|
// Generally, you don't need to use DEFINE_REAL by itself, as INTERCEPTOR
|
|
|
|
// macros does its job. In exceptional cases you may need to call REAL(foo)
|
|
|
|
// without defining INTERCEPTOR(..., foo, ...). For example, if you override
|
|
|
|
// foo with an interceptor for other function.
|
2021-07-20 19:44:37 +02:00
|
|
|
#if !SANITIZER_MAC && !SANITIZER_FUCHSIA
|
|
|
|
# define DEFINE_REAL(ret_type, func, ...) \
|
2012-11-12 16:53:47 +01:00
|
|
|
typedef ret_type (*FUNC_TYPE(func))(__VA_ARGS__); \
|
2021-07-20 19:44:37 +02:00
|
|
|
namespace __interception { \
|
|
|
|
FUNC_TYPE(func) PTR_TO_REAL(func); \
|
2012-11-12 16:53:47 +01:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define DEFINE_REAL(ret_type, func, ...)
|
|
|
|
#endif
|
|
|
|
|
2018-10-31 12:14:23 +01: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
|
|
|
|
|
|
|
// We need to define the __interceptor_func name just to get
|
|
|
|
// sanitizer_common/scripts/gen_dynamic_list.py to export func.
|
|
|
|
// But we don't need to export __interceptor_func to get that.
|
|
|
|
#define INTERCEPTOR(ret_type, func, ...) \
|
|
|
|
extern "C"[[ gnu::alias(#func), gnu::visibility("hidden") ]] ret_type \
|
|
|
|
__interceptor_##func(__VA_ARGS__); \
|
|
|
|
extern "C" INTERCEPTOR_ATTRIBUTE ret_type func(__VA_ARGS__)
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#elif !SANITIZER_MAC
|
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-12 16:53:47 +01:00
|
|
|
#define INTERCEPTOR(ret_type, func, ...) \
|
|
|
|
DEFINE_REAL(ret_type, func, __VA_ARGS__) \
|
|
|
|
DECLARE_WRAPPER(ret_type, func, __VA_ARGS__) \
|
|
|
|
extern "C" \
|
|
|
|
INTERCEPTOR_ATTRIBUTE \
|
|
|
|
ret_type WRAP(func)(__VA_ARGS__)
|
|
|
|
|
2013-11-04 22:33:31 +01:00
|
|
|
// We don't need INTERCEPTOR_WITH_SUFFIX on non-Darwin for now.
|
|
|
|
#define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \
|
|
|
|
INTERCEPTOR(ret_type, func, __VA_ARGS__)
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#else // SANITIZER_MAC
|
2013-11-04 22:33:31 +01:00
|
|
|
|
|
|
|
#define INTERCEPTOR_ZZZ(suffix, ret_type, func, ...) \
|
|
|
|
extern "C" ret_type func(__VA_ARGS__) suffix; \
|
|
|
|
extern "C" ret_type WRAP(func)(__VA_ARGS__); \
|
|
|
|
INTERPOSER(func); \
|
|
|
|
extern "C" INTERCEPTOR_ATTRIBUTE ret_type WRAP(func)(__VA_ARGS__)
|
|
|
|
|
|
|
|
#define INTERCEPTOR(ret_type, func, ...) \
|
|
|
|
INTERCEPTOR_ZZZ(/*no symbol variants*/, ret_type, func, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define INTERCEPTOR_WITH_SUFFIX(ret_type, func, ...) \
|
|
|
|
INTERCEPTOR_ZZZ(__DARWIN_ALIAS_C(func), ret_type, func, __VA_ARGS__)
|
|
|
|
|
|
|
|
// Override |overridee| with |overrider|.
|
|
|
|
#define OVERRIDE_FUNCTION(overridee, overrider) \
|
|
|
|
INTERPOSER_2(overridee, WRAP(overrider))
|
|
|
|
#endif
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#if SANITIZER_WINDOWS
|
2012-11-12 16:53:47 +01:00
|
|
|
# define INTERCEPTOR_WINAPI(ret_type, func, ...) \
|
|
|
|
typedef ret_type (__stdcall *FUNC_TYPE(func))(__VA_ARGS__); \
|
|
|
|
namespace __interception { \
|
|
|
|
FUNC_TYPE(func) PTR_TO_REAL(func); \
|
|
|
|
} \
|
|
|
|
extern "C" \
|
|
|
|
INTERCEPTOR_ATTRIBUTE \
|
|
|
|
ret_type __stdcall WRAP(func)(__VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ISO C++ forbids casting between pointer-to-function and pointer-to-object,
|
|
|
|
// so we use casting via an integral type __interception::uptr,
|
|
|
|
// assuming that system is POSIX-compliant. Using other hacks seem
|
|
|
|
// challenging, as we don't even pass function type to
|
|
|
|
// INTERCEPT_FUNCTION macro, only its name.
|
|
|
|
namespace __interception {
|
|
|
|
#if defined(_WIN64)
|
2019-11-05 14:54:57 +01:00
|
|
|
typedef unsigned long long uptr;
|
2012-11-12 16:53:47 +01:00
|
|
|
#else
|
2019-11-05 14:54:57 +01:00
|
|
|
typedef unsigned long uptr;
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif // _WIN64
|
|
|
|
} // namespace __interception
|
|
|
|
|
|
|
|
#define INCLUDED_FROM_INTERCEPTION_LIB
|
|
|
|
|
2018-10-31 12:14:23 +01:00
|
|
|
#if SANITIZER_LINUX || SANITIZER_FREEBSD || SANITIZER_NETBSD || \
|
2020-11-13 17:03:23 +01:00
|
|
|
SANITIZER_SOLARIS
|
2018-10-31 12:14:23 +01:00
|
|
|
|
2012-11-12 16:53:47 +01:00
|
|
|
# include "interception_linux.h"
|
2014-05-22 09:09:21 +02:00
|
|
|
# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_LINUX_OR_FREEBSD(func)
|
2013-12-05 10:18:38 +01:00
|
|
|
# define INTERCEPT_FUNCTION_VER(func, symver) \
|
2014-05-22 09:09:21 +02:00
|
|
|
INTERCEPT_FUNCTION_VER_LINUX_OR_FREEBSD(func, symver)
|
2018-10-31 12:14:23 +01:00
|
|
|
#elif SANITIZER_MAC
|
2012-11-12 16:53:47 +01:00
|
|
|
# include "interception_mac.h"
|
|
|
|
# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_MAC(func)
|
2013-12-05 10:18:38 +01:00
|
|
|
# define INTERCEPT_FUNCTION_VER(func, symver) \
|
|
|
|
INTERCEPT_FUNCTION_VER_MAC(func, symver)
|
2018-10-31 12:14:23 +01:00
|
|
|
#elif SANITIZER_WINDOWS
|
2012-11-12 16:53:47 +01:00
|
|
|
# include "interception_win.h"
|
|
|
|
# define INTERCEPT_FUNCTION(func) INTERCEPT_FUNCTION_WIN(func)
|
2013-12-05 10:18:38 +01:00
|
|
|
# define INTERCEPT_FUNCTION_VER(func, symver) \
|
|
|
|
INTERCEPT_FUNCTION_VER_WIN(func, symver)
|
2012-11-12 16:53:47 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef INCLUDED_FROM_INTERCEPTION_LIB
|
|
|
|
|
|
|
|
#endif // INTERCEPTION_H
|