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
40 # define SANITIZER_MAC 0
41 # define SANITIZER_IOS 0
45 # define SANITIZER_WINDOWS 1
47 # define SANITIZER_WINDOWS 0
50 #if defined(__ANDROID__) || defined(ANDROID)
51 # define SANITIZER_ANDROID 1
53 # define SANITIZER_ANDROID 0
56 #define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC)
58 #if __LP64__ || defined(_WIN64)
59 # define SANITIZER_WORDSIZE 64
61 # define SANITIZER_WORDSIZE 32
64 #if SANITIZER_WORDSIZE == 64
65 # define FIRST_32_SECOND_64(a, b) (b)
67 # define FIRST_32_SECOND_64(a, b) (a)
70 #if defined(__x86_64__) && !defined(_LP64)
71 # define SANITIZER_X32 1
73 # define SANITIZER_X32 0
76 // By default we allow to use SizeClassAllocator64 on 64-bit platform.
77 // But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
78 // does not work well and we need to fallback to SizeClassAllocator32.
79 // For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
80 // change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
81 #ifndef SANITIZER_CAN_USE_ALLOCATOR64
82 # if defined(__aarch64__)
83 # define SANITIZER_CAN_USE_ALLOCATOR64 0
85 # define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
89 // The range of addresses which can be returned my mmap.
90 // FIXME: this value should be different on different platforms,
91 // e.g. on AArch64 it is most likely (1ULL << 39). Larger values will still work
92 // but will consume more memory for TwoLevelByteMap.
93 #if defined(__aarch64__)
94 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 39)
96 # define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
99 // The AArch64 linux port uses the canonical syscall set as mandated by
100 // the upstream linux community for all new ports. Other ports may still
101 // use legacy syscalls.
102 #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
103 # if defined(__aarch64__) && SANITIZER_LINUX
104 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
106 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
110 #endif // SANITIZER_PLATFORM_H