1 | /* |
2 | * Copyright (C) 2014-2018 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "BCompiler.h" |
29 | |
30 | #ifdef __APPLE__ |
31 | #include <Availability.h> |
32 | #include <AvailabilityMacros.h> |
33 | #include <TargetConditionals.h> |
34 | #endif |
35 | |
36 | #define BPLATFORM(PLATFORM) (defined BPLATFORM_##PLATFORM && BPLATFORM_##PLATFORM) |
37 | #define BOS(OS) (defined BOS_##OS && BOS_##OS) |
38 | |
39 | #ifdef __APPLE__ |
40 | #define BOS_DARWIN 1 |
41 | #endif |
42 | |
43 | #ifdef __unix |
44 | #define BOS_UNIX 1 |
45 | #endif |
46 | |
47 | #ifdef __linux__ |
48 | #define BOS_LINUX 1 |
49 | #endif |
50 | |
51 | #if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__) |
52 | #define BOS_FREEBSD 1 |
53 | #endif |
54 | |
55 | #if defined(WIN32) || defined(_WIN32) |
56 | #define BOS_WINDOWS 1 |
57 | #endif |
58 | |
59 | #if BOS(DARWIN) && !defined(BUILDING_WITH_CMAKE) |
60 | #if TARGET_OS_IOS |
61 | #define BPLATFORM_IOS 1 |
62 | #if TARGET_OS_SIMULATOR |
63 | #define BPLATFORM_IOS_SIMULATOR 1 |
64 | #endif |
65 | #endif |
66 | #if TARGET_OS_IPHONE |
67 | #define BPLATFORM_IOS_FAMILY 1 |
68 | #if TARGET_OS_SIMULATOR |
69 | #define BPLATFORM_IOS_FAMILY_SIMULATOR 1 |
70 | #endif |
71 | #elif TARGET_OS_MAC |
72 | #define BPLATFORM_MAC 1 |
73 | #endif |
74 | #endif |
75 | |
76 | #if BPLATFORM(MAC) || BPLATFORM(IOS_FAMILY) |
77 | #define BPLATFORM_COCOA 1 |
78 | #endif |
79 | |
80 | #if defined(TARGET_OS_WATCH) && TARGET_OS_WATCH |
81 | #define BPLATFORM_WATCHOS 1 |
82 | #endif |
83 | |
84 | #if defined(TARGET_OS_TV) && TARGET_OS_TV |
85 | #define BPLATFORM_APPLETV 1 |
86 | #endif |
87 | |
88 | /* ==== Policy decision macros: these define policy choices for a particular port. ==== */ |
89 | |
90 | /* BUSE() - use a particular third-party library or optional OS service */ |
91 | #define BUSE(FEATURE) (defined BUSE_##FEATURE && BUSE_##FEATURE) |
92 | |
93 | /* ==== Compiler adaptation macros: these describe the capabilities of the compiler. ==== */ |
94 | |
95 | /* BCOMPILER_SUPPORTS() - check for a compiler feature */ |
96 | #define BCOMPILER_SUPPORTS(FEATURE) (defined BCOMPILER_SUPPORTS_##FEATURE && BCOMPILER_SUPPORTS_##FEATURE) |
97 | |
98 | /* ==== Platform adaptation macros: these describe properties of the target environment. ==== */ |
99 | |
100 | /* BCPU() - the target CPU architecture */ |
101 | #define BCPU(_FEATURE) (defined BCPU_##_FEATURE && BCPU_##_FEATURE) |
102 | |
103 | /* BCPU(X86) - i386 / x86 32-bit */ |
104 | #if defined(__i386__) \ |
105 | || defined(i386) \ |
106 | || defined(_M_IX86) \ |
107 | || defined(_X86_) \ |
108 | || defined(__THW_INTEL) |
109 | #define BCPU_X86 1 |
110 | #endif |
111 | |
112 | /* BCPU(X86_64) - AMD64 / Intel64 / x86_64 64-bit */ |
113 | #if defined(__x86_64__) \ |
114 | || defined(_M_X64) |
115 | #define BCPU_X86_64 1 |
116 | #endif |
117 | |
118 | /* BCPU(ARM64) - Apple */ |
119 | #if (defined(__arm64__) && defined(__APPLE__)) || defined(__aarch64__) |
120 | #define BCPU_ARM64 1 |
121 | #endif |
122 | |
123 | /* BCPU(ARM) - ARM, any version*/ |
124 | #define BARM_ARCH_AT_LEAST(N) (BCPU(ARM) && BARM_ARCH_VERSION >= N) |
125 | |
126 | #if defined(arm) \ |
127 | || defined(__arm__) \ |
128 | || defined(ARM) \ |
129 | || defined(_ARM_) |
130 | #define BCPU_ARM 1 |
131 | |
132 | /* Set BARM_ARCH_VERSION */ |
133 | #if defined(__ARM_ARCH_4__) \ |
134 | || defined(__ARM_ARCH_4T__) \ |
135 | || defined(__MARM_ARMV4__) |
136 | #define BARM_ARCH_VERSION 4 |
137 | |
138 | #elif defined(__ARM_ARCH_5__) \ |
139 | || defined(__ARM_ARCH_5T__) \ |
140 | || defined(__MARM_ARMV5__) |
141 | #define BARM_ARCH_VERSION 5 |
142 | |
143 | #elif defined(__ARM_ARCH_5E__) \ |
144 | || defined(__ARM_ARCH_5TE__) \ |
145 | || defined(__ARM_ARCH_5TEJ__) |
146 | #define BARM_ARCH_VERSION 5 |
147 | |
148 | #elif defined(__ARM_ARCH_6__) \ |
149 | || defined(__ARM_ARCH_6J__) \ |
150 | || defined(__ARM_ARCH_6K__) \ |
151 | || defined(__ARM_ARCH_6Z__) \ |
152 | || defined(__ARM_ARCH_6ZK__) \ |
153 | || defined(__ARM_ARCH_6T2__) \ |
154 | || defined(__ARMV6__) |
155 | #define BARM_ARCH_VERSION 6 |
156 | |
157 | #elif defined(__ARM_ARCH_7A__) \ |
158 | || defined(__ARM_ARCH_7K__) \ |
159 | || defined(__ARM_ARCH_7R__) \ |
160 | || defined(__ARM_ARCH_7S__) |
161 | #define BARM_ARCH_VERSION 7 |
162 | |
163 | #elif defined(__ARM_ARCH_8__) \ |
164 | || defined(__ARM_ARCH_8A__) |
165 | #define BARM_ARCH_VERSION 8 |
166 | |
167 | /* MSVC sets _M_ARM */ |
168 | #elif defined(_M_ARM) |
169 | #define BARM_ARCH_VERSION _M_ARM |
170 | |
171 | /* RVCT sets _TARGET_ARCH_ARM */ |
172 | #elif defined(__TARGET_ARCH_ARM) |
173 | #define BARM_ARCH_VERSION __TARGET_ARCH_ARM |
174 | |
175 | #else |
176 | #define WTF_ARM_ARCH_VERSION 0 |
177 | |
178 | #endif |
179 | |
180 | /* Set BTHUMB_ARCH_VERSION */ |
181 | #if defined(__ARM_ARCH_4T__) |
182 | #define BTHUMB_ARCH_VERSION 1 |
183 | |
184 | #elif defined(__ARM_ARCH_5T__) \ |
185 | || defined(__ARM_ARCH_5TE__) \ |
186 | || defined(__ARM_ARCH_5TEJ__) |
187 | #define BTHUMB_ARCH_VERSION 2 |
188 | |
189 | #elif defined(__ARM_ARCH_6J__) \ |
190 | || defined(__ARM_ARCH_6K__) \ |
191 | || defined(__ARM_ARCH_6Z__) \ |
192 | || defined(__ARM_ARCH_6ZK__) \ |
193 | || defined(__ARM_ARCH_6M__) |
194 | #define BTHUMB_ARCH_VERSION 3 |
195 | |
196 | #elif defined(__ARM_ARCH_6T2__) \ |
197 | || defined(__ARM_ARCH_7__) \ |
198 | || defined(__ARM_ARCH_7A__) \ |
199 | || defined(__ARM_ARCH_7K__) \ |
200 | || defined(__ARM_ARCH_7M__) \ |
201 | || defined(__ARM_ARCH_7R__) \ |
202 | || defined(__ARM_ARCH_7S__) |
203 | #define BTHUMB_ARCH_VERSION 4 |
204 | |
205 | /* RVCT sets __TARGET_ARCH_THUMB */ |
206 | #elif defined(__TARGET_ARCH_THUMB) |
207 | #define BTHUMB_ARCH_VERSION __TARGET_ARCH_THUMB |
208 | |
209 | #else |
210 | #define BTHUMB_ARCH_VERSION 0 |
211 | #endif |
212 | |
213 | /* BCPU(ARM_TRADITIONAL) - Thumb2 is not available, only traditional ARM (v4 or greater) */ |
214 | /* BCPU(ARM_THUMB2) - Thumb2 instruction set is available */ |
215 | /* Only one of these will be defined. */ |
216 | #if !defined(BCPU_ARM_TRADITIONAL) && !defined(BCPU_ARM_THUMB2) |
217 | # if defined(thumb2) || defined(__thumb2__) \ |
218 | || ((defined(__thumb) || defined(__thumb__)) && BTHUMB_ARCH_VERSION == 4) |
219 | # define BCPU_ARM_TRADITIONAL 0 |
220 | # define BCPU_ARM_THUMB2 1 |
221 | # elif BARM_ARCH_AT_LEAST(4) |
222 | # define BCPU_ARM_TRADITIONAL 1 |
223 | # define BCPU_ARM_THUMB2 0 |
224 | # else |
225 | # error "Not supported ARM architecture" |
226 | # endif |
227 | #elif BCPU(ARM_TRADITIONAL) && BCPU(ARM_THUMB2) /* Sanity Check */ |
228 | # error "Cannot use both of BCPU_ARM_TRADITIONAL and BCPU_ARM_THUMB2 platforms" |
229 | #endif /* !defined(BCPU_ARM_TRADITIONAL) && !defined(BCPU_ARM_THUMB2) */ |
230 | |
231 | #endif /* ARM */ |
232 | |
233 | #define BATTRIBUTE_PRINTF(formatStringArgument, extraArguments) __attribute__((__format__(printf, formatStringArgument, extraArguments))) |
234 | |
235 | #if BPLATFORM(MAC) || BPLATFORM(IOS_FAMILY) |
236 | #define BUSE_OS_LOG 1 |
237 | #endif |
238 | |
239 | #if !defined(BUSE_EXPORT_MACROS) && (BPLATFORM(MAC) || BPLATFORM(IOS_FAMILY)) |
240 | #define BUSE_EXPORT_MACROS 1 |
241 | #endif |
242 | |
243 | /* BUNUSED_PARAM */ |
244 | #if !defined(BUNUSED_PARAM) |
245 | #define BUNUSED_PARAM(variable) (void)variable |
246 | #endif |
247 | |
248 | /* This is used for debugging when hacking on how bmalloc calculates its physical footprint. */ |
249 | #define ENABLE_PHYSICAL_PAGE_MAP 0 |
250 | |
251 | #if BPLATFORM(IOS_FAMILY) && (BCPU(ARM64) || BCPU(ARM)) |
252 | #define BUSE_CHECK_NANO_MALLOC 1 |
253 | #else |
254 | #define BUSE_CHECK_NANO_MALLOC 0 |
255 | #endif |
256 | |
257 | |