2012-06-05 22:25:27 +08:00
|
|
|
//===-- sanitizer_internal_defs.h -------------------------------*- C++ -*-===//
|
2012-05-31 22:11:07 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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-05-31 22:11:07 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is shared between AddressSanitizer and ThreadSanitizer.
|
2012-06-05 21:50:57 +08:00
|
|
|
// It contains macro used in run-time libraries code.
|
2012-05-31 22:11:07 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SANITIZER_DEFS_H
|
|
|
|
#define SANITIZER_DEFS_H
|
|
|
|
|
2013-03-19 22:33:38 +08:00
|
|
|
#include "sanitizer_platform.h"
|
2013-03-19 21:54:41 +08:00
|
|
|
|
2015-01-03 12:29:12 +08:00
|
|
|
#ifndef SANITIZER_DEBUG
|
|
|
|
# define SANITIZER_DEBUG 0
|
|
|
|
#endif
|
|
|
|
|
2018-02-09 00:29:48 +08:00
|
|
|
#define SANITIZER_STRINGIFY_(S) #S
|
|
|
|
#define SANITIZER_STRINGIFY(S) SANITIZER_STRINGIFY_(S)
|
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
// Only use SANITIZER_*ATTRIBUTE* before the function return type!
|
2013-03-19 22:54:17 +08:00
|
|
|
#if SANITIZER_WINDOWS
|
2017-01-29 14:11:32 +08:00
|
|
|
#if SANITIZER_IMPORT_INTERFACE
|
|
|
|
# define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllimport)
|
|
|
|
#else
|
2014-07-15 16:16:04 +08:00
|
|
|
# define SANITIZER_INTERFACE_ATTRIBUTE __declspec(dllexport)
|
2017-01-29 14:11:32 +08:00
|
|
|
#endif
|
2013-01-30 21:12:08 +08:00
|
|
|
# define SANITIZER_WEAK_ATTRIBUTE
|
2016-10-29 04:14:18 +08:00
|
|
|
#elif SANITIZER_GO
|
2013-01-30 21:12:08 +08:00
|
|
|
# define SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
# define SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
#else
|
|
|
|
# define SANITIZER_INTERFACE_ATTRIBUTE __attribute__((visibility("default")))
|
|
|
|
# define SANITIZER_WEAK_ATTRIBUTE __attribute__((weak))
|
|
|
|
#endif
|
|
|
|
|
2017-08-31 06:49:31 +08:00
|
|
|
// TLS is handled differently on different platforms
|
2018-03-03 20:12:03 +08:00
|
|
|
#if SANITIZER_LINUX || SANITIZER_NETBSD || \
|
|
|
|
SANITIZER_FREEBSD || SANITIZER_OPENBSD
|
2017-08-31 06:49:31 +08:00
|
|
|
# define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE \
|
|
|
|
__attribute__((tls_model("initial-exec"))) thread_local
|
|
|
|
#else
|
|
|
|
# define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE
|
|
|
|
#endif
|
|
|
|
|
2017-01-29 13:44:59 +08:00
|
|
|
//--------------------------- WEAK FUNCTIONS ---------------------------------//
|
|
|
|
// When working with weak functions, to simplify the code and make it more
|
|
|
|
// portable, when possible define a default implementation using this macro:
|
|
|
|
//
|
|
|
|
// SANITIZER_INTERFACE_WEAK_DEF(<return_type>, <name>, <parameter list>)
|
|
|
|
//
|
|
|
|
// For example:
|
|
|
|
// SANITIZER_INTERFACE_WEAK_DEF(bool, compare, int a, int b) { return a > b; }
|
|
|
|
//
|
|
|
|
#if SANITIZER_WINDOWS
|
|
|
|
#include "sanitizer_win_defs.h"
|
|
|
|
# define SANITIZER_INTERFACE_WEAK_DEF(ReturnType, Name, ...) \
|
|
|
|
WIN_WEAK_EXPORT_DEF(ReturnType, Name, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
# define SANITIZER_INTERFACE_WEAK_DEF(ReturnType, Name, ...) \
|
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE \
|
|
|
|
ReturnType Name(__VA_ARGS__)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// SANITIZER_SUPPORTS_WEAK_HOOKS means that we support real weak functions that
|
|
|
|
// will evaluate to a null pointer when not defined.
|
2017-10-07 09:46:36 +08:00
|
|
|
#ifndef SANITIZER_SUPPORTS_WEAK_HOOKS
|
2018-02-06 07:02:09 +08:00
|
|
|
#if (SANITIZER_LINUX || SANITIZER_SOLARIS) && !SANITIZER_GO
|
|
|
|
# define SANITIZER_SUPPORTS_WEAK_HOOKS 1
|
|
|
|
// Before Xcode 4.5, the Darwin linker doesn't reliably support undefined
|
|
|
|
// weak symbols. Mac OS X 10.9/Darwin 13 is the first release only supported
|
|
|
|
// by Xcode >= 4.5.
|
|
|
|
#elif SANITIZER_MAC && \
|
|
|
|
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1090 && !SANITIZER_GO
|
2013-01-30 21:12:08 +08:00
|
|
|
# define SANITIZER_SUPPORTS_WEAK_HOOKS 1
|
|
|
|
#else
|
|
|
|
# define SANITIZER_SUPPORTS_WEAK_HOOKS 0
|
|
|
|
#endif
|
2017-10-07 09:46:36 +08:00
|
|
|
#endif // SANITIZER_SUPPORTS_WEAK_HOOKS
|
2017-01-29 13:44:59 +08:00
|
|
|
// For some weak hooks that will be called very often and we want to avoid the
|
|
|
|
// overhead of executing the default implementation when it is not necessary,
|
|
|
|
// we can use the flag SANITIZER_SUPPORTS_WEAK_HOOKS to only define the default
|
|
|
|
// implementation for platforms that doesn't support weak symbols. For example:
|
|
|
|
//
|
|
|
|
// #if !SANITIZER_SUPPORT_WEAK_HOOKS
|
|
|
|
// SANITIZER_INTERFACE_WEAK_DEF(bool, compare_hook, int a, int b) {
|
|
|
|
// return a > b;
|
|
|
|
// }
|
|
|
|
// #endif
|
|
|
|
//
|
|
|
|
// And then use it as: if (compare_hook) compare_hook(a, b);
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2013-01-30 21:12:08 +08:00
|
|
|
|
2014-07-26 06:05:02 +08:00
|
|
|
// We can use .preinit_array section on Linux to call sanitizer initialization
|
|
|
|
// functions very early in the process startup (unless PIC macro is defined).
|
2018-07-02 01:52:41 +08:00
|
|
|
//
|
|
|
|
// On FreeBSD, .preinit_array functions are called with rtld_bind_lock writer
|
|
|
|
// lock held. It will lead to dead lock if unresolved PLT functions (which helds
|
|
|
|
// rtld_bind_lock reader lock) are called inside .preinit_array functions.
|
|
|
|
//
|
2014-07-26 06:05:02 +08:00
|
|
|
// FIXME: do we have anything like this on Mac?
|
2018-02-22 05:13:07 +08:00
|
|
|
#ifndef SANITIZER_CAN_USE_PREINIT_ARRAY
|
2018-09-17 13:22:26 +08:00
|
|
|
#if ((SANITIZER_LINUX && !SANITIZER_ANDROID) || SANITIZER_OPENBSD || \
|
2019-12-19 10:21:46 +08:00
|
|
|
SANITIZER_FUCHSIA || SANITIZER_NETBSD) && !defined(PIC)
|
2018-07-02 01:52:41 +08:00
|
|
|
#define SANITIZER_CAN_USE_PREINIT_ARRAY 1
|
[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
|
|
|
// Before Solaris 11.4, .preinit_array is fully supported only with GNU ld.
|
|
|
|
// FIXME: Check for those conditions.
|
|
|
|
#elif SANITIZER_SOLARIS && !defined(PIC)
|
|
|
|
# define SANITIZER_CAN_USE_PREINIT_ARRAY 1
|
2014-07-26 06:05:02 +08:00
|
|
|
#else
|
|
|
|
# define SANITIZER_CAN_USE_PREINIT_ARRAY 0
|
|
|
|
#endif
|
2018-02-22 05:13:07 +08:00
|
|
|
#endif // SANITIZER_CAN_USE_PREINIT_ARRAY
|
2014-07-26 06:05:02 +08:00
|
|
|
|
[asan] make asan work with 7fff8000 offset and prelink
When prelink is installed in the system, prelink-ed
libraries map between 0x003000000000 and 0x004000000000 thus occupying the shadow Gap,
so we need so split the address space even further, like this:
|| [0x10007fff8000, 0x7fffffffffff] || HighMem ||
|| [0x02008fff7000, 0x10007fff7fff] || HighShadow ||
|| [0x004000000000, 0x02008fff6fff] || ShadowGap3 ||
|| [0x003000000000, 0x003fffffffff] || MidMem ||
|| [0x00087fff8000, 0x002fffffffff] || ShadowGap2 ||
|| [0x00067fff8000, 0x00087fff7fff] || MidShadow ||
|| [0x00008fff7000, 0x00067fff7fff] || ShadowGap ||
|| [0x00007fff8000, 0x00008fff6fff] || LowShadow ||
|| [0x000000000000, 0x00007fff7fff] || LowMem ||
Do it only if necessary.
Also added a bit of profiling code to make sure that the
mapping code is efficient.
Added a lit test to simulate prelink-ed libraries.
Unfortunately, this test does not work with binutils-gold linker.
If gold is the default linker the test silently passes.
Also replaced
__has_feature(address_sanitizer)
with
__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
in two places.
Patch partially by Jakub Jelinek.
llvm-svn: 175263
2013-02-15 20:00:24 +08:00
|
|
|
// GCC does not understand __has_feature
|
2013-01-30 21:12:08 +08:00
|
|
|
#if !defined(__has_feature)
|
|
|
|
# define __has_feature(x) 0
|
|
|
|
#endif
|
|
|
|
|
2018-07-21 03:24:11 +08:00
|
|
|
// Older GCCs do not understand __has_attribute.
|
|
|
|
#if !defined(__has_attribute)
|
|
|
|
# define __has_attribute(x) 0
|
|
|
|
#endif
|
|
|
|
|
2013-01-30 21:12:08 +08:00
|
|
|
// For portability reasons we do not include stddef.h, stdint.h or any other
|
|
|
|
// system header, but we do need some basic types that are not defined
|
|
|
|
// in a portable way by the language itself.
|
|
|
|
namespace __sanitizer {
|
|
|
|
|
|
|
|
#if defined(_WIN64)
|
|
|
|
// 64-bit Windows uses LLP64 data model.
|
2019-09-12 07:19:48 +08:00
|
|
|
typedef unsigned long long uptr;
|
|
|
|
typedef signed long long sptr;
|
2013-01-30 21:12:08 +08:00
|
|
|
#else
|
2019-09-12 07:19:48 +08:00
|
|
|
typedef unsigned long uptr;
|
|
|
|
typedef signed long sptr;
|
2013-01-30 21:12:08 +08:00
|
|
|
#endif // defined(_WIN64)
|
2014-05-21 15:34:03 +08:00
|
|
|
#if defined(__x86_64__)
|
|
|
|
// Since x32 uses ILP32 data model in 64-bit hardware mode, we must use
|
|
|
|
// 64-bit pointer to unwind stack frame.
|
2019-09-12 07:19:48 +08:00
|
|
|
typedef unsigned long long uhwptr;
|
2014-05-21 15:34:03 +08:00
|
|
|
#else
|
2019-09-12 07:19:48 +08:00
|
|
|
typedef uptr uhwptr;
|
2014-05-21 15:34:03 +08:00
|
|
|
#endif
|
2013-01-30 21:12:08 +08:00
|
|
|
typedef unsigned char u8;
|
2019-09-12 07:19:48 +08:00
|
|
|
typedef unsigned short u16;
|
2013-01-30 21:12:08 +08:00
|
|
|
typedef unsigned int u32;
|
2019-09-12 07:19:48 +08:00
|
|
|
typedef unsigned long long u64;
|
|
|
|
typedef signed char s8;
|
|
|
|
typedef signed short s16;
|
|
|
|
typedef signed int s32;
|
|
|
|
typedef signed long long s64;
|
2015-04-09 23:25:21 +08:00
|
|
|
#if SANITIZER_WINDOWS
|
|
|
|
// On Windows, files are HANDLE, which is a synonim of void*.
|
|
|
|
// Use void* to avoid including <windows.h> everywhere.
|
|
|
|
typedef void* fd_t;
|
|
|
|
typedef unsigned error_t;
|
|
|
|
#else
|
2013-02-01 23:58:46 +08:00
|
|
|
typedef int fd_t;
|
2015-04-09 00:03:22 +08:00
|
|
|
typedef int error_t;
|
2015-04-09 23:25:21 +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_SOLARIS && !defined(_LP64)
|
|
|
|
typedef long pid_t;
|
|
|
|
#else
|
2016-01-27 04:10:01 +08:00
|
|
|
typedef int pid_t;
|
[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
|
|
|
#endif
|
2013-01-30 21:12:08 +08:00
|
|
|
|
2018-03-03 20:12:03 +08:00
|
|
|
#if SANITIZER_FREEBSD || SANITIZER_NETBSD || \
|
|
|
|
SANITIZER_OPENBSD || SANITIZER_MAC || \
|
2018-11-06 03:19:15 +08:00
|
|
|
(SANITIZER_SOLARIS && (defined(_LP64) || _FILE_OFFSET_BITS == 64)) || \
|
2017-08-08 19:40:15 +08:00
|
|
|
(SANITIZER_LINUX && defined(__x86_64__))
|
2013-02-27 19:22:40 +08:00
|
|
|
typedef u64 OFF_T;
|
|
|
|
#else
|
|
|
|
typedef uptr OFF_T;
|
|
|
|
#endif
|
|
|
|
typedef u64 OFF64_T;
|
2013-10-24 14:23:39 +08:00
|
|
|
|
|
|
|
#if (SANITIZER_WORDSIZE == 64) || SANITIZER_MAC
|
|
|
|
typedef uptr operator_new_size_type;
|
|
|
|
#else
|
2018-03-04 02:38:20 +08:00
|
|
|
# if SANITIZER_OPENBSD || defined(__s390__) && !defined(__s390x__)
|
2016-04-15 05:17:19 +08:00
|
|
|
// Special case: 31-bit s390 has unsigned long as size_t.
|
|
|
|
typedef unsigned long operator_new_size_type;
|
|
|
|
# else
|
2013-10-24 14:23:39 +08:00
|
|
|
typedef u32 operator_new_size_type;
|
2016-04-15 05:17:19 +08:00
|
|
|
# endif
|
2013-10-24 14:23:39 +08:00
|
|
|
#endif
|
2013-01-30 21:12:08 +08:00
|
|
|
|
2017-04-18 02:17:38 +08:00
|
|
|
typedef u64 tid_t;
|
2013-01-30 21:12:08 +08:00
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
// ----------- ATTENTION -------------
|
|
|
|
// This header should NOT include any other headers to avoid portability issues.
|
|
|
|
|
2012-06-05 21:50:57 +08:00
|
|
|
// Common defs.
|
2018-12-08 04:05:55 +08:00
|
|
|
#ifndef INLINE
|
2013-04-12 17:37:20 +08:00
|
|
|
#define INLINE inline
|
2018-12-08 04:05:55 +08:00
|
|
|
#endif
|
2012-06-05 21:50:57 +08:00
|
|
|
#define INTERFACE_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE
|
2015-11-30 21:27:18 +08:00
|
|
|
#define SANITIZER_WEAK_DEFAULT_IMPL \
|
|
|
|
extern "C" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE
|
|
|
|
#define SANITIZER_WEAK_CXX_DEFAULT_IMPL \
|
|
|
|
extern "C++" SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE NOINLINE
|
2012-06-05 21:50:57 +08:00
|
|
|
|
|
|
|
// Platform-specific defs.
|
2012-11-06 20:47:42 +08:00
|
|
|
#if defined(_MSC_VER)
|
2013-04-12 17:37:20 +08:00
|
|
|
# define ALWAYS_INLINE __forceinline
|
2012-06-05 21:50:57 +08:00
|
|
|
// FIXME(timurrrr): do we need this on Windows?
|
|
|
|
# define ALIAS(x)
|
|
|
|
# define ALIGNED(x) __declspec(align(x))
|
2012-06-06 21:37:02 +08:00
|
|
|
# define FORMAT(f, a)
|
2012-06-05 21:50:57 +08:00
|
|
|
# define NOINLINE __declspec(noinline)
|
|
|
|
# define NORETURN __declspec(noreturn)
|
|
|
|
# define THREADLOCAL __declspec(thread)
|
2012-11-06 20:54:16 +08:00
|
|
|
# define LIKELY(x) (x)
|
|
|
|
# define UNLIKELY(x) (x)
|
2016-06-18 01:48:52 +08:00
|
|
|
# define PREFETCH(x) /* _mm_prefetch(x, _MM_HINT_NTA) */ (void)0
|
2018-07-20 16:33:41 +08:00
|
|
|
# define WARN_UNUSED_RESULT
|
2012-11-06 20:47:42 +08:00
|
|
|
#else // _MSC_VER
|
2013-03-29 17:44:16 +08:00
|
|
|
# define ALWAYS_INLINE inline __attribute__((always_inline))
|
2012-06-05 21:50:57 +08:00
|
|
|
# define ALIAS(x) __attribute__((alias(x)))
|
2013-06-04 16:25:17 +08:00
|
|
|
// Please only use the ALIGNED macro before the type.
|
|
|
|
// Using ALIGNED after the variable declaration is not portable!
|
2012-06-05 21:50:57 +08:00
|
|
|
# define ALIGNED(x) __attribute__((aligned(x)))
|
2012-06-06 21:37:02 +08:00
|
|
|
# define FORMAT(f, a) __attribute__((format(printf, f, a)))
|
2012-06-05 21:50:57 +08:00
|
|
|
# define NOINLINE __attribute__((noinline))
|
|
|
|
# define NORETURN __attribute__((noreturn))
|
|
|
|
# define THREADLOCAL __thread
|
|
|
|
# define LIKELY(x) __builtin_expect(!!(x), 1)
|
|
|
|
# define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
2013-01-16 22:35:13 +08:00
|
|
|
# if defined(__i386__) || defined(__x86_64__)
|
|
|
|
// __builtin_prefetch(x) generates prefetchnt0 on x86
|
|
|
|
# define PREFETCH(x) __asm__("prefetchnta (%0)" : : "r" (x))
|
|
|
|
# else
|
|
|
|
# define PREFETCH(x) __builtin_prefetch(x)
|
|
|
|
# endif
|
2018-07-20 16:33:41 +08:00
|
|
|
# define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
2012-11-06 20:54:16 +08:00
|
|
|
#endif // _MSC_VER
|
2012-05-31 22:11:07 +08:00
|
|
|
|
2014-05-12 22:44:29 +08:00
|
|
|
#if !defined(_MSC_VER) || defined(__clang__)
|
|
|
|
# define UNUSED __attribute__((unused))
|
|
|
|
# define USED __attribute__((used))
|
|
|
|
#else
|
|
|
|
# define UNUSED
|
|
|
|
# define USED
|
|
|
|
#endif
|
|
|
|
|
2015-08-10 23:24:22 +08:00
|
|
|
#if !defined(_MSC_VER) || defined(__clang__) || MSC_PREREQ(1900)
|
|
|
|
# define NOEXCEPT noexcept
|
|
|
|
#else
|
|
|
|
# define NOEXCEPT throw()
|
|
|
|
#endif
|
|
|
|
|
2013-06-04 22:06:16 +08:00
|
|
|
// Unaligned versions of basic types.
|
|
|
|
typedef ALIGNED(1) u16 uu16;
|
|
|
|
typedef ALIGNED(1) u32 uu32;
|
|
|
|
typedef ALIGNED(1) u64 uu64;
|
|
|
|
typedef ALIGNED(1) s16 us16;
|
|
|
|
typedef ALIGNED(1) s32 us32;
|
|
|
|
typedef ALIGNED(1) s64 us64;
|
|
|
|
|
2013-03-19 22:54:17 +08:00
|
|
|
#if SANITIZER_WINDOWS
|
2016-01-16 09:15:19 +08:00
|
|
|
} // namespace __sanitizer
|
2019-09-12 07:19:48 +08:00
|
|
|
typedef unsigned long DWORD;
|
2016-01-16 09:15:19 +08:00
|
|
|
namespace __sanitizer {
|
2012-06-15 15:29:14 +08:00
|
|
|
typedef DWORD thread_return_t;
|
|
|
|
# define THREAD_CALLING_CONV __stdcall
|
|
|
|
#else // _WIN32
|
|
|
|
typedef void* thread_return_t;
|
|
|
|
# define THREAD_CALLING_CONV
|
|
|
|
#endif // _WIN32
|
|
|
|
typedef thread_return_t (THREAD_CALLING_CONV *thread_callback_t)(void* arg);
|
|
|
|
|
2012-06-06 23:22:20 +08:00
|
|
|
// NOTE: Functions below must be defined in each run-time.
|
|
|
|
void NORETURN Die();
|
2013-08-13 20:03:51 +08:00
|
|
|
|
2012-06-06 23:22:20 +08:00
|
|
|
void NORETURN CheckFailed(const char *file, int line, const char *cond,
|
|
|
|
u64 v1, u64 v2);
|
|
|
|
|
|
|
|
// Check macro
|
2012-06-06 17:26:25 +08:00
|
|
|
#define RAW_CHECK_MSG(expr, msg) do { \
|
2014-05-14 22:03:31 +08:00
|
|
|
if (UNLIKELY(!(expr))) { \
|
2012-06-06 17:26:25 +08:00
|
|
|
RawWrite(msg); \
|
|
|
|
Die(); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define RAW_CHECK(expr) RAW_CHECK_MSG(expr, #expr)
|
|
|
|
|
2012-06-06 23:22:20 +08:00
|
|
|
#define CHECK_IMPL(c1, op, c2) \
|
|
|
|
do { \
|
2017-09-15 12:05:15 +08:00
|
|
|
__sanitizer::u64 v1 = (__sanitizer::u64)(c1); \
|
|
|
|
__sanitizer::u64 v2 = (__sanitizer::u64)(c2); \
|
2014-05-14 22:03:31 +08:00
|
|
|
if (UNLIKELY(!(v1 op v2))) \
|
2012-06-06 23:22:20 +08:00
|
|
|
__sanitizer::CheckFailed(__FILE__, __LINE__, \
|
|
|
|
"(" #c1 ") " #op " (" #c2 ")", v1, v2); \
|
|
|
|
} while (false) \
|
|
|
|
/**/
|
|
|
|
|
|
|
|
#define CHECK(a) CHECK_IMPL((a), !=, 0)
|
|
|
|
#define CHECK_EQ(a, b) CHECK_IMPL((a), ==, (b))
|
|
|
|
#define CHECK_NE(a, b) CHECK_IMPL((a), !=, (b))
|
|
|
|
#define CHECK_LT(a, b) CHECK_IMPL((a), <, (b))
|
|
|
|
#define CHECK_LE(a, b) CHECK_IMPL((a), <=, (b))
|
|
|
|
#define CHECK_GT(a, b) CHECK_IMPL((a), >, (b))
|
|
|
|
#define CHECK_GE(a, b) CHECK_IMPL((a), >=, (b))
|
|
|
|
|
2015-01-03 12:29:12 +08:00
|
|
|
#if SANITIZER_DEBUG
|
2012-06-30 00:58:33 +08:00
|
|
|
#define DCHECK(a) CHECK(a)
|
|
|
|
#define DCHECK_EQ(a, b) CHECK_EQ(a, b)
|
|
|
|
#define DCHECK_NE(a, b) CHECK_NE(a, b)
|
|
|
|
#define DCHECK_LT(a, b) CHECK_LT(a, b)
|
|
|
|
#define DCHECK_LE(a, b) CHECK_LE(a, b)
|
|
|
|
#define DCHECK_GT(a, b) CHECK_GT(a, b)
|
|
|
|
#define DCHECK_GE(a, b) CHECK_GE(a, b)
|
|
|
|
#else
|
|
|
|
#define DCHECK(a)
|
|
|
|
#define DCHECK_EQ(a, b)
|
|
|
|
#define DCHECK_NE(a, b)
|
|
|
|
#define DCHECK_LT(a, b)
|
|
|
|
#define DCHECK_LE(a, b)
|
|
|
|
#define DCHECK_GT(a, b)
|
|
|
|
#define DCHECK_GE(a, b)
|
|
|
|
#endif
|
|
|
|
|
2012-10-09 16:42:07 +08:00
|
|
|
#define UNREACHABLE(msg) do { \
|
|
|
|
CHECK(0 && msg); \
|
|
|
|
Die(); \
|
2012-10-16 12:50:32 +08:00
|
|
|
} while (0)
|
2012-10-09 16:42:07 +08:00
|
|
|
|
|
|
|
#define UNIMPLEMENTED() UNREACHABLE("unimplemented")
|
2012-06-06 23:47:40 +08:00
|
|
|
|
2012-06-21 18:04:36 +08:00
|
|
|
#define COMPILER_CHECK(pred) IMPL_COMPILER_ASSERT(pred, __LINE__)
|
|
|
|
|
2012-08-28 19:54:51 +08:00
|
|
|
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
|
|
|
|
|
2012-06-21 18:04:36 +08:00
|
|
|
#define IMPL_PASTE(a, b) a##b
|
|
|
|
#define IMPL_COMPILER_ASSERT(pred, line) \
|
2012-09-11 18:31:28 +08:00
|
|
|
typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
|
2012-06-21 18:04:36 +08:00
|
|
|
|
2012-06-15 21:09:52 +08:00
|
|
|
// Limits for integral types. We have to redefine it in case we don't
|
|
|
|
// have stdint.h (like in Visual Studio 9).
|
2012-09-24 19:43:40 +08:00
|
|
|
#undef __INT64_C
|
|
|
|
#undef __UINT64_C
|
2012-11-21 20:38:58 +08:00
|
|
|
#if SANITIZER_WORDSIZE == 64
|
2012-06-15 21:09:52 +08:00
|
|
|
# define __INT64_C(c) c ## L
|
|
|
|
# define __UINT64_C(c) c ## UL
|
|
|
|
#else
|
|
|
|
# define __INT64_C(c) c ## LL
|
|
|
|
# define __UINT64_C(c) c ## ULL
|
2012-11-21 20:38:58 +08:00
|
|
|
#endif // SANITIZER_WORDSIZE == 64
|
2012-06-15 21:09:52 +08:00
|
|
|
#undef INT32_MIN
|
|
|
|
#define INT32_MIN (-2147483647-1)
|
|
|
|
#undef INT32_MAX
|
|
|
|
#define INT32_MAX (2147483647)
|
|
|
|
#undef UINT32_MAX
|
|
|
|
#define UINT32_MAX (4294967295U)
|
|
|
|
#undef INT64_MIN
|
|
|
|
#define INT64_MIN (-__INT64_C(9223372036854775807)-1)
|
|
|
|
#undef INT64_MAX
|
|
|
|
#define INT64_MAX (__INT64_C(9223372036854775807))
|
|
|
|
#undef UINT64_MAX
|
|
|
|
#define UINT64_MAX (__UINT64_C(18446744073709551615))
|
2018-05-24 02:13:21 +08:00
|
|
|
#undef UINTPTR_MAX
|
|
|
|
#if SANITIZER_WORDSIZE == 64
|
|
|
|
# define UINTPTR_MAX (18446744073709551615UL)
|
|
|
|
#else
|
|
|
|
# define UINTPTR_MAX (4294967295U)
|
|
|
|
#endif // SANITIZER_WORDSIZE == 64
|
2012-06-15 21:09:52 +08:00
|
|
|
|
2012-08-27 17:30:58 +08:00
|
|
|
enum LinkerInitialized { LINKER_INITIALIZED = 0 };
|
|
|
|
|
2012-09-24 19:43:40 +08:00
|
|
|
#if !defined(_MSC_VER) || defined(__clang__)
|
Fix AddressSanitizer on s390 (31-bit)
Summary:
GET_CALLER_PC doesn't work properly on 31-bit s390, as pointers are 31-bit, the MSB bit can be set when the return address is copied into integer.
This causes e.g. errors like:
#0 0xfdadb129 (<unknown module>)
#1 0x7da5e1d1 in __asan::GetStackTraceWithPcBpAndContext(__sanitizer::BufferedStackTrace*, unsigned long, unsigned long, unsigned long, void*, bool) ../../../../../libsanitizer/asan/asan_stack.h:50
#2 0x7da5e1d1 in __asan::ErrorGeneric::Print() ../../../../../libsanitizer/asan/asan_errors.cc:482
#3 0x7db178d5 in __asan::ErrorDescription::Print() ../../../../../libsanitizer/asan/asan_errors.h:360
#4 0x7db178d5 in __asan::ScopedInErrorReport::~ScopedInErrorReport() ../../../../../libsanitizer/asan/asan_report.cc:167
#5 0x7db178d5 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) ../../../../../libsanitizer/asan/asan_report.cc:397
#6 0x7dadb14f in __interceptor_memcmp ../../../../../libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:626
#7 0x400cf5 in main /home/jakub/gcc/gcc/testsuite/c-c++-common/asan/memcmp-1.c:14
#8 0x7d807215 in __libc_start_main (/lib/libc.so.6+0x1a215)
#9 0x4007ed (/home/jakub/gcc/obj/gcc/testsuite/memcmp-1.exe+0x4007ed)
The actual return PC inside __interceptor_memcmp was 0x7dadb129 rather than 0xfdadb129.
Reviewers: koriakin, kcc
Reviewed By: kcc
Subscribers: kubamracek
Differential Revision: https://reviews.llvm.org/D29824
llvm-svn: 294793
2017-02-11 06:26:19 +08:00
|
|
|
#if SANITIZER_S390_31
|
|
|
|
#define GET_CALLER_PC() \
|
|
|
|
(__sanitizer::uptr) __builtin_extract_return_addr(__builtin_return_address(0))
|
|
|
|
#else
|
2017-01-06 05:25:20 +08:00
|
|
|
#define GET_CALLER_PC() (__sanitizer::uptr) __builtin_return_address(0)
|
Fix AddressSanitizer on s390 (31-bit)
Summary:
GET_CALLER_PC doesn't work properly on 31-bit s390, as pointers are 31-bit, the MSB bit can be set when the return address is copied into integer.
This causes e.g. errors like:
#0 0xfdadb129 (<unknown module>)
#1 0x7da5e1d1 in __asan::GetStackTraceWithPcBpAndContext(__sanitizer::BufferedStackTrace*, unsigned long, unsigned long, unsigned long, void*, bool) ../../../../../libsanitizer/asan/asan_stack.h:50
#2 0x7da5e1d1 in __asan::ErrorGeneric::Print() ../../../../../libsanitizer/asan/asan_errors.cc:482
#3 0x7db178d5 in __asan::ErrorDescription::Print() ../../../../../libsanitizer/asan/asan_errors.h:360
#4 0x7db178d5 in __asan::ScopedInErrorReport::~ScopedInErrorReport() ../../../../../libsanitizer/asan/asan_report.cc:167
#5 0x7db178d5 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) ../../../../../libsanitizer/asan/asan_report.cc:397
#6 0x7dadb14f in __interceptor_memcmp ../../../../../libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:626
#7 0x400cf5 in main /home/jakub/gcc/gcc/testsuite/c-c++-common/asan/memcmp-1.c:14
#8 0x7d807215 in __libc_start_main (/lib/libc.so.6+0x1a215)
#9 0x4007ed (/home/jakub/gcc/obj/gcc/testsuite/memcmp-1.exe+0x4007ed)
The actual return PC inside __interceptor_memcmp was 0x7dadb129 rather than 0xfdadb129.
Reviewers: koriakin, kcc
Reviewed By: kcc
Subscribers: kubamracek
Differential Revision: https://reviews.llvm.org/D29824
llvm-svn: 294793
2017-02-11 06:26:19 +08:00
|
|
|
#endif
|
2017-01-06 05:25:20 +08:00
|
|
|
#define GET_CURRENT_FRAME() (__sanitizer::uptr) __builtin_frame_address(0)
|
2016-01-16 08:31:29 +08:00
|
|
|
inline void Trap() {
|
|
|
|
__builtin_trap();
|
|
|
|
}
|
2012-08-28 22:11:57 +08:00
|
|
|
#else
|
2012-08-28 23:25:07 +08:00
|
|
|
extern "C" void* _ReturnAddress(void);
|
2016-08-06 00:01:57 +08:00
|
|
|
extern "C" void* _AddressOfReturnAddress(void);
|
2012-08-28 23:25:07 +08:00
|
|
|
# pragma intrinsic(_ReturnAddress)
|
2016-08-06 00:01:57 +08:00
|
|
|
# pragma intrinsic(_AddressOfReturnAddress)
|
2017-01-06 05:25:20 +08:00
|
|
|
#define GET_CALLER_PC() (__sanitizer::uptr) _ReturnAddress()
|
2012-08-28 22:11:57 +08:00
|
|
|
// CaptureStackBackTrace doesn't need to know BP on Windows.
|
2017-01-06 05:25:20 +08:00
|
|
|
#define GET_CURRENT_FRAME() \
|
|
|
|
(((__sanitizer::uptr)_AddressOfReturnAddress()) + sizeof(__sanitizer::uptr))
|
2016-01-16 08:31:29 +08:00
|
|
|
|
|
|
|
extern "C" void __ud2(void);
|
|
|
|
# pragma intrinsic(__ud2)
|
|
|
|
inline void Trap() {
|
|
|
|
__ud2();
|
|
|
|
}
|
2012-08-28 22:11:57 +08:00
|
|
|
#endif
|
|
|
|
|
2013-05-08 22:43:49 +08:00
|
|
|
#define HANDLE_EINTR(res, f) \
|
|
|
|
{ \
|
|
|
|
int rverrno; \
|
|
|
|
do { \
|
|
|
|
res = (f); \
|
|
|
|
} while (internal_iserror(res, &rverrno) && rverrno == EINTR); \
|
2012-10-02 21:41:40 +08:00
|
|
|
}
|
|
|
|
|
2015-01-23 07:36:47 +08:00
|
|
|
// Forces the compiler to generate a frame pointer in the function.
|
2017-01-06 05:25:20 +08:00
|
|
|
#define ENABLE_FRAME_POINTER \
|
|
|
|
do { \
|
|
|
|
volatile __sanitizer::uptr enable_fp; \
|
|
|
|
enable_fp = GET_CURRENT_FRAME(); \
|
|
|
|
(void)enable_fp; \
|
2015-01-23 07:36:47 +08:00
|
|
|
} while (0)
|
|
|
|
|
2016-01-16 08:31:29 +08:00
|
|
|
} // namespace __sanitizer
|
|
|
|
|
2019-09-12 07:19:48 +08:00
|
|
|
namespace __asan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __dsan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __dfsan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __lsan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __msan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __hwasan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __tsan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __scudo {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __ubsan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __xray {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __interception {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
|
|
|
namespace __hwasan {
|
|
|
|
using namespace __sanitizer;
|
|
|
|
}
|
2016-01-16 08:31:29 +08:00
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
#endif // SANITIZER_DEFS_H
|