libitm.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /* Copyright (C) 2008-2015 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. /* The following are externally visible definitions and functions, though
  38. only very few of these should be called by user code. */
  39. /* Values used as arguments to abort. */
  40. typedef enum {
  41. userAbort = 1,
  42. userRetry = 2,
  43. TMConflict= 4,
  44. exceptionBlockAbort = 8,
  45. outerAbort = 16
  46. } _ITM_abortReason;
  47. /* Arguments to changeTransactionMode */
  48. typedef enum
  49. {
  50. modeSerialIrrevocable,
  51. } _ITM_transactionState;
  52. /* Results from inTransaction */
  53. typedef enum
  54. {
  55. outsideTransaction = 0, /* So "if (inTransaction(td))" works */
  56. inRetryableTransaction,
  57. inIrrevocableTransaction
  58. } _ITM_howExecuting;
  59. /* Values to describe properties of code, passed in to beginTransaction.
  60. Some of these constants are duplicated in some of the ITM_beginTransaction
  61. implementations, so update those too when applying any changes. */
  62. typedef enum
  63. {
  64. pr_instrumentedCode = 0x0001,
  65. pr_uninstrumentedCode = 0x0002,
  66. pr_multiwayCode = pr_instrumentedCode | pr_uninstrumentedCode,
  67. /* Called pr_hasNoXMMUpdate in the Intel document, used for
  68. avoiding vector register save/restore for any target. */
  69. pr_hasNoVectorUpdate = 0x0004,
  70. pr_hasNoAbort = 0x0008,
  71. /* Not present in the Intel document, used for avoiding
  72. floating point register save/restore for any target. */
  73. pr_hasNoFloatUpdate = 0x0010,
  74. pr_hasNoIrrevocable = 0x0020,
  75. pr_doesGoIrrevocable = 0x0040,
  76. pr_aWBarriersOmitted = 0x0100,
  77. pr_RaRBarriersOmitted = 0x0200,
  78. pr_undoLogCode = 0x0400,
  79. pr_preferUninstrumented = 0x0800,
  80. /* Exception blocks are not used nor supported. */
  81. pr_exceptionBlock = 0x1000,
  82. pr_hasElse = 0x2000,
  83. pr_readOnly = 0x4000,
  84. pr_hasNoSimpleReads = 0x400000,
  85. /* These are not part of the ABI but used for custom HTM fast paths. See
  86. ITM_beginTransaction and gtm_thread::begin_transaction. */
  87. pr_HTMRetryableAbort = 0x800000,
  88. pr_HTMRetriedAfterAbort = 0x1000000
  89. } _ITM_codeProperties;
  90. /* Result from startTransaction that describes what actions to take.
  91. Some of these constants are duplicated in some of the ITM_beginTransaction
  92. implementations, so update those too when applying any changes. */
  93. typedef enum
  94. {
  95. a_runInstrumentedCode = 0x01,
  96. a_runUninstrumentedCode = 0x02,
  97. a_saveLiveVariables = 0x04,
  98. a_restoreLiveVariables = 0x08,
  99. a_abortTransaction = 0x10,
  100. a_tryHTMFastPath = 0x20
  101. } _ITM_actions;
  102. typedef struct
  103. {
  104. uint32_t reserved_1;
  105. uint32_t flags;
  106. uint32_t reserved_2;
  107. uint32_t reserved_3;
  108. const char *psource;
  109. } _ITM_srcLocation;
  110. typedef void (* _ITM_userUndoFunction)(void *);
  111. typedef void (* _ITM_userCommitFunction) (void *);
  112. #define _ITM_VERSION "0.90 (Feb 29 2008)"
  113. #define _ITM_VERSION_NO 90
  114. extern int _ITM_versionCompatible (int) ITM_REGPARM;
  115. extern const char * _ITM_libraryVersion (void) ITM_REGPARM;
  116. void _ITM_error(const _ITM_srcLocation *, int errorCode)
  117. ITM_REGPARM ITM_NORETURN;
  118. extern _ITM_howExecuting _ITM_inTransaction(void) ITM_REGPARM;
  119. typedef uint64_t _ITM_transactionId_t; /* Transaction identifier */
  120. #define _ITM_noTransactionId 1 /* Id for non-transactional code. */
  121. extern _ITM_transactionId_t _ITM_getTransactionId(void) ITM_REGPARM;
  122. extern uint32_t _ITM_beginTransaction(uint32_t, ...) ITM_REGPARM;
  123. extern void _ITM_abortTransaction(_ITM_abortReason) ITM_REGPARM ITM_NORETURN;
  124. extern void _ITM_commitTransaction (void) ITM_REGPARM;
  125. extern void _ITM_changeTransactionMode (_ITM_transactionState) ITM_REGPARM;
  126. extern void _ITM_addUserCommitAction(_ITM_userCommitFunction,
  127. _ITM_transactionId_t, void *) ITM_REGPARM;
  128. extern void _ITM_addUserUndoAction(_ITM_userUndoFunction, void *) ITM_REGPARM;
  129. extern void _ITM_dropReferences (void *, size_t) ITM_REGPARM ITM_PURE;
  130. extern void *_ITM_malloc (size_t)
  131. __attribute__((__malloc__)) ITM_PURE;
  132. extern void *_ITM_calloc (size_t, size_t)
  133. __attribute__((__malloc__)) ITM_PURE;
  134. extern void _ITM_free (void *) ITM_PURE;
  135. /* The following typedefs exist to make the macro expansions below work
  136. properly. They are not part of any API. */
  137. typedef uint8_t _ITM_TYPE_U1;
  138. typedef uint16_t _ITM_TYPE_U2;
  139. typedef uint32_t _ITM_TYPE_U4;
  140. typedef uint64_t _ITM_TYPE_U8;
  141. typedef float _ITM_TYPE_F;
  142. typedef double _ITM_TYPE_D;
  143. typedef long double _ITM_TYPE_E;
  144. typedef float _Complex _ITM_TYPE_CF;
  145. typedef double _Complex _ITM_TYPE_CD;
  146. typedef long double _Complex _ITM_TYPE_CE;
  147. #define ITM_BARRIERS(T) \
  148. extern _ITM_TYPE_##T _ITM_R##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  149. extern _ITM_TYPE_##T _ITM_RaR##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  150. extern _ITM_TYPE_##T _ITM_RaW##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  151. extern _ITM_TYPE_##T _ITM_RfW##T(const _ITM_TYPE_##T *) ITM_REGPARM; \
  152. extern void _ITM_W##T (_ITM_TYPE_##T *, _ITM_TYPE_##T) ITM_REGPARM; \
  153. extern void _ITM_WaR##T (_ITM_TYPE_##T *, _ITM_TYPE_##T) ITM_REGPARM; \
  154. extern void _ITM_WaW##T (_ITM_TYPE_##T *, _ITM_TYPE_##T) ITM_REGPARM;
  155. ITM_BARRIERS(U1)
  156. ITM_BARRIERS(U2)
  157. ITM_BARRIERS(U4)
  158. ITM_BARRIERS(U8)
  159. ITM_BARRIERS(F)
  160. ITM_BARRIERS(D)
  161. ITM_BARRIERS(E)
  162. ITM_BARRIERS(CF)
  163. ITM_BARRIERS(CD)
  164. ITM_BARRIERS(CE)
  165. #define ITM_LOG(T) \
  166. extern void _ITM_L##T (const _ITM_TYPE_##T *) ITM_REGPARM;
  167. ITM_LOG(U1)
  168. ITM_LOG(U2)
  169. ITM_LOG(U4)
  170. ITM_LOG(U8)
  171. ITM_LOG(F)
  172. ITM_LOG(D)
  173. ITM_LOG(E)
  174. ITM_LOG(CF)
  175. ITM_LOG(CD)
  176. ITM_LOG(CE)
  177. #if defined(__i386__) || defined(__x86_64__)
  178. # ifdef __MMX__
  179. typedef int _ITM_TYPE_M64 __attribute__((vector_size(8), may_alias));
  180. ITM_BARRIERS(M64)
  181. ITM_LOG(M64)
  182. # endif
  183. # ifdef __SSE__
  184. typedef float _ITM_TYPE_M128 __attribute__((vector_size(16), may_alias));
  185. ITM_BARRIERS(M128)
  186. ITM_LOG(M128)
  187. # endif
  188. # ifdef __AVX__
  189. typedef float _ITM_TYPE_M256 __attribute__((vector_size(32), may_alias));
  190. ITM_BARRIERS(M256)
  191. ITM_LOG(M256)
  192. # endif
  193. #endif /* i386 */
  194. #undef ITM_BARRIERS
  195. #undef ITM_LOG
  196. extern void _ITM_LB (const void *, size_t) ITM_REGPARM;
  197. extern void _ITM_memcpyRnWt(void *, const void *, size_t) ITM_REGPARM;
  198. extern void _ITM_memcpyRnWtaR(void *, const void *, size_t) ITM_REGPARM;
  199. extern void _ITM_memcpyRnWtaW(void *, const void *, size_t) ITM_REGPARM;
  200. extern void _ITM_memcpyRtWn(void *, const void *, size_t) ITM_REGPARM;
  201. extern void _ITM_memcpyRtWt(void *, const void *, size_t) ITM_REGPARM;
  202. extern void _ITM_memcpyRtWtaR(void *, const void *, size_t) ITM_REGPARM;
  203. extern void _ITM_memcpyRtWtaW(void *, const void *, size_t) ITM_REGPARM;
  204. extern void _ITM_memcpyRtaRWn(void *, const void *, size_t) ITM_REGPARM;
  205. extern void _ITM_memcpyRtaRWt(void *, const void *, size_t) ITM_REGPARM;
  206. extern void _ITM_memcpyRtaRWtaR(void *, const void *, size_t) ITM_REGPARM;
  207. extern void _ITM_memcpyRtaRWtaW(void *, const void *, size_t) ITM_REGPARM;
  208. extern void _ITM_memcpyRtaWWn(void *, const void *, size_t) ITM_REGPARM;
  209. extern void _ITM_memcpyRtaWWt(void *, const void *, size_t) ITM_REGPARM;
  210. extern void _ITM_memcpyRtaWWtaR(void *, const void *, size_t) ITM_REGPARM;
  211. extern void _ITM_memcpyRtaWWtaW(void *, const void *, size_t) ITM_REGPARM;
  212. extern void _ITM_memmoveRnWt(void *, const void *, size_t) ITM_REGPARM;
  213. extern void _ITM_memmoveRnWtaR(void *, const void *, size_t) ITM_REGPARM;
  214. extern void _ITM_memmoveRnWtaW(void *, const void *, size_t) ITM_REGPARM;
  215. extern void _ITM_memmoveRtWn(void *, const void *, size_t) ITM_REGPARM;
  216. extern void _ITM_memmoveRtWt(void *, const void *, size_t) ITM_REGPARM;
  217. extern void _ITM_memmoveRtWtaR(void *, const void *, size_t) ITM_REGPARM;
  218. extern void _ITM_memmoveRtWtaW(void *, const void *, size_t) ITM_REGPARM;
  219. extern void _ITM_memmoveRtaRWn(void *, const void *, size_t) ITM_REGPARM;
  220. extern void _ITM_memmoveRtaRWt(void *, const void *, size_t) ITM_REGPARM;
  221. extern void _ITM_memmoveRtaRWtaR(void *, const void *, size_t) ITM_REGPARM;
  222. extern void _ITM_memmoveRtaRWtaW(void *, const void *, size_t) ITM_REGPARM;
  223. extern void _ITM_memmoveRtaWWn(void *, const void *, size_t) ITM_REGPARM;
  224. extern void _ITM_memmoveRtaWWt(void *, const void *, size_t) ITM_REGPARM;
  225. extern void _ITM_memmoveRtaWWtaR(void *, const void *, size_t) ITM_REGPARM;
  226. extern void _ITM_memmoveRtaWWtaW(void *, const void *, size_t) ITM_REGPARM;
  227. extern void _ITM_memsetW(void *, int, size_t) ITM_REGPARM;
  228. extern void _ITM_memsetWaR(void *, int, size_t) ITM_REGPARM;
  229. extern void _ITM_memsetWaW(void *, int, size_t) ITM_REGPARM;
  230. // ??? These are not yet in the official spec; still work-in-progress.
  231. extern void *_ITM_getTMCloneOrIrrevocable (void *) ITM_REGPARM;
  232. extern void *_ITM_getTMCloneSafe (void *) ITM_REGPARM;
  233. extern void _ITM_registerTMCloneTable (void *, size_t);
  234. extern void _ITM_deregisterTMCloneTable (void *);
  235. extern void *_ITM_cxa_allocate_exception (size_t);
  236. extern void _ITM_cxa_throw (void *obj, void *tinfo, void *dest);
  237. extern void *_ITM_cxa_begin_catch (void *exc_ptr);
  238. extern void _ITM_cxa_end_catch (void);
  239. extern void _ITM_commitTransactionEH(void *exc_ptr) ITM_REGPARM;
  240. #ifdef __cplusplus
  241. } /* extern "C" */
  242. #endif
  243. #endif /* LIBITM_H */