]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / lib / sanitizer_common / sanitizer_platform.h
1 //===-- sanitizer_platform.h ------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Common platform macros.
11 //===----------------------------------------------------------------------===//
12
13 #ifndef SANITIZER_PLATFORM_H
14 #define SANITIZER_PLATFORM_H
15
16 #if !defined(__linux__) && !defined(__FreeBSD__) && \
17 !defined(__APPLE__) && !defined(_WIN32)
18 # error "This operating system is not supported"
19 #endif
20
21 #if defined(__linux__)
22 # define SANITIZER_LINUX 1
23 #else
24 # define SANITIZER_LINUX 0
25 #endif
26
27 #if defined(__FreeBSD__)
28 # define SANITIZER_FREEBSD 1
29 #else
30 # define SANITIZER_FREEBSD 0
31 #endif
32
33 #if defined(__APPLE__)
34 # define SANITIZER_MAC 1
35 # include <TargetConditionals.h>
36 # if TARGET_OS_IPHONE
37 # define SANITIZER_IOS 1
38 # else
39 # define SANITIZER_IOS 0
40 # endif
41 # if TARGET_IPHONE_SIMULATOR
42 # define SANITIZER_IOSSIM 1
43 # else
44 # define SANITIZER_IOSSIM 0
45 # endif
46 #else
47 # define SANITIZER_MAC 0
48 # define SANITIZER_IOS 0
49 # define SANITIZER_IOSSIM 0
50 #endif
51
52 #if defined(_WIN32)
53 # define SANITIZER_WINDOWS 1
54 #else
55 # define SANITIZER_WINDOWS 0
56 #endif
57
58 #if defined(__ANDROID__)
59 # define SANITIZER_ANDROID 1
60 #else
61 # define SANITIZER_ANDROID 0
62 #endif
63
64 #define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC)
65
66 #if __LP64__ || defined(_WIN64)
67 # define SANITIZER_WORDSIZE 64
68 #else
69 # define SANITIZER_WORDSIZE 32
70 #endif
71
72 #if SANITIZER_WORDSIZE == 64
73 # define FIRST_32_SECOND_64(a, b) (b)
74 #else
75 # define FIRST_32_SECOND_64(a, b) (a)
76 #endif
77
78 #if defined(__x86_64__) && !defined(_LP64)
79 # define SANITIZER_X32 1
80 #else
81 # define SANITIZER_X32 0
82 #endif
83
84 // VMA size definition for architecture that support multiple sizes.
85 // AArch64 has 3 VMA sizes: 39, 42 and 48.
86 #if !defined(SANITIZER_AARCH64_VMA)
87 # define SANITIZER_AARCH64_VMA 39
88 #else
89 # if SANITIZER_AARCH64_VMA != 39 && SANITIZER_AARCH64_VMA != 42
90 # error "invalid SANITIZER_AARCH64_VMA size"
91 # endif
92 #endif
93
94 // By default we allow to use SizeClassAllocator64 on 64-bit platform.
95 // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
96 // does not work well and we need to fallback to SizeClassAllocator32.
97 // For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
98 // change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
99 #ifndef SANITIZER_CAN_USE_ALLOCATOR64
100 # if defined(__mips64) || (defined(__aarch64__) && SANITIZER_AARCH64_VMA == 39)
101 # define SANITIZER_CAN_USE_ALLOCATOR64 0
102 # else
103 # define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
104 # endif
105 #endif
106
107 // The range of addresses which can be returned my mmap.
108 // FIXME: this value should be different on different platforms,
109 // e.g. on AArch64 it is most likely (1ULL << 39). Larger values will still work
110 // but will consume more memory for TwoLevelByteMap.
111 #if defined(__aarch64__)
112 # if SANITIZER_AARCH64_VMA == 39
113 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 39)
114 # elif SANITIZER_AARCH64_VMA == 42
115 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 42)
116 # endif
117 #elif defined(__mips__)
118 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40)
119 #else
120 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
121 #endif
122
123 // The AArch64 linux port uses the canonical syscall set as mandated by
124 // the upstream linux community for all new ports. Other ports may still
125 // use legacy syscalls.
126 #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
127 # if defined(__aarch64__) && SANITIZER_LINUX
128 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
129 # else
130 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
131 # endif
132 #endif
133
134 // udi16 syscalls can only be used when the following conditions are
135 // met:
136 // * target is one of arm32, x86-32, sparc32, sh or m68k
137 // * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15
138 // built against > linux-2.2 kernel headers
139 // Since we don't want to include libc headers here, we check the
140 // target only.
141 #if defined(__arm__) || SANITIZER_X32 || defined(__sparc__)
142 #define SANITIZER_USES_UID16_SYSCALLS 1
143 #else
144 #define SANITIZER_USES_UID16_SYSCALLS 0
145 #endif
146
147 #if defined(__mips__) || (defined(__aarch64__) && SANITIZER_AARCH64_VMA == 39)
148 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10)
149 #elif defined(__aarch64__) && SANITIZER_AARCH64_VMA == 42
150 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 11)
151 #else
152 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
153 #endif
154
155 // Assume obsolete RPC headers are available by default
156 #if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
157 # define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
158 # define HAVE_TIRPC_RPC_XDR_H 0
159 #endif
160
161 /// \macro MSC_PREREQ
162 /// \brief Is the compiler MSVC of at least the specified version?
163 /// The common \param version values to check for are:
164 /// * 1800: Microsoft Visual Studio 2013 / 12.0
165 /// * 1900: Microsoft Visual Studio 2015 / 14.0
166 #ifdef _MSC_VER
167 # define MSC_PREREQ(version) (_MSC_VER >= (version))
168 #else
169 # define MSC_PREREQ(version) 0
170 #endif
171
172 #endif // SANITIZER_PLATFORM_H