gc_config_macros.h 13 KB

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