-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This uses the GCC builtins for the atomic ops, avoiding architecture-specific code.
- Loading branch information
1 parent
698c97c
commit 583b1ce
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _ASM_LKL_FUTEX_H | ||
#define _ASM_LKL_FUTEX_H | ||
|
||
#ifdef __KERNEL__ | ||
|
||
#include <linux/futex.h> | ||
#include <asm/errno.h> | ||
|
||
static inline int arch_futex_atomic_op_inuser(int op, int oparg, int *oval, | ||
u32 __user *uaddr) | ||
{ | ||
int oldval = 0, ret = 0; | ||
|
||
switch (op) { | ||
case FUTEX_OP_SET: | ||
__atomic_exchange(uaddr, &oparg, oval, __ATOMIC_SEQ_CST); | ||
break; | ||
case FUTEX_OP_ADD: | ||
__atomic_fetch_add(uaddr, oparg, __ATOMIC_SEQ_CST); | ||
break; | ||
case FUTEX_OP_OR: | ||
__atomic_fetch_or(uaddr, oparg, __ATOMIC_SEQ_CST); | ||
break; | ||
case FUTEX_OP_ANDN: | ||
__atomic_fetch_and(uaddr, ~oparg, __ATOMIC_SEQ_CST); | ||
break; | ||
case FUTEX_OP_XOR: | ||
__atomic_fetch_xor(uaddr, oparg, __ATOMIC_SEQ_CST); | ||
break; | ||
default: | ||
ret = -ENOSYS; | ||
} | ||
|
||
if (!ret) | ||
*oval = oldval; | ||
|
||
return ret; | ||
} | ||
|
||
static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, | ||
u32 oldval, u32 newval) | ||
{ | ||
if (uaddr == NULL) { | ||
return -EFAULT; | ||
} else { | ||
u32 v = oldval; | ||
int ret = __atomic_compare_exchange_n(uaddr, &v, newval, 0 /*weak*/, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); | ||
|
||
*uval = v; | ||
|
||
return ret; | ||
} | ||
} | ||
|
||
#endif | ||
#endif |