blob: 92f78481f1e47e424933287e7b46a7a555aca279 [file] [log] [blame]
Evgeniy Stepanov24e13722013-03-19 14:33:38 +00001//===-- 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
Stephen Hines2d1fdb22014-05-28 23:58:16 -070016#if !defined(__linux__) && !defined(__FreeBSD__) && \
17 !defined(__APPLE__) && !defined(_WIN32)
Evgeniy Stepanov24e13722013-03-19 14:33:38 +000018# 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
Stephen Hines2d1fdb22014-05-28 23:58:16 -070027#if defined(__FreeBSD__)
28# define SANITIZER_FREEBSD 1
29#else
30# define SANITIZER_FREEBSD 0
31#endif
32
Evgeniy Stepanov24e13722013-03-19 14:33:38 +000033#if defined(__APPLE__)
34# define SANITIZER_MAC 1
Alexander Potapenkob8a141f2013-10-31 17:38:18 +000035# include <TargetConditionals.h>
36# if TARGET_OS_IPHONE
37# define SANITIZER_IOS 1
38# else
39# define SANITIZER_IOS 0
40# endif
Evgeniy Stepanov24e13722013-03-19 14:33:38 +000041#else
42# define SANITIZER_MAC 0
Alexander Potapenkob8a141f2013-10-31 17:38:18 +000043# define SANITIZER_IOS 0
Evgeniy Stepanov24e13722013-03-19 14:33:38 +000044#endif
45
46#if defined(_WIN32)
47# define SANITIZER_WINDOWS 1
48#else
49# define SANITIZER_WINDOWS 0
50#endif
51
Dan Albertb625a872014-10-20 15:35:01 +000052#if defined(__ANDROID__)
Evgeniy Stepanov24e13722013-03-19 14:33:38 +000053# define SANITIZER_ANDROID 1
54#else
55# define SANITIZER_ANDROID 0
56#endif
57
Stephen Hines2d1fdb22014-05-28 23:58:16 -070058#define SANITIZER_POSIX (SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_MAC)
59
60#if __LP64__ || defined(_WIN64)
61# define SANITIZER_WORDSIZE 64
62#else
63# define SANITIZER_WORDSIZE 32
64#endif
65
66#if SANITIZER_WORDSIZE == 64
67# define FIRST_32_SECOND_64(a, b) (b)
68#else
69# define FIRST_32_SECOND_64(a, b) (a)
70#endif
71
72#if defined(__x86_64__) && !defined(_LP64)
73# define SANITIZER_X32 1
74#else
75# define SANITIZER_X32 0
76#endif
77
78// By default we allow to use SizeClassAllocator64 on 64-bit platform.
79// But in some cases (e.g. AArch64's 39-bit address space) SizeClassAllocator64
80// does not work well and we need to fallback to SizeClassAllocator32.
81// For such platforms build this code with -DSANITIZER_CAN_USE_ALLOCATOR64=0 or
82// change the definition of SANITIZER_CAN_USE_ALLOCATOR64 here.
83#ifndef SANITIZER_CAN_USE_ALLOCATOR64
Stephen Hines6d186232014-11-26 17:56:19 -080084# if defined(__aarch64__) || defined(__mips64)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070085# define SANITIZER_CAN_USE_ALLOCATOR64 0
86# else
87# define SANITIZER_CAN_USE_ALLOCATOR64 (SANITIZER_WORDSIZE == 64)
88# endif
89#endif
90
91// The range of addresses which can be returned my mmap.
92// FIXME: this value should be different on different platforms,
93// e.g. on AArch64 it is most likely (1ULL << 39). Larger values will still work
94// but will consume more memory for TwoLevelByteMap.
95#if defined(__aarch64__)
96# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 39)
Stephen Hines6d186232014-11-26 17:56:19 -080097#elif defined(__mips__)
98# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 40)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070099#else
100# define SANITIZER_MMAP_RANGE_SIZE FIRST_32_SECOND_64(1ULL << 32, 1ULL << 47)
101#endif
102
103// The AArch64 linux port uses the canonical syscall set as mandated by
104// the upstream linux community for all new ports. Other ports may still
105// use legacy syscalls.
106#ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
107# if defined(__aarch64__) && SANITIZER_LINUX
108# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
109# else
110# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
111# endif
112#endif
Evgeniy Stepanov24e13722013-03-19 14:33:38 +0000113
Stephen Hines86277eb2015-03-23 12:06:32 -0700114// udi16 syscalls can only be used when the following conditions are
115// met:
116// * target is one of arm32, x86-32, sparc32, sh or m68k
117// * libc version is libc5, glibc-2.0, glibc-2.1 or glibc-2.2 to 2.15
118// built against > linux-2.2 kernel headers
119// Since we don't want to include libc headers here, we check the
120// target only.
121#if defined(__arm__) || SANITIZER_X32 || defined(__sparc__)
122#define SANITIZER_USES_UID16_SYSCALLS 1
123#else
124#define SANITIZER_USES_UID16_SYSCALLS 0
125#endif
126
Stephen Hines6d186232014-11-26 17:56:19 -0800127#ifdef __mips__
128# define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 10)
129#else
130# define SANITIZER_POINTER_FORMAT_LENGTH FIRST_32_SECOND_64(8, 12)
131#endif
132
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -0700133// Assume obsolete RPC headers are available by default
134#if !defined(HAVE_RPC_XDR_H) && !defined(HAVE_TIRPC_RPC_XDR_H)
135# define HAVE_RPC_XDR_H (SANITIZER_LINUX && !SANITIZER_ANDROID)
136# define HAVE_TIRPC_RPC_XDR_H 0
137#endif
138
Evgeniy Stepanov24e13722013-03-19 14:33:38 +0000139#endif // SANITIZER_PLATFORM_H