sanitizer_platform.h revision 314564
1251034Sed//===-- sanitizer_platform.h ------------------------------------*- C++ -*-===// 2251034Sed// 3251034Sed// The LLVM Compiler Infrastructure 4251034Sed// 5251034Sed// This file is distributed under the University of Illinois Open Source 6251034Sed// License. See LICENSE.TXT for details. 7251034Sed// 8251034Sed//===----------------------------------------------------------------------===// 9251034Sed// 10251034Sed// Common platform macros. 11251034Sed//===----------------------------------------------------------------------===// 12251034Sed 13251034Sed#ifndef SANITIZER_PLATFORM_H 14251034Sed#define SANITIZER_PLATFORM_H 15251034Sed 16276789Sdim#if !defined(__linux__) && !defined(__FreeBSD__) && \ 17276789Sdim !defined(__APPLE__) && !defined(_WIN32) 18251034Sed# error "This operating system is not supported" 19251034Sed#endif 20251034Sed 21251034Sed#if defined(__linux__) 22251034Sed# define SANITIZER_LINUX 1 23251034Sed#else 24251034Sed# define SANITIZER_LINUX 0 25251034Sed#endif 26251034Sed 27276789Sdim#if defined(__FreeBSD__) 28276789Sdim# define SANITIZER_FREEBSD 1 29276789Sdim#else 30276789Sdim# define SANITIZER_FREEBSD 0 31276789Sdim#endif 32276789Sdim 33251034Sed#if defined(__APPLE__) 34251034Sed# define SANITIZER_MAC 1 35274201Sdim# include <TargetConditionals.h> 36274201Sdim# if TARGET_OS_IPHONE 37274201Sdim# define SANITIZER_IOS 1 38274201Sdim# else 39274201Sdim# define SANITIZER_IOS 0 40274201Sdim# endif 41288943Sdim# if TARGET_IPHONE_SIMULATOR 42288943Sdim# define SANITIZER_IOSSIM 1 43288943Sdim# else 44288943Sdim# define SANITIZER_IOSSIM 0 45288943Sdim# endif 46251034Sed#else 47251034Sed# define SANITIZER_MAC 0 48274201Sdim# define SANITIZER_IOS 0 49288943Sdim# define SANITIZER_IOSSIM 0 50251034Sed#endif 51251034Sed 52309124Sdim#if defined(__APPLE__) && TARGET_OS_IPHONE && TARGET_OS_WATCH 53309124Sdim# define SANITIZER_WATCHOS 1 54309124Sdim#else 55309124Sdim# define SANITIZER_WATCHOS 0 56309124Sdim#endif 57309124Sdim 58309124Sdim#if defined(__APPLE__) && TARGET_OS_IPHONE && TARGET_OS_TV 59309124Sdim# define SANITIZER_TVOS 1 60309124Sdim#else 61309124Sdim# define SANITIZER_TVOS 0 62309124Sdim#endif 63309124Sdim 64251034Sed#if defined(_WIN32) 65251034Sed# define SANITIZER_WINDOWS 1 66251034Sed#else 67251034Sed# define SANITIZER_WINDOWS 0 68251034Sed#endif 69251034Sed 70309124Sdim#if defined(_WIN64) 71309124Sdim# define SANITIZER_WINDOWS64 1 72309124Sdim#else 73309124Sdim# define SANITIZER_WINDOWS64 0 74309124Sdim#endif 75309124Sdim 76276789Sdim#if defined(__ANDROID__) 77251034Sed# define SANITIZER_ANDROID 1 78251034Sed#else 79251034Sed# define SANITIZER_ANDROID 0 80251034Sed#endif 81251034Sed 82276789Sdim#define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC) 83251034Sed 84276789Sdim#if __LP64__ || defined(_WIN64) 85276789Sdim# define SANITIZER_WORDSIZE 64 86276789Sdim#else 87276789Sdim# define SANITIZER_WORDSIZE 32 88276789Sdim#endif 89276789Sdim 90276789Sdim#if SANITIZER_WORDSIZE == 64 91276789Sdim# define FIRST_32_SECOND_64(a, b) (b) 92276789Sdim#else 93276789Sdim# define FIRST_32_SECOND_64(a, b) (a) 94276789Sdim#endif 95276789Sdim 96276789Sdim#if defined(__x86_64__) && !defined(_LP64) 97276789Sdim# define SANITIZER_X32 1 98276789Sdim#else 99276789Sdim# define SANITIZER_X32 0 100276789Sdim#endif 101276789Sdim 102309124Sdim#if defined(__mips__) 103309124Sdim# define SANITIZER_MIPS 1 104309124Sdim# if defined(__mips64) 105309124Sdim# define SANITIZER_MIPS32 0 106309124Sdim# define SANITIZER_MIPS64 1 107309124Sdim# else 108309124Sdim# define SANITIZER_MIPS32 1 109309124Sdim# define SANITIZER_MIPS64 0 110309124Sdim# endif 111309124Sdim#else 112309124Sdim# define SANITIZER_MIPS 0 113309124Sdim# define SANITIZER_MIPS32 0 114309124Sdim# define SANITIZER_MIPS64 0 115309124Sdim#endif 116309124Sdim 117309124Sdim#if defined(__s390__) 118309124Sdim# define SANITIZER_S390 1 119309124Sdim# if defined(__s390x__) 120309124Sdim# define SANITIZER_S390_31 0 121309124Sdim# define SANITIZER_S390_64 1 122309124Sdim# else 123309124Sdim# define SANITIZER_S390_31 1 124309124Sdim# define SANITIZER_S390_64 0 125309124Sdim# endif 126309124Sdim#else 127309124Sdim# define SANITIZER_S390 0 128309124Sdim# define SANITIZER_S390_31 0 129309124Sdim# define SANITIZER_S390_64 0 130309124Sdim#endif 131309124Sdim 132309124Sdim#if defined(__powerpc__) 133309124Sdim# define SANITIZER_PPC 1 134309124Sdim# if defined(__powerpc64__) 135309124Sdim# define SANITIZER_PPC32 0 136309124Sdim# define SANITIZER_PPC64 1 137309124Sdim// 64-bit PPC has two ABIs (v1 and v2). The old powerpc64 target is 138309124Sdim// big-endian, and uses v1 ABI (known for its function descriptors), 139309124Sdim// while the new powerpc64le target is little-endian and uses v2. 140309124Sdim// In theory, you could convince gcc to compile for their evil twins 141309124Sdim// (eg. big-endian v2), but you won't find such combinations in the wild 142309124Sdim// (it'd require bootstrapping a whole system, which would be quite painful 143309124Sdim// - there's no target triple for that). LLVM doesn't support them either. 144309124Sdim# if _CALL_ELF == 2 145309124Sdim# define SANITIZER_PPC64V1 0 146309124Sdim# define SANITIZER_PPC64V2 1 147309124Sdim# else 148309124Sdim# define SANITIZER_PPC64V1 1 149309124Sdim# define SANITIZER_PPC64V2 0 150309124Sdim# endif 151309124Sdim# else 152309124Sdim# define SANITIZER_PPC32 1 153309124Sdim# define SANITIZER_PPC64 0 154309124Sdim# define SANITIZER_PPC64V1 0 155309124Sdim# define SANITIZER_PPC64V2 0 156309124Sdim# endif 157309124Sdim#else 158309124Sdim# define SANITIZER_PPC 0 159309124Sdim# define SANITIZER_PPC32 0 160309124Sdim# define SANITIZER_PPC64 0 161309124Sdim# define SANITIZER_PPC64V1 0 162309124Sdim# define SANITIZER_PPC64V2 0 163309124Sdim#endif 164309124Sdim 165276789Sdim// By default we allow to use SizeClassAllocator64 on 64-bit platform. 166276789Sdim// But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64 167276789Sdim// does not work well and we need to fallback to SizeClassAllocator32. 168276789Sdim// For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or 169276789Sdim// change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here. 170276789Sdim#ifndef SANITIZER_CAN_USE_ALLOCATOR64 171314564Sdim# if SANITIZER_ANDROID && defined(__aarch64__) 172314564Sdim# define SANITIZER_CAN_USE_ALLOCATOR64 1 173314564Sdim# elif defined(__mips64) || defined(__aarch64__) 174276789Sdim# define SANITIZER_CAN_USE_ALLOCATOR64 0 175276789Sdim# else 176276789Sdim# define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64) 177276789Sdim# endif 178276789Sdim#endif 179276789Sdim 180276789Sdim// The range of addresses which can be returned my mmap. 181296417Sdim// FIXME: this value should be different on different platforms. Larger values 182296417Sdim// will still work but will consume more memory for TwoLevelByteMap. 183296417Sdim#if defined(__mips__) 184276789Sdim# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40) 185309124Sdim#elif defined(__aarch64__) 186309124Sdim# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 48) 187276789Sdim#else 188276789Sdim# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47) 189276789Sdim#endif 190276789Sdim 191276789Sdim// The AArch64 linux port uses the canonical syscall set as mandated by 192276789Sdim// the upstream linux community for all new ports. Other ports may still 193276789Sdim// use legacy syscalls. 194276789Sdim#ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 195276789Sdim# if defined(__aarch64__) && SANITIZER_LINUX 196276789Sdim# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1 197276789Sdim# else 198276789Sdim# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0 199276789Sdim# endif 200276789Sdim#endif 201276789Sdim 202288943Sdim// udi16 syscalls can only be used when the following conditions are 203288943Sdim// met: 204288943Sdim// * target is one of arm32, x86-32, sparc32, sh or m68k 205288943Sdim// * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15 206288943Sdim// built against > linux-2.2 kernel headers 207288943Sdim// Since we don't want to include libc headers here, we check the 208288943Sdim// target only. 209288943Sdim#if defined(__arm__) || SANITIZER_X32 || defined(__sparc__) 210288943Sdim#define SANITIZER_USES_UID16_SYSCALLS 1 211288943Sdim#else 212288943Sdim#define SANITIZER_USES_UID16_SYSCALLS 0 213288943Sdim#endif 214288943Sdim 215296417Sdim#if defined(__mips__) 216276789Sdim# define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10) 217276789Sdim#else 218276789Sdim# define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12) 219276789Sdim#endif 220276789Sdim 221288943Sdim// Assume obsolete RPC headers are available by default 222288943Sdim#if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H) 223288943Sdim# define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID) 224288943Sdim# define HAVE_TIRPC_RPC_XDR_H 0 225288943Sdim#endif 226288943Sdim 227296417Sdim/// \macro MSC_PREREQ 228296417Sdim/// \brief Is the compiler MSVC of at least the specified version? 229296417Sdim/// The common \param version values to check for are: 230296417Sdim/// * 1800: Microsoft Visual Studio 2013 / 12.0 231296417Sdim/// * 1900: Microsoft Visual Studio 2015 / 14.0 232296417Sdim#ifdef _MSC_VER 233296417Sdim# define MSC_PREREQ(version) (_MSC_VER >= (version)) 234296417Sdim#else 235296417Sdim# define MSC_PREREQ(version) 0 236296417Sdim#endif 237296417Sdim 238309124Sdim#if defined(__arm64__) && SANITIZER_IOS 239309124Sdim# define SANITIZER_NON_UNIQUE_TYPEINFO 1 240309124Sdim#else 241309124Sdim# define SANITIZER_NON_UNIQUE_TYPEINFO 0 242309124Sdim#endif 243309124Sdim 244309124Sdim// On linux, some architectures had an ABI transition from 64-bit long double 245309124Sdim// (ie. same as double) to 128-bit long double. On those, glibc symbols 246309124Sdim// involving long doubles come in two versions, and we need to pass the 247309124Sdim// correct one to dlvsym when intercepting them. 248309124Sdim#if SANITIZER_LINUX && (SANITIZER_S390 || SANITIZER_PPC32 || SANITIZER_PPC64V1) 249309124Sdim#define SANITIZER_NLDBL_VERSION "GLIBC_2.4" 250309124Sdim#endif 251309124Sdim 252314564Sdim#if SANITIZER_GO == 0 253314564Sdim# define SANITIZER_GO 0 254314564Sdim#endif 255314564Sdim 256251034Sed#endif // SANITIZER_PLATFORM_H 257