xref: /aosp_15_r20/external/compiler-rt/include/sanitizer/tsan_interface_atomic.h (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot //===-- tsan_interface_atomic.h ---------------------------------*- C++ -*-===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot //                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot //
10*7c3d14c8STreehugger Robot // This file is a part of ThreadSanitizer (TSan), a race detector.
11*7c3d14c8STreehugger Robot //
12*7c3d14c8STreehugger Robot // Public interface header for TSan atomics.
13*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
14*7c3d14c8STreehugger Robot #ifndef TSAN_INTERFACE_ATOMIC_H
15*7c3d14c8STreehugger Robot #define TSAN_INTERFACE_ATOMIC_H
16*7c3d14c8STreehugger Robot 
17*7c3d14c8STreehugger Robot #ifdef __cplusplus
18*7c3d14c8STreehugger Robot extern "C" {
19*7c3d14c8STreehugger Robot #endif
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot typedef char     __tsan_atomic8;
22*7c3d14c8STreehugger Robot typedef short    __tsan_atomic16;  // NOLINT
23*7c3d14c8STreehugger Robot typedef int      __tsan_atomic32;
24*7c3d14c8STreehugger Robot typedef long     __tsan_atomic64;  // NOLINT
25*7c3d14c8STreehugger Robot #if defined(__SIZEOF_INT128__) \
26*7c3d14c8STreehugger Robot     || (__clang_major__ * 100 + __clang_minor__ >= 302)
27*7c3d14c8STreehugger Robot __extension__ typedef __int128 __tsan_atomic128;
28*7c3d14c8STreehugger Robot # define __TSAN_HAS_INT128 1
29*7c3d14c8STreehugger Robot #else
30*7c3d14c8STreehugger Robot # define __TSAN_HAS_INT128 0
31*7c3d14c8STreehugger Robot #endif
32*7c3d14c8STreehugger Robot 
33*7c3d14c8STreehugger Robot // Part of ABI, do not change.
34*7c3d14c8STreehugger Robot // http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?view=markup
35*7c3d14c8STreehugger Robot typedef enum {
36*7c3d14c8STreehugger Robot   __tsan_memory_order_relaxed,
37*7c3d14c8STreehugger Robot   __tsan_memory_order_consume,
38*7c3d14c8STreehugger Robot   __tsan_memory_order_acquire,
39*7c3d14c8STreehugger Robot   __tsan_memory_order_release,
40*7c3d14c8STreehugger Robot   __tsan_memory_order_acq_rel,
41*7c3d14c8STreehugger Robot   __tsan_memory_order_seq_cst
42*7c3d14c8STreehugger Robot } __tsan_memory_order;
43*7c3d14c8STreehugger Robot 
44*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_load(const volatile __tsan_atomic8 *a,
45*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
46*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_load(const volatile __tsan_atomic16 *a,
47*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
48*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_load(const volatile __tsan_atomic32 *a,
49*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
50*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_load(const volatile __tsan_atomic64 *a,
51*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
52*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
53*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_load(const volatile __tsan_atomic128 *a,
54*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
55*7c3d14c8STreehugger Robot #endif
56*7c3d14c8STreehugger Robot 
57*7c3d14c8STreehugger Robot void __tsan_atomic8_store(volatile __tsan_atomic8 *a, __tsan_atomic8 v,
58*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
59*7c3d14c8STreehugger Robot void __tsan_atomic16_store(volatile __tsan_atomic16 *a, __tsan_atomic16 v,
60*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
61*7c3d14c8STreehugger Robot void __tsan_atomic32_store(volatile __tsan_atomic32 *a, __tsan_atomic32 v,
62*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
63*7c3d14c8STreehugger Robot void __tsan_atomic64_store(volatile __tsan_atomic64 *a, __tsan_atomic64 v,
64*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
65*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
66*7c3d14c8STreehugger Robot void __tsan_atomic128_store(volatile __tsan_atomic128 *a, __tsan_atomic128 v,
67*7c3d14c8STreehugger Robot     __tsan_memory_order mo);
68*7c3d14c8STreehugger Robot #endif
69*7c3d14c8STreehugger Robot 
70*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_exchange(volatile __tsan_atomic8 *a,
71*7c3d14c8STreehugger Robot     __tsan_atomic8 v, __tsan_memory_order mo);
72*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_exchange(volatile __tsan_atomic16 *a,
73*7c3d14c8STreehugger Robot     __tsan_atomic16 v, __tsan_memory_order mo);
74*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_exchange(volatile __tsan_atomic32 *a,
75*7c3d14c8STreehugger Robot     __tsan_atomic32 v, __tsan_memory_order mo);
76*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_exchange(volatile __tsan_atomic64 *a,
77*7c3d14c8STreehugger Robot     __tsan_atomic64 v, __tsan_memory_order mo);
78*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
79*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_exchange(volatile __tsan_atomic128 *a,
80*7c3d14c8STreehugger Robot     __tsan_atomic128 v, __tsan_memory_order mo);
81*7c3d14c8STreehugger Robot #endif
82*7c3d14c8STreehugger Robot 
83*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_fetch_add(volatile __tsan_atomic8 *a,
84*7c3d14c8STreehugger Robot     __tsan_atomic8 v, __tsan_memory_order mo);
85*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_fetch_add(volatile __tsan_atomic16 *a,
86*7c3d14c8STreehugger Robot     __tsan_atomic16 v, __tsan_memory_order mo);
87*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_fetch_add(volatile __tsan_atomic32 *a,
88*7c3d14c8STreehugger Robot     __tsan_atomic32 v, __tsan_memory_order mo);
89*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_fetch_add(volatile __tsan_atomic64 *a,
90*7c3d14c8STreehugger Robot     __tsan_atomic64 v, __tsan_memory_order mo);
91*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
92*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_fetch_add(volatile __tsan_atomic128 *a,
93*7c3d14c8STreehugger Robot     __tsan_atomic128 v, __tsan_memory_order mo);
94*7c3d14c8STreehugger Robot #endif
95*7c3d14c8STreehugger Robot 
96*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_fetch_sub(volatile __tsan_atomic8 *a,
97*7c3d14c8STreehugger Robot     __tsan_atomic8 v, __tsan_memory_order mo);
98*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_fetch_sub(volatile __tsan_atomic16 *a,
99*7c3d14c8STreehugger Robot     __tsan_atomic16 v, __tsan_memory_order mo);
100*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_fetch_sub(volatile __tsan_atomic32 *a,
101*7c3d14c8STreehugger Robot     __tsan_atomic32 v, __tsan_memory_order mo);
102*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_fetch_sub(volatile __tsan_atomic64 *a,
103*7c3d14c8STreehugger Robot     __tsan_atomic64 v, __tsan_memory_order mo);
104*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
105*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_fetch_sub(volatile __tsan_atomic128 *a,
106*7c3d14c8STreehugger Robot     __tsan_atomic128 v, __tsan_memory_order mo);
107*7c3d14c8STreehugger Robot #endif
108*7c3d14c8STreehugger Robot 
109*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_fetch_and(volatile __tsan_atomic8 *a,
110*7c3d14c8STreehugger Robot     __tsan_atomic8 v, __tsan_memory_order mo);
111*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_fetch_and(volatile __tsan_atomic16 *a,
112*7c3d14c8STreehugger Robot     __tsan_atomic16 v, __tsan_memory_order mo);
113*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_fetch_and(volatile __tsan_atomic32 *a,
114*7c3d14c8STreehugger Robot     __tsan_atomic32 v, __tsan_memory_order mo);
115*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_fetch_and(volatile __tsan_atomic64 *a,
116*7c3d14c8STreehugger Robot     __tsan_atomic64 v, __tsan_memory_order mo);
117*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
118*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_fetch_and(volatile __tsan_atomic128 *a,
119*7c3d14c8STreehugger Robot     __tsan_atomic128 v, __tsan_memory_order mo);
120*7c3d14c8STreehugger Robot #endif
121*7c3d14c8STreehugger Robot 
122*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_fetch_or(volatile __tsan_atomic8 *a,
123*7c3d14c8STreehugger Robot     __tsan_atomic8 v, __tsan_memory_order mo);
124*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_fetch_or(volatile __tsan_atomic16 *a,
125*7c3d14c8STreehugger Robot     __tsan_atomic16 v, __tsan_memory_order mo);
126*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_fetch_or(volatile __tsan_atomic32 *a,
127*7c3d14c8STreehugger Robot     __tsan_atomic32 v, __tsan_memory_order mo);
128*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_fetch_or(volatile __tsan_atomic64 *a,
129*7c3d14c8STreehugger Robot     __tsan_atomic64 v, __tsan_memory_order mo);
130*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
131*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_fetch_or(volatile __tsan_atomic128 *a,
132*7c3d14c8STreehugger Robot     __tsan_atomic128 v, __tsan_memory_order mo);
133*7c3d14c8STreehugger Robot #endif
134*7c3d14c8STreehugger Robot 
135*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_fetch_xor(volatile __tsan_atomic8 *a,
136*7c3d14c8STreehugger Robot     __tsan_atomic8 v, __tsan_memory_order mo);
137*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_fetch_xor(volatile __tsan_atomic16 *a,
138*7c3d14c8STreehugger Robot     __tsan_atomic16 v, __tsan_memory_order mo);
139*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_fetch_xor(volatile __tsan_atomic32 *a,
140*7c3d14c8STreehugger Robot     __tsan_atomic32 v, __tsan_memory_order mo);
141*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_fetch_xor(volatile __tsan_atomic64 *a,
142*7c3d14c8STreehugger Robot     __tsan_atomic64 v, __tsan_memory_order mo);
143*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
144*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_fetch_xor(volatile __tsan_atomic128 *a,
145*7c3d14c8STreehugger Robot     __tsan_atomic128 v, __tsan_memory_order mo);
146*7c3d14c8STreehugger Robot #endif
147*7c3d14c8STreehugger Robot 
148*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_fetch_nand(volatile __tsan_atomic8 *a,
149*7c3d14c8STreehugger Robot     __tsan_atomic8 v, __tsan_memory_order mo);
150*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_fetch_nand(volatile __tsan_atomic16 *a,
151*7c3d14c8STreehugger Robot     __tsan_atomic16 v, __tsan_memory_order mo);
152*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_fetch_nand(volatile __tsan_atomic32 *a,
153*7c3d14c8STreehugger Robot     __tsan_atomic32 v, __tsan_memory_order mo);
154*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_fetch_nand(volatile __tsan_atomic64 *a,
155*7c3d14c8STreehugger Robot     __tsan_atomic64 v, __tsan_memory_order mo);
156*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
157*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_fetch_nand(volatile __tsan_atomic128 *a,
158*7c3d14c8STreehugger Robot     __tsan_atomic128 v, __tsan_memory_order mo);
159*7c3d14c8STreehugger Robot #endif
160*7c3d14c8STreehugger Robot 
161*7c3d14c8STreehugger Robot int __tsan_atomic8_compare_exchange_weak(volatile __tsan_atomic8 *a,
162*7c3d14c8STreehugger Robot     __tsan_atomic8 *c, __tsan_atomic8 v, __tsan_memory_order mo,
163*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
164*7c3d14c8STreehugger Robot int __tsan_atomic16_compare_exchange_weak(volatile __tsan_atomic16 *a,
165*7c3d14c8STreehugger Robot     __tsan_atomic16 *c, __tsan_atomic16 v, __tsan_memory_order mo,
166*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
167*7c3d14c8STreehugger Robot int __tsan_atomic32_compare_exchange_weak(volatile __tsan_atomic32 *a,
168*7c3d14c8STreehugger Robot     __tsan_atomic32 *c, __tsan_atomic32 v, __tsan_memory_order mo,
169*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
170*7c3d14c8STreehugger Robot int __tsan_atomic64_compare_exchange_weak(volatile __tsan_atomic64 *a,
171*7c3d14c8STreehugger Robot     __tsan_atomic64 *c, __tsan_atomic64 v, __tsan_memory_order mo,
172*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
173*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
174*7c3d14c8STreehugger Robot int __tsan_atomic128_compare_exchange_weak(volatile __tsan_atomic128 *a,
175*7c3d14c8STreehugger Robot     __tsan_atomic128 *c, __tsan_atomic128 v, __tsan_memory_order mo,
176*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
177*7c3d14c8STreehugger Robot #endif
178*7c3d14c8STreehugger Robot 
179*7c3d14c8STreehugger Robot int __tsan_atomic8_compare_exchange_strong(volatile __tsan_atomic8 *a,
180*7c3d14c8STreehugger Robot     __tsan_atomic8 *c, __tsan_atomic8 v, __tsan_memory_order mo,
181*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
182*7c3d14c8STreehugger Robot int __tsan_atomic16_compare_exchange_strong(volatile __tsan_atomic16 *a,
183*7c3d14c8STreehugger Robot     __tsan_atomic16 *c, __tsan_atomic16 v, __tsan_memory_order mo,
184*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
185*7c3d14c8STreehugger Robot int __tsan_atomic32_compare_exchange_strong(volatile __tsan_atomic32 *a,
186*7c3d14c8STreehugger Robot     __tsan_atomic32 *c, __tsan_atomic32 v, __tsan_memory_order mo,
187*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
188*7c3d14c8STreehugger Robot int __tsan_atomic64_compare_exchange_strong(volatile __tsan_atomic64 *a,
189*7c3d14c8STreehugger Robot     __tsan_atomic64 *c, __tsan_atomic64 v, __tsan_memory_order mo,
190*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
191*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
192*7c3d14c8STreehugger Robot int __tsan_atomic128_compare_exchange_strong(volatile __tsan_atomic128 *a,
193*7c3d14c8STreehugger Robot     __tsan_atomic128 *c, __tsan_atomic128 v, __tsan_memory_order mo,
194*7c3d14c8STreehugger Robot     __tsan_memory_order fail_mo);
195*7c3d14c8STreehugger Robot #endif
196*7c3d14c8STreehugger Robot 
197*7c3d14c8STreehugger Robot __tsan_atomic8 __tsan_atomic8_compare_exchange_val(
198*7c3d14c8STreehugger Robot     volatile __tsan_atomic8 *a, __tsan_atomic8 c, __tsan_atomic8 v,
199*7c3d14c8STreehugger Robot     __tsan_memory_order mo, __tsan_memory_order fail_mo);
200*7c3d14c8STreehugger Robot __tsan_atomic16 __tsan_atomic16_compare_exchange_val(
201*7c3d14c8STreehugger Robot     volatile __tsan_atomic16 *a, __tsan_atomic16 c, __tsan_atomic16 v,
202*7c3d14c8STreehugger Robot     __tsan_memory_order mo, __tsan_memory_order fail_mo);
203*7c3d14c8STreehugger Robot __tsan_atomic32 __tsan_atomic32_compare_exchange_val(
204*7c3d14c8STreehugger Robot     volatile __tsan_atomic32 *a, __tsan_atomic32 c, __tsan_atomic32 v,
205*7c3d14c8STreehugger Robot     __tsan_memory_order mo, __tsan_memory_order fail_mo);
206*7c3d14c8STreehugger Robot __tsan_atomic64 __tsan_atomic64_compare_exchange_val(
207*7c3d14c8STreehugger Robot     volatile __tsan_atomic64 *a, __tsan_atomic64 c, __tsan_atomic64 v,
208*7c3d14c8STreehugger Robot     __tsan_memory_order mo, __tsan_memory_order fail_mo);
209*7c3d14c8STreehugger Robot #if __TSAN_HAS_INT128
210*7c3d14c8STreehugger Robot __tsan_atomic128 __tsan_atomic128_compare_exchange_val(
211*7c3d14c8STreehugger Robot     volatile __tsan_atomic128 *a, __tsan_atomic128 c, __tsan_atomic128 v,
212*7c3d14c8STreehugger Robot     __tsan_memory_order mo, __tsan_memory_order fail_mo);
213*7c3d14c8STreehugger Robot #endif
214*7c3d14c8STreehugger Robot 
215*7c3d14c8STreehugger Robot void __tsan_atomic_thread_fence(__tsan_memory_order mo);
216*7c3d14c8STreehugger Robot void __tsan_atomic_signal_fence(__tsan_memory_order mo);
217*7c3d14c8STreehugger Robot 
218*7c3d14c8STreehugger Robot #ifdef __cplusplus
219*7c3d14c8STreehugger Robot }  // extern "C"
220*7c3d14c8STreehugger Robot #endif
221*7c3d14c8STreehugger Robot 
222*7c3d14c8STreehugger Robot #endif  // TSAN_INTERFACE_ATOMIC_H
223