2 * SPDX-License-Identifier: LGPL-2.1-or-later
4 * Copyright 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Userspace RCU - sys_futex/compat_futex header.
9 #ifndef _UST_COMMON_COMPAT_FUTEX_H
10 #define _UST_COMMON_COMPAT_FUTEX_H
15 #include <sys/syscall.h>
25 * sys_futex compatibility header.
26 * Use *only* *either of* futex_noasync OR futex_async on a given address.
28 * futex_noasync cannot be executed in signal handlers, but ensures that
29 * it will be put in a wait queue even in compatibility mode.
31 * futex_async is signal-handler safe for the wakeup. It uses polling
32 * on the wait-side in compatibility mode.
34 * BEWARE: sys_futex() FUTEX_WAIT may return early if interrupted
38 extern int lttng_ust_compat_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
39 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
40 __attribute__((visibility("hidden")));
42 extern int lttng_ust_compat_futex_async(int32_t *uaddr
, int op
, int32_t val
,
43 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
44 __attribute__((visibility("hidden")));
46 #if (defined(__linux__) && defined(__NR_futex))
50 #include <urcu/compiler.h>
51 #include <urcu/arch.h>
53 static inline int lttng_ust_futex(int32_t *uaddr
, int op
, int32_t val
,
54 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
56 return syscall(__NR_futex
, uaddr
, op
, val
, timeout
,
60 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
61 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
65 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
66 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
68 * The fallback on ENOSYS is the async-safe version of
69 * the compat futex implementation, because the
70 * async-safe compat implementation allows being used
71 * concurrently with calls to futex(). Indeed, sys_futex
72 * FUTEX_WAIT, on some architectures (mips and parisc),
73 * within a given process, spuriously return ENOSYS due
74 * to signal restart bugs on some kernel versions.
76 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
83 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
84 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
88 ret
= lttng_ust_futex(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
89 if (caa_unlikely(ret
< 0 && errno
== ENOSYS
)) {
90 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
,
96 #elif defined(__FreeBSD__)
98 #include <sys/types.h>
101 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
102 const struct timespec
*timeout
,
103 int32_t *uaddr2
__attribute__((unused
)),
104 int32_t val3
__attribute__((unused
)))
107 void *umtx_uaddr
= NULL
, *umtx_uaddr2
= NULL
;
108 struct _umtx_time umtx_timeout
= {
109 ._flags
= UMTX_ABSTIME
,
110 ._clockid
= CLOCK_MONOTONIC
,
115 /* On FreeBSD, a "u_int" is a 32-bit integer. */
116 umtx_op
= UMTX_OP_WAIT_UINT
;
117 if (timeout
!= NULL
) {
118 umtx_timeout
._timeout
= *timeout
;
119 umtx_uaddr
= (void *) sizeof(umtx_timeout
);
120 umtx_uaddr2
= (void *) &umtx_timeout
;
124 umtx_op
= UMTX_OP_WAKE
;
131 return _umtx_op(uaddr
, umtx_op
, (uint32_t) val
, umtx_uaddr
,
135 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
136 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
138 return lttng_ust_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
141 #elif defined(__CYGWIN__)
144 * The futex_noasync compat code uses a weak symbol to share state across
145 * different shared object which is not possible on Windows with the
146 * Portable Executable format. Use the async compat code for both cases.
148 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
149 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
151 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
154 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
155 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
157 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
162 static inline int lttng_ust_futex_noasync(int32_t *uaddr
, int op
, int32_t val
,
163 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
165 return lttng_ust_compat_futex_noasync(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
168 static inline int lttng_ust_futex_async(int32_t *uaddr
, int op
, int32_t val
,
169 const struct timespec
*timeout
, int32_t *uaddr2
, int32_t val3
)
171 return lttng_ust_compat_futex_async(uaddr
, op
, val
, timeout
, uaddr2
, val3
);
180 #endif /* _UST_COMMON_COMPAT_FUTEX_H */
This page took 0.044467 seconds and 4 git commands to generate.