libitm.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* Copyright (C) 2008-2022 Free Software Foundation, Inc.
  2. Contributed by Richard Henderson <rth@redhat.com>.
  3. This file is part of the GNU Transactional Memory Library (libitm).
  4. Libitm is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. /* The external interface of this library follows the specification described
  20. in version 1 of http://www.intel.com/some/path/here.pdf. */
  21. #ifndef LIBITM_H
  22. #define LIBITM_H 1
  23. #include <stddef.h>
  24. #include <stdbool.h>
  25. #include <stdint.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifdef __i386__
  30. /* Only for 32-bit x86. */
  31. # define ITM_REGPARM __attribute__((regparm(2)))
  32. #else
  33. # define ITM_REGPARM
  34. #endif
  35. #define ITM_NORETURN __attribute__((noreturn))
  36. #define ITM_PURE __attribute__((transaction_pure))
  37. #ifdef _GLIBCXX_NOTHROW
  38. # define _ITM_NOTHROW _GLIBCXX_NOTHROW
  39. #elif !defined (__cplusplus)
  40. # define _ITM_NOTHROW __attribute__((__nothrow__))
  41. #elif __cplusplus < 201103L
  42. # define _ITM_NOTHROW throw ()
  43. #else
  44. # define _ITM_NOTHROW noexcept
  45. #endif
  46. /* The following are externally visible definitions and functions, though
  47. only very few of these should be called by user code. */
  48. /* Values used as arguments to abort. */
  49. typedef enum {
  50. userAbort = 1,
  51. userRetry = 2,
  52. TMConflict= 4,
  53. exceptionBlockAbort = 8,
  54. outerAbort = 16
  55. } _ITM_abortReason;
  56. /* Arguments to changeTransactionMode */
  57. typedef enum
  58. {
  59. modeSerialIrrevocable,
  60. } _ITM_transactionState;
  61. /* Results from inTransaction */
  62. typedef enum
  63. {
  64. outsideTransaction = 0, /* So "if (inTransaction(td))" works */
  65. inRetryableTransaction,
  66. inIrrevocableTransaction
  67. } _ITM_howExecuting;
  68. /* Values to describe properties of code, passed in to beginTransaction.
  69. Some of these constants are duplicated in some of the ITM_beginTransaction
  70. implementations, so update those too when applying any changes. */
  71. typedef enum
  72. {
  73. pr_instrumentedCode = 0x0001,
  74. pr_uninstrumentedCode = 0x0002,
  75. pr_multiwayCode = pr_instrumentedCode | pr_uninstrumentedCode,
  76. /* Called pr_hasNoXMMUpdate in the Intel document, used for
  77. avoiding vector register save/restore for any target. */
  78. pr_hasNoVectorUpdate = 0x0004,
  79. pr_hasNoAbort = 0x0008,
  80. /* Not present in the Intel document, used for avoiding
  81. floating point register save/restore for any target. */
  82. pr_hasNoFloatUpdate = 0x0010,
  83. pr_hasNoIrrevocable = 0x0020,
  84. pr_doesGoIrrevocable = 0x0040,
  85. pr_aWBarriersOmitted = 0x0100,
  86. pr_RaRBarriersOmitted = 0x0200,
  87. pr_undoLogCode = 0x0400,
  88. pr_preferUninstrumented = 0x0800,
  89. /* Exception blocks are not used nor supported. */
  90. pr_exceptionBlock = 0x1000,
  91. pr_hasElse = 0x2000,
  92. pr_readOnly = 0x4000,
  93. pr_hasNoSimpleReads = 0x400000,
  94. /* These are not part of the ABI but used for custom HTM fast paths. See
  95. ITM_beginTransaction and gtm_thread::begin_transaction. */
  96. pr_HTMRetryableAbort = 0x800000,
  97. pr_HTMRetriedAfterAbort = 0x1000000
  98. } _ITM_codeProperties;
  99. /* Result from startTransaction that describes what actions to take.
  100. Some of these constants are duplicated in some of the ITM_beginTransaction
  101. implementations, so update those too when applying any changes. */
  102. typedef enum
  103. {
  104. a_runInstrumentedCode = 0x01,
  105. a_runUninstrumentedCode = 0x02,
  106. a_saveLiveVariables = 0x04,
  107. a_restoreLiveVariables = 0x08,
  108. a_abortTransaction = 0x10,
  109. a_tryHTMFastPath = 0x20
  110. } _ITM_actions;
  111. typedef struct
  112. {
  113. uint32_t reserved_1;
  114. uint32_t flags;
  115. uint32_t reserved_2;
  116. uint32_t reserved_3;
  117. const char *psource;
  118. } _ITM_srcLocation;
  119. typedef void (* _ITM_userUndoFunction)(void *);
  120. typedef void (* _ITM_userCommitFunction) (void *);
  121. #define _ITM_VERSION "0.90 (Feb 29 2008)"
  122. #define _ITM_VERSION_NO 90
  123. extern int _ITM_versionCompatible (int) ITM_REGPARM;
  124. extern const char * _ITM_libraryVersion (void) ITM_REGPARM;
  125. void _ITM_error(const _ITM_srcLocation *, int errorCode)
  126. ITM_REGPARM ITM_NORETURN;
  127. extern _ITM_howExecuting _ITM_inTransaction(void) ITM_REGPARM;
  128. typedef uint64_t _ITM_transactionId_t; /* Transaction identifier */
  129. #define _ITM_noTransactionId 1 /* Id for non-transactional code. */
  130. extern _ITM_transactionId_t _ITM_getTransactionId(void) ITM_REGPARM;
  131. extern uint32_t _ITM_beginTransaction(uint32_t, ...) ITM_REGPARM;
  132. extern void _ITM_abortTransaction(_ITM_abortReason) ITM_REGPARM ITM_NORETURN;
  133. extern void _ITM_commitTransaction (void) ITM_REGPARM;
  134. extern void _ITM_changeTransactionMode (_ITM_transactionState) ITM_REGPARM;
  135. extern void _ITM_addUserCommitAction(_ITM_userCommitFunction,
  136. _ITM_transactionId_t, void *) ITM_REGPARM;
  137. extern void _ITM_addUserUndoAction(_ITM_userUndoFunction, void *) ITM_REGPARM;
  138. extern void _ITM_dropReferences (void *, size_t) ITM_REGPARM ITM_PURE;
  139. extern void *_ITM_malloc (size_t)
  140. __attribute__((__malloc__)) ITM_PURE;
  141. extern void *_ITM_calloc (size_t, size_t)
  142. __attribute__((__malloc__)) ITM_PURE;
  143. extern void _ITM_free (void *) ITM_PURE;
  144. /* The following typedefs exist to make the macro expansions below work
  145. properly. They are not part of any API. */
  146. typedef uint8_t _ITM_TYPE_U1;
  147. typedef uint16_t _ITM_TYPE_U2;
  148. typedef uint32_t _ITM_TYPE_U4;
  149. typedef uint64_t _ITM_TYPE_U8;
  150. typedef float _ITM_TYPE_F;
  151. typedef double _ITM_TYPE_D;
  152. typedef long double _ITM_TYPE_E;
  153. typedef float _Complex _ITM_TYPE_CF;
  154. typedef double _Complex _ITM_TYPE_CD;
  155. typedef long double _Complex _ITM_TYPE_CE;
  156. #define ITM_BARRIERS(T) \
  157. extern _ITM_TYPE_##T _ITM_R##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  158. extern _ITM_TYPE_##T _ITM_RaR##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  159. extern _ITM_TYPE_##T _ITM_RaW##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  160. extern _ITM_TYPE_##T _ITM_RfW##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  161. extern void _ITM_W##T (_ITM_TYPE_##T *, _ITM_TYPE_##T) ITM_REGPARM; \
  162. extern void _ITM_WaR##T (_ITM_TYPE_##T *, _ITM_TYPE_##T) ITM_REGPARM; \
  163. extern void _ITM_WaW##T (_ITM_TYPE_##T *, _ITM_TYPE_##T) ITM_REGPARM;
  164. ITM_BARRIERS(U1)
  165. ITM_BARRIERS(U2)
  166. ITM_BARRIERS(U4)
  167. ITM_BARRIERS(U8)
  168. ITM_BARRIERS(F)
  169. ITM_BARRIERS(D)
  170. ITM_BARRIERS(E)
  171. ITM_BARRIERS(CF)
  172. ITM_BARRIERS(CD)
  173. ITM_BARRIERS(CE)
  174. #define ITM_LOG(T) \
  175. extern void _ITM_L##T (const _ITM_TYPE_##T *) ITM_REGPARM;
  176. ITM_LOG(U1)
  177. ITM_LOG(U2)
  178. ITM_LOG(U4)
  179. ITM_LOG(U8)
  180. ITM_LOG(F)
  181. ITM_LOG(D)
  182. ITM_LOG(E)
  183. ITM_LOG(CF)
  184. ITM_LOG(CD)
  185. ITM_LOG(CE)
  186. #if defined(__i386__) || defined(__x86_64__)
  187. # ifdef __MMX__
  188. typedef int _ITM_TYPE_M64 __attribute__((vector_size(8), may_alias));
  189. ITM_BARRIERS(M64)
  190. ITM_LOG(M64)
  191. # endif
  192. # ifdef __SSE__
  193. typedef float _ITM_TYPE_M128 __attribute__((vector_size(16), may_alias));
  194. ITM_BARRIERS(M128)
  195. ITM_LOG(M128)
  196. # endif
  197. # ifdef __AVX__
  198. typedef float _ITM_TYPE_M256 __attribute__((vector_size(32), may_alias));
  199. ITM_BARRIERS(M256)
  200. ITM_LOG(M256)
  201. # endif
  202. #endif /* i386 */
  203. #undef ITM_BARRIERS
  204. #undef ITM_LOG
  205. extern void _ITM_LB (const void *, size_t) ITM_REGPARM;
  206. extern void _ITM_memcpyRnWt(void *, const void *, size_t) ITM_REGPARM;
  207. extern void _ITM_memcpyRnWtaR(void *, const void *, size_t) ITM_REGPARM;
  208. extern void _ITM_memcpyRnWtaW(void *, const void *, size_t) ITM_REGPARM;
  209. extern void _ITM_memcpyRtWn(void *, const void *, size_t) ITM_REGPARM;
  210. extern void _ITM_memcpyRtWt(void *, const void *, size_t) ITM_REGPARM;
  211. extern void _ITM_memcpyRtWtaR(void *, const void *, size_t) ITM_REGPARM;
  212. extern void _ITM_memcpyRtWtaW(void *, const void *, size_t) ITM_REGPARM;
  213. extern void _ITM_memcpyRtaRWn(void *, const void *, size_t) ITM_REGPARM;
  214. extern void _ITM_memcpyRtaRWt(void *, const void *, size_t) ITM_REGPARM;
  215. extern void _ITM_memcpyRtaRWtaR(void *, const void *, size_t) ITM_REGPARM;
  216. extern void _ITM_memcpyRtaRWtaW(void *, const void *, size_t) ITM_REGPARM;
  217. extern void _ITM_memcpyRtaWWn(void *, const void *, size_t) ITM_REGPARM;
  218. extern void _ITM_memcpyRtaWWt(void *, const void *, size_t) ITM_REGPARM;
  219. extern void _ITM_memcpyRtaWWtaR(void *, const void *, size_t) ITM_REGPARM;
  220. extern void _ITM_memcpyRtaWWtaW(void *, const void *, size_t) ITM_REGPARM;
  221. extern void _ITM_memmoveRnWt(void *, const void *, size_t) ITM_REGPARM;
  222. extern void _ITM_memmoveRnWtaR(void *, const void *, size_t) ITM_REGPARM;
  223. extern void _ITM_memmoveRnWtaW(void *, const void *, size_t) ITM_REGPARM;
  224. extern void _ITM_memmoveRtWn(void *, const void *, size_t) ITM_REGPARM;
  225. extern void _ITM_memmoveRtWt(void *, const void *, size_t) ITM_REGPARM;
  226. extern void _ITM_memmoveRtWtaR(void *, const void *, size_t) ITM_REGPARM;
  227. extern void _ITM_memmoveRtWtaW(void *, const void *, size_t) ITM_REGPARM;
  228. extern void _ITM_memmoveRtaRWn(void *, const void *, size_t) ITM_REGPARM;
  229. extern void _ITM_memmoveRtaRWt(void *, const void *, size_t) ITM_REGPARM;
  230. extern void _ITM_memmoveRtaRWtaR(void *, const void *, size_t) ITM_REGPARM;
  231. extern void _ITM_memmoveRtaRWtaW(void *, const void *, size_t) ITM_REGPARM;
  232. extern void _ITM_memmoveRtaWWn(void *, const void *, size_t) ITM_REGPARM;
  233. extern void _ITM_memmoveRtaWWt(void *, const void *, size_t) ITM_REGPARM;
  234. extern void _ITM_memmoveRtaWWtaR(void *, const void *, size_t) ITM_REGPARM;
  235. extern void _ITM_memmoveRtaWWtaW(void *, const void *, size_t) ITM_REGPARM;
  236. extern void _ITM_memsetW(void *, int, size_t) ITM_REGPARM;
  237. extern void _ITM_memsetWaR(void *, int, size_t) ITM_REGPARM;
  238. extern void _ITM_memsetWaW(void *, int, size_t) ITM_REGPARM;
  239. // ??? These are not yet in the official spec; still work-in-progress.
  240. extern void *_ITM_getTMCloneOrIrrevocable (void *) ITM_REGPARM;
  241. extern void *_ITM_getTMCloneSafe (void *) ITM_REGPARM;
  242. extern void _ITM_registerTMCloneTable (void *, size_t);
  243. extern void _ITM_deregisterTMCloneTable (void *);
  244. extern void *_ITM_cxa_allocate_exception (size_t) _ITM_NOTHROW;
  245. extern void _ITM_cxa_free_exception (void *exc_ptr) _ITM_NOTHROW;
  246. extern void _ITM_cxa_throw (void *obj, void *tinfo, void (*dest) (void *));
  247. extern void *_ITM_cxa_begin_catch (void *exc_ptr) _ITM_NOTHROW;
  248. extern void _ITM_cxa_end_catch (void); /* This can throw. */
  249. extern void _ITM_commitTransactionEH(void *exc_ptr) ITM_REGPARM;
  250. #ifdef __cplusplus
  251. } /* extern "C" */
  252. #endif
  253. #endif /* LIBITM_H */