Skip to content

Commit

Permalink
[LibOS] Add missing locking around move_futex_waiter
Browse files Browse the repository at this point in the history
That function modifies `waiter->futex`, which requires
`g_futex_tree_lock` to be held.

Signed-off-by: Borys Popławski <[email protected]>
  • Loading branch information
boryspoplawski committed Apr 24, 2022
1 parent ad85fe9 commit 9774ce1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion LibOS/shim/src/sys/shim_futex.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ static struct shim_thread* remove_futex_waiter(struct futex_waiter* waiter,
*/
static void move_futex_waiter(struct futex_waiter* waiter, struct shim_futex* futex1,
struct shim_futex* futex2) {
assert(spinlock_is_locked(&g_futex_tree_lock));
assert(spinlock_is_locked(&futex1->lock));
assert(spinlock_is_locked(&futex2->lock));

Expand Down Expand Up @@ -633,7 +634,6 @@ static int futex_requeue(uint32_t* uaddr1, uint32_t* uaddr2, int to_wake, int to
futex1 = find_futex(uaddr1);

lock_two_futexes(futex1, futex2);
spinlock_unlock(&g_futex_tree_lock);

if (val != NULL) {
if (__atomic_load_n(uaddr1, __ATOMIC_RELAXED) != *val) {
Expand Down Expand Up @@ -668,6 +668,7 @@ static int futex_requeue(uint32_t* uaddr1, uint32_t* uaddr2, int to_wake, int to

out_unlock:
unlock_two_futexes(futex1, futex2);
spinlock_unlock(&g_futex_tree_lock);

if (needs_dequeue1 || needs_dequeue2) {
maybe_dequeue_two_futexes(futex1, futex2);
Expand Down

0 comments on commit 9774ce1

Please sign in to comment.