1 //===-- sanitizer_platform.h ------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Common platform macros.
9 //===----------------------------------------------------------------------===//
11 #ifndef SANITIZER_PLATFORM_H
12 #define SANITIZER_PLATFORM_H
14 #if !defined(__linux__) && !defined(__FreeBSD__) && \
15 !defined(__APPLE__) && !defined(_WIN32)
16 # error "This operating system is not supported"
19 #if defined(__linux__)
20 # define SANITIZER_LINUX 1
22 # define SANITIZER_LINUX 0
25 #if defined(__FreeBSD__)
26 # define SANITIZER_FREEBSD 1
28 # define SANITIZER_FREEBSD 0
31 #if defined(__APPLE__)
32 # define SANITIZER_MAC 1
33 # include <TargetConditionals.h>
35 # define SANITIZER_IOS 1
37 # define SANITIZER_IOS 0
39 # if TARGET_IPHONE_SIMULATOR
40 # define SANITIZER_IOSSIM 1
42 # define SANITIZER_IOSSIM 0
45 # define SANITIZER_MAC 0
46 # define SANITIZER_IOS 0
47 # define SANITIZER_IOSSIM 0
51 # define SANITIZER_WINDOWS 1
53 # define SANITIZER_WINDOWS 0
56 #if defined(__ANDROID__)
57 # define SANITIZER_ANDROID 1
59 # define SANITIZER_ANDROID 0
62 #define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC)
64 #if __LP64__ || defined(_WIN64)
65 # define SANITIZER_WORDSIZE 64
67 # define SANITIZER_WORDSIZE 32
70 #if SANITIZER_WORDSIZE == 64
71 # define FIRST_32_SECOND_64(a, b) (b)
73 # define FIRST_32_SECOND_64(a, b) (a)
76 #if defined(__x86_64__) && !defined(_LP64)
77 # define SANITIZER_X32 1
79 # define SANITIZER_X32 0
82 // VMA size definition for architecture that support multiple sizes.
83 // AArch64 has 3 VMA sizes: 39, 42 and 48.
84 #if !defined(SANITIZER_AARCH64_VMA)
85 # define SANITIZER_AARCH64_VMA 39
87 # if SANITIZER_AARCH64_VMA != 39 && SANITIZER_AARCH64_VMA != 42
88 # error "invalid SANITIZER_AARCH64_VMA size"
92 // By default we allow to use SizeClassAllocator64 on 64-bit platform.
93 // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
94 // does not work well and we need to fallback to SizeClassAllocator32.
95 // For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
96 // change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
97 #ifndef SANITIZER_CAN_USE_ALLOCATOR64
98 # if defined(__mips64) || defined(__aarch64__)
99 # define SANITIZER_CAN_USE_ALLOCATOR64 0
101 # define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
105 // The range of addresses which can be returned my mmap.
106 // FIXME: this value should be different on different platforms. Larger values
107 // will still work but will consume more memory for TwoLevelByteMap.
108 #if defined(__mips__)
109 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40)
111 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
114 // The AArch64 linux port uses the canonical syscall set as mandated by
115 // the upstream linux community for all new ports. Other ports may still
116 // use legacy syscalls.
117 #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
118 # if defined(__aarch64__) && SANITIZER_LINUX
119 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
121 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
125 // udi16 syscalls can only be used when the following conditions are
127 // * target is one of arm32, x86-32, sparc32, sh or m68k
128 // * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15
129 // built against > linux-2.2 kernel headers
130 // Since we don't want to include libc headers here, we check the
132 #if defined(__arm__) || SANITIZER_X32 || defined(__sparc__)
133 #define SANITIZER_USES_UID16_SYSCALLS 1
135 #define SANITIZER_USES_UID16_SYSCALLS 0
138 #if defined(__mips__) || (defined(__aarch64__) && SANITIZER_AARCH64_VMA == 39)
139 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10)
140 #elif defined(__aarch64__) && SANITIZER_AARCH64_VMA == 42
141 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 11)
143 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
146 // Assume obsolete RPC headers are available by default
147 #if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
148 # define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
149 # define HAVE_TIRPC_RPC_XDR_H 0
152 /// \macro MSC_PREREQ
153 /// \brief Is the compiler MSVC of at least the specified version?
154 /// The common \param version values to check for are:
155 /// * 1800: Microsoft Visual Studio 2013 / 12.0
156 /// * 1900: Microsoft Visual Studio 2015 / 14.0
158 # define MSC_PREREQ(version) (_MSC_VER >= (version))
160 # define MSC_PREREQ(version) 0
163 #endif // SANITIZER_PLATFORM_H