futex
u32 futex[2];
oval64.futex[futex_pos] = oldval;
if (get_user(oval64.futex[other_pos], (u32 __user *)uaddr64 + other_pos))
nval64.futex[futex_pos] = newval;
nval64.futex[other_pos] = oval64.futex[other_pos];
oldval = oval64.futex[futex_pos];
other = oval64.futex[other_pos];
orig_other = orig64.futex[other_pos];
unsigned int futex;
stub_data->futex = FUTEX_IN_KERN;
os_futex_wake(&stub_data->futex);
d->futex = FUTEX_IN_KERN;
res = stub_syscall3(__NR_futex, (unsigned long)&d->futex,
res = stub_syscall4(__NR_futex, (unsigned long)&d->futex,
} while (res == -EINTR || d->futex == FUTEX_IN_KERN);
data->futex = FUTEX_IN_CHILD;
CATCH_EINTR(syscall(__NR_futex, &data->futex,
ret = syscall(__NR_futex, &data->futex,
} while (data->futex == FUTEX_IN_CHILD);
proc_data->futex = FUTEX_IN_CHILD;
struct futex_mm_data *fd = ¤t->mm->futex;
csr = current->mm->futex.unlock.cs_ranges;
memset(&tsk->futex, 0, sizeof(tsk->futex));
INIT_LIST_HEAD(&tsk->futex.pi_state_list);
tsk->futex.state = FUTEX_STATE_OK;
mutex_init(&tsk->futex.exit_mutex);
struct futex_mm_data futex;
} futex;
struct futex_sched_data futex;
if (unlikely(current->futex.pi_state_cache))
kfree(current->futex.pi_state_cache);
struct robust_list_head __user *head = curr->futex.robust_list;
struct robust_list_head __user *head = current->futex.robust_list;
current->futex.robust_list = NULL;
struct compat_robust_list_head __user *head = current->futex.compat_robust_list;
struct compat_robust_list_head __user *head = current->futex.compat_robust_list;
current->futex.compat_robust_list = NULL;
struct list_head *next, *head = &curr->futex.pi_state_list;
if (unlikely(tsk->futex.robust_list)) {
tsk->futex.robust_list = NULL;
if (unlikely(tsk->futex.compat_robust_list)) {
tsk->futex.compat_robust_list = NULL;
if (unlikely(!list_empty(&tsk->futex.pi_state_list)))
if (tsk->futex.state == FUTEX_STATE_EXITING) {
__assume_ctx_lock(&tsk->futex.exit_mutex);
mutex_unlock(&tsk->futex.exit_mutex);
tsk->futex.state = FUTEX_STATE_DEAD;
__acquires(&tsk->futex.exit_mutex)
mutex_lock(&tsk->futex.exit_mutex);
tsk->futex.state = FUTEX_STATE_EXITING;
__releases(&tsk->futex.exit_mutex)
tsk->futex.state = state;
mutex_unlock(&tsk->futex.exit_mutex);
WARN_ON_ONCE(atomic_long_read(&mm->futex.phash.atomic) != 0);
atomic_long_set(&mm->futex.phash.atomic, LONG_MAX);
call_rcu_hurry(&mm->futex.phash.rcu, futex_ref_rcu);
unsigned int *ptr = per_cpu_ptr(mm->futex.phash.ref, cpu);
this_cpu_inc(*mm->futex.phash.ref); /* 0 -> 1 */
ret = atomic_long_add_return(count - LONG_MAX - 1, &mm->futex.phash.atomic);
struct mm_struct *mm = container_of(head, struct mm_struct, futex.phash.rcu);
struct futex_private_hash *fph = rcu_dereference_raw(mm->futex.phash.hash);
WARN_ON_ONCE(rcu_dereference_raw(mm->futex.phash.hash) != fph);
if (poll_state_synchronize_rcu(mm->futex.phash.batches)) {
call_rcu_hurry(&mm->futex.phash.rcu, futex_ref_rcu);
__this_cpu_inc(*mm->futex.phash.ref);
return atomic_long_inc_not_zero(&mm->futex.phash.atomic);
__this_cpu_dec(*mm->futex.phash.ref);
return atomic_long_dec_and_test(&mm->futex.phash.atomic);
return atomic_long_read(&mm->futex.phash.atomic) == 0;
free_percpu(mm->futex.phash.ref);
kvfree(mm->futex.phash.hash_new);
fph = rcu_dereference_raw(mm->futex.phash.hash);
if (!mm->futex.phash.hash_new)
fph = rcu_dereference(mm->futex.phash.hash);
fph = rcu_dereference(mm->futex.phash.hash);
if (!mm->futex.phash.ref) {
mm->futex.phash.ref = alloc_percpu(unsigned int);
if (!mm->futex.phash.ref)
this_cpu_inc(*mm->futex.phash.ref); /* 0 -> 1 */
scoped_guard(mutex, &mm->futex.phash.lock) {
cur = rcu_dereference_protected(mm->futex.phash.hash,
lockdep_is_held(&mm->futex.phash.lock));
new = mm->futex.phash.hash_new;
mm->futex.phash.hash_new = NULL;
mm->futex.phash.hash_new = new;
fph = rcu_dereference(current->mm->futex.phash.hash);
fph = rcu_dereference(current->mm->futex.phash.hash);
struct futex_mm_phash *mmph = &mm->futex.phash;
futex_hash_init_mm(&mm->futex);
futex_robust_unlock_init_mm(&mm->futex);
scoped_guard(mutex, &mm->futex.phash.lock) {
fph = mm->futex.phash.hash_new;
mm->futex.phash.hash_new = NULL;
fph = rcu_dereference(mm->futex.phash.hash);
fph = rcu_dereference(key->private.mm->futex.phash.hash);
mutex_lock(&exiting->futex.exit_mutex);
mutex_unlock(&exiting->futex.exit_mutex);
current->futex.pi_state_cache = pi_state;
if (likely(current->futex.pi_state_cache))
current->futex.pi_state_cache = pi_state;
if (tsk && tsk->futex.state != FUTEX_STATE_DEAD)
struct futex_pi_state *pi_state = current->futex.pi_state_cache;
list_add(&pi_state->list, &p->futex.pi_state_list);
current->futex.pi_state_cache = NULL;
if (unlikely(p->futex.state != FUTEX_STATE_OK)) {
list_add(&pi_state->list, &new_owner->futex.pi_state_list);
if (current->futex.pi_state_cache) {
SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
current->futex.robust_list = head;
return p->futex.compat_robust_list;
return p->futex.robust_list;
current->futex.compat_robust_list = head;
restart->futex.uaddr = uaddr;
restart->futex.val = val;
restart->futex.time = *abs_time;
restart->futex.bitset = bitset;
restart->futex.flags = flags | FLAGS_HAS_TIMEOUT;
u32 __user *uaddr = restart->futex.uaddr;
if (restart->futex.flags & FLAGS_HAS_TIMEOUT)
tp = &restart->futex.time;
return (long)futex_wait(uaddr, restart->futex.flags,
restart->futex.val, tp, restart->futex.bitset);
COND_SYSCALL(futex);
worker[i].futex = calloc(params.nfutexes, sizeof(*worker[i].futex));
if (!worker[i].futex)
worker[i].tid, &worker[i].futex[0], t);
worker[i].tid, &worker[i].futex[0],
&worker[i].futex[params.nfutexes-1], t);
zfree(&worker[i].futex);
u_int32_t *futex;
ret = futex_wait(&w->futex[i], 1234, NULL, futex_flag);
ret = futex_lock_pi(w->futex, NULL, futex_flag);
w->tid, w->futex, ret);
ret = futex_unlock_pi(w->futex, futex_flag);
w->tid, w->futex, ret);
worker[i].futex = calloc(1, sizeof(u_int32_t));
if (!worker[i].futex)
worker[i].futex = &global_futex;
worker[i].tid, worker[i].futex, t);
zfree(&worker[i].futex);
u_int32_t *futex;
if (futex_wait(&futex, 0, NULL, futex_flag) != EINTR)
&futex, params.nwakes, nwakes);
static u_int32_t futex = 0;
waker->nwoken = futex_wake(&futex, nwakes, futex_flag);
futex_numa->futex = 0;
futex_numa->futex = 0;
futex = shm;
ksft_print_dbg_msg("Calling shared (file backed) futex_wait on futex: %p\n", futex);
ksft_print_dbg_msg("Calling shared (file backed) futex_wake on futex: %p\n", futex);
void *futex;
if (futex_wait(futex, 0, &to, flags))
futex = &f_private;
ksft_print_dbg_msg("Calling private futex_wait on futex: %p\n", futex);
ksft_print_dbg_msg("Calling private futex_wake on futex: %p\n", futex);
res = futex_wake(futex, 1, FUTEX_PRIVATE_FLAG);
futex = shared_data;
ksft_print_dbg_msg("Calling shared (page anon) futex_wait on futex: %p\n", futex);
ksft_print_dbg_msg("Calling shared (page anon) futex_wake on futex: %p\n", futex);
res = futex_wake(futex, 1, 0);
head->futex_offset = (size_t) offsetof(struct lock_struct, futex) -
_Atomic(unsigned int) *futex = &lock->futex;
if (atomic_compare_exchange_strong(futex, &zero, tid)) {
tid = atomic_load(futex);
atomic_store(futex, tid);
ret = futex_wait((futex_t *) futex, tid, &to, 0);
struct lock_struct lock = { .futex = 0 };
_Atomic(unsigned int) *futex = &lock.futex;
ASSERT_TRUE(*futex & FUTEX_OWNER_DIED);
struct lock_struct lock = { .futex = 0 };
_Atomic(unsigned int) *futex = &lock.futex;
ASSERT_TRUE(*futex & FUTEX_OWNER_DIED);
locks[i].futex = 0;
if (!(lock->futex & FUTEX_OWNER_DIED)) {
struct lock_struct lock = { .futex = 0 };
_Atomic(unsigned int) *futex = &lock.futex;
*futex = tid;
ret = self->vdso(futex, tid, &head.list_op_pending);
ASSERT_EQ(*futex, 0);
struct lock_struct lock = { .futex = 0 };
_Atomic(unsigned int) *futex = &lock.futex;
*futex = tid | FUTEX_WAITERS;
ret = self->vdso(futex, tid, &head.list_op_pending);
ASSERT_EQ(*futex, tid | FUTEX_WAITERS);
_Atomic(unsigned int) futex;
struct lock_struct lock = { .futex = 0 };
_Atomic(unsigned int) *futex = &lock.futex;
*futex = tid | FUTEX_WAITERS;
ret = sys_futex_robust_unlock(futex, FUTEX_ROBUST_UNLOCK | variant->op, tid,
ASSERT_EQ(*futex, 0);
futex_t futex;
return futex(uaddr, FUTEX_WAIT, val, timeout, NULL, 0, opflags);
return futex(uaddr, FUTEX_WAKE, nr_wake, NULL, NULL, 0, opflags);
return futex(uaddr, FUTEX_WAIT_BITSET, val, timeout, NULL, bitset,
return futex(uaddr, FUTEX_WAKE_BITSET, nr_wake, NULL, NULL, bitset,
return futex(uaddr, FUTEX_LOCK_PI, detect, timeout, NULL, 0, opflags);
return futex(uaddr, FUTEX_UNLOCK_PI, 0, NULL, NULL, 0, opflags);
return futex(uaddr, FUTEX_WAKE_OP, nr_wake, nr_wake2, uaddr2, wake_op,
return futex(uaddr, FUTEX_REQUEUE, nr_wake, nr_requeue, uaddr2, 0,
return futex(uaddr, FUTEX_CMP_REQUEUE, nr_wake, nr_requeue, uaddr2,
return futex(uaddr, FUTEX_WAIT_REQUEUE_PI, val, timeout, uaddr2, 0,
return futex(uaddr, FUTEX_CMP_REQUEUE_PI, nr_wake, nr_requeue, uaddr2,
futex(&addr, FUTEX_WAKE, 1, NULL, NULL, 0);