2011-11-30 09:07:02 +08:00
|
|
|
//===-- asan_interceptors.h -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// ASan-private header for asan_interceptors.cc
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef ASAN_INTERCEPTORS_H
|
|
|
|
#define ASAN_INTERCEPTORS_H
|
|
|
|
|
|
|
|
#include "asan_internal.h"
|
2017-07-20 09:29:01 +08:00
|
|
|
#include "asan_interceptors_memintrinsics.h"
|
2014-11-18 18:33:15 +08:00
|
|
|
#include "interception/interception.h"
|
2013-12-26 23:34:31 +08:00
|
|
|
#include "sanitizer_common/sanitizer_platform_interceptors.h"
|
|
|
|
|
2017-08-02 15:59:30 +08:00
|
|
|
namespace __asan {
|
|
|
|
|
|
|
|
void InitializeAsanInterceptors();
|
|
|
|
void InitializePlatformInterceptors();
|
|
|
|
|
|
|
|
#define ENSURE_ASAN_INITED() \
|
|
|
|
do { \
|
|
|
|
CHECK(!asan_init_is_running); \
|
|
|
|
if (UNLIKELY(!asan_inited)) { \
|
|
|
|
AsanInitFromRtl(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
// There is no general interception at all on Fuchsia.
|
|
|
|
// Only the functions in asan_interceptors_memintrinsics.h are
|
|
|
|
// really defined to replace libc functions.
|
|
|
|
#if !SANITIZER_FUCHSIA
|
|
|
|
|
2013-12-26 23:34:31 +08:00
|
|
|
// Use macro to describe if specific function should be
|
|
|
|
// intercepted on a given platform.
|
|
|
|
#if !SANITIZER_WINDOWS
|
|
|
|
# define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 1
|
|
|
|
# define ASAN_INTERCEPT__LONGJMP 1
|
|
|
|
# define ASAN_INTERCEPT_INDEX 1
|
|
|
|
# define ASAN_INTERCEPT_PTHREAD_CREATE 1
|
2014-06-04 20:13:54 +08:00
|
|
|
# define ASAN_INTERCEPT_FORK 1
|
2013-12-26 23:34:31 +08:00
|
|
|
#else
|
|
|
|
# define ASAN_INTERCEPT_ATOLL_AND_STRTOLL 0
|
|
|
|
# define ASAN_INTERCEPT__LONGJMP 0
|
|
|
|
# define ASAN_INTERCEPT_INDEX 0
|
|
|
|
# define ASAN_INTERCEPT_PTHREAD_CREATE 0
|
2014-06-04 20:13:54 +08:00
|
|
|
# define ASAN_INTERCEPT_FORK 0
|
2013-12-26 23:34:31 +08:00
|
|
|
#endif
|
|
|
|
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
|
|
|
|
SANITIZER_SOLARIS
|
2013-12-26 23:34:31 +08:00
|
|
|
# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
|
|
|
|
#else
|
|
|
|
# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
|
|
|
|
#endif
|
|
|
|
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
#if (SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_SOLARIS
|
2013-12-26 23:34:31 +08:00
|
|
|
# define ASAN_INTERCEPT_SWAPCONTEXT 1
|
|
|
|
#else
|
|
|
|
# define ASAN_INTERCEPT_SWAPCONTEXT 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !SANITIZER_WINDOWS
|
|
|
|
# define ASAN_INTERCEPT_SIGLONGJMP 1
|
|
|
|
#else
|
|
|
|
# define ASAN_INTERCEPT_SIGLONGJMP 0
|
|
|
|
#endif
|
|
|
|
|
2017-05-04 22:03:57 +08:00
|
|
|
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
|
|
|
# define ASAN_INTERCEPT___LONGJMP_CHK 1
|
|
|
|
#else
|
|
|
|
# define ASAN_INTERCEPT___LONGJMP_CHK 0
|
|
|
|
#endif
|
|
|
|
|
2014-07-03 22:20:56 +08:00
|
|
|
// Android bug: https://code.google.com/p/android/issues/detail?id=61799
|
|
|
|
#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && \
|
[Sanitizers] Basic sanitizer Solaris support (PR 33274)
Summary:
This is the first mostly working version of the Sanitizer port to 32-bit Solaris/x86.
It is currently based on Solaris 11.4 Beta.
This part was initially developed inside libsanitizer in the GCC tree and should apply to
both. Subsequent parts will address changes to clang, the compiler-rt build system
and testsuite.
I'm not yet sure what the right patch granularity is: if it's profitable to split the patch
up, I'd like to get guidance on how to do so.
Most of the changes are probably straightforward with a few exceptions:
* The Solaris syscall interface isn't stable, undocumented and can change within an
OS release. The stable interface is the libc interface, which I'm using here, if possible
using the internal _-prefixed names.
* While the patch primarily target 32-bit x86, I've left a few sparc changes in. They
cannot currently be used with clang due to a backend limitation, but have worked
fine inside the gcc tree.
* Some functions (e.g. largefile versions of functions like open64) only exist in 32-bit
Solaris, so I've introduced a separate SANITIZER_SOLARIS32 to check for that.
The patch (with the subsequent ones to be submitted shortly) was tested
on i386-pc-solaris2.11. Only a few failures remain, some of them analyzed, some
still TBD:
AddressSanitizer-i386-sunos :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos :: TestCases/malloc-no-intercept.c
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/concurrent_overflow.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/init-order-atexit.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/log-path_test.cc
AddressSanitizer-i386-sunos-dynamic :: TestCases/malloc-no-intercept.c
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/MemoryMappingLayout.DumpListOfModules
SanitizerCommon-Unit :: ./Sanitizer-i386-Test/SanitizerCommon.PthreadDestructorIterations
Maybe this is good enough the get the ball rolling.
Reviewers: kcc, alekseyshl
Reviewed By: alekseyshl
Subscribers: srhines, jyknight, kubamracek, krytarowski, fedor.sergeev, llvm-commits, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D40898
llvm-svn: 320740
2017-12-15 04:14:29 +08:00
|
|
|
!(SANITIZER_ANDROID && defined(__i386)) && \
|
|
|
|
!SANITIZER_SOLARIS
|
2013-12-26 23:34:31 +08:00
|
|
|
# define ASAN_INTERCEPT___CXA_THROW 1
|
|
|
|
#else
|
|
|
|
# define ASAN_INTERCEPT___CXA_THROW 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !SANITIZER_WINDOWS
|
|
|
|
# define ASAN_INTERCEPT___CXA_ATEXIT 1
|
|
|
|
#else
|
|
|
|
# define ASAN_INTERCEPT___CXA_ATEXIT 0
|
|
|
|
#endif
|
2012-02-02 18:39:40 +08:00
|
|
|
|
2016-04-21 06:45:23 +08:00
|
|
|
#if SANITIZER_LINUX && !SANITIZER_ANDROID
|
|
|
|
# define ASAN_INTERCEPT___STRDUP 1
|
|
|
|
#else
|
|
|
|
# define ASAN_INTERCEPT___STRDUP 0
|
|
|
|
#endif
|
|
|
|
|
2012-06-25 14:53:10 +08:00
|
|
|
DECLARE_REAL(int, memcmp, const void *a1, const void *a2, uptr size)
|
|
|
|
DECLARE_REAL(char*, strchr, const char *str, int c)
|
2014-08-22 00:12:46 +08:00
|
|
|
DECLARE_REAL(SIZE_T, strlen, const char *s)
|
2012-06-25 14:53:10 +08:00
|
|
|
DECLARE_REAL(char*, strncpy, char *to, const char *from, uptr size)
|
|
|
|
DECLARE_REAL(uptr, strnlen, const char *s, uptr maxlen)
|
2012-08-24 17:22:05 +08:00
|
|
|
DECLARE_REAL(char*, strstr, const char *s1, const char *s2)
|
2012-02-02 18:39:40 +08:00
|
|
|
|
2015-03-16 22:22:53 +08:00
|
|
|
#if !SANITIZER_MAC
|
|
|
|
#define ASAN_INTERCEPT_FUNC(name) \
|
|
|
|
do { \
|
|
|
|
if ((!INTERCEPT_FUNCTION(name) || !REAL(name))) \
|
|
|
|
VReport(1, "AddressSanitizer: failed to intercept '" #name "'\n"); \
|
|
|
|
} while (0)
|
2015-09-23 05:34:44 +08:00
|
|
|
#define ASAN_INTERCEPT_FUNC_VER(name, ver) \
|
|
|
|
do { \
|
|
|
|
if ((!INTERCEPT_FUNCTION_VER(name, ver) || !REAL(name))) \
|
|
|
|
VReport( \
|
|
|
|
1, "AddressSanitizer: failed to intercept '" #name "@@" #ver "'\n"); \
|
|
|
|
} while (0)
|
2015-03-16 22:22:53 +08:00
|
|
|
#else
|
|
|
|
// OS X interceptors don't need to be initialized with INTERCEPT_FUNCTION.
|
|
|
|
#define ASAN_INTERCEPT_FUNC(name)
|
|
|
|
#endif // SANITIZER_MAC
|
|
|
|
|
2017-08-02 15:59:30 +08:00
|
|
|
#endif // !SANITIZER_FUCHSIA
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
#endif // ASAN_INTERCEPTORS_H
|