gc_config_macros.h 14 KB

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