Debian Codegraph @

gc/include/gc_config_macros.h

raw
1 /*
2 * Copyright (c) 1994 by Xerox Corporation. All rights reserved.
3 * Copyright (c) 1996 by Silicon Graphics. All rights reserved.
4 * Copyright (c) 1998 by Fergus Henderson. All rights reserved.
5 * Copyright (c) 2000-2009 by Hewlett-Packard Development Company.
6 * All rights reserved.
7 * Copyright (c) 2008-2020 Ivan Maidanski
8 *
9 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
10 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
11 *
12 * Permission is hereby granted to use or copy this program
13 * for any purpose, provided the above notices are retained on all copies.
14 * Permission to modify the code and to distribute modified code is granted,
15 * provided the above notices are retained, and a notice that the code was
16 * modified is included with the above copyright notice.
17 */
18
19 /* This should never be included directly; it is included only from gc.h. */
20 /* We separate it only to make gc.h more suitable as documentation. */
21 #if defined(GC_H)
22
23 /* Convenient internal macro to test version of GCC. */
24 #if defined(__GNUC__) && defined(__GNUC_MINOR__)
25 # define GC_GNUC_PREREQ(major, minor) \
26 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((major) << 16) + (minor))
27 #else
28 # define GC_GNUC_PREREQ(major, minor) 0 /* FALSE */
29 #endif
30
31 /* Some tests for old macros. These violate our namespace rules and */
32 /* will disappear shortly. Use the GC_ names. */
33 #if defined(SOLARIS_THREADS) || defined(_SOLARIS_THREADS) \
34 || defined(_SOLARIS_PTHREADS) || defined(GC_SOLARIS_PTHREADS)
35 /* We no longer support old style Solaris threads. */
36 /* GC_SOLARIS_THREADS now means pthreads. */
37 # ifndef GC_SOLARIS_THREADS
38 # define GC_SOLARIS_THREADS
39 # endif
40 #endif
41 #if defined(IRIX_THREADS)
42 # define GC_IRIX_THREADS
43 #endif
44 #if defined(DGUX_THREADS) && !defined(GC_DGUX386_THREADS)
45 # define GC_DGUX386_THREADS
46 #endif
47 #if defined(AIX_THREADS)
48 # define GC_AIX_THREADS
49 #endif
50 #if defined(HPUX_THREADS)
51 # define GC_HPUX_THREADS
52 #endif
53 #if defined(OSF1_THREADS)
54 # define GC_OSF1_THREADS
55 #endif
56 #if defined(LINUX_THREADS)
57 # define GC_LINUX_THREADS
58 #endif
59 #if defined(WIN32_THREADS)
60 # define GC_WIN32_THREADS
61 #endif
62 #if defined(RTEMS_THREADS)
63 # define GC_RTEMS_PTHREADS
64 #endif
65 #if defined(USE_LD_WRAP)
66 # define GC_USE_LD_WRAP
67 #endif
68
69 #if defined(GC_WIN32_PTHREADS) && !defined(GC_WIN32_THREADS)
70 /* Using pthreads-win32 library (or other Win32 implementation). */
71 # define GC_WIN32_THREADS
72 #endif
73
74 #if defined(GC_AIX_THREADS) || defined(GC_DARWIN_THREADS) \
75 || defined(GC_DGUX386_THREADS) || defined(GC_FREEBSD_THREADS) \
76 || defined(GC_HPUX_THREADS) \
77 || defined(GC_IRIX_THREADS) || defined(GC_LINUX_THREADS) \
78 || defined(GC_NETBSD_THREADS) || defined(GC_OPENBSD_THREADS) \
79 || defined(GC_OSF1_THREADS) || defined(GC_SOLARIS_THREADS) \
80 || defined(GC_WIN32_THREADS) || defined(GC_RTEMS_PTHREADS)
81 # ifndef GC_THREADS
82 # define GC_THREADS
83 # endif
84 #elif defined(GC_THREADS)
85 # if defined(__linux__)
86 # define GC_LINUX_THREADS
87 # elif defined(__OpenBSD__)
88 # define GC_OPENBSD_THREADS
89 # elif defined(_PA_RISC1_1) || defined(_PA_RISC2_0) || defined(hppa) \
90 || defined(__HPPA) || (defined(__ia64) && defined(_HPUX_SOURCE))
91 # define GC_HPUX_THREADS
92 # elif defined(__HAIKU__)
93 # define GC_HAIKU_THREADS
94 # elif (defined(__DragonFly__) || defined(__FreeBSD_kernel__) \
95 || defined(__FreeBSD__)) && !defined(GC_NO_FREEBSD)
96 # define GC_FREEBSD_THREADS
97 # elif defined(__NetBSD__)
98 # define GC_NETBSD_THREADS
99 # elif defined(__alpha) || defined(__alpha__) /* && !Linux && !xBSD */
100 # define GC_OSF1_THREADS
101 # elif (defined(mips) || defined(__mips) || defined(_mips)) \
102 && !(defined(nec_ews) || defined(_nec_ews) \
103 || defined(ultrix) || defined(__ultrix))
104 # define GC_IRIX_THREADS
105 # elif defined(__sparc) /* && !Linux */ \
106 || ((defined(sun) || defined(__sun)) \
107 && (defined(i386) || defined(__i386__) \
108 || defined(__amd64) || defined(__amd64__)))
109 # define GC_SOLARIS_THREADS
110 # elif defined(__APPLE__) && defined(__MACH__)
111 # define GC_DARWIN_THREADS
112 # endif
113 # if defined(DGUX) && (defined(i386) || defined(__i386__))
114 # define GC_DGUX386_THREADS
115 # endif
116 # if defined(_AIX)
117 # define GC_AIX_THREADS
118 # endif
119 # if (defined(_WIN32) || defined(_MSC_VER) || defined(__BORLANDC__) \
120 || defined(__CYGWIN32__) || defined(__CYGWIN__) || defined(__CEGCC__) \
121 || defined(_WIN32_WCE) || defined(__MINGW32__)) \
122 && !defined(GC_WIN32_THREADS)
123 /* Either posix or native Win32 threads. */
124 # define GC_WIN32_THREADS
125 # endif
126 # if defined(__rtems__) && (defined(i386) || defined(__i386__))
127 # define GC_RTEMS_PTHREADS
128 # endif
129 #endif /* GC_THREADS */
130
131 #undef GC_PTHREADS
132 #if (!defined(GC_WIN32_THREADS) || defined(GC_WIN32_PTHREADS) \
133 || defined(__CYGWIN32__) || defined(__CYGWIN__)) && defined(GC_THREADS) \
134 && !defined(NN_PLATFORM_CTR) && !defined(NN_BUILD_TARGET_PLATFORM_NX)
135 /* Posix threads. */
136 # define GC_PTHREADS
137 #endif
138
139 #if !defined(_PTHREADS) && defined(GC_NETBSD_THREADS)
140 # define _PTHREADS
141 #endif
142
143 #if defined(GC_DGUX386_THREADS) && !defined(_POSIX4A_DRAFT10_SOURCE)
144 # define _POSIX4A_DRAFT10_SOURCE 1
145 #endif
146
147 #if !defined(_REENTRANT) && defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS)
148 /* Better late than never. This fails if system headers that depend */
149 /* on this were previously included. */
150 # define _REENTRANT 1
151 #endif
152
153 #define __GC
154 #if !defined(_WIN32_WCE) || defined(__GNUC__)
155 # include <stddef.h>
156 # if defined(__MINGW32__) && !defined(_WIN32_WCE)
157 # include <stdint.h>
158 /* We mention uintptr_t. */
159 /* Perhaps this should be included in pure msft environments */
160 /* as well? */
161 # endif
162 #else /* _WIN32_WCE */
163 /* Yet more kludges for WinCE. */
164 # include <stdlib.h> /* size_t is defined here */
165 # ifndef _PTRDIFF_T_DEFINED
166 /* ptrdiff_t is not defined */
167 # define _PTRDIFF_T_DEFINED
168 typedef long ptrdiff_t;
169 # endif
170 #endif /* _WIN32_WCE */
171
172 #if !defined(GC_NOT_DLL) && !defined(GC_DLL) \
173 && ((defined(_DLL) && !defined(__GNUC__)) \
174 || (defined(DLL_EXPORT) && defined(GC_BUILD)))
175 # define GC_DLL
176 #endif
177
178 #if defined(GC_DLL) && !defined(GC_API)
179
180 # if defined(__CEGCC__)
181 # if defined(GC_BUILD)
182 # define GC_API __declspec(dllexport)
183 # else
184 # define GC_API __declspec(dllimport)
185 # endif
186
187 # elif defined(__MINGW32__)
188 # if defined(__cplusplus) && defined(GC_BUILD)
189 # define GC_API extern __declspec(dllexport)
190 # elif defined(GC_BUILD) || defined(__MINGW32_DELAY_LOAD__)
191 # define GC_API __declspec(dllexport)
192 # else
193 # define GC_API extern __declspec(dllimport)
194 # endif
195
196 # elif defined(_MSC_VER) || defined(__DMC__) || defined(__BORLANDC__) \
197 || defined(__CYGWIN__)
198 # ifdef GC_BUILD
199 # define GC_API extern __declspec(dllexport)
200 # else
201 # define GC_API __declspec(dllimport)
202 # endif
203
204 # elif defined(__WATCOMC__)
205 # ifdef GC_BUILD
206 # define GC_API extern __declspec(dllexport)
207 # else
208 # define GC_API extern __declspec(dllimport)
209 # endif
210
211 # elif defined(__SYMBIAN32__)
212 # ifdef GC_BUILD
213 # define GC_API extern EXPORT_C
214 # else
215 # define GC_API extern IMPORT_C
216 # endif
217
218 # elif defined(__GNUC__)
219 /* Only matters if used in conjunction with -fvisibility=hidden option. */
220 # if defined(GC_BUILD) && !defined(GC_NO_VISIBILITY) \
221 && (GC_GNUC_PREREQ(4, 0) || defined(GC_VISIBILITY_HIDDEN_SET))
222 # define GC_API extern __attribute__((__visibility__("default")))
223 # endif
224 # endif
225 #endif /* GC_DLL */
226
227 #ifndef GC_API
228 # define GC_API extern
229 #endif
230
231 #ifndef GC_CALL
232 # define GC_CALL
233 #endif
234
235 #ifndef GC_CALLBACK
236 # define GC_CALLBACK GC_CALL
237 #endif
238
239 #ifndef GC_ATTR_MALLOC
240 /* 'malloc' attribute should be used for all malloc-like functions */
241 /* (to tell the compiler that a function may be treated as if any */
242 /* non-NULL pointer it returns cannot alias any other pointer valid */
243 /* when the function returns). If the client code violates this rule */
244 /* by using custom GC_oom_func then define GC_OOM_FUNC_RETURNS_ALIAS. */
245 # ifdef GC_OOM_FUNC_RETURNS_ALIAS
246 # define GC_ATTR_MALLOC /* empty */
247 # elif GC_GNUC_PREREQ(3, 1)
248 # define GC_ATTR_MALLOC __attribute__((__malloc__))
249 # elif defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(__EDG__)
250 # define GC_ATTR_MALLOC \
251 __declspec(allocator) __declspec(noalias) __declspec(restrict)
252 # elif defined(_MSC_VER) && _MSC_VER >= 1400
253 # define GC_ATTR_MALLOC __declspec(noalias) __declspec(restrict)
254 # else
255 # define GC_ATTR_MALLOC
256 # endif
257 #endif
258
259 #ifndef GC_ATTR_ALLOC_SIZE
260 /* 'alloc_size' attribute improves __builtin_object_size correctness. */
261 # undef GC_ATTR_CALLOC_SIZE
262 # ifdef __clang__
263 # if __has_attribute(__alloc_size__)
264 # define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
265 # define GC_ATTR_CALLOC_SIZE(n, s) __attribute__((__alloc_size__(n, s)))
266 # else
267 # define GC_ATTR_ALLOC_SIZE(argnum) /* empty */
268 # endif
269 # elif GC_GNUC_PREREQ(4, 3) && !defined(__ICC)
270 # define GC_ATTR_ALLOC_SIZE(argnum) __attribute__((__alloc_size__(argnum)))
271 # define GC_ATTR_CALLOC_SIZE(n, s) __attribute__((__alloc_size__(n, s)))
272 # else
273 # define GC_ATTR_ALLOC_SIZE(argnum) /* empty */
274 # endif
275 #endif
276
277 #ifndef GC_ATTR_CALLOC_SIZE
278 # define GC_ATTR_CALLOC_SIZE(n, s) /* empty */
279 #endif
280
281 #ifndef GC_ATTR_NONNULL
282 # if GC_GNUC_PREREQ(4, 0)
283 # define GC_ATTR_NONNULL(argnum) __attribute__((__nonnull__(argnum)))
284 # else
285 # define GC_ATTR_NONNULL(argnum) /* empty */
286 # endif
287 #endif
288
289 #ifndef GC_ATTR_CONST
290 # if GC_GNUC_PREREQ(4, 0)
291 # define GC_ATTR_CONST __attribute__((__const__))
292 # else
293 # define GC_ATTR_CONST /* empty */
294 # endif
295 #endif
296
297 #ifndef GC_ATTR_DEPRECATED
298 # ifdef GC_BUILD
299 # undef GC_ATTR_DEPRECATED
300 # define GC_ATTR_DEPRECATED /* empty */
301 # elif GC_GNUC_PREREQ(4, 0)
302 # define GC_ATTR_DEPRECATED __attribute__((__deprecated__))
303 # elif defined(_MSC_VER) && _MSC_VER >= 1200
304 # define GC_ATTR_DEPRECATED __declspec(deprecated)
305 # else
306 # define GC_ATTR_DEPRECATED /* empty */
307 # endif
308 #endif
309
310 #if defined(__sgi) && !defined(__GNUC__) && _COMPILER_VERSION >= 720
311 # define GC_ADD_CALLER
312 # define GC_RETURN_ADDR (GC_word)__return_address
313 #endif
314
315 #if defined(__linux__) || defined(__GLIBC__)
316 # if !defined(__native_client__)
317 # include <features.h>
318 # endif
319 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1 || __GLIBC__ > 2) \
320 && !defined(__ia64__) \
321 && !defined(GC_MISSING_EXECINFO_H) \
322 && !defined(GC_HAVE_BUILTIN_BACKTRACE)
323 # define GC_HAVE_BUILTIN_BACKTRACE
324 # endif
325 # if defined(__i386__) || defined(__amd64__) || defined(__x86_64__)
326 # define GC_CAN_SAVE_CALL_STACKS
327 # endif
328 #endif /* GLIBC */
329
330 #if defined(_MSC_VER) && _MSC_VER >= 1200 /* version 12.0+ (MSVC 6.0+) */ \
331 && !defined(_M_ARM) && !defined(_M_ARM64) \
332 && !defined(_AMD64_) && !defined(_M_X64) && !defined(_WIN32_WCE) \
333 && !defined(GC_HAVE_NO_BUILTIN_BACKTRACE) \
334 && !defined(GC_HAVE_BUILTIN_BACKTRACE)
335 # define GC_HAVE_BUILTIN_BACKTRACE
336 #endif
337
338 #if defined(GC_HAVE_BUILTIN_BACKTRACE) && !defined(GC_CAN_SAVE_CALL_STACKS)
339 # define GC_CAN_SAVE_CALL_STACKS
340 #endif
341
342 #if defined(__sparc__)
343 # define GC_CAN_SAVE_CALL_STACKS
344 #endif
345
346 /* If we're on a platform on which we can't save call stacks, but */
347 /* gcc is normally used, we go ahead and define GC_ADD_CALLER. */
348 /* We make this decision independent of whether gcc is actually being */
349 /* used, in order to keep the interface consistent, and allow mixing */
350 /* of compilers. */
351 /* This may also be desirable if it is possible but expensive to */
352 /* retrieve the call chain. */
353 #if (defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__) \
354 || defined(__FreeBSD_kernel__) || defined(__HAIKU__) \
355 || defined(__NetBSD__) || defined(__OpenBSD__) \
356 || defined(HOST_ANDROID) || defined(__ANDROID__)) \
357 && !defined(GC_CAN_SAVE_CALL_STACKS)
358 # define GC_ADD_CALLER
359 # if GC_GNUC_PREREQ(2, 95)
360 /* gcc knows how to retrieve return address, but we don't know */
361 /* how to generate call stacks. */
362 # define GC_RETURN_ADDR (GC_word)__builtin_return_address(0)
363 # if GC_GNUC_PREREQ(4, 0) && (defined(__i386__) || defined(__amd64__) \
364 || defined(__x86_64__) /* and probably others... */) \
365 && !defined(GC_NO_RETURN_ADDR_PARENT)
366 # define GC_HAVE_RETURN_ADDR_PARENT
367 # define GC_RETURN_ADDR_PARENT \
368 (GC_word)__builtin_extract_return_addr(__builtin_return_address(1))
369 /* Note: a compiler might complain that calling */
370 /* __builtin_return_address with a nonzero argument is unsafe. */
371 # endif
372 # else
373 /* Just pass 0 for gcc compatibility. */
374 # define GC_RETURN_ADDR 0
375 # endif
376 #endif /* !GC_CAN_SAVE_CALL_STACKS */
377
378 #ifdef GC_PTHREADS
379
380 # if (defined(GC_DARWIN_THREADS) || defined(GC_WIN32_PTHREADS) \
381 || defined(__native_client__) || defined(GC_RTEMS_PTHREADS)) \
382 && !defined(GC_NO_DLOPEN)
383 /* Either there is no dlopen() or we do not need to intercept it. */
384 # define GC_NO_DLOPEN
385 # endif
386
387 # if (defined(GC_DARWIN_THREADS) || defined(GC_WIN32_PTHREADS) \
388 || defined(__native_client__)) \
389 && !defined(GC_NO_PTHREAD_SIGMASK)
390 /* Either there is no pthread_sigmask() or no need to intercept it. */
391 # define GC_NO_PTHREAD_SIGMASK
392 # endif
393
394 # if defined(__native_client__)
395 /* At present, NaCl pthread_create() prototype does not have */
396 /* "const" for its "attr" argument; also, NaCl pthread_exit() one */
397 /* does not have "noreturn" attribute. */
398 # ifndef GC_PTHREAD_CREATE_CONST
399 # define GC_PTHREAD_CREATE_CONST /* empty */
400 # endif
401 # ifndef GC_HAVE_PTHREAD_EXIT
402 # define GC_HAVE_PTHREAD_EXIT
403 # define GC_PTHREAD_EXIT_ATTRIBUTE /* empty */
404 # endif
405 # endif
406
407 # if !defined(GC_HAVE_PTHREAD_EXIT) \
408 && !defined(HOST_ANDROID) && !defined(__ANDROID__) \
409 && (defined(GC_LINUX_THREADS) || defined(GC_SOLARIS_THREADS))
410 # define GC_HAVE_PTHREAD_EXIT
411 /* Intercept pthread_exit on Linux and Solaris. */
412 # if GC_GNUC_PREREQ(2, 7)
413 # define GC_PTHREAD_EXIT_ATTRIBUTE __attribute__((__noreturn__))
414 # elif defined(__NORETURN) /* used in Solaris */
415 # define GC_PTHREAD_EXIT_ATTRIBUTE __NORETURN
416 # else
417 # define GC_PTHREAD_EXIT_ATTRIBUTE /* empty */
418 # endif
419 # endif
420
421 # if (!defined(GC_HAVE_PTHREAD_EXIT) || defined(__native_client__)) \
422 && !defined(GC_NO_PTHREAD_CANCEL)
423 /* Either there is no pthread_cancel() or no need to intercept it. */
424 # define GC_NO_PTHREAD_CANCEL
425 # endif
426
427 #endif /* GC_PTHREADS */
428
429 #ifdef __cplusplus
430
431 #ifndef GC_ATTR_EXPLICIT
432 # if __cplusplus >= 201103L && !defined(__clang__) || _MSVC_LANG >= 201103L \
433 || defined(CPPCHECK)
434 # define GC_ATTR_EXPLICIT explicit
435 # else
436 # define GC_ATTR_EXPLICIT /* empty */
437 # endif
438 #endif
439
440 #ifndef GC_NOEXCEPT
441 # if defined(__DMC__) || (defined(__BORLANDC__) \
442 && (defined(_RWSTD_NO_EXCEPTIONS) || defined(_RWSTD_NO_EX_SPEC))) \
443 || (defined(_MSC_VER) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS) \
444 || (defined(__WATCOMC__) && !defined(_CPPUNWIND))
445 # define GC_NOEXCEPT /* empty */
446 # ifndef GC_NEW_ABORTS_ON_OOM
447 # define GC_NEW_ABORTS_ON_OOM
448 # endif
449 # elif __cplusplus >= 201103L || _MSVC_LANG >= 201103L
450 # define GC_NOEXCEPT noexcept
451 # else
452 # define GC_NOEXCEPT throw()
453 # endif
454 #endif
455
456 #ifndef GC_CONSTEXPR
457 # if __cplusplus >= 202002L
458 # define GC_CONSTEXPR constexpr
459 # else
460 # define GC_CONSTEXPR /* empty */
461 # endif
462 #endif
463
464 #endif /* __cplusplus */
465
466 #endif