xref: /netbsd-src/external/gpl3/gcc.old/dist/libsanitizer/sanitizer_common/sanitizer_platform.h (revision c38e7cc395b1472a774ff828e46123de44c628e9)
1 //===-- sanitizer_platform.h ------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // Common platform macros.
9 //===----------------------------------------------------------------------===//
10 
11 #ifndef SANITIZER_PLATFORM_H
12 #define SANITIZER_PLATFORM_H
13 
14 #if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \
15   !defined(__APPLE__) && !defined(_WIN32)
16 # error "This operating system is not supported"
17 #endif
18 
19 #if defined(__linux__)
20 # define SANITIZER_LINUX   1
21 #else
22 # define SANITIZER_LINUX   0
23 #endif
24 
25 #if defined(__FreeBSD__)
26 # define SANITIZER_FREEBSD 1
27 #else
28 # define SANITIZER_FREEBSD 0
29 #endif
30 
31 #if defined(__NetBSD__)
32 # define SANITIZER_NETBSD 1
33 #else
34 # define SANITIZER_NETBSD 0
35 #endif
36 
37 #if defined(__APPLE__)
38 # define SANITIZER_MAC     1
39 # include <TargetConditionals.h>
40 # if TARGET_OS_IPHONE
41 #  define SANITIZER_IOS    1
42 # else
43 #  define SANITIZER_IOS    0
44 # endif
45 #else
46 # define SANITIZER_MAC     0
47 # define SANITIZER_IOS     0
48 #endif
49 
50 #if defined(_WIN32)
51 # define SANITIZER_WINDOWS 1
52 #else
53 # define SANITIZER_WINDOWS 0
54 #endif
55 
56 #if defined(__ANDROID__)
57 # define SANITIZER_ANDROID 1
58 #else
59 # define SANITIZER_ANDROID 0
60 #endif
61 
62 #define SANITIZER_POSIX (SANITIZER_NETBSD || SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC)
63 
64 #if __LP64__ || defined(_WIN64)
65 #  define SANITIZER_WORDSIZE 64
66 #else
67 #  define SANITIZER_WORDSIZE 32
68 #endif
69 
70 #if SANITIZER_WORDSIZE == 64
71 # define FIRST_32_SECOND_64(a, b) (b)
72 #else
73 # define FIRST_32_SECOND_64(a, b) (a)
74 #endif
75 
76 #if defined(__x86_64__) && !defined(_LP64)
77 # define SANITIZER_X32 1
78 #else
79 # define SANITIZER_X32 0
80 #endif
81 
82 // By default we allow to use SizeClassAllocator64 on 64-bit platform.
83 // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
84 // does not work well and we need to fallback to SizeClassAllocator32.
85 // For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
86 // change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
87 #ifndef SANITIZER_CAN_USE_ALLOCATOR64
88 # if defined(__aarch64__) || defined(__mips64)
89 #  define SANITIZER_CAN_USE_ALLOCATOR64 0
90 # else
91 #  define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
92 # endif
93 #endif
94 
95 // The range of addresses which can be returned my mmap.
96 // FIXME: this value should be different on different platforms,
97 // e.g. on AArch64 it is most likely (1ULL << 39). Larger values will still work
98 // but will consume more memory for TwoLevelByteMap.
99 #if defined(__aarch64__)
100 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 39)
101 #else
102 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
103 #endif
104 
105 // The AArch64 linux port uses the canonical syscall set as mandated by
106 // the upstream linux community for all new ports. Other ports may still
107 // use legacy syscalls.
108 #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
109 # if defined(__aarch64__) && SANITIZER_LINUX
110 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
111 # else
112 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
113 # endif
114 #endif
115 
116 // udi16 syscalls can only be used when the following conditions are
117 // met:
118 // * target is one of arm32, x86-32, sparc32, sh or m68k
119 // * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15
120 //   built against > linux-2.2 kernel headers
121 // Since we don't want to include libc headers here, we check the
122 // target only.
123 #if defined(__arm__) || SANITIZER_X32 || defined(__sparc__)
124 #define SANITIZER_USES_UID16_SYSCALLS 1
125 #else
126 #define SANITIZER_USES_UID16_SYSCALLS 0
127 #endif
128 
129 #ifdef __mips__
130 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10)
131 #else
132 # define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
133 #endif
134 
135 // Assume obsolete RPC headers are available by default
136 #if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
137 # define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
138 # define HAVE_TIRPC_RPC_XDR_H 0
139 #endif
140 
141 #endif // SANITIZER_PLATFORM_H
142