workaround.hpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2015. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_DETAIL_WORKAROUND_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_WORKAROUND_HPP
  12. #ifndef BOOST_CONFIG_HPP
  13. # include <boost/config.hpp>
  14. #endif
  15. #
  16. #if defined(BOOST_HAS_PRAGMA_ONCE)
  17. # pragma once
  18. #endif
  19. #if defined(BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION) && defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
  20. #error "BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION && BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION can't be defined at the same time"
  21. #endif
  22. //#define BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION
  23. #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
  24. #define BOOST_INTERPROCESS_WINDOWS
  25. #if !defined(BOOST_INTERPROCESS_FORCE_NATIVE_EMULATION) && !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION)
  26. #define BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION
  27. #endif
  28. #define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
  29. #else
  30. #include <unistd.h>
  31. #if defined (__CYGWIN__) && (!defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE < 200112L))
  32. #error "Error: Compiling on Cygwin without POSIX is not supported. Please define _XOPEN_SOURCE >= 600 or _POSIX_C_SOURCE >= 200112 when compiling"
  33. #endif
  34. //////////////////////////////////////////////////////
  35. //Check for XSI shared memory objects. They are available in nearly all UNIX platforms
  36. //////////////////////////////////////////////////////
  37. #if !defined(__QNXNTO__) && !defined(__ANDROID__) && !defined(__HAIKU__) && !(__VXWORKS__) && !(__EMSCRIPTEN__)
  38. #define BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS
  39. #endif
  40. //////////////////////////////////////////////////////
  41. // From SUSv3/UNIX 98, pthread_mutexattr_settype is mandatory
  42. //////////////////////////////////////////////////////
  43. #if defined(_XOPEN_UNIX) && ((_XOPEN_VERSION + 0) >= 500)
  44. #define BOOST_INTERPROCESS_POSIX_RECURSIVE_MUTEXES
  45. #endif
  46. //////////////////////////////////////////////////////
  47. // _POSIX_THREAD_PROCESS_SHARED (POSIX.1b/POSIX.4)
  48. //////////////////////////////////////////////////////
  49. #if defined(_POSIX_THREAD_PROCESS_SHARED) && ((_POSIX_THREAD_PROCESS_SHARED + 0) > 0)
  50. //Cygwin defines _POSIX_THREAD_PROCESS_SHARED but does not implement it.
  51. #if defined(__CYGWIN__)
  52. #define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  53. #elif defined(__APPLE__)
  54. //The pthreads implementation of darwin stores a pointer to a mutex inside the condition
  55. //structure so real sharing between processes is broken. See:
  56. //https://opensource.apple.com/source/libpthread/libpthread-301.30.1/src/pthread_cond.c.auto.html
  57. //in method pthread_cond_wait
  58. #define BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  59. #endif
  60. //If buggy _POSIX_THREAD_PROCESS_SHARED is detected avoid using it
  61. #if defined(BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED)
  62. #undef BOOST_INTERPROCESS_BUGGY_POSIX_PROCESS_SHARED
  63. #else
  64. #define BOOST_INTERPROCESS_POSIX_PROCESS_SHARED
  65. #endif
  66. #endif
  67. //////////////////////////////////////////////////////
  68. // BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
  69. //////////////////////////////////////////////////////
  70. #if (_XOPEN_SOURCE >= 700 || _POSIX_C_SOURCE >= 200809L)
  71. #define BOOST_INTERPROCESS_POSIX_ROBUST_MUTEXES
  72. #endif
  73. //////////////////////////////////////////////////////
  74. // _POSIX_SHARED_MEMORY_OBJECTS (POSIX.1b/POSIX.4)
  75. //////////////////////////////////////////////////////
  76. #if ( defined(_POSIX_SHARED_MEMORY_OBJECTS) && ((_POSIX_SHARED_MEMORY_OBJECTS + 0) > 0) ) ||\
  77. (defined(__vms) && __CRTL_VER >= 70200000)
  78. #define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
  79. //Some systems have filesystem-based resources, so the
  80. //portable "/shmname" format does not work due to permission issues
  81. //For those systems we need to form a path to a temporary directory:
  82. // hp-ux tru64 vms freebsd
  83. #if defined(__hpux) || defined(__osf__) || defined(__vms) || (defined(__FreeBSD__) && (__FreeBSD__ < 7))
  84. #define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
  85. //Some systems have "jailed" environments where shm usage is restricted at runtime
  86. //and temporary file based shm is possible in those executions.
  87. #elif defined(__FreeBSD__)
  88. #define BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY
  89. #endif
  90. #endif
  91. //////////////////////////////////////////////////////
  92. // _POSIX_MAPPED_FILES (POSIX.1b/POSIX.4)
  93. //////////////////////////////////////////////////////
  94. #if defined(_POSIX_MAPPED_FILES) && ((_POSIX_MAPPED_FILES + 0) > 0)
  95. #define BOOST_INTERPROCESS_POSIX_MAPPED_FILES
  96. #endif
  97. //////////////////////////////////////////////////////
  98. // _POSIX_SEMAPHORES (POSIX.1b/POSIX.4)
  99. //////////////////////////////////////////////////////
  100. #if ( defined(_POSIX_SEMAPHORES) && ((_POSIX_SEMAPHORES + 0) > 0) ) ||\
  101. ( defined(__FreeBSD__) && (__FreeBSD__ >= 4)) || \
  102. defined(__APPLE__)
  103. #define BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES
  104. //MacOsX declares _POSIX_SEMAPHORES but sem_init returns ENOSYS
  105. #if !defined(__APPLE__)
  106. #define BOOST_INTERPROCESS_POSIX_UNNAMED_SEMAPHORES
  107. #endif
  108. #if defined(__osf__) || defined(__vms)
  109. #define BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SEMAPHORES
  110. #endif
  111. #endif
  112. //////////////////////////////////////////////////////
  113. // _POSIX_BARRIERS (SUSv3/Unix03)
  114. //////////////////////////////////////////////////////
  115. #if defined(_POSIX_BARRIERS) && ((_POSIX_BARRIERS + 0) >= 200112L)
  116. #define BOOST_INTERPROCESS_POSIX_BARRIERS
  117. #endif
  118. //////////////////////////////////////////////////////
  119. // _POSIX_TIMEOUTS (SUSv3/Unix03)
  120. //////////////////////////////////////////////////////
  121. #if defined(_POSIX_TIMEOUTS) && ((_POSIX_TIMEOUTS + 0L) >= 200112L)
  122. #define BOOST_INTERPROCESS_POSIX_TIMEOUTS
  123. #endif
  124. //////////////////////////////////////////////////////
  125. // Detect BSD derivatives to detect sysctl
  126. //////////////////////////////////////////////////////
  127. #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
  128. #define BOOST_INTERPROCESS_BSD_DERIVATIVE
  129. //Some *BSD systems (OpenBSD & NetBSD) need sys/param.h before sys/sysctl.h, whereas
  130. //others (FreeBSD & Darwin) need sys/types.h
  131. #include <sys/types.h>
  132. #include <sys/param.h>
  133. #include <sys/sysctl.h>
  134. #if defined(CTL_KERN) && defined (KERN_BOOTTIME)
  135. //#define BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME
  136. #endif
  137. #endif
  138. //////////////////////////////////////////////////////
  139. //64 bit offset
  140. //////////////////////////////////////////////////////
  141. #if (defined (_V6_ILP32_OFFBIG) &&(_V6_ILP32_OFFBIG - 0 > 0)) ||\
  142. (defined (_V6_LP64_OFF64) &&(_V6_LP64_OFF64 - 0 > 0)) ||\
  143. (defined (_V6_LPBIG_OFFBIG) &&(_V6_LPBIG_OFFBIG - 0 > 0)) ||\
  144. (defined (_XBS5_ILP32_OFFBIG)&&(_XBS5_ILP32_OFFBIG - 0 > 0)) ||\
  145. (defined (_XBS5_LP64_OFF64) &&(_XBS5_LP64_OFF64 - 0 > 0)) ||\
  146. (defined (_XBS5_LPBIG_OFFBIG)&&(_XBS5_LPBIG_OFFBIG - 0 > 0)) ||\
  147. (defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))||\
  148. (defined (_FILE_OFFSET_BITS) &&(_FILE_OFFSET_BITS - 0 >= 64))
  149. #define BOOST_INTERPROCESS_UNIX_64_BIT_OR_BIGGER_OFF_T
  150. #endif
  151. //////////////////////////////////////////////////////
  152. //posix_fallocate
  153. //////////////////////////////////////////////////////
  154. #if (_XOPEN_SOURCE >= 600 || _POSIX_C_SOURCE >= 200112L)
  155. #define BOOST_INTERPROCESS_POSIX_FALLOCATE
  156. #endif
  157. #endif //!defined(BOOST_INTERPROCESS_WINDOWS)
  158. #if defined(BOOST_INTERPROCESS_WINDOWS) || defined(BOOST_INTERPROCESS_POSIX_MAPPED_FILES)
  159. # define BOOST_INTERPROCESS_MAPPED_FILES
  160. #endif
  161. //Now declare some Boost.Interprocess features depending on the implementation
  162. #if defined(BOOST_INTERPROCESS_POSIX_NAMED_SEMAPHORES) && !defined(BOOST_INTERPROCESS_POSIX_SEMAPHORES_NO_UNLINK)
  163. #define BOOST_INTERPROCESS_NAMED_MUTEX_USES_POSIX_SEMAPHORES
  164. #define BOOST_INTERPROCESS_NAMED_SEMAPHORE_USES_POSIX_SEMAPHORES
  165. #endif
  166. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  167. #define BOOST_INTERPROCESS_PERFECT_FORWARDING
  168. #endif
  169. // Timeout duration use if BOOST_INTERPROCESS_ENABLE_TIMEOUT_WHEN_LOCKING is set
  170. #ifndef BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS
  171. #define BOOST_INTERPROCESS_TIMEOUT_WHEN_LOCKING_DURATION_MS 10000
  172. #endif
  173. // Max open or create tries with managed memory segments
  174. #ifndef BOOST_INTERPROCESS_MANAGED_OPEN_OR_CREATE_INITIALIZE_MAX_TRIES
  175. #define BOOST_INTERPROCESS_MANAGED_OPEN_OR_CREATE_INITIALIZE_MAX_TRIES 20u
  176. #endif
  177. // Maximum timeout in seconds with open or create tries with managed memory segments
  178. // waiting the creator to initialize the shared memory
  179. #ifndef BOOST_INTERPROCESS_MANAGED_OPEN_OR_CREATE_INITIALIZE_TIMEOUT_SEC
  180. #define BOOST_INTERPROCESS_MANAGED_OPEN_OR_CREATE_INITIALIZE_TIMEOUT_SEC 300u
  181. #endif
  182. //Other switches
  183. //BOOST_INTERPROCESS_MSG_QUEUE_USES_CIRC_INDEX
  184. //message queue uses a circular queue as index instead of an array (better performance)
  185. //Boost version < 1.52 uses an array, so undef this if you want to communicate
  186. //with processes compiled with those versions.
  187. #define BOOST_INTERPROCESS_MSG_QUEUE_CIRCULAR_INDEX
  188. //Macros for documentation purposes. For code, expands to the argument
  189. #define BOOST_INTERPROCESS_IMPDEF(TYPE) TYPE
  190. #define BOOST_INTERPROCESS_SEEDOC(TYPE) TYPE
  191. #define BOOST_INTERPROCESS_DOC1ST(TYPE1, TYPE2) TYPE2
  192. #define BOOST_INTERPROCESS_I ,
  193. #define BOOST_INTERPROCESS_DOCIGN(T1) T1
  194. //#define BOOST_INTERPROCESS_DISABLE_FORCEINLINE
  195. #if defined(BOOST_INTERPROCESS_DISABLE_FORCEINLINE)
  196. #define BOOST_INTERPROCESS_FORCEINLINE inline
  197. #elif defined(BOOST_INTERPROCESS_FORCEINLINE_IS_BOOST_FORCELINE)
  198. #define BOOST_INTERPROCESS_FORCEINLINE BOOST_FORCEINLINE
  199. #elif defined(BOOST_MSVC) && (_MSC_VER < 1900 || defined(_DEBUG))
  200. //"__forceinline" and MSVC seems to have some bugs in old versions and in debug mode
  201. #define BOOST_INTERPROCESS_FORCEINLINE inline
  202. #elif defined(BOOST_CLANG) || (defined(BOOST_GCC) && ((__GNUC__ <= 5) || defined(__MINGW32__)))
  203. //Older GCCs have problems with forceinline
  204. //Clang can have code bloat issues with forceinline, see
  205. //https://lists.boost.org/boost-users/2023/04/91445.php and
  206. //https://github.com/llvm/llvm-project/issues/62202
  207. #define BOOST_INTERPROCESS_FORCEINLINE inline
  208. #else
  209. #define BOOST_INTERPROCESS_FORCEINLINE BOOST_FORCEINLINE
  210. #endif
  211. #ifdef BOOST_WINDOWS
  212. #define BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES
  213. #ifdef __clang__
  214. #define BOOST_INTERPROCESS_DISABLE_DEPRECATED_WARNING _Pragma("clang diagnostic push") \
  215. _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
  216. #define BOOST_INTERPROCESS_RESTORE_WARNING _Pragma("clang diagnostic pop")
  217. #else // __clang__
  218. #define BOOST_INTERPROCESS_DISABLE_DEPRECATED_WARNING __pragma(warning(push)) \
  219. __pragma(warning(disable : 4996))
  220. #define BOOST_INTERPROCESS_RESTORE_WARNING __pragma(warning(pop))
  221. #endif // __clang__
  222. #endif
  223. #if defined(BOOST_HAS_THREADS)
  224. # if defined(_MSC_VER) || defined(__MWERKS__) || defined(__MINGW32__) || defined(__BORLANDC__)
  225. //no reentrant posix functions (eg: localtime_r)
  226. # elif (!defined(__hpux) || (defined(__hpux) && defined(_REENTRANT)))
  227. # define BOOST_INTERPROCESS_HAS_REENTRANT_STD_FUNCTIONS
  228. # endif
  229. #endif
  230. namespace boost {
  231. namespace interprocess {
  232. template <typename T1>
  233. BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore(T1 const&)
  234. {}
  235. }} //namespace boost::interprocess {
  236. #if !(defined BOOST_NO_EXCEPTIONS)
  237. # define BOOST_INTERPROCESS_TRY { try
  238. # define BOOST_INTERPROCESS_CATCH(x) catch(x)
  239. # define BOOST_INTERPROCESS_RETHROW throw;
  240. # define BOOST_INTERPROCESS_CATCH_END }
  241. #else
  242. # if !defined(BOOST_MSVC) || BOOST_MSVC >= 1900
  243. # define BOOST_INTERPROCESS_TRY { if (true)
  244. # define BOOST_INTERPROCESS_CATCH(x) else if (false)
  245. # else
  246. // warning C4127: conditional expression is constant
  247. # define BOOST_INTERPROCESS_TRY { \
  248. __pragma(warning(push)) \
  249. __pragma(warning(disable: 4127)) \
  250. if (true) \
  251. __pragma(warning(pop))
  252. # define BOOST_INTERPROCESS_CATCH(x) else \
  253. __pragma(warning(push)) \
  254. __pragma(warning(disable: 4127)) \
  255. if (false) \
  256. __pragma(warning(pop))
  257. # endif
  258. # define BOOST_INTERPROCESS_RETHROW
  259. # define BOOST_INTERPROCESS_CATCH_END }
  260. #endif
  261. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  262. # ifndef BOOST_NO_CXX11_VARIADIC_MACROS
  263. # define BOOST_INTERPROCESS_STATIC_ASSERT( ... ) static_assert(__VA_ARGS__, #__VA_ARGS__)
  264. # else
  265. # define BOOST_INTERPROCESS_STATIC_ASSERT( B ) static_assert(B, #B)
  266. # endif
  267. #else
  268. namespace boost {
  269. namespace interprocess {
  270. namespace dtl {
  271. template<bool B>
  272. struct STATIC_ASSERTION_FAILURE;
  273. template<>
  274. struct STATIC_ASSERTION_FAILURE<true> {};
  275. template<unsigned> struct static_assert_test {};
  276. }
  277. }
  278. }
  279. #define BOOST_INTERPROCESS_STATIC_ASSERT(B) \
  280. typedef ::boost::interprocess::dtl::static_assert_test<\
  281. (unsigned)sizeof(::boost::interprocess::dtl::STATIC_ASSERTION_FAILURE<bool(B)>)>\
  282. BOOST_JOIN(boost_container_static_assert_typedef_, __LINE__) BOOST_ATTRIBUTE_UNUSED
  283. #endif
  284. #ifndef BOOST_NO_CXX11_STATIC_ASSERT
  285. # ifndef BOOST_NO_CXX11_VARIADIC_MACROS
  286. # define BOOST_INTERPROCESS_STATIC_ASSERT_MSG( ... ) static_assert(__VA_ARGS__)
  287. # else
  288. # define BOOST_INTERPROCESS_STATIC_ASSERT_MSG( B, Msg ) static_assert( B, Msg )
  289. # endif
  290. #else
  291. # define BOOST_INTERPROCESS_STATIC_ASSERT_MSG( B, Msg ) BOOST_INTERPROCESS_STATIC_ASSERT( B )
  292. #endif
  293. #if !defined(BOOST_NO_CXX17_INLINE_VARIABLES)
  294. # define BOOST_INTERPROCESS_CONSTANT_VAR BOOST_INLINE_CONSTEXPR
  295. #else
  296. # define BOOST_INTERPROCESS_CONSTANT_VAR static BOOST_CONSTEXPR_OR_CONST
  297. #endif
  298. #if defined(__GNUC__) && ((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40600)
  299. #define BOOST_INTERPROCESS_GCC_COMPATIBLE_HAS_DIAGNOSTIC_IGNORED
  300. #elif defined(__clang__)
  301. #define BOOST_INTERPROCESS_GCC_COMPATIBLE_HAS_DIAGNOSTIC_IGNORED
  302. #endif
  303. ////////////////////////////////////////////
  304. //
  305. // BOOST_INTERPROCESS_EINTR_RETRY
  306. //
  307. ////////////////////////////////////////////
  308. //#define DISABLE_BOOST_INTERPROCESS_EINTR_RETRY
  309. #if !defined(DISABLE_BOOST_INTERPROCESS_EINTR_RETRY) && defined(__GNUC__)
  310. /* taken from glibc unistd.h and fixes musl */
  311. #define BOOST_INTERPROCESS_EINTR_RETRY(RESULTTYPE, FAILUREVALUE, EXPRESSION) \
  312. (__extension__ \
  313. ({ RESULTTYPE __result; \
  314. do __result = (RESULTTYPE) (EXPRESSION); \
  315. while (__result == FAILUREVALUE && errno == EINTR); \
  316. __result; }))
  317. #else //!defined(DISABLE_BOOST_INTERPROCESS_EINTR_RETRY) && defined(__GNUC__)
  318. #define BOOST_INTERPROCESS_EINTR_RETRY(RESULTTYPE, FAILUREVALUE, EXPRESSION) ((RESULTTYPE)(EXPRESSION))
  319. #endif //!defined(DISABLE_BOOST_INTERPROCESS_EINTR_RETRY) && defined(__GNUC__)
  320. #if !defined(BOOST_INTERPROCESS_ATEXIT)
  321. #define BOOST_INTERPROCESS_ATEXIT(f) std::atexit((f))
  322. #endif //!defined(BOOST_INTERPROCESS_ATEXIT)
  323. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_WORKAROUND_HPP