Skip to content

Commit

Permalink
Add futex support to LKL.
Browse files Browse the repository at this point in the history
This uses the GCC builtins for the atomic ops, avoiding
architecture-specific code.
  • Loading branch information
davidchisnall authored and SeanTAllen committed May 21, 2020
1 parent 698c97c commit 583b1ce
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
1 change: 0 additions & 1 deletion arch/lkl/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ generic-y += errno.h
generic-y += extable.h
generic-y += exec.h
generic-y += ftrace.h
generic-y += futex.h
generic-y += hardirq.h
generic-y += hw_irq.h
generic-y += ioctl.h
Expand Down
57 changes: 57 additions & 0 deletions arch/lkl/include/asm/futex.h
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

0 comments on commit 583b1ce

Please sign in to comment.